geoportal-data-viewer-app/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/ConvertToDataViewModel.java

247 lines
9.9 KiB
Java
Raw Normal View History

package org.gcube.portlets.user.geoportaldataviewer.server;
import java.util.ArrayList;
import java.util.List;
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.UploadedImage;
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.LayerConcessioneDV;
import org.gcube.portlets.user.geoportaldataviewer.shared.products.RelazioneScavoDV;
import org.gcube.portlets.user.geoportaldataviewer.shared.products.content.OtherContentDV;
import org.gcube.portlets.user.geoportaldataviewer.shared.products.model.RecordDV;
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);
/**
* To concessione.
*
* @param concessione the concessione
* @return the concessione
* @throws Exception the exception
*/
public static ConcessioneDV toConcessione(
Concessione concessione) throws Exception {
if(concessione==null)
return null;
ConcessioneDV theConcessione = new ConcessioneDV();
theConcessione.setAccesso(concessione.getAccesso().name());
theConcessione.setAuthors(concessione.getAuthors());
theConcessione.setCentroidLat(concessione.getCentroidLat());
theConcessione.setCentroidLong(concessione.getCentroidLong());
theConcessione.setContributore(concessione.getContributore());
theConcessione.setCreationTime(concessione.getCreationTime());
theConcessione.setCreationUser(concessione.getCreationUser());
theConcessione.setDataFineProgetto(concessione.getDataFineProgetto());
theConcessione.setDataInizioProgetto(concessione.getDataInizioProgetto());
theConcessione.setDescrizioneContenuto(concessione.getDescrizioneContenuto());
theConcessione.setEditore(concessione.getEditore());
theConcessione.setFontiFinanziamento(concessione.getFontiFinanziamento());
theConcessione.setId(concessione.getId());
if(concessione.getGenericContent()!=null){
List<OtherContentDV> otherContentsDV = new ArrayList<OtherContentDV>(concessione.getGenericContent().size());
for (OtherContent gc : concessione.getGenericContent()) {
otherContentsDV.add(toOtherContentDV(gc, theConcessione));
}
theConcessione.setGenericContent(otherContentsDV);
}
if(concessione.getImmaginiRappresentative()!=null){
List<UploadedImageDV> uploadedImagesDV = new ArrayList<UploadedImageDV>(concessione.getImmaginiRappresentative().size());
for (UploadedImage ui : concessione.getImmaginiRappresentative()) {
uploadedImagesDV.add(toUploadedImage(ui, theConcessione));
}
theConcessione.setImmaginiRappresentative(uploadedImagesDV);
}
theConcessione.setIntroduzione(concessione.getIntroduzione());
theConcessione.setLastUpdateTime(concessione.getLastUpdateTime());
theConcessione.setLastUpdateUser(concessione.getLastUpdateUser());
theConcessione.setLicenzaID(concessione.getLicenzaID());
theConcessione.setNome(concessione.getNome());
theConcessione.setParoleChiaveICCD(concessione.getParoleChiaveICCD());
theConcessione.setParoleChiaveLibere(concessione.getParoleChiaveLibere());
if(concessione.getPianteFineScavo()!=null){
List<LayerConcessioneDV> piantaScavoDV = new ArrayList<LayerConcessioneDV>(concessione.getPianteFineScavo().size());
for (LayerConcessione lc : concessione.getPianteFineScavo()) {
piantaScavoDV.add(toLayerConcessione(lc, theConcessione));
}
theConcessione.setPianteFineScavo(piantaScavoDV);
}
if(concessione.getPosizionamentoScavo()!=null){
LayerConcessioneDV thePosizScavo = toLayerConcessione(concessione.getPosizionamentoScavo(), theConcessione);
theConcessione.setPosizionamentoScavo(thePosizScavo);
}
theConcessione.setRecordType(concessione.getRecordType().name());
theConcessione.setRelazioneScavo(toRelazioneScavo(concessione.getRelazioneScavo(), theConcessione));
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());
LOG.debug("Returning concessione: "+theConcessione);
return theConcessione;
}
/**
* 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, RecordDV recordDV) {
if (relazioneScavo == null)
return null;
RelazioneScavoDV theRelazioneDiScavo = new RelazioneScavoDV();
theRelazioneDiScavo.setAbstractSection(relazioneScavo.getAbstractSection());
theRelazioneDiScavo.setCreationTime(relazioneScavo.getCreationTime());
theRelazioneDiScavo.setId(relazioneScavo.getId());
theRelazioneDiScavo.setLicenseID(relazioneScavo.getLicenseID());
theRelazioneDiScavo.setPolicy(relazioneScavo.getPolicy().name());
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, RecordDV recordDV) {
if (uploadedImage == null)
return null;
UploadedImageDV theUploadedImageDV = new UploadedImageDV();
theUploadedImageDV.setCreationTime(uploadedImage.getCreationTime());
theUploadedImageDV.setDidascalia(uploadedImage.getDidascalia());
theUploadedImageDV.setFormat(uploadedImage.getFormat());
theUploadedImageDV.setId(uploadedImage.getId());
theUploadedImageDV.setLicenseID(uploadedImage.getLicenseID());
theUploadedImageDV.setPolicy(uploadedImage.getPolicy().name());
theUploadedImageDV.setRecord(recordDV);
theUploadedImageDV.setResponsabili(uploadedImage.getResponsabili());
theUploadedImageDV.setSoggetto(uploadedImage.getSoggetto());
theUploadedImageDV.setTitolo(uploadedImage.getTitolo());
LOG.debug("Returning: "+theUploadedImageDV);
return theUploadedImageDV;
}
/**
* 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, RecordDV recordDV) {
if (layerConcessione == null)
return null;
LayerConcessioneDV theLayerConessione = new org.gcube.portlets.user.geoportaldataviewer.shared.products.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(layerConcessione.getCreationTime());
theLayerConessione.setId(layerConcessione.getId());
theLayerConessione.setLicenseID(layerConcessione.getLicenseID());
theLayerConessione.setMetodoRaccoltaDati(layerConcessione.getMetodoRaccoltaDati());
theLayerConessione.setPolicy(layerConcessione.getPolicy().name());
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, RecordDV recordDV) {
if (otherContent == null)
return null;
OtherContentDV theOtherContent = new OtherContentDV();
theOtherContent.setCreationTime(otherContent.getCreationTime());
theOtherContent.setId(otherContent.getId());
theOtherContent.setLicenseID(otherContent.getLicenseID());
theOtherContent.setPolicy(otherContent.getPolicy().name());
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);
}
}