Search in sources :

Example 1 with IAction

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());
}
Also used : IState(org.eclipse.vorto.repository.workflow.model.IState) IAction(org.eclipse.vorto.repository.workflow.model.IAction)

Example 2 with IAction

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.");
    }
}
Also used : IState(org.eclipse.vorto.repository.workflow.model.IState) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) IAction(org.eclipse.vorto.repository.workflow.model.IAction) HashMap(java.util.HashMap) WorkflowException(org.eclipse.vorto.repository.workflow.WorkflowException)

Aggregations

IAction (org.eclipse.vorto.repository.workflow.model.IAction)2 IState (org.eclipse.vorto.repository.workflow.model.IState)2 HashMap (java.util.HashMap)1 ModelInfo (org.eclipse.vorto.repository.core.ModelInfo)1 WorkflowException (org.eclipse.vorto.repository.workflow.WorkflowException)1