Search in sources :

Example 1 with MultiInstanceLoopCharacteristics

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

the class AbstractActivityBpmnParseHandler method createMultiInstanceLoopCharacteristics.

protected void createMultiInstanceLoopCharacteristics(BpmnParse bpmnParse, Activity modelActivity) {
    MultiInstanceLoopCharacteristics loopCharacteristics = modelActivity.getLoopCharacteristics();
    // Activity Behavior
    MultiInstanceActivityBehavior miActivityBehavior = null;
    ActivityImpl activity = bpmnParse.getCurrentScope().findActivity(modelActivity.getId());
    if (activity == null) {
        throw new ActivitiException("Activity " + modelActivity.getId() + " needed for multi instance cannot bv found");
    }
    if (loopCharacteristics.isSequential()) {
        miActivityBehavior = bpmnParse.getActivityBehaviorFactory().createSequentialMultiInstanceBehavior(activity, (AbstractBpmnActivityBehavior) activity.getActivityBehavior());
    } else {
        miActivityBehavior = bpmnParse.getActivityBehaviorFactory().createParallelMultiInstanceBehavior(activity, (AbstractBpmnActivityBehavior) activity.getActivityBehavior());
    }
    // ActivityImpl settings
    activity.setScope(true);
    activity.setProperty("multiInstance", loopCharacteristics.isSequential() ? "sequential" : "parallel");
    activity.setActivityBehavior(miActivityBehavior);
    ExpressionManager expressionManager = bpmnParse.getExpressionManager();
    BpmnModel bpmnModel = bpmnParse.getBpmnModel();
    // loopcardinality
    if (StringUtils.isNotEmpty(loopCharacteristics.getLoopCardinality())) {
        miActivityBehavior.setLoopCardinalityExpression(expressionManager.createExpression(loopCharacteristics.getLoopCardinality()));
    }
    // completion condition
    if (StringUtils.isNotEmpty(loopCharacteristics.getCompletionCondition())) {
        miActivityBehavior.setCompletionConditionExpression(expressionManager.createExpression(loopCharacteristics.getCompletionCondition()));
    }
    // activiti:collection
    if (StringUtils.isNotEmpty(loopCharacteristics.getInputDataItem())) {
        if (loopCharacteristics.getInputDataItem().contains("{")) {
            miActivityBehavior.setCollectionExpression(expressionManager.createExpression(loopCharacteristics.getInputDataItem()));
        } else {
            miActivityBehavior.setCollectionVariable(loopCharacteristics.getInputDataItem());
        }
    }
    // activiti:elementVariable
    if (StringUtils.isNotEmpty(loopCharacteristics.getElementVariable())) {
        miActivityBehavior.setCollectionElementVariable(loopCharacteristics.getElementVariable());
    }
    // activiti:elementIndexVariable
    if (StringUtils.isNotEmpty(loopCharacteristics.getElementIndexVariable())) {
        miActivityBehavior.setCollectionElementIndexVariable(loopCharacteristics.getElementIndexVariable());
    }
}
Also used : ExpressionManager(org.activiti.engine.impl.el.ExpressionManager) ActivitiException(org.activiti.engine.ActivitiException) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) MultiInstanceLoopCharacteristics(org.activiti.bpmn.model.MultiInstanceLoopCharacteristics) AbstractBpmnActivityBehavior(org.activiti.engine.impl.bpmn.behavior.AbstractBpmnActivityBehavior) MultiInstanceActivityBehavior(org.activiti.engine.impl.bpmn.behavior.MultiInstanceActivityBehavior) BpmnModel(org.activiti.bpmn.model.BpmnModel)

Example 2 with MultiInstanceLoopCharacteristics

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

the class FeedbackStepDefinitionConverter method createFeedbackUserTask.

protected UserTask createFeedbackUserTask(FeedbackStepDefinition feedbackStepDefinition, WorkflowDefinitionConversion conversion, Map<String, BaseElement> processElements) {
    UserTask feedbackTask = new UserTask();
    feedbackTask.setId(conversion.getUniqueNumberedId(ConversionConstants.USER_TASK_ID_PREFIX));
    feedbackTask.setName(getProvideFeedbackTaskName());
    feedbackTask.setAssignee("${" + VARIABLE_FEEDBACK_PROVIDER + "}");
    MultiInstanceLoopCharacteristics multiInstanceLoopCharacteristics = new MultiInstanceLoopCharacteristics();
    multiInstanceLoopCharacteristics.setSequential(false);
    multiInstanceLoopCharacteristics.setInputDataItem(VARIABLE_FEEDBACK_PROVIDERS);
    multiInstanceLoopCharacteristics.setElementVariable(VARIABLE_FEEDBACK_PROVIDER);
    feedbackTask.setLoopCharacteristics(multiInstanceLoopCharacteristics);
    addFlowElement(conversion, feedbackTask);
    processElements.put(FEEDBACK_USER_TASK, feedbackTask);
    return feedbackTask;
}
Also used : MultiInstanceLoopCharacteristics(org.activiti.bpmn.model.MultiInstanceLoopCharacteristics) UserTask(org.activiti.bpmn.model.UserTask)

Example 3 with MultiInstanceLoopCharacteristics

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

the class MultiInstanceExport method writeMultiInstance.

public static void writeMultiInstance(Activity activity, XMLStreamWriter xtw) throws Exception {
    if (activity.getLoopCharacteristics() != null) {
        MultiInstanceLoopCharacteristics multiInstanceObject = activity.getLoopCharacteristics();
        if (StringUtils.isNotEmpty(multiInstanceObject.getLoopCardinality()) || StringUtils.isNotEmpty(multiInstanceObject.getInputDataItem()) || StringUtils.isNotEmpty(multiInstanceObject.getCompletionCondition())) {
            xtw.writeStartElement(ELEMENT_MULTIINSTANCE);
            BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_MULTIINSTANCE_SEQUENTIAL, String.valueOf(multiInstanceObject.isSequential()).toLowerCase(), xtw);
            if (StringUtils.isNotEmpty(multiInstanceObject.getInputDataItem())) {
                BpmnXMLUtil.writeQualifiedAttribute(ATTRIBUTE_MULTIINSTANCE_COLLECTION, multiInstanceObject.getInputDataItem(), xtw);
            }
            if (StringUtils.isNotEmpty(multiInstanceObject.getElementVariable())) {
                BpmnXMLUtil.writeQualifiedAttribute(ATTRIBUTE_MULTIINSTANCE_VARIABLE, multiInstanceObject.getElementVariable(), xtw);
            }
            if (StringUtils.isNotEmpty(multiInstanceObject.getLoopCardinality())) {
                xtw.writeStartElement(ELEMENT_MULTIINSTANCE_CARDINALITY);
                xtw.writeCharacters(multiInstanceObject.getLoopCardinality());
                xtw.writeEndElement();
            }
            if (StringUtils.isNotEmpty(multiInstanceObject.getCompletionCondition())) {
                xtw.writeStartElement(ELEMENT_MULTIINSTANCE_CONDITION);
                xtw.writeCharacters(multiInstanceObject.getCompletionCondition());
                xtw.writeEndElement();
            }
            xtw.writeEndElement();
        }
    }
}
Also used : MultiInstanceLoopCharacteristics(org.activiti.bpmn.model.MultiInstanceLoopCharacteristics)

Example 4 with MultiInstanceLoopCharacteristics

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

the class MultiInstanceParser method parseChildElement.

public void parseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model) throws Exception {
    if (parentElement instanceof Activity == false)
        return;
    MultiInstanceLoopCharacteristics multiInstanceDef = new MultiInstanceLoopCharacteristics();
    BpmnXMLUtil.addXMLLocation(multiInstanceDef, xtr);
    if (xtr.getAttributeValue(null, ATTRIBUTE_MULTIINSTANCE_SEQUENTIAL) != null) {
        multiInstanceDef.setSequential(Boolean.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_MULTIINSTANCE_SEQUENTIAL)));
    }
    multiInstanceDef.setInputDataItem(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_MULTIINSTANCE_COLLECTION));
    multiInstanceDef.setElementVariable(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_MULTIINSTANCE_VARIABLE));
    multiInstanceDef.setElementIndexVariable(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_MULTIINSTANCE_INDEX_VARIABLE));
    boolean readyWithMultiInstance = false;
    try {
        while (readyWithMultiInstance == false && xtr.hasNext()) {
            xtr.next();
            if (xtr.isStartElement() && ELEMENT_MULTIINSTANCE_CARDINALITY.equalsIgnoreCase(xtr.getLocalName())) {
                multiInstanceDef.setLoopCardinality(xtr.getElementText());
            } else if (xtr.isStartElement() && ELEMENT_MULTIINSTANCE_DATAINPUT.equalsIgnoreCase(xtr.getLocalName())) {
                multiInstanceDef.setInputDataItem(xtr.getElementText());
            } else if (xtr.isStartElement() && ELEMENT_MULTIINSTANCE_DATAITEM.equalsIgnoreCase(xtr.getLocalName())) {
                if (xtr.getAttributeValue(null, ATTRIBUTE_NAME) != null) {
                    multiInstanceDef.setElementVariable(xtr.getAttributeValue(null, ATTRIBUTE_NAME));
                }
            } else if (xtr.isStartElement() && ELEMENT_MULTIINSTANCE_CONDITION.equalsIgnoreCase(xtr.getLocalName())) {
                multiInstanceDef.setCompletionCondition(xtr.getElementText());
            } else if (xtr.isEndElement() && getElementName().equalsIgnoreCase(xtr.getLocalName())) {
                readyWithMultiInstance = true;
            }
        }
    } catch (Exception e) {
        LOGGER.warn("Error parsing multi instance definition", e);
    }
    ((Activity) parentElement).setLoopCharacteristics(multiInstanceDef);
}
Also used : MultiInstanceLoopCharacteristics(org.activiti.bpmn.model.MultiInstanceLoopCharacteristics) Activity(org.activiti.bpmn.model.Activity)

Example 5 with MultiInstanceLoopCharacteristics

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

the class DefaultProcessDiagramGenerator method drawActivity.

protected void drawActivity(DefaultProcessDiagramCanvas processDiagramCanvas, BpmnModel bpmnModel, FlowNode flowNode, List<String> highLightedActivities, List<String> highLightedFlows, double scaleFactor) {
    ActivityDrawInstruction drawInstruction = activityDrawInstructions.get(flowNode.getClass());
    if (drawInstruction != null) {
        drawInstruction.draw(processDiagramCanvas, bpmnModel, flowNode);
        // Gather info on the multi instance marker
        boolean multiInstanceSequential = false, multiInstanceParallel = false, collapsed = false;
        if (flowNode instanceof Activity) {
            Activity activity = (Activity) flowNode;
            MultiInstanceLoopCharacteristics multiInstanceLoopCharacteristics = activity.getLoopCharacteristics();
            if (multiInstanceLoopCharacteristics != null) {
                multiInstanceSequential = multiInstanceLoopCharacteristics.isSequential();
                multiInstanceParallel = !multiInstanceSequential;
            }
        }
        // Gather info on the collapsed marker
        GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
        if (flowNode instanceof SubProcess) {
            collapsed = graphicInfo.getExpanded() != null && !graphicInfo.getExpanded();
        } else if (flowNode instanceof CallActivity) {
            collapsed = true;
        }
        if (scaleFactor == 1.0) {
            // Actually draw the markers
            processDiagramCanvas.drawActivityMarkers((int) graphicInfo.getX(), (int) graphicInfo.getY(), (int) graphicInfo.getWidth(), (int) graphicInfo.getHeight(), multiInstanceSequential, multiInstanceParallel, collapsed);
        }
        // Draw highlighted activities
        if (highLightedActivities.contains(flowNode.getId())) {
            drawHighLight(processDiagramCanvas, bpmnModel.getGraphicInfo(flowNode.getId()));
        }
    }
    // Outgoing transitions of activity
    for (SequenceFlow sequenceFlow : flowNode.getOutgoingFlows()) {
        boolean highLighted = (highLightedFlows.contains(sequenceFlow.getId()));
        String defaultFlow = null;
        if (flowNode instanceof Activity) {
            defaultFlow = ((Activity) flowNode).getDefaultFlow();
        } else if (flowNode instanceof Gateway) {
            defaultFlow = ((Gateway) flowNode).getDefaultFlow();
        }
        boolean isDefault = false;
        if (defaultFlow != null && defaultFlow.equalsIgnoreCase(sequenceFlow.getId())) {
            isDefault = true;
        }
        boolean drawConditionalIndicator = sequenceFlow.getConditionExpression() != null && !(flowNode instanceof Gateway);
        String sourceRef = sequenceFlow.getSourceRef();
        String targetRef = sequenceFlow.getTargetRef();
        FlowElement sourceElement = bpmnModel.getFlowElement(sourceRef);
        FlowElement targetElement = bpmnModel.getFlowElement(targetRef);
        List<GraphicInfo> graphicInfoList = bpmnModel.getFlowLocationGraphicInfo(sequenceFlow.getId());
        if (graphicInfoList != null && graphicInfoList.size() > 0) {
            graphicInfoList = connectionPerfectionizer(processDiagramCanvas, bpmnModel, sourceElement, targetElement, graphicInfoList);
            int[] xPoints = new int[graphicInfoList.size()];
            int[] yPoints = new int[graphicInfoList.size()];
            for (int i = 1; i < graphicInfoList.size(); i++) {
                GraphicInfo graphicInfo = graphicInfoList.get(i);
                GraphicInfo previousGraphicInfo = graphicInfoList.get(i - 1);
                if (i == 1) {
                    xPoints[0] = (int) previousGraphicInfo.getX();
                    yPoints[0] = (int) previousGraphicInfo.getY();
                }
                xPoints[i] = (int) graphicInfo.getX();
                yPoints[i] = (int) graphicInfo.getY();
            }
            processDiagramCanvas.drawSequenceflow(xPoints, yPoints, drawConditionalIndicator, isDefault, highLighted, scaleFactor);
            // Draw sequenceflow label
            GraphicInfo labelGraphicInfo = bpmnModel.getLabelGraphicInfo(sequenceFlow.getId());
            if (labelGraphicInfo != null) {
                processDiagramCanvas.drawLabel(sequenceFlow.getName(), labelGraphicInfo, false);
            }
        }
    }
    // Nested elements
    if (flowNode instanceof FlowElementsContainer) {
        for (FlowElement nestedFlowElement : ((FlowElementsContainer) flowNode).getFlowElements()) {
            if (nestedFlowElement instanceof FlowNode) {
                drawActivity(processDiagramCanvas, bpmnModel, (FlowNode) nestedFlowElement, highLightedActivities, highLightedFlows, scaleFactor);
            }
        }
    }
}
Also used : EventSubProcess(org.activiti.bpmn.model.EventSubProcess) SubProcess(org.activiti.bpmn.model.SubProcess) SequenceFlow(org.activiti.bpmn.model.SequenceFlow) GraphicInfo(org.activiti.bpmn.model.GraphicInfo) CallActivity(org.activiti.bpmn.model.CallActivity) Activity(org.activiti.bpmn.model.Activity) FlowElementsContainer(org.activiti.bpmn.model.FlowElementsContainer) CallActivity(org.activiti.bpmn.model.CallActivity) MultiInstanceLoopCharacteristics(org.activiti.bpmn.model.MultiInstanceLoopCharacteristics) ExclusiveGateway(org.activiti.bpmn.model.ExclusiveGateway) EventGateway(org.activiti.bpmn.model.EventGateway) InclusiveGateway(org.activiti.bpmn.model.InclusiveGateway) ParallelGateway(org.activiti.bpmn.model.ParallelGateway) Gateway(org.activiti.bpmn.model.Gateway) FlowElement(org.activiti.bpmn.model.FlowElement) FlowNode(org.activiti.bpmn.model.FlowNode)

Aggregations

MultiInstanceLoopCharacteristics (org.activiti.bpmn.model.MultiInstanceLoopCharacteristics)8 Activity (org.activiti.bpmn.model.Activity)4 FlowElement (org.activiti.bpmn.model.FlowElement)4 SequenceFlow (org.activiti.bpmn.model.SequenceFlow)3 SubProcess (org.activiti.bpmn.model.SubProcess)3 UserTask (org.activiti.bpmn.model.UserTask)3 Artifact (org.activiti.bpmn.model.Artifact)2 FlowNode (org.activiti.bpmn.model.FlowNode)2 Gateway (org.activiti.bpmn.model.Gateway)2 GraphicInfo (org.activiti.bpmn.model.GraphicInfo)2 Process (org.activiti.bpmn.model.Process)2 ServiceTask (org.activiti.bpmn.model.ServiceTask)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Association (org.activiti.bpmn.model.Association)1 BaseElement (org.activiti.bpmn.model.BaseElement)1 BoundaryEvent (org.activiti.bpmn.model.BoundaryEvent)1 BpmnModel (org.activiti.bpmn.model.BpmnModel)1 CallActivity (org.activiti.bpmn.model.CallActivity)1