Report model
This commit is contained in:
parent
5387f6ce04
commit
bb1bda69f8
|
@ -44,6 +44,15 @@
|
|||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/de.grundid.opendatalab/geojson-jackson -->
|
||||
<dependency>
|
||||
<groupId>de.grundid.opendatalab</groupId>
|
||||
<artifactId>geojson-jackson</artifactId>
|
||||
<version>1.14</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -1,9 +1,11 @@
|
|||
package org.gcube.application.cms.plugins;
|
||||
|
||||
import org.gcube.application.cms.plugins.faults.InvalidProfileException;
|
||||
import org.gcube.application.cms.plugins.faults.PluginExecutionException;
|
||||
import org.gcube.application.cms.plugins.model.PluginDescriptor;
|
||||
import org.gcube.application.cms.plugins.reports.DocumentHandlingReport;
|
||||
import org.gcube.application.cms.plugins.requests.BaseExecutionRequest;
|
||||
import org.gcube.application.geoportal.common.faults.InvalidRequestException;
|
||||
import org.gcube.application.geoportal.common.model.profile.HandlerDeclaration;
|
||||
import org.gcube.application.geoportal.common.model.profile.Profile;
|
||||
|
||||
|
@ -19,10 +21,12 @@ public abstract class AbstractPlugin implements Plugin{
|
|||
protected HandlerDeclaration getConfigurationFromProfile(Profile profile) throws InvalidProfileException{
|
||||
return getMultipleDeclarationsFromProfile(profile).get(0);
|
||||
}
|
||||
|
||||
protected List<HandlerDeclaration> getMultipleDeclarationsFromProfile(Profile p)throws InvalidProfileException {
|
||||
Map<String,List<HandlerDeclaration>> map = p.getHandlersMapByID();
|
||||
if(map.containsKey(getDescriptor().getId()))
|
||||
return map.get(getDescriptor().getId());
|
||||
else throw new InvalidProfileException("No Configuration found for "+getDescriptor().getId()+" in "+p.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
package org.gcube.application.cms.plugins;
|
||||
|
||||
import org.gcube.application.cms.plugins.faults.InvalidPluginRequestException;
|
||||
import org.gcube.application.cms.plugins.reports.IndexDocumentReport;
|
||||
import org.gcube.application.cms.plugins.requests.IndexDocumentRequest;
|
||||
|
||||
public interface IndexerPluginInterface extends InitializablePlugin{
|
||||
|
||||
public IndexDocumentReport index(IndexDocumentRequest request);
|
||||
public IndexDocumentReport index(IndexDocumentRequest request) throws InvalidPluginRequestException;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.gcube.application.cms.plugins;
|
||||
|
||||
import org.gcube.application.cms.plugins.faults.EventException;
|
||||
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;
|
||||
|
@ -14,11 +15,11 @@ public interface LifecycleManager extends InitializablePlugin{
|
|||
|
||||
// Lifecycle operations
|
||||
|
||||
public StepExecutionReport performStep(StepExecutionRequest request)throws StepException;
|
||||
public StepExecutionReport performStep(StepExecutionRequest request) throws StepException, InvalidPluginRequestException;
|
||||
|
||||
public Configuration getCurrentConfiguration() throws ConfigurationException;
|
||||
|
||||
public EventExecutionReport onEvent(EventExecutionRequest request) throws EventException;
|
||||
public EventExecutionReport onEvent(EventExecutionRequest request) throws EventException, InvalidPluginRequestException;
|
||||
|
||||
public void setPluginManager(PluginManagerInterface manager);
|
||||
}
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package org.gcube.application.cms.plugins;
|
||||
|
||||
import org.gcube.application.cms.plugins.faults.InvalidPluginRequestException;
|
||||
import org.gcube.application.cms.plugins.faults.MaterializationException;
|
||||
import org.gcube.application.cms.plugins.reports.MaterializationReport;
|
||||
import org.gcube.application.cms.plugins.requests.MaterializationRequest;
|
||||
|
||||
public interface MaterializationPlugin extends InitializablePlugin{
|
||||
|
||||
public MaterializationReport materialize(MaterializationRequest request) throws MaterializationException;
|
||||
public MaterializationReport materialize(MaterializationRequest request) throws MaterializationException, InvalidPluginRequestException;
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package org.gcube.application.cms.plugins.faults;
|
||||
|
||||
public class IndexingException extends PluginExecutionException{
|
||||
public IndexingException() {
|
||||
}
|
||||
|
||||
public IndexingException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public IndexingException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public IndexingException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public IndexingException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package org.gcube.application.cms.plugins.faults;
|
||||
|
||||
public class InvalidPluginRequestException extends PluginExecutionException {
|
||||
public InvalidPluginRequestException() {
|
||||
}
|
||||
|
||||
public InvalidPluginRequestException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public InvalidPluginRequestException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public InvalidPluginRequestException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public InvalidPluginRequestException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ import lombok.NonNull;
|
|||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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.BaseExecutionRequest;
|
||||
import org.gcube.application.cms.serialization.Serialization;
|
||||
|
@ -24,7 +25,8 @@ public class DocumentHandlingReport<T extends BaseExecutionRequest> extends Repo
|
|||
LifecycleInformation toSetLifecycleInformation;
|
||||
|
||||
|
||||
public DocumentHandlingReport(@NonNull T theRequest) {
|
||||
public DocumentHandlingReport(@NonNull T theRequest) throws InvalidPluginRequestException {
|
||||
theRequest.validate();
|
||||
this.theRequest = theRequest;
|
||||
toSetLifecycleInformation=theRequest.getDocument().getLifecycleInformation();
|
||||
resultingDocument = theRequest.getDocument().getTheDocument();
|
||||
|
|
|
@ -2,14 +2,16 @@ package org.gcube.application.cms.plugins.reports;
|
|||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
import org.gcube.application.cms.plugins.faults.InvalidPluginRequestException;
|
||||
import org.gcube.application.cms.plugins.requests.EventExecutionRequest;
|
||||
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
|
||||
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation;
|
||||
|
||||
@Data
|
||||
@ToString(callSuper = true)
|
||||
public class EventExecutionReport extends DocumentHandlingReport<EventExecutionRequest>{
|
||||
|
||||
public EventExecutionReport(EventExecutionRequest req){
|
||||
public EventExecutionReport(EventExecutionRequest req) throws InvalidPluginRequestException {
|
||||
super(req);
|
||||
this.setToSetLifecycleInformation(theRequest.getDocument().getLifecycleInformation().cleanState());
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
|||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
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.ProfiledDocument;
|
||||
|
@ -18,7 +19,7 @@ public class IndexDocumentReport extends DocumentHandlingReport<IndexDocumentReq
|
|||
public SpatialReference toSetSpatialReference;
|
||||
|
||||
|
||||
public IndexDocumentReport(@NonNull IndexDocumentRequest theRequest) {
|
||||
public IndexDocumentReport(@NonNull IndexDocumentRequest theRequest) throws InvalidPluginRequestException {
|
||||
super(theRequest);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
package org.gcube.application.cms.plugins.reports;
|
||||
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@NoArgsConstructor
|
||||
public class InitializationReport extends Report{
|
||||
|
||||
|
||||
public InitializationReport(Status status, String... messages) {
|
||||
super(status, messages);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,13 +2,14 @@ package org.gcube.application.cms.plugins.reports;
|
|||
|
||||
import lombok.Data;
|
||||
import lombok.NonNull;
|
||||
import org.gcube.application.cms.plugins.faults.InvalidPluginRequestException;
|
||||
import org.gcube.application.cms.plugins.requests.MaterializationRequest;
|
||||
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
|
||||
|
||||
|
||||
public class MaterializationReport extends DocumentHandlingReport<MaterializationRequest>{
|
||||
|
||||
public MaterializationReport(@NonNull MaterializationRequest theRequest) {
|
||||
public MaterializationReport(@NonNull MaterializationRequest theRequest) throws InvalidPluginRequestException {
|
||||
super(theRequest);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,17 @@
|
|||
package org.gcube.application.cms.plugins.reports;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.gcube.application.cms.plugins.faults.PluginExecutionException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
public class Report {
|
||||
|
||||
public static enum Status {
|
||||
|
@ -16,6 +21,13 @@ public class Report {
|
|||
private Status status;
|
||||
private List<String> messages;
|
||||
|
||||
public Report(Status status,String ... messages) {
|
||||
this.status = status;
|
||||
this.messages=new ArrayList<>();
|
||||
for (String s : messages)
|
||||
this.messages.add(s);
|
||||
}
|
||||
|
||||
public Report putMessage(String msg){
|
||||
if(messages==null)messages=new ArrayList<>();
|
||||
messages.add(msg);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.gcube.application.cms.plugins.reports;
|
||||
|
||||
import lombok.*;
|
||||
import org.gcube.application.cms.plugins.faults.InvalidPluginRequestException;
|
||||
import org.gcube.application.cms.plugins.requests.EventExecutionRequest;
|
||||
import org.gcube.application.cms.plugins.requests.StepExecutionRequest;
|
||||
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
|
||||
|
@ -13,7 +14,7 @@ import java.util.List;
|
|||
@ToString
|
||||
public class StepExecutionReport extends DocumentHandlingReport<StepExecutionRequest>{
|
||||
|
||||
public StepExecutionReport(@NonNull StepExecutionRequest theRequest) {
|
||||
public StepExecutionReport(@NonNull StepExecutionRequest theRequest) throws InvalidPluginRequestException {
|
||||
|
||||
super(theRequest);
|
||||
this.getToSetLifecycleInformation().cleanState();
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.gcube.application.cms.plugins.requests;
|
|||
|
||||
import lombok.Data;
|
||||
import org.bson.Document;
|
||||
import org.gcube.application.cms.plugins.faults.InvalidPluginRequestException;
|
||||
import org.gcube.application.geoportal.common.faults.InvalidRequestException;
|
||||
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
|
||||
import org.gcube.application.geoportal.common.model.profile.Profile;
|
||||
|
@ -13,12 +14,17 @@ public class BaseExecutionRequest {
|
|||
ProfiledDocument document;
|
||||
Document callParameters;
|
||||
|
||||
public final String getMandatory(String param) throws InvalidRequestException {
|
||||
public final String getMandatory(String param) throws InvalidPluginRequestException {
|
||||
return getMandatory(param,callParameters);
|
||||
}
|
||||
|
||||
public static final String getMandatory(String param,Document params) throws InvalidRequestException {
|
||||
if(!params.containsKey(param)) throw new InvalidRequestException("Missing mandatory parameter "+param);
|
||||
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(profile==null)throw new InvalidPluginRequestException("Profile cannot be null ");
|
||||
if(document==null) throw new InvalidPluginRequestException("Document cannot be null");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import org.gcube.application.cms.plugins.InitializablePlugin;
|
|||
import org.gcube.application.cms.plugins.Plugin;
|
||||
import org.gcube.application.cms.plugins.PluginsReflections;
|
||||
import org.gcube.application.cms.plugins.faults.InitializationException;
|
||||
import org.gcube.application.cms.plugins.faults.PluginExecutionException;
|
||||
import org.gcube.application.geoportal.common.utils.tests.GCubeTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
|
@ -37,13 +38,14 @@ public class BasicPluginTest {
|
|||
if(p instanceof InitializablePlugin){
|
||||
InitializablePlugin ip=(InitializablePlugin)p;
|
||||
try {
|
||||
ip.init();
|
||||
ip.init().validate();
|
||||
|
||||
|
||||
if(GCubeTest.isTestInfrastructureEnabled()){
|
||||
TokenSetter.set(GCubeTest.getContext());
|
||||
ip.initInContext();
|
||||
ip.initInContext().validate();
|
||||
}
|
||||
} catch (InitializationException e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(System.err);
|
||||
Assert.fail("Unable to Init "+p.getDescriptor().getId());
|
||||
}
|
||||
|
@ -54,7 +56,7 @@ public class BasicPluginTest {
|
|||
System.out.println("Plugin Loading OK");
|
||||
|
||||
if(GCubeTest.isTestInfrastructureEnabled()){
|
||||
ImplementationProvider.get().setEngine(new ISProvider(), ISInterface.class);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,18 +19,18 @@ public class DummyPlugin implements LifecycleManager, IndexerPluginInterface, Ma
|
|||
|
||||
|
||||
@Override
|
||||
public IndexDocumentReport index(IndexDocumentRequest request) {
|
||||
public IndexDocumentReport index(IndexDocumentRequest request) throws InvalidPluginRequestException {
|
||||
return new IndexDocumentReport(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InitializationReport initInContext() throws InitializationException {
|
||||
return new InitializationReport();
|
||||
return new InitializationReport(Report.Status.WARNING,"DUMB");
|
||||
}
|
||||
|
||||
@Override
|
||||
public InitializationReport init() throws InitializationException {
|
||||
return new InitializationReport();
|
||||
return new InitializationReport(Report.Status.WARNING,"DUMB");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -39,7 +39,8 @@ public class DummyPlugin implements LifecycleManager, IndexerPluginInterface, Ma
|
|||
}
|
||||
|
||||
@Override
|
||||
public StepExecutionReport performStep(StepExecutionRequest request) throws StepException {
|
||||
public StepExecutionReport performStep(StepExecutionRequest request) throws StepException, InvalidPluginRequestException {
|
||||
request.validate();
|
||||
return new StepExecutionReport(request);
|
||||
}
|
||||
|
||||
|
@ -49,7 +50,7 @@ public class DummyPlugin implements LifecycleManager, IndexerPluginInterface, Ma
|
|||
}
|
||||
|
||||
@Override
|
||||
public EventExecutionReport onEvent(EventExecutionRequest request) throws EventException {
|
||||
public EventExecutionReport onEvent(EventExecutionRequest request) throws EventException, InvalidPluginRequestException {
|
||||
return new EventExecutionReport(request);
|
||||
}
|
||||
|
||||
|
@ -59,7 +60,7 @@ public class DummyPlugin implements LifecycleManager, IndexerPluginInterface, Ma
|
|||
}
|
||||
|
||||
@Override
|
||||
public MaterializationReport materialize(MaterializationRequest request) throws MaterializationException {
|
||||
public MaterializationReport materialize(MaterializationRequest request) throws MaterializationException, InvalidPluginRequestException {
|
||||
return new MaterializationReport(request);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
package org.gcube.application.cms.commons.model;
|
||||
|
||||
import org.gcube.application.cms.tests.BasicPluginTest;
|
||||
import org.junit.Test;
|
||||
|
||||
public class DummyTest extends BasicPluginTest {
|
||||
|
||||
@Test
|
||||
public void myTest(){}
|
||||
}
|
|
@ -9,7 +9,7 @@ import org.bson.Document;
|
|||
import org.gcube.application.cms.plugins.IndexerPluginInterface;
|
||||
import org.gcube.application.cms.plugins.MaterializationPlugin;
|
||||
import org.gcube.application.cms.plugins.PluginManagerInterface;
|
||||
import org.gcube.application.cms.plugins.faults.EventException;
|
||||
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;
|
||||
|
@ -18,9 +18,6 @@ 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;
|
||||
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.requests.StepExecutionRequest;
|
||||
import org.gcube.application.geoportal.common.model.document.*;
|
||||
|
@ -87,7 +84,7 @@ public class ConcessioniLifeCycleManager implements LifecycleManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public StepExecutionReport performStep(StepExecutionRequest request) throws StepException {
|
||||
public StepExecutionReport performStep(StepExecutionRequest request) throws StepException, InvalidPluginRequestException {
|
||||
log.info("Serving Request {}",request);
|
||||
StepExecutionReport report=new StepExecutionReport(request);
|
||||
report.setStatus(Report.Status.OK);
|
||||
|
@ -210,7 +207,7 @@ public class ConcessioniLifeCycleManager implements LifecycleManager {
|
|||
|
||||
|
||||
@Override
|
||||
public EventExecutionReport onEvent(EventExecutionRequest request) throws EventException {
|
||||
public EventExecutionReport onEvent(EventExecutionRequest request) throws EventException, InvalidPluginRequestException {
|
||||
log.info("Executing Event {}",request);
|
||||
EventExecutionReport report=new EventExecutionReport(request);
|
||||
|
||||
|
|
Loading…
Reference in New Issue