Search in sources :

Example 11 with Task

use of org.eclipse.bpmn2.Task in project kie-wb-common by kiegroup.

the class Bpmn2JsonUnmarshaller method revisitMultiInstanceTasks.

public void revisitMultiInstanceTasks(Definitions def) {
    try {
        List<RootElement> rootElements = def.getRootElements();
        for (RootElement root : rootElements) {
            if (root instanceof Process) {
                Process process = (Process) root;
                List<FlowElement> flowElements = process.getFlowElements();
                for (FlowElement fe : flowElements) {
                    if (fe instanceof Task) {
                        Task task = (Task) fe;
                        Iterator<FeatureMap.Entry> iter = task.getAnyAttribute().iterator();
                        while (iter.hasNext()) {
                            FeatureMap.Entry entry = iter.next();
                            if (entry.getEStructuralFeature().getName().equals("mitask")) {
                                String multiValue = (String) entry.getValue();
                                String[] multiValueParts = multiValue.split("@");
                                if (multiValueParts != null && multiValueParts.length == 5) {
                                    String miCollectionInput = (multiValueParts[0].equals(" ") ? "" : multiValueParts[0]);
                                    String miCollectionOutput = (multiValueParts[1].equals(" ") ? "" : multiValueParts[1]);
                                    String miDataInput = (multiValueParts[2].equals(" ") ? "" : multiValueParts[2]);
                                    String miDataOutput = (multiValueParts[3].equals(" ") ? "" : multiValueParts[3]);
                                    String miCompletionCondition = (multiValueParts[4].equals(" ") ? "" : multiValueParts[4]);
                                    MultiInstanceLoopCharacteristics loopCharacteristics = Bpmn2Factory.eINSTANCE.createMultiInstanceLoopCharacteristics();
                                    if (miCollectionInput != null && miCollectionInput.length() > 0) {
                                        List<Property> properties = process.getProperties();
                                        for (Property prop : properties) {
                                            if (prop.getId() != null && prop.getId().equals(miCollectionInput)) {
                                                DataInput miCollectionInputDI = Bpmn2Factory.eINSTANCE.createDataInput();
                                                miCollectionInputDI.setName("miinputCollection");
                                                ItemDefinition miCollectionInputDIItemDefinition = this.getMessageItemDefinition(def.getRootElements(), prop.getId());
                                                miCollectionInputDI.setItemSubjectRef(miCollectionInputDIItemDefinition);
                                                task.getIoSpecification().getDataInputs().add(miCollectionInputDI);
                                                if (task.getIoSpecification().getInputSets() == null || task.getIoSpecification().getInputSets().size() < 1) {
                                                    InputSet inset = Bpmn2Factory.eINSTANCE.createInputSet();
                                                    task.getIoSpecification().getInputSets().add(inset);
                                                }
                                                task.getIoSpecification().getInputSets().get(0).getDataInputRefs().add(miCollectionInputDI);
                                                loopCharacteristics.setLoopDataInputRef(miCollectionInputDI);
                                                DataInputAssociation miCollectionInputDataInputAssociation = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
                                                miCollectionInputDataInputAssociation.getSourceRef().add(prop);
                                                miCollectionInputDataInputAssociation.setTargetRef(miCollectionInputDI);
                                                task.getDataInputAssociations().add(miCollectionInputDataInputAssociation);
                                                break;
                                            }
                                        }
                                    }
                                    if (miCollectionOutput != null && miCollectionOutput.length() > 0) {
                                        List<Property> properties = process.getProperties();
                                        for (Property prop : properties) {
                                            if (prop.getId() != null && prop.getId().equals(miCollectionOutput)) {
                                                DataOutput miCollectionOutputDI = Bpmn2Factory.eINSTANCE.createDataOutput();
                                                miCollectionOutputDI.setName("mioutputCollection");
                                                ItemDefinition miCollectionOutputDIItemDefinition = this.getMessageItemDefinition(def.getRootElements(), prop.getId());
                                                miCollectionOutputDI.setItemSubjectRef(miCollectionOutputDIItemDefinition);
                                                task.getIoSpecification().getDataOutputs().add(miCollectionOutputDI);
                                                if (task.getIoSpecification().getOutputSets() == null || task.getIoSpecification().getOutputSets().size() < 1) {
                                                    OutputSet outset = Bpmn2Factory.eINSTANCE.createOutputSet();
                                                    task.getIoSpecification().getOutputSets().add(outset);
                                                }
                                                task.getIoSpecification().getOutputSets().get(0).getDataOutputRefs().add(miCollectionOutputDI);
                                                loopCharacteristics.setLoopDataOutputRef(miCollectionOutputDI);
                                                DataOutputAssociation miCollectionInputDataOutputAssociation = Bpmn2Factory.eINSTANCE.createDataOutputAssociation();
                                                miCollectionInputDataOutputAssociation.setTargetRef(prop);
                                                miCollectionInputDataOutputAssociation.getSourceRef().add(miCollectionOutputDI);
                                                task.getDataOutputAssociations().add(miCollectionInputDataOutputAssociation);
                                                break;
                                            }
                                        }
                                    }
                                    if (miDataInput != null && miDataInput.length() > 0) {
                                        List<DataInput> dins = task.getIoSpecification().getDataInputs();
                                        for (DataInput di : dins) {
                                            if (di.getName().equals(miDataInput)) {
                                                DataInput inputDataItemObj = Bpmn2Factory.eINSTANCE.createDataInput();
                                                inputDataItemObj.setId("miDataInputX");
                                                inputDataItemObj.setItemSubjectRef(di.getItemSubjectRef());
                                                loopCharacteristics.setInputDataItem(inputDataItemObj);
                                                break;
                                            }
                                        }
                                    }
                                    if (miDataOutput != null && miDataOutput.length() > 0) {
                                        List<DataOutput> douts = task.getIoSpecification().getDataOutputs();
                                        for (DataOutput dout : douts) {
                                            if (dout.getName().equals(miDataOutput)) {
                                                DataOutput outputDataItemObj = Bpmn2Factory.eINSTANCE.createDataOutput();
                                                outputDataItemObj.setId("miDataOutputX");
                                                outputDataItemObj.setItemSubjectRef(dout.getItemSubjectRef());
                                                loopCharacteristics.setOutputDataItem(outputDataItemObj);
                                                break;
                                            }
                                        }
                                    }
                                    if (miCompletionCondition != null && !miCompletionCondition.isEmpty()) {
                                        FormalExpression expr = Bpmn2Factory.eINSTANCE.createFormalExpression();
                                        expr.setBody(miCompletionCondition);
                                        loopCharacteristics.setCompletionCondition(expr);
                                    }
                                    task.setLoopCharacteristics(loopCharacteristics);
                                    if (miDataInput != null && miDataInput.length() > 0 && ((MultiInstanceLoopCharacteristics) task.getLoopCharacteristics()).getInputDataItem() != null) {
                                        DataInputAssociation dias = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
                                        dias.getSourceRef().add(((MultiInstanceLoopCharacteristics) task.getLoopCharacteristics()).getInputDataItem());
                                        List<DataInput> dins = task.getIoSpecification().getDataInputs();
                                        for (DataInput di : dins) {
                                            if (di.getName().equals(miDataInput)) {
                                                dias.setTargetRef(di);
                                                task.getDataInputAssociations().add(dias);
                                                break;
                                            }
                                        }
                                    }
                                    if (miDataOutput != null && miDataOutput.length() > 0 && ((MultiInstanceLoopCharacteristics) task.getLoopCharacteristics()).getOutputDataItem() != null) {
                                        DataOutputAssociation dout = Bpmn2Factory.eINSTANCE.createDataOutputAssociation();
                                        dout.setTargetRef(((MultiInstanceLoopCharacteristics) task.getLoopCharacteristics()).getOutputDataItem());
                                        List<DataOutput> douts = task.getIoSpecification().getDataOutputs();
                                        for (DataOutput dou : douts) {
                                            if (dou.getName().equals(miDataOutput)) {
                                                dout.getSourceRef().add(dou);
                                                task.getDataOutputAssociations().add(dout);
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : DataOutput(org.eclipse.bpmn2.DataOutput) ServiceTask(org.eclipse.bpmn2.ServiceTask) ReceiveTask(org.eclipse.bpmn2.ReceiveTask) SendTask(org.eclipse.bpmn2.SendTask) GlobalTask(org.eclipse.bpmn2.GlobalTask) BusinessRuleTask(org.eclipse.bpmn2.BusinessRuleTask) Task(org.eclipse.bpmn2.Task) ScriptTask(org.eclipse.bpmn2.ScriptTask) UserTask(org.eclipse.bpmn2.UserTask) ItemDefinition(org.eclipse.bpmn2.ItemDefinition) AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) SubProcess(org.eclipse.bpmn2.SubProcess) Process(org.eclipse.bpmn2.Process) Entry(java.util.Map.Entry) SimpleFeatureMapEntry(org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry) MultiInstanceLoopCharacteristics(org.eclipse.bpmn2.MultiInstanceLoopCharacteristics) DataOutputAssociation(org.eclipse.bpmn2.DataOutputAssociation) Property(org.eclipse.bpmn2.Property) OutputSet(org.eclipse.bpmn2.OutputSet) FormalExpression(org.eclipse.bpmn2.FormalExpression) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) FeatureMap(org.eclipse.emf.ecore.util.FeatureMap) DataInput(org.eclipse.bpmn2.DataInput) InputSet(org.eclipse.bpmn2.InputSet) RootElement(org.eclipse.bpmn2.RootElement) FlowElement(org.eclipse.bpmn2.FlowElement) DataInputAssociation(org.eclipse.bpmn2.DataInputAssociation)

Example 12 with Task

use of org.eclipse.bpmn2.Task in project kie-wb-common by kiegroup.

the class Bpmn2JsonUnmarshaller method unmarshallItem.

public BaseElement unmarshallItem(JsonParser parser, String preProcessingData) throws JsonParseException, IOException {
    String resourceId = null;
    Map<String, String> properties = null;
    String stencil = null;
    List<BaseElement> childElements = new ArrayList<BaseElement>();
    List<String> outgoing = new ArrayList<String>();
    while (parser.nextToken() != JsonToken.END_OBJECT) {
        String fieldname = parser.getCurrentName();
        parser.nextToken();
        if ("resourceId".equals(fieldname)) {
            resourceId = parser.getText();
        } else if ("properties".equals(fieldname)) {
            properties = unmarshallProperties(parser);
        } else if ("stencil".equals(fieldname)) {
            // "stencil":{"id":"Task"},
            parser.nextToken();
            parser.nextToken();
            stencil = parser.getText();
            parser.nextToken();
        } else if ("childShapes".equals(fieldname)) {
            while (parser.nextToken() != JsonToken.END_ARRAY) {
                // open the
                // object
                // the childShapes element is a json array. We opened the
                // array.
                childElements.add(unmarshallItem(parser, preProcessingData));
            }
        } else if ("bounds".equals(fieldname)) {
            // bounds: {"lowerRight":{"x":484.0,"y":198.0},"upperLeft":{"x":454.0,"y":168.0}}
            parser.nextToken();
            parser.nextToken();
            parser.nextToken();
            parser.nextToken();
            Integer x2 = parser.getIntValue();
            parser.nextToken();
            parser.nextToken();
            Integer y2 = parser.getIntValue();
            parser.nextToken();
            parser.nextToken();
            parser.nextToken();
            parser.nextToken();
            parser.nextToken();
            Integer x1 = parser.getIntValue();
            parser.nextToken();
            parser.nextToken();
            Integer y1 = parser.getIntValue();
            parser.nextToken();
            parser.nextToken();
            Bounds b = DcFactory.eINSTANCE.createBounds();
            b.setX(x1);
            b.setY(y1);
            b.setWidth(x2 - x1);
            b.setHeight(y2 - y1);
            this._bounds.put(resourceId, b);
        } else if ("dockers".equals(fieldname)) {
            // "dockers":[{"x":50,"y":40},{"x":353.5,"y":115},{"x":353.5,"y":152},{"x":50,"y":40}],
            List<Point> dockers = new ArrayList<Point>();
            JsonToken nextToken = parser.nextToken();
            boolean end = JsonToken.END_ARRAY.equals(nextToken);
            while (!end) {
                nextToken = parser.nextToken();
                nextToken = parser.nextToken();
                Integer x = parser.getIntValue();
                parser.nextToken();
                parser.nextToken();
                Integer y = parser.getIntValue();
                Point point = DcFactory.eINSTANCE.createPoint();
                point.setX(x);
                point.setY(y);
                dockers.add(point);
                parser.nextToken();
                nextToken = parser.nextToken();
                end = JsonToken.END_ARRAY.equals(nextToken);
            }
            this._dockers.put(resourceId, dockers);
        } else if ("outgoing".equals(fieldname)) {
            while (parser.nextToken() != JsonToken.END_ARRAY) {
                // {resourceId: oryx_1AAA8C9A-39A5-42FC-8ED1-507A7F3728EA}
                parser.nextToken();
                parser.nextToken();
                outgoing.add(parser.getText());
                parser.nextToken();
            }
            // pass on the array
            parser.skipChildren();
        } else if ("target".equals(fieldname)) {
            // we already collected that info with the outgoing field.
            parser.skipChildren();
        // "target": {
        // "resourceId": "oryx_A75E7546-DF71-48EA-84D3-2A8FD4A47568"
        // }
        // add to the map:
        // parser.nextToken(); // resourceId:
        // parser.nextToken(); // the value we want to save
        // targetId = parser.getText();
        // parser.nextToken(); // }, closing the object
        }
    }
    properties.put("resourceId", resourceId);
    boolean customElement = isCustomElement(properties.get("tasktype"), preProcessingData);
    BaseElement baseElt = this.createBaseElement(stencil, properties.get("tasktype"), customElement);
    // register the sequence flow targets.
    if (baseElt instanceof SequenceFlow) {
        _sequenceFlowTargets.addAll(outgoing);
    }
    _outgoingFlows.put(baseElt, outgoing);
    _objMap.put(baseElt, // keep the object around to do connections
    resourceId);
    _idMap.put(resourceId, baseElt);
    // baseElt.setId(resourceId); commented out as bpmn2 seems to create
    // duplicate ids right now.
    applyProperties(baseElt, properties, preProcessingData);
    if (baseElt instanceof Definitions) {
        Process rootLevelProcess = null;
        if (childElements == null || childElements.size() < 1) {
            if (rootLevelProcess == null) {
                rootLevelProcess = Bpmn2Factory.eINSTANCE.createProcess();
                // set the properties and item definitions first
                if (properties.get("vardefs") != null && properties.get("vardefs").length() > 0) {
                    String[] vardefs = properties.get("vardefs").split(",\\s*");
                    for (String vardef : vardefs) {
                        Property prop = Bpmn2Factory.eINSTANCE.createProperty();
                        ItemDefinition itemdef = Bpmn2Factory.eINSTANCE.createItemDefinition();
                        // check if we define a structure ref in the definition
                        if (vardef.contains(":")) {
                            String[] vardefParts = vardef.split(":\\s*");
                            prop.setId(vardefParts[0]);
                            itemdef.setId("_" + prop.getId() + "Item");
                            boolean haveKPI = false;
                            String kpiValue = "";
                            if (vardefParts.length == 3) {
                                itemdef.setStructureRef(vardefParts[1]);
                                if (vardefParts[2].equals("true")) {
                                    haveKPI = true;
                                    kpiValue = vardefParts[2];
                                }
                            }
                            if (vardefParts.length == 2) {
                                if (vardefParts[1].equals("true") || vardefParts[1].equals("false")) {
                                    if (vardefParts[1].equals("true")) {
                                        haveKPI = true;
                                        kpiValue = vardefParts[1];
                                    }
                                } else {
                                    itemdef.setStructureRef(vardefParts[1]);
                                }
                            }
                            if (haveKPI) {
                                Utils.setMetaDataExtensionValue(prop, "customKPI", wrapInCDATABlock(kpiValue));
                            }
                        } else {
                            prop.setId(vardef);
                            itemdef.setId("_" + prop.getId() + "Item");
                        }
                        prop.setItemSubjectRef(itemdef);
                        rootLevelProcess.getProperties().add(prop);
                        ((Definitions) baseElt).getRootElements().add(itemdef);
                    }
                }
                if (properties.get("adhocprocess") != null && properties.get("adhocprocess").equals("true")) {
                    ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
                    EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "adHoc", false, false);
                    SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("adhocprocess"));
                    rootLevelProcess.getAnyAttribute().add(extensionEntry);
                }
                if (properties.get("customdescription") != null && properties.get("customdescription").length() > 0) {
                    Utils.setMetaDataExtensionValue(rootLevelProcess, "customDescription", wrapInCDATABlock(properties.get("customdescription")));
                }
                rootLevelProcess.setId(properties.get("id"));
                applyProcessProperties(rootLevelProcess, properties);
                ((Definitions) baseElt).getRootElements().add(rootLevelProcess);
            }
        } else {
            for (BaseElement child : childElements) {
                // } else {
                if (child instanceof SequenceFlow) {
                    // for some reason sequence flows are placed as root elements.
                    // find if the target has a container, and if we can use it:
                    List<String> ids = _outgoingFlows.get(child);
                    FlowElementsContainer container = null;
                    for (String id : ids) {
                        // yes, we iterate, but we'll take the first in the list that will work.
                        Object obj = _idMap.get(id);
                        if (obj instanceof EObject && ((EObject) obj).eContainer() instanceof FlowElementsContainer) {
                            container = (FlowElementsContainer) ((EObject) obj).eContainer();
                            break;
                        }
                    }
                    if (container != null) {
                        container.getFlowElements().add((SequenceFlow) child);
                        continue;
                    }
                }
                if (child instanceof Task || child instanceof SequenceFlow || child instanceof Gateway || child instanceof Event || child instanceof Artifact || child instanceof DataObject || child instanceof SubProcess || child instanceof Lane || child instanceof CallActivity || child instanceof TextAnnotation) {
                    if (rootLevelProcess == null) {
                        rootLevelProcess = Bpmn2Factory.eINSTANCE.createProcess();
                        // set the properties and item definitions first
                        if (properties.get("vardefs") != null && properties.get("vardefs").length() > 0) {
                            String[] vardefs = properties.get("vardefs").split(",\\s*");
                            for (String vardef : vardefs) {
                                Property prop = Bpmn2Factory.eINSTANCE.createProperty();
                                ItemDefinition itemdef = Bpmn2Factory.eINSTANCE.createItemDefinition();
                                // check if we define a structure ref in the definition
                                if (vardef.contains(":")) {
                                    String[] vardefParts = vardef.split(":\\s*");
                                    prop.setId(vardefParts[0]);
                                    itemdef.setId("_" + prop.getId() + "Item");
                                    boolean haveKPI = false;
                                    String kpiValue = "";
                                    if (vardefParts.length == 3) {
                                        itemdef.setStructureRef(vardefParts[1]);
                                        if (vardefParts[2].equals("true")) {
                                            haveKPI = true;
                                            kpiValue = vardefParts[2];
                                        }
                                    }
                                    if (vardefParts.length == 2) {
                                        if (vardefParts[1].equals("true") || vardefParts[1].equals("false")) {
                                            if (vardefParts[1].equals("true")) {
                                                haveKPI = true;
                                                kpiValue = vardefParts[1];
                                            }
                                        } else {
                                            itemdef.setStructureRef(vardefParts[1]);
                                        }
                                    }
                                    if (haveKPI) {
                                        Utils.setMetaDataExtensionValue(prop, "customKPI", wrapInCDATABlock(kpiValue));
                                    }
                                } else {
                                    prop.setId(vardef);
                                    itemdef.setId("_" + prop.getId() + "Item");
                                }
                                prop.setItemSubjectRef(itemdef);
                                rootLevelProcess.getProperties().add(prop);
                                ((Definitions) baseElt).getRootElements().add(itemdef);
                            }
                        }
                        if (properties.get("adhocprocess") != null && properties.get("adhocprocess").equals("true")) {
                            ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
                            EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "adHoc", false, false);
                            SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("adhocprocess"));
                            rootLevelProcess.getAnyAttribute().add(extensionEntry);
                        }
                        if (properties.get("customdescription") != null && properties.get("customdescription").length() > 0) {
                            Utils.setMetaDataExtensionValue(rootLevelProcess, "customDescription", wrapInCDATABlock(properties.get("customdescription")));
                        }
                        rootLevelProcess.setId(properties.get("id"));
                        applyProcessProperties(rootLevelProcess, properties);
                        ((Definitions) baseElt).getRootElements().add(rootLevelProcess);
                    }
                }
                if (child instanceof Task) {
                    rootLevelProcess.getFlowElements().add((Task) child);
                } else if (child instanceof CallActivity) {
                    rootLevelProcess.getFlowElements().add((CallActivity) child);
                } else if (child instanceof RootElement) {
                    ((Definitions) baseElt).getRootElements().add((RootElement) child);
                } else if (child instanceof SequenceFlow) {
                    rootLevelProcess.getFlowElements().add((SequenceFlow) child);
                } else if (child instanceof Gateway) {
                    rootLevelProcess.getFlowElements().add((Gateway) child);
                } else if (child instanceof Event) {
                    rootLevelProcess.getFlowElements().add((Event) child);
                } else if (child instanceof TextAnnotation) {
                    rootLevelProcess.getFlowElements().add((TextAnnotation) child);
                } else if (child instanceof Artifact) {
                    rootLevelProcess.getArtifacts().add((Artifact) child);
                } else if (child instanceof DataObject) {
                    // bubble up data objects
                    // rootLevelProcess.getFlowElements().add(0, (DataObject) child);
                    rootLevelProcess.getFlowElements().add((DataObject) child);
                // ItemDefinition def = ((DataObject) child).getItemSubjectRef();
                // if (def != null) {
                // if (def.eResource() == null) {
                // ((Definitions) rootLevelProcess.eContainer()).getRootElements().add(0, def);
                // }
                // Import imported = def.getImport();
                // if (imported != null && imported.eResource() == null) {
                // ((Definitions) rootLevelProcess.eContainer()).getImports().add(0, imported);
                // }
                // }
                } else if (child instanceof SubProcess) {
                    rootLevelProcess.getFlowElements().add((SubProcess) child);
                } else if (child instanceof Lane) {
                // lanes handled later
                } else {
                    _logger.error("Don't know what to do of " + child);
                }
            // }
            }
        }
    } else if (baseElt instanceof Process) {
        for (BaseElement child : childElements) {
            if (child instanceof Lane) {
                if (((Process) baseElt).getLaneSets().isEmpty()) {
                    ((Process) baseElt).getLaneSets().add(Bpmn2Factory.eINSTANCE.createLaneSet());
                }
                ((Process) baseElt).getLaneSets().get(0).getLanes().add((Lane) child);
                addLaneFlowNodes((Process) baseElt, (Lane) child);
            } else if (child instanceof Artifact) {
                ((Process) baseElt).getArtifacts().add((Artifact) child);
            } else {
                _logger.error("Don't know what to do of " + child);
            }
        }
    } else if (baseElt instanceof SubProcess) {
        for (BaseElement child : childElements) {
            if (child instanceof FlowElement) {
                ((SubProcess) baseElt).getFlowElements().add((FlowElement) child);
            } else if (child instanceof Artifact) {
                ((SubProcess) baseElt).getArtifacts().add((Artifact) child);
            } else {
                _logger.error("Subprocess - don't know what to do of " + child);
            }
        }
    } else if (baseElt instanceof Message) {
    // we do not support base-element messages from the json. They are created dynamically for events that use them.
    } else if (baseElt instanceof Lane) {
        for (BaseElement child : childElements) {
            if (child instanceof FlowNode) {
                ((Lane) baseElt).getFlowNodeRefs().add((FlowNode) child);
            } else // }
            if (child instanceof Artifact) {
                _artifacts.add((Artifact) child);
            } else {
                _logger.error("Don't know what to do of " + childElements);
            }
        }
        _lanes.add((Lane) baseElt);
    } else {
        if (!childElements.isEmpty()) {
            _logger.error("Don't know what to do of " + childElements + " with " + baseElt);
        }
    }
    return baseElt;
}
Also used : ServiceTask(org.eclipse.bpmn2.ServiceTask) ReceiveTask(org.eclipse.bpmn2.ReceiveTask) SendTask(org.eclipse.bpmn2.SendTask) GlobalTask(org.eclipse.bpmn2.GlobalTask) BusinessRuleTask(org.eclipse.bpmn2.BusinessRuleTask) Task(org.eclipse.bpmn2.Task) ScriptTask(org.eclipse.bpmn2.ScriptTask) UserTask(org.eclipse.bpmn2.UserTask) Message(org.eclipse.bpmn2.Message) SequenceFlow(org.eclipse.bpmn2.SequenceFlow) ArrayList(java.util.ArrayList) ItemDefinition(org.eclipse.bpmn2.ItemDefinition) AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) SubProcess(org.eclipse.bpmn2.SubProcess) Process(org.eclipse.bpmn2.Process) CallActivity(org.eclipse.bpmn2.CallActivity) EAttributeImpl(org.eclipse.emf.ecore.impl.EAttributeImpl) ExclusiveGateway(org.eclipse.bpmn2.ExclusiveGateway) Gateway(org.eclipse.bpmn2.Gateway) InclusiveGateway(org.eclipse.bpmn2.InclusiveGateway) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) List(java.util.List) JsonToken(com.fasterxml.jackson.core.JsonToken) SimpleFeatureMapEntry(org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry) TextAnnotation(org.eclipse.bpmn2.TextAnnotation) Property(org.eclipse.bpmn2.Property) AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) SubProcess(org.eclipse.bpmn2.SubProcess) Bounds(org.eclipse.dd.dc.Bounds) Definitions(org.eclipse.bpmn2.Definitions) Lane(org.eclipse.bpmn2.Lane) FlowElementsContainer(org.eclipse.bpmn2.FlowElementsContainer) Point(org.eclipse.dd.dc.Point) Artifact(org.eclipse.bpmn2.Artifact) BaseElement(org.eclipse.bpmn2.BaseElement) DataObject(org.eclipse.bpmn2.DataObject) RootElement(org.eclipse.bpmn2.RootElement) FlowElement(org.eclipse.bpmn2.FlowElement) StartEvent(org.eclipse.bpmn2.StartEvent) Event(org.eclipse.bpmn2.Event) CatchEvent(org.eclipse.bpmn2.CatchEvent) BoundaryEvent(org.eclipse.bpmn2.BoundaryEvent) ThrowEvent(org.eclipse.bpmn2.ThrowEvent) EndEvent(org.eclipse.bpmn2.EndEvent) EObject(org.eclipse.emf.ecore.EObject) DataObject(org.eclipse.bpmn2.DataObject) ExtendedMetaData(org.eclipse.emf.ecore.util.ExtendedMetaData) FlowNode(org.eclipse.bpmn2.FlowNode)

Example 13 with Task

use of org.eclipse.bpmn2.Task in project kie-wb-common by kiegroup.

the class Bpmn2JsonUnmarshaller method revisitDataObjects.

public void revisitDataObjects(Definitions def) {
    List<RootElement> rootElements = def.getRootElements();
    List<ItemDefinition> itemDefinitionsToAddUnfiltered = new ArrayList<ItemDefinition>();
    List<ItemDefinition> itemDefinitionsToAddFiltered = new ArrayList<ItemDefinition>();
    for (RootElement root : rootElements) {
        if (root instanceof Process) {
            Process process = (Process) root;
            List<FlowElement> flowElements = process.getFlowElements();
            for (FlowElement fe : flowElements) {
                if (fe instanceof DataObject) {
                    DataObject da = (DataObject) fe;
                    ItemDefinition itemdef = Bpmn2Factory.eINSTANCE.createItemDefinition();
                    itemdef.setId("_" + da.getId() + "Item");
                    Iterator<FeatureMap.Entry> iter = da.getAnyAttribute().iterator();
                    while (iter.hasNext()) {
                        FeatureMap.Entry entry = iter.next();
                        if (entry.getEStructuralFeature().getName().equals("datype")) {
                            String typeValue = (String) entry.getValue();
                            if (typeValue != null && !typeValue.equals("None")) {
                                itemdef.setStructureRef((String) entry.getValue());
                            }
                        }
                    }
                    da.setItemSubjectRef(itemdef);
                    itemDefinitionsToAddUnfiltered.add(itemdef);
                }
            }
        }
    }
    for (ItemDefinition itemDef : itemDefinitionsToAddUnfiltered) {
        boolean foundItemDef = false;
        for (RootElement ele : rootElements) {
            if (ele instanceof ItemDefinition) {
                ItemDefinition idef = (ItemDefinition) ele;
                if (idef.getId().equals(itemDef.getId())) {
                    foundItemDef = true;
                    break;
                }
            }
        }
        if (!foundItemDef) {
            itemDefinitionsToAddFiltered.add(itemDef);
        }
    }
    for (ItemDefinition itemDefFil : itemDefinitionsToAddFiltered) {
        def.getRootElements().add(itemDefFil);
    }
    for (RootElement root : rootElements) {
        if (root instanceof Process) {
            Process process = (Process) root;
            List<Artifact> artifactElements = process.getArtifacts();
            for (Artifact af : artifactElements) {
                if (af instanceof Association) {
                    Association as = (Association) af;
                    if (as.getSourceRef() != null && as.getSourceRef() instanceof DataObject && as.getTargetRef() != null && (as.getTargetRef() instanceof Task || as.getTargetRef() instanceof ThrowEvent)) {
                        DataObject da = (DataObject) as.getSourceRef();
                        if (as.getTargetRef() instanceof Task) {
                            Task task = (Task) as.getTargetRef();
                            if (task.getIoSpecification() == null) {
                                InputOutputSpecification iospec = Bpmn2Factory.eINSTANCE.createInputOutputSpecification();
                                task.setIoSpecification(iospec);
                            }
                            if (task.getIoSpecification().getInputSets() == null || task.getIoSpecification().getInputSets().size() < 1) {
                                InputSet inset = Bpmn2Factory.eINSTANCE.createInputSet();
                                task.getIoSpecification().getInputSets().add(inset);
                            }
                            InputSet inSet = task.getIoSpecification().getInputSets().get(0);
                            boolean foundDataInput = false;
                            for (DataInput dataInput : inSet.getDataInputRefs()) {
                                if (dataInput.getId().equals(task.getId() + "_" + da.getId() + "InputX")) {
                                    foundDataInput = true;
                                }
                            }
                            if (!foundDataInput) {
                                DataInput d = Bpmn2Factory.eINSTANCE.createDataInput();
                                d.setId(task.getId() + "_" + da.getId() + "InputX");
                                d.setName(da.getId() + "InputX");
                                task.getIoSpecification().getDataInputs().add(d);
                                task.getIoSpecification().getInputSets().get(0).getDataInputRefs().add(d);
                                DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
                                dia.setTargetRef(d);
                                dia.getSourceRef().add(da);
                                task.getDataInputAssociations().add(dia);
                            }
                        } else if (as.getTargetRef() instanceof ThrowEvent) {
                            ThrowEvent te = (ThrowEvent) as.getTargetRef();
                            // update throw event data input and add data input association
                            boolean foundDataInput = false;
                            List<DataInput> dataInputs = te.getDataInputs();
                            for (DataInput din : dataInputs) {
                                if (din.getId().equals(te.getId() + "_" + da.getId() + "InputX")) {
                                    foundDataInput = true;
                                }
                            }
                            if (!foundDataInput) {
                                DataInput datain = Bpmn2Factory.eINSTANCE.createDataInput();
                                datain.setId(te.getId() + "_" + da.getId() + "InputX");
                                datain.setName(da.getId() + "InputX");
                                te.getDataInputs().add(datain);
                                if (te.getInputSet() == null) {
                                    InputSet inset = Bpmn2Factory.eINSTANCE.createInputSet();
                                    te.setInputSet(inset);
                                }
                                te.getInputSet().getDataInputRefs().add(datain);
                                DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
                                dia.setTargetRef(datain);
                                dia.getSourceRef().add(da);
                                te.getDataInputAssociation().add(dia);
                            }
                        }
                    }
                    if (as.getTargetRef() != null && as.getTargetRef() instanceof DataObject && as.getSourceRef() != null && (as.getSourceRef() instanceof Task || as.getSourceRef() instanceof CatchEvent)) {
                        DataObject da = (DataObject) as.getTargetRef();
                        if (as.getSourceRef() instanceof Task) {
                            Task task = (Task) as.getSourceRef();
                            if (task.getIoSpecification() == null) {
                                InputOutputSpecification iospec = Bpmn2Factory.eINSTANCE.createInputOutputSpecification();
                                task.setIoSpecification(iospec);
                            }
                            if (task.getIoSpecification().getOutputSets() == null || task.getIoSpecification().getOutputSets().size() < 1) {
                                OutputSet outSet = Bpmn2Factory.eINSTANCE.createOutputSet();
                                task.getIoSpecification().getOutputSets().add(outSet);
                            }
                            boolean foundDataOutput = false;
                            OutputSet outSet = task.getIoSpecification().getOutputSets().get(0);
                            for (DataOutput dataOut : outSet.getDataOutputRefs()) {
                                if (dataOut.getId().equals(task.getId() + "_" + da.getId() + "OutputX")) {
                                    foundDataOutput = true;
                                }
                            }
                            if (!foundDataOutput) {
                                DataOutput d = Bpmn2Factory.eINSTANCE.createDataOutput();
                                d.setId(task.getId() + "_" + da.getId() + "OutputX");
                                d.setName(da.getId() + "OutputX");
                                task.getIoSpecification().getDataOutputs().add(d);
                                task.getIoSpecification().getOutputSets().get(0).getDataOutputRefs().add(d);
                                DataOutputAssociation doa = Bpmn2Factory.eINSTANCE.createDataOutputAssociation();
                                doa.getSourceRef().add(d);
                                doa.setTargetRef(da);
                                task.getDataOutputAssociations().add(doa);
                            }
                        } else if (as.getSourceRef() instanceof CatchEvent) {
                            CatchEvent ce = (CatchEvent) as.getSourceRef();
                            // update catch event data output and add data output association
                            boolean foundDataOutput = false;
                            List<DataOutput> dataOutputs = ce.getDataOutputs();
                            for (DataOutput dout : dataOutputs) {
                                if (dout.getId().equals(ce.getId() + "_" + da.getId() + "OutputX")) {
                                    foundDataOutput = true;
                                }
                            }
                            if (!foundDataOutput) {
                                DataOutput dataout = Bpmn2Factory.eINSTANCE.createDataOutput();
                                dataout.setId(ce.getId() + "_" + da.getId() + "OutputX");
                                dataout.setName(da.getId() + "OutputX");
                                ce.getDataOutputs().add(dataout);
                                if (ce.getOutputSet() == null) {
                                    OutputSet outset = Bpmn2Factory.eINSTANCE.createOutputSet();
                                    ce.setOutputSet(outset);
                                }
                                ce.getOutputSet().getDataOutputRefs().add(dataout);
                                DataOutputAssociation dia = Bpmn2Factory.eINSTANCE.createDataOutputAssociation();
                                dia.setTargetRef(da);
                                dia.getSourceRef().add(dataout);
                                ce.getDataOutputAssociation().add(dia);
                            }
                        }
                    }
                    if (as.getSourceRef() != null && as.getSourceRef() instanceof DataObject && as.getTargetRef() != null && (as.getTargetRef() instanceof SequenceFlow)) {
                        SequenceFlow sf = (SequenceFlow) as.getTargetRef();
                        if (sf.getSourceRef() != null && sf.getSourceRef() instanceof Activity && sf.getTargetRef() != null && sf.getTargetRef() instanceof Activity) {
                            Activity sourceElement = (Activity) sf.getSourceRef();
                            Activity targetElement = (Activity) sf.getTargetRef();
                            DataObject da = (DataObject) as.getSourceRef();
                            if (targetElement.getIoSpecification() == null) {
                                InputOutputSpecification iospec = Bpmn2Factory.eINSTANCE.createInputOutputSpecification();
                                targetElement.setIoSpecification(iospec);
                            }
                            if (targetElement.getIoSpecification().getInputSets() == null || targetElement.getIoSpecification().getInputSets().size() < 1) {
                                InputSet inset = Bpmn2Factory.eINSTANCE.createInputSet();
                                targetElement.getIoSpecification().getInputSets().add(inset);
                            }
                            InputSet inSet = targetElement.getIoSpecification().getInputSets().get(0);
                            boolean foundDataInput = false;
                            for (DataInput dataInput : inSet.getDataInputRefs()) {
                                if (dataInput.getId().equals(targetElement.getId() + "_" + da.getId() + "InputX")) {
                                    foundDataInput = true;
                                }
                            }
                            if (!foundDataInput) {
                                DataInput d = Bpmn2Factory.eINSTANCE.createDataInput();
                                d.setId(targetElement.getId() + "_" + da.getId() + "InputX");
                                d.setName(da.getId() + "InputX");
                                targetElement.getIoSpecification().getDataInputs().add(d);
                                targetElement.getIoSpecification().getInputSets().get(0).getDataInputRefs().add(d);
                                DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
                                dia.setTargetRef(d);
                                dia.getSourceRef().add(da);
                                targetElement.getDataInputAssociations().add(dia);
                            }
                            if (sourceElement.getIoSpecification() == null) {
                                InputOutputSpecification iospec = Bpmn2Factory.eINSTANCE.createInputOutputSpecification();
                                sourceElement.setIoSpecification(iospec);
                            }
                            if (sourceElement.getIoSpecification().getOutputSets() == null || sourceElement.getIoSpecification().getOutputSets().size() < 1) {
                                OutputSet outSet = Bpmn2Factory.eINSTANCE.createOutputSet();
                                sourceElement.getIoSpecification().getOutputSets().add(outSet);
                            }
                            boolean foundDataOutput = false;
                            OutputSet outSet = sourceElement.getIoSpecification().getOutputSets().get(0);
                            for (DataOutput dataOut : outSet.getDataOutputRefs()) {
                                if (dataOut.getId().equals(sourceElement.getId() + "_" + da.getId() + "OutputX")) {
                                    foundDataOutput = true;
                                }
                            }
                            if (!foundDataOutput) {
                                DataOutput d = Bpmn2Factory.eINSTANCE.createDataOutput();
                                d.setId(sourceElement.getId() + "_" + da.getId() + "OutputX");
                                d.setName(da.getId() + "OutputX");
                                sourceElement.getIoSpecification().getDataOutputs().add(d);
                                sourceElement.getIoSpecification().getOutputSets().get(0).getDataOutputRefs().add(d);
                                DataOutputAssociation doa = Bpmn2Factory.eINSTANCE.createDataOutputAssociation();
                                doa.getSourceRef().add(d);
                                doa.setTargetRef(da);
                                sourceElement.getDataOutputAssociations().add(doa);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : DataOutput(org.eclipse.bpmn2.DataOutput) ServiceTask(org.eclipse.bpmn2.ServiceTask) ReceiveTask(org.eclipse.bpmn2.ReceiveTask) SendTask(org.eclipse.bpmn2.SendTask) GlobalTask(org.eclipse.bpmn2.GlobalTask) BusinessRuleTask(org.eclipse.bpmn2.BusinessRuleTask) Task(org.eclipse.bpmn2.Task) ScriptTask(org.eclipse.bpmn2.ScriptTask) UserTask(org.eclipse.bpmn2.UserTask) SequenceFlow(org.eclipse.bpmn2.SequenceFlow) ItemDefinition(org.eclipse.bpmn2.ItemDefinition) ArrayList(java.util.ArrayList) Activity(org.eclipse.bpmn2.Activity) CallActivity(org.eclipse.bpmn2.CallActivity) AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) SubProcess(org.eclipse.bpmn2.SubProcess) Process(org.eclipse.bpmn2.Process) CatchEvent(org.eclipse.bpmn2.CatchEvent) Entry(java.util.Map.Entry) SimpleFeatureMapEntry(org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry) Association(org.eclipse.bpmn2.Association) DataOutputAssociation(org.eclipse.bpmn2.DataOutputAssociation) DataInputAssociation(org.eclipse.bpmn2.DataInputAssociation) ArrayList(java.util.ArrayList) List(java.util.List) DataOutputAssociation(org.eclipse.bpmn2.DataOutputAssociation) ThrowEvent(org.eclipse.bpmn2.ThrowEvent) OutputSet(org.eclipse.bpmn2.OutputSet) InputOutputSpecification(org.eclipse.bpmn2.InputOutputSpecification) Artifact(org.eclipse.bpmn2.Artifact) FeatureMap(org.eclipse.emf.ecore.util.FeatureMap) InputSet(org.eclipse.bpmn2.InputSet) DataInput(org.eclipse.bpmn2.DataInput) RootElement(org.eclipse.bpmn2.RootElement) DataObject(org.eclipse.bpmn2.DataObject) FlowElement(org.eclipse.bpmn2.FlowElement) DataInputAssociation(org.eclipse.bpmn2.DataInputAssociation)

Example 14 with Task

use of org.eclipse.bpmn2.Task in project kie-wb-common by kiegroup.

the class Bpmn2JsonUnmarshaller method setUserTaskInfo.

private void setUserTaskInfo(FlowElementsContainer container) {
    List<FlowElement> flowElements = container.getFlowElements();
    for (FlowElement fe : flowElements) {
        // Set name and metaData "elementname" to "Task_n" if empty
        if (fe instanceof UserTask) {
            UserTask task = (UserTask) fe;
            String name = task.getName();
            if (name == null || name.length() == 0) {
                LastUserTaskID++;
                String newName = DEFAULT_USERTASK_NAME_PREFIX + LastUserTaskID;
                task.setName(newName);
                if (task.getExtensionValues() != null && task.getExtensionValues().size() > 0) {
                    for (ExtensionAttributeValue extattrval : task.getExtensionValues()) {
                        FeatureMap extensionElements = extattrval.getValue();
                        List<MetaDataType> metadataExtensions = (List<MetaDataType>) extensionElements.get(DroolsPackage.Literals.DOCUMENT_ROOT__META_DATA, true);
                        for (MetaDataType eleMetadata : metadataExtensions) {
                            if (eleMetadata.getName() != null && eleMetadata.getName().equals("elementname")) {
                                eleMetadata.setMetaValue(wrapInCDATABlock(newName));
                            }
                        }
                    }
                }
            }
        }
        if (fe instanceof FlowElementsContainer) {
            setUserTaskInfo((FlowElementsContainer) fe);
        }
    }
}
Also used : FeatureMap(org.eclipse.emf.ecore.util.FeatureMap) MetaDataType(org.jboss.drools.MetaDataType) FlowElement(org.eclipse.bpmn2.FlowElement) UserTask(org.eclipse.bpmn2.UserTask) FlowElementsContainer(org.eclipse.bpmn2.FlowElementsContainer) ArrayList(java.util.ArrayList) List(java.util.List) ExtensionAttributeValue(org.eclipse.bpmn2.ExtensionAttributeValue)

Example 15 with Task

use of org.eclipse.bpmn2.Task in project kie-wb-common by kiegroup.

the class Bpmn2JsonUnmarshaller method applyTaskProperties.

protected void applyTaskProperties(Task task, Map<String, String> properties, String preProcessingData) {
    if (properties.get("name") != null) {
        task.setName(StringEscapeUtils.escapeXml(properties.get("name")).replaceAll("\\r\\n|\\r|\\n", " "));
    } else {
        task.setName("");
    }
    // add unescaped and untouched name value as extension element as well
    Utils.setMetaDataExtensionValue(task, "elementname", wrapInCDATABlock(properties.get("name").replaceAll("\\\\n", "\n")));
    DataInput taskNameDataInput = null;
    if (properties.get("taskname") != null && properties.get("taskname").length() > 0) {
        if (isCustomElement(properties.get("tasktype"), preProcessingData)) {
            // add kiegroup-specific attribute "taskName"
            ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
            EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "taskName", false, false);
            SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("taskname").replaceAll("&", "").replaceAll(" ", ""));
            task.getAnyAttribute().add(extensionEntry);
        }
        // map the taskName to iospecification
        taskNameDataInput = Bpmn2Factory.eINSTANCE.createDataInput();
        taskNameDataInput.setId(task.getId() + "_TaskNameInputX");
        taskNameDataInput.setName("TaskName");
        // Make the DataInput a String
        ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
        EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "dtype", false, false);
        SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, "String");
        taskNameDataInput.getAnyAttribute().add(extensionEntry);
        if (task.getIoSpecification() == null) {
            InputOutputSpecification iospec = Bpmn2Factory.eINSTANCE.createInputOutputSpecification();
            task.setIoSpecification(iospec);
        }
        task.getIoSpecification().getDataInputs().add(taskNameDataInput);
        // taskName also needs to be in dataInputAssociation
        DataInputAssociation taskNameDataInputAssociation = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
        taskNameDataInputAssociation.setTargetRef(taskNameDataInput);
        Assignment taskNameAssignment = Bpmn2Factory.eINSTANCE.createAssignment();
        FormalExpression fromExp = Bpmn2Factory.eINSTANCE.createFormalExpression();
        fromExp.setBody(properties.get("taskname").replaceAll("&", "").replaceAll(" ", ""));
        taskNameAssignment.setFrom(fromExp);
        FormalExpression toExp = Bpmn2Factory.eINSTANCE.createFormalExpression();
        toExp.setBody(task.getId() + "_TaskNameInputX");
        taskNameAssignment.setTo(toExp);
        taskNameDataInputAssociation.getAssignment().add(taskNameAssignment);
        task.getDataInputAssociations().add(taskNameDataInputAssociation);
    }
    // process lanes
    if (properties.get("lanes") != null && properties.get("lanes").length() > 0) {
        ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
        EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "lanes", false, false);
        SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("lanes"));
        task.getAnyAttribute().add(extensionEntry);
    }
    // isAsync metadata
    if (properties.get("isasync") != null && properties.get("isasync").length() > 0 && properties.get("isasync").equals("true")) {
        Utils.setMetaDataExtensionValue(task, "customAsync", wrapInCDATABlock(properties.get("isasync")));
    }
    // autostart metadata
    if (properties.get("customautostart") != null && properties.get("customautostart").length() > 0 && properties.get("customautostart").equals("true")) {
        Utils.setMetaDataExtensionValue(task, "customAutoStart", wrapInCDATABlock(properties.get("customautostart")));
    }
    parseAssignmentsInfo(properties);
    // process data input set
    Map<String, DataInput> alreadyProcessedInputs = new HashMap<String, DataInput>();
    alreadyProcessedInputs.put("TaskName", taskNameDataInput);
    applyDataInputProperties(task, properties, alreadyProcessedInputs);
    for (DataInput processedInput : alreadyProcessedInputs.values()) {
        if (processedInput != null) {
            task.getIoSpecification().getInputSets().get(0).getDataInputRefs().add(processedInput);
        }
    }
    // process data output set
    applyDataOutputProperties(task, properties);
    // process assignments
    if (properties.get("assignments") != null && properties.get("assignments").length() > 0) {
        String[] allAssignments = properties.get("assignments").split(",\\s*");
        for (String assignment : allAssignments) {
            if (assignment.contains("=")) {
                String[] assignmentParts = assignment.split("=\\s*");
                String fromPart = assignmentParts[0];
                if (fromPart.startsWith("[din]")) {
                    fromPart = fromPart.substring(5, fromPart.length());
                }
                DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
                boolean foundTaskName = false;
                if (task.getIoSpecification() != null && task.getIoSpecification().getDataOutputs() != null) {
                    List<DataInput> dataInputs = task.getIoSpecification().getDataInputs();
                    for (DataInput di : dataInputs) {
                        if (di.getId().equals(task.getId() + "_" + fromPart + (fromPart.endsWith("InputX") ? "" : "InputX"))) {
                            dia.setTargetRef(di);
                            if (di.getName().equals("TaskName")) {
                                foundTaskName = true;
                                break;
                            }
                        }
                    }
                }
                // if we are dealing with TaskName and none has been defined, add it
                if (fromPart.equals("TaskName") && !foundTaskName) {
                    DataInput assignmentTaskNameDataInput = Bpmn2Factory.eINSTANCE.createDataInput();
                    assignmentTaskNameDataInput.setId(task.getId() + "_TaskNameInputX");
                    assignmentTaskNameDataInput.setName("TaskName");
                    if (task.getIoSpecification() == null) {
                        InputOutputSpecification iospec = Bpmn2Factory.eINSTANCE.createInputOutputSpecification();
                        task.setIoSpecification(iospec);
                    }
                    task.getIoSpecification().getDataInputs().add(assignmentTaskNameDataInput);
                    dia.setTargetRef(assignmentTaskNameDataInput);
                    InputSet inset = task.getIoSpecification().getInputSets().get(0);
                    inset.getDataInputRefs().add(assignmentTaskNameDataInput);
                }
                Assignment a = Bpmn2Factory.eINSTANCE.createAssignment();
                FormalExpression fromExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
                if (assignmentParts.length > 1) {
                    String replacer = decodeAssociationValue(assignmentParts[1]);
                    fromExpression.setBody(wrapInCDATABlock(replacer));
                } else {
                    // for custom workitem properties check individually for values
                    if (properties.get(fromPart.toLowerCase()) != null && properties.get(fromPart.toLowerCase()).length() > 0) {
                        fromExpression.setBody(properties.get(fromPart.toLowerCase()));
                    } else {
                        fromExpression.setBody("");
                    }
                }
                FormalExpression toExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
                toExpression.setBody(dia.getTargetRef().getId());
                a.setFrom(fromExpression);
                a.setTo(toExpression);
                dia.getAssignment().add(a);
                task.getDataInputAssociations().add(dia);
            // } else if(assignment.contains("<->")) {
            // String[] assignmentParts = assignment.split( "<->\\s*" );
            // DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
            // DataOutputAssociation doa = Bpmn2Factory.eINSTANCE.createDataOutputAssociation();
            // 
            // ItemAwareElement ie = Bpmn2Factory.eINSTANCE.createItemAwareElement();
            // ie.setId(assignmentParts[0]);
            // dia.getSourceRef().add(ie);
            // doa.setTargetRef(ie);
            // 
            // List<DataInput> dataInputs = task.getIoSpecification().getDataInputs();
            // for(DataInput di : dataInputs) {
            // if(di.getId().equals(task.getId() + "_" + assignmentParts[1] + (assignmentParts[1].endsWith("InputX") ? "" : "InputX"))) {
            // dia.setTargetRef(di);
            // break;
            // }
            // }
            // List<DataOutput> dataOutputs = task.getIoSpecification().getDataOutputs();
            // for(DataOutput dout : dataOutputs) {
            // if(dout.getId().equals(task.getId() + "_" + assignmentParts[1] + (assignmentParts[1].endsWith("OutputX") ? "" : "OutputX"))) {
            // doa.getSourceRef().add(dout);
            // break;
            // }
            // }
            // task.getDataInputAssociations().add(dia);
            // task.getDataOutputAssociations().add(doa);
            } else if (assignment.contains("->")) {
                String[] assignmentParts = assignment.split("->\\s*");
                String fromPart = assignmentParts[0];
                boolean isDataInput = false;
                boolean isDataOutput = false;
                if (fromPart.startsWith("[din]")) {
                    fromPart = fromPart.substring(5, fromPart.length());
                    isDataInput = true;
                }
                if (fromPart.startsWith("[dout]")) {
                    fromPart = fromPart.substring(6, fromPart.length());
                    isDataOutput = true;
                }
                List<DataOutput> dataOutputs = task.getIoSpecification().getDataOutputs();
                if (isDataOutput) {
                    DataOutputAssociation doa = Bpmn2Factory.eINSTANCE.createDataOutputAssociation();
                    for (DataOutput dout : dataOutputs) {
                        if (dout.getId().equals(task.getId() + "_" + fromPart + (fromPart.endsWith("OutputX") ? "" : "OutputX"))) {
                            doa.getSourceRef().add(dout);
                            break;
                        }
                    }
                    ItemAwareElement ie = Bpmn2Factory.eINSTANCE.createItemAwareElement();
                    ie.setId(assignmentParts[1]);
                    doa.setTargetRef(ie);
                    task.getDataOutputAssociations().add(doa);
                } else if (isDataInput) {
                    DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
                    // association from process var to dataInput var
                    ItemAwareElement ie = Bpmn2Factory.eINSTANCE.createItemAwareElement();
                    ie.setId(fromPart);
                    dia.getSourceRef().add(ie);
                    List<DataInput> dataInputs = task.getIoSpecification().getDataInputs();
                    for (DataInput di : dataInputs) {
                        if (di.getId().equals(task.getId() + "_" + assignmentParts[1] + (assignmentParts[1].endsWith("InputX") ? "" : "InputX"))) {
                            dia.setTargetRef(di);
                            break;
                        }
                    }
                    task.getDataInputAssociations().add(dia);
                }
            } else {
            // TODO throw exception here?
            }
        }
        // check if multiple taskname datainput associations exist and remove them
        List<DataInputAssociation> dataInputAssociations = task.getDataInputAssociations();
        boolean haveTaskNameInput = false;
        for (Iterator<DataInputAssociation> itr = dataInputAssociations.iterator(); itr.hasNext(); ) {
            DataInputAssociation da = itr.next();
            if (da.getAssignment() != null && da.getAssignment().size() > 0) {
                Assignment a = da.getAssignment().get(0);
                if (((FormalExpression) a.getTo()).getBody().equals(task.getId() + "_TaskNameInputX")) {
                    if (!haveTaskNameInput) {
                        haveTaskNameInput = true;
                    } else {
                        itr.remove();
                    }
                }
            }
        }
    }
    // process on-entry and on-exit actions as custom elements
    applyOnEntryActions(task, properties);
    applyOnExitActions(task, properties);
    // multi instance
    if (properties.get("multipleinstance") != null && properties.get("multipleinstance").length() > 0 && properties.get("multipleinstance").equals("true")) {
        // will be revisited at end
        ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
        EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "mitask", false, false);
        StringBuffer buff = new StringBuffer();
        buff.append((properties.get("multipleinstancecollectioninput") != null && properties.get("multipleinstancecollectioninput").length() > 0) ? properties.get("multipleinstancecollectioninput") : " ");
        buff.append("@");
        buff.append((properties.get("multipleinstancecollectionoutput") != null && properties.get("multipleinstancecollectionoutput").length() > 0) ? properties.get("multipleinstancecollectionoutput") : " ");
        buff.append("@");
        buff.append((properties.get("multipleinstancedatainput") != null && properties.get("multipleinstancedatainput").length() > 0) ? properties.get("multipleinstancedatainput") : " ");
        buff.append("@");
        buff.append((properties.get("multipleinstancedataoutput") != null && properties.get("multipleinstancedataoutput").length() > 0) ? properties.get("multipleinstancedataoutput") : " ");
        buff.append("@");
        buff.append((properties.get("multipleinstancecompletioncondition") != null && properties.get("multipleinstancecompletioncondition").length() > 0) ? properties.get("multipleinstancecompletioncondition") : " ");
        SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, buff.toString());
        task.getAnyAttribute().add(extensionEntry);
    }
    // simulation
    if (properties.get("distributiontype") != null && properties.get("distributiontype").length() > 0) {
        TimeParameters timeParams = BpsimFactory.eINSTANCE.createTimeParameters();
        Parameter processingTimeParam = BpsimFactory.eINSTANCE.createParameter();
        if (properties.get("distributiontype").equals("normal")) {
            NormalDistributionType normalDistributionType = BpsimFactory.eINSTANCE.createNormalDistributionType();
            normalDistributionType.setStandardDeviation(Double.valueOf(properties.get("standarddeviation")));
            normalDistributionType.setMean(Double.valueOf(properties.get("mean")));
            processingTimeParam.getParameterValue().add(normalDistributionType);
        } else if (properties.get("distributiontype").equals("uniform")) {
            UniformDistributionType uniformDistributionType = BpsimFactory.eINSTANCE.createUniformDistributionType();
            uniformDistributionType.setMax(Double.valueOf(properties.get("max")));
            uniformDistributionType.setMin(Double.valueOf(properties.get("min")));
            processingTimeParam.getParameterValue().add(uniformDistributionType);
        // random distribution not supported in bpsim 1.0
        // } else if(properties.get("distributiontype").equals("random")) {
        // RandomDistributionType randomDistributionType = BpsimFactory.eINSTANCE.createRandomDistributionType();
        // randomDistributionType.setMax(Double.valueOf(properties.get("max")));
        // randomDistributionType.setMin(Double.valueOf(properties.get("min")));
        // processingTimeParam.getParameterValue().add(randomDistributionType);
        } else if (properties.get("distributiontype").equals("poisson")) {
            PoissonDistributionType poissonDistributionType = BpsimFactory.eINSTANCE.createPoissonDistributionType();
            poissonDistributionType.setMean(Double.valueOf(properties.get("mean")));
            processingTimeParam.getParameterValue().add(poissonDistributionType);
        }
        // }
        if (properties.get("waittime") != null) {
            Parameter waittimeParam = BpsimFactory.eINSTANCE.createParameter();
            FloatingParameterType waittimeParamValue = BpsimFactory.eINSTANCE.createFloatingParameterType();
            DecimalFormat twoDForm = new DecimalFormat("#.##");
            waittimeParamValue.setValue(Double.valueOf(twoDForm.format(Double.valueOf(properties.get("waittime")))));
            waittimeParam.getParameterValue().add(waittimeParamValue);
            timeParams.setWaitTime(waittimeParam);
        }
        timeParams.setProcessingTime(processingTimeParam);
        if (_simulationElementParameters.containsKey(task.getId())) {
            _simulationElementParameters.get(task.getId()).add(timeParams);
        } else {
            List<EObject> values = new ArrayList<EObject>();
            values.add(timeParams);
            _simulationElementParameters.put(task.getId(), values);
        }
    }
    CostParameters costParameters = BpsimFactory.eINSTANCE.createCostParameters();
    if (properties.get("unitcost") != null && properties.get("unitcost").length() > 0) {
        Parameter unitcostParam = BpsimFactory.eINSTANCE.createParameter();
        FloatingParameterType unitCostParameterValue = BpsimFactory.eINSTANCE.createFloatingParameterType();
        unitCostParameterValue.setValue(new Double(properties.get("unitcost")));
        unitcostParam.getParameterValue().add(unitCostParameterValue);
        costParameters.setUnitCost(unitcostParam);
    }
    // }
    if (_simulationElementParameters.containsKey(task.getId())) {
        _simulationElementParameters.get(task.getId()).add(costParameters);
    } else {
        List<EObject> values = new ArrayList<EObject>();
        values.add(costParameters);
        _simulationElementParameters.put(task.getId(), values);
    }
}
Also used : DataOutput(org.eclipse.bpmn2.DataOutput) CostParameters(bpsim.CostParameters) HashMap(java.util.HashMap) NormalDistributionType(bpsim.NormalDistributionType) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) Assignment(org.eclipse.bpmn2.Assignment) EAttributeImpl(org.eclipse.emf.ecore.impl.EAttributeImpl) EObject(org.eclipse.emf.ecore.EObject) SimpleFeatureMapEntry(org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry) ArrayList(java.util.ArrayList) List(java.util.List) DataOutputAssociation(org.eclipse.bpmn2.DataOutputAssociation) UniformDistributionType(bpsim.UniformDistributionType) InputOutputSpecification(org.eclipse.bpmn2.InputOutputSpecification) ItemAwareElement(org.eclipse.bpmn2.ItemAwareElement) FormalExpression(org.eclipse.bpmn2.FormalExpression) FloatingParameterType(bpsim.FloatingParameterType) DataInput(org.eclipse.bpmn2.DataInput) InputSet(org.eclipse.bpmn2.InputSet) PoissonDistributionType(bpsim.PoissonDistributionType) Parameter(bpsim.Parameter) ExtendedMetaData(org.eclipse.emf.ecore.util.ExtendedMetaData) TimeParameters(bpsim.TimeParameters) DataInputAssociation(org.eclipse.bpmn2.DataInputAssociation)

Aggregations

FlowElement (org.eclipse.bpmn2.FlowElement)9 RootElement (org.eclipse.bpmn2.RootElement)9 ArrayList (java.util.ArrayList)7 DataInputAssociation (org.eclipse.bpmn2.DataInputAssociation)7 ItemAwareElement (org.eclipse.bpmn2.ItemAwareElement)7 DataInput (org.eclipse.bpmn2.DataInput)6 DataOutputAssociation (org.eclipse.bpmn2.DataOutputAssociation)6 InputSet (org.eclipse.bpmn2.InputSet)6 List (java.util.List)5 BusinessRuleTask (org.eclipse.bpmn2.BusinessRuleTask)5 DataOutput (org.eclipse.bpmn2.DataOutput)5 FormalExpression (org.eclipse.bpmn2.FormalExpression)5 InputOutputSpecification (org.eclipse.bpmn2.InputOutputSpecification)5 ReceiveTask (org.eclipse.bpmn2.ReceiveTask)5 ScriptTask (org.eclipse.bpmn2.ScriptTask)5 SendTask (org.eclipse.bpmn2.SendTask)5 ServiceTask (org.eclipse.bpmn2.ServiceTask)5 UserTask (org.eclipse.bpmn2.UserTask)5 AdHocSubProcess (org.eclipse.bpmn2.AdHocSubProcess)4 GlobalTask (org.eclipse.bpmn2.GlobalTask)4