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