Lifecycleinformation in result

This commit is contained in:
Fabio Sinibaldi 2022-01-17 14:19:59 +01:00
parent 1cdf92ba1a
commit a4e8cb2f1e
3 changed files with 22 additions and 8 deletions

View File

@ -2,10 +2,11 @@ package org.gcube.application.cms.plugins.reports;
import lombok.Data; import lombok.Data;
import org.gcube.application.cms.plugins.requests.StepExecutionRequest; import org.gcube.application.cms.plugins.requests.StepExecutionRequest;
import org.gcube.application.geoportal.common.model.document.LifecycleInformation;
import org.gcube.application.geoportal.common.model.document.ProfiledDocument; import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
@Data @Data
public class ExecutionReport extends Report{ public class ExecutionReport {
StepExecutionRequest request; StepExecutionRequest request;

View File

@ -1,7 +1,6 @@
package org.gcube.application.cms.concessioni.plugins; package org.gcube.application.cms.concessioni.plugins;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.bson.Document;
import org.gcube.application.cms.Serialization; import org.gcube.application.cms.Serialization;
import org.gcube.application.cms.custom.gna.concessioni.model.ProfiledConcessione; import org.gcube.application.cms.custom.gna.concessioni.model.ProfiledConcessione;
import org.gcube.application.cms.plugins.LifecycleManager; import org.gcube.application.cms.plugins.LifecycleManager;
@ -11,11 +10,10 @@ import org.gcube.application.cms.plugins.faults.StepException;
import org.gcube.application.cms.plugins.model.PluginDescriptor; import org.gcube.application.cms.plugins.model.PluginDescriptor;
import org.gcube.application.cms.plugins.reports.ExecutionReport; import org.gcube.application.cms.plugins.reports.ExecutionReport;
import org.gcube.application.cms.plugins.reports.InitializationReport; import org.gcube.application.cms.plugins.reports.InitializationReport;
import org.gcube.application.cms.plugins.reports.Report;
import org.gcube.application.cms.plugins.requests.StepExecutionRequest; import org.gcube.application.cms.plugins.requests.StepExecutionRequest;
import org.gcube.application.geoportal.common.model.document.ComparableVersion; import org.gcube.application.geoportal.common.model.document.ComparableVersion;
import org.gcube.application.geoportal.common.model.document.LifecycleInformation;
import org.gcube.application.geoportal.common.model.document.ProfiledDocument; import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
import org.gcube.application.geoportal.common.utils.JSONPathWrapper;
@Slf4j @Slf4j
public class ConcessioniLifeCycleManager implements LifecycleManager { public class ConcessioniLifeCycleManager implements LifecycleManager {
@ -46,9 +44,12 @@ public class ConcessioniLifeCycleManager implements LifecycleManager {
public ExecutionReport performStep(StepExecutionRequest request) throws StepException { public ExecutionReport performStep(StepExecutionRequest request) throws StepException {
log.info("Serving Request {}",request); log.info("Serving Request {}",request);
ExecutionReport report=new ExecutionReport(); ExecutionReport report=new ExecutionReport();
LifecycleInformation info=new LifecycleInformation();
info.setPhase(request.getStep());
info.setLastOperationStatus(LifecycleInformation.Status.OK);
report.setRequest(request); report.setRequest(request);
report.setStatus(Report.Status.OK);
report.setResult(request.getDocument()); report.setResult(request.getDocument());
try { try {
switch (request.getStep()) { switch (request.getStep()) {
case StepExecutionRequest.Steps.ON_INIT_DOCUMENT: case StepExecutionRequest.Steps.ON_INIT_DOCUMENT:
@ -80,8 +81,8 @@ public class ConcessioniLifeCycleManager implements LifecycleManager {
throw e; throw e;
}catch (Throwable t){ }catch (Throwable t){
log.error("Unable to perform step "+request.getStep(),t); log.error("Unable to perform step "+request.getStep(),t);
report.setStatus(Report.Status.ERROR); report.getResult().getLifecycleInformation().setLastOperationStatus(LifecycleInformation.Status.ERROR);
report.putMessage("Unable to execute Step "+request.getStep()+". Error was "+t.getMessage()); report.getResult().getLifecycleInformation().addErrorMessage("Unable to execute Step "+request.getStep()+". Error was "+t.getMessage());
} }
return report; return report;
} }

View File

@ -2,6 +2,7 @@ package org.gcube.application.geoportal.common.model.document;
import lombok.*; import lombok.*;
import java.util.ArrayList;
import java.util.List; import java.util.List;
@NoArgsConstructor @NoArgsConstructor
@ -18,7 +19,7 @@ public class LifecycleInformation {
public static final String CHILDREN="children"; public static final String CHILDREN="children";
public static enum Status{ public static enum Status{
PASSED,ERROR,WARNING OK,ERROR,WARNING
} }
@ -28,4 +29,15 @@ public class LifecycleInformation {
private List<String> warningMessages; private List<String> warningMessages;
private List<LifecycleInformation> children; private List<LifecycleInformation> children;
public void addErrorMessage(String msg){
if(errorMessages==null)
errorMessages=new ArrayList<>();
errorMessages.add(msg);
}
public void addWarningMessage(String msg){
if(warningMessages==null)
warningMessages=new ArrayList<>();
warningMessages.add(msg);
}
} }