Commit 18f80d5e authored by Artem Hrybeniuk's avatar Artem Hrybeniuk
Browse files

WIP: Project models update to java.time

parent 131d99d4
......@@ -15,7 +15,7 @@
*/
package org.genesys.catalog.model.dataset;
import java.util.Date;
import java.time.Instant;
import java.util.List;
import java.util.Objects;
import java.util.Set;
......@@ -209,7 +209,7 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Acl
@Column(name = "firstPublishedDate")
@NotCopyable
private Date firstPublishedDate;
private Instant firstPublishedDate;
/** The publish state. */
@Enumerated(EnumType.ORDINAL)
......@@ -242,7 +242,7 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Acl
this.endDate = locations.stream().map(DatasetLocation::getEndDate).filter(d -> d != null).max(String::compareTo).orElse(null);
}
if (Objects.isNull(firstPublishedDate) && Objects.equals(state, PublishState.PUBLISHED)) {
firstPublishedDate = new Date();
firstPublishedDate = Instant.now();
}
trimStringsToNull();
......@@ -695,7 +695,7 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Acl
*
* @return the first published date
*/
public Date getFirstPublishedDate() {
public Instant getFirstPublishedDate() {
return firstPublishedDate;
}
......
......@@ -35,8 +35,8 @@ import org.springframework.data.elasticsearch.annotations.FieldType;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
......@@ -235,7 +235,7 @@ public class Descriptor extends UuidModel implements SelfCleaning, Publishable,
@Column(name = "firstPublishedDate")
@NotCopyable
private Date firstPublishedDate;
private Instant firstPublishedDate;
/**
* Instantiates a new descriptor.
......@@ -250,7 +250,7 @@ public class Descriptor extends UuidModel implements SelfCleaning, Publishable,
@PreUpdate
private void preupdate() {
if (Objects.isNull(firstPublishedDate) && Objects.equals(state, PublishState.PUBLISHED)) {
firstPublishedDate = new Date();
firstPublishedDate = Instant.now();
}
trimStringsToNull();
}
......@@ -743,7 +743,7 @@ public class Descriptor extends UuidModel implements SelfCleaning, Publishable,
*
* @return the first published date
*/
public Date getFirstPublishedDate() {
public Instant getFirstPublishedDate() {
return firstPublishedDate;
}
......
......@@ -15,7 +15,7 @@
*/
package org.genesys.catalog.model.traits;
import java.util.Date;
import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.util.Objects;
......@@ -153,7 +153,7 @@ public class DescriptorList extends UuidModel implements Publishable, SelfCleani
@Column(name = "firstPublishedDate")
@NotCopyable
private Date firstPublishedDate;
private Instant firstPublishedDate;
/**
* Pre-persist, pre-update
......@@ -162,7 +162,7 @@ public class DescriptorList extends UuidModel implements Publishable, SelfCleani
@PreUpdate
private void preupdate() {
if (Objects.isNull(firstPublishedDate) && Objects.equals(state, PublishState.PUBLISHED)) {
firstPublishedDate = new Date();
firstPublishedDate = Instant.now();
}
trimStringsToNull();
}
......@@ -387,7 +387,7 @@ public class DescriptorList extends UuidModel implements Publishable, SelfCleani
*
* @return the first published date
*/
public Date getFirstPublishedDate() {
public Instant getFirstPublishedDate() {
return firstPublishedDate;
}
......
......@@ -21,8 +21,8 @@ import static org.springframework.util.StringUtils.*;
import java.io.IOException;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.time.Instant;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
......@@ -529,7 +529,7 @@ class CustomMappingBuilder {
return FieldType.Float;
} else if (Integer.TYPE.equals(clazz) || Integer.class.equals(clazz)) {
return FieldType.Integer;
} else if (Date.class.isAssignableFrom(clazz)) {
} else if (Instant.class.isAssignableFrom(clazz)) {
return FieldType.Date;
} else if (Number.class.isAssignableFrom(clazz)) {
return FieldType.Double;
......
......@@ -15,8 +15,7 @@
*/
package org.genesys2.server.api.v1;
import java.util.Calendar;
import java.util.Date;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;
import java.util.Set;
......@@ -161,7 +160,7 @@ public class KPIController {
@GetMapping(value = "/executions/{name}/run")
public ExecutionRun executionRunByDate(final @PathVariable String name,
@RequestParam(value="date", required = true) @DateTimeFormat(pattern="yyyy-MM-dd") final Date date) {
@RequestParam(value="date", required = true) @DateTimeFormat(pattern="yyyy-MM-dd") final LocalDate date) {
return kpiService.findExecutionRunByDate(kpiService.getExecution(name), date);
}
......@@ -176,8 +175,8 @@ public class KPIController {
@PostMapping(value = "/executions/{name}/diff")
public SortedMap<Date, List<Observation>> executionRuns(final @PathVariable String name, @RequestParam(value="days", required = false) final Integer days, @RequestParam(value="from", required = false) @DateTimeFormat(pattern="yyyy-MM-dd") Date from,
@RequestParam(value="to", required = false) @DateTimeFormat(pattern="yyyy-MM-dd") Date to, @RequestBody(required = false) final Map<String, Set<String>> keys) {
public SortedMap<LocalDate, List<Observation>> executionRuns(final @PathVariable String name, @RequestParam(value="days", required = false) final Integer days, @RequestParam(value="from", required = false) @DateTimeFormat(pattern="yyyy-MM-dd") LocalDate from,
@RequestParam(value="to", required = false) @DateTimeFormat(pattern="yyyy-MM-dd") LocalDate to, @RequestBody(required = false) final Map<String, Set<String>> keys) {
Execution execution = kpiService.getExecution(name);
if (execution == null) {
......@@ -185,14 +184,14 @@ public class KPIController {
}
if (days != null) {
Calendar startDate = Calendar.getInstance();
LocalDate startDate = LocalDate.now();
if (to != null) {
startDate.setTime(to);
startDate = to;
} else {
to = startDate.getTime();
to = startDate;
}
startDate.add(Calendar.DAY_OF_MONTH, -days);
from = startDate.getTime();
startDate = startDate.minusDays(days);
from = startDate;
}
return kpiService.calculateRunDiff(execution, from, to, keys);
......
......@@ -16,8 +16,8 @@
package org.genesys2.server.api.v1;
import java.util.Calendar;
import java.util.Date;
import java.time.LocalDate;
import java.time.ZoneOffset;
import java.util.List;
import java.util.Map;
import java.util.Set;
......@@ -29,7 +29,6 @@ import org.genesys2.server.model.kpi.Observation;
import org.genesys2.server.service.KPIService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.access.prepost.PreAuthorize;
......@@ -75,7 +74,7 @@ public class KPIReadController {
@PostMapping(value="/observations/{executionName}", params = { "date" })
public ArrayNode observations(@PathVariable final String executionName,
@RequestParam(value="date", required = true) @DateTimeFormat(pattern="yyyyMMdd") final Date date,
@RequestParam(value="date", required = true) @DateTimeFormat(pattern="yyyyMMdd") final LocalDate date,
@RequestBody(required = false) final Map<String, Set<String>> keys) {
ArrayNode l = objectMapper.createArrayNode();
......@@ -88,20 +87,20 @@ public class KPIReadController {
@PostMapping(value="/observations/range/{executionName}")
public Page<Object> observations2(@PathVariable final String executionName, @RequestParam(value = "days", required = false) final Integer days,
@RequestParam(value = "from", required = false) @DateTimeFormat(pattern = "yyyyMMdd") Date from,
@RequestParam(value = "to", required = false) @DateTimeFormat(pattern = "yyyyMMdd") Date to, final Pagination pagination, @RequestBody(required = false) final Map<String, Set<String>> keys) {
@RequestParam(value = "from", required = false) @DateTimeFormat(pattern = "yyyyMMdd") LocalDate from,
@RequestParam(value = "to", required = false) @DateTimeFormat(pattern = "yyyyMMdd") LocalDate to, final Pagination pagination, @RequestBody(required = false) final Map<String, Set<String>> keys) {
Execution execution = kpiService.getExecution(executionName);
if (days != null) {
Calendar startDate = Calendar.getInstance();
LocalDate startDate = LocalDate.now();
if (to != null) {
startDate.setTime(to);
startDate = to;
} else {
to = startDate.getTime();
to = startDate;
}
startDate.add(Calendar.DAY_OF_MONTH, -days);
from = startDate.getTime();
startDate = startDate.minusDays(days);
from = startDate;
}
......@@ -111,7 +110,7 @@ public class KPIReadController {
private ObjectNode toMap(Tuple observation) {
ObjectNode m = toMap(observation.get(1, Observation.class));
m.put("timestamp", observation.get(0, Date.class).getTime());
m.put("timestamp", observation.get(0, LocalDate.class).atStartOfDay().toInstant(ZoneOffset.UTC).toEpochMilli());
return m;
}
......
......@@ -18,7 +18,7 @@ package org.genesys2.server.component.listener;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.time.Instant;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map.Entry;
......@@ -110,7 +110,7 @@ public class CreateContentListener extends RunAsAdminListener {
// If nothing is found, parse the resource and create content
if (article == null) {
try {
contentService.createGlobalArticle(slug, locale, entry.getValue().get("title").asText(), null, entry.getValue().get("body").asText(), isTemplate, new Date(), null);
contentService.createGlobalArticle(slug, locale, entry.getValue().get("title").asText(), null, entry.getValue().get("body").asText(), isTemplate, Instant.now(), null);
LOG.warn("Created article for slug: {} lang={}", slug, locale.getLanguage());
} catch (CRMException e) {
LOG.error("Failed to create global article slug={}.", slug, e);
......
......@@ -17,7 +17,7 @@
package org.genesys2.server.model.genesys;
import java.text.MessageFormat;
import java.util.Date;
import java.time.Instant;
import java.util.List;
import java.util.UUID;
......@@ -27,8 +27,6 @@ import javax.persistence.Lob;
import javax.persistence.OneToMany;
import javax.persistence.PrePersist;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
......@@ -76,8 +74,7 @@ public class MaterialRequest extends AuditedVersionedModel {
@JsonProperty(value = "subrequests")
private List<MaterialSubRequest> subRequests;
@Temporal(TemporalType.TIMESTAMP)
private Date lastReminderDate;
private Instant lastReminderDate;
@Column(name = "internal")
private boolean internalRequest = false;
......@@ -152,7 +149,7 @@ public class MaterialRequest extends AuditedVersionedModel {
this.subRequests = subRequests;
}
public Date getLastReminderDate() {
public Instant getLastReminderDate() {
return lastReminderDate;
}
......@@ -164,7 +161,7 @@ public class MaterialRequest extends AuditedVersionedModel {
this.internalRequest = internalRequest;
}
public void setLastReminderDate(Date lastReminderDate) {
public void setLastReminderDate(Instant lastReminderDate) {
this.lastReminderDate = lastReminderDate;
}
}
......@@ -17,7 +17,7 @@
package org.genesys2.server.model.genesys;
import java.text.MessageFormat;
import java.util.Date;
import java.time.Instant;
import java.util.UUID;
import javax.persistence.Column;
......@@ -26,8 +26,6 @@ import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.PrePersist;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.genesys.blocks.model.AuditedVersionedModel;
import org.hibernate.annotations.Type;
......@@ -72,8 +70,7 @@ public class MaterialSubRequest extends AuditedVersionedModel {
@JsonIdentityReference(alwaysAsId = true)
private MaterialRequest sourceRequest;
@Temporal(TemporalType.TIMESTAMP)
private Date lastReminderDate;
private Instant lastReminderDate;
@PrePersist
void prepersist() {
......@@ -133,11 +130,11 @@ public class MaterialSubRequest extends AuditedVersionedModel {
this.sourceRequest = sourceRequest;
}
public Date getLastReminderDate() {
public Instant getLastReminderDate() {
return lastReminderDate;
}
public void setLastReminderDate(Date lastReminderDate) {
public void setLastReminderDate(Instant lastReminderDate) {
this.lastReminderDate = lastReminderDate;
}
......
......@@ -16,8 +16,6 @@
package org.genesys2.server.model.genesys;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
......@@ -26,12 +24,13 @@ import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.genesys2.server.model.impl.FaoInstitute;
import org.springframework.data.annotation.CreatedDate;
import java.time.Instant;
import java.time.LocalDate;
/**
* This is a copy of the SGVS seed samples record. An accession may be deposited to SGSV several times.
*/
......@@ -66,8 +65,7 @@ public class SvalbardDeposit implements AccessionRelated, java.io.Serializable {
private Float quantity;
@Temporal(TemporalType.DATE)
private Date depositDate;
private LocalDate depositDate;
@Column(length = 20)
private String boxNo;
@Column(name = "regen", length = 50)
......@@ -75,7 +73,7 @@ public class SvalbardDeposit implements AccessionRelated, java.io.Serializable {
@CreatedDate
@Column(name = "createdDate")
private Date createdDate;
private Instant createdDate;
public String getAcceNumb() {
return acceNumb;
......@@ -134,11 +132,11 @@ public class SvalbardDeposit implements AccessionRelated, java.io.Serializable {
this.genus = genus;
}
public Date getCreatedDate() {
public Instant getCreatedDate() {
return createdDate;
}
protected void setCreatedDate(Date createdDate) {
protected void setCreatedDate(Instant createdDate) {
this.createdDate = createdDate;
}
......@@ -158,11 +156,11 @@ public class SvalbardDeposit implements AccessionRelated, java.io.Serializable {
this.institute = institute;
}
public Date getDepositDate() {
public LocalDate getDepositDate() {
return depositDate;
}
public void setDepositDate(Date depositDate) {
public void setDepositDate(LocalDate depositDate) {
this.depositDate = depositDate;
}
......
......@@ -15,8 +15,6 @@
*/
package org.genesys2.server.model.grin;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
......@@ -24,6 +22,8 @@ import org.genesys.blocks.model.EmptyModel;
import com.fasterxml.jackson.annotation.JsonIgnore;
import java.time.Instant;
/**
* The Class CooperatorOwnedModel.
*/
......@@ -38,7 +38,7 @@ public abstract class CooperatorOwnedModel extends EmptyModel {
@Column(name = "created_date", nullable = false)
@JsonIgnore
private Date createdDate;
private Instant createdDate;
@Column(name = "owned_by", nullable = false)
@JsonIgnore
......@@ -46,7 +46,7 @@ public abstract class CooperatorOwnedModel extends EmptyModel {
@Column(name = "owned_date", nullable = false)
@JsonIgnore
private Date ownedDate;
private Instant ownedDate;
@Column(name = "modified_by")
@JsonIgnore
......@@ -54,7 +54,7 @@ public abstract class CooperatorOwnedModel extends EmptyModel {
@Column(name = "modified_date")
@JsonIgnore
private Date modifiedDate;
private Instant modifiedDate;
/**
* @return the createdById
......@@ -73,14 +73,14 @@ public abstract class CooperatorOwnedModel extends EmptyModel {
/**
* @return the createdDate
*/
public Date getCreatedDate() {
public Instant getCreatedDate() {
return createdDate;
}
/**
* @param createdDate the createdDate to set
*/
public void setCreatedDate(Date createdDate) {
public void setCreatedDate(Instant createdDate) {
this.createdDate = createdDate;
}
......@@ -101,14 +101,14 @@ public abstract class CooperatorOwnedModel extends EmptyModel {
/**
* @return the ownedDate
*/
public Date getOwnedDate() {
public Instant getOwnedDate() {
return ownedDate;
}
/**
* @param ownedDate the ownedDate to set
*/
public void setOwnedDate(Date ownedDate) {
public void setOwnedDate(Instant ownedDate) {
this.ownedDate = ownedDate;
}
......@@ -129,14 +129,14 @@ public abstract class CooperatorOwnedModel extends EmptyModel {
/**
* @return the modifiedDate
*/
public Date getModifiedDate() {
public Instant getModifiedDate() {
return modifiedDate;
}
/**
* @param modifiedDate the modifiedDate to set
*/
public void setModifiedDate(Date modifiedDate) {
public void setModifiedDate(Instant modifiedDate) {
this.modifiedDate = modifiedDate;
}
}
......@@ -15,8 +15,6 @@
*/
package org.genesys2.server.model.grin;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Cacheable;
import javax.persistence.Column;
......@@ -44,6 +42,8 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import java.time.Instant;
/**
* Auto-generated by:
* org.apache.openjpa.jdbc.meta.ReverseMappingTool$AnnotatedCodeGenerator
......@@ -138,7 +138,7 @@ public class TaxonomySpecies extends CooperatorOwnedModel implements IGrinSpecie
@Basic
@Column(name = "name_verified_date")
private Date nameVerifiedDate;
private Instant nameVerifiedDate;
@Basic
@Column(name = "nomen_number")
......@@ -413,11 +413,11 @@ public class TaxonomySpecies extends CooperatorOwnedModel implements IGrinSpecie
this.nameAuthority = nameAuthority;
}
public Date getNameVerifiedDate() {
public Instant getNameVerifiedDate() {
return nameVerifiedDate;
}
public void setNameVerifiedDate(final Date nameVerifiedDate) {
public void setNameVerifiedDate(final Instant nameVerifiedDate) {
this.nameVerifiedDate = nameVerifiedDate;
}
......
......@@ -18,7 +18,6 @@ package org.genesys2.server.model.impl;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
......@@ -27,8 +26,6 @@ import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
......@@ -67,13 +64,11 @@ public class ActivityPost extends AuditedVersionedModel implements Publishable {
@NotNull
@JsonView({ JsonViews.Public.class })
@Temporal(TemporalType.TIMESTAMP)
@Column(nullable = false)
private Date publishDate;
private Instant publishDate;
@JsonView({ JsonViews.Protected.class })
@Temporal(TemporalType.TIMESTAMP)
private Date expirationDate;
private Instant expirationDate;
@ManyToOne(fetch = FetchType.LAZY, cascade = {})
@JoinColumn(name = "imageId", unique = false)
......@@ -99,19 +94,19 @@ public class ActivityPost extends AuditedVersionedModel implements Publishable {
return this.getCreatedDate();
}
public Date getPublishDate() {
public Instant getPublishDate() {
return publishDate;
}
public void setPublishDate(final Date publishDate) {
public void setPublishDate(final Instant publishDate) {
this.publishDate = publishDate;
}
public Date getExpirationDate() {
public Instant getExpirationDate() {