geoportal-data-common/src/main/java/org/gcube/application/geoportalcommon/ConvertToDataViewModel.java

674 lines
24 KiB
Java
Raw Normal View History

2021-07-30 11:37:46 +02:00
package org.gcube.application.geoportalcommon;
2021-09-13 17:38:21 +02:00
import java.io.Serializable;
2021-07-30 11:37:46 +02:00
import java.util.ArrayList;
import java.util.List;
import org.gcube.application.geoportal.common.model.legacy.AbstractRelazione;
2021-07-30 11:37:46 +02:00
import org.gcube.application.geoportal.common.model.legacy.AccessPolicy;
import org.gcube.application.geoportal.common.model.legacy.BBOX;
import org.gcube.application.geoportal.common.model.legacy.Concessione;
import org.gcube.application.geoportal.common.model.legacy.LayerConcessione;
import org.gcube.application.geoportal.common.model.legacy.OtherContent;
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;
2021-09-13 17:38:21 +02:00
import org.gcube.application.geoportal.common.model.legacy.report.ValidationReport;
2021-07-30 11:37:46 +02:00
import org.gcube.application.geoportalcommon.shared.gis.BoundsMap;
2021-09-09 10:15:55 +02:00
import org.gcube.application.geoportalcommon.shared.products.BaseConcessioneDV;
2021-07-30 11:37:46 +02:00
import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV;
import org.gcube.application.geoportalcommon.shared.products.content.OtherContentDV;
import org.gcube.application.geoportalcommon.shared.products.content.WorkspaceContentDV;
import org.gcube.application.geoportalcommon.shared.products.model.AbstractRelazioneScavoDV;
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;
2021-09-13 17:38:21 +02:00
import org.gcube.application.geoportalcommon.shared.products.model.ValidationReportDV;
import org.gcube.application.geoportalcommon.shared.products.model.ValidationReportDV.ValidationStatus;
2021-09-29 11:36:13 +02:00
import org.gcube.application.geoportalcommon.shared.products.paths.FileSetPathsDV;
2021-08-04 15:49:31 +02:00
import org.gcube.application.geoportalcommon.util.DateUtils;
2021-07-30 11:37:46 +02:00
import org.gcube.application.geoportalcommon.util.URLParserUtil;
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 {
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 = "dd-MM-yyyy";
public static final String HOURS_MINUTES_SEPARATOR = ":";
public static final String TIME_FORMAT = "HH" + HOURS_MINUTES_SEPARATOR + "mm";
2022-03-11 12:01:27 +01:00
2021-07-30 11:37:46 +02:00
/**
* To concessione.
*
* @param concessione the concessione
* @return the concessione
* @throws Exception the exception
*/
public static ConcessioneDV toConcessione(Concessione concessione) throws Exception {
2021-10-06 16:54:59 +02:00
LOG.debug("toConcessione called");
2021-07-30 11:37:46 +02:00
if (concessione == null)
return null;
2021-09-09 10:15:55 +02:00
2021-10-06 16:54:59 +02:00
LOG.debug("toConcessione called for concessione with mongoId: " + concessione.getMongo_id());
if (LOG.isTraceEnabled())
LOG.trace("Source concessione is: " + concessione);
2021-07-30 11:37:46 +02:00
try {
ConcessioneDV theConcessione = new ConcessioneDV();
theConcessione.setPolicy(toPolicy(concessione.getPolicy()));
2021-09-29 12:09:47 +02:00
theConcessione.setAuthors(concessione.getAuthors());
2021-07-30 11:37:46 +02:00
theConcessione.setCentroidLat(concessione.getCentroidLat());
theConcessione.setCentroidLong(concessione.getCentroidLong());
theConcessione.setContributore(concessione.getContributore());
2021-08-04 15:49:31 +02:00
theConcessione.setCreationTime(DateUtils.asDate(concessione.getCreationTime()));
2021-07-30 11:37:46 +02:00
theConcessione.setCreationUser(toUser(concessione.getCreationUser()));
2021-08-04 15:49:31 +02:00
theConcessione.setDataInizioProgetto(DateUtils.asDate(concessione.getDataInizioProgetto()));
theConcessione.setDataFineProgetto(DateUtils.asDate(concessione.getDataFineProgetto()));
2021-07-30 11:37:46 +02:00
theConcessione.setDescrizioneContenuto(concessione.getDescrizioneContenuto());
theConcessione.setEditore(concessione.getEditore());
theConcessione.setFontiFinanziamento(concessione.getFontiFinanziamento());
2021-08-02 15:12:33 +02:00
theConcessione.setItemId(concessione.getMongo_id());
2021-07-30 11:37:46 +02:00
theConcessione.setNome(concessione.getNome());
2021-09-09 10:15:55 +02:00
2021-07-30 11:37:46 +02:00
theConcessione.setIntroduzione(concessione.getIntroduzione());
2021-08-04 15:49:31 +02:00
theConcessione.setLastUpdateTime(DateUtils.asDate(concessione.getLastUpdateTime()));
2021-07-30 11:37:46 +02:00
theConcessione.setLastUpdateUser(toUser(concessione.getLastUpdateUser()));
theConcessione.setLicenzaID(concessione.getLicenzaID());
theConcessione.setParoleChiaveICCD(concessione.getParoleChiaveICCD());
theConcessione.setParoleChiaveLibere(concessione.getParoleChiaveLibere());
2021-09-09 10:15:55 +02:00
2021-07-30 11:37:46 +02:00
theConcessione.setResponsabile(concessione.getResponsabile());
theConcessione.setRisorseCorrelate(concessione.getRisorseCorrelate());
theConcessione.setSoggetto(concessione.getSoggetto());
theConcessione.setTitolariCopyright(concessione.getTitolareCopyright());
theConcessione.setTitolariLicenza(concessione.getTitolareLicenza());
theConcessione.setTitolari(concessione.getTitolari());
theConcessione.setVersion(concessione.getVersion());
2021-09-09 10:15:55 +02:00
2021-07-30 11:37:46 +02:00
theConcessione.setRecordType(concessione.getRecordType().name());
2021-09-09 10:15:55 +02:00
theConcessione.setAbstractRelazioneScavo(toAbstractRelazioneScavo(concessione.getAbstractRelazione()));
2021-07-30 11:37:46 +02:00
theConcessione.setRelazioneScavo(toRelazioneScavo(concessione.getRelazioneScavo()));
2021-09-09 10:15:55 +02:00
2021-07-30 11:37:46 +02:00
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);
}
2021-09-09 10:15:55 +02:00
2021-07-30 11:37:46 +02:00
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);
}
2021-09-09 10:15:55 +02:00
2021-07-30 11:37:46 +02:00
if (concessione.getPianteFineScavo() != null) {
List<LayerConcessioneDV> piantaScavoDV = new ArrayList<LayerConcessioneDV>(
concessione.getPianteFineScavo().size());
for (LayerConcessione lc : concessione.getPianteFineScavo()) {
2021-09-13 17:38:21 +02:00
// TODO CHECK WHY I HAVE TO PASS theConcessione = null IN ORDER TO AVOID GWT
// serialization error
2021-09-09 11:55:33 +02:00
piantaScavoDV.add(toLayerConcessione(lc, null));
2021-07-30 11:37:46 +02:00
}
theConcessione.setPianteFineScavo(piantaScavoDV);
}
2021-09-09 10:15:55 +02:00
2021-07-30 11:37:46 +02:00
if (concessione.getPosizionamentoScavo() != null) {
2021-09-13 17:38:21 +02:00
// TODO CHECK WHY I HAVE TO PASS theConcessione = null IN ORDER TO AVOID GWT
// serialization error
LayerConcessioneDV thePosizScavo = toLayerConcessione(concessione.getPosizionamentoScavo(), null);
2021-07-30 11:37:46 +02:00
theConcessione.setPosizionamentoScavo(thePosizScavo);
}
2021-09-09 10:15:55 +02:00
2021-10-06 16:54:59 +02:00
LOG.debug("Returning concessioneDV with id: " + theConcessione.getItemId());
if (LOG.isTraceEnabled())
LOG.trace("Returning: " + theConcessione);
2021-07-30 11:37:46 +02:00
return theConcessione;
2021-09-09 10:15:55 +02:00
} catch (Exception e) {
LOG.error("Error on converting concessione: " + concessione, e);
2021-07-30 11:37:46 +02:00
return null;
}
}
2021-09-09 10:15:55 +02:00
2021-08-04 15:49:31 +02:00
/**
2021-09-09 10:15:55 +02:00
* To metadata concessione.
2021-08-04 15:49:31 +02:00
*
* @param concessione the concessione
2021-09-13 17:38:21 +02:00
* @param includeValidationReport the include validation report
2021-09-09 10:15:55 +02:00
* @return the concessione DV
2021-08-04 15:49:31 +02:00
* @throws Exception the exception
*/
public static ConcessioneDV toMetadataConcessione(Concessione concessione, boolean includeValidationReport)
throws Exception {
2021-10-06 16:54:59 +02:00
LOG.debug("toMetadataConcessione called");
2021-08-04 15:49:31 +02:00
if (concessione == null)
return null;
2021-09-09 10:15:55 +02:00
2021-10-06 16:54:59 +02:00
LOG.debug("toMetadataConcessione called for concessione with [mongoId: " + concessione.getMongo_id()
+ ", includeValidationReport: " + includeValidationReport + "]");
if (LOG.isTraceEnabled())
LOG.trace("Source concessione is: " + concessione);
2021-08-04 15:49:31 +02:00
try {
ConcessioneDV theConcessione = new ConcessioneDV();
theConcessione.setPolicy(toPolicy(concessione.getPolicy()));
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());
2021-08-05 17:50:26 +02:00
theConcessione.setAuthors(concessione.getAuthors());
2021-08-06 09:17:09 +02:00
theConcessione.setCreationTime(DateUtils.asDate(concessione.getCreationTime()));
2021-09-09 10:15:55 +02:00
2021-08-04 15:49:31 +02:00
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());
2021-09-09 10:15:55 +02:00
2021-08-04 15:49:31 +02:00
theConcessione.setResponsabile(concessione.getResponsabile());
theConcessione.setTitolariCopyright(concessione.getTitolareCopyright());
theConcessione.setTitolariLicenza(concessione.getTitolareLicenza());
theConcessione.setTitolari(concessione.getTitolari());
if (includeValidationReport) {
2021-09-13 17:38:21 +02:00
theConcessione.setValidationReport(toValidationReport(concessione.getReport()));
if (theConcessione.getValidationReport() != null)
2021-09-14 16:41:29 +02:00
theConcessione.setValidationStatus(theConcessione.getValidationReport().getStatus());
}
2021-08-04 15:49:31 +02:00
2021-10-06 16:54:59 +02:00
LOG.info("Returning concessioneDV with id: " + theConcessione.getItemId());
if (LOG.isTraceEnabled())
LOG.trace("Returning: " + theConcessione);
2021-09-09 10:15:55 +02:00
return theConcessione;
} catch (Exception e) {
LOG.error("Error on converting concessione: " + concessione, e);
return null;
}
}
/**
* To validation report.
*
* @param validationReport the validation report
* @return the validation report DV
* @throws Exception the exception
*/
2021-09-13 17:38:21 +02:00
public static ValidationReportDV toValidationReport(ValidationReport validationReport) throws Exception {
2021-10-06 16:54:59 +02:00
LOG.debug("toValidationReport called");
2021-09-13 17:38:21 +02:00
if (validationReport == null)
return null;
2021-10-06 16:54:59 +02:00
LOG.debug("toValidationReport called for: "+validationReport);
2021-09-13 17:38:21 +02:00
ValidationReportDV theVR = new ValidationReportDV();
theVR.setErrorMessages(validationReport.getErrorMessages());
theVR.setObjectName(validationReport.getObjectName());
theVR.setStatus(ValidationStatus.valueOf(validationReport.getStatus().name()));
theVR.setWarningMessages(validationReport.getWarningMessages());
theVR.setAsJSONString(toJSON(validationReport));
2021-10-06 16:54:59 +02:00
LOG.debug("Returning: "+theVR);
2021-09-13 17:38:21 +02:00
return theVR;
}
2021-09-09 10:15:55 +02:00
/**
* To base concessione.
*
* @param concessione the concessione
* @return the concessione DV
* @throws Exception the exception
*/
public static BaseConcessioneDV toBaseConcessione(Concessione concessione) throws Exception {
2021-10-06 16:54:59 +02:00
LOG.debug("toBaseConcessione called");
2021-09-09 10:15:55 +02:00
if (concessione == null)
return null;
2021-10-06 16:54:59 +02:00
LOG.debug("toBaseConcessione called for concessione with mongoId: " + concessione.getMongo_id());
if (LOG.isTraceEnabled())
LOG.trace("Source concessione is: " + concessione);
2021-09-09 10:15:55 +02:00
try {
BaseConcessioneDV theConcessione = new BaseConcessioneDV();
theConcessione.setPolicy(toPolicy(concessione.getPolicy()));
theConcessione.setCreationTime(DateUtils.asDate(concessione.getCreationTime()));
theConcessione.setCreationUser(toUser(concessione.getCreationUser()));
theConcessione.setItemId(concessione.getMongo_id());
theConcessione.setNome(concessione.getNome());
theConcessione.setAuthors(concessione.getAuthors());
theConcessione.setCreationTime(DateUtils.asDate(concessione.getCreationTime()));
theConcessione.setIntroduzione(concessione.getIntroduzione());
theConcessione.setLastUpdateTime(DateUtils.asDate(concessione.getLastUpdateTime()));
theConcessione.setLastUpdateUser(toUser(concessione.getLastUpdateUser()));
theConcessione.setLicenzaID(concessione.getLicenzaID());
2021-08-04 15:49:31 +02:00
2021-10-06 16:54:59 +02:00
LOG.debug("Returning BaseConcessioneDV with id: " + theConcessione.getItemId());
if (LOG.isTraceEnabled())
LOG.trace("Returning: " + theConcessione);
2021-08-04 15:49:31 +02:00
return theConcessione;
2021-09-09 10:15:55 +02:00
} catch (Exception e) {
LOG.error("Error on converting concessione: " + concessione, e);
2021-08-04 15:49:31 +02:00
return null;
}
}
2021-09-09 10:15:55 +02:00
2021-07-30 11:37:46 +02:00
/**
* To user.
*
* @param username the username
* @return the string
*/
public static String toUser(String username) {
2021-09-09 10:15:55 +02:00
if (username == null)
2021-07-30 11:37:46 +02:00
return null;
2021-09-09 10:15:55 +02:00
2021-07-30 11:37:46 +02:00
return username;
2021-09-09 10:15:55 +02:00
2021-07-30 11:37:46 +02:00
}
2021-09-09 10:15:55 +02:00
2021-07-30 11:37:46 +02:00
/**
* To policy.
*
* @param policy the policy
* @return the string
*/
public static String toPolicy(AccessPolicy policy) {
2021-09-09 10:15:55 +02:00
if (policy == null)
2021-07-30 11:37:46 +02:00
return null;
2021-09-09 10:15:55 +02:00
2021-07-30 11:37:46 +02:00
return policy.name();
2021-09-09 10:15:55 +02:00
2021-07-30 11:37:46 +02:00
}
2021-09-09 10:15:55 +02:00
2021-07-30 11:37:46 +02:00
/**
* To abstract relazione scavo.
*
* @param abstractRelazione the abstract relazione
2021-07-30 11:37:46 +02:00
* @return the abstract relazione scavo DV
*/
public static AbstractRelazioneScavoDV toAbstractRelazioneScavo(AbstractRelazione abstractRelazione) {
2021-10-06 16:54:59 +02:00
LOG.debug("toAbstractRelazioneScavo called");
if (abstractRelazione == null)
2021-07-30 11:37:46 +02:00
return null;
AbstractRelazioneScavoDV theARelDiScavo = new AbstractRelazioneScavoDV();
theARelDiScavo.setAbstractSectionIta(abstractRelazione.getAbstractIta());
theARelDiScavo.setAbstractSectionEng(abstractRelazione.getAbstractEng());
2021-09-09 10:15:55 +02:00
theARelDiScavo.setCreationTime(DateUtils.asDate(abstractRelazione.getCreationTime()));
theARelDiScavo.setId(abstractRelazione.getId());
theARelDiScavo.setLicenseID(abstractRelazione.getLicenseID());
theARelDiScavo.setPolicy(toPolicy(abstractRelazione.getPolicy()));
theARelDiScavo.setTitolo(abstractRelazione.getTitolo());
List<PersistedContent> actContent = abstractRelazione.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));
}
}
theARelDiScavo.setListWsContent(listWsContent);
}
2021-07-30 11:37:46 +02:00
LOG.debug("Returning: " + theARelDiScavo);
return theARelDiScavo;
2021-07-30 11:37:46 +02:00
}
/**
* To relazione scavo.
*
* @param relazioneScavo the relazione scavo
* @return the relazione scavo data view
*/
public static RelazioneScavoDV toRelazioneScavo(RelazioneScavo relazioneScavo) {
2021-10-06 16:54:59 +02:00
LOG.debug("toRelazioneScavo called");
2021-07-30 11:37:46 +02:00
if (relazioneScavo == null)
return null;
RelazioneScavoDV theRelDiScavo = new RelazioneScavoDV();
theRelDiScavo.setCreationTime(DateUtils.asDate(relazioneScavo.getCreationTime()));
theRelDiScavo.setId(relazioneScavo.getId());
theRelDiScavo.setLicenseID(relazioneScavo.getLicenseID());
theRelDiScavo.setPolicy(toPolicy(relazioneScavo.getPolicy()));
2021-09-09 10:15:55 +02:00
// theRelazioneDiScavo.setRecord(recordDV);
theRelDiScavo.setResponsabili(relazioneScavo.getResponsabili());
theRelDiScavo.setSoggetto(relazioneScavo.getSoggetto());
theRelDiScavo.setTitolo(relazioneScavo.getTitolo());
2021-09-09 10:15:55 +02:00
2021-07-30 11:37:46 +02:00
List<PersistedContent> actContent = relazioneScavo.getActualContent();
2021-09-09 10:15:55 +02:00
if (actContent != null && actContent.size() > 0) {
2021-07-30 11:37:46 +02:00
List<WorkspaceContentDV> listWsContent = new ArrayList<WorkspaceContentDV>();
2021-09-09 10:15:55 +02:00
2021-07-30 11:37:46 +02:00
for (PersistedContent content : actContent) {
2021-09-09 10:15:55 +02:00
if (content != null && content instanceof WorkspaceContent) {
listWsContent.add(toWorkspaceContent((WorkspaceContent) content));
2021-07-30 11:37:46 +02:00
}
}
theRelDiScavo.setListWsContent(listWsContent);
2021-07-30 11:37:46 +02:00
}
LOG.debug("Returning: " + theRelDiScavo);
return theRelDiScavo;
2021-07-30 11:37:46 +02:00
}
2021-09-09 10:15:55 +02:00
2021-07-30 11:37:46 +02:00
/**
* To uploaded image.
*
* @param uploadedImage the uploaded image
* @return the uploaded image data-view
*/
public static UploadedImageDV toUploadedImage(UploadedImage uploadedImage) {
2021-10-06 16:54:59 +02:00
LOG.debug("toUploadedImage called");
2021-07-30 11:37:46 +02:00
if (uploadedImage == null)
return null;
UploadedImageDV theUploadedImageDV = new UploadedImageDV();
2021-08-04 15:49:31 +02:00
theUploadedImageDV.setCreationTime(DateUtils.asDate(uploadedImage.getCreationTime()));
2021-07-30 11:37:46 +02:00
theUploadedImageDV.setDidascalia(uploadedImage.getDidascalia());
theUploadedImageDV.setFormat(uploadedImage.getFormat());
theUploadedImageDV.setId(uploadedImage.getId());
theUploadedImageDV.setLicenseID(uploadedImage.getLicenseID());
theUploadedImageDV.setPolicy(toPolicy(uploadedImage.getPolicy()));
2021-09-09 10:15:55 +02:00
// theUploadedImageDV.setRecord(recordDV);
2021-07-30 11:37:46 +02:00
theUploadedImageDV.setResponsabili(uploadedImage.getResponsabili());
theUploadedImageDV.setSoggetto(uploadedImage.getSoggetto());
theUploadedImageDV.setTitolo(uploadedImage.getTitolo());
2021-09-09 10:15:55 +02:00
2021-07-30 11:37:46 +02:00
List<PersistedContent> actContent = uploadedImage.getActualContent();
2021-09-09 10:15:55 +02:00
if (actContent != null && actContent.size() > 0) {
2021-07-30 11:37:46 +02:00
List<WorkspaceContentDV> listWsContent = new ArrayList<WorkspaceContentDV>();
2021-09-09 10:15:55 +02:00
2021-07-30 11:37:46 +02:00
for (PersistedContent content : actContent) {
2021-09-09 10:15:55 +02:00
if (content != null && content instanceof WorkspaceContent) {
listWsContent.add(toWorkspaceContent((WorkspaceContent) content));
2021-07-30 11:37:46 +02:00
}
}
theUploadedImageDV.setListWsContent(listWsContent);
}
LOG.debug("Returning: " + theUploadedImageDV);
return theUploadedImageDV;
}
2021-09-09 10:15:55 +02:00
2021-07-30 11:37:46 +02:00
/**
* To workspace content.
*
* @param wContent the w content
* @return the workspace content DV
*/
2021-09-09 10:15:55 +02:00
public static WorkspaceContentDV toWorkspaceContent(WorkspaceContent wContent) {
2021-10-06 16:54:59 +02:00
LOG.debug("toWorkspaceContent called");
2021-07-30 11:37:46 +02:00
if (wContent == null)
return null;
2021-09-09 10:15:55 +02:00
2021-07-30 11:37:46 +02:00
WorkspaceContentDV theWSDV = new WorkspaceContentDV();
theWSDV.setLink(wContent.getLink());
theWSDV.setMimetype(wContent.getMimetype());
theWSDV.setStorageID(wContent.getStorageID());
theWSDV.setId(wContent.getId());
theWSDV.setName(wContent.getName());
2021-09-09 10:15:55 +02:00
2021-07-30 11:37:46 +02:00
return theWSDV;
}
/**
* To layer concessione.
*
2021-09-09 10:15:55 +02:00
* @param layerConcessione the layer concessione
* @param refersToBaseConcessione the refers to base concessione
2021-07-30 11:37:46 +02:00
* @return the layer concessione data view
*/
2021-09-09 10:15:55 +02:00
public static LayerConcessioneDV toLayerConcessione(LayerConcessione layerConcessione,
2021-09-13 17:38:21 +02:00
BaseConcessioneDV refersToBaseConcessione) {
2021-07-30 11:37:46 +02:00
if (layerConcessione == null)
return null;
2021-09-09 10:15:55 +02:00
LOG.debug("Converting: " + layerConcessione);
2021-07-30 11:37:46 +02:00
LayerConcessioneDV theLayerConessione = new LayerConcessioneDV();
theLayerConessione.setAbstractSection(layerConcessione.getAbstractSection());
2021-09-09 10:15:55 +02:00
2021-07-30 11:37:46 +02:00
String wmsLink = layerConcessione.getWmsLink();
String layerName = null;
BoundsMap bounds = null;
2021-09-09 10:15:55 +02:00
// reading layer name from wmsLink
// string bbox
if (wmsLink != null) {
2021-07-30 11:37:46 +02:00
layerName = URLParserUtil.extractValueOfParameterFromURL("layers", wmsLink);
String bbox = URLParserUtil.extractValueOfParameterFromURL("bbox", wmsLink);
String wmsVersion = URLParserUtil.extractValueOfParameterFromURL("version", wmsLink);
bounds = toBoundMap(wmsVersion, bbox, ",");
2021-09-09 10:15:55 +02:00
LOG.debug("Built bounds from wmsLInk: " + bounds);
2021-07-30 11:37:46 +02:00
}
2021-09-09 10:15:55 +02:00
if (layerName != null)
2021-07-30 11:37:46 +02:00
theLayerConessione.setLayerName(layerName);
else
theLayerConessione.setLayerName(layerConcessione.getLayerName());
theLayerConessione.setWmsLink(wmsLink);
theLayerConessione.setLayerID(layerConcessione.getLayerID());
theLayerConessione.setLayerUUID(layerConcessione.getLayerUUID());
theLayerConessione.setAuthors(layerConcessione.getAuthors());
2021-09-09 10:15:55 +02:00
if (bounds == null)
2021-07-30 11:37:46 +02:00
bounds = toBoundMap(layerConcessione.getBbox());
2021-09-09 10:15:55 +02:00
2021-07-30 11:37:46 +02:00
theLayerConessione.setBbox(bounds);
2021-08-04 15:49:31 +02:00
theLayerConessione.setCreationTime(DateUtils.asDate(layerConcessione.getCreationTime()));
2021-07-30 11:37:46 +02:00
theLayerConessione.setId(layerConcessione.getId());
theLayerConessione.setLicenseID(layerConcessione.getLicenseID());
theLayerConessione.setMetodoRaccoltaDati(layerConcessione.getMetodoRaccoltaDati());
theLayerConessione.setPolicy(toPolicy(layerConcessione.getPolicy()));
2021-09-09 10:15:55 +02:00
// theLayerConessione.setRecord(recordDV);
2021-07-30 11:37:46 +02:00
theLayerConessione.setScalaAcquisizione(layerConcessione.getScalaAcquisizione());
theLayerConessione.setSubTopic(layerConcessione.getSubTopic());
theLayerConessione.setTitolo(layerConcessione.getTitolo());
theLayerConessione.setTopicCategory(layerConcessione.getTopicCategory());
theLayerConessione.setValutazioneQualita(layerConcessione.getValutazioneQualita());
2021-09-09 10:15:55 +02:00
theLayerConessione.setRefersTo(refersToBaseConcessione);
2021-09-29 11:36:13 +02:00
2021-09-28 10:53:04 +02:00
List<PersistedContent> actContent = layerConcessione.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));
}
}
theLayerConessione.setListWsContent(listWsContent);
}
2021-07-30 11:37:46 +02:00
LOG.debug("Returning: " + theLayerConessione);
return theLayerConessione;
}
/**
* To other content DV.
*
* @param otherContent the other content
* @return the other content DV
*/
public static OtherContentDV toOtherContentDV(OtherContent otherContent) {
if (otherContent == null)
return null;
OtherContentDV theOtherContent = new OtherContentDV();
2021-08-04 15:49:31 +02:00
theOtherContent.setCreationTime(DateUtils.asDate(otherContent.getCreationTime()));
2021-07-30 11:37:46 +02:00
theOtherContent.setId(otherContent.getId());
theOtherContent.setLicenseID(otherContent.getLicenseID());
theOtherContent.setPolicy(toPolicy(otherContent.getPolicy()));
2021-09-09 10:15:55 +02:00
// theOtherContent.setRecord(recordDV);
2021-07-30 11:37:46 +02:00
theOtherContent.setTitolo(otherContent.getTitolo());
return theOtherContent;
}
2021-09-29 11:36:13 +02:00
public static FileSetPathsDV getFileSetPaths() {
LOG.info("readFileSetPaths called");
2021-10-06 16:54:59 +02:00
FileSetPathsDV fsp = new FileSetPathsDV();
2021-09-29 11:36:13 +02:00
List<String> fileSetPaths = new ArrayList<String>();
fileSetPaths.add(Concessione.Paths.ABSTRACT_RELAZIONE);
fileSetPaths.add(Concessione.Paths.RELAZIONE);
fileSetPaths.add(Concessione.Paths.IMMAGINI);
fileSetPaths.add(Concessione.Paths.POSIZIONAMENTO);
fileSetPaths.add(Concessione.Paths.PIANTE);
fsp.setFileSetPaths(fileSetPaths);
return fsp;
}
2021-07-30 11:37:46 +02:00
/**
* 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);
}
2021-09-09 10:15:55 +02:00
2021-07-30 11:37:46 +02:00
/**
* To bound map.
*
* @param wmsVersion the wms version
2021-09-09 10:15:55 +02:00
* @param bbox the bbox
* @param separator the separator
2021-07-30 11:37:46 +02:00
* @return the bounds map
*/
public static BoundsMap toBoundMap(String wmsVersion, String bbox, String separator) {
if (bbox == null)
return null;
2021-09-09 10:15:55 +02:00
if (wmsVersion == null)
2021-07-30 11:37:46 +02:00
return null;
2021-09-09 10:15:55 +02:00
if (separator == null)
2021-07-30 11:37:46 +02:00
separator = ",";
2021-09-09 10:15:55 +02:00
2021-07-30 11:37:46 +02:00
try {
2021-09-09 10:15:55 +02:00
2021-07-30 11:37:46 +02:00
String[] bboxArr = bbox.split(separator);
2021-09-09 10:15:55 +02:00
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);
2021-07-30 11:37:46 +02:00
}
2021-09-09 10:15:55 +02:00
} catch (Exception e) {
LOG.warn("Error on creating Bounds for wmsVersion " + wmsVersion + " and bbox " + bbox + " : ", e);
2021-07-30 11:37:46 +02:00
return null;
}
}
2021-09-09 10:15:55 +02:00
2021-07-30 11:37:46 +02:00
/**
* To double.
*
* @param value the value
* @return the double
*/
public static Double toDouble(String value) {
try {
return Double.parseDouble(value);
2021-09-09 10:15:55 +02:00
} catch (Exception e) {
LOG.warn("Error on parsing " + value + " as double: ", e);
2021-07-30 11:37:46 +02:00
return null;
}
}
2021-09-13 17:38:21 +02:00
/**
* To JSON.
*
* @param theObj the the obj
2021-09-13 17:38:21 +02:00
* @return the string
*/
public static String toJSON(Object theObj) {
LOG.debug("toJSON called");
try {
if (theObj instanceof Serializable) {
return org.gcube.application.geoportal.client.utils.Serialization.write(theObj);
}
throw new Exception("The input object is not serializable");
} catch (Exception e) {
LOG.warn("Error on deserializing: ", e);
return null;
}
}
2021-07-30 11:37:46 +02:00
}