Identification References

This commit is contained in:
Fabio Sinibaldi 2022-04-11 17:23:27 +02:00
parent 2e6fa21426
commit d6521900b5
15 changed files with 187 additions and 67 deletions

View File

@ -228,7 +228,7 @@ public class SimpleLifeCycleManager extends AbstractLifeCycleManager implements
case OK : {
info.setLastOperationStatus(LifecycleInformation.Status.OK);
if(toHandle instanceof IndexDocumentReport)
toUpdate.setToSetSpatialReference(((IndexDocumentReport)toHandle).getToSetSpatialReference());
toUpdate.setToSetIdentificationReferences(((IndexDocumentReport)toHandle).getToSetIdentificationReferences());
// Propagate changes for further processings
toUpdate.getTheRequest().getDocument().setTheDocument(toHandle.getResultingDocument());
toUpdate.setToSetLifecycleInformation(toHandle.getToSetLifecycleInformation());

View File

@ -9,8 +9,12 @@ import org.gcube.application.cms.plugins.faults.InvalidPluginRequestException;
import org.gcube.application.cms.plugins.faults.PluginExecutionException;
import org.gcube.application.cms.plugins.requests.BaseExecutionRequest;
import org.gcube.application.geoportal.common.model.document.Project;
import org.gcube.application.geoportal.common.model.document.identification.IdentificationReference;
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation;
import org.gcube.application.geoportal.common.model.document.temporal.TemporalReference;
import org.gcube.application.geoportal.common.model.document.identification.TemporalReference;
import java.util.ArrayList;
import java.util.List;
@Data
@ -23,9 +27,13 @@ public class DocumentHandlingReport<T extends BaseExecutionRequest> extends Repo
Document resultingDocument;
LifecycleInformation toSetLifecycleInformation;
protected List<IdentificationReference> toSetIdentificationReferences=null;
TemporalReference toSetTemporalReference;
Document toSetSpatialReference;
public DocumentHandlingReport<T> addIdentificationReference(IdentificationReference toAdd){
if(toSetIdentificationReferences == null) toSetIdentificationReferences = new ArrayList<>();
toSetIdentificationReferences.add(toAdd);
return this;
}
public DocumentHandlingReport(@NonNull T theRequest) throws InvalidPluginRequestException {
@ -77,8 +85,8 @@ public class DocumentHandlingReport<T extends BaseExecutionRequest> extends Repo
break;
}
}
if(toSetSpatialReference != null) toReturn.setSpatialReference(toSetSpatialReference);
if(toSetTemporalReference != null) toReturn.setTemporalReference(toSetTemporalReference);
if(toSetIdentificationReferences!=null)
toReturn.setIdentificationReferences(toSetIdentificationReferences);
return toReturn;
}
}

View File

@ -9,25 +9,28 @@ import org.gcube.application.cms.plugins.faults.InvalidPluginRequestException;
import org.gcube.application.cms.plugins.faults.PluginExecutionException;
import org.gcube.application.cms.plugins.requests.IndexDocumentRequest;
import org.gcube.application.geoportal.common.model.document.Project;
import org.gcube.application.geoportal.common.model.document.temporal.TemporalReference;
import org.gcube.application.geoportal.common.model.document.identification.IdentificationReference;
import org.gcube.application.geoportal.common.model.document.identification.TemporalReference;
import java.util.ArrayList;
import java.util.List;
@Getter
@Setter
public class IndexDocumentReport extends DocumentHandlingReport<IndexDocumentRequest> {
public TemporalReference toSetTemporalReference;
public Document toSetSpatialReference;
// protected List<IdentificationReference> toSetIndexReferences=new ArrayList<>();
public IndexDocumentReport(@NonNull IndexDocumentRequest theRequest) throws InvalidPluginRequestException {
super(theRequest);
}
@Override
public Project prepareResult() throws JsonProcessingException, PluginExecutionException {
Project toReturn= super.prepareResult();
if(toSetSpatialReference != null) toReturn.setSpatialReference(toSetSpatialReference);
if(toSetTemporalReference != null) toReturn.setTemporalReference(toSetTemporalReference);
return toReturn;
}
// @Override
// public Project prepareResult() throws JsonProcessingException, PluginExecutionException {
// Project toReturn= super.prepareResult();
// if(toSetSpatialReference != null) toReturn.setSpatialReference(toSetSpatialReference);
// if(toSetTemporalReference != null) toReturn.setTemporalReference(toSetTemporalReference);
// return toReturn;
// }
}

View File

@ -2,13 +2,11 @@ package org.gcube.application.cms.plugins.reports;
import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.*;
import org.bson.Document;
import org.gcube.application.cms.plugins.faults.InvalidPluginRequestException;
import org.gcube.application.cms.plugins.faults.PluginExecutionException;
import org.gcube.application.cms.plugins.requests.EventExecutionRequest;
import org.gcube.application.cms.plugins.requests.StepExecutionRequest;
import org.gcube.application.geoportal.common.model.document.Project;
import org.gcube.application.geoportal.common.model.document.temporal.TemporalReference;
import java.util.ArrayList;
import java.util.List;

View File

@ -1,15 +1,18 @@
package org.gcube.application.geoportal.common.model.document;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.vdurmont.semver4j.Semver;
import lombok.*;
import org.bson.Document;
import org.gcube.application.geoportal.common.model.document.accounting.PublicationInfo;
import org.gcube.application.geoportal.common.model.document.identification.IdentificationReference;
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation;
import org.gcube.application.geoportal.common.model.document.temporal.TemporalReference;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@NoArgsConstructor
@ -26,8 +29,7 @@ public class Project {
public static final String PROFILE_VERSION="_profileVersion";
public static final String LIFECYCLE_INFORMATION="_lifecycleInformation";
public static final String RELATIONSHIPS="_relationships";
public static final String SPATIAL_REFERENCE="_spatialReference";
public static final String TEMPORAL_REFERENCE="_temporalReference";
public static final String IDENTIFICATION_REFERENCES="_identificationReferences";
public static final String THE_DOCUMENT="_theDocument";
public static final String LOCK="_lock";
@ -52,14 +54,10 @@ public class Project {
private LifecycleInformation lifecycleInformation;
@JsonProperty(RELATIONSHIPS)
private Relationship[] relationships;
private List<Relationship> relationships;
// Expected GEOJSON
@JsonProperty(SPATIAL_REFERENCE)
private Document spatialReference;
@JsonProperty(TEMPORAL_REFERENCE)
private TemporalReference temporalReference;
@JsonProperty(IDENTIFICATION_REFERENCES)
private List<IdentificationReference> identificationReferences;
@JsonProperty(THE_DOCUMENT)
private Document theDocument;
@ -79,6 +77,15 @@ public class Project {
if (this == o) return true;
if (!(o instanceof Project)) return false;
Project project = (Project) o;
return Objects.equals(getId(), project.getId()) && Objects.equals(getVersion(), project.getVersion()) && Objects.equals(getInfo(), project.getInfo()) && Objects.equals(getProfileID(), project.getProfileID()) && Objects.equals(getProfileVersion(), project.getProfileVersion()) && Objects.equals(getLifecycleInformation(), project.getLifecycleInformation()) && Arrays.equals(getRelationships(), project.getRelationships()) && Objects.equals(getSpatialReference(), project.getSpatialReference()) && Objects.equals(getTemporalReference(), project.getTemporalReference()) && Objects.equals(getTheDocument(), project.getTheDocument());
return Objects.equals(getId(), project.getId()) && Objects.equals(getVersion(), project.getVersion()) && Objects.equals(getInfo(), project.getInfo()) && Objects.equals(getProfileID(), project.getProfileID()) && Objects.equals(getProfileVersion(), project.getProfileVersion()) && Objects.equals(getLifecycleInformation(), project.getLifecycleInformation()) && Objects.equals(getIdentificationReferences(), project.getIdentificationReferences()) && Objects.equals(getRelationships(), project.getRelationships()) && Objects.equals(getTheDocument(), project.getTheDocument());
}
@JsonIgnore
public List<IdentificationReference> getIdentificationReferenceByType(String type){
if(identificationReferences==null) return Collections.emptyList();
else return identificationReferences.stream()
.filter(item -> item.getType().equals(type)).collect(Collectors.toList());
};
}

View File

@ -12,10 +12,13 @@ public class Relationship {
public static final String RELATIONSHIP_NAME="_relationshipName";
public static final String TARGET_ID="_targetID";
public static final String TARGET_UCD="_targetUCD";
@JsonProperty(RELATIONSHIP_NAME)
private String relationshipName;
@JsonProperty(TARGET_ID)
private String targetID;
@JsonProperty(TARGET_ID)
private String targetUCD;
}

View File

@ -0,0 +1,7 @@
package org.gcube.application.geoportal.common.model.document.identification;
public class CentroidRecordReference extends IdentificationReference{
public static final String CENTROID_RECORD_REFERENCE="CENTROID_RECORD_TYPE";
}

View File

@ -0,0 +1,22 @@
package org.gcube.application.geoportal.common.model.document.identification;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.bson.Document;
@ToString(callSuper = true)
@NoArgsConstructor
public class IdentificationReference extends Document {
public static final String TYPE="_type";
public IdentificationReference(String type) {
setType(type);
}
@JsonIgnore
public String getType(){return super.getString(TYPE);}
@JsonIgnore
public void setType(String type){super.put(TYPE,type);}
}

View File

@ -0,0 +1,24 @@
package org.gcube.application.geoportal.common.model.document.identification;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.NoArgsConstructor;
import lombok.ToString;
@NoArgsConstructor
@ToString(callSuper = true)
public class SpatialReference extends IdentificationReference{
public static final String SPATIAL_REFERENCE_TYPE="SPATIAL REFERENCE";
public static final String GEO_JSON="geoJSON";
public SpatialReference(Object geoJSON) {
setGeoJson(geoJSON);
setType(SPATIAL_REFERENCE_TYPE);
}
@JsonIgnore
public Object getGeoJson(){return super.get(GEO_JSON);}
@JsonIgnore
public Object setGeoJson(Object geoJSON){return super.put(GEO_JSON,geoJSON);}
}

View File

@ -0,0 +1,10 @@
package org.gcube.application.geoportal.common.model.document.identification;
import lombok.*;
import org.bson.Document;
@ToString (callSuper = true)
public class TemporalReference extends IdentificationReference {
public static final String TEMPORAL_REFERENCE_TYPE="TEMPORAL_REFERENCE_TYPE";
}

View File

@ -1,14 +0,0 @@
package org.gcube.application.geoportal.common.model.document.temporal;
import lombok.*;
import org.bson.Document;
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@ToString
public class TemporalReference extends Document {
private String field;
}

View File

@ -3,6 +3,7 @@ package org.gcube.application.geoportal.service.profiledDocuments;
import org.bson.Document;
import org.gcube.application.cms.serialization.Serialization;
import org.gcube.application.geoportal.common.model.document.Project;
import org.gcube.application.geoportal.common.model.document.identification.SpatialReference;
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation;
import org.gcube.application.geoportal.common.model.useCaseDescriptor.Field;
import org.gcube.application.geoportal.common.model.rest.RegisterFileSetRequest;
@ -67,7 +68,7 @@ public class ProfiledConcessioniTests extends AbstractProfiledDocumentsTests{
doc=step(doc.getId(),approveDraftReq);
System.out.println(doc);
assertTrue(doc.getLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK));
assertTrue(doc.getSpatialReference()!=null);
System.out.println("Project "+doc.getId()+" published with spatial reference "+doc.getSpatialReference().toJson());
assertTrue(doc.getIdentificationReferenceByType(SpatialReference.SPATIAL_REFERENCE_TYPE).size()==1);
System.out.println("Project "+doc.getId()+" published with spatial reference "+doc.getIdentificationReferenceByType(SpatialReference.SPATIAL_REFERENCE_TYPE).get(0));
}
}

View File

@ -10,6 +10,8 @@ import org.gcube.application.cms.plugins.faults.InitializationException;
import org.gcube.application.cms.plugins.faults.InvalidPluginRequestException;
import org.gcube.application.cms.plugins.faults.InvalidProfileException;
import org.gcube.application.cms.plugins.model.ComparableVersion;
import org.gcube.application.geoportal.common.model.document.identification.IdentificationReference;
import org.gcube.application.geoportal.common.model.document.identification.SpatialReference;
import org.gcube.application.geoportal.common.model.plugins.IndexerPluginDescriptor;
import org.gcube.application.geoportal.common.model.plugins.PluginDescriptor;
import org.gcube.application.cms.plugins.reports.IndexDocumentReport;
@ -121,25 +123,32 @@ public class SDIIndexerPlugin extends SDIAbstractPlugin implements IndexerPlugin
// ********************** EVALAUTE POSITION
log.debug("indexing UseCaseDescriptor {} : Evaluating Centroid... ", useCaseDescriptor.getId());
if(project.getSpatialReference()!=null){
log.debug("Using user defined spatial reference "+ project.getSpatialReference());
SpatialReference reference =null;
List<IdentificationReference> refs=project.getIdentificationReferenceByType(SpatialReference.SPATIAL_REFERENCE_TYPE);
if(!refs.isEmpty()){
GeoJsonObject object = Serialization.convert(project.getSpatialReference(), GeoJsonObject.class);
// Use existing Reference
GCubeSDILayer.BBOX bbox= GCubeSDILayer.BBOX.fromGeoJSON( object.getBbox());
reference = Serialization.convert(refs.get(0), SpatialReference.class);
log.info("Found declared BBOX {} ",bbox);
Double pointX=(bbox.getMaxX()-bbox.getMinX());
Double pointY = bbox.getMaxY()-bbox.getMinY();
String wkt = String .format("POINT (%1$f %2$f) ",
log.debug("Using user defined spatial reference " + reference);
GeoJsonObject object = Serialization.convert(reference.getGeoJson(), GeoJsonObject.class);
GCubeSDILayer.BBOX bbox = GCubeSDILayer.BBOX.fromGeoJSON(object.getBbox());
log.info("Found declared BBOX {} ", bbox);
Double pointX = (bbox.getMaxX() - bbox.getMinX());
Double pointY = bbox.getMaxY() - bbox.getMinY();
String wkt = String.format("POINT (%1$f %2$f) ",
pointX, pointY);
centroidDoc.put("geom",wkt);
centroidDoc.put("geom", wkt);
throw new Exception("Not yet implemented");
}else {
} else{
// unable to use current Spatial reference, try evaluating it
log.debug("UseCaseDescriptor {} : Getting evaluation paths from useCaseDescriptor.. ", useCaseDescriptor.getId());
List bboxEvaluationPaths = profileConfiguration.get("bboxEvaluation",List.class);
if(bboxEvaluationPaths==null || bboxEvaluationPaths.isEmpty())
@ -166,7 +175,6 @@ public class SDIIndexerPlugin extends SDIAbstractPlugin implements IndexerPlugin
if(toSet == null)
throw new IndexingException("No BBOX has been found on paths : "+bboxEvaluationPaths);
Double pointX=(toSet.getMaxX()-toSet.getMinX());
Double pointY = toSet.getMaxY()-toSet.getMinY();
log.info("Evaluated BBOX {} ",toSet);
@ -176,14 +184,15 @@ public class SDIIndexerPlugin extends SDIAbstractPlugin implements IndexerPlugin
centroidDoc.put("geom",wkt);
Point toSetSpatialReference = new Point();
Point toSetgeoJSON = new Point();
LngLatAlt pointCoordinates = new LngLatAlt();
pointCoordinates.setLongitude(pointX);
pointCoordinates.setLatitude(pointY);
toSetSpatialReference.setCoordinates(pointCoordinates);
toSetgeoJSON.setCoordinates(pointCoordinates);
toSetgeoJSON.setBbox(toSet.asGeoJSONArray());
reference = new SpatialReference(toSetgeoJSON);
toSetSpatialReference.setBbox(toSet.asGeoJSONArray());
report.setToSetSpatialReference(Serialization.asDocument(toSetSpatialReference));
report.addIdentificationReference(reference);
}
@ -288,7 +297,7 @@ public class SDIIndexerPlugin extends SDIAbstractPlugin implements IndexerPlugin
fields.add(new PostgisTable.Field(m.getName(), PostgisTable.FieldType.valueOf(m.getType())));
});
return fields;
return fields;
}

View File

@ -18,6 +18,7 @@ import org.gcube.application.geoportal.common.model.document.Project;
import org.gcube.application.geoportal.common.model.document.filesets.sdi.GCubeSDILayer;
import org.gcube.application.geoportal.common.model.document.filesets.Materialization;
import org.gcube.application.geoportal.common.model.document.filesets.sdi.GeoServerPlatform;
import org.gcube.application.geoportal.common.model.document.identification.SpatialReference;
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
import org.gcube.application.geoportal.common.utils.Files;
@ -50,7 +51,7 @@ public class IndexerTest extends BasicPluginTest {
System.out.println("Response is "+Serialization.write(response));
assertTrue(response.getStatus().equals(Report.Status.OK));
assertTrue(response.prepareResult().getSpatialReference()!=null);
assertTrue(response.prepareResult().getIdentificationReferenceByType(SpatialReference.SPATIAL_REFERENCE_TYPE).size()==1);
}

View File

@ -0,0 +1,41 @@
{
"_id" : "MOSI",
"_version" : "1.0.0",
"_name" : "GNA : MOSI",
"_description" : "Modulistica siti",
"_creationInfo": {
"_user" : {
"_username": "fabio.sinibaldi"
}
},
"_schema" :{ "title" : {"_min" : 1},
"section" : { "_max" : 1, "_min" : 1,
"_children" : [
{"fileset" :{"_type" : "RegisteredFileSet", "_min": 1}},
{"title" : {"_min" : 1}}
]
}
},
"_dataAccessPolicies" : [
{"_policy" : {"_read" : "own", "_write" : "own"}, "_roles":[]},
{"_policy" : {"_read" : "any", "_write" : "none"}, "_roles":["Guest"],
"_enforcer": {"_filter" : "{\"_lifecycleInformation._phase\" : {\"$eq\" : \"PUBLISHED\"}}"}},
{"_policy" : {"_read" : "any", "_write" : "none"}, "_roles":["Editor"]},
{"_policy" : {"_read" : "any", "_write" : "any"}, "_roles":["Admin"]}
],
"_handlers" : [
{
"_id" : "DEFAULT-SINGLE-STEP",
"_type" : "LifecycleManagement",
"_configuration" : {
"step_access" : [
{"STEP" : "PUBLISH", "roles" :[]}
]
}
}
]
}