diff --git a/src/main/java/org/gcube/application/geoportalcommon/ConvertToDataValueObjectModel.java b/src/main/java/org/gcube/application/geoportalcommon/ConvertToDataValueObjectModel.java index 57f89d8..78a2039 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/ConvertToDataValueObjectModel.java +++ b/src/main/java/org/gcube/application/geoportalcommon/ConvertToDataValueObjectModel.java @@ -34,6 +34,7 @@ import org.gcube.application.geoportalcommon.geoportal.config.FilePath; import org.gcube.application.geoportalcommon.geoportal.config.GcubeProfile; import org.gcube.application.geoportalcommon.geoportal.config.ItemField; import org.gcube.application.geoportalcommon.geoportal.serdes.Payload; +import org.gcube.application.geoportalcommon.geoportal.util.GisUtil; import org.gcube.application.geoportalcommon.shared.geoportal.ConfigurationDV; import org.gcube.application.geoportalcommon.shared.geoportal.DocumentDV; import org.gcube.application.geoportalcommon.shared.geoportal.ResultDocumentDV; @@ -41,12 +42,15 @@ import org.gcube.application.geoportalcommon.shared.geoportal.config.ActionDefin import org.gcube.application.geoportalcommon.shared.geoportal.config.FilePathDV; import org.gcube.application.geoportalcommon.shared.geoportal.config.GcubeProfileDV; import org.gcube.application.geoportalcommon.shared.geoportal.config.ItemFieldDV; +import org.gcube.application.geoportalcommon.shared.geoportal.geojson.Crs; +import org.gcube.application.geoportalcommon.shared.geoportal.geojson.GeoJSON; import org.gcube.application.geoportalcommon.shared.geoportal.materialization.IndexLayerDV; import org.gcube.application.geoportalcommon.shared.geoportal.materialization.innerobject.PayloadDV; import org.gcube.application.geoportalcommon.shared.geoportal.project.AccessDV; import org.gcube.application.geoportalcommon.shared.geoportal.project.AccountingInfoDV; import org.gcube.application.geoportalcommon.shared.geoportal.project.BasicLifecycleInformationDV; import org.gcube.application.geoportalcommon.shared.geoportal.project.IdentificationReferenceDV; +import org.gcube.application.geoportalcommon.shared.geoportal.project.IdentificationReferencesTYPE; import org.gcube.application.geoportalcommon.shared.geoportal.project.LifecycleInformationDV; import org.gcube.application.geoportalcommon.shared.geoportal.project.ProjectDV; import org.gcube.application.geoportalcommon.shared.geoportal.project.PublicationInfoDV; @@ -56,6 +60,8 @@ import org.gcube.application.geoportalcommon.shared.geoportal.ucd.GEOPORTAL_DATA import org.gcube.application.geoportalcommon.shared.geoportal.ucd.HandlerDeclarationDV; import org.gcube.application.geoportalcommon.shared.geoportal.ucd.RelationshipDefinitionDV; import org.gcube.application.geoportalcommon.shared.geoportal.ucd.UseCaseDescriptorDV; +import org.json.JSONException; +import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -91,7 +97,8 @@ public class ConvertToDataValueObjectModel { public static final String TIME_FORMAT = "HH" + HOURS_MINUTES_SEPARATOR + "mm"; - public static List KEYSET_POSSIBLE_DATE = Arrays.asList("start", "end", "created", "updated", "inizio", "fine", "creato", "aggiornato"); + public static List KEYSET_POSSIBLE_DATE = Arrays.asList("start", "end", "created", "updated", "inizio", + "fine", "creato", "aggiornato"); /** * To use case descriptor DV. @@ -552,10 +559,16 @@ public class ConvertToDataValueObjectModel { theProject.setLifecycleInformationDV(toLifecycleInformationDV(project.getLifecycleInformation())); } -// if (projectReader.isIncludeSpatialReference()) { -// theProject.setSpatialReference(toDocumentDV(project.getSpatialReference(), DocumentDV.class, -// projectReader.getListDocumentKeys(), projectReader.isIncludeFullDocumentMap())); -// } + if (projectReader.isIncludeSpatialReference()) { + // theProject.setMapIdentReferenceDV(project.getIdentificationReferences()); + List ids = project + .getIdentificationReferenceByType(IdentificationReferencesTYPE.SPATIAL_REFERENCE.getType()); + if (ids != null && !ids.isEmpty()) { + GeoJSON geoJson = toSpatialReference(ids.get(0).toJson()); + theProject.setSpatialReference(geoJson); + } + + } // // if (projectReader.isIncludeTemporalReference()) { // theProject.setTemporalReference(toTemporalReferenceDV(project.getTemporalReference(), @@ -577,6 +590,30 @@ public class ConvertToDataValueObjectModel { } + public static GeoJSON toSpatialReference(String geoJSONObject) { + LOG.debug("toSpatialReference called"); + + if (geoJSONObject == null) + return null; + + GeoJSON geoJson = null; + try { + geoJson = new GeoJSON(); + JSONObject jsonObject = new JSONObject(geoJSONObject).getJSONObject("geoJSON"); + geoJson.setType(jsonObject.getString("type")); + geoJson.setBbox(GisUtil.fromJSONArray(jsonObject.getJSONArray("bbox"))); + Crs crs = org.gcube.application.geoportal.client.utils.Serialization + .read(jsonObject.getJSONObject("crs").toString(), Crs.class); + geoJson.setCrs(crs); + geoJson.setGeoJSON(jsonObject.toString()); + } catch (JSONException | IOException e) { + LOG.warn("Error on converting " + GeoJSON.class.getSimpleName() + " from : " + geoJSONObject, e); + } + + return geoJson; + + } + /** * To result document DV. * @@ -599,18 +636,18 @@ public class ConvertToDataValueObjectModel { ResultDocumentDV.class, null, true); rd.setId(project.getId()); rd.setProfileID(project.getProfileID()); - + try { Double centroidLat = project.getTheDocument().get(CENTROID_LAT, Double.class); rd.setCentroidLat(centroidLat); - }catch (Exception e) { + } catch (Exception e) { // TODO: handle exception } - + try { Double centroidLong = project.getTheDocument().get(CENTROID_LONG, Double.class); rd.setCentroidLong(centroidLong); - }catch (Exception e) { + } catch (Exception e) { // TODO: handle exception } @@ -764,7 +801,7 @@ public class ConvertToDataValueObjectModel { return formatter.format(instant); } } catch (Exception e) { - LOG.warn("Date format error: "+e.getMessage()); + LOG.warn("Date format error: " + e.getMessage()); } return instantString; @@ -1145,59 +1182,38 @@ public class ConvertToDataValueObjectModel { p.setStorageID(p.getStorageID()); return p; } - - + /** * - * { - "_type": "GIS-CENTROIDS", - "layer": { - "_type": "gcube-sdi-layer", - "_platformInfo": [ - { - "_type": "Geoserver", - "workspace": "profiledconcessioni_devvre", - "storeName": "profiledconcessioni_devvre_centroids", - "_host": "geoserver-218.dev.d4science.org" - } - ], - "_bbox": { - "_maxX": 180.0, - "_minX": -180.0, - "_maxY": 90.0, - "_minY": -90.0 - }, - "_ogcLinks": { - "wms": { - "wms": "https://geoserver-218.dev.d4science.org/geoserver/profiledconcessioni_devvre/wms?service=WMS&version=1.1.0&request=GetMap&layers=profiledconcessioni_devvre:null&styles=&bbox=-180.000000,-90.000000,180.000000,90.000000&srs=EPSG:4326&format=application/openlayers&width=400&height=400" - } - } - }, - "indexName": "profiledconcessioni_devvre_centroids", - "records": 4, - "crossReferencedLayers": {}, - "flag": "public" - } + * { "_type": "GIS-CENTROIDS", "layer": { "_type": "gcube-sdi-layer", + * "_platformInfo": [ { "_type": "Geoserver", "workspace": + * "profiledconcessioni_devvre", "storeName": + * "profiledconcessioni_devvre_centroids", "_host": + * "geoserver-218.dev.d4science.org" } ], "_bbox": { "_maxX": 180.0, "_minX": + * -180.0, "_maxY": 90.0, "_minY": -90.0 }, "_ogcLinks": { "wms": { "wms": + * "https://geoserver-218.dev.d4science.org/geoserver/profiledconcessioni_devvre/wms?service=WMS&version=1.1.0&request=GetMap&layers=profiledconcessioni_devvre:null&styles=&bbox=-180.000000,-90.000000,180.000000,90.000000&srs=EPSG:4326&format=application/openlayers&width=400&height=400" + * } } }, "indexName": "profiledconcessioni_devvre_centroids", "records": 4, + * "crossReferencedLayers": {}, "flag": "public" } */ - - + public static IndexLayerDV convert(Index toConvert) throws InvalidObjectException { - - if(toConvert==null || toConvert.getType()==null) - throw new InvalidObjectException("Unable to convert Index. Unknown type: "+toConvert); - + + if (toConvert == null || toConvert.getType() == null) + throw new InvalidObjectException("Unable to convert Index. Unknown type: " + toConvert); + IndexLayerDV toReturn = null; - switch(toConvert.getType()) { - case "GIS-CENTROIDS" : { - toReturn = Serialization.convert(toConvert,IndexLayerDV.class); - // toReturn.setLayer(Serialization.read(toConvert.get("layer"), GCubeSDILayer.class)); - // toReturn.setFlag(toConvert.getString("flag")); - // toReturn.setIndexName(toConvert.getString()); + switch (toConvert.getType()) { + case "GIS-CENTROIDS": { + toReturn = Serialization.convert(toConvert, IndexLayerDV.class); + // toReturn.setLayer(Serialization.read(toConvert.get("layer"), + // GCubeSDILayer.class)); + // toReturn.setFlag(toConvert.getString("flag")); + // toReturn.setIndexName(toConvert.getString()); break; } - default:{ - throw new InvalidObjectException("Unable to convert Index. Unknown type : "+toConvert.getType()); + default: { + throw new InvalidObjectException("Unable to convert Index. Unknown type : " + toConvert.getType()); } } diff --git a/src/main/java/org/gcube/application/geoportalcommon/ProjectDVBuilder.java b/src/main/java/org/gcube/application/geoportalcommon/ProjectDVBuilder.java index 5ee7551..f5be1e2 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/ProjectDVBuilder.java +++ b/src/main/java/org/gcube/application/geoportalcommon/ProjectDVBuilder.java @@ -12,7 +12,7 @@ import java.util.List; public class ProjectDVBuilder { private boolean lifecycleInformation; - private boolean spatialReference; + private boolean spatialReference = true; //default private boolean temporalReference; private boolean relationships; private List listDocumentKeys; diff --git a/src/main/java/org/gcube/application/geoportalcommon/geoportal/util/GisUtil.java b/src/main/java/org/gcube/application/geoportalcommon/geoportal/util/GisUtil.java new file mode 100644 index 0000000..b7b3acc --- /dev/null +++ b/src/main/java/org/gcube/application/geoportalcommon/geoportal/util/GisUtil.java @@ -0,0 +1,26 @@ +package org.gcube.application.geoportalcommon.geoportal.util; + +import org.gcube.application.geoportalcommon.shared.geoportal.materialization.innerobject.BBOXDV; +import org.json.JSONArray; + +public class GisUtil { + + public static BBOXDV fromJSONArray(JSONArray outerArray) { + + try { + if (outerArray == null) + return new BBOXDV(); + + double[] coords = new double[outerArray.length()]; + + for (int i = 0; i < outerArray.length(); i++) { + coords[i] = outerArray.getDouble(i); + } + + return BBOXDV.fromGeoJSON(coords); + } catch (Exception e) { + return new BBOXDV(); + } + } + +} diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/geojson/Crs.java b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/geojson/Crs.java new file mode 100644 index 0000000..cac5bbf --- /dev/null +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/geojson/Crs.java @@ -0,0 +1,67 @@ +package org.gcube.application.geoportalcommon.shared.geoportal.geojson; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class Crs implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -8848168371106854638L; + + public Crs(){ + + } + + @JsonProperty + private String type; + @JsonProperty + private Map properties = new HashMap(); + + public void setType(String type) { + this.type = type; + } + + public String getType() { + return type; + } + + public Map getProperties() { + return properties; + } + + public void setProperties(Map properties) { + this.properties = properties; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof Crs)) { + return false; + } + Crs crs = (Crs) o; + if (properties != null ? !properties.equals(crs.properties) : crs.properties != null) { + return false; + } + return !(type != null ? !type.equals(crs.type) : crs.type != null); + } + + @Override + public int hashCode() { + int result = type != null ? type.hashCode() : 0; + result = 31 * result + (properties != null ? properties.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "Crs{" + "type='" + type + '\'' + ", properties=" + properties + '}'; + } +} diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/geojson/GeoJSON.java b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/geojson/GeoJSON.java new file mode 100644 index 0000000..ed53996 --- /dev/null +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/geojson/GeoJSON.java @@ -0,0 +1,70 @@ +package org.gcube.application.geoportalcommon.shared.geoportal.geojson; + +import java.io.Serializable; + +import org.gcube.application.geoportalcommon.shared.geoportal.materialization.innerobject.BBOXDV; + +public class GeoJSON implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -7798331554142534921L; + + private String type; + private Crs crs; + private BBOXDV bbox; + private String geoJSON; + + public GeoJSON() { + + } + + public String getType() { + return type; + } + + public Crs getCrs() { + return crs; + } + + public BBOXDV getBbox() { + return bbox; + } + + public String getGeoJSON() { + return geoJSON; + } + + public void setType(String type) { + this.type = type; + } + + public void setCrs(Crs crs) { + this.crs = crs; + } + + public void setBbox(BBOXDV bbox) { + this.bbox = bbox; + } + + public void setGeoJSON(String geoJSON) { + this.geoJSON = geoJSON; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("GeoJSON [type="); + builder.append(type); + builder.append(", crs="); + builder.append(crs); + builder.append(", bbox="); + builder.append(bbox); + builder.append(", geoJSON="); + builder.append(geoJSON); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/IdentificationReferenceDV.java b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/IdentificationReferenceDV.java index dcec7b4..acc8302 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/IdentificationReferenceDV.java +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/IdentificationReferenceDV.java @@ -26,6 +26,14 @@ public class IdentificationReferenceDV extends DocumentDV implements Serializabl return type; } + public IdentificationReferencesTYPE asIdentificationReferencesTYPE() { + try { + return IdentificationReferencesTYPE.valueOf(type); + } catch (Exception e) { + } + return null; + } + @Override public String toString() { StringBuilder builder = new StringBuilder(); diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/IdentificationReferencesTYPE.java b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/IdentificationReferencesTYPE.java new file mode 100644 index 0000000..ac0d3ba --- /dev/null +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/IdentificationReferencesTYPE.java @@ -0,0 +1,35 @@ +package org.gcube.application.geoportalcommon.shared.geoportal.project; + + +/** + * The Enum IdentificationReferencesTYPE. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Oct 26, 2022 + */ +public enum IdentificationReferencesTYPE { + + SPATIAL_REFERENCE("SPATIAL REFERENCE"); + + String type; + + /** + * Instantiates a new identification references TYPE. + * + * @param type the type + */ + IdentificationReferencesTYPE(String type) { + this.type = type; + } + + /** + * Gets the type. + * + * @return the type + */ + public String getType() { + return type; + } + +} diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/ProjectDV.java b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/ProjectDV.java index 9509dda..93a10f9 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/ProjectDV.java +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/ProjectDV.java @@ -5,9 +5,9 @@ import java.util.List; import java.util.Map; import org.gcube.application.geoportalcommon.shared.geoportal.DocumentDV; +import org.gcube.application.geoportalcommon.shared.geoportal.geojson.GeoJSON; public class ProjectDV implements Serializable { - /** * */ @@ -25,6 +25,9 @@ public class ProjectDV implements Serializable { private Map mapIdentReferenceDV; private LifecycleInformationDV lifecycleInformationDV; + // Shortcut to "SPATIAL REFERENCE" containted into IdentificationReferenceDV + private GeoJSON spatialReference; + public ProjectDV() { } @@ -101,6 +104,14 @@ public class ProjectDV implements Serializable { this.lifecycleInformationDV = lifecycleInformationDV; } + public GeoJSON getSpatialReference() { + return spatialReference; + } + + public void setSpatialReference(GeoJSON spatialReference) { + this.spatialReference = spatialReference; + } + @Override public String toString() { StringBuilder builder = new StringBuilder(); @@ -122,6 +133,8 @@ public class ProjectDV implements Serializable { builder.append(mapIdentReferenceDV); builder.append(", lifecycleInformationDV="); builder.append(lifecycleInformationDV); + builder.append(", spatialReference="); + builder.append(spatialReference); builder.append("]"); return builder.toString(); } diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/ucd/GEOPORTAL_DATA_HANDLER.java b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/ucd/GEOPORTAL_DATA_HANDLER.java index e1a425d..1986ac5 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/ucd/GEOPORTAL_DATA_HANDLER.java +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/ucd/GEOPORTAL_DATA_HANDLER.java @@ -3,6 +3,7 @@ package org.gcube.application.geoportalcommon.shared.geoportal.ucd; public enum GEOPORTAL_DATA_HANDLER { geoportal_data_list("org.gcube.portlets.user.geoportal-data-list", "DATA_LIST_GUI"), + geoportal_basic_data_list("org.gcube.portlets.user.geoportal-basic-data-list", "BASIC_DATA_LIST_GUI"), geoportal_data_entry("org.gcube.portlets.user.geoportal-data-entry-app", "DATA_ENTRY_GUI"), geoportal_workflow_action_list("org.gcube.portlets.user.geoportal-workflow-action-list","WORKFLOW_ACTION_LIST_GUI"), gna_concessioni_lc("GNA-CONCESSIONI-LC", "LifecycleManagement"); diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/view/ProjectView.java b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/view/ProjectView.java index e777451..9b3e7fc 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/view/ProjectView.java +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/view/ProjectView.java @@ -16,9 +16,6 @@ public class ProjectView implements Serializable { // The DocumentDV (contained in the ProjectDV) is listed in SectionView private List listSections = new ArrayList(); - private Double centroidLong; - private Double centroidLat; - public ProjectView() { } @@ -35,14 +32,6 @@ public class ProjectView implements Serializable { return listSections; } - public Double getCentroidLong() { - return centroidLong; - } - - public Double getCentroidLat() { - return centroidLat; - } - public void setTheProjectDV(ProjectDV theProjectDV) { this.theProjectDV = theProjectDV; } @@ -51,14 +40,6 @@ public class ProjectView implements Serializable { this.listSections = listSections; } - public void setCentroidLong(Double centroidLong) { - this.centroidLong = centroidLong; - } - - public void setCentroidLat(Double centroidLat) { - this.centroidLat = centroidLat; - } - @Override public String toString() { StringBuilder builder = new StringBuilder(); @@ -66,10 +47,6 @@ public class ProjectView implements Serializable { builder.append(theProjectDV); builder.append(", listSections="); builder.append(listSections); - builder.append(", centroidLong="); - builder.append(centroidLong); - builder.append(", centroidLat="); - builder.append(centroidLat); builder.append("]"); return builder.toString(); }