moved date fields to java.util.Date

This commit is contained in:
Francesco Mangiacrapa 2021-08-04 15:49:31 +02:00
parent 5e0ed38245
commit c40877b589
5 changed files with 152 additions and 30 deletions

View File

@ -22,6 +22,7 @@ import org.gcube.application.geoportalcommon.shared.products.model.AbstractRelaz
import org.gcube.application.geoportalcommon.shared.products.model.LayerConcessioneDV;
import org.gcube.application.geoportalcommon.shared.products.model.RelazioneScavoDV;
import org.gcube.application.geoportalcommon.shared.products.model.UploadedImageDV;
import org.gcube.application.geoportalcommon.util.DateUtils;
import org.gcube.application.geoportalcommon.util.URLParserUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -68,10 +69,10 @@ public class ConvertToDataViewModel {
theConcessione.setCentroidLat(concessione.getCentroidLat());
theConcessione.setCentroidLong(concessione.getCentroidLong());
theConcessione.setContributore(concessione.getContributore());
theConcessione.setCreationTime(toDateFormatString(concessione.getCreationTime()));
theConcessione.setCreationTime(DateUtils.asDate(concessione.getCreationTime()));
theConcessione.setCreationUser(toUser(concessione.getCreationUser()));
theConcessione.setDataFineProgetto(toDateFormatString(concessione.getDataFineProgetto()));
theConcessione.setDataInizioProgetto(toDateFormatString(concessione.getDataInizioProgetto()));
theConcessione.setDataInizioProgetto(DateUtils.asDate(concessione.getDataInizioProgetto()));
theConcessione.setDataFineProgetto(DateUtils.asDate(concessione.getDataFineProgetto()));
theConcessione.setDescrizioneContenuto(concessione.getDescrizioneContenuto());
theConcessione.setEditore(concessione.getEditore());
theConcessione.setFontiFinanziamento(concessione.getFontiFinanziamento());
@ -79,10 +80,9 @@ public class ConvertToDataViewModel {
theConcessione.setNome(concessione.getNome());
theConcessione.setIntroduzione(concessione.getIntroduzione());
theConcessione.setLastUpdateTime(toDateFormatString(concessione.getLastUpdateTime()));
theConcessione.setLastUpdateTime(DateUtils.asDate(concessione.getLastUpdateTime()));
theConcessione.setLastUpdateUser(toUser(concessione.getLastUpdateUser()));
theConcessione.setLicenzaID(concessione.getLicenzaID());
theConcessione.setNome(concessione.getNome());
theConcessione.setParoleChiaveICCD(concessione.getParoleChiaveICCD());
theConcessione.setParoleChiaveLibere(concessione.getParoleChiaveLibere());
@ -144,6 +144,60 @@ public class ConvertToDataViewModel {
}
/**
* To base concessione.
*
* @param concessione the concessione
* @return the concessione DV with core fields
* @throws Exception the exception
*/
public static ConcessioneDV toBaseConcessione(Concessione concessione) throws Exception {
LOG.debug("called toConcessione for: "+concessione);
if (concessione == null)
return null;
try {
ConcessioneDV theConcessione = new ConcessioneDV();
theConcessione.setPolicy(toPolicy(concessione.getPolicy()));
//theConcessione.setAuthors(concessione.getAuthors());
theConcessione.setCentroidLat(concessione.getCentroidLat());
theConcessione.setCentroidLong(concessione.getCentroidLong());
theConcessione.setContributore(concessione.getContributore());
theConcessione.setCreationTime(DateUtils.asDate(concessione.getCreationTime()));
theConcessione.setCreationUser(toUser(concessione.getCreationUser()));
theConcessione.setDataInizioProgetto(DateUtils.asDate(concessione.getDataInizioProgetto()));
theConcessione.setDataFineProgetto(DateUtils.asDate(concessione.getDataFineProgetto()));
theConcessione.setDescrizioneContenuto(concessione.getDescrizioneContenuto());
theConcessione.setEditore(concessione.getEditore());
theConcessione.setFontiFinanziamento(concessione.getFontiFinanziamento());
theConcessione.setItemId(concessione.getMongo_id());
theConcessione.setNome(concessione.getNome());
theConcessione.setIntroduzione(concessione.getIntroduzione());
theConcessione.setLastUpdateTime(DateUtils.asDate(concessione.getLastUpdateTime()));
theConcessione.setLastUpdateUser(toUser(concessione.getLastUpdateUser()));
theConcessione.setLicenzaID(concessione.getLicenzaID());
theConcessione.setParoleChiaveICCD(concessione.getParoleChiaveICCD());
theConcessione.setParoleChiaveLibere(concessione.getParoleChiaveLibere());
theConcessione.setResponsabile(concessione.getResponsabile());
theConcessione.setTitolariCopyright(concessione.getTitolareCopyright());
theConcessione.setTitolariLicenza(concessione.getTitolareLicenza());
theConcessione.setTitolari(concessione.getTitolari());
LOG.debug("Returning base concessione: " + theConcessione);
return theConcessione;
}catch (Exception e) {
LOG.error("Error on converting concessione: "+concessione, e);
return null;
}
}
//TO AVOID SERIALIZATION ISSUE AGAINST GWT
// public static List<String> toListString(List<String> orginList){
// if(orginList==null)
@ -236,7 +290,7 @@ public class ConvertToDataViewModel {
theRelazioneDiScavo.setAbstractSectionIta(relazioneScavo.getAbstractIta());
theRelazioneDiScavo.setAbstractSectionEng(relazioneScavo.getAbstractEng());
theRelazioneDiScavo.setCreationTime(toDateFormatString(relazioneScavo.getCreationTime()));
theRelazioneDiScavo.setCreationTime(DateUtils.asDate(relazioneScavo.getCreationTime()));
theRelazioneDiScavo.setId(relazioneScavo.getId());
theRelazioneDiScavo.setLicenseID(relazioneScavo.getLicenseID());
theRelazioneDiScavo.setPolicy(toPolicy(relazioneScavo.getPolicy()));
@ -261,7 +315,7 @@ public class ConvertToDataViewModel {
return null;
RelazioneScavoDV theRelazioneDiScavo = new RelazioneScavoDV();
theRelazioneDiScavo.setCreationTime(toDateFormatString(relazioneScavo.getCreationTime()));
theRelazioneDiScavo.setCreationTime(DateUtils.asDate(relazioneScavo.getCreationTime()));
theRelazioneDiScavo.setId(relazioneScavo.getId());
theRelazioneDiScavo.setLicenseID(relazioneScavo.getLicenseID());
theRelazioneDiScavo.setPolicy(toPolicy(relazioneScavo.getPolicy()));
@ -298,7 +352,7 @@ public class ConvertToDataViewModel {
return null;
UploadedImageDV theUploadedImageDV = new UploadedImageDV();
theUploadedImageDV.setCreationTime(toDateFormatString(uploadedImage.getCreationTime()));
theUploadedImageDV.setCreationTime(DateUtils.asDate(uploadedImage.getCreationTime()));
theUploadedImageDV.setDidascalia(uploadedImage.getDidascalia());
theUploadedImageDV.setFormat(uploadedImage.getFormat());
theUploadedImageDV.setId(uploadedImage.getId());
@ -389,7 +443,7 @@ public class ConvertToDataViewModel {
bounds = toBoundMap(layerConcessione.getBbox());
theLayerConessione.setBbox(bounds);
theLayerConessione.setCreationTime(toDateFormatString(layerConcessione.getCreationTime()));
theLayerConessione.setCreationTime(DateUtils.asDate(layerConcessione.getCreationTime()));
theLayerConessione.setId(layerConcessione.getId());
theLayerConessione.setLicenseID(layerConcessione.getLicenseID());
theLayerConessione.setMetodoRaccoltaDati(layerConcessione.getMetodoRaccoltaDati());
@ -419,7 +473,7 @@ public class ConvertToDataViewModel {
return null;
OtherContentDV theOtherContent = new OtherContentDV();
theOtherContent.setCreationTime(toDateFormatString(otherContent.getCreationTime()));
theOtherContent.setCreationTime(DateUtils.asDate(otherContent.getCreationTime()));
theOtherContent.setId(otherContent.getId());
theOtherContent.setLicenseID(otherContent.getLicenseID());
theOtherContent.setPolicy(toPolicy(otherContent.getPolicy()));

View File

@ -2,6 +2,7 @@ package org.gcube.application.geoportalcommon.shared.products;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.gcube.application.geoportalcommon.shared.products.content.OtherContentDV;
@ -56,10 +57,10 @@ public class ConcessioneDV extends RecordDV implements Serializable {
private List<String> risorseCorrelate;
/** The data inizio progetto. */
private String dataInizioProgetto;
private Date dataInizioProgetto;
/** The data fine progetto. */
private String dataFineProgetto;
private Date dataFineProgetto;
/** The titolare licenza. */
private List<String> titolariLicenza;
@ -289,7 +290,7 @@ public class ConcessioneDV extends RecordDV implements Serializable {
*
* @return the data inizio progetto
*/
public String getDataInizioProgetto() {
public Date getDataInizioProgetto() {
return dataInizioProgetto;
}
@ -298,7 +299,7 @@ public class ConcessioneDV extends RecordDV implements Serializable {
*
* @param dataInizioProgetto the new data inizio progetto
*/
public void setDataInizioProgetto(String dataInizioProgetto) {
public void setDataInizioProgetto(Date dataInizioProgetto) {
this.dataInizioProgetto = dataInizioProgetto;
}
@ -307,17 +308,17 @@ public class ConcessioneDV extends RecordDV implements Serializable {
*
* @return the data fine progetto
*/
public String getDataFineProgetto() {
public Date getDataFineProgetto() {
return dataFineProgetto;
}
/**
* Sets the data fine progetto.
*
* @param dataFineProgetto the new data fine progetto
* @param date the new data fine progetto
*/
public void setDataFineProgetto(String dataFineProgetto) {
this.dataFineProgetto = dataFineProgetto;
public void setDataFineProgetto(Date date) {
this.dataFineProgetto = date;
}
/**

View File

@ -1,6 +1,7 @@
package org.gcube.application.geoportalcommon.shared.products.content;
import java.io.Serializable;
import java.util.Date;
import org.gcube.application.geoportalcommon.shared.products.model.RecordDV;
@ -32,7 +33,7 @@ public abstract class AssociatedContentDV implements Serializable{
private String titolo;
/** The creation time. */
private String creationTime;
private Date creationTime;
/** The record. */
private RecordDV record;
@ -54,7 +55,7 @@ public abstract class AssociatedContentDV implements Serializable{
* @param creationTime the creation time
* @param record the record
*/
public AssociatedContentDV(long id, String policy, String licenseID, String titolo, String creationTime,
public AssociatedContentDV(long id, String policy, String licenseID, String titolo, Date creationTime,
RecordDV record) {
super();
this.id = id;
@ -142,7 +143,7 @@ public abstract class AssociatedContentDV implements Serializable{
*
* @return the creation time
*/
public String getCreationTime() {
public Date getCreationTime() {
return creationTime;
}
@ -151,7 +152,7 @@ public abstract class AssociatedContentDV implements Serializable{
*
* @param creationTime the new creation time
*/
public void setCreationTime(String creationTime) {
public void setCreationTime(Date creationTime) {
this.creationTime = creationTime;
}

View File

@ -1,6 +1,7 @@
package org.gcube.application.geoportalcommon.shared.products.model;
import java.io.Serializable;
import java.util.Date;
/**
@ -42,13 +43,13 @@ public abstract class RecordDV implements Serializable {
/** The last update time. */
// Accounting
private String lastUpdateTime;
private Date lastUpdateTime;
/** The last update user. */
private String lastUpdateUser;
/** The creation time. */
private String creationTime;
private Date creationTime;
/** The creation user. */
private String creationUser;
@ -191,17 +192,17 @@ public abstract class RecordDV implements Serializable {
*
* @return the last update time
*/
public String getLastUpdateTime() {
public Date getLastUpdateTime() {
return lastUpdateTime;
}
/**
* Sets the last update time.
*
* @param lastUpdateTime the new last update time
* @param date the new last update time
*/
public void setLastUpdateTime(String lastUpdateTime) {
this.lastUpdateTime = lastUpdateTime;
public void setLastUpdateTime(Date date) {
this.lastUpdateTime = date;
}
/**
@ -227,7 +228,7 @@ public abstract class RecordDV implements Serializable {
*
* @return the creation time
*/
public String getCreationTime() {
public Date getCreationTime() {
return creationTime;
}
@ -236,7 +237,7 @@ public abstract class RecordDV implements Serializable {
*
* @param creationTime the new creation time
*/
public void setCreationTime(String creationTime) {
public void setCreationTime(Date creationTime) {
this.creationTime = creationTime;
}

View File

@ -0,0 +1,65 @@
package org.gcube.application.geoportalcommon.util;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
/**
* The Class DateUtils.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Aug 4, 2021
*/
public class DateUtils {
/**
* As date.
*
* @param localDate the local date
* @return the date
*/
public static Date asDate(LocalDate localDate) {
if (localDate == null)
return null;
return Date.from(localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
}
/**
* As date.
*
* @param localDateTime the local date time
* @return the date
*/
public static Date asDate(LocalDateTime localDateTime) {
if (localDateTime == null)
return null;
return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
}
/**
* As local date.
*
* @param date the date
* @return the local date
*/
public static LocalDate asLocalDate(Date date) {
if (date == null)
return null;
return Instant.ofEpochMilli(date.getTime()).atZone(ZoneId.systemDefault()).toLocalDate();
}
/**
* As local date time.
*
* @param date the date
* @return the local date time
*/
public static LocalDateTime asLocalDateTime(Date date) {
if (date == null)
return null;
return Instant.ofEpochMilli(date.getTime()).atZone(ZoneId.systemDefault()).toLocalDateTime();
}
}