Base Requests
This commit is contained in:
parent
eaf8ade867
commit
49cb279664
|
@ -1,11 +1,18 @@
|
|||
package org.gcube.application.cms.plugins;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.gcube.application.cms.plugins.faults.InvalidPluginRequestException;
|
||||
import org.gcube.application.cms.plugins.reports.IndexDocumentReport;
|
||||
import org.gcube.application.cms.plugins.requests.BaseRequest;
|
||||
import org.gcube.application.cms.plugins.requests.IndexDocumentRequest;
|
||||
import org.gcube.application.geoportal.common.model.configuration.Index;
|
||||
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
|
||||
|
||||
public interface IndexerPluginInterface extends InitializablePlugin{
|
||||
|
||||
public IndexDocumentReport index(IndexDocumentRequest request) throws InvalidPluginRequestException;
|
||||
|
||||
public Index getIndex(BaseRequest request) throws ConfigurationException;
|
||||
|
||||
}
|
||||
|
|
|
@ -5,10 +5,12 @@ import org.gcube.application.cms.plugins.faults.InvalidPluginRequestException;
|
|||
import org.gcube.application.cms.plugins.faults.StepException;
|
||||
import org.gcube.application.cms.plugins.reports.EventExecutionReport;
|
||||
import org.gcube.application.cms.plugins.reports.StepExecutionReport;
|
||||
import org.gcube.application.cms.plugins.requests.BaseRequest;
|
||||
import org.gcube.application.cms.plugins.requests.EventExecutionRequest;
|
||||
import org.gcube.application.cms.plugins.requests.StepExecutionRequest;
|
||||
import org.gcube.application.geoportal.common.model.configuration.Configuration;
|
||||
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
|
||||
|
||||
|
||||
public interface LifecycleManager extends InitializablePlugin{
|
||||
|
@ -17,7 +19,7 @@ public interface LifecycleManager extends InitializablePlugin{
|
|||
|
||||
public StepExecutionReport performStep(StepExecutionRequest request) throws StepException, InvalidPluginRequestException;
|
||||
|
||||
public Configuration getCurrentConfiguration() throws ConfigurationException;
|
||||
public Configuration getCurrentConfiguration(BaseRequest request) throws ConfigurationException;
|
||||
|
||||
public EventExecutionReport onEvent(EventExecutionRequest request) throws EventException, InvalidPluginRequestException;
|
||||
|
||||
|
|
|
@ -1,29 +1,28 @@
|
|||
package org.gcube.application.cms.plugins.requests;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.*;
|
||||
import org.bson.Document;
|
||||
import org.gcube.application.cms.plugins.faults.InvalidPluginRequestException;
|
||||
import org.gcube.application.geoportal.common.model.document.Project;
|
||||
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.useCaseDescriptor.UseCaseDescriptor;
|
||||
|
||||
@Data
|
||||
public class BaseExecutionRequest {
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString(callSuper = true)
|
||||
public class BaseExecutionRequest extends BaseRequest{
|
||||
|
||||
|
||||
UseCaseDescriptor useCaseDescriptor;
|
||||
Project document;
|
||||
Document callParameters;
|
||||
|
||||
public final String getMandatory(String param) throws InvalidPluginRequestException {
|
||||
return getMandatory(param,callParameters);
|
||||
}
|
||||
|
||||
public static final String getMandatory(String param,Document params) throws InvalidPluginRequestException {
|
||||
if(!params.containsKey(param)) throw new InvalidPluginRequestException("Missing mandatory parameter "+param);
|
||||
return params.getString(param);
|
||||
public BaseExecutionRequest(@NonNull UseCaseDescriptor useCaseDescriptor, @NonNull User caller, @NonNull Context context, Project document) {
|
||||
super(useCaseDescriptor, caller, context);
|
||||
this.document = document;
|
||||
}
|
||||
|
||||
public void validate() throws InvalidPluginRequestException {
|
||||
if(useCaseDescriptor ==null)throw new InvalidPluginRequestException("UseCaseDescriptor cannot be null ");
|
||||
super.validate();
|
||||
if(document==null) throw new InvalidPluginRequestException("Document cannot be null");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package org.gcube.application.cms.plugins.requests;
|
||||
|
||||
import lombok.*;
|
||||
import org.bson.Document;
|
||||
import org.gcube.application.cms.plugins.faults.InvalidPluginRequestException;
|
||||
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.useCaseDescriptor.UseCaseDescriptor;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString(callSuper = true)
|
||||
@RequiredArgsConstructor
|
||||
public class BaseRequest {
|
||||
|
||||
@NonNull
|
||||
UseCaseDescriptor useCaseDescriptor;
|
||||
@NonNull
|
||||
User caller;
|
||||
@NonNull
|
||||
Context context;
|
||||
|
||||
|
||||
Document callParameters;
|
||||
|
||||
public final String getMandatory(String param) throws InvalidPluginRequestException {
|
||||
return getMandatory(param,callParameters);
|
||||
}
|
||||
|
||||
public static final String getMandatory(String param,Document params) throws InvalidPluginRequestException {
|
||||
if(!params.containsKey(param)) throw new InvalidPluginRequestException("Missing mandatory parameter "+param);
|
||||
return params.getString(param);
|
||||
}
|
||||
|
||||
public void validate() throws InvalidPluginRequestException {
|
||||
if(useCaseDescriptor ==null)throw new InvalidPluginRequestException("UseCaseDescriptor cannot be null ");
|
||||
}
|
||||
|
||||
}
|
|
@ -1,9 +1,13 @@
|
|||
package org.gcube.application.cms.plugins.requests;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
import lombok.*;
|
||||
import org.gcube.application.geoportal.common.model.document.Project;
|
||||
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.useCaseDescriptor.UseCaseDescriptor;
|
||||
|
||||
@Data
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString(callSuper = true)
|
||||
public class EventExecutionRequest extends BaseExecutionRequest{
|
||||
|
||||
|
@ -13,6 +17,10 @@ public class EventExecutionRequest extends BaseExecutionRequest{
|
|||
public static final String ON_DELETE_DOCUMENT="@@@DELETE_DOCUMENT@@";
|
||||
}
|
||||
|
||||
public EventExecutionRequest(@NonNull UseCaseDescriptor useCaseDescriptor, @NonNull User caller, @NonNull Context context, Project document, String event) {
|
||||
super(useCaseDescriptor, caller, context, document);
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
String event;
|
||||
|
||||
|
|
|
@ -1,8 +1,15 @@
|
|||
package org.gcube.application.cms.plugins.requests;
|
||||
|
||||
import lombok.NonNull;
|
||||
import lombok.ToString;
|
||||
import org.gcube.application.geoportal.common.model.document.Project;
|
||||
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.useCaseDescriptor.UseCaseDescriptor;
|
||||
|
||||
@ToString(callSuper = true)
|
||||
public class IndexDocumentRequest extends BaseExecutionRequest{
|
||||
|
||||
public IndexDocumentRequest(@NonNull UseCaseDescriptor useCaseDescriptor, @NonNull User caller, @NonNull Context context, Project document) {
|
||||
super(useCaseDescriptor, caller, context, document);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,15 @@
|
|||
package org.gcube.application.cms.plugins.requests;
|
||||
|
||||
import lombok.NonNull;
|
||||
import lombok.ToString;
|
||||
import org.gcube.application.geoportal.common.model.document.Project;
|
||||
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.useCaseDescriptor.UseCaseDescriptor;
|
||||
|
||||
@ToString(callSuper = true)
|
||||
public class MaterializationRequest extends BaseExecutionRequest{
|
||||
|
||||
public MaterializationRequest(@NonNull UseCaseDescriptor useCaseDescriptor, @NonNull User caller, @NonNull Context context, Project document) {
|
||||
super(useCaseDescriptor, caller, context, document);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,26 +1,22 @@
|
|||
package org.gcube.application.cms.plugins.requests;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
import lombok.*;
|
||||
import org.gcube.application.geoportal.common.model.document.Project;
|
||||
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.useCaseDescriptor.UseCaseDescriptor;
|
||||
|
||||
@Data
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString(callSuper = true)
|
||||
public class StepExecutionRequest extends BaseExecutionRequest{
|
||||
|
||||
public static class Steps{
|
||||
|
||||
public static final String ON_MATERIALIZE_DOCUMENT="@@@MATERIALIZE_DOCUMENT@@";
|
||||
public static final String ON_DEMATERIALIZE_DOCUMENT="@@@DEMATERIALIZE_DOCUMENT@@";
|
||||
|
||||
public static final String ON_INDEX_DOCUMENT="@@@INDEX_DOCUMENT@@";
|
||||
public static final String ON_DEINDEX_DOCUMENT="@@@DEINDEX_DOCUMENT@@";
|
||||
public StepExecutionRequest(@NonNull UseCaseDescriptor useCaseDescriptor, @NonNull User caller, @NonNull Context context, Project document, String step) {
|
||||
super(useCaseDescriptor, caller, context, document);
|
||||
this.step = step;
|
||||
}
|
||||
|
||||
|
||||
|
||||
String step;
|
||||
User user;
|
||||
Context context;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.gcube.application.cms.tests.model;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.gcube.application.cms.plugins.IndexerPluginInterface;
|
||||
import org.gcube.application.cms.plugins.LifecycleManager;
|
||||
import org.gcube.application.cms.plugins.MaterializationPlugin;
|
||||
|
@ -8,12 +9,11 @@ import org.gcube.application.cms.plugins.faults.*;
|
|||
import org.gcube.application.cms.plugins.model.ComparableVersion;
|
||||
import org.gcube.application.cms.plugins.model.PluginDescriptor;
|
||||
import org.gcube.application.cms.plugins.reports.*;
|
||||
import org.gcube.application.cms.plugins.requests.EventExecutionRequest;
|
||||
import org.gcube.application.cms.plugins.requests.IndexDocumentRequest;
|
||||
import org.gcube.application.cms.plugins.requests.MaterializationRequest;
|
||||
import org.gcube.application.cms.plugins.requests.StepExecutionRequest;
|
||||
import org.gcube.application.cms.plugins.requests.*;
|
||||
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.rest.ConfigurationException;
|
||||
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
|
||||
|
||||
public class DummyPlugin implements LifecycleManager, IndexerPluginInterface, MaterializationPlugin {
|
||||
|
||||
|
@ -23,6 +23,11 @@ public class DummyPlugin implements LifecycleManager, IndexerPluginInterface, Ma
|
|||
return new IndexDocumentReport(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Index getIndex(UseCaseDescriptor ucd, Document params) throws ConfigurationException {
|
||||
return new Index("Dummy index");
|
||||
}
|
||||
|
||||
@Override
|
||||
public InitializationReport initInContext() throws InitializationException {
|
||||
return new InitializationReport(Report.Status.WARNING,"DUMB");
|
||||
|
@ -45,7 +50,7 @@ public class DummyPlugin implements LifecycleManager, IndexerPluginInterface, Ma
|
|||
}
|
||||
|
||||
@Override
|
||||
public Configuration getCurrentConfiguration() throws ConfigurationException {
|
||||
public Configuration getCurrentConfiguration(BaseRequest ucd) throws ConfigurationException {
|
||||
return new Configuration();
|
||||
}
|
||||
|
||||
|
|
|
@ -12,14 +12,11 @@ import org.gcube.application.cms.plugins.PluginManagerInterface;
|
|||
import org.gcube.application.cms.plugins.faults.*;
|
||||
import org.gcube.application.cms.plugins.model.ComparableVersion;
|
||||
import org.gcube.application.cms.plugins.reports.*;
|
||||
import org.gcube.application.cms.plugins.requests.EventExecutionRequest;
|
||||
import org.gcube.application.cms.plugins.requests.IndexDocumentRequest;
|
||||
import org.gcube.application.cms.plugins.requests.MaterializationRequest;
|
||||
import org.gcube.application.cms.plugins.requests.*;
|
||||
import org.gcube.application.cms.serialization.Serialization;
|
||||
import org.gcube.application.cms.custom.gna.concessioni.model.ProfiledConcessione;
|
||||
import org.gcube.application.cms.plugins.LifecycleManager;
|
||||
import org.gcube.application.cms.plugins.model.PluginDescriptor;
|
||||
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;
|
||||
import org.gcube.application.geoportal.common.model.document.access.AccessPolicy;
|
||||
|
@ -29,9 +26,12 @@ 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.configuration.Configuration;
|
||||
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.ContextUtils;
|
||||
import org.gcube.application.geoportal.common.utils.Files;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Slf4j
|
||||
public class ConcessioniLifeCycleManager implements LifecycleManager {
|
||||
|
||||
|
@ -108,7 +108,8 @@ public class ConcessioniLifeCycleManager implements LifecycleManager {
|
|||
if(!request.getDocument().getLifecycleInformation().getPhase().equals(LifecycleInformation.DRAFT_PHASE))
|
||||
throw new StepException("Document is not in Draft phase");
|
||||
//Materialize layers
|
||||
MaterializationRequest matReq = new MaterializationRequest();
|
||||
MaterializationRequest matReq = new MaterializationRequest(request.getUseCaseDescriptor(),request.getCaller(), request.getContext(), request.getDocument());
|
||||
|
||||
matReq.setDocument(request.getDocument());
|
||||
matReq.setUseCaseDescriptor(request.getUseCaseDescriptor());
|
||||
Document params = new Document();
|
||||
|
@ -159,9 +160,8 @@ public class ConcessioniLifeCycleManager implements LifecycleManager {
|
|||
.equals(Phases.PENDING_APPROVAL))
|
||||
throw new StepException("Document is not in "+Phases.PENDING_APPROVAL+" phase");
|
||||
|
||||
IndexDocumentRequest indexRequest = new IndexDocumentRequest();
|
||||
indexRequest.setDocument(request.getDocument());
|
||||
indexRequest.setUseCaseDescriptor(request.getUseCaseDescriptor());
|
||||
IndexDocumentRequest indexRequest = new IndexDocumentRequest(request.getUseCaseDescriptor(),request.getCaller(), request.getContext(),request.getDocument());
|
||||
|
||||
Document callParameters = new Document();
|
||||
callParameters.put("workspace",Files.fixFilename("gna_concessioni_"+request.getContext().getId()));
|
||||
callParameters.put("indexName",Files.fixFilename("gna_concessioni_centroids_"+request.getContext().getId()));
|
||||
|
@ -252,8 +252,24 @@ public class ConcessioniLifeCycleManager implements LifecycleManager {
|
|||
|
||||
|
||||
@Override
|
||||
public Configuration getCurrentConfiguration() throws ConfigurationException {
|
||||
return null;
|
||||
public Configuration getCurrentConfiguration(BaseRequest req) throws ConfigurationException {
|
||||
Configuration toReturn = new Configuration();
|
||||
toReturn.setArchives(new ArrayList<>());
|
||||
|
||||
IndexerPluginInterface indexerPlugin;
|
||||
indexerPlugin = (IndexerPluginInterface) pluginManager.getById("SDI-Indexer-Plugin");
|
||||
|
||||
Document callParameters = new Document();
|
||||
callParameters.put("workspace",Files.fixFilename("gna_concessioni_"+req.getContext()));
|
||||
callParameters.put("indexName",Files.fixFilename("gna_concessioni_centroids_"+req.getContext()));
|
||||
|
||||
|
||||
BaseRequest indexRequest = new BaseRequest(req.getUseCaseDescriptor(),req.getCaller(),req.getContext());
|
||||
indexRequest.setCallParameters(callParameters);
|
||||
|
||||
toReturn.getIndexes().add(indexerPlugin.getIndex(indexRequest));
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -11,11 +11,13 @@ import org.gcube.application.cms.plugins.model.PluginDescriptor;
|
|||
import org.gcube.application.cms.plugins.reports.EventExecutionReport;
|
||||
import org.gcube.application.cms.plugins.reports.StepExecutionReport;
|
||||
import org.gcube.application.cms.plugins.reports.InitializationReport;
|
||||
import org.gcube.application.cms.plugins.requests.BaseRequest;
|
||||
import org.gcube.application.cms.plugins.requests.EventExecutionRequest;
|
||||
import org.gcube.application.cms.plugins.requests.StepExecutionRequest;
|
||||
import org.gcube.application.cms.plugins.model.ComparableVersion;
|
||||
import org.gcube.application.geoportal.common.model.configuration.Configuration;
|
||||
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
|
||||
|
||||
@Slf4j
|
||||
public class SimpleLifeCycleManager implements LifecycleManager {
|
||||
|
@ -55,7 +57,7 @@ public class SimpleLifeCycleManager implements LifecycleManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Configuration getCurrentConfiguration() throws ConfigurationException {
|
||||
public Configuration getCurrentConfiguration(BaseRequest ucd) throws ConfigurationException {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.mongodb.client.MongoDatabase;
|
|||
import com.vdurmont.semver4j.Semver;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.ArrayStack;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.bson.Document;
|
||||
import org.bson.types.ObjectId;
|
||||
|
@ -15,10 +16,12 @@ import org.gcube.application.cms.plugins.faults.StepException;
|
|||
import org.gcube.application.cms.plugins.model.PluginDescriptor;
|
||||
import org.gcube.application.cms.plugins.reports.DocumentHandlingReport;
|
||||
import org.gcube.application.cms.plugins.reports.StepExecutionReport;
|
||||
import org.gcube.application.cms.plugins.requests.BaseRequest;
|
||||
import org.gcube.application.cms.plugins.requests.EventExecutionRequest;
|
||||
import org.gcube.application.cms.plugins.requests.StepExecutionRequest;
|
||||
import org.gcube.application.geoportal.common.faults.StorageException;
|
||||
import org.gcube.application.geoportal.common.model.configuration.Archive;
|
||||
import org.gcube.application.geoportal.common.model.configuration.Index;
|
||||
import org.gcube.application.geoportal.common.model.document.*;
|
||||
import org.gcube.application.geoportal.common.model.document.access.Access;
|
||||
import org.gcube.application.geoportal.common.model.document.access.AccessPolicy;
|
||||
|
@ -388,6 +391,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
|||
log.debug("Asking configuration for {} in {} ", useCaseDescriptor.getId(), UserUtils.getCurrent().getContext());
|
||||
Configuration toReturn= new Configuration();
|
||||
List<Archive> archives = new ArrayList<>();
|
||||
List<Index> indexes=new ArrayList<>();
|
||||
// Set Basic Info
|
||||
toReturn.setArchives(archives);
|
||||
toReturn.setProfileId(this.getUseCaseDescriptor().getId());
|
||||
|
@ -402,6 +406,8 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
|||
mongoArchive.put("collection_name",getToUseCollectionName());
|
||||
archives.add(mongoArchive);
|
||||
|
||||
// TODO ADD TEXT INDEXES
|
||||
|
||||
// Set WS Info
|
||||
try {
|
||||
archives.add(new WorkspaceManager().getConfiguration());
|
||||
|
@ -409,6 +415,16 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
|||
throw new ConfigurationException("Unable to get WS Configuration",e);
|
||||
}
|
||||
|
||||
// ADD LC Infos
|
||||
|
||||
AccountingInfo user = UserUtils.getCurrent().asInfo();
|
||||
Configuration lcConfig = getLCManager().getCurrentConfiguration(new BaseRequest(useCaseDescriptor,user.getUser(),user.getContext()));
|
||||
if(lcConfig.getArchives()!=null)
|
||||
archives.addAll(lcConfig.getArchives());
|
||||
|
||||
if(lcConfig.getIndexes()!=null)
|
||||
indexes.addAll(lcConfig.getIndexes());
|
||||
|
||||
log.debug("Returning current configuration {}",toReturn);
|
||||
return toReturn;
|
||||
}
|
||||
|
@ -417,14 +433,8 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
|||
private Project step(Project theDocument, String step, Document callParameters){
|
||||
try{
|
||||
log.info("[UseCaseDescriptor {}] Invoking Step {} on {}" , useCaseDescriptor.getId(),step,getManager().getDescriptor());
|
||||
StepExecutionRequest request=new StepExecutionRequest();
|
||||
request.setCallParameters(callParameters);
|
||||
request.setDocument(theDocument);
|
||||
request.setUseCaseDescriptor(useCaseDescriptor);
|
||||
request.setStep(step);
|
||||
AccountingInfo user= UserUtils.getCurrent().asInfo();
|
||||
request.setUser(user.getUser());
|
||||
request.setContext(user.getContext());
|
||||
StepExecutionRequest request=new StepExecutionRequest(useCaseDescriptor,user.getUser(),user.getContext(),theDocument,step);
|
||||
|
||||
log.debug("Requesting Step Execution {}",request);
|
||||
StepExecutionReport report= getManager().performStep(request);
|
||||
|
@ -463,11 +473,8 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
|||
private Project triggerEvent(Project theDocument, String event, Document parameters) {
|
||||
try{
|
||||
log.info("[UseCaseDescriptor {}] triggering event {} on {}" , useCaseDescriptor.getId(),event,getManager().getDescriptor());
|
||||
EventExecutionRequest request= new EventExecutionRequest();
|
||||
request.setEvent(event);
|
||||
request.setUseCaseDescriptor(useCaseDescriptor);
|
||||
request.setCallParameters(parameters);
|
||||
request.setDocument(theDocument);
|
||||
AccountingInfo user= UserUtils.getCurrent().asInfo();
|
||||
EventExecutionRequest request= new EventExecutionRequest(useCaseDescriptor,user.getUser(),user.getContext(),theDocument,event);
|
||||
log.debug("Triggering {}",request);
|
||||
DocumentHandlingReport report = getManager().onEvent(request);
|
||||
return report.prepareResult();
|
||||
|
|
|
@ -3,13 +3,18 @@ package org.gcube.application.cms.sdi.engine;
|
|||
import lombok.NonNull;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bson.Document;
|
||||
import org.gcube.application.cms.plugins.requests.BaseRequest;
|
||||
import org.gcube.application.cms.sdi.faults.SDIInteractionException;
|
||||
import org.gcube.application.geoportal.common.model.configuration.Index;
|
||||
import org.gcube.application.geoportal.common.model.legacy.SDILayerDescriptor;
|
||||
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
|
||||
import org.gcube.application.geoportal.common.model.rest.DatabaseConnection;
|
||||
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
|
@ -49,6 +54,13 @@ public class PostgisIndexer {
|
|||
|
||||
PostgisTable table = null;
|
||||
|
||||
private String storeName = null;
|
||||
private String workspace = null;
|
||||
private SDILayerDescriptor indexLayer = null;
|
||||
|
||||
private List<SDILayerDescriptor> crossReferenceableLayers= new ArrayList<>();
|
||||
|
||||
|
||||
public void initIndex(String indexName, List<PostgisTable.Field> fields, String workspace,String storeName) throws SQLException, SDIInteractionException {
|
||||
log.info("Check/init index for {} ", useCaseDescriptor.getId());
|
||||
table = new PostgisTable(indexName,fields, PostgisTable.GeometryType.POINT);
|
||||
|
@ -58,7 +70,8 @@ public class PostgisIndexer {
|
|||
dbManager.create(table);
|
||||
|
||||
log.debug("Checking/ registering index layer in GS ");
|
||||
manager.configureCentroidLayer(indexName,workspace,storeName,table,connectionParameters);
|
||||
String wmsUrl=manager.configureCentroidLayer(indexName,workspace,storeName,table,connectionParameters);
|
||||
|
||||
|
||||
|
||||
// TODO Additional layers
|
||||
|
@ -67,8 +80,25 @@ public class PostgisIndexer {
|
|||
}
|
||||
|
||||
|
||||
HashMap<String,String> wmsUrls=new HashMap<>();
|
||||
|
||||
private String wmsByIndex(String indexName){
|
||||
|
||||
}
|
||||
|
||||
|
||||
public Index getIndexConfiguration(){
|
||||
Index toReturn = new Index("GIS-CENTROIDS");
|
||||
// SDI Layers
|
||||
|
||||
|
||||
|
||||
// cross reference info
|
||||
|
||||
|
||||
toReturn.put("",);
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
|
||||
public void insert(Document toInsertRecord)throws SDIInteractionException {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.gcube.application.cms.sdi.plugins;
|
||||
|
||||
import com.sun.tools.javac.code.Type;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bson.Document;
|
||||
|
@ -12,6 +13,7 @@ import org.gcube.application.cms.plugins.model.PluginDescriptor;
|
|||
import org.gcube.application.cms.plugins.reports.IndexDocumentReport;
|
||||
import org.gcube.application.cms.plugins.reports.InitializationReport;
|
||||
import org.gcube.application.cms.plugins.reports.Report;
|
||||
import org.gcube.application.cms.plugins.requests.BaseRequest;
|
||||
import org.gcube.application.cms.plugins.requests.IndexDocumentRequest;
|
||||
import org.gcube.application.cms.sdi.engine.PostgisIndexer;
|
||||
import org.gcube.application.cms.sdi.engine.PostgisTable;
|
||||
|
@ -19,14 +21,18 @@ import org.gcube.application.cms.sdi.faults.SDIInteractionException;
|
|||
import org.gcube.application.cms.serialization.Serialization;
|
||||
import org.gcube.application.geoportal.common.model.JSONPathWrapper;
|
||||
import org.gcube.application.cms.plugins.model.ComparableVersion;
|
||||
import org.gcube.application.geoportal.common.model.configuration.Index;
|
||||
import org.gcube.application.geoportal.common.model.document.Project;
|
||||
import org.gcube.application.geoportal.common.model.document.filesets.GCubeSDILayer;
|
||||
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.ContextUtils;
|
||||
import org.geojson.Crs;
|
||||
import org.geojson.GeoJsonObject;
|
||||
import org.geojson.LngLatAlt;
|
||||
import org.geojson.Point;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -96,39 +102,11 @@ public class SDIIndexerPlugin extends SDIAbstractPlugin implements IndexerPlugin
|
|||
try{
|
||||
// ********* INIT INDEX
|
||||
// TODO CACHE
|
||||
PostgisIndexer indexer = new PostgisIndexer(sdiCache.getObject(), useCaseDescriptor,postgisCache.getObject());
|
||||
PostgisIndexer indexer = getIndexer(useCaseDescriptor,requestArguments);
|
||||
|
||||
Document profileConfiguration =getConfigurationFromProfile(useCaseDescriptor).getConfiguration();
|
||||
log.debug("UseCaseDescriptor Configuration is {} ",profileConfiguration);
|
||||
|
||||
// SCHEMA
|
||||
log.debug("UseCaseDescriptor {} : Evaluating Index schema.. ", useCaseDescriptor.getId());
|
||||
List<PostgisTable.Field> fields = new ArrayList<>(); // TODO From UseCaseDescriptor
|
||||
fields.add(new PostgisTable.Field("geom", PostgisTable.FieldType.GEOMETRY));
|
||||
fields.add(new PostgisTable.Field("projectid", PostgisTable.FieldType.TEXT));
|
||||
List mappingObjs= profileConfiguration.get("explicitFieldMapping",List.class);
|
||||
|
||||
log.trace("Loading mappings from useCaseDescriptor.. ");
|
||||
List<MappingObject> mappingObjects= new ArrayList<>();
|
||||
if(mappingObjs!=null){
|
||||
for (Object mappingObj : mappingObjs) {
|
||||
log.trace("Mapping is {} ",mappingObj);
|
||||
MappingObject m = Serialization.convert(mappingObj,MappingObject.class);
|
||||
m.validate();
|
||||
|
||||
fields.add(new PostgisTable.Field(m.getName(), PostgisTable.FieldType.valueOf(m.getType())));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
indexer.initIndex(requestArguments.getString("indexName"),
|
||||
fields,
|
||||
requestArguments.getString("workspace"),
|
||||
requestArguments.getString("indexName"));
|
||||
|
||||
|
||||
|
||||
// ************* PREPARE RECORD
|
||||
|
@ -214,14 +192,13 @@ public class SDIIndexerPlugin extends SDIAbstractPlugin implements IndexerPlugin
|
|||
//*********** Additional Values from useCaseDescriptor
|
||||
|
||||
log.info("Setting additional values to centroid from mappings ..");
|
||||
for(MappingObject m : mappingObjects){
|
||||
for(MappingObject m : getMappings(useCaseDescriptor)){
|
||||
List<Object> foundValues = documentNavigator.getByPath(m.getPath());
|
||||
Object toSetValue=null;
|
||||
if(!foundValues.isEmpty())
|
||||
toSetValue=foundValues.get(0);
|
||||
log.trace("Setting {} = {} in centroid doc ",m.getName(),toSetValue);
|
||||
centroidDoc.put(m.getName(),foundValues.get(0));
|
||||
|
||||
}
|
||||
|
||||
log.info("Inserting Centroid {} into {} ",centroidDoc.toJson(),indexer);
|
||||
|
@ -241,4 +218,59 @@ public class SDIIndexerPlugin extends SDIAbstractPlugin implements IndexerPlugin
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Index getIndex(BaseRequest request) throws ConfigurationException {
|
||||
try {
|
||||
return getIndexer(request.getUseCaseDescriptor(), request.getCallParameters()).getIndexConfiguration();
|
||||
}catch(Throwable t ){
|
||||
throw new ConfigurationException("Unable to get Postgis index for ucd "+request.getUseCaseDescriptor().getId()+" in "+ request.getContext(),t);
|
||||
}
|
||||
}
|
||||
|
||||
// Inits index
|
||||
// TODO CACHE
|
||||
private PostgisIndexer getIndexer(UseCaseDescriptor ucd,Document params) throws ConfigurationException, SQLException, InvalidProfileException, SDIInteractionException {
|
||||
PostgisIndexer indexer = new PostgisIndexer(sdiCache.getObject(), ucd, postgisCache.getObject());
|
||||
|
||||
List<MappingObject> mappingObjects = getMappings(ucd);
|
||||
List<PostgisTable.Field> fields = getFields(mappingObjects);
|
||||
|
||||
|
||||
indexer.initIndex(params.getString("indexName"),
|
||||
fields,
|
||||
params.getString("workspace"),
|
||||
params.getString("indexName"));
|
||||
return indexer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private List<PostgisTable.Field> getFields(List<MappingObject> mappings){
|
||||
List<PostgisTable.Field> fields = new ArrayList<>(); // TODO From UseCaseDescriptor
|
||||
fields.add(new PostgisTable.Field("geom", PostgisTable.FieldType.GEOMETRY));
|
||||
fields.add(new PostgisTable.Field("projectid", PostgisTable.FieldType.TEXT));
|
||||
|
||||
mappings.forEach(m -> {
|
||||
fields.add(new PostgisTable.Field(m.getName(), PostgisTable.FieldType.valueOf(m.getType())));
|
||||
});
|
||||
|
||||
return fields;
|
||||
}
|
||||
|
||||
|
||||
private List<MappingObject> getMappings(UseCaseDescriptor ucd) throws InvalidProfileException {
|
||||
log.debug("UseCaseDescriptor {} : Evaluating Index schema.. ", ucd.getId());
|
||||
Document profileConfiguration = getConfigurationFromProfile(ucd).getConfiguration();
|
||||
List mappingObjs= profileConfiguration.get("explicitFieldMapping",List.class);
|
||||
log.trace("Loading mappings from useCaseDescriptor.. ");
|
||||
List<MappingObject> mappingObjects= new ArrayList<>();
|
||||
if(mappingObjs!=null){
|
||||
for (Object mappingObj : mappingObjs) {
|
||||
log.trace("Mapping is {} ",mappingObj);
|
||||
MappingObject m = Serialization.convert(mappingObj,MappingObject.class);
|
||||
m.validate();
|
||||
}
|
||||
}
|
||||
return mappingObjects;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue