Configurable Multiple handler management
This commit is contained in:
parent
8e6b1e0106
commit
0322042d73
|
@ -3,8 +3,10 @@ package org.gcube.application.cms.plugins;
|
||||||
import org.gcube.application.cms.plugins.Plugin;
|
import org.gcube.application.cms.plugins.Plugin;
|
||||||
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public interface PluginManagerInterface {
|
public interface PluginManagerInterface {
|
||||||
|
|
||||||
public Plugin getById(String pluginID) throws ConfigurationException;
|
public Plugin getById(String pluginID) throws ConfigurationException;
|
||||||
|
public Map<String,Plugin> getByType(String type) throws ConfigurationException;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
import org.gcube.application.cms.plugins.IndexerPluginInterface;
|
import org.gcube.application.cms.plugins.IndexerPluginInterface;
|
||||||
import org.gcube.application.cms.plugins.LifecycleManager;
|
import org.gcube.application.cms.plugins.LifecycleManager;
|
||||||
|
import org.gcube.application.cms.plugins.MaterializationPlugin;
|
||||||
import org.gcube.application.cms.plugins.faults.*;
|
import org.gcube.application.cms.plugins.faults.*;
|
||||||
import org.gcube.application.cms.plugins.implementations.executions.GuardedStepExecution;
|
import org.gcube.application.cms.plugins.implementations.executions.GuardedStepExecution;
|
||||||
import org.gcube.application.cms.plugins.reports.*;
|
import org.gcube.application.cms.plugins.reports.*;
|
||||||
|
@ -48,17 +49,23 @@ public class Default3PhaseManager extends SimpleLifeCycleManager implements Life
|
||||||
@Override
|
@Override
|
||||||
protected EventExecutionReport onDeleteDocument(EventExecutionReport report) throws ConfigurationException, InvalidPluginRequestException, MaterializationException, EventException {
|
protected EventExecutionReport onDeleteDocument(EventExecutionReport report) throws ConfigurationException, InvalidPluginRequestException, MaterializationException, EventException {
|
||||||
report = super.onDeleteDocument(report);
|
report = super.onDeleteDocument(report);
|
||||||
return deIndex(report,getIndexer(),getInternalIndexParams(report.getTheRequest()));
|
for(IndexerPluginInterface indexer : getIndexer(report.getTheRequest()))
|
||||||
|
report= deIndex(report,indexer,getInternalIndexParams(report.getTheRequest()));
|
||||||
|
return report;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected EventExecutionReport onDeleteFileSet(EventExecutionReport theReport) throws ConfigurationException, InvalidPluginRequestException, MaterializationException, EventException {
|
protected EventExecutionReport onDeleteFileSet(EventExecutionReport theReport) throws ConfigurationException, InvalidPluginRequestException, MaterializationException, EventException {
|
||||||
theReport = super.onDeleteFileSet(theReport);
|
theReport = super.onDeleteFileSet(theReport);
|
||||||
String phase = theReport.getTheRequest().getDocument().getLifecycleInformation().getPhase();
|
String phase = theReport.getTheRequest().getDocument().getLifecycleInformation().getPhase();
|
||||||
|
Document parameters = null;
|
||||||
if(phase.equals(Phases.PENDING_APPROVAL))
|
if(phase.equals(Phases.PENDING_APPROVAL))
|
||||||
return index(theReport,getIndexer(),getInternalIndexParams(theReport.getTheRequest()));
|
parameters =getInternalIndexParams(theReport.getTheRequest());
|
||||||
if(phase.equals(Phases.PUBLISHED))
|
if(phase.equals(Phases.PUBLISHED))
|
||||||
return index(theReport,getIndexer(),getPublicIndexParams(theReport.getTheRequest()));
|
parameters = getPublicIndexParams(theReport.getTheRequest());
|
||||||
|
if(parameters!= null)
|
||||||
|
for(IndexerPluginInterface indexer : getIndexer(theReport.getTheRequest()))
|
||||||
|
theReport = index(theReport,indexer,getPublicIndexParams(theReport.getTheRequest()));
|
||||||
return theReport;
|
return theReport;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,11 +76,13 @@ public class Default3PhaseManager extends SimpleLifeCycleManager implements Life
|
||||||
@Override
|
@Override
|
||||||
protected StepExecutionReport run() throws Exception {
|
protected StepExecutionReport run() throws Exception {
|
||||||
// Materialize
|
// Materialize
|
||||||
theReport = materializeDocument(theReport,getMaterializer(),getMaterializationParameters(theReport.getTheRequest()));
|
|
||||||
|
for(MaterializationPlugin mat : getMaterializer(theReport.getTheRequest()))
|
||||||
|
theReport = materializeDocument(theReport,mat,getMaterializationParameters(theReport.getTheRequest()));
|
||||||
if(theReport.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK)){
|
if(theReport.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK)){
|
||||||
// Index
|
// Index
|
||||||
theReport = index(theReport,getIndexer(),
|
for(IndexerPluginInterface indexer : getIndexer(theReport.getTheRequest()))
|
||||||
getInternalIndexParams(theReport.getTheRequest()));
|
theReport = index(theReport,indexer,getInternalIndexParams(theReport.getTheRequest()));
|
||||||
// setPhase
|
// setPhase
|
||||||
if(theReport.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK))
|
if(theReport.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK))
|
||||||
theReport.getToSetLifecycleInformation().setPhase(Phases.PENDING_APPROVAL);
|
theReport.getToSetLifecycleInformation().setPhase(Phases.PENDING_APPROVAL);
|
||||||
|
@ -87,8 +96,8 @@ public class Default3PhaseManager extends SimpleLifeCycleManager implements Life
|
||||||
@Override
|
@Override
|
||||||
protected StepExecutionReport run() throws Exception {
|
protected StepExecutionReport run() throws Exception {
|
||||||
// Index
|
// Index
|
||||||
theReport = index(theReport,getIndexer(),
|
for(IndexerPluginInterface indexer : getIndexer(theReport.getTheRequest()))
|
||||||
getPublicIndexParams(theReport.getTheRequest()));
|
theReport = index(theReport,indexer,getPublicIndexParams(theReport.getTheRequest()));
|
||||||
// setPhase
|
// setPhase
|
||||||
if(theReport.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK))
|
if(theReport.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK))
|
||||||
theReport.getToSetLifecycleInformation().setPhase(Phases.PUBLISHED);
|
theReport.getToSetLifecycleInformation().setPhase(Phases.PUBLISHED);
|
||||||
|
|
|
@ -15,12 +15,17 @@ import org.gcube.application.geoportal.common.model.configuration.Configuration;
|
||||||
import org.gcube.application.geoportal.common.model.configuration.Index;
|
import org.gcube.application.geoportal.common.model.configuration.Index;
|
||||||
import org.gcube.application.geoportal.common.model.document.filesets.RegisteredFileSet;
|
import org.gcube.application.geoportal.common.model.document.filesets.RegisteredFileSet;
|
||||||
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation;
|
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation;
|
||||||
|
import org.gcube.application.geoportal.common.model.plugins.IndexerPluginDescriptor;
|
||||||
|
import org.gcube.application.geoportal.common.model.plugins.MaterializerPluginDescriptor;
|
||||||
import org.gcube.application.geoportal.common.model.plugins.OperationDescriptor;
|
import org.gcube.application.geoportal.common.model.plugins.OperationDescriptor;
|
||||||
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||||
|
import org.gcube.application.geoportal.common.model.useCaseDescriptor.HandlerDeclaration;
|
||||||
|
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
|
||||||
import org.gcube.application.geoportal.common.utils.Files;
|
import org.gcube.application.geoportal.common.utils.Files;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class SimpleLifeCycleManager extends AbstractLifeCycleManager implements LifecycleManager {
|
public class SimpleLifeCycleManager extends AbstractLifeCycleManager implements LifecycleManager {
|
||||||
|
@ -85,17 +90,18 @@ public class SimpleLifeCycleManager extends AbstractLifeCycleManager implements
|
||||||
setStep(new GuardedStepExecution(Steps.PUBLISH) {
|
setStep(new GuardedStepExecution(Steps.PUBLISH) {
|
||||||
@Override
|
@Override
|
||||||
protected StepExecutionReport run() throws Exception {
|
protected StepExecutionReport run() throws Exception {
|
||||||
if(!theReport.getTheRequest().getDocument().getLifecycleInformation().getPhase().equals(LifecycleInformation.CommonPhases.DRAFT_PHASE))
|
//Check Performed by Guarded Step Execution
|
||||||
throw new StepException("Document is not in "+LifecycleInformation.CommonPhases.DRAFT_PHASE+" phase");
|
// if(!theReport.getTheRequest().getDocument().getLifecycleInformation().getPhase().equals(LifecycleInformation.CommonPhases.DRAFT_PHASE))
|
||||||
|
// throw new StepException("Document is not in "+LifecycleInformation.CommonPhases.DRAFT_PHASE+" phase");
|
||||||
|
|
||||||
// Materialize
|
// Materialize
|
||||||
theReport = materializeDocument(theReport, getMaterializer(),
|
for(MaterializationPlugin mat : getMaterializer(theReport.getTheRequest()))
|
||||||
getMaterializationParameters(theReport.getTheRequest()));
|
theReport = materializeDocument(theReport, mat, getMaterializationParameters(theReport.getTheRequest()));
|
||||||
|
|
||||||
if(theReport.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK)){
|
if(theReport.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK)){
|
||||||
// Index
|
// Index
|
||||||
theReport = index(theReport,getIndexer(),
|
for(IndexerPluginInterface indexer : getIndexer(theReport.getTheRequest()))
|
||||||
getPublicIndexParams(theReport.getTheRequest()));
|
theReport = index(theReport,indexer,getPublicIndexParams(theReport.getTheRequest()));
|
||||||
// setPhase
|
// setPhase
|
||||||
if(theReport.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK))
|
if(theReport.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK))
|
||||||
theReport.getToSetLifecycleInformation().setPhase("PUBLISHED");
|
theReport.getToSetLifecycleInformation().setPhase("PUBLISHED");
|
||||||
|
@ -133,12 +139,14 @@ public class SimpleLifeCycleManager extends AbstractLifeCycleManager implements
|
||||||
JSONPathWrapper wrapper = new JSONPathWrapper(report.getTheRequest().getDocument().getTheDocument().toJson());
|
JSONPathWrapper wrapper = new JSONPathWrapper(report.getTheRequest().getDocument().getTheDocument().toJson());
|
||||||
for (String s : wrapper.getMatchingPaths("..*[?(@." + RegisteredFileSet.PAYLOADS + ")]")){
|
for (String s : wrapper.getMatchingPaths("..*[?(@." + RegisteredFileSet.PAYLOADS + ")]")){
|
||||||
log.info("Requesting dematerialization for {} ",s);
|
log.info("Requesting dematerialization for {} ",s);
|
||||||
report = deMaterialize(report,getMaterializer(),new Document("fileSetPath",s));
|
for(MaterializationPlugin mat : getMaterializer(report.getTheRequest()))
|
||||||
|
report = deMaterialize(report,mat,new Document("fileSetPath",s));
|
||||||
if(!report.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK))
|
if(!report.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(report.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK)) {
|
if(report.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK)) {
|
||||||
report = deIndex(report,getIndexer(),getPublicIndexParams(report.getTheRequest()));
|
for(IndexerPluginInterface indexer : getIndexer(report.getTheRequest()))
|
||||||
|
report = deIndex(report,indexer,getPublicIndexParams(report.getTheRequest()));
|
||||||
}
|
}
|
||||||
return report;
|
return report;
|
||||||
}
|
}
|
||||||
|
@ -147,11 +155,13 @@ public class SimpleLifeCycleManager extends AbstractLifeCycleManager implements
|
||||||
protected EventExecutionReport onDeleteFileSet(EventExecutionReport theReport) throws ConfigurationException, InvalidPluginRequestException, MaterializationException, EventException {
|
protected EventExecutionReport onDeleteFileSet(EventExecutionReport theReport) throws ConfigurationException, InvalidPluginRequestException, MaterializationException, EventException {
|
||||||
// dematerialize selected
|
// dematerialize selected
|
||||||
blockNonDraft(theReport);
|
blockNonDraft(theReport);
|
||||||
deMaterialize(theReport,getMaterializer(),
|
for(MaterializationPlugin mat : getMaterializer(theReport.getTheRequest()))
|
||||||
theReport.getTheRequest().getCallParameters());
|
deMaterialize(theReport,mat,
|
||||||
|
theReport.getTheRequest().getCallParameters());
|
||||||
// de index
|
// de index
|
||||||
if(theReport.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK))
|
for(IndexerPluginInterface indexer : getIndexer(theReport.getTheRequest()))
|
||||||
deIndex(theReport,getIndexer(),getPublicIndexParams(theReport.getTheRequest()));
|
if(theReport.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK))
|
||||||
|
deIndex(theReport,indexer,getPublicIndexParams(theReport.getTheRequest()));
|
||||||
return theReport;
|
return theReport;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,12 +172,22 @@ public class SimpleLifeCycleManager extends AbstractLifeCycleManager implements
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected IndexerPluginInterface getIndexer() throws ConfigurationException {
|
protected List<IndexerPluginInterface> getIndexer(BaseRequest request) throws ConfigurationException {
|
||||||
return (IndexerPluginInterface) pluginManager.getById("SDI-Indexer-Plugin");
|
ArrayList<IndexerPluginInterface> toReturn=new ArrayList<>();
|
||||||
|
UseCaseDescriptor desc = request.getUseCaseDescriptor();
|
||||||
|
List<HandlerDeclaration> indexers = desc.getHandlersMapByType().get(IndexerPluginDescriptor.INDEXER);
|
||||||
|
for (HandlerDeclaration handlerDeclaration : indexers)
|
||||||
|
toReturn.add((IndexerPluginInterface) pluginManager.getById(handlerDeclaration.getId()));
|
||||||
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected MaterializationPlugin getMaterializer() throws ConfigurationException {
|
protected List<MaterializationPlugin> getMaterializer(BaseRequest request) throws ConfigurationException {
|
||||||
return (MaterializationPlugin) pluginManager.getById("SDI-Default-Materializer");
|
ArrayList<MaterializationPlugin> toReturn=new ArrayList<>();
|
||||||
|
UseCaseDescriptor desc = request.getUseCaseDescriptor();
|
||||||
|
List<HandlerDeclaration> materializers = desc.getHandlersMapByType().get(MaterializerPluginDescriptor.MATERIALIZER);
|
||||||
|
for (HandlerDeclaration handlerDeclaration : materializers)
|
||||||
|
toReturn.add((MaterializationPlugin) pluginManager.getById(handlerDeclaration.getId()));
|
||||||
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected <T extends DocumentHandlingReport> T deIndex(T report, IndexerPluginInterface indexer, Document parameters) throws InvalidPluginRequestException {
|
protected <T extends DocumentHandlingReport> T deIndex(T report, IndexerPluginInterface indexer, Document parameters) throws InvalidPluginRequestException {
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
package org.gcube.application.cms.commons.model;
|
package org.gcube.application.cms.commons.model;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
public class Serialization {
|
public class Serialization {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSerializations(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import org.gcube.application.geoportal.common.utils.ContextUtils;
|
||||||
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class PluginManager extends AbstractScopedMap<PluginManager.PluginMap> implements PluginManagerInterface {
|
public class PluginManager extends AbstractScopedMap<PluginManager.PluginMap> implements PluginManagerInterface {
|
||||||
|
@ -128,4 +129,15 @@ public class PluginManager extends AbstractScopedMap<PluginManager.PluginMap> im
|
||||||
log.warn("Invalid report provided by {} ",p.getDescriptor().getId(),e);
|
log.warn("Invalid report provided by {} ",p.getDescriptor().getId(),e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Plugin> getByType(String type) throws ConfigurationException {
|
||||||
|
HashMap<String,Plugin> toReturn = new HashMap<>();
|
||||||
|
getObject().forEach((s, plugin) -> {
|
||||||
|
if (plugin!=null&&plugin.getDescriptor().getType().equals(type))
|
||||||
|
toReturn.put(s,plugin);
|
||||||
|
});
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,6 +133,7 @@ public class SDIIndexerPlugin extends SDIAbstractPlugin implements IndexerPlugin
|
||||||
|
|
||||||
log.debug("Using user defined spatial reference " + reference);
|
log.debug("Using user defined spatial reference " + reference);
|
||||||
|
|
||||||
|
|
||||||
GeoJsonObject object = Serialization.convert(reference.getGeoJson(), GeoJsonObject.class);
|
GeoJsonObject object = Serialization.convert(reference.getGeoJson(), GeoJsonObject.class);
|
||||||
|
|
||||||
GCubeSDILayer.BBOX bbox = GCubeSDILayer.BBOX.fromGeoJSON(object.getBbox());
|
GCubeSDILayer.BBOX bbox = GCubeSDILayer.BBOX.fromGeoJSON(object.getBbox());
|
||||||
|
|
Loading…
Reference in New Issue