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"));
}
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);
}
}
}
}
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.");
}
}
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);
}
}
}
}
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);
}
});
}
Aggregations