use of org.activiti.engine.repository.ProcessDefinition in project Activiti by Activiti.
the class StartAuthorizationTest method testPotentialStarter.
@Deployment
public void testPotentialStarter() throws Exception {
// first check an unauthorized user. An exception is expected
setUpUsersAndGroups();
try {
// Authentication should not be done. So an unidentified user should also be able to start the process
identityService.setAuthenticatedUserId("unauthorizedUser");
try {
runtimeService.startProcessInstanceByKey("potentialStarter");
} catch (Exception e) {
fail("No StartAuthorizationException expected, " + e.getClass().getName() + " caught.");
}
// check with an authorized user obviously it should be no problem starting the process
identityService.setAuthenticatedUserId("user1");
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("potentialStarter");
assertProcessEnded(processInstance.getId());
assertTrue(processInstance.isEnded());
//check extensionElements with : <formalExpression>group2, group(group3), user(user3)</formalExpression>
ProcessDefinition potentialStarter = repositoryService.createProcessDefinitionQuery().processDefinitionKey("potentialStarter").startableByUser("user1").latestVersion().singleResult();
assertNotNull(potentialStarter);
potentialStarter = repositoryService.createProcessDefinitionQuery().processDefinitionKey("potentialStarter").startableByUser("user3").latestVersion().singleResult();
assertNotNull(potentialStarter);
potentialStarter = repositoryService.createProcessDefinitionQuery().processDefinitionKey("potentialStarter").startableByUser("userInGroup2").latestVersion().singleResult();
assertNotNull(potentialStarter);
potentialStarter = repositoryService.createProcessDefinitionQuery().processDefinitionKey("potentialStarter").startableByUser("userInGroup3").latestVersion().singleResult();
assertNotNull(potentialStarter);
} finally {
tearDownUsersAndGroups();
}
}
use of org.activiti.engine.repository.ProcessDefinition in project Activiti by Activiti.
the class ProcessDefinitionIdentityLinkResource method deleteIdentityLink.
@RequestMapping(value = "/repository/process-definitions/{processDefinitionId}/identitylinks/{family}/{identityId}", method = RequestMethod.DELETE)
public void deleteIdentityLink(@PathVariable("processDefinitionId") String processDefinitionId, @PathVariable("family") String family, @PathVariable("identityId") String identityId, HttpServletResponse response) {
ProcessDefinition processDefinition = getProcessDefinitionFromRequest(processDefinitionId);
validateIdentityLinkArguments(family, identityId);
// Check if identitylink to delete exists
IdentityLink link = getIdentityLink(family, identityId, processDefinition.getId());
if (link.getUserId() != null) {
repositoryService.deleteCandidateStarterUser(processDefinition.getId(), link.getUserId());
} else {
repositoryService.deleteCandidateStarterGroup(processDefinition.getId(), link.getGroupId());
}
response.setStatus(HttpStatus.NO_CONTENT.value());
}
use of org.activiti.engine.repository.ProcessDefinition in project Activiti by Activiti.
the class ProcessDefinitionIdentityLinkResource method getIdentityLink.
@RequestMapping(value = "/repository/process-definitions/{processDefinitionId}/identitylinks/{family}/{identityId}", method = RequestMethod.GET, produces = "application/json")
public RestIdentityLink getIdentityLink(@PathVariable("processDefinitionId") String processDefinitionId, @PathVariable("family") String family, @PathVariable("identityId") String identityId, HttpServletRequest request) {
ProcessDefinition processDefinition = getProcessDefinitionFromRequest(processDefinitionId);
validateIdentityLinkArguments(family, identityId);
// Check if identitylink to get exists
IdentityLink link = getIdentityLink(family, identityId, processDefinition.getId());
return restResponseFactory.createRestIdentityLink(link);
}
use of org.activiti.engine.repository.ProcessDefinition in project Activiti by Activiti.
the class ProcessDefinitionResource method executeProcessDefinitionAction.
@RequestMapping(value = "/repository/process-definitions/{processDefinitionId}", method = RequestMethod.PUT, produces = "application/json")
public ProcessDefinitionResponse executeProcessDefinitionAction(@PathVariable String processDefinitionId, @RequestBody ProcessDefinitionActionRequest actionRequest, HttpServletRequest request) {
if (actionRequest == null) {
throw new ActivitiIllegalArgumentException("No action found in request body.");
}
ProcessDefinition processDefinition = getProcessDefinitionFromRequest(processDefinitionId);
if (actionRequest.getCategory() != null) {
// Update of category required
repositoryService.setProcessDefinitionCategory(processDefinition.getId(), actionRequest.getCategory());
// No need to re-fetch the ProcessDefinition entity, just update category in response
ProcessDefinitionResponse response = restResponseFactory.createProcessDefinitionResponse(processDefinition);
response.setCategory(actionRequest.getCategory());
return response;
} else {
// Actual action
if (actionRequest.getAction() != null) {
if (ProcessDefinitionActionRequest.ACTION_SUSPEND.equals(actionRequest.getAction())) {
return suspendProcessDefinition(processDefinition, actionRequest.isIncludeProcessInstances(), actionRequest.getDate());
} else if (ProcessDefinitionActionRequest.ACTION_ACTIVATE.equals(actionRequest.getAction())) {
return activateProcessDefinition(processDefinition, actionRequest.isIncludeProcessInstances(), actionRequest.getDate());
}
}
throw new ActivitiIllegalArgumentException("Invalid action: '" + actionRequest.getAction() + "'.");
}
}
use of org.activiti.engine.repository.ProcessDefinition in project Activiti by Activiti.
the class SimpleWorkflowResource method createWorkflow.
@RequestMapping(value = "/simple-workflow", method = RequestMethod.POST, produces = "application/json")
public SimpleWorkflowSuccessResponse createWorkflow(@RequestBody String json) {
// Convert json to simple workflow definition
SimpleWorkflowJsonConverter jsonConverter = new SimpleWorkflowJsonConverter();
WorkflowDefinition workflowDefinition = jsonConverter.readWorkflowDefinition(json.getBytes());
WorkflowDefinitionConversionFactory conversionFactory = new WorkflowDefinitionConversionFactory();
WorkflowDefinitionConversion conversion = conversionFactory.createWorkflowDefinitionConversion(workflowDefinition);
conversion.convert();
// Deploy process
BpmnModel bpmnModel = conversion.getBpmnModel();
Deployment deployment = repositoryService.createDeployment().addBpmnModel(bpmnModel.getProcesses().get(0).getName() + ".bpmn20.xml", bpmnModel).deploy();
// Fetch process definition id
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();
return new SimpleWorkflowSuccessResponse(processDefinition.getId());
}
Aggregations