Search in sources :

Example 16 with ProcessDefinitionEntity

use of org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity in project bamboobsc by billchen198318.

the class BusinessProcessManagementUtils method getProcessDefinitionDiagramById.

public static byte[] getProcessDefinitionDiagramById(String processDefinitionId) throws Exception {
    ProcessDefinition pd = repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefinitionId).singleResult();
    if (pd == null) {
        return null;
    }
    byte[] data = null;
    ProcessDefinitionEntity pde = (ProcessDefinitionEntity) pd;
    InputStream is = repositoryService.getResourceAsStream(pde.getDeploymentId(), pde.getDiagramResourceName());
    data = IOUtils.toByteArray(is);
    is.close();
    is = null;
    return data;
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)

Example 17 with ProcessDefinitionEntity

use of org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity in project carbon-business-process by wso2.

the class BPMNDataPublisher method configDataPublishing.

/**
 * Configure for data publishing to DAS for analytics
 *
 * @param receiverURLSet             Analytics receiver's url
 * @param username                   Analytics server's username
 * @param password                   Analytics server's password
 * @param authURLSet                 Analytics Auth URL set
 * @param type                       Bpmn Analytics Publisher Type
 * @param asyncDataPublishingEnabled is async Data Publishing Enabled
 * @param genericAnalyticsEnabled    is generic Analytics Enabled
 * @param kpiAnalyticsEnabled        is KPI Analytics Enabled
 * @throws DataEndpointAuthenticationException
 * @throws DataEndpointAgentConfigurationException
 * @throws TransportException
 * @throws DataEndpointException
 * @throws DataEndpointConfigurationException
 */
void configDataPublishing(String receiverURLSet, String username, String password, String authURLSet, String type, boolean asyncDataPublishingEnabled, boolean genericAnalyticsEnabled, boolean kpiAnalyticsEnabled) throws DataEndpointAuthenticationException, DataEndpointAgentConfigurationException, TransportException, DataEndpointException, DataEndpointConfigurationException {
    if (receiverURLSet != null && username != null && password != null) {
        // Configure data publisher to be used by all data publishing listeners
        if (log.isDebugEnabled()) {
            log.debug("Creating BPMN analytics data publisher with Receiver URL: " + receiverURLSet + ", Auth URL: " + authURLSet + " and Data publisher type: " + type);
        }
        dataPublisher = new DataPublisher(type, receiverURLSet, authURLSet, username, password);
        BPMNAnalyticsHolder.getInstance().setAsyncDataPublishingEnabled(asyncDataPublishingEnabled);
        BPMNEngineService engineService = BPMNAnalyticsHolder.getInstance().getBpmnEngineService();
        // Attach data publishing listeners to all existing processes
        if (log.isDebugEnabled()) {
            log.debug("Attaching data publishing listeners to already deployed processes...");
        }
        RepositoryService repositoryService = engineService.getProcessEngine().getRepositoryService();
        List<ProcessDefinition> processDefinitions = repositoryService.createProcessDefinitionQuery().list();
        for (ProcessDefinition processDefinition : processDefinitions) {
            // Process definition returned by the query does not contain all details such as task definitions.
            // And it is also not the actual process definition, but a copy of it, so attaching listners to
            // them is useless. Therefore, we have to fetch the complete process definition from the repository
            // again.
            ProcessDefinition completeProcessDefinition = repositoryService.getProcessDefinition(processDefinition.getId());
            if (completeProcessDefinition instanceof ProcessDefinitionEntity) {
                ProcessDefinitionEntity processDefinitionEntity = (ProcessDefinitionEntity) completeProcessDefinition;
                if (genericAnalyticsEnabled) {
                    processDefinitionEntity.addExecutionListener(PvmEvent.EVENTNAME_END, new ProcessTerminationListener());
                }
                if (kpiAnalyticsEnabled) {
                    processDefinitionEntity.addExecutionListener(PvmEvent.EVENTNAME_END, new ProcessTerminationKPIListener());
                }
                Map<String, TaskDefinition> tasks = processDefinitionEntity.getTaskDefinitions();
                List<ActivityImpl> activities = processDefinitionEntity.getActivities();
                for (ActivityImpl activity : activities) {
                    if (activity.getProperty("type").toString().equalsIgnoreCase("usertask")) {
                        tasks.get(activity.getId()).addTaskListener(TaskListener.EVENTNAME_COMPLETE, new TaskCompletionListener());
                    }
                // We are publishing analytics data of service tasks in process termination ATM.
                // else if(activity.getProperty("type").toString().equalsIgnoreCase("servicetask")){
                // activity.addExecutionListener(PvmEvent.EVENTNAME_END,new
                // ServiceTaskCompletionListener());
                // }
                }
            }
        }
        // Configure parse handlers, which attaches data publishing listeners to new processes
        if (log.isDebugEnabled()) {
            log.debug("Associating parse handlers for processes and tasks, so that data publishing listeners " + "will be attached to new processes.");
        }
        ProcessEngineConfigurationImpl engineConfig = (ProcessEngineConfigurationImpl) engineService.getProcessEngine().getProcessEngineConfiguration();
        if (engineConfig.getPostBpmnParseHandlers() == null) {
            engineConfig.setPostBpmnParseHandlers(new ArrayList<BpmnParseHandler>());
        }
        if (genericAnalyticsEnabled) {
            engineConfig.getPostBpmnParseHandlers().add(new ProcessParseHandler());
            engineConfig.getPostBpmnParseHandlers().add(new TaskParseHandler());
            engineConfig.getBpmnDeployer().getBpmnParser().getBpmnParserHandlers().addHandler(new ProcessParseHandler());
            engineConfig.getBpmnDeployer().getBpmnParser().getBpmnParserHandlers().addHandler(new TaskParseHandler());
        }
        if (kpiAnalyticsEnabled) {
            engineConfig.getPostBpmnParseHandlers().add(new ProcessKPIParseHandler());
            engineConfig.getBpmnDeployer().getBpmnParser().getBpmnParserHandlers().addHandler(new ProcessKPIParseHandler());
        }
    } else {
        log.warn("Required fields for data publisher are not configured. Receiver URLs, username and password " + "are mandatory. Data publishing will not be enabled.");
    }
}
Also used : TaskCompletionListener(org.wso2.carbon.bpmn.analytics.publisher.listeners.TaskCompletionListener) TaskParseHandler(org.wso2.carbon.bpmn.analytics.publisher.handlers.TaskParseHandler) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ProcessParseHandler(org.wso2.carbon.bpmn.analytics.publisher.handlers.ProcessParseHandler) BpmnParseHandler(org.activiti.engine.parse.BpmnParseHandler) ProcessKPIParseHandler(org.wso2.carbon.bpmn.analytics.publisher.handlers.ProcessKPIParseHandler) ProcessTerminationKPIListener(org.wso2.carbon.bpmn.analytics.publisher.listeners.ProcessTerminationKPIListener) BPMNEngineService(org.wso2.carbon.bpmn.core.BPMNEngineService) TaskDefinition(org.activiti.engine.impl.task.TaskDefinition) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) ProcessTerminationListener(org.wso2.carbon.bpmn.analytics.publisher.listeners.ProcessTerminationListener) DataPublisher(org.wso2.carbon.databridge.agent.DataPublisher) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) RepositoryService(org.activiti.engine.RepositoryService)

Example 18 with ProcessDefinitionEntity

use of org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity in project carbon-business-process by wso2.

the class ServiceTaskParseHandler method executeParse.

@Override
protected void executeParse(BpmnParse bpmnParse, BaseElement element) {
    ProcessDefinitionEntity processDefinitionEntity = bpmnParse.getCurrentProcessDefinition();
    List<ActivityImpl> activities = processDefinitionEntity.getActivities();
    for (ActivityImpl activity : activities) {
        if (activity.getId().equals(element.getId())) {
            if (log.isDebugEnabled()) {
                log.debug("Enabling data publishing for service task: " + element.getId());
            }
            activity.addExecutionListener(PvmEvent.EVENTNAME_END, new ServiceTaskCompletionListener());
        }
    }
}
Also used : ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) ServiceTaskCompletionListener(org.wso2.carbon.bpmn.analytics.publisher.listeners.ServiceTaskCompletionListener)

Example 19 with ProcessDefinitionEntity

use of org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity in project carbon-business-process by wso2.

the class BPMNInstanceService method getProcessInstanceDiagram.

/**
 * Get process instance diagram as a byte stream by passing the instance ID
 *
 * @param instanceId
 * @return Byte array String
 * @throws BPSFault
 */
public String getProcessInstanceDiagram(String instanceId) throws BPSFault {
    Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    try {
        RuntimeService runtimeService = BPMNServerHolder.getInstance().getEngine().getRuntimeService();
        RepositoryService repositoryService = BPMNServerHolder.getInstance().getEngine().getRepositoryService();
        List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery().processInstanceTenantId(tenantId.toString()).processInstanceId(instanceId).list();
        if (processInstances.isEmpty()) {
            String msg = "No process instance diagram for ID: " + instanceId;
            log.info(msg);
            return null;
        }
        ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(processInstances.get(0).getProcessDefinitionId());
        if (processDefinition != null && processDefinition.isGraphicalNotationDefined()) {
            InputStream diagramStream = new DefaultProcessDiagramGenerator().generateDiagram(repositoryService.getBpmnModel(processDefinition.getId()), "png", runtimeService.getActiveActivityIds(instanceId));
            BufferedImage bufferedImage = ImageIO.read(diagramStream);
            return encodeToString(bufferedImage, "png");
        } else {
            String msg = "Process definition graphical notations doesn't exists: " + instanceId;
            log.debug(msg);
        }
    } catch (IOException e) {
        String msg = "Failed to get the process instance.";
        log.error(msg, e);
    }
    return null;
}
Also used : RuntimeService(org.activiti.engine.RuntimeService) InputStream(java.io.InputStream) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) DefaultProcessDiagramGenerator(org.activiti.image.impl.DefaultProcessDiagramGenerator) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage) RepositoryService(org.activiti.engine.RepositoryService)

Example 20 with ProcessDefinitionEntity

use of org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity in project carbon-business-process by wso2.

the class AnalyticsConfigurationService method configureProcessLevelEvents.

@PUT
@Path("/processes/{process_id}")
@Consumes({ MediaType.APPLICATION_JSON })
public void configureProcessLevelEvents(@PathParam("process_id") String processDefinitionId, DataPublisherConfig dataPublisherConfig) {
    try {
        RepositoryService repositoryService = BPMNOSGIService.getRepositoryService();
        ProcessDefinition process = repositoryService.getProcessDefinition(processDefinitionId);
        if (process != null && process instanceof ProcessDefinitionEntity) {
            ProcessDefinitionEntity processDefinitionEntity = (ProcessDefinitionEntity) process;
            if (dataPublisherConfig.isEnabled()) {
                List<ExecutionListener> endListeners = processDefinitionEntity.getExecutionListeners(PvmEvent.EVENTNAME_END);
                ExecutionListener processTerminationListener = null;
                for (ExecutionListener listener : endListeners) {
                    if (listener instanceof ProcessTerminationListener) {
                        processTerminationListener = listener;
                        break;
                    }
                }
                if (processTerminationListener == null) {
                    if (log.isDebugEnabled()) {
                        log.debug("Adding process termination listener to process: " + processDefinitionId);
                    }
                    processDefinitionEntity.addExecutionListener(PvmEvent.EVENTNAME_END, new ProcessTerminationListener());
                }
            } else {
                List<ExecutionListener> endListeners = processDefinitionEntity.getExecutionListeners(PvmEvent.EVENTNAME_END);
                ExecutionListener processTerminationListener = null;
                for (ExecutionListener listener : endListeners) {
                    if (listener instanceof ProcessTerminationListener) {
                        processTerminationListener = listener;
                        break;
                    }
                }
                if (processTerminationListener != null) {
                    if (log.isDebugEnabled()) {
                        log.debug("Removing process termination listener from process: " + processDefinitionId);
                    }
                    endListeners.remove(processTerminationListener);
                }
            }
        }
    } catch (Exception e) {
        String msg = "Failed to configure events for process: " + processDefinitionId;
        log.error(msg, e);
        throw new BPMNRestException(msg, e);
    }
}
Also used : ProcessTerminationListener(org.wso2.carbon.bpmn.analytics.publisher.listeners.ProcessTerminationListener) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) BPMNRestException(org.wso2.carbon.bpmn.rest.common.exception.BPMNRestException) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) BPMNRestException(org.wso2.carbon.bpmn.rest.common.exception.BPMNRestException) RepositoryService(org.activiti.engine.RepositoryService) ExecutionListener(org.activiti.engine.delegate.ExecutionListener)

Aggregations

ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)64 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)12 ActivitiException (org.activiti.engine.ActivitiException)11 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)9 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)8 ActivityImpl (org.activiti.engine.impl.pvm.process.ActivityImpl)8 BpmnModel (org.activiti.bpmn.model.BpmnModel)7 InputStream (java.io.InputStream)6 ArrayList (java.util.ArrayList)6 RepositoryService (org.activiti.engine.RepositoryService)6 ProcessDefinitionEntityManager (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntityManager)6 StreamResource (com.vaadin.terminal.StreamResource)5 HashMap (java.util.HashMap)5 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)5 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)4 Deployment (org.activiti.engine.test.Deployment)4 Embedded (com.vaadin.ui.Embedded)3 Label (com.vaadin.ui.Label)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2