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;
}
use of org.activiti.engine.repository.ProcessDefinition in project Activiti by Activiti.
the class DeploymentManager method removeDeployment.
public void removeDeployment(String deploymentId, boolean cascade) {
DeploymentEntityManager deploymentEntityManager = Context.getCommandContext().getDeploymentEntityManager();
DeploymentEntity deployment = deploymentEntityManager.findDeploymentById(deploymentId);
if (deployment == null)
throw new ActivitiObjectNotFoundException("Could not find a deployment with id '" + deploymentId + "'.", DeploymentEntity.class);
// Remove any process definition from the cache
List<ProcessDefinition> processDefinitions = new ProcessDefinitionQueryImpl(Context.getCommandContext()).deploymentId(deploymentId).list();
ActivitiEventDispatcher eventDispatcher = Context.getProcessEngineConfiguration().getEventDispatcher();
for (ProcessDefinition processDefinition : processDefinitions) {
// Since all process definitions are deleted by a single query, we should dispatch the events in this loop
if (eventDispatcher.isEnabled()) {
eventDispatcher.dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_DELETED, processDefinition));
}
}
// Delete data
deploymentEntityManager.deleteDeployment(deploymentId, cascade);
// Since we use a delete by query, delete-events are not automatically dispatched
if (eventDispatcher.isEnabled()) {
eventDispatcher.dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_DELETED, deployment));
}
for (ProcessDefinition processDefinition : processDefinitions) {
processDefinitionCache.remove(processDefinition.getId());
}
}
use of org.activiti.engine.repository.ProcessDefinition in project Activiti by Activiti.
the class TimerStartEventJobHandler method startProcessDefinitionByKey.
protected void startProcessDefinitionByKey(JobEntity job, String configuration, DeploymentManager deploymentManager, CommandContext commandContext) {
// it says getActivityId, but < 5.21, this would have the process definition key stored
String processDefinitionKey = TimerEventHandler.getActivityIdFromConfiguration(configuration);
ProcessDefinition processDefinition = null;
if (job.getTenantId() == null || ProcessEngineConfiguration.NO_TENANT_ID.equals(job.getTenantId())) {
processDefinition = deploymentManager.findDeployedLatestProcessDefinitionByKey(processDefinitionKey);
} else {
processDefinition = deploymentManager.findDeployedLatestProcessDefinitionByKeyAndTenantId(processDefinitionKey, job.getTenantId());
}
if (processDefinition == null) {
throw new ActivitiException("Could not find process definition needed for timer start event");
}
try {
if (!deploymentManager.isProcessDefinitionSuspended(processDefinition.getId())) {
dispatchTimerFiredEvent(job, commandContext);
new StartProcessInstanceCmd<ProcessInstance>(processDefinitionKey, null, null, null, job.getTenantId()).execute(commandContext);
} else {
log.debug("Ignoring timer of suspended process definition {}", processDefinition.getId());
}
} catch (RuntimeException e) {
log.error("exception during timer execution", e);
throw e;
} catch (Exception e) {
log.error("exception during timer execution", e);
throw new ActivitiException("exception during timer execution: " + e.getMessage(), e);
}
}
use of org.activiti.engine.repository.ProcessDefinition in project Activiti by Activiti.
the class StartAuthorizationTest method testProcessDefinitionList.
// this test checks the list without user constraint
@Deployment
public void testProcessDefinitionList() throws Exception {
setUpUsersAndGroups();
try {
// Process 1 has no potential starters
ProcessDefinition latestProcessDef = repositoryService.createProcessDefinitionQuery().processDefinitionKey("process1").singleResult();
List<User> authorizedUsers = identityService.createUserQuery().potentialStarter(latestProcessDef.getId()).list();
assertEquals(0, authorizedUsers.size());
// user1 and user2 are potential Startes of Process2
latestProcessDef = repositoryService.createProcessDefinitionQuery().processDefinitionKey("process2").singleResult();
authorizedUsers = identityService.createUserQuery().potentialStarter(latestProcessDef.getId()).orderByUserId().asc().list();
assertEquals(2, authorizedUsers.size());
assertEquals("user1", authorizedUsers.get(0).getId());
assertEquals("user2", authorizedUsers.get(1).getId());
// Process 2 has no potential starter groups
latestProcessDef = repositoryService.createProcessDefinitionQuery().processDefinitionKey("process2").singleResult();
List<Group> authorizedGroups = identityService.createGroupQuery().potentialStarter(latestProcessDef.getId()).list();
assertEquals(0, authorizedGroups.size());
// Process 3 has 3 groups as authorized starter groups
latestProcessDef = repositoryService.createProcessDefinitionQuery().processDefinitionKey("process4").singleResult();
authorizedGroups = identityService.createGroupQuery().potentialStarter(latestProcessDef.getId()).orderByGroupId().asc().list();
assertEquals(3, authorizedGroups.size());
assertEquals("group1", authorizedGroups.get(0).getId());
assertEquals("group2", authorizedGroups.get(1).getId());
assertEquals("group3", authorizedGroups.get(2).getId());
// do not mention user, all processes should be selected
List<ProcessDefinition> processDefinitions = repositoryService.createProcessDefinitionQuery().orderByProcessDefinitionName().asc().list();
assertEquals(4, processDefinitions.size());
assertEquals("process1", processDefinitions.get(0).getKey());
assertEquals("process2", processDefinitions.get(1).getKey());
assertEquals("process3", processDefinitions.get(2).getKey());
assertEquals("process4", processDefinitions.get(3).getKey());
// check user1, process3 has "user1" as only authorized starter, and
// process2 has two authorized starters, of which one is "user1"
processDefinitions = repositoryService.createProcessDefinitionQuery().orderByProcessDefinitionName().asc().startableByUser("user1").list();
assertEquals(2, processDefinitions.size());
assertEquals("process2", processDefinitions.get(0).getKey());
assertEquals("process3", processDefinitions.get(1).getKey());
// "user2" can only start process2
processDefinitions = repositoryService.createProcessDefinitionQuery().startableByUser("user2").list();
assertEquals(1, processDefinitions.size());
assertEquals("process2", processDefinitions.get(0).getKey());
// no process could be started with "user4"
processDefinitions = repositoryService.createProcessDefinitionQuery().startableByUser("user4").list();
assertEquals(0, processDefinitions.size());
// "userInGroup3" is in "group3" and can start only process4 via group authorization
processDefinitions = repositoryService.createProcessDefinitionQuery().startableByUser("userInGroup3").list();
assertEquals(1, processDefinitions.size());
assertEquals("process4", processDefinitions.get(0).getKey());
// "userInGroup2" can start process4, via both user and group authorizations
// but we have to be sure that process4 appears only once
processDefinitions = repositoryService.createProcessDefinitionQuery().startableByUser("userInGroup2").list();
assertEquals(1, processDefinitions.size());
assertEquals("process4", processDefinitions.get(0).getKey());
} finally {
tearDownUsersAndGroups();
}
}
Aggregations