Search in sources :

Example 1 with ProcessDefinitionEntity

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

the class WebServiceUELTest method testWebServiceInvocationWithDataFlowUEL.

@Deployment
public void testWebServiceInvocationWithDataFlowUEL() throws Exception {
    ProcessDefinitionEntity processDefinition = processEngineConfiguration.getCommandExecutor().execute(new Command<ProcessDefinitionEntity>() {

        public ProcessDefinitionEntity execute(CommandContext commandContext) {
            return Context.getProcessEngineConfiguration().getDeploymentManager().findDeployedLatestProcessDefinitionByKey("webServiceInvocationWithDataFlowUEL");
        }
    });
    ItemDefinition itemDefinition = processDefinition.getIoSpecification().getDataInputs().get(0).getDefinition();
    ItemInstance itemInstance = itemDefinition.createInstance();
    FieldBaseStructureInstance structureInstance = (FieldBaseStructureInstance) itemInstance.getStructureInstance();
    structureInstance.setFieldValue("prefix", "The counter has the value ");
    structureInstance.setFieldValue("suffix", ". Good news");
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("dataInputOfProcess", itemInstance);
    ProcessInstance instance = processEngine.getRuntimeService().startProcessInstanceByKey("webServiceInvocationWithDataFlowUEL", variables);
    waitForJobExecutorToProcessAllJobs(10000L, 250L);
    String response = (String) processEngine.getRuntimeService().getVariable(instance.getId(), "dataOutputOfProcess");
    assertEquals("The counter has the value -1. Good news", response);
}
Also used : CommandContext(org.activiti.engine.impl.interceptor.CommandContext) HashMap(java.util.HashMap) ItemDefinition(org.activiti.engine.impl.bpmn.data.ItemDefinition) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) FieldBaseStructureInstance(org.activiti.engine.impl.bpmn.data.FieldBaseStructureInstance) ItemInstance(org.activiti.engine.impl.bpmn.data.ItemInstance) Deployment(org.activiti.engine.test.Deployment)

Example 2 with ProcessDefinitionEntity

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

the class BaseProcessDefinitionDiagramLayoutResource method getDiagramNode.

public ObjectNode getDiagramNode(String processInstanceId, String processDefinitionId) {
    List<String> highLightedFlows = Collections.<String>emptyList();
    List<String> highLightedActivities = Collections.<String>emptyList();
    Map<String, ObjectNode> subProcessInstanceMap = new HashMap<String, ObjectNode>();
    ProcessInstance processInstance = null;
    if (processInstanceId != null) {
        processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
        if (processInstance == null) {
            throw new ActivitiObjectNotFoundException("Process instance could not be found");
        }
        processDefinitionId = processInstance.getProcessDefinitionId();
        List<ProcessInstance> subProcessInstances = runtimeService.createProcessInstanceQuery().superProcessInstanceId(processInstanceId).list();
        for (ProcessInstance subProcessInstance : subProcessInstances) {
            String subDefId = subProcessInstance.getProcessDefinitionId();
            String superExecutionId = ((ExecutionEntity) subProcessInstance).getSuperExecutionId();
            ProcessDefinitionEntity subDef = (ProcessDefinitionEntity) repositoryService.getProcessDefinition(subDefId);
            ObjectNode processInstanceJSON = new ObjectMapper().createObjectNode();
            processInstanceJSON.put("processInstanceId", subProcessInstance.getId());
            processInstanceJSON.put("superExecutionId", superExecutionId);
            processInstanceJSON.put("processDefinitionId", subDef.getId());
            processInstanceJSON.put("processDefinitionKey", subDef.getKey());
            processInstanceJSON.put("processDefinitionName", subDef.getName());
            subProcessInstanceMap.put(superExecutionId, processInstanceJSON);
        }
    }
    if (processDefinitionId == null) {
        throw new ActivitiObjectNotFoundException("No process definition id provided");
    }
    ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) repositoryService.getProcessDefinition(processDefinitionId);
    if (processDefinition == null) {
        throw new ActivitiException("Process definition " + processDefinitionId + " could not be found");
    }
    ObjectNode responseJSON = new ObjectMapper().createObjectNode();
    // Process definition
    JsonNode pdrJSON = getProcessDefinitionResponse(processDefinition);
    if (pdrJSON != null) {
        responseJSON.put("processDefinition", pdrJSON);
    }
    // Highlighted activities
    if (processInstance != null) {
        ArrayNode activityArray = new ObjectMapper().createArrayNode();
        ArrayNode flowsArray = new ObjectMapper().createArrayNode();
        highLightedActivities = runtimeService.getActiveActivityIds(processInstanceId);
        highLightedFlows = getHighLightedFlows(processInstanceId, processDefinition);
        for (String activityName : highLightedActivities) {
            activityArray.add(activityName);
        }
        for (String flow : highLightedFlows) flowsArray.add(flow);
        responseJSON.put("highLightedActivities", activityArray);
        responseJSON.put("highLightedFlows", flowsArray);
    }
    // Pool shape, if process is participant in collaboration
    if (processDefinition.getParticipantProcess() != null) {
        ParticipantProcess pProc = processDefinition.getParticipantProcess();
        ObjectNode participantProcessJSON = new ObjectMapper().createObjectNode();
        participantProcessJSON.put("id", pProc.getId());
        if (StringUtils.isNotEmpty(pProc.getName())) {
            participantProcessJSON.put("name", pProc.getName());
        } else {
            participantProcessJSON.put("name", "");
        }
        participantProcessJSON.put("x", pProc.getX());
        participantProcessJSON.put("y", pProc.getY());
        participantProcessJSON.put("width", pProc.getWidth());
        participantProcessJSON.put("height", pProc.getHeight());
        responseJSON.put("participantProcess", participantProcessJSON);
    }
    if (processDefinition.getLaneSets() != null && !processDefinition.getLaneSets().isEmpty()) {
        ArrayNode laneSetArray = new ObjectMapper().createArrayNode();
        for (LaneSet laneSet : processDefinition.getLaneSets()) {
            ArrayNode laneArray = new ObjectMapper().createArrayNode();
            if (laneSet.getLanes() != null && !laneSet.getLanes().isEmpty()) {
                for (Lane lane : laneSet.getLanes()) {
                    ObjectNode laneJSON = new ObjectMapper().createObjectNode();
                    laneJSON.put("id", lane.getId());
                    if (StringUtils.isNotEmpty(lane.getName())) {
                        laneJSON.put("name", lane.getName());
                    } else {
                        laneJSON.put("name", "");
                    }
                    laneJSON.put("x", lane.getX());
                    laneJSON.put("y", lane.getY());
                    laneJSON.put("width", lane.getWidth());
                    laneJSON.put("height", lane.getHeight());
                    List<String> flowNodeIds = lane.getFlowNodeIds();
                    ArrayNode flowNodeIdsArray = new ObjectMapper().createArrayNode();
                    for (String flowNodeId : flowNodeIds) {
                        flowNodeIdsArray.add(flowNodeId);
                    }
                    laneJSON.put("flowNodeIds", flowNodeIdsArray);
                    laneArray.add(laneJSON);
                }
            }
            ObjectNode laneSetJSON = new ObjectMapper().createObjectNode();
            laneSetJSON.put("id", laneSet.getId());
            if (StringUtils.isNotEmpty(laneSet.getName())) {
                laneSetJSON.put("name", laneSet.getName());
            } else {
                laneSetJSON.put("name", "");
            }
            laneSetJSON.put("lanes", laneArray);
            laneSetArray.add(laneSetJSON);
        }
        if (laneSetArray.size() > 0)
            responseJSON.put("laneSets", laneSetArray);
    }
    ArrayNode sequenceFlowArray = new ObjectMapper().createArrayNode();
    ArrayNode activityArray = new ObjectMapper().createArrayNode();
    for (ActivityImpl activity : processDefinition.getActivities()) {
        getActivity(processInstanceId, activity, activityArray, sequenceFlowArray, processInstance, highLightedFlows, subProcessInstanceMap);
    }
    responseJSON.put("activities", activityArray);
    responseJSON.put("sequenceFlows", sequenceFlowArray);
    return responseJSON;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HashMap(java.util.HashMap) Lane(org.activiti.engine.impl.pvm.process.Lane) JsonNode(com.fasterxml.jackson.databind.JsonNode) LaneSet(org.activiti.engine.impl.pvm.process.LaneSet) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) ParticipantProcess(org.activiti.engine.impl.pvm.process.ParticipantProcess) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with ProcessDefinitionEntity

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

the class WebServiceUELTest method testAsyncInvocationWithDataFlowUEL.

@Deployment
public void testAsyncInvocationWithDataFlowUEL() throws Exception {
    assertEquals(-1, webServiceMock.getCount());
    ProcessDefinitionEntity processDefinition = processEngineConfiguration.getCommandExecutor().execute(new Command<ProcessDefinitionEntity>() {

        public ProcessDefinitionEntity execute(CommandContext commandContext) {
            return Context.getProcessEngineConfiguration().getDeploymentManager().findDeployedLatestProcessDefinitionByKey("asyncWebServiceInvocationWithDataFlowUEL");
        }
    });
    ItemDefinition itemDefinition = processDefinition.getIoSpecification().getDataInputs().get(0).getDefinition();
    ItemInstance itemInstance = itemDefinition.createInstance();
    FieldBaseStructureInstance structureInstance = (FieldBaseStructureInstance) itemInstance.getStructureInstance();
    structureInstance.setFieldValue("newCounterValue", 23);
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("dataInputOfProcess", itemInstance);
    processEngine.getRuntimeService().startProcessInstanceByKey("asyncWebServiceInvocationWithDataFlowUEL", variables);
    waitForJobExecutorToProcessAllJobs(10000L, 250L);
    assertEquals(23, webServiceMock.getCount());
}
Also used : CommandContext(org.activiti.engine.impl.interceptor.CommandContext) HashMap(java.util.HashMap) ItemDefinition(org.activiti.engine.impl.bpmn.data.ItemDefinition) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) FieldBaseStructureInstance(org.activiti.engine.impl.bpmn.data.FieldBaseStructureInstance) ItemInstance(org.activiti.engine.impl.bpmn.data.ItemInstance) Deployment(org.activiti.engine.test.Deployment)

Example 4 with ProcessDefinitionEntity

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

the class ProcessDefinitionImageStreamResourceBuilder method buildStreamResource.

public StreamResource buildStreamResource(ProcessInstance processInstance, RepositoryService repositoryService, RuntimeService runtimeService, ProcessDiagramGenerator diagramGenerator, ProcessEngineConfiguration processEngineConfig) {
    StreamResource imageResource = null;
    ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(processInstance.getProcessDefinitionId());
    if (processDefinition != null && processDefinition.isGraphicalNotationDefined()) {
        try {
            BpmnModel bpmnModel = repositoryService.getBpmnModel(processInstance.getProcessDefinitionId());
            InputStream definitionImageStream = diagramGenerator.generateDiagram(bpmnModel, "png", runtimeService.getActiveActivityIds(processInstance.getId()), Collections.<String>emptyList(), processEngineConfig.getActivityFontName(), processEngineConfig.getLabelFontName(), processEngineConfig.getAnnotationFontName(), processEngineConfig.getClassLoader(), 1.0);
            if (definitionImageStream != null) {
                StreamSource streamSource = new InputStreamStreamSource(definitionImageStream);
                // Create image name
                String imageExtension = extractImageExtension(processDefinition.getDiagramResourceName());
                String fileName = processInstance.getId() + UUID.randomUUID() + "." + imageExtension;
                imageResource = new StreamResource(streamSource, fileName, ExplorerApp.get());
            }
        } catch (Throwable t) {
            // Image can't be generated, ignore this
            LOGGER.warn("Process image cannot be generated due to exception: {} - {}", t.getClass().getName(), t.getMessage());
        }
    }
    return imageResource;
}
Also used : StreamResource(com.vaadin.terminal.StreamResource) InputStream(java.io.InputStream) StreamSource(com.vaadin.terminal.StreamResource.StreamSource) InputStreamStreamSource(org.activiti.explorer.ui.util.InputStreamStreamSource) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) InputStreamStreamSource(org.activiti.explorer.ui.util.InputStreamStreamSource) BpmnModel(org.activiti.bpmn.model.BpmnModel)

Example 5 with ProcessDefinitionEntity

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

the class ProcessDefinitionImageStreamResourceBuilder method buildStreamResource.

public StreamResource buildStreamResource(String processInstanceId, String processDefinitionId, RepositoryService repositoryService, RuntimeService runtimeService, ProcessDiagramGenerator diagramGenerator, ProcessEngineConfiguration processEngineConfig) {
    StreamResource imageResource = null;
    ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(processDefinitionId);
    if (processDefinition != null && processDefinition.isGraphicalNotationDefined()) {
        BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
        InputStream definitionImageStream = diagramGenerator.generateDiagram(bpmnModel, "png", runtimeService.getActiveActivityIds(processInstanceId), Collections.<String>emptyList(), processEngineConfig.getActivityFontName(), processEngineConfig.getLabelFontName(), processEngineConfig.getAnnotationFontName(), processEngineConfig.getClassLoader(), 1.0);
        StreamSource streamSource = new InputStreamStreamSource(definitionImageStream);
        // Create image name
        String imageExtension = extractImageExtension(processDefinition.getDiagramResourceName());
        String fileName = processInstanceId + UUID.randomUUID() + "." + imageExtension;
        imageResource = new StreamResource(streamSource, fileName, ExplorerApp.get());
    }
    return imageResource;
}
Also used : StreamResource(com.vaadin.terminal.StreamResource) InputStream(java.io.InputStream) StreamSource(com.vaadin.terminal.StreamResource.StreamSource) InputStreamStreamSource(org.activiti.explorer.ui.util.InputStreamStreamSource) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) InputStreamStreamSource(org.activiti.explorer.ui.util.InputStreamStreamSource) BpmnModel(org.activiti.bpmn.model.BpmnModel)

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