use of org.eclipse.vorto.repository.workflow.model.IAction in project vorto by eclipse.
the class DefaultWorkflowService method start.
@Override
public ModelId start(ModelId modelId, IUserContext user) {
IAction initial = SIMPLE_WORKFLOW.getInitialAction();
initial.getFunctions().forEach(a -> executeFunction(a, createDummyModelInfo(modelId, user), user, Collections.emptyMap()));
IState nextState = initial.getTo();
return getModelRepository(user).updateState(modelId, nextState.getName());
}
use of org.eclipse.vorto.repository.workflow.model.IAction in project vorto by eclipse.
the class DefaultWorkflowService method doAction.
@Override
public ModelInfo doAction(ModelId model, IUserContext user, String actionName) throws WorkflowException {
ModelInfo modelInfo = getModelRepository(user).getById(model);
final Optional<IState> state = SIMPLE_WORKFLOW.getState(modelInfo.getState());
final Optional<IAction> action = state.get().getAction(actionName);
if (action.isPresent() && isValidInput(modelInfo, action.get(), user) && passesConditions(action.get().getConditions(), modelInfo, user)) {
// test
IAction actionTest = action.get();
final IState newState = action.get().getTo();
modelInfo.setState(newState.getName());
ModelInfo updatedInfo = getModelRepository(user).updateMeta(modelInfo);
Map<String, Object> ctx = new HashMap<>();
action.get().getFunctions().stream().forEach(a -> executeFunction(a, modelInfo, user, ctx));
return updatedInfo;
} else {
throw new WorkflowException(modelInfo, "The given action is invalid.");
}
}
Aggregations