Concessioni Lifecycle invocation to SDI Materialization Plugin

This commit is contained in:
Fabio Sinibaldi 2022-02-14 15:00:59 +01:00
parent face519810
commit 85ceecda12
5 changed files with 96 additions and 40 deletions

View File

@ -1,5 +1,11 @@
package org.gcube.application.cms.plugins.reports;
import lombok.Data;
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
@Data
public class MaterializationReport extends Report{
private ProfiledDocument resultDocument;
}

View File

@ -3,6 +3,8 @@ package org.gcube.application.cms.plugins.requests;
import lombok.Data;
import org.bson.Document;
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
import org.gcube.application.geoportal.common.model.document.accounting.Context;
import org.gcube.application.geoportal.common.model.document.accounting.User;
import org.gcube.application.geoportal.common.model.profile.Profile;
@Data
@ -22,4 +24,6 @@ public class StepExecutionRequest {
ProfiledDocument document;
String step;
Document callParameters;
User user;
Context context;
}

View File

@ -5,9 +5,11 @@ import org.bson.BsonDocument;
import org.bson.BsonString;
import org.bson.BsonValue;
import org.bson.Document;
import org.gcube.application.cms.plugins.MaterializationPlugin;
import org.gcube.application.cms.plugins.faults.EventException;
import org.gcube.application.cms.plugins.reports.EventExecutionReport;
import org.gcube.application.cms.plugins.reports.*;
import org.gcube.application.cms.plugins.requests.EventExecutionRequest;
import org.gcube.application.cms.plugins.requests.MaterializationRequest;
import org.gcube.application.cms.serialization.Serialization;
import org.gcube.application.cms.custom.gna.concessioni.model.ProfiledConcessione;
import org.gcube.application.cms.plugins.LifecycleManager;
@ -15,8 +17,6 @@ import org.gcube.application.cms.plugins.faults.InitializationException;
import org.gcube.application.cms.plugins.faults.ShutDownException;
import org.gcube.application.cms.plugins.faults.StepException;
import org.gcube.application.cms.plugins.model.PluginDescriptor;
import org.gcube.application.cms.plugins.reports.StepExecutionReport;
import org.gcube.application.cms.plugins.reports.InitializationReport;
import org.gcube.application.cms.plugins.requests.StepExecutionRequest;
import org.gcube.application.geoportal.common.model.document.*;
import org.gcube.application.geoportal.common.model.document.access.Access;
@ -27,6 +27,7 @@ import org.gcube.application.geoportal.common.model.document.lifecycle.Triggered
import org.gcube.application.geoportal.common.model.legacy.report.ConstraintCheck;
import org.gcube.application.geoportal.common.model.rest.Configuration;
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
import org.gcube.application.geoportal.common.utils.Files;
@Slf4j
public class ConcessioniLifeCycleManager implements LifecycleManager {
@ -65,29 +66,28 @@ public class ConcessioniLifeCycleManager implements LifecycleManager {
try {
switch (request.getStep()) {
case StepExecutionRequest.Steps.ON_MATERIALIZE_DOCUMENT: {
// SDI Create Layers
break;
}
case StepExecutionRequest.Steps.ON_DEMATERIALIZE_DOCUMENT: {
// SDI Remove Layers
break;
}
case StepExecutionRequest.Steps.ON_DEINDEX_DOCUMENT: {
// SDI Remove from centroids
break;
}
case StepExecutionRequest.Steps.ON_INDEX_DOCUMENT: {
// SDI Add to centroids
break;
}
case "SUBMIT-FOR-REVIEW" :{
//Checks
//Materialize layers
//Index-confidential
//Notifications
//TODO Checks
//Materialize layers
MaterializationRequest matReq = new MaterializationRequest();
matReq.setDocument(request.getDocument());
matReq.setProfile(request.getProfile());
Document params = new Document();
String workspace = request.getProfile().getId() + request.getContext().getId();
params.put("workspace", Files.fixFilename(workspace));
matReq.setParameters(params);
MaterializationReport matRep = new SDIMaterializerPlugin().materialize(matReq);
if (!matRep.getStatus().equals(Report.Status.OK)) {
info.setLastOperationStatus(LifecycleInformation.Status.ERROR);
for(String msg : matRep.getMessages())
info.addErrorMessage(msg);
}
//TODO Index-confidential
//TODO Notifications
break;
}
@ -98,6 +98,7 @@ public class ConcessioniLifeCycleManager implements LifecycleManager {
}
case "APPROVE DRAFT":{
// Index-published
break;
}
@ -160,11 +161,6 @@ public class ConcessioniLifeCycleManager implements LifecycleManager {
}
// Materialization
private static final void materialize(){
}
// STATIC ROUTINES

View File

@ -1,8 +1,11 @@
package org.gcube.application.cms.concessioni.plugins;
import com.mongodb.util.JSON;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.bson.Document;
import org.gcube.application.cms.concessioni.sdi.SDIManager;
import org.gcube.application.cms.concessioni.sdi.faults.SDIInteractionException;
import org.gcube.application.cms.plugins.MaterializationPlugin;
import org.gcube.application.cms.plugins.faults.InitializationException;
import org.gcube.application.cms.plugins.faults.MaterializationException;
@ -10,16 +13,29 @@ import org.gcube.application.cms.plugins.faults.ShutDownException;
import org.gcube.application.cms.plugins.model.PluginDescriptor;
import org.gcube.application.cms.plugins.reports.InitializationReport;
import org.gcube.application.cms.plugins.reports.MaterializationReport;
import org.gcube.application.cms.plugins.reports.Report;
import org.gcube.application.cms.plugins.requests.MaterializationRequest;
import org.gcube.application.cms.serialization.Serialization;
import org.gcube.application.geoportal.common.model.JSONPathWrapper;
import org.gcube.application.geoportal.common.model.document.filesets.Materialization;
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation;
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
import org.gcube.application.geoportal.common.model.document.filesets.RegisteredFileSet;
import org.gcube.application.geoportal.common.model.profile.Field;
import org.gcube.application.geoportal.common.model.profile.HandlerDeclaration;
import org.gcube.application.geoportal.common.model.profile.Profile;
import java.util.List;
@Slf4j
public class SDIMaterializerPlugin implements MaterializationPlugin {
@Data
public static class MaterializationConfig{
private String schemaField;
private String documentPath;
}
SDIManager sdiManager;
@Override
@ -37,10 +53,19 @@ public class SDIMaterializerPlugin implements MaterializationPlugin {
}
/**
* Expected params :
* -workspace MANDATORY
* -titleField
*
* @param request
* @return
* @throws MaterializationException
*/
@Override
public MaterializationReport materialize(MaterializationRequest request) throws MaterializationException {
log.info("Materializer {} : Performing {} ",this.getDescriptor().getId(),request);
ProfiledDocument doc=request.getDocument();
ProfiledDocument profiledDocument=request.getDocument();
Profile profile = request.getProfile();
Document configuration=request.getParameters();
Document profileConfiguration =null;
@ -50,22 +75,45 @@ public class SDIMaterializerPlugin implements MaterializationPlugin {
}
}
MaterializationReport report= new MaterializationReport();
log.debug("Profile Configuration is {} ",profileConfiguration);
try{
// for each
RegisteredFileSet fileSet=null;
sdiManager.materializeLayer()
JSONPathWrapper documentNavigator=new JSONPathWrapper(profiledDocument.getTheDocument().toJson());
JSONPathWrapper profileNavigator=new JSONPathWrapper(profile.getSchema().toJson());
for(Object fsConfigObj : configuration.get("registeredFileSetPaths", List.class)){
log.debug("Managing {} ",fsConfigObj);
MaterializationConfig fsConfig=Serialization.convert(fsConfigObj,MaterializationConfig.class);
Field f = profileNavigator.getByPath(fsConfig.getSchemaField(), Field.class).get(0);
// TODO Check if schema points to RegisteredFileSet
}catch (MaterializationException e){
throw e;
for(RegisteredFileSet fs : documentNavigator.getByPath(fsConfig.getDocumentPath(),RegisteredFileSet.class)){
log.debug("Found {} ",fs);
configuration.putIfAbsent("basePersistencePath",profile.getId());
configuration.putIfAbsent("documentID",profiledDocument.get_id());
if(configuration.containsKey("titleField"))
configuration.putIfAbsent("layerTitle",fs.getString(configuration.getString("titleField")));
RegisteredFileSet obtained = sdiManager.materializeLayer(fs,configuration);
log.debug("Obtained {} ",obtained);
documentNavigator.set("$..[?(@.uuid == "+fs.getUUID()+")]",obtained);
}
}
profiledDocument.setTheDocument(Document.parse(documentNavigator.getCtx().json()));
report.setResultDocument(profiledDocument);
report.setStatus(Report.Status.OK);
}catch (SDIInteractionException e){
log.error("Unable to materialize "+request,e);
report.setStatus(Report.Status.ERROR);
report.putMessage(e.getMessage());
}catch (Throwable t){
log.error("Unable to execute on event "+request.getEvent(),t);
info.setLastOperationStatus(LifecycleInformation.Status.ERROR);
info.addErrorMessage("Unable to execute on event "+request.getEvent()+". Error was "+t.getMessage());
log.error("Unable to materialize "+request,t);
report.setStatus(Report.Status.ERROR);
report.putMessage(t.getMessage());
}finally{
return report;
}
}

View File

@ -9,6 +9,8 @@ import java.util.List;
@ToString (callSuper = true)
public class RegisteredFileSet extends Document {
public static final String UUID="uuid";
public static final String CREATION_INFO="creationInfo";
public static final String ACCESS="access";