gcube-cms-suite/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/implementations/GuardedExecution.java

36 lines
988 B
Java

package org.gcube.application.cms.plugins.implementations;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.gcube.application.cms.plugins.reports.DocumentHandlingReport;
import org.gcube.application.cms.plugins.requests.BaseExecutionRequest;
@Slf4j
public abstract class GuardedExecution<R extends BaseExecutionRequest,T extends DocumentHandlingReport> {
@Getter
protected T result = null;
protected T theReport;
public T execute() throws Exception {
log.trace("Executing {} ",theReport.getTheRequest());
if(theReport==null) throw new RuntimeException("Unexpected state : request cannot be null");
result = run();
log.trace("Report is {} ",theReport);
return result;
}
public T getResult() {
return result;
}
protected abstract T run() throws Exception;
public GuardedExecution<R, T> setTheReport(T theReport) {
this.theReport = theReport;
return this;
}
}