changes for AddresourceOperation
This commit is contained in:
parent
bb0d641c12
commit
f11ea84657
|
@ -0,0 +1,16 @@
|
||||||
|
package org.gcube.vremanagement.contextmanager.model.exceptions;
|
||||||
|
|
||||||
|
public class InvalidParameterException extends OperationException {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
|
||||||
|
public InvalidParameterException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package org.gcube.vremanagement.contextmanager.model.exceptions;
|
||||||
|
|
||||||
|
public abstract class OperationException extends Exception{
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public OperationException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
// TODO Auto-generated constructor stub
|
||||||
|
}
|
||||||
|
|
||||||
|
public OperationException(String message) {
|
||||||
|
super(message);
|
||||||
|
// TODO Auto-generated constructor stub
|
||||||
|
}
|
||||||
|
|
||||||
|
public OperationException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
// TODO Auto-generated constructor stub
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package org.gcube.vremanagement.contextmanager.model.operators;
|
||||||
|
|
||||||
|
public class AddResourceParameter implements OperatorParameters{
|
||||||
|
|
||||||
|
private String contextId;
|
||||||
|
private String resourceId;
|
||||||
|
|
||||||
|
protected AddResourceParameter() {}
|
||||||
|
|
||||||
|
public AddResourceParameter(String contextId, String resourceId) {
|
||||||
|
super();
|
||||||
|
this.contextId = contextId;
|
||||||
|
this.resourceId = resourceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getContextId() {
|
||||||
|
return contextId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getResourceId() {
|
||||||
|
return resourceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
package org.gcube.vremanagement.contextmanager.model.operators;
|
package org.gcube.vremanagement.contextmanager.model.operators;
|
||||||
|
|
||||||
public class OperationParameters {
|
public interface OperatorParameters {
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,15 +1,15 @@
|
||||||
package org.gcube.vremanagement.contextmanager.model.operators.context;
|
package org.gcube.vremanagement.contextmanager.model.operators.context;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.gcube.vremanagement.contextmanager.model.types.Context;
|
import org.gcube.vremanagement.contextmanager.model.types.Context;
|
||||||
|
|
||||||
public interface ContextOperator {
|
public interface ContextOperator {
|
||||||
|
|
||||||
Context.Type getApplicationContextType();
|
Set<Context.Type> getAllowedContextType();
|
||||||
|
|
||||||
String getOperationId();
|
String getOperationId();
|
||||||
|
|
||||||
String getName();
|
|
||||||
|
|
||||||
String getDescription();
|
String getDescription();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,40 @@
|
||||||
package org.gcube.vremanagement.contextmanager.model.operators.context;
|
package org.gcube.vremanagement.contextmanager.model.operators.context;
|
||||||
|
|
||||||
public interface CustomContextOperator extends ContextOperator {
|
import org.gcube.vremanagement.contextmanager.model.exceptions.InvalidParameterException;
|
||||||
|
import org.gcube.vremanagement.contextmanager.model.exceptions.OperationException;
|
||||||
|
import org.gcube.vremanagement.contextmanager.model.operators.OperatorParameters;
|
||||||
|
import org.gcube.vremanagement.contextmanager.model.report.OperationResult;
|
||||||
|
import org.gcube.vremanagement.contextmanager.model.report.ReportEntry;
|
||||||
|
import org.gcube.vremanagement.contextmanager.model.types.Context;
|
||||||
|
|
||||||
|
public abstract class CustomContextOperator<T, P extends OperatorParameters> implements ContextOperator {
|
||||||
|
|
||||||
|
protected abstract P checkAndTrasformParameters(Context context, OperatorParameters params) throws InvalidParameterException;
|
||||||
|
|
||||||
|
protected abstract T execute(Context context, P params) throws OperationException;
|
||||||
|
|
||||||
|
public abstract T undo(Context context, OperatorParameters params);
|
||||||
|
|
||||||
|
public ReportEntry<T> run(Context context, P params){
|
||||||
|
P operationParams = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
operationParams = checkAndTrasformParameters(context, params);
|
||||||
|
} catch (InvalidParameterException e) {
|
||||||
|
return new ReportEntry<T>(this.getOperationId(), this.getDescription(), OperationResult.failure("parameters error: "+e.getMessage()), null);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
return new ReportEntry<T>(this.getOperationId(), this.getDescription(), OperationResult.failure("unexpected parameters error: "+e.getMessage()), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
T result = null;
|
||||||
|
try {
|
||||||
|
result = execute(context, operationParams);
|
||||||
|
}catch (OperationException e) {
|
||||||
|
return new ReportEntry<T>(this.getOperationId(), this.getDescription(), OperationResult.failure("operation error: "+e.getMessage()), null);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
return new ReportEntry<T>(this.getOperationId(), this.getDescription(), OperationResult.failure("unexpected operation error: "+e.getMessage()), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ReportEntry<T>(this.getOperationId(), this.getDescription(), OperationResult.success() , result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
package org.gcube.vremanagement.contextmanager.model.operators.resource;
|
|
||||||
|
|
||||||
import org.gcube.vremanagement.contextmanager.model.operators.OperationParameters;
|
|
||||||
|
|
||||||
public interface ResourceOperator {
|
|
||||||
|
|
||||||
public void onResourceAdd(String token, String context, OperationParameters parameters);
|
|
||||||
|
|
||||||
public void onResourceRemove(String token, String context, OperationParameters parameters);
|
|
||||||
|
|
||||||
}
|
|
|
@ -3,12 +3,64 @@ package org.gcube.vremanagement.contextmanager.model.report;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.gcube.vremanagement.contextmanager.model.types.Context.Type;
|
||||||
|
|
||||||
public class Report {
|
public class Report {
|
||||||
|
|
||||||
String contextName;
|
private String contextId;
|
||||||
String contextType;
|
private String contextName;
|
||||||
|
private Type contextType;
|
||||||
|
private String operationName;
|
||||||
|
private String user;
|
||||||
|
|
||||||
|
private OperationResult result;
|
||||||
|
|
||||||
private List<ReportOperation> entries = new LinkedList<>();
|
private List<ReportOperation> entries = new LinkedList<>();
|
||||||
|
|
||||||
|
protected Report() {}
|
||||||
|
|
||||||
|
public Report(String contextId, String contextName, Type contextType, String operationName, String user) {
|
||||||
|
super();
|
||||||
|
this.contextId = contextId;
|
||||||
|
this.contextName = contextName;
|
||||||
|
this.contextType = contextType;
|
||||||
|
this.operationName = operationName;
|
||||||
|
this.user = user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getContextId() {
|
||||||
|
return contextId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getContextName() {
|
||||||
|
return contextName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Type getContextType() {
|
||||||
|
return contextType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOperationName() {
|
||||||
|
return operationName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ReportOperation> getEntries() {
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(ReportOperation operation) {
|
||||||
|
entries.add(operation);
|
||||||
|
}
|
||||||
|
|
||||||
|
public OperationResult getResult() {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setResult(OperationResult result) {
|
||||||
|
this.result = result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,27 +1,27 @@
|
||||||
package org.gcube.vremanagement.contextmanager.model.report;
|
package org.gcube.vremanagement.contextmanager.model.report;
|
||||||
|
|
||||||
import org.gcube.vremanagement.contextmanager.model.operators.OperationParameters;
|
import org.gcube.vremanagement.contextmanager.model.operators.OperatorParameters;
|
||||||
|
|
||||||
public class ReportEntry implements ReportOperation{
|
public class ReportEntry<T> implements ReportOperation{
|
||||||
|
|
||||||
private String operationId;
|
private String operationId;
|
||||||
private String name;
|
|
||||||
private String description;
|
private String description;
|
||||||
private OperationParameters parameters;
|
private OperatorParameters parameters;
|
||||||
private OperationResult result;
|
private OperationResult result;
|
||||||
|
private T entryDescriptor;
|
||||||
|
|
||||||
protected ReportEntry() {}
|
protected ReportEntry() {}
|
||||||
|
|
||||||
public ReportEntry(String operationId, String name, String description, OperationResult result) {
|
public ReportEntry(String operationId, String description, OperationResult result, T entryDescriptor) {
|
||||||
super();
|
super();
|
||||||
this.operationId = operationId;
|
this.operationId = operationId;
|
||||||
this.name = name;
|
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.result = result;
|
this.result = result;
|
||||||
|
this.entryDescriptor = entryDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReportEntry(String operationId, String name, String description, OperationResult result, OperationParameters parameters) {
|
public ReportEntry(String operationId, String description, OperationResult result, OperatorParameters parameters, T entryDescriptor) {
|
||||||
this(operationId, name, description, result);
|
this(operationId, description, result, entryDescriptor);
|
||||||
this.parameters = parameters;
|
this.parameters = parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,20 +29,25 @@ public class ReportEntry implements ReportOperation{
|
||||||
return operationId;
|
return operationId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OperationParameters getParameters() {
|
public OperatorParameters getParameters() {
|
||||||
return parameters;
|
return parameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OperationResult getResult() {
|
public OperationResult getResult() {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSingleOperation() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T getEntryDescriptor() {
|
||||||
|
return entryDescriptor;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,24 +6,18 @@ import java.util.List;
|
||||||
public class ReportGroup implements ReportOperation{
|
public class ReportGroup implements ReportOperation{
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
private String description;
|
|
||||||
|
|
||||||
protected ReportGroup() {}
|
protected ReportGroup() {}
|
||||||
|
|
||||||
private List<ReportEntry> entries = new LinkedList<>();
|
private List<ReportEntry> entries = new LinkedList<>();
|
||||||
|
|
||||||
public ReportGroup(String name, String description) {
|
public ReportGroup(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.description = description;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDescription() {
|
|
||||||
return description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addEntry(ReportEntry entry) {
|
public void addEntry(ReportEntry entry) {
|
||||||
entries.add(entry);
|
entries.add(entry);
|
||||||
|
|
|
@ -2,4 +2,7 @@ package org.gcube.vremanagement.contextmanager.model.report;
|
||||||
|
|
||||||
public interface ReportOperation {
|
public interface ReportOperation {
|
||||||
|
|
||||||
|
default boolean isSingleOperation() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package org.gcube.vremanagement.contextmanager.model.types;
|
||||||
|
|
||||||
public class Context {
|
public class Context {
|
||||||
|
|
||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
private String name;
|
private String name;
|
||||||
private Context parent;
|
private Context parent;
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
package org.gcube.vremanagement.contextmanager.model.types;
|
||||||
|
|
||||||
|
import org.gcube.vremanagement.contextmanager.model.exceptions.InvalidContextException;
|
||||||
|
|
||||||
|
public interface ContextRetriever {
|
||||||
|
|
||||||
|
Context getContextById(String id) throws InvalidContextException;
|
||||||
|
}
|
Loading…
Reference in New Issue