Search in sources :

Example 26 with Process

use of org.activiti.bpmn.model.Process in project Activiti by Activiti.

the class ActivitiTestCaseProcessValidator method validate.

@Override
public List<ValidationError> validate(BpmnModel bpmnModel) {
    List<ValidationError> errorList = new ArrayList<ValidationError>();
    CustomParseValidator customParseValidator = new CustomParseValidator();
    for (Process process : bpmnModel.getProcesses()) {
        customParseValidator.executeParse(bpmnModel, process);
    }
    for (String errorRef : bpmnModel.getErrors().keySet()) {
        ValidationError error = new ValidationError();
        error.setValidatorSetName("Manual BPMN parse validator");
        error.setProblem(errorRef);
        error.setActivityId(bpmnModel.getErrors().get(errorRef));
        errorList.add(error);
    }
    return errorList;
}
Also used : ArrayList(java.util.ArrayList) Process(org.activiti.bpmn.model.Process) ValidationError(org.activiti.validation.ValidationError)

Example 27 with Process

use of org.activiti.bpmn.model.Process in project Activiti by Activiti.

the class DefaultProcessDiagramGenerator method initProcessDiagramCanvas.

protected static DefaultProcessDiagramCanvas initProcessDiagramCanvas(BpmnModel bpmnModel, String imageType, String activityFontName, String labelFontName, String annotationFontName, ClassLoader customClassLoader) {
    // We need to calculate maximum values to know how big the image will be in its entirety
    double minX = Double.MAX_VALUE;
    double maxX = 0;
    double minY = Double.MAX_VALUE;
    double maxY = 0;
    for (Pool pool : bpmnModel.getPools()) {
        GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(pool.getId());
        minX = graphicInfo.getX();
        maxX = graphicInfo.getX() + graphicInfo.getWidth();
        minY = graphicInfo.getY();
        maxY = graphicInfo.getY() + graphicInfo.getHeight();
    }
    List<FlowNode> flowNodes = gatherAllFlowNodes(bpmnModel);
    for (FlowNode flowNode : flowNodes) {
        GraphicInfo flowNodeGraphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
        // width
        if (flowNodeGraphicInfo.getX() + flowNodeGraphicInfo.getWidth() > maxX) {
            maxX = flowNodeGraphicInfo.getX() + flowNodeGraphicInfo.getWidth();
        }
        if (flowNodeGraphicInfo.getX() < minX) {
            minX = flowNodeGraphicInfo.getX();
        }
        // height
        if (flowNodeGraphicInfo.getY() + flowNodeGraphicInfo.getHeight() > maxY) {
            maxY = flowNodeGraphicInfo.getY() + flowNodeGraphicInfo.getHeight();
        }
        if (flowNodeGraphicInfo.getY() < minY) {
            minY = flowNodeGraphicInfo.getY();
        }
        for (SequenceFlow sequenceFlow : flowNode.getOutgoingFlows()) {
            List<GraphicInfo> graphicInfoList = bpmnModel.getFlowLocationGraphicInfo(sequenceFlow.getId());
            if (graphicInfoList != null) {
                for (GraphicInfo graphicInfo : graphicInfoList) {
                    // width
                    if (graphicInfo.getX() > maxX) {
                        maxX = graphicInfo.getX();
                    }
                    if (graphicInfo.getX() < minX) {
                        minX = graphicInfo.getX();
                    }
                    // height
                    if (graphicInfo.getY() > maxY) {
                        maxY = graphicInfo.getY();
                    }
                    if (graphicInfo.getY() < minY) {
                        minY = graphicInfo.getY();
                    }
                }
            }
        }
    }
    List<Artifact> artifacts = gatherAllArtifacts(bpmnModel);
    for (Artifact artifact : artifacts) {
        GraphicInfo artifactGraphicInfo = bpmnModel.getGraphicInfo(artifact.getId());
        if (artifactGraphicInfo != null) {
            // width
            if (artifactGraphicInfo.getX() + artifactGraphicInfo.getWidth() > maxX) {
                maxX = artifactGraphicInfo.getX() + artifactGraphicInfo.getWidth();
            }
            if (artifactGraphicInfo.getX() < minX) {
                minX = artifactGraphicInfo.getX();
            }
            // height
            if (artifactGraphicInfo.getY() + artifactGraphicInfo.getHeight() > maxY) {
                maxY = artifactGraphicInfo.getY() + artifactGraphicInfo.getHeight();
            }
            if (artifactGraphicInfo.getY() < minY) {
                minY = artifactGraphicInfo.getY();
            }
        }
        List<GraphicInfo> graphicInfoList = bpmnModel.getFlowLocationGraphicInfo(artifact.getId());
        if (graphicInfoList != null) {
            for (GraphicInfo graphicInfo : graphicInfoList) {
                // width
                if (graphicInfo.getX() > maxX) {
                    maxX = graphicInfo.getX();
                }
                if (graphicInfo.getX() < minX) {
                    minX = graphicInfo.getX();
                }
                // height
                if (graphicInfo.getY() > maxY) {
                    maxY = graphicInfo.getY();
                }
                if (graphicInfo.getY() < minY) {
                    minY = graphicInfo.getY();
                }
            }
        }
    }
    int nrOfLanes = 0;
    for (Process process : bpmnModel.getProcesses()) {
        for (Lane l : process.getLanes()) {
            nrOfLanes++;
            GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(l.getId());
            // // width
            if (graphicInfo.getX() + graphicInfo.getWidth() > maxX) {
                maxX = graphicInfo.getX() + graphicInfo.getWidth();
            }
            if (graphicInfo.getX() < minX) {
                minX = graphicInfo.getX();
            }
            // height
            if (graphicInfo.getY() + graphicInfo.getHeight() > maxY) {
                maxY = graphicInfo.getY() + graphicInfo.getHeight();
            }
            if (graphicInfo.getY() < minY) {
                minY = graphicInfo.getY();
            }
        }
    }
    // Special case, see https://activiti.atlassian.net/browse/ACT-1431
    if (flowNodes.isEmpty() && bpmnModel.getPools().isEmpty() && nrOfLanes == 0) {
        // Nothing to show
        minX = 0;
        minY = 0;
    }
    return new DefaultProcessDiagramCanvas((int) maxX + 10, (int) maxY + 10, (int) minX, (int) minY, imageType, activityFontName, labelFontName, annotationFontName, customClassLoader);
}
Also used : SequenceFlow(org.activiti.bpmn.model.SequenceFlow) GraphicInfo(org.activiti.bpmn.model.GraphicInfo) Lane(org.activiti.bpmn.model.Lane) EventSubProcess(org.activiti.bpmn.model.EventSubProcess) Process(org.activiti.bpmn.model.Process) SubProcess(org.activiti.bpmn.model.SubProcess) Artifact(org.activiti.bpmn.model.Artifact) Pool(org.activiti.bpmn.model.Pool) FlowNode(org.activiti.bpmn.model.FlowNode)

Example 28 with Process

use of org.activiti.bpmn.model.Process in project Activiti by Activiti.

the class BaseBpmnJsonConverter method convertToBpmnModel.

public void convertToBpmnModel(JsonNode elementNode, JsonNode modelNode, ActivityProcessor processor, BaseElement parentElement, Map<String, JsonNode> shapeMap, BpmnModel bpmnModel) {
    this.processor = processor;
    this.model = bpmnModel;
    BaseElement baseElement = convertJsonToElement(elementNode, modelNode, shapeMap);
    baseElement.setId(BpmnJsonConverterUtil.getElementId(elementNode));
    if (baseElement instanceof FlowElement) {
        FlowElement flowElement = (FlowElement) baseElement;
        flowElement.setName(getPropertyValueAsString(PROPERTY_NAME, elementNode));
        flowElement.setDocumentation(getPropertyValueAsString(PROPERTY_DOCUMENTATION, elementNode));
        BpmnJsonConverterUtil.convertJsonToListeners(elementNode, flowElement);
        if (baseElement instanceof Activity) {
            Activity activity = (Activity) baseElement;
            activity.setAsynchronous(getPropertyValueAsBoolean(PROPERTY_ASYNCHRONOUS, elementNode));
            activity.setNotExclusive(!getPropertyValueAsBoolean(PROPERTY_EXCLUSIVE, elementNode));
            String multiInstanceType = getPropertyValueAsString(PROPERTY_MULTIINSTANCE_TYPE, elementNode);
            String multiInstanceCardinality = getPropertyValueAsString(PROPERTY_MULTIINSTANCE_CARDINALITY, elementNode);
            String multiInstanceCollection = getPropertyValueAsString(PROPERTY_MULTIINSTANCE_COLLECTION, elementNode);
            String multiInstanceCondition = getPropertyValueAsString(PROPERTY_MULTIINSTANCE_CONDITION, elementNode);
            if (StringUtils.isNotEmpty(multiInstanceType) && "none".equalsIgnoreCase(multiInstanceType) == false) {
                String multiInstanceVariable = getPropertyValueAsString(PROPERTY_MULTIINSTANCE_VARIABLE, elementNode);
                MultiInstanceLoopCharacteristics multiInstanceObject = new MultiInstanceLoopCharacteristics();
                if ("sequential".equalsIgnoreCase(multiInstanceType)) {
                    multiInstanceObject.setSequential(true);
                } else {
                    multiInstanceObject.setSequential(false);
                }
                multiInstanceObject.setLoopCardinality(multiInstanceCardinality);
                multiInstanceObject.setInputDataItem(multiInstanceCollection);
                multiInstanceObject.setElementVariable(multiInstanceVariable);
                multiInstanceObject.setCompletionCondition(multiInstanceCondition);
                activity.setLoopCharacteristics(multiInstanceObject);
            }
        } else if (baseElement instanceof Gateway) {
            JsonNode flowOrderNode = getProperty(PROPERTY_SEQUENCEFLOW_ORDER, elementNode);
            if (flowOrderNode != null) {
                flowOrderNode = BpmnJsonConverterUtil.validateIfNodeIsTextual(flowOrderNode);
                JsonNode orderArray = flowOrderNode.get("sequenceFlowOrder");
                if (orderArray != null && orderArray.size() > 0) {
                    for (JsonNode orderNode : orderArray) {
                        ExtensionElement orderElement = new ExtensionElement();
                        orderElement.setName("EDITOR_FLOW_ORDER");
                        orderElement.setElementText(orderNode.asText());
                        flowElement.addExtensionElement(orderElement);
                    }
                }
            }
        }
    }
    if (baseElement instanceof FlowElement) {
        FlowElement flowElement = (FlowElement) baseElement;
        if (flowElement instanceof SequenceFlow) {
            ExtensionElement idExtensionElement = new ExtensionElement();
            idExtensionElement.setName("EDITOR_RESOURCEID");
            idExtensionElement.setElementText(elementNode.get(EDITOR_SHAPE_ID).asText());
            flowElement.addExtensionElement(idExtensionElement);
        }
        if (parentElement instanceof Process) {
            ((Process) parentElement).addFlowElement(flowElement);
        } else if (parentElement instanceof SubProcess) {
            ((SubProcess) parentElement).addFlowElement(flowElement);
        } else if (parentElement instanceof Lane) {
            Lane lane = (Lane) parentElement;
            lane.getFlowReferences().add(flowElement.getId());
            lane.getParentProcess().addFlowElement(flowElement);
        }
    } else if (baseElement instanceof Artifact) {
        Artifact artifact = (Artifact) baseElement;
        if (parentElement instanceof Process) {
            ((Process) parentElement).addArtifact(artifact);
        } else if (parentElement instanceof SubProcess) {
            ((SubProcess) parentElement).addArtifact(artifact);
        } else if (parentElement instanceof Lane) {
            Lane lane = (Lane) parentElement;
            lane.getFlowReferences().add(artifact.getId());
            lane.getParentProcess().addArtifact(artifact);
        }
    }
}
Also used : SubProcess(org.activiti.bpmn.model.SubProcess) SequenceFlow(org.activiti.bpmn.model.SequenceFlow) ExtensionElement(org.activiti.bpmn.model.ExtensionElement) Lane(org.activiti.bpmn.model.Lane) Activity(org.activiti.bpmn.model.Activity) JsonNode(com.fasterxml.jackson.databind.JsonNode) Process(org.activiti.bpmn.model.Process) SubProcess(org.activiti.bpmn.model.SubProcess) Artifact(org.activiti.bpmn.model.Artifact) BaseElement(org.activiti.bpmn.model.BaseElement) MultiInstanceLoopCharacteristics(org.activiti.bpmn.model.MultiInstanceLoopCharacteristics) FlowElement(org.activiti.bpmn.model.FlowElement) Gateway(org.activiti.bpmn.model.Gateway)

Example 29 with Process

use of org.activiti.bpmn.model.Process in project Activiti by Activiti.

the class BaseBpmnJsonConverter method convertToJson.

public void convertToJson(BaseElement baseElement, ActivityProcessor processor, BpmnModel model, FlowElementsContainer container, ArrayNode shapesArrayNode, double subProcessX, double subProcessY) {
    this.model = model;
    this.processor = processor;
    this.subProcessX = subProcessX;
    this.subProcessY = subProcessY;
    this.shapesArrayNode = shapesArrayNode;
    GraphicInfo graphicInfo = model.getGraphicInfo(baseElement.getId());
    String stencilId = null;
    if (baseElement instanceof ServiceTask) {
        ServiceTask serviceTask = (ServiceTask) baseElement;
        if ("mail".equalsIgnoreCase(serviceTask.getType())) {
            stencilId = STENCIL_TASK_MAIL;
        } else if ("camel".equalsIgnoreCase(serviceTask.getType())) {
            stencilId = STENCIL_TASK_CAMEL;
        } else if ("mule".equalsIgnoreCase(serviceTask.getType())) {
            stencilId = STENCIL_TASK_MULE;
        } else {
            stencilId = getStencilId(baseElement);
        }
    } else {
        stencilId = getStencilId(baseElement);
    }
    flowElementNode = BpmnJsonConverterUtil.createChildShape(baseElement.getId(), stencilId, graphicInfo.getX() - subProcessX + graphicInfo.getWidth(), graphicInfo.getY() - subProcessY + graphicInfo.getHeight(), graphicInfo.getX() - subProcessX, graphicInfo.getY() - subProcessY);
    shapesArrayNode.add(flowElementNode);
    ObjectNode propertiesNode = objectMapper.createObjectNode();
    propertiesNode.put(PROPERTY_OVERRIDE_ID, baseElement.getId());
    if (baseElement instanceof FlowElement) {
        FlowElement flowElement = (FlowElement) baseElement;
        if (StringUtils.isNotEmpty(flowElement.getName())) {
            propertiesNode.put(PROPERTY_NAME, flowElement.getName());
        }
        if (StringUtils.isNotEmpty(flowElement.getDocumentation())) {
            propertiesNode.put(PROPERTY_DOCUMENTATION, flowElement.getDocumentation());
        }
    }
    convertElementToJson(propertiesNode, baseElement);
    flowElementNode.put(EDITOR_SHAPE_PROPERTIES, propertiesNode);
    ArrayNode outgoingArrayNode = objectMapper.createArrayNode();
    if (baseElement instanceof FlowNode) {
        FlowNode flowNode = (FlowNode) baseElement;
        for (SequenceFlow sequenceFlow : flowNode.getOutgoingFlows()) {
            outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(sequenceFlow.getId()));
        }
        for (MessageFlow messageFlow : model.getMessageFlows().values()) {
            if (messageFlow.getSourceRef().equals(flowNode.getId())) {
                outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(messageFlow.getId()));
            }
        }
    }
    if (baseElement instanceof Activity) {
        Activity activity = (Activity) baseElement;
        for (BoundaryEvent boundaryEvent : activity.getBoundaryEvents()) {
            outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(boundaryEvent.getId()));
        }
        propertiesNode.put(PROPERTY_ASYNCHRONOUS, activity.isAsynchronous());
        propertiesNode.put(PROPERTY_EXCLUSIVE, !activity.isNotExclusive());
        if (activity.getLoopCharacteristics() != null) {
            MultiInstanceLoopCharacteristics loopDef = activity.getLoopCharacteristics();
            if (StringUtils.isNotEmpty(loopDef.getLoopCardinality()) || StringUtils.isNotEmpty(loopDef.getInputDataItem()) || StringUtils.isNotEmpty(loopDef.getCompletionCondition())) {
                if (loopDef.isSequential() == false) {
                    propertiesNode.put(PROPERTY_MULTIINSTANCE_TYPE, "Parallel");
                } else {
                    propertiesNode.put(PROPERTY_MULTIINSTANCE_TYPE, "Sequential");
                }
                if (StringUtils.isNotEmpty(loopDef.getLoopCardinality())) {
                    propertiesNode.put(PROPERTY_MULTIINSTANCE_CARDINALITY, loopDef.getLoopCardinality());
                }
                if (StringUtils.isNotEmpty(loopDef.getInputDataItem())) {
                    propertiesNode.put(PROPERTY_MULTIINSTANCE_COLLECTION, loopDef.getInputDataItem());
                }
                if (StringUtils.isNotEmpty(loopDef.getElementVariable())) {
                    propertiesNode.put(PROPERTY_MULTIINSTANCE_VARIABLE, loopDef.getElementVariable());
                }
                if (StringUtils.isNotEmpty(loopDef.getCompletionCondition())) {
                    propertiesNode.put(PROPERTY_MULTIINSTANCE_CONDITION, loopDef.getCompletionCondition());
                }
            }
        }
        if (activity instanceof UserTask) {
            BpmnJsonConverterUtil.convertListenersToJson(((UserTask) activity).getTaskListeners(), false, propertiesNode);
        }
        BpmnJsonConverterUtil.convertListenersToJson(activity.getExecutionListeners(), true, propertiesNode);
        if (CollectionUtils.isNotEmpty(activity.getDataInputAssociations())) {
            for (DataAssociation dataAssociation : activity.getDataInputAssociations()) {
                if (model.getFlowElement(dataAssociation.getSourceRef()) != null) {
                    createDataAssociation(dataAssociation, true, activity);
                }
            }
        }
        if (CollectionUtils.isNotEmpty(activity.getDataOutputAssociations())) {
            for (DataAssociation dataAssociation : activity.getDataOutputAssociations()) {
                if (model.getFlowElement(dataAssociation.getTargetRef()) != null) {
                    createDataAssociation(dataAssociation, false, activity);
                    outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(dataAssociation.getId()));
                }
            }
        }
    }
    for (Artifact artifact : container.getArtifacts()) {
        if (artifact instanceof Association) {
            Association association = (Association) artifact;
            if (StringUtils.isNotEmpty(association.getSourceRef()) && association.getSourceRef().equals(baseElement.getId())) {
                outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(association.getId()));
            }
        }
    }
    if (baseElement instanceof DataStoreReference) {
        for (Process process : model.getProcesses()) {
            processDataStoreReferences(process, baseElement.getId(), outgoingArrayNode);
        }
    }
    flowElementNode.put("outgoing", outgoingArrayNode);
}
Also used : ServiceTask(org.activiti.bpmn.model.ServiceTask) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) BoundaryEvent(org.activiti.bpmn.model.BoundaryEvent) DataAssociation(org.activiti.bpmn.model.DataAssociation) SequenceFlow(org.activiti.bpmn.model.SequenceFlow) GraphicInfo(org.activiti.bpmn.model.GraphicInfo) UserTask(org.activiti.bpmn.model.UserTask) Activity(org.activiti.bpmn.model.Activity) Process(org.activiti.bpmn.model.Process) SubProcess(org.activiti.bpmn.model.SubProcess) MessageFlow(org.activiti.bpmn.model.MessageFlow) Artifact(org.activiti.bpmn.model.Artifact) DataStoreReference(org.activiti.bpmn.model.DataStoreReference) DataAssociation(org.activiti.bpmn.model.DataAssociation) Association(org.activiti.bpmn.model.Association) MultiInstanceLoopCharacteristics(org.activiti.bpmn.model.MultiInstanceLoopCharacteristics) FlowElement(org.activiti.bpmn.model.FlowElement) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) FlowNode(org.activiti.bpmn.model.FlowNode)

Example 30 with Process

use of org.activiti.bpmn.model.Process in project Activiti by Activiti.

the class WorkflowDefinitionConversionTest method testEmptyWorkflowDefinitionConversion.

/**
	 * Check if all required artifacts are created when converting an empty workflow-definition.
	 */
@Test
public void testEmptyWorkflowDefinitionConversion() {
    WorkflowDefinition definition = new WorkflowDefinition();
    definition.setDescription("This is the description");
    definition.setId("workflowdefinition");
    definition.setName("My workflow definition");
    WorkflowDefinitionConversion conversion = conversionFactory.createWorkflowDefinitionConversion(definition);
    conversion.convert();
    BpmnModel bpmnModel = conversion.getBpmnModel();
    assertNotNull(bpmnModel);
    Process process = bpmnModel.getMainProcess();
    assertNotNull(process);
    assertEquals("This is the description", process.getDocumentation());
    assertEquals("My workflow definition", process.getName());
    assertEquals("workflowdefinition", process.getId());
    // Default start-task key should be used, as no custom startform-config is present
    boolean startTaskFound = false;
    for (FlowElement element : process.getFlowElements()) {
        if (element instanceof StartEvent) {
            assertEquals("bpm:startTask", ((StartEvent) element).getFormKey());
            startTaskFound = true;
        }
    }
    assertTrue(startTaskFound);
    // Check presence of content-model
    M2Model contentModel = AlfrescoConversionUtil.getContentModel(conversion);
    assertNotNull(contentModel);
    // Check presence of form-config and default workflow-details
    Module module = AlfrescoConversionUtil.getExtension(conversion).getModules().get(0);
    assertNotNull(module);
    assertEquals(1L, module.getConfigurations().size());
    Configuration config = module.getConfigurations().get(0);
    assertEquals(1L, config.getForms().size());
    assertEquals("activiti$workflowdefinition", config.getCondition());
    assertEquals(AlfrescoConversionConstants.EVALUATOR_STRING_COMPARE, config.getEvaluator());
}
Also used : WorkflowDefinitionConversion(org.activiti.workflow.simple.converter.WorkflowDefinitionConversion) Configuration(org.activiti.workflow.simple.alfresco.model.config.Configuration) FlowElement(org.activiti.bpmn.model.FlowElement) M2Model(org.activiti.workflow.simple.alfresco.model.M2Model) StartEvent(org.activiti.bpmn.model.StartEvent) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) Process(org.activiti.bpmn.model.Process) Module(org.activiti.workflow.simple.alfresco.model.config.Module) BpmnModel(org.activiti.bpmn.model.BpmnModel) Test(org.junit.Test)

Aggregations

Process (org.activiti.bpmn.model.Process)32 FlowElement (org.activiti.bpmn.model.FlowElement)13 SequenceFlow (org.activiti.bpmn.model.SequenceFlow)9 SubProcess (org.activiti.bpmn.model.SubProcess)9 BpmnModel (org.activiti.bpmn.model.BpmnModel)8 Lane (org.activiti.bpmn.model.Lane)8 Pool (org.activiti.bpmn.model.Pool)8 UserTask (org.activiti.bpmn.model.UserTask)6 Artifact (org.activiti.bpmn.model.Artifact)5 List (java.util.List)4 EventSubProcess (org.activiti.bpmn.model.EventSubProcess)4 FlowNode (org.activiti.bpmn.model.FlowNode)4 GraphicInfo (org.activiti.bpmn.model.GraphicInfo)4 WorkflowDefinitionConversion (org.activiti.workflow.simple.converter.WorkflowDefinitionConversion)4 WorkflowDefinition (org.activiti.workflow.simple.definition.WorkflowDefinition)4 Test (org.junit.Test)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 ArrayList (java.util.ArrayList)3 ActivitiListener (org.activiti.bpmn.model.ActivitiListener)3