Search in sources :

Example 96 with ProcessDefinition

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.");
    }
}
Also used : RuntimeService(org.activiti.engine.RuntimeService) ObjectInputStream(java.io.ObjectInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) DefaultProcessDiagramGenerator(org.activiti.image.impl.DefaultProcessDiagramGenerator) ActivitiException(org.activiti.engine.ActivitiException) ServletException(javax.servlet.ServletException) BPMNRestException(org.wso2.carbon.bpmn.rest.common.exception.BPMNRestException) BPMNContentNotSupportedException(org.wso2.carbon.bpmn.rest.common.exception.BPMNContentNotSupportedException) XMLStreamException(javax.xml.stream.XMLStreamException) BPMNConflictException(org.wso2.carbon.bpmn.rest.common.exception.BPMNConflictException) JAXBException(javax.xml.bind.JAXBException) NotFoundException(javax.ws.rs.NotFoundException) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) IOException(java.io.IOException) RestApiBasicAuthenticationException(org.wso2.carbon.bpmn.rest.common.exception.RestApiBasicAuthenticationException) RepositoryService(org.activiti.engine.RepositoryService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 97 with ProcessDefinition

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;
}
Also used : ResponseHolder(org.wso2.carbon.bpmn.rest.model.stats.ResponseHolder) ArrayList(java.util.ArrayList) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) RepositoryService(org.activiti.engine.RepositoryService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 98 with ProcessDefinition

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;
}
Also used : HistoricProcessInstanceQuery(org.activiti.engine.history.HistoricProcessInstanceQuery) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ArrayList(java.util.ArrayList) HistoryService(org.activiti.engine.HistoryService) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ResponseHolder(org.wso2.carbon.bpmn.rest.model.stats.ResponseHolder) ProcessInstanceAverageInfo(org.wso2.carbon.bpmn.rest.model.stats.ProcessInstanceAverageInfo) RepositoryService(org.activiti.engine.RepositoryService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 99 with ProcessDefinition

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);
        }
    }
}
Also used : BPSFault(org.wso2.carbon.bpmn.core.BPSFault) ProcessDefinitionQuery(org.activiti.engine.repository.ProcessDefinitionQuery) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition)

Example 100 with ProcessDefinition

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;
}
Also used : DeploymentQuery(org.activiti.engine.repository.DeploymentQuery) BPMNProcess(org.wso2.carbon.bpmn.core.mgt.model.BPMNProcess) BPMNDeployment(org.wso2.carbon.bpmn.core.mgt.model.BPMNDeployment) Deployment(org.activiti.engine.repository.Deployment) ProcessDefinitionQuery(org.activiti.engine.repository.ProcessDefinitionQuery) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ProcessEngine(org.activiti.engine.ProcessEngine)

Aggregations

ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)211 Deployment (org.activiti.engine.test.Deployment)82 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)42 ArrayList (java.util.ArrayList)29 ActivitiException (org.activiti.engine.ActivitiException)25 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)23 RepositoryService (org.activiti.engine.RepositoryService)20 ProcessDefinitionQuery (org.activiti.engine.repository.ProcessDefinitionQuery)19 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)19 Task (org.activiti.engine.task.Task)16 Date (java.util.Date)14 Test (org.junit.Test)14 JsonNode (com.fasterxml.jackson.databind.JsonNode)12 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)12 HashMap (java.util.HashMap)12 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)11 JobDefinitionEntity (org.finra.herd.model.jpa.JobDefinitionEntity)11 InputStream (java.io.InputStream)10 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)10 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)9