use of org.activiti.engine.repository.ProcessDefinition in project carbon-business-process by wso2.
the class ProcessInstanceService method getProcessInstanceDiagram.
@GET
@Path("/{processInstanceId}/diagram")
@Produces(MediaType.APPLICATION_JSON)
public Response getProcessInstanceDiagram(@PathParam("processInstanceId") String processInstanceId) {
ProcessInstance processInstance = getProcessInstanceFromRequest(processInstanceId);
RepositoryService repositoryService = BPMNOSGIService.getRepositoryService();
ProcessDefinition pde = repositoryService.getProcessDefinition(processInstance.getProcessDefinitionId());
if (pde != null && pde.hasGraphicalNotation()) {
RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
InputStream diagramStream = new DefaultProcessDiagramGenerator().generateDiagram(repositoryService.getBpmnModel(pde.getId()), "png", runtimeService.getActiveActivityIds(processInstanceId));
try {
return Response.ok().type("image/png").entity(IOUtils.toByteArray(diagramStream)).build();
} catch (Exception e) {
throw new ActivitiIllegalArgumentException("Error exporting diagram", e);
}
} else {
throw new ActivitiIllegalArgumentException("Process instance with id '" + processInstance.getId() + "' has no graphical notation defined.");
}
}
use of org.activiti.engine.repository.ProcessDefinition in project carbon-business-process by wso2.
the class ProcessStatisticsService method getAllProcesses.
/**
* Get all deployed processes
*
* @return list with the processDefinitions of all deployed processes
*/
@GET
@Path("/processes/")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public ResponseHolder getAllProcesses() {
// Get a list of the deployed processes
RepositoryService repositoryService = BPMNOSGIService.getRepositoryService();
List<ProcessDefinition> processDefinitionList = repositoryService.createProcessDefinitionQuery().processDefinitionTenantId(getTenantIdStr()).list();
List<Object> listOfProcesses = new ArrayList<>();
ResponseHolder response = new ResponseHolder();
for (ProcessDefinition processDefinition : processDefinitionList) {
listOfProcesses.add(processDefinition.getId());
}
response.setData(listOfProcesses);
return response;
}
use of org.activiti.engine.repository.ProcessDefinition in project carbon-business-process by wso2.
the class ProcessStatisticsService method getAvgTimeDurationForCompletedProcesses.
/**
* Get the average time duration of completed processes
*
* @return list with the completed processes and the average time duration taken for each process
*/
@GET
@Path("/process-instances/duration/average")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public ResponseHolder getAvgTimeDurationForCompletedProcesses() {
ResponseHolder response = new ResponseHolder();
List<Object> list = new ArrayList<>();
HistoryService historyService = BPMNOSGIService.getHistoryService();
RepositoryService repositoryService = BPMNOSGIService.getRepositoryService();
List<ProcessDefinition> deployedProcessList = repositoryService.createProcessDefinitionQuery().processDefinitionTenantId(getTenantIdStr()).list();
for (ProcessDefinition instance : deployedProcessList) {
ProcessInstanceAverageInfo bpmnProcessInstance = new ProcessInstanceAverageInfo();
bpmnProcessInstance.setProcessDefinitionId(instance.getId());
double totalTime = 0;
double averageTime;
String processDefinitionID = instance.getId();
HistoricProcessInstanceQuery historicProcessInstanceQuery = historyService.createHistoricProcessInstanceQuery().processInstanceTenantId(getTenantIdStr()).processDefinitionId(processDefinitionID).finished();
long instanceCount = historicProcessInstanceQuery.count();
if (instanceCount != 0) {
List<HistoricProcessInstance> instanceList = historicProcessInstanceQuery.list();
for (HistoricProcessInstance completedProcess : instanceList) {
double timeDurationOfTask = completedProcess.getDurationInMillis();
double timeInMins = timeDurationOfTask / (1000 * 60);
totalTime += timeInMins;
}
averageTime = totalTime / instanceCount;
bpmnProcessInstance.setAverageTimeForCompletion(averageTime);
list.add(bpmnProcessInstance);
}
}
response.setData(list);
return response;
}
use of org.activiti.engine.repository.ProcessDefinition in project carbon-business-process by wso2.
the class BPMNDeploymentService method aggregateRemovableProcessInstances.
private void aggregateRemovableProcessInstances(BPMNDeletableInstances bpmnDeletableInstances, String deploymentId, Integer tenantId, ProcessEngine processEngine) throws BPSFault {
ProcessDefinitionQuery query = processEngine.getRepositoryService().createProcessDefinitionQuery();
List<ProcessDefinition> processes = query.processDefinitionTenantId(tenantId.toString()).deploymentId(deploymentId).list();
for (ProcessDefinition process : processes) {
if (!constructBPMNInstancesByProcessID(bpmnDeletableInstances, process.getId(), tenantId, processEngine)) {
String errorMessage = " Failed to undeploy the package. Please delete the instances before undeploying " + "the package";
throw new BPSFault(errorMessage);
}
}
}
use of org.activiti.engine.repository.ProcessDefinition in project carbon-business-process by wso2.
the class BPMNDeploymentService method getProcessById.
public BPMNProcess getProcessById(String processId) {
Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
ProcessEngine engine = BPMNServerHolder.getInstance().getEngine();
ProcessDefinitionQuery query = engine.getRepositoryService().createProcessDefinitionQuery();
ProcessDefinition process = query.processDefinitionTenantId(tenantId.toString()).processDefinitionId(processId).singleResult();
DeploymentQuery deploymentQuery = engine.getRepositoryService().createDeploymentQuery();
Deployment deployment = deploymentQuery.deploymentId(process.getDeploymentId()).singleResult();
BPMNProcess bpmnProcess = new BPMNProcess();
bpmnProcess.setDeploymentId(process.getDeploymentId());
bpmnProcess.setName(process.getName());
bpmnProcess.setKey(process.getKey());
bpmnProcess.setProcessId(process.getId());
bpmnProcess.setVersion(process.getVersion());
bpmnProcess.setDeploymentTime(deployment.getDeploymentTime());
bpmnProcess.setDeploymentName(deployment.getName());
return bpmnProcess;
}
Aggregations