Search in sources :

Example 31 with ProcessDefinition

use of org.activiti.engine.repository.ProcessDefinition in project Activiti by Activiti.

the class ProcessDefinitionSuspensionTest method testDelayedSuspendProcessDefinitionIncludingProcessInstances.

@Deployment(resources = { "org/activiti/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testDelayedSuspendProcessDefinitionIncludingProcessInstances() {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    Date startTime = new Date();
    processEngineConfiguration.getClock().setCurrentTime(startTime);
    // Start some process instances
    int nrOfProcessInstances = 30;
    for (int i = 0; i < nrOfProcessInstances; i++) {
        runtimeService.startProcessInstanceById(processDefinition.getId());
    }
    assertEquals(nrOfProcessInstances, runtimeService.createProcessInstanceQuery().count());
    assertEquals(nrOfProcessInstances, runtimeService.createProcessInstanceQuery().active().count());
    assertEquals(0, runtimeService.createProcessInstanceQuery().suspended().count());
    assertEquals(0, taskService.createTaskQuery().suspended().count());
    assertEquals(nrOfProcessInstances, taskService.createTaskQuery().active().count());
    assertEquals(1, repositoryService.createProcessDefinitionQuery().active().count());
    assertEquals(0, repositoryService.createProcessDefinitionQuery().suspended().count());
    // Suspend process definition in one week from now
    long oneWeekFromStartTime = startTime.getTime() + (7 * 24 * 60 * 60 * 1000);
    repositoryService.suspendProcessDefinitionById(processDefinition.getId(), true, new Date(oneWeekFromStartTime));
    // Verify we can start process instances
    runtimeService.startProcessInstanceById(processDefinition.getId());
    nrOfProcessInstances = nrOfProcessInstances + 1;
    assertEquals(nrOfProcessInstances, runtimeService.createProcessInstanceQuery().count());
    // Move clock 9 days further and let job executor run
    long eightDaysSinceStartTime = oneWeekFromStartTime + (2 * 24 * 60 * 60 * 1000);
    processEngineConfiguration.getClock().setCurrentTime(new Date(eightDaysSinceStartTime));
    waitForJobExecutorToProcessAllJobs(5000L, 50L);
    // Try to start process instance. It should fail now.
    try {
        runtimeService.startProcessInstanceById(processDefinition.getId());
        fail();
    } catch (ActivitiException e) {
        assertTextPresentIgnoreCase("suspended", e.getMessage());
    }
    assertEquals(nrOfProcessInstances, runtimeService.createProcessInstanceQuery().count());
    assertEquals(0, runtimeService.createProcessInstanceQuery().active().count());
    assertEquals(nrOfProcessInstances, runtimeService.createProcessInstanceQuery().suspended().count());
    assertEquals(nrOfProcessInstances, taskService.createTaskQuery().suspended().count());
    assertEquals(0, taskService.createTaskQuery().active().count());
    assertEquals(0, repositoryService.createProcessDefinitionQuery().active().count());
    assertEquals(1, repositoryService.createProcessDefinitionQuery().suspended().count());
    // Activate again
    repositoryService.activateProcessDefinitionById(processDefinition.getId(), true, null);
    assertEquals(nrOfProcessInstances, runtimeService.createProcessInstanceQuery().count());
    assertEquals(nrOfProcessInstances, runtimeService.createProcessInstanceQuery().active().count());
    assertEquals(0, runtimeService.createProcessInstanceQuery().suspended().count());
    assertEquals(0, taskService.createTaskQuery().suspended().count());
    assertEquals(nrOfProcessInstances, taskService.createTaskQuery().active().count());
    assertEquals(1, repositoryService.createProcessDefinitionQuery().active().count());
    assertEquals(0, repositoryService.createProcessDefinitionQuery().suspended().count());
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) Date(java.util.Date) Deployment(org.activiti.engine.test.Deployment)

Example 32 with ProcessDefinition

use of org.activiti.engine.repository.ProcessDefinition in project Activiti by Activiti.

the class RepositoryServiceTest method testProcessDefinitionEntitySerializable.

@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testProcessDefinitionEntitySerializable() {
    String procDefId = repositoryService.createProcessDefinitionQuery().singleResult().getId();
    ProcessDefinition processDefinition = repositoryService.getProcessDefinition(procDefId);
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        new ObjectOutputStream(baos).writeObject(processDefinition);
        byte[] bytes = baos.toByteArray();
        assertTrue(bytes.length > 0);
    } catch (IOException e) {
        e.printStackTrace();
        fail();
    }
}
Also used : ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) Deployment(org.activiti.engine.test.Deployment)

Example 33 with ProcessDefinition

use of org.activiti.engine.repository.ProcessDefinition in project Activiti by Activiti.

the class RepositoryServiceTest method testStartProcessInstanceById.

@Deployment(resources = { "org/activiti/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());
}
Also used : ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) Deployment(org.activiti.engine.test.Deployment)

Example 34 with ProcessDefinition

use of org.activiti.engine.repository.ProcessDefinition in project Activiti by Activiti.

the class ReportingUtil method generateTaskDurationReport.

// WARNING!!! DemoWare!!!
public static void generateTaskDurationReport(String processDefinitionId) {
    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    RepositoryService repositoryService = processEngine.getRepositoryService();
    // Fetch process definition
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefinitionId).singleResult();
    // Report descriptin
    String reportDescription = "Average task duration report for process definition " + processDefinition.getName() + " ( version " + processDefinition.getVersion() + ")";
    // Script (just plain String for the moment)
    String script = "importPackage(java.sql);" + "importPackage(java.lang);" + "importPackage(org.activiti.explorer.reporting);" + "" + "var processDefinitionId = '" + processDefinitionId + "';" + "" + "var result = ReportingUtil.executeSelectSqlQuery(\"select NAME_, avg(DURATION_) from ACT_HI_TASKINST where PROC_DEF_ID_ = '" + processDefinitionId + "' and END_TIME_ is not null group by NAME_\");" + "" + "var reportData = new ReportData();" + "var dataset = reportData.newDataset();" + "dataset.type = 'pieChart';" + "dataset.description = '" + reportDescription + "';" + "" + "while (result.next()) { " + "  var name = result.getString(1);" + "  var val = result.getLong(2) / 1000;" + "  dataset.add(name, val);" + "}" + "" + "execution.setVariable('reportData', reportData.toBytes());";
    // Generate bpmn model
    WorkflowDefinition workflowDefinition = new WorkflowDefinition().name(processDefinition.getName() + " task duration report").description(reportDescription).addScriptStep(script);
    // Convert to BPMN 2.0 XML
    WorkflowDefinitionConversion conversion = ExplorerApp.get().getWorkflowDefinitionConversionFactory().createWorkflowDefinitionConversion(workflowDefinition);
    conversion.convert();
    conversion.getBpmnModel().setTargetNamespace("activiti-report");
    // Generate DI
    BpmnAutoLayout bpmnAutoLayout = new BpmnAutoLayout(conversion.getBpmnModel());
    bpmnAutoLayout.execute();
    // Deploy
    repositoryService.createDeployment().name(processDefinition.getName() + " - task duration report").addString(conversion.getProcess().getId() + ".bpmn20.xml", conversion.getBpmn20Xml()).deploy();
}
Also used : WorkflowDefinitionConversion(org.activiti.workflow.simple.converter.WorkflowDefinitionConversion) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) BpmnAutoLayout(org.activiti.bpmn.BpmnAutoLayout) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ProcessEngine(org.activiti.engine.ProcessEngine) RepositoryService(org.activiti.engine.RepositoryService)

Example 35 with ProcessDefinition

use of org.activiti.engine.repository.ProcessDefinition in project Activiti by Activiti.

the class DeploymentEntityManager method findNewLatestProcessDefinitionAfterRemovalOf.

protected ProcessDefinition findNewLatestProcessDefinitionAfterRemovalOf(ProcessDefinition processDefinitionToBeRemoved) {
    // The latest process definition is not necessarily the one with 'version -1' (some versions could have been deleted)
    // Hence, the following logic
    ProcessDefinitionQueryImpl query = new ProcessDefinitionQueryImpl();
    query.processDefinitionKey(processDefinitionToBeRemoved.getKey());
    if (processDefinitionToBeRemoved.getTenantId() != null && !ProcessEngineConfiguration.NO_TENANT_ID.equals(processDefinitionToBeRemoved.getTenantId())) {
        query.processDefinitionTenantId(processDefinitionToBeRemoved.getTenantId());
    } else {
        query.processDefinitionWithoutTenantId();
    }
    query.processDefinitionVersionLowerThan(processDefinitionToBeRemoved.getVersion());
    query.orderByProcessDefinitionVersion().desc();
    List<ProcessDefinition> processDefinitions = getProcessDefinitionManager().findProcessDefinitionsByQueryCriteria(query, new Page(0, 1));
    if (processDefinitions != null && processDefinitions.size() > 0) {
        return processDefinitions.get(0);
    }
    return null;
}
Also used : ProcessDefinitionQueryImpl(org.activiti.engine.impl.ProcessDefinitionQueryImpl) Page(org.activiti.engine.impl.Page) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition)

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