346 lines
12 KiB
Java
346 lines
12 KiB
Java
package org.gcube.portlets.user.geoportaldataviewer.server;
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.format.DateTimeFormatterBuilder;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import org.gcube.application.geoportal.model.AccessPolicy;
|
|
import org.gcube.application.geoportal.model.concessioni.Concessione;
|
|
import org.gcube.application.geoportal.model.concessioni.LayerConcessione;
|
|
import org.gcube.application.geoportal.model.concessioni.RelazioneScavo;
|
|
import org.gcube.application.geoportal.model.content.OtherContent;
|
|
import org.gcube.application.geoportal.model.content.PersistedContent;
|
|
import org.gcube.application.geoportal.model.content.UploadedImage;
|
|
import org.gcube.application.geoportal.model.content.WorkspaceContent;
|
|
import org.gcube.application.geoportal.model.gis.BBOX;
|
|
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;
|
|
import org.gcube.portlets.user.geoportaldataviewer.shared.products.content.WorkspaceContentDV;
|
|
import org.gcube.portlets.user.geoportaldataviewer.shared.products.model.LayerConcessioneDV;
|
|
import org.gcube.portlets.user.geoportaldataviewer.shared.products.model.RelazioneScavoDV;
|
|
import org.gcube.portlets.user.geoportaldataviewer.shared.products.model.UploadedImageDV;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
/**
|
|
* The Class ConvertToGUIModel.
|
|
*
|
|
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
|
*
|
|
* Nov 2, 2020
|
|
*/
|
|
public class ConvertToDataViewModel {
|
|
|
|
/** 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 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.
|
|
*
|
|
* @param concessione the concessione
|
|
* @return the concessione
|
|
* @throws Exception the exception
|
|
*/
|
|
public static ConcessioneDV toConcessione(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(toDateString(concessione.getCreationTime()));
|
|
theConcessione.setCreationUser(toUser(concessione.getCreationUser()));
|
|
theConcessione.setDataFineProgetto(toDateString(concessione.getDataFineProgetto()));
|
|
theConcessione.setDataInizioProgetto(toDateString(concessione.getDataInizioProgetto()));
|
|
theConcessione.setDescrizioneContenuto(concessione.getDescrizioneContenuto());
|
|
theConcessione.setEditore(concessione.getEditore());
|
|
theConcessione.setFontiFinanziamento(toListString(concessione.getFontiFinanziamento()));
|
|
theConcessione.setId(concessione.getId());
|
|
theConcessione.setNome(concessione.getNome());
|
|
|
|
theConcessione.setIntroduzione(concessione.getIntroduzione());
|
|
theConcessione.setLastUpdateTime(toDateString(concessione.getLastUpdateTime()));
|
|
theConcessione.setLastUpdateUser(toUser(concessione.getLastUpdateUser()));
|
|
theConcessione.setLicenzaID(concessione.getLicenzaID());
|
|
theConcessione.setNome(concessione.getNome());
|
|
theConcessione.setParoleChiaveICCD(concessione.getParoleChiaveICCD());
|
|
theConcessione.setParoleChiaveLibere(concessione.getParoleChiaveLibere());
|
|
|
|
theConcessione.setResponsabile(concessione.getResponsabile());
|
|
theConcessione.setRisorseCorrelate(concessione.getRisorseCorrelate());
|
|
theConcessione.setSoggetto(concessione.getSoggetto());
|
|
theConcessione.setTitolareCopyright(concessione.getTitolareCopyright());
|
|
theConcessione.setTitolareLicenza(concessione.getTitolareLicenza());
|
|
theConcessione.setTitolari(concessione.getTitolari());
|
|
theConcessione.setVersion(concessione.getVersion());
|
|
|
|
theConcessione.setRecordType(concessione.getRecordType().name());
|
|
|
|
theConcessione.setRelazioneScavo(toRelazioneScavo(concessione.getRelazioneScavo()));
|
|
|
|
|
|
if (concessione.getImmaginiRappresentative() != null) {
|
|
List<UploadedImageDV> uploadedImagesDV = new ArrayList<UploadedImageDV>(
|
|
concessione.getImmaginiRappresentative().size());
|
|
for (UploadedImage ui : concessione.getImmaginiRappresentative()) {
|
|
uploadedImagesDV.add(toUploadedImage(ui));
|
|
}
|
|
theConcessione.setImmaginiRappresentative(uploadedImagesDV);
|
|
}
|
|
|
|
|
|
if (concessione.getGenericContent() != null) {
|
|
List<OtherContentDV> otherContentsDV = new ArrayList<OtherContentDV>(
|
|
concessione.getGenericContent().size());
|
|
for (OtherContent gc : concessione.getGenericContent()) {
|
|
otherContentsDV.add(toOtherContentDV(gc));
|
|
}
|
|
theConcessione.setGenericContent(otherContentsDV);
|
|
}
|
|
|
|
|
|
if (concessione.getPianteFineScavo() != null) {
|
|
List<LayerConcessioneDV> piantaScavoDV = new ArrayList<LayerConcessioneDV>(
|
|
concessione.getPianteFineScavo().size());
|
|
for (LayerConcessione lc : concessione.getPianteFineScavo()) {
|
|
piantaScavoDV.add(toLayerConcessione(lc));
|
|
}
|
|
theConcessione.setPianteFineScavo(piantaScavoDV);
|
|
}
|
|
|
|
if (concessione.getPosizionamentoScavo() != null) {
|
|
LayerConcessioneDV thePosizScavo = toLayerConcessione(concessione.getPosizionamentoScavo());
|
|
theConcessione.setPosizionamentoScavo(thePosizScavo);
|
|
}
|
|
|
|
|
|
LOG.debug("Returning 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)
|
|
return null;
|
|
|
|
List<String> destList = new ArrayList<String>(orginList.size());
|
|
for (String orgValue : orginList) {
|
|
destList.add(orgValue);
|
|
}
|
|
|
|
return destList;
|
|
}
|
|
|
|
public static String toUser(String username) {
|
|
|
|
if(username==null)
|
|
return null;
|
|
|
|
return username;
|
|
|
|
}
|
|
|
|
public static String toPolicy(AccessPolicy policy) {
|
|
|
|
if(policy==null)
|
|
return null;
|
|
|
|
return policy.name();
|
|
|
|
}
|
|
|
|
public static String toDateString(LocalDateTime dateTime) {
|
|
|
|
if(dateTime==null)
|
|
return null;
|
|
|
|
return dateTime.toString();
|
|
}
|
|
|
|
/**
|
|
* To relazione scavo.
|
|
*
|
|
* @param relazioneScavo the relazione scavo
|
|
* @param recordDV the record data view
|
|
* @return the relazione scavo data view
|
|
*/
|
|
public static RelazioneScavoDV toRelazioneScavo(RelazioneScavo relazioneScavo) {
|
|
|
|
if (relazioneScavo == null)
|
|
return null;
|
|
|
|
RelazioneScavoDV theRelazioneDiScavo = new RelazioneScavoDV();
|
|
theRelazioneDiScavo.setAbstractSection(relazioneScavo.getAbstractSection());
|
|
theRelazioneDiScavo.setCreationTime(toDateString(relazioneScavo.getCreationTime()));
|
|
theRelazioneDiScavo.setId(relazioneScavo.getId());
|
|
theRelazioneDiScavo.setLicenseID(relazioneScavo.getLicenseID());
|
|
theRelazioneDiScavo.setPolicy(toPolicy(relazioneScavo.getPolicy()));
|
|
//theRelazioneDiScavo.setRecord(recordDV);
|
|
theRelazioneDiScavo.setResponsabili(relazioneScavo.getResponsabili());
|
|
theRelazioneDiScavo.setSoggetto(relazioneScavo.getSoggetto());
|
|
theRelazioneDiScavo.setTitolo(relazioneScavo.getTitolo());
|
|
|
|
LOG.debug("Returning: " + theRelazioneDiScavo);
|
|
return theRelazioneDiScavo;
|
|
}
|
|
|
|
/**
|
|
* To uploaded image.
|
|
*
|
|
* @param uploadedImage the uploaded image
|
|
* @param recordDV the record data-view
|
|
* @return the uploaded image data-view
|
|
*/
|
|
public static UploadedImageDV toUploadedImage(UploadedImage uploadedImage) {
|
|
|
|
if (uploadedImage == null)
|
|
return null;
|
|
|
|
UploadedImageDV theUploadedImageDV = new UploadedImageDV();
|
|
theUploadedImageDV.setCreationTime(toDateString(uploadedImage.getCreationTime()));
|
|
theUploadedImageDV.setDidascalia(uploadedImage.getDidascalia());
|
|
theUploadedImageDV.setFormat(uploadedImage.getFormat());
|
|
theUploadedImageDV.setId(uploadedImage.getId());
|
|
theUploadedImageDV.setLicenseID(uploadedImage.getLicenseID());
|
|
theUploadedImageDV.setPolicy(toPolicy(uploadedImage.getPolicy()));
|
|
//theUploadedImageDV.setRecord(recordDV);
|
|
theUploadedImageDV.setResponsabili(uploadedImage.getResponsabili());
|
|
theUploadedImageDV.setSoggetto(uploadedImage.getSoggetto());
|
|
theUploadedImageDV.setTitolo(uploadedImage.getTitolo());
|
|
|
|
List<PersistedContent> actContent = uploadedImage.getActualContent();
|
|
if(actContent!=null && actContent.size()>0) {
|
|
List<WorkspaceContentDV> listWsContent = new ArrayList<WorkspaceContentDV>();
|
|
|
|
for (PersistedContent content : actContent) {
|
|
if(content!=null && content instanceof WorkspaceContent) {
|
|
listWsContent.add(toWorkspaceContent((WorkspaceContent)content));
|
|
}
|
|
}
|
|
theUploadedImageDV.setListWsContent(listWsContent);
|
|
}
|
|
|
|
LOG.debug("Returning: " + theUploadedImageDV);
|
|
return theUploadedImageDV;
|
|
}
|
|
|
|
|
|
/**
|
|
* To workspace content.
|
|
*
|
|
* @param wContent the w content
|
|
* @return the workspace content DV
|
|
*/
|
|
public static WorkspaceContentDV toWorkspaceContent(WorkspaceContent wContent){
|
|
if (wContent == null)
|
|
return null;
|
|
|
|
WorkspaceContentDV theWSDV = new WorkspaceContentDV();
|
|
theWSDV.setLink(wContent.getLink());
|
|
theWSDV.setMimetype(wContent.getMimetype());
|
|
theWSDV.setStorageID(wContent.getStorageID());
|
|
theWSDV.setId(wContent.getId());
|
|
|
|
return theWSDV;
|
|
}
|
|
|
|
/**
|
|
* To layer concessione.
|
|
*
|
|
* @param layerConcessione the layer concessione
|
|
* @param recordDV the record DV
|
|
* @return the layer concessione data view
|
|
*/
|
|
public static LayerConcessioneDV toLayerConcessione(LayerConcessione layerConcessione) {
|
|
|
|
if (layerConcessione == null)
|
|
return null;
|
|
|
|
LayerConcessioneDV theLayerConessione = new LayerConcessioneDV();
|
|
theLayerConessione.setAbstractSection(layerConcessione.getAbstractSection());
|
|
theLayerConessione.setLayerName(layerConcessione.getLayerName());
|
|
theLayerConessione.setLayerID(layerConcessione.getLayerID());
|
|
theLayerConessione.setLayerUUID(layerConcessione.getLayerUUID());
|
|
theLayerConessione.setAuthors(layerConcessione.getAuthors());
|
|
BoundsMap bounds = toBoundMap(layerConcessione.getBbox());
|
|
theLayerConessione.setBbox(bounds);
|
|
theLayerConessione.setCreationTime(toDateString(layerConcessione.getCreationTime()));
|
|
theLayerConessione.setId(layerConcessione.getId());
|
|
theLayerConessione.setLicenseID(layerConcessione.getLicenseID());
|
|
theLayerConessione.setMetodoRaccoltaDati(layerConcessione.getMetodoRaccoltaDati());
|
|
theLayerConessione.setPolicy(toPolicy(layerConcessione.getPolicy()));
|
|
//theLayerConessione.setRecord(recordDV);
|
|
theLayerConessione.setScalaAcquisizione(layerConcessione.getScalaAcquisizione());
|
|
theLayerConessione.setSubTopic(layerConcessione.getSubTopic());
|
|
theLayerConessione.setTitolo(layerConcessione.getTitolo());
|
|
theLayerConessione.setTopicCategory(layerConcessione.getTopicCategory());
|
|
theLayerConessione.setValutazioneQualita(layerConcessione.getValutazioneQualita());
|
|
theLayerConessione.setWmsLink(layerConcessione.getWmsLink());
|
|
|
|
LOG.debug("Returning: " + theLayerConessione);
|
|
return theLayerConessione;
|
|
|
|
}
|
|
|
|
/**
|
|
* To other content DV.
|
|
*
|
|
* @param otherContent the other content
|
|
* @param recordDV the record DV
|
|
* @return the other content DV
|
|
*/
|
|
public static OtherContentDV toOtherContentDV(OtherContent otherContent) {
|
|
|
|
if (otherContent == null)
|
|
return null;
|
|
|
|
OtherContentDV theOtherContent = new OtherContentDV();
|
|
theOtherContent.setCreationTime(toDateString(otherContent.getCreationTime()));
|
|
theOtherContent.setId(otherContent.getId());
|
|
theOtherContent.setLicenseID(otherContent.getLicenseID());
|
|
theOtherContent.setPolicy(toPolicy(otherContent.getPolicy()));
|
|
//theOtherContent.setRecord(recordDV);
|
|
theOtherContent.setTitolo(otherContent.getTitolo());
|
|
|
|
return theOtherContent;
|
|
}
|
|
|
|
/**
|
|
* To bound map.
|
|
*
|
|
* @param bbox the bbox
|
|
* @return the bounds map
|
|
*/
|
|
public static BoundsMap toBoundMap(BBOX bbox) {
|
|
|
|
if (bbox == null)
|
|
return null;
|
|
|
|
return new BoundsMap(bbox.getMinLong(), bbox.getMinLat(), bbox.getMaxLong(), bbox.getMaxLat(), null);
|
|
}
|
|
|
|
}
|