Search in sources :

Example 1 with IState

use of org.eclipse.vorto.repository.workflow.model.IState 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 IState

use of org.eclipse.vorto.repository.workflow.model.IState 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)

Example 3 with IState

use of org.eclipse.vorto.repository.workflow.model.IState in project vorto by eclipse.

the class DefaultWorkflowService method getPossibleActions.

@Override
public List<String> getPossibleActions(ModelId model, IUserContext user) {
    ModelInfo modelInfo = getModelRepository(user).getById(model);
    Optional<IState> state = SIMPLE_WORKFLOW.getState(modelInfo.getState());
    return state.get().getActions().stream().filter(action -> passesConditions(action.getConditions(), modelInfo, user)).map(IWorkflowElement::getName).collect(Collectors.toList());
}
Also used : IState(org.eclipse.vorto.repository.workflow.model.IState) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo)

Aggregations

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