Search in sources :

Example 41 with ProcessDefinition

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();
    }
}
Also used : ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) Deployment(org.activiti.engine.test.Deployment)

Example 42 with ProcessDefinition

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());
}
Also used : ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) IdentityLink(org.activiti.engine.task.IdentityLink) RestIdentityLink(org.activiti.rest.service.api.engine.RestIdentityLink) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 43 with ProcessDefinition

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);
}
Also used : ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) IdentityLink(org.activiti.engine.task.IdentityLink) RestIdentityLink(org.activiti.rest.service.api.engine.RestIdentityLink) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 44 with ProcessDefinition

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() + "'.");
    }
}
Also used : ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 45 with ProcessDefinition

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());
}
Also used : WorkflowDefinitionConversion(org.activiti.workflow.simple.converter.WorkflowDefinitionConversion) WorkflowDefinitionConversionFactory(org.activiti.workflow.simple.converter.WorkflowDefinitionConversionFactory) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) Deployment(org.activiti.engine.repository.Deployment) SimpleWorkflowJsonConverter(org.activiti.workflow.simple.converter.json.SimpleWorkflowJsonConverter) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) BpmnModel(org.activiti.bpmn.model.BpmnModel) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)167 Deployment (org.activiti.engine.test.Deployment)82 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)37 ActivitiException (org.activiti.engine.ActivitiException)24 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)19 Task (org.activiti.engine.task.Task)16 ArrayList (java.util.ArrayList)15 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)14 JsonNode (com.fasterxml.jackson.databind.JsonNode)12 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)12 Date (java.util.Date)10 HashMap (java.util.HashMap)9 HttpGet (org.apache.http.client.methods.HttpGet)9 StringEntity (org.apache.http.entity.StringEntity)9 BpmnModel (org.activiti.bpmn.model.BpmnModel)8 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)7 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)7 IdentityLink (org.activiti.engine.task.IdentityLink)7