Commit b9242afb authored by Matija Obreza's avatar Matija Obreza
Browse files

Merge branch 'java-time' into 'main'

Migrating to java.time

See merge request genesys-pgr/application-blocks!116
parents d66e2285 4d147569
......@@ -33,6 +33,8 @@ import org.genesys.blocks.model.filters.NumberFilter;
*/
public class AuditLogFilter extends EmptyModelFilter<AuditLogFilter, AuditLog> {
private static final long serialVersionUID = -3179751746560952451L;
/** The classname. */
public String classname;
......
......@@ -23,6 +23,8 @@ import org.genesys.blocks.model.filters.UuidModelFilter;
public class Other2EntityFilter extends UuidModelFilter<Other2EntityFilter, Other2Entity> {
private static final long serialVersionUID = 1L;
@Override
public List<Predicate> collectPredicates() {
return collectPredicates(QOther2Entity.other2Entity);
......
......@@ -32,7 +32,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
......
......@@ -18,8 +18,8 @@ package org.genesys.blocks.auditlog.test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import java.time.Instant;
import java.util.Calendar;
import java.util.Date;
import java.util.UUID;
import org.genesys.blocks.auditlog.model.Other2Entity;
......@@ -69,7 +69,7 @@ public class Other2EntityTest extends EntityTest<Other2Entity, Other2EntityRepos
Calendar instance = Calendar.getInstance();
instance.add(Calendar.MONTH, 10);
Other2Entity record2 = repository.save(makeDefault(UUID.randomUUID(), 2L, instance.getTime()));
Other2Entity record2 = repository.save(makeDefault(UUID.randomUUID(), 2L, instance.toInstant()));
assertThat(record2, notNullValue());
assertThat(record2.getUuid(), notNullValue());
assertThat(record2.getId(), is(greaterThan(1L)));
......@@ -90,14 +90,14 @@ public class Other2EntityTest extends EntityTest<Other2Entity, Other2EntityRepos
assertThat(page.getContent().get(0), equalTo(record));
filter = new Other2EntityFilter();
filter.createdDate().ge(instance.getTime());
filter.createdDate().ge(instance.toInstant());
page = repository.findAll(filter.buildPredicate(), PageRequest.of(0, 5));
assertThat(page.getTotalElements(), is(1L));
assertThat(page.getContent().get(0), equalTo(record2));
filter = new Other2EntityFilter();
filter.lastModifiedDate().ge(instance.getTime());
filter.lastModifiedDate().ge(instance.toInstant());
page = repository.findAll(filter.buildPredicate(), PageRequest.of(0, 5));
assertThat(page.getTotalElements(), is(1L));
......@@ -106,10 +106,10 @@ public class Other2EntityTest extends EntityTest<Other2Entity, Other2EntityRepos
@Override
protected Other2Entity makeDefault() {
return makeDefault(UUID.randomUUID(), 1L, new Date());
return makeDefault(UUID.randomUUID(), 1L, Instant.now());
}
private Other2Entity makeDefault(UUID uuid, Long createdBy, Date createdDate) {
private Other2Entity makeDefault(UUID uuid, Long createdBy, Instant createdDate) {
Other2Entity other2Entity = new Other2Entity();
other2Entity.setUuid(uuid);
other2Entity.setCreatedBy(createdBy);
......
/*
* Copyright 2019 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.genesys.blocks.model.filters;
import java.io.Serializable;
import java.time.Instant;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Predicate;
import com.querydsl.core.types.dsl.TemporalExpression;
/**
* Utility filtering for {@link Instant} type.
*/
public class InstantFilter implements Serializable {
private static final long serialVersionUID = 7335760829004802798L;
/** Matches records where date is on or after "since" value. */
// >=
public Instant ge;
/** The gt. */
// >
public Instant gt;
/** Matches records where date is on or before "until" value. */
// <=
public Instant le;
/** The lt. */
// <
public Instant lt;
/**
* Builds the query.
*
* @param date the date
* @return the predicate
*/
public Predicate buildQuery(final TemporalExpression<Instant> date) {
final BooleanBuilder and = new BooleanBuilder();
if (ge != null) {
and.and(date.isNotNull());
and.and(date.goe(ge));
}
if (gt != null) {
and.and(date.isNotNull());
and.and(date.gt(gt));
}
if (le != null) {
and.and(date.isNotNull());
and.and(date.loe(le));
}
if (lt != null) {
and.and(date.isNotNull());
and.and(date.lt(lt));
}
return and;
}
/*
* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
final StringBuilder str = new StringBuilder();
if (ge != null) {
str.append(" date >= ").append(ge).append(" ");
}
if (gt != null) {
str.append(" date > ").append(gt).append(" ");
}
if (le != null) {
str.append(" date <= ").append(le).append(" ");
}
if (lt != null) {
str.append(" date < ").append(lt).append(" ");
}
return str.toString().replaceAll("\\s{2,}", " ");
}
/**
* Lt.
*
* @param date the date
* @return the date filter
*/
public InstantFilter lt(final Instant date) {
lt = date;
return this;
}
/**
* Ge.
*
* @param date the date
* @return the date filter
*/
public InstantFilter ge(final Instant date) {
ge = date;
return this;
}
}
......@@ -15,7 +15,7 @@
*/
package org.genesys.blocks.model;
import java.util.Date;
import java.time.Instant;
import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
......@@ -52,7 +52,7 @@ public abstract class AuditedVersionedModel extends VersionedModel {
@JsonView(JsonViews.Public.class)
@CreatedDate
@Column(name = "createdDate", updatable = false)
private Date createdDate;
private Instant createdDate;
/** The last modified by. */
@JsonView(JsonViews.Protected.class)
......@@ -65,7 +65,7 @@ public abstract class AuditedVersionedModel extends VersionedModel {
@JsonView(JsonViews.Public.class)
@LastModifiedDate
@Column(name = "lastModifiedDate")
private Date lastModifiedDate;
private Instant lastModifiedDate;
/**
* Gets the created by.
......@@ -90,7 +90,7 @@ public abstract class AuditedVersionedModel extends VersionedModel {
*
* @return the created date
*/
public Date getCreatedDate() {
public Instant getCreatedDate() {
return createdDate;
}
......@@ -99,7 +99,7 @@ public abstract class AuditedVersionedModel extends VersionedModel {
*
* @param createdDate the new created date
*/
public void setCreatedDate(final Date createdDate) {
public void setCreatedDate(final Instant createdDate) {
this.createdDate = createdDate;
}
......@@ -126,7 +126,7 @@ public abstract class AuditedVersionedModel extends VersionedModel {
*
* @return the last modified date
*/
public Date getLastModifiedDate() {
public Instant getLastModifiedDate() {
return lastModifiedDate;
}
......@@ -135,7 +135,7 @@ public abstract class AuditedVersionedModel extends VersionedModel {
*
* @param lastModifiedDate the new last modified date
*/
public void setLastModifiedDate(final Date lastModifiedDate) {
public void setLastModifiedDate(final Instant lastModifiedDate) {
this.lastModifiedDate = lastModifiedDate;
}
}
......@@ -43,10 +43,10 @@ public abstract class AuditedVersionedModelFilter<T extends AuditedVersionedMode
public Set<Long> lastModifiedBy;
/** The created date. */
public DateFilter createdDate;
public InstantFilter createdDate;
/** The last modified date. */
public DateFilter lastModifiedDate;
public InstantFilter lastModifiedDate;
/**
* Collects list of filter predicates
......@@ -101,9 +101,9 @@ public abstract class AuditedVersionedModelFilter<T extends AuditedVersionedMode
*
* @return the date filter
*/
public synchronized DateFilter createdDate() {
public synchronized InstantFilter createdDate() {
if (createdDate == null) {
createdDate = new DateFilter();
createdDate = new InstantFilter();
}
return createdDate;
}
......@@ -113,9 +113,9 @@ public abstract class AuditedVersionedModelFilter<T extends AuditedVersionedMode
*
* @return the date filter
*/
public synchronized DateFilter lastModifiedDate() {
public synchronized InstantFilter lastModifiedDate() {
if (lastModifiedDate == null) {
lastModifiedDate = new DateFilter();
lastModifiedDate = new InstantFilter();
}
return lastModifiedDate;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment