Report Validation

This commit is contained in:
Fabio Sinibaldi 2022-02-17 14:47:51 +01:00
parent 08c334b624
commit 31b7d28572
10 changed files with 95 additions and 16 deletions

View File

@ -1,6 +1,6 @@
package org.gcube.application.cms.plugins.faults; package org.gcube.application.cms.plugins.faults;
public class EventException extends Exception{ public class EventException extends PluginExecutionException{
public EventException() { public EventException() {
} }

View File

@ -1,6 +1,6 @@
package org.gcube.application.cms.plugins.faults; package org.gcube.application.cms.plugins.faults;
public class InitializationException extends Exception{ public class InitializationException extends PluginExecutionException{
public InitializationException() { public InitializationException() {
} }

View File

@ -1,6 +1,6 @@
package org.gcube.application.cms.plugins.faults; package org.gcube.application.cms.plugins.faults;
public class MaterializationException extends Exception { public class MaterializationException extends PluginExecutionException {
public MaterializationException() { public MaterializationException() {
} }

View File

@ -0,0 +1,22 @@
package org.gcube.application.cms.plugins.faults;
public class PluginExecutionException extends Exception{
public PluginExecutionException() {
}
public PluginExecutionException(String message) {
super(message);
}
public PluginExecutionException(String message, Throwable cause) {
super(message, cause);
}
public PluginExecutionException(Throwable cause) {
super(cause);
}
public PluginExecutionException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}

View File

@ -1,6 +1,6 @@
package org.gcube.application.cms.plugins.faults; package org.gcube.application.cms.plugins.faults;
public class StepException extends Exception { public class StepException extends PluginExecutionException {
public StepException() { public StepException() {
} }

View File

@ -0,0 +1,55 @@
package org.gcube.application.cms.plugins.reports;
import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.bson.Document;
import org.gcube.application.cms.plugins.faults.PluginExecutionException;
import org.gcube.application.cms.plugins.requests.BaseExecutionRequest;
import org.gcube.application.cms.serialization.Serialization;
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation;
@Data
@Slf4j
public class DocumentHandlingReport<T extends BaseExecutionRequest> extends Report{
T theRequest;
Document resultingDocument;
LifecycleInformation toSetLifecycleInformation;
public ProfiledDocument prepareResult() throws JsonProcessingException, PluginExecutionException {
log.trace("Preparing document ID {} from report ... ",theRequest.getDocument().get_id());
this.validate();
ProfiledDocument toReturn = theRequest.getDocument();
if(resultingDocument !=null ) {
log.trace("Updating Document ");
toReturn.setTheDocument(resultingDocument);
}
if(toSetLifecycleInformation != null){
log.trace("Merging lifecycleInformation");
Document original = Serialization.asDocument(toReturn.getLifecycleInformation());
Document toSet = Serialization.asDocument(toSetLifecycleInformation);
toSet.putAll(original);
toReturn.setLifecycleInformation(Serialization.convert(toSet,LifecycleInformation.class));
}
log.trace("Report status is {} ",getStatus());
LifecycleInformation info = toReturn.getLifecycleInformation();
switch (getStatus()){
case ERROR: {
info.setLastOperationStatus(LifecycleInformation.Status.ERROR);
this.getMessages().forEach(s -> info.addErrorMessage(s));
break;
}
case WARNING:{
info.setLastOperationStatus(LifecycleInformation.Status.WARNING);
this.getMessages().forEach(s -> info.addWarningMessage(s));
break;
}
case OK: {
}
}
return toReturn;
}
}

View File

@ -1,15 +1,12 @@
package org.gcube.application.cms.plugins.reports; package org.gcube.application.cms.plugins.reports;
import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.Data; import lombok.Data;
import org.bson.Document;
import org.gcube.application.cms.plugins.requests.EventExecutionRequest; 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.ProfiledDocument;
import org.gcube.application.geoportal.common.model.profile.Profile;
@Data @Data
public class EventExecutionReport { public class EventExecutionReport extends DocumentHandlingReport<EventExecutionRequest>{
private EventExecutionRequest request;
private ProfiledDocument result;
} }

View File

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

View File

@ -1,6 +1,7 @@
package org.gcube.application.cms.plugins.reports; package org.gcube.application.cms.plugins.reports;
import lombok.Data; import lombok.Data;
import org.gcube.application.cms.plugins.faults.PluginExecutionException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -20,4 +21,11 @@ public class Report {
messages.add(msg); messages.add(msg);
return this; return this;
} }
public void validate()throws PluginExecutionException {
if(status == null) throw new PluginExecutionException("Status is null");
if(!status.equals(Status.OK))
if(messages==null || messages.isEmpty()) throw new PluginExecutionException("Messages are mandatory for status != OK ");
}
} }

View File

@ -8,11 +8,7 @@ import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
import java.util.List; import java.util.List;
@Data @Data
public class StepExecutionReport { public class StepExecutionReport extends DocumentHandlingReport<StepExecutionRequest>{
StepExecutionRequest request;
ProfiledDocument result;
List<EventExecutionRequest> toTriggerEvents; List<EventExecutionRequest> toTriggerEvents;