Search in sources :

Example 1 with WorkflowException

use of org.eclipse.vorto.repository.workflow.WorkflowException in project vorto by eclipse.

the class BulkOperationServiceTest method makeModelPublic.

@Test
public void makeModelPublic() {
    importModel("creator", "officialprefix_point3d.type");
    try {
        releaseModel(ModelId.fromPrettyFormat("com.mycompany:Point3d:1.0.0"), createUserContext("creator"));
    } catch (WorkflowException e) {
        fail("Cannot release newly imported model?");
    }
    checkCorrectness("com.mycompany:Point3d:1.0.0", "private", "Released");
    IBulkOperationsService modelService = getModelService("publisher");
    List<ModelId> result = modelService.makeModelPublic(ModelId.fromPrettyFormat("com.mycompany:Point3d:1.0.0"));
    assertEquals(1, result.size());
    ModelInfo modelInfo = getModelRepository(createUserContext("creator")).getById(ModelId.fromPrettyFormat("com.mycompany:Point3d:1.0.0"));
    assertEquals("public", modelInfo.getVisibility());
    assertTrue(hasAnonymousPolicy("com.mycompany:Point3d:1.0.0"));
}
Also used : ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) WorkflowException(org.eclipse.vorto.repository.workflow.WorkflowException) ModelId(org.eclipse.vorto.model.ModelId) Test(org.junit.Test)

Example 2 with WorkflowException

use of org.eclipse.vorto.repository.workflow.WorkflowException in project vorto by eclipse.

the class BulkReleaseFunction method execute.

@Override
public void execute(ModelInfo model, IUserContext user, Map<String, Object> context) {
    for (ModelId referenceId : model.getReferences()) {
        IModelRepository repository = repositoryFactory.getRepositoryByModel(referenceId);
        ModelInfo referenceModel = repository.getById(referenceId);
        if (ModelState.Draft.getName().equals(referenceModel.getState())) {
            try {
                workflowService.doAction(referenceId, user, SimpleWorkflowModel.ACTION_RELEASE.getName());
            } catch (WorkflowException e) {
                logger.error("Problem executing release for model " + referenceId + "during bulk release function", e);
            }
        }
    }
}
Also used : IModelRepository(org.eclipse.vorto.repository.core.IModelRepository) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) WorkflowException(org.eclipse.vorto.repository.workflow.WorkflowException) ModelId(org.eclipse.vorto.model.ModelId)

Example 3 with WorkflowException

use of org.eclipse.vorto.repository.workflow.WorkflowException 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 4 with WorkflowException

use of org.eclipse.vorto.repository.workflow.WorkflowException in project vorto by eclipse.

the class BulkApproveFunction method execute.

@Override
public void execute(ModelInfo model, IUserContext user, Map<String, Object> context) {
    for (ModelId referenceId : model.getReferences()) {
        IModelRepository repository = repositoryFactory.getRepositoryByModel(referenceId);
        ModelInfo referenceModel = repository.getById(referenceId);
        if (ModelState.InReview.getName().equals(referenceModel.getState())) {
            try {
                workflowService.doAction(referenceId, user, SimpleWorkflowModel.ACTION_APPROVE.getName());
            } catch (WorkflowException e) {
                logger.error("Problem executing release for model " + referenceId + "during bulk approve function", e);
            }
        }
    }
}
Also used : IModelRepository(org.eclipse.vorto.repository.core.IModelRepository) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) WorkflowException(org.eclipse.vorto.repository.workflow.WorkflowException) ModelId(org.eclipse.vorto.model.ModelId)

Example 5 with WorkflowException

use of org.eclipse.vorto.repository.workflow.WorkflowException in project vorto by eclipse.

the class DefaultPayloadMappingService method saveSpecification.

@Override
public void saveSpecification(IMappingSpecification specification, IUserContext user) {
    MappingSpecificationSerializer.create(specification).iterator().forEachRemaining(serializer -> {
        final ModelId createdModelId = serializer.getModelId();
        String serializedMapping = serializer.serialize();
        LOGGER.trace(String.format("Saving mapping: %s", serializedMapping));
        this.modelRepositoryFactory.getRepositoryByModel(createdModelId).save(createdModelId, serializedMapping.getBytes(), createdModelId.getName() + ".mapping", user, false);
        try {
            workflowService.start(createdModelId, user);
        } catch (WorkflowException e) {
            throw new RuntimeException("Could not start workflow for mapping model", e);
        }
    });
}
Also used : WorkflowException(org.eclipse.vorto.repository.workflow.WorkflowException) ModelId(org.eclipse.vorto.model.ModelId)

Aggregations

WorkflowException (org.eclipse.vorto.repository.workflow.WorkflowException)5 ModelId (org.eclipse.vorto.model.ModelId)4 ModelInfo (org.eclipse.vorto.repository.core.ModelInfo)4 IModelRepository (org.eclipse.vorto.repository.core.IModelRepository)2 HashMap (java.util.HashMap)1 IAction (org.eclipse.vorto.repository.workflow.model.IAction)1 IState (org.eclipse.vorto.repository.workflow.model.IState)1 Test (org.junit.Test)1