@Override public List<ProcessDefinition> executeList(CommandContext commandContext, Page page) { checkQueryOk(); List<ProcessDefinition> list = commandContext .getProcessDefinitionManager() .findProcessDefinitionsByQueryCriteria(this, page); for (ProcessDefinition processDefinition : list) { BpmnModelInstance bpmnModelInstance = Context.getProcessEngineConfiguration() .getDeploymentCache() .findBpmnModelInstanceForProcessDefinition( (ProcessDefinitionEntity) processDefinition); ModelElementInstance processElement = bpmnModelInstance.getModelElementById(processDefinition.getKey()); if (processElement != null) { Collection<Documentation> documentations = processElement.getChildElementsByType(Documentation.class); List<String> docStrings = new ArrayList<String>(); for (Documentation documentation : documentations) { docStrings.add(documentation.getTextContent()); } ProcessDefinitionEntity processDefinitionEntity = (ProcessDefinitionEntity) processDefinition; processDefinitionEntity.setProperty( BpmnParse.PROPERTYNAME_DOCUMENTATION, BpmnParse.parseDocumentation(docStrings)); } } return list; }
@Deployment(resources = {"org/camunda/bpm/engine/test/api/mgmt/SuspensionTest.testBase.bpmn"}) public void testActivationByProcessDefinitionKey_shouldActivateJob() { // given // a deployed process definition ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult(); // a running process instance with a failed job Map<String, Object> params = new HashMap<String, Object>(); params.put("fail", Boolean.TRUE); runtimeService.startProcessInstanceByKey("suspensionProcess", params); // suspended job definitions and corresponding jobs managementService.suspendJobDefinitionByProcessDefinitionKey("suspensionProcess", true); // the failed job JobQuery jobQuery = managementService.createJobQuery(); Job job = jobQuery.singleResult(); assertTrue(job.isSuspended()); // when // the job will be activated managementService.activateJobByProcessDefinitionKey(processDefinition.getKey()); // then // the job should be suspended assertEquals(0, jobQuery.suspended().count()); assertEquals(1, jobQuery.active().count()); Job activeJob = jobQuery.active().singleResult(); assertEquals(job.getId(), activeJob.getId()); assertFalse(activeJob.isSuspended()); }
@Deployment(resources = {"org/camunda/bpm/engine/test/db/processOne.bpmn20.xml"}) public void testSuspendActivateProcessDefinitionByKey() { ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult(); assertFalse(processDefinition.isSuspended()); // suspend repositoryService.suspendProcessDefinitionByKey(processDefinition.getKey()); processDefinition = repositoryService.createProcessDefinitionQuery().singleResult(); assertTrue(processDefinition.isSuspended()); // activate repositoryService.activateProcessDefinitionByKey(processDefinition.getKey()); processDefinition = repositoryService.createProcessDefinitionQuery().singleResult(); assertFalse(processDefinition.isSuspended()); }
@Deployment(resources = {"org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml"}) public void testStartProcessInstanceById() { List<ProcessDefinition> processDefinitions = repositoryService.createProcessDefinitionQuery().list(); assertEquals(1, processDefinitions.size()); ProcessDefinition processDefinition = processDefinitions.get(0); assertEquals("oneTaskProcess", processDefinition.getKey()); assertNotNull(processDefinition.getId()); }
@Deployment(resources = {"org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml"}) public void testSuspendProcessInstancesDuringProcessDefinitionSuspend() { int nrOfProcessInstances = 9; // Fire up a few processes for the deployed process definition ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult(); for (int i = 0; i < nrOfProcessInstances; i++) { runtimeService.startProcessInstanceByKey(processDefinition.getKey()); } assertEquals(nrOfProcessInstances, runtimeService.createProcessInstanceQuery().count()); assertEquals(0, runtimeService.createProcessInstanceQuery().suspended().count()); assertEquals( nrOfProcessInstances, runtimeService.createProcessInstanceQuery().active().count()); // Suspend process definitions and include process instances repositoryService.suspendProcessDefinitionById(processDefinition.getId(), true, null); // Verify all process instances are also suspended for (ProcessInstance processInstance : runtimeService.createProcessInstanceQuery().list()) { assertTrue(processInstance.isSuspended()); } // Verify all process instances can't be continued for (Task task : taskService.createTaskQuery().list()) { try { taskService.complete(task.getId()); fail("A suspended task shouldn't be able to be continued"); } catch (SuspendedEntityInteractionException e) { // This is good } } assertEquals(nrOfProcessInstances, runtimeService.createProcessInstanceQuery().count()); assertEquals( nrOfProcessInstances, runtimeService.createProcessInstanceQuery().suspended().count()); assertEquals(0, runtimeService.createProcessInstanceQuery().active().count()); // Activate the process definition again repositoryService.activateProcessDefinitionById(processDefinition.getId(), true, null); // Verify that all process instances can be completed for (Task task : taskService.createTaskQuery().list()) { taskService.complete(task.getId()); } assertEquals(0, runtimeService.createProcessInstanceQuery().count()); assertEquals(0, runtimeService.createProcessInstanceQuery().suspended().count()); assertEquals(0, runtimeService.createProcessInstanceQuery().active().count()); }
@Deployment(resources = {"org/camunda/bpm/engine/test/api/oneTaskProcess.bpmn20.xml"}) public void testFindProcessDefinitionById() { List<ProcessDefinition> definitions = repositoryService.createProcessDefinitionQuery().list(); assertEquals(1, definitions.size()); ProcessDefinition processDefinition = repositoryService .createProcessDefinitionQuery() .processDefinitionId(definitions.get(0).getId()) .singleResult(); runtimeService.startProcessInstanceByKey("oneTaskProcess"); assertNotNull(processDefinition); assertEquals("oneTaskProcess", processDefinition.getKey()); assertEquals("The One Task Process", processDefinition.getName()); processDefinition = repositoryService.getProcessDefinition(definitions.get(0).getId()); assertEquals("This is a process for testing purposes", processDefinition.getDescription()); }
@Deployment(resources = {"org/camunda/bpm/engine/test/api/runtime/oneTaskProcess.bpmn20.xml"}) public void testContinueProcessAfterProcessDefinitionSuspend() { // Start Process Instance ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult(); runtimeService.startProcessInstanceByKey(processDefinition.getKey()); // Verify one task is created Task task = taskService.createTaskQuery().singleResult(); assertNotNull(task); assertEquals(1, runtimeService.createProcessInstanceQuery().count()); // Suspend process definition repositoryService.suspendProcessDefinitionById(processDefinition.getId()); // Process should be able to continue taskService.complete(task.getId()); assertEquals(0, runtimeService.createProcessInstanceQuery().count()); }
@Deployment(resources = {"org/camunda/bpm/engine/test/db/processOne.bpmn20.xml"}) public void testStartProcessInstanceForSuspendedProcessDefinition() { ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult(); repositoryService.suspendProcessDefinitionById(processDefinition.getId()); // By id try { runtimeService.startProcessInstanceById(processDefinition.getId()); fail("Exception is expected but not thrown"); } catch (SuspendedEntityInteractionException e) { assertTextPresentIgnoreCase("is suspended", e.getMessage()); } // By Key try { runtimeService.startProcessInstanceByKey(processDefinition.getKey()); fail("Exception is expected but not thrown"); } catch (SuspendedEntityInteractionException e) { assertTextPresentIgnoreCase("is suspended", e.getMessage()); } }
public void setProcessDefinition(ProcessDefinition processDefinition) { this.processDefinitionId = processDefinition.getId(); this.processDefinitionKey = processDefinition.getKey(); this.processDefinitionName = processDefinition.getName(); }