|
|
|
@ -1,7 +1,7 @@
|
|
|
|
|
package org.gcube.portlets.user.geoportaldataviewer.server;
|
|
|
|
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.time.format.DateTimeFormatterBuilder;
|
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
@ -14,6 +14,7 @@ import org.gcube.application.geoportal.common.model.legacy.PersistedContent;
|
|
|
|
|
import org.gcube.application.geoportal.common.model.legacy.RelazioneScavo;
|
|
|
|
|
import org.gcube.application.geoportal.common.model.legacy.UploadedImage;
|
|
|
|
|
import org.gcube.application.geoportal.common.model.legacy.WorkspaceContent;
|
|
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.server.util.URLParserUtil;
|
|
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.BoundsMap;
|
|
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.shared.products.ConcessioneDV;
|
|
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.shared.products.content.OtherContentDV;
|
|
|
|
@ -33,17 +34,17 @@ import org.slf4j.LoggerFactory;
|
|
|
|
|
*/
|
|
|
|
|
public class ConvertToDataViewModel {
|
|
|
|
|
|
|
|
|
|
private static final String NO_TIME = "T00:00";
|
|
|
|
|
|
|
|
|
|
/** The Constant LOG. */
|
|
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(ConvertToDataViewModel.class);
|
|
|
|
|
|
|
|
|
|
public static final String DATE_FORMAT = "yyyy-MM-dd";
|
|
|
|
|
public static final String DATE_FORMAT = "dd-MM-yyyy";
|
|
|
|
|
|
|
|
|
|
public static final String HOURS_MINUTES_SEPARATOR = ":";
|
|
|
|
|
|
|
|
|
|
public static final String TIME_FORMAT = "HH" + HOURS_MINUTES_SEPARATOR + "mm";
|
|
|
|
|
|
|
|
|
|
public static final DateTimeFormatterBuilder dtf = new DateTimeFormatterBuilder()
|
|
|
|
|
.appendPattern(DATE_FORMAT + " " + TIME_FORMAT);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* To concessione.
|
|
|
|
@ -66,10 +67,10 @@ public class ConvertToDataViewModel {
|
|
|
|
|
theConcessione.setCentroidLat(concessione.getCentroidLat());
|
|
|
|
|
theConcessione.setCentroidLong(concessione.getCentroidLong());
|
|
|
|
|
theConcessione.setContributore(concessione.getContributore());
|
|
|
|
|
theConcessione.setCreationTime(toDateString(concessione.getCreationTime()));
|
|
|
|
|
theConcessione.setCreationTime(toDateFormatString(concessione.getCreationTime()));
|
|
|
|
|
theConcessione.setCreationUser(toUser(concessione.getCreationUser()));
|
|
|
|
|
theConcessione.setDataFineProgetto(toDateString(concessione.getDataFineProgetto()));
|
|
|
|
|
theConcessione.setDataInizioProgetto(toDateString(concessione.getDataInizioProgetto()));
|
|
|
|
|
theConcessione.setDataFineProgetto(toDateFormatString(concessione.getDataFineProgetto()));
|
|
|
|
|
theConcessione.setDataInizioProgetto(toDateFormatString(concessione.getDataInizioProgetto()));
|
|
|
|
|
theConcessione.setDescrizioneContenuto(concessione.getDescrizioneContenuto());
|
|
|
|
|
theConcessione.setEditore(concessione.getEditore());
|
|
|
|
|
theConcessione.setFontiFinanziamento(concessione.getFontiFinanziamento());
|
|
|
|
@ -77,7 +78,7 @@ public class ConvertToDataViewModel {
|
|
|
|
|
theConcessione.setNome(concessione.getNome());
|
|
|
|
|
|
|
|
|
|
theConcessione.setIntroduzione(concessione.getIntroduzione());
|
|
|
|
|
theConcessione.setLastUpdateTime(toDateString(concessione.getLastUpdateTime()));
|
|
|
|
|
theConcessione.setLastUpdateTime(toDateFormatString(concessione.getLastUpdateTime()));
|
|
|
|
|
theConcessione.setLastUpdateUser(toUser(concessione.getLastUpdateUser()));
|
|
|
|
|
theConcessione.setLicenzaID(concessione.getLicenzaID());
|
|
|
|
|
theConcessione.setNome(concessione.getNome());
|
|
|
|
@ -172,11 +173,31 @@ public class ConvertToDataViewModel {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String toDateString(LocalDateTime dateTime) {
|
|
|
|
|
public static String toDateFormatString(LocalDateTime dateTime) {
|
|
|
|
|
|
|
|
|
|
if(dateTime==null)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
String time = dateTime.toString();
|
|
|
|
|
DateTimeFormatter formatter = null;
|
|
|
|
|
try {
|
|
|
|
|
if(!time.endsWith(NO_TIME)) {
|
|
|
|
|
formatter = DateTimeFormatter.ofPattern(DATE_FORMAT + " " + TIME_FORMAT);
|
|
|
|
|
}else {
|
|
|
|
|
time = time.replace(NO_TIME, "");
|
|
|
|
|
formatter = DateTimeFormatter.ofPattern(DATE_FORMAT);
|
|
|
|
|
}
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
|
LOG.warn("Parsing error: ",e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if(formatter!=null)
|
|
|
|
|
return dateTime.format(formatter);
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
|
LOG.warn("Date format error: ",e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dateTime.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -194,7 +215,7 @@ public class ConvertToDataViewModel {
|
|
|
|
|
|
|
|
|
|
RelazioneScavoDV theRelazioneDiScavo = new RelazioneScavoDV();
|
|
|
|
|
theRelazioneDiScavo.setAbstractSection(relazioneScavo.getAbstractSection());
|
|
|
|
|
theRelazioneDiScavo.setCreationTime(toDateString(relazioneScavo.getCreationTime()));
|
|
|
|
|
theRelazioneDiScavo.setCreationTime(toDateFormatString(relazioneScavo.getCreationTime()));
|
|
|
|
|
theRelazioneDiScavo.setId(relazioneScavo.getId());
|
|
|
|
|
theRelazioneDiScavo.setLicenseID(relazioneScavo.getLicenseID());
|
|
|
|
|
theRelazioneDiScavo.setPolicy(toPolicy(relazioneScavo.getPolicy()));
|
|
|
|
@ -220,7 +241,7 @@ public class ConvertToDataViewModel {
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
UploadedImageDV theUploadedImageDV = new UploadedImageDV();
|
|
|
|
|
theUploadedImageDV.setCreationTime(toDateString(uploadedImage.getCreationTime()));
|
|
|
|
|
theUploadedImageDV.setCreationTime(toDateFormatString(uploadedImage.getCreationTime()));
|
|
|
|
|
theUploadedImageDV.setDidascalia(uploadedImage.getDidascalia());
|
|
|
|
|
theUploadedImageDV.setFormat(uploadedImage.getFormat());
|
|
|
|
|
theUploadedImageDV.setId(uploadedImage.getId());
|
|
|
|
@ -279,15 +300,40 @@ public class ConvertToDataViewModel {
|
|
|
|
|
if (layerConcessione == null)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
LOG.debug("Converting: "+layerConcessione);
|
|
|
|
|
LayerConcessioneDV theLayerConessione = new LayerConcessioneDV();
|
|
|
|
|
theLayerConessione.setAbstractSection(layerConcessione.getAbstractSection());
|
|
|
|
|
theLayerConessione.setLayerName(layerConcessione.getLayerName());
|
|
|
|
|
|
|
|
|
|
String wmsLink = layerConcessione.getWmsLink();
|
|
|
|
|
String layerName = null;
|
|
|
|
|
BoundsMap bounds = null;
|
|
|
|
|
|
|
|
|
|
//reading layer name from wmsLink
|
|
|
|
|
//string bbox
|
|
|
|
|
if(wmsLink!=null) {
|
|
|
|
|
layerName = URLParserUtil.extractValueOfParameterFromURL("layers", wmsLink);
|
|
|
|
|
String bbox = URLParserUtil.extractValueOfParameterFromURL("bbox", wmsLink);
|
|
|
|
|
String wmsVersion = URLParserUtil.extractValueOfParameterFromURL("version", wmsLink);
|
|
|
|
|
bounds = toBoundMap(wmsVersion, bbox, ",");
|
|
|
|
|
LOG.debug("Built bounds from wmsLInk: "+bounds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(layerName!=null)
|
|
|
|
|
theLayerConessione.setLayerName(layerName);
|
|
|
|
|
else
|
|
|
|
|
theLayerConessione.setLayerName(layerConcessione.getLayerName());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
theLayerConessione.setWmsLink(wmsLink);
|
|
|
|
|
theLayerConessione.setLayerID(layerConcessione.getLayerID());
|
|
|
|
|
theLayerConessione.setLayerUUID(layerConcessione.getLayerUUID());
|
|
|
|
|
theLayerConessione.setAuthors(layerConcessione.getAuthors());
|
|
|
|
|
BoundsMap bounds = toBoundMap(layerConcessione.getBbox());
|
|
|
|
|
|
|
|
|
|
if(bounds==null)
|
|
|
|
|
bounds = toBoundMap(layerConcessione.getBbox());
|
|
|
|
|
|
|
|
|
|
theLayerConessione.setBbox(bounds);
|
|
|
|
|
theLayerConessione.setCreationTime(toDateString(layerConcessione.getCreationTime()));
|
|
|
|
|
theLayerConessione.setCreationTime(toDateFormatString(layerConcessione.getCreationTime()));
|
|
|
|
|
theLayerConessione.setId(layerConcessione.getId());
|
|
|
|
|
theLayerConessione.setLicenseID(layerConcessione.getLicenseID());
|
|
|
|
|
theLayerConessione.setMetodoRaccoltaDati(layerConcessione.getMetodoRaccoltaDati());
|
|
|
|
@ -298,7 +344,7 @@ public class ConvertToDataViewModel {
|
|
|
|
|
theLayerConessione.setTitolo(layerConcessione.getTitolo());
|
|
|
|
|
theLayerConessione.setTopicCategory(layerConcessione.getTopicCategory());
|
|
|
|
|
theLayerConessione.setValutazioneQualita(layerConcessione.getValutazioneQualita());
|
|
|
|
|
theLayerConessione.setWmsLink(layerConcessione.getWmsLink());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LOG.debug("Returning: " + theLayerConessione);
|
|
|
|
|
return theLayerConessione;
|
|
|
|
@ -318,7 +364,7 @@ public class ConvertToDataViewModel {
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
OtherContentDV theOtherContent = new OtherContentDV();
|
|
|
|
|
theOtherContent.setCreationTime(toDateString(otherContent.getCreationTime()));
|
|
|
|
|
theOtherContent.setCreationTime(toDateFormatString(otherContent.getCreationTime()));
|
|
|
|
|
theOtherContent.setId(otherContent.getId());
|
|
|
|
|
theOtherContent.setLicenseID(otherContent.getLicenseID());
|
|
|
|
|
theOtherContent.setPolicy(toPolicy(otherContent.getPolicy()));
|
|
|
|
@ -341,5 +387,50 @@ public class ConvertToDataViewModel {
|
|
|
|
|
|
|
|
|
|
return new BoundsMap(bbox.getMinLong(), bbox.getMinLat(), bbox.getMaxLong(), bbox.getMaxLat(), null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* To bound map.
|
|
|
|
|
*
|
|
|
|
|
* @param bbox the bbox
|
|
|
|
|
* @return the bounds map
|
|
|
|
|
*/
|
|
|
|
|
public static BoundsMap toBoundMap(String wmsVersion, String bbox, String separator) {
|
|
|
|
|
|
|
|
|
|
if (bbox == null)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
if(wmsVersion==null)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
if(separator==null)
|
|
|
|
|
separator = ",";
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
String[] bboxArr = bbox.split(separator);
|
|
|
|
|
|
|
|
|
|
if(wmsVersion.startsWith("1.3")) {
|
|
|
|
|
//is 1.3.x
|
|
|
|
|
return new BoundsMap(toDouble(bboxArr[1]), toDouble(bboxArr[0]), toDouble(bboxArr[3]), toDouble(bboxArr[2]), wmsVersion);
|
|
|
|
|
}else {
|
|
|
|
|
//should be 1.1.X
|
|
|
|
|
return new BoundsMap(toDouble(bboxArr[0]), toDouble(bboxArr[1]), toDouble(bboxArr[2]), toDouble(bboxArr[3]), wmsVersion);
|
|
|
|
|
}
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
|
LOG.warn("Error on creating Bounds for wmsVersion "+wmsVersion+" and bbox "+bbox+" : ",e);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Double toDouble(String value) {
|
|
|
|
|
try {
|
|
|
|
|
return Double.parseDouble(value);
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
|
LOG.warn("Error on parsing "+value+" as double: ",e);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|