Report Validation
This commit is contained in:
parent
08c334b624
commit
31b7d28572
|
@ -1,6 +1,6 @@
|
|||
package org.gcube.application.cms.plugins.faults;
|
||||
|
||||
public class EventException extends Exception{
|
||||
public class EventException extends PluginExecutionException{
|
||||
|
||||
public EventException() {
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.gcube.application.cms.plugins.faults;
|
||||
|
||||
public class InitializationException extends Exception{
|
||||
public class InitializationException extends PluginExecutionException{
|
||||
|
||||
public InitializationException() {
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.gcube.application.cms.plugins.faults;
|
||||
|
||||
public class MaterializationException extends Exception {
|
||||
public class MaterializationException extends PluginExecutionException {
|
||||
|
||||
public MaterializationException() {
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package org.gcube.application.cms.plugins.faults;
|
||||
|
||||
public class StepException extends Exception {
|
||||
public class StepException extends PluginExecutionException {
|
||||
|
||||
public StepException() {
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -1,15 +1,12 @@
|
|||
package org.gcube.application.cms.plugins.reports;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import lombok.Data;
|
||||
import org.bson.Document;
|
||||
import org.gcube.application.cms.plugins.requests.EventExecutionRequest;
|
||||
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
|
||||
import org.gcube.application.geoportal.common.model.profile.Profile;
|
||||
|
||||
@Data
|
||||
public class EventExecutionReport {
|
||||
public class EventExecutionReport extends DocumentHandlingReport<EventExecutionRequest>{
|
||||
|
||||
private EventExecutionRequest request;
|
||||
private ProfiledDocument result;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package org.gcube.application.cms.plugins.reports;
|
||||
|
||||
import lombok.Data;
|
||||
import org.gcube.application.cms.plugins.requests.MaterializationRequest;
|
||||
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
|
||||
|
||||
@Data
|
||||
public class MaterializationReport extends Report{
|
||||
public class MaterializationReport extends DocumentHandlingReport<MaterializationRequest>{
|
||||
|
||||
|
||||
private ProfiledDocument resultDocument;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.gcube.application.cms.plugins.reports;
|
||||
|
||||
import lombok.Data;
|
||||
import org.gcube.application.cms.plugins.faults.PluginExecutionException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -20,4 +21,11 @@ public class Report {
|
|||
messages.add(msg);
|
||||
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 ");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,11 +8,7 @@ import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
|
|||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class StepExecutionReport {
|
||||
|
||||
StepExecutionRequest request;
|
||||
|
||||
ProfiledDocument result;
|
||||
public class StepExecutionReport extends DocumentHandlingReport<StepExecutionRequest>{
|
||||
|
||||
List<EventExecutionRequest> toTriggerEvents;
|
||||
|
||||
|
|
Loading…
Reference in New Issue