Search in sources :

Example 1 with BPMNPlane

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

the class Bpmn2JsonMarshaller method findOutgoingAssociation.

protected Association findOutgoingAssociation(BPMNPlane plane, BaseElement baseElement) {
    Association result = _diagramAssociations.get(baseElement.getId());
    if (result != null) {
        return result;
    }
    if (!(plane.getBpmnElement() instanceof Process)) {
        throw new IllegalArgumentException("Don't know how to get associations from a non-Process Diagram");
    }
    Process process = (Process) plane.getBpmnElement();
    for (Artifact artifact : process.getArtifacts()) {
        if (artifact instanceof Association) {
            Association association = (Association) artifact;
            if (association.getSourceRef() == baseElement) {
                _diagramAssociations.put(baseElement.getId(), association);
                return association;
            }
        }
    }
    return null;
}
Also used : Association(org.eclipse.bpmn2.Association) DataOutputAssociation(org.eclipse.bpmn2.DataOutputAssociation) DataInputAssociation(org.eclipse.bpmn2.DataInputAssociation) AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) Process(org.eclipse.bpmn2.Process) SubProcess(org.eclipse.bpmn2.SubProcess) Artifact(org.eclipse.bpmn2.Artifact)

Example 2 with BPMNPlane

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

the class Bpmn2JsonMarshaller method marshallDataObject.

protected void marshallDataObject(DataObject dataObject, BPMNPlane plane, JsonGenerator generator, float xOffset, float yOffset, Map<String, Object> flowElementProperties) throws JsonGenerationException, IOException {
    Map<String, Object> properties = new LinkedHashMap<String, Object>(flowElementProperties);
    putDocumentationProperty(dataObject, properties);
    if (dataObject.getName() != null && dataObject.getName().length() > 0) {
        properties.put(NAME, StringEscapeUtils.unescapeXml(dataObject.getName()));
    } else {
        // we need a name, use id instead
        properties.put(NAME, dataObject.getId());
    }
    // overwrite name if elementname extension element is present
    String elementName = Utils.getMetaDataValue(dataObject.getExtensionValues(), "elementname");
    if (elementName != null) {
        properties.put(NAME, elementName);
    }
    if (dataObject.getItemSubjectRef().getStructureRef() != null && dataObject.getItemSubjectRef().getStructureRef().length() > 0) {
        if (defaultTypesList.contains(dataObject.getItemSubjectRef().getStructureRef())) {
            properties.put(STANDARDTYPE, dataObject.getItemSubjectRef().getStructureRef());
        } else {
            properties.put(CUSTOMTYPE, dataObject.getItemSubjectRef().getStructureRef());
        }
    }
    Association outgoingAssociaton = findOutgoingAssociation(plane, dataObject);
    Association incomingAssociation = null;
    Process process = (Process) plane.getBpmnElement();
    for (Artifact artifact : process.getArtifacts()) {
        if (artifact instanceof Association) {
            Association association = (Association) artifact;
            if (association.getTargetRef() == dataObject) {
                incomingAssociation = association;
            }
        }
    }
    if (outgoingAssociaton != null && incomingAssociation == null) {
        properties.put(INPUT_OUTPUT, "Input");
    }
    if (outgoingAssociaton == null && incomingAssociation != null) {
        properties.put(INPUT_OUTPUT, "Output");
    }
    marshallProperties(properties, generator);
    generator.writeObjectFieldStart("stencil");
    generator.writeObjectField("id", "DataObject");
    generator.writeEndObject();
    generator.writeArrayFieldStart("childShapes");
    generator.writeEndArray();
    generator.writeArrayFieldStart("outgoing");
    List<Association> associations = findOutgoingAssociations(plane, dataObject);
    if (associations != null) {
        for (Association as : associations) {
            generator.writeStartObject();
            generator.writeObjectField("resourceId", as.getId());
            generator.writeEndObject();
        }
    }
    generator.writeEndArray();
    Bounds bounds = ((BPMNShape) findDiagramElement(plane, dataObject)).getBounds();
    generator.writeObjectFieldStart("bounds");
    generator.writeObjectFieldStart("lowerRight");
    generator.writeObjectField("x", bounds.getX() + bounds.getWidth() - xOffset);
    generator.writeObjectField("y", bounds.getY() + bounds.getHeight() - yOffset);
    generator.writeEndObject();
    generator.writeObjectFieldStart("upperLeft");
    generator.writeObjectField("x", bounds.getX() - xOffset);
    generator.writeObjectField("y", bounds.getY() - yOffset);
    generator.writeEndObject();
    generator.writeEndObject();
}
Also used : Association(org.eclipse.bpmn2.Association) DataOutputAssociation(org.eclipse.bpmn2.DataOutputAssociation) DataInputAssociation(org.eclipse.bpmn2.DataInputAssociation) Bounds(org.eclipse.dd.dc.Bounds) DataObject(org.eclipse.bpmn2.DataObject) AdHocSubProcess(org.eclipse.bpmn2.AdHocSubProcess) Process(org.eclipse.bpmn2.Process) SubProcess(org.eclipse.bpmn2.SubProcess) BPMNShape(org.eclipse.bpmn2.di.BPMNShape) Artifact(org.eclipse.bpmn2.Artifact) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with BPMNPlane

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

the class Bpmn2JsonMarshaller method marshallGroup.

protected void marshallGroup(Group group, BPMNPlane plane, JsonGenerator generator, float xOffset, float yOffset, String preProcessingData, Definitions def) throws JsonGenerationException, IOException {
    Map<String, Object> properties = new LinkedHashMap<>();
    if (group.getCategoryValueRef() != null && group.getCategoryValueRef().getValue() != null) {
        properties.put("name", StringEscapeUtils.unescapeXml(group.getCategoryValueRef().getValue()));
    }
    putDocumentationProperty(group, properties);
    marshallProperties(properties, generator);
    generator.writeObjectFieldStart("stencil");
    generator.writeObjectField("id", "Group");
    generator.writeEndObject();
    generator.writeArrayFieldStart("childShapes");
    generator.writeEndArray();
    generator.writeArrayFieldStart("outgoing");
    if (findOutgoingAssociation(plane, group) != null) {
        generator.writeStartObject();
        generator.writeObjectField("resourceId", findOutgoingAssociation(plane, group).getId());
        generator.writeEndObject();
    }
    generator.writeEndArray();
    Bounds bounds = ((BPMNShape) findDiagramElement(plane, group)).getBounds();
    generator.writeObjectFieldStart("bounds");
    generator.writeObjectFieldStart("lowerRight");
    generator.writeObjectField("x", bounds.getX() + bounds.getWidth() - xOffset);
    generator.writeObjectField("y", bounds.getY() + bounds.getHeight() - yOffset);
    generator.writeEndObject();
    generator.writeObjectFieldStart("upperLeft");
    generator.writeObjectField("x", bounds.getX() - xOffset);
    generator.writeObjectField("y", bounds.getY() - yOffset);
    generator.writeEndObject();
    generator.writeEndObject();
}
Also used : Bounds(org.eclipse.dd.dc.Bounds) DataObject(org.eclipse.bpmn2.DataObject) BPMNShape(org.eclipse.bpmn2.di.BPMNShape) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with BPMNPlane

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

the class Bpmn2JsonMarshaller method marshallProcess.

protected void marshallProcess(Process process, Definitions def, JsonGenerator generator, String preProcessingData) throws JsonGenerationException, IOException {
    BPMNPlane plane = null;
    for (BPMNDiagram d : def.getDiagrams()) {
        if (d != null) {
            BPMNPlane p = d.getPlane();
            if (p != null) {
                if (p.getBpmnElement() == process) {
                    plane = p;
                    break;
                }
            }
        }
    }
    if (plane == null) {
        throw new IllegalArgumentException("Could not find BPMNDI information");
    }
    generator.writeArrayFieldStart("childShapes");
    List<String> laneFlowElementsIds = new ArrayList<String>();
    for (LaneSet laneSet : process.getLaneSets()) {
        for (Lane lane : laneSet.getLanes()) {
            // we only want to marshall lanes if we have the bpmndi info for them!
            if (findDiagramElement(plane, lane) != null) {
                laneFlowElementsIds.addAll(marshallLanes(lane, plane, generator, 0, 0, preProcessingData, def));
            }
        }
    }
    for (FlowElement flowElement : process.getFlowElements()) {
        if (!laneFlowElementsIds.contains(flowElement.getId())) {
            marshallFlowElement(flowElement, plane, generator, 0, 0, preProcessingData, def);
        }
    }
    for (Artifact artifact : process.getArtifacts()) {
        marshallArtifact(artifact, plane, generator, 0, 0, preProcessingData, def);
    }
    generator.writeEndArray();
}
Also used : BPMNDiagram(org.eclipse.bpmn2.di.BPMNDiagram) FlowElement(org.eclipse.bpmn2.FlowElement) ArrayList(java.util.ArrayList) Lane(org.eclipse.bpmn2.Lane) LaneSet(org.eclipse.bpmn2.LaneSet) BPMNPlane(org.eclipse.bpmn2.di.BPMNPlane) Artifact(org.eclipse.bpmn2.Artifact)

Example 5 with BPMNPlane

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

the class Bpmn2JsonMarshaller method marshallTask.

protected void marshallTask(Task task, BPMNPlane plane, JsonGenerator generator, float xOffset, float yOffset, String preProcessingData, Definitions def, Map<String, Object> flowElementProperties) throws JsonGenerationException, IOException {
    Map<String, Object> properties = new LinkedHashMap<String, Object>(flowElementProperties);
    String taskType = "None";
    if (task instanceof BusinessRuleTask) {
        taskType = "Business Rule";
        Iterator<FeatureMap.Entry> iter = task.getAnyAttribute().iterator();
        while (iter.hasNext()) {
            FeatureMap.Entry entry = iter.next();
            if (entry.getEStructuralFeature().getName().equals("ruleFlowGroup")) {
                properties.put("ruleflowgroup", entry.getValue());
            }
        }
    } else if (task instanceof ScriptTask) {
        setScriptProperties((ScriptTask) task, properties);
        taskType = "Script";
    } else if (task instanceof ServiceTask) {
        taskType = "Service";
        ServiceTask serviceTask = (ServiceTask) task;
        if (serviceTask.getOperationRef() != null && serviceTask.getImplementation() != null) {
            properties.put("serviceimplementation", serviceTask.getImplementation());
            properties.put("serviceoperation", serviceTask.getOperationRef().getName() == null ? serviceTask.getOperationRef().getImplementationRef() : serviceTask.getOperationRef().getName());
            if (def != null) {
                List<RootElement> roots = def.getRootElements();
                for (RootElement root : roots) {
                    if (root instanceof Interface) {
                        Interface inter = (Interface) root;
                        List<Operation> interOperations = inter.getOperations();
                        for (Operation interOper : interOperations) {
                            if (interOper.getId().equals(serviceTask.getOperationRef().getId())) {
                                properties.put("serviceinterface", inter.getName() == null ? inter.getImplementationRef() : inter.getName());
                            }
                        }
                    }
                }
            }
        }
    } else if (task instanceof ManualTask) {
        taskType = "Manual";
    } else if (task instanceof UserTask) {
        taskType = "User";
        // get the user task actors
        List<ResourceRole> roles = task.getResources();
        StringBuilder sb = new StringBuilder();
        for (ResourceRole role : roles) {
            if (role instanceof PotentialOwner) {
                FormalExpression fe = (FormalExpression) ((PotentialOwner) role).getResourceAssignmentExpression().getExpression();
                if (fe.getBody() != null && fe.getBody().length() > 0) {
                    sb.append(fe.getBody());
                    sb.append(",");
                }
            }
        }
        if (sb.length() > 0) {
            sb.setLength(sb.length() - 1);
        }
        properties.put("actors", sb.toString());
    } else if (task instanceof SendTask) {
        taskType = "Send";
        SendTask st = (SendTask) task;
        if (st.getMessageRef() != null) {
            properties.put("messageref", st.getMessageRef().getId());
        }
    } else if (task instanceof ReceiveTask) {
        taskType = "Receive";
        ReceiveTask rt = (ReceiveTask) task;
        if (rt.getMessageRef() != null) {
            properties.put("messageref", rt.getMessageRef().getId());
        }
    }
    // custom async
    String customAsyncMetaData = Utils.getMetaDataValue(task.getExtensionValues(), "customAsync");
    String customAsync = (customAsyncMetaData != null && customAsyncMetaData.length() > 0) ? customAsyncMetaData : "false";
    properties.put("isasync", customAsync);
    // custom autostart
    String customAutoStartMetaData = Utils.getMetaDataValue(task.getExtensionValues(), "customAutoStart");
    String customAutoStart = (customAutoStartMetaData != null && customAutoStartMetaData.length() > 0) ? customAutoStartMetaData : "false";
    properties.put("customautostart", customAutoStart);
    // backwards compatibility with jbds editor
    boolean foundTaskName = false;
    if (task instanceof UserTask && task.getIoSpecification() != null && task.getIoSpecification().getDataInputs() != null) {
        List<DataInput> taskDataInputs = task.getIoSpecification().getDataInputs();
        for (DataInput din : taskDataInputs) {
            if (din.getName() != null && din.getName().equals("TaskName")) {
                List<DataInputAssociation> taskDataInputAssociations = task.getDataInputAssociations();
                for (DataInputAssociation dia : taskDataInputAssociations) {
                    if (dia.getTargetRef() != null && dia.getTargetRef().getId().equals(din.getId()) && dia.getAssignment() != null && !dia.getAssignment().isEmpty() && dia.getAssignment().get(0).getFrom() != null) {
                        properties.put("taskname", ((FormalExpression) dia.getAssignment().get(0).getFrom()).getBody());
                        foundTaskName = true;
                    }
                }
                break;
            }
        }
    }
    if (!foundTaskName) {
        // try the drools specific attribute set on the task
        Iterator<FeatureMap.Entry> iter = task.getAnyAttribute().iterator();
        while (iter.hasNext()) {
            FeatureMap.Entry entry = iter.next();
            if (entry.getEStructuralFeature().getName().equals("taskName")) {
                String tname = (String) entry.getValue();
                if (tname != null && tname.length() > 0) {
                    properties.put("taskname", tname);
                }
            }
        }
    }
    // check if we are dealing with a custom task
    boolean isCustomElement = isCustomElement((String) properties.get("taskname"), preProcessingData);
    if (isCustomElement) {
        properties.put("tasktype", properties.get("taskname"));
    } else {
        properties.put("tasktype", taskType);
    }
    // multiple instance
    if (task.getLoopCharacteristics() != null) {
        properties.put("multipleinstance", "true");
        MultiInstanceLoopCharacteristics taskmi = (MultiInstanceLoopCharacteristics) task.getLoopCharacteristics();
        if (taskmi.getLoopDataInputRef() != null) {
            ItemAwareElement iedatainput = taskmi.getLoopDataInputRef();
            List<DataInputAssociation> taskInputAssociations = task.getDataInputAssociations();
            for (DataInputAssociation dia : taskInputAssociations) {
                if (dia.getTargetRef().equals(iedatainput)) {
                    properties.put("multipleinstancecollectioninput", dia.getSourceRef().get(0).getId());
                    break;
                }
            }
        }
        if (taskmi.getLoopDataOutputRef() != null) {
            ItemAwareElement iedataoutput = taskmi.getLoopDataOutputRef();
            List<DataOutputAssociation> taskOutputAssociations = task.getDataOutputAssociations();
            for (DataOutputAssociation dout : taskOutputAssociations) {
                if (dout.getSourceRef().get(0).equals(iedataoutput)) {
                    properties.put("multipleinstancecollectionoutput", dout.getTargetRef().getId());
                    break;
                }
            }
        }
        if (taskmi.getInputDataItem() != null && taskmi.getInputDataItem().getItemSubjectRef() != null) {
            List<DataInput> taskDataInputs = task.getIoSpecification().getDataInputs();
            for (DataInput din : taskDataInputs) {
                if (din != null && din.getItemSubjectRef() != null && taskmi.getInputDataItem() != null && taskmi.getInputDataItem().getItemSubjectRef() != null) {
                    if (din.getItemSubjectRef().getId().equals(taskmi.getInputDataItem().getItemSubjectRef().getId())) {
                        properties.put("multipleinstancedatainput", din.getName());
                    }
                }
            }
        }
        if (taskmi.getOutputDataItem() != null && taskmi.getOutputDataItem().getItemSubjectRef() != null) {
            List<DataOutput> taskDataOutputs = task.getIoSpecification().getDataOutputs();
            for (DataOutput dout : taskDataOutputs) {
                if (dout != null && dout.getItemSubjectRef() != null && taskmi.getOutputDataItem() != null && taskmi.getOutputDataItem().getItemSubjectRef() != null) {
                    if (dout.getItemSubjectRef().getId().equals(taskmi.getOutputDataItem().getItemSubjectRef().getId())) {
                        properties.put("multipleinstancedataoutput", dout.getName());
                    }
                }
            }
        }
        if (taskmi.getCompletionCondition() != null) {
            if (taskmi.getCompletionCondition() instanceof FormalExpression) {
                properties.put("multipleinstancecompletioncondition", ((FormalExpression) taskmi.getCompletionCondition()).getBody());
            }
        }
    } else {
        properties.put("multipleinstance", "false");
    }
    // data inputs
    List<String> disallowedInputs = new ArrayList<String>();
    disallowedInputs.add("miinputCollection");
    if ((task instanceof UserTask) || isCustomElement) {
        disallowedInputs.add("TaskName");
    }
    String datainputset = marshallDataInputSet(task, properties, disallowedInputs);
    DataInput groupDataInput = null;
    DataInput skippableDataInput = null;
    DataInput commentDataInput = null;
    DataInput descriptionDataInput = null;
    DataInput contentDataInput = null;
    DataInput priorityDataInput = null;
    DataInput localeDataInput = null;
    DataInput createdByDataInput = null;
    DataInput notCompletedReassignInput = null;
    DataInput notStartedReassignInput = null;
    DataInput notCompletedNotificationInput = null;
    DataInput notStartedNotificationInput = null;
    if (task.getIoSpecification() != null) {
        List<InputSet> inputSetList = task.getIoSpecification().getInputSets();
        for (InputSet inset : inputSetList) {
            List<DataInput> dataInputList = inset.getDataInputRefs();
            for (DataInput dataIn : dataInputList) {
                // dont add "TaskName" as that is added manually
                String dataInName = dataIn.getName();
                if (task instanceof UserTask && dataInName != null) {
                    if (dataInName.equals("GroupId")) {
                        groupDataInput = dataIn;
                    } else if (dataInName.equals("Skippable")) {
                        skippableDataInput = dataIn;
                    } else if (dataInName.equals("Comment")) {
                        commentDataInput = dataIn;
                    } else if (dataInName.equals("Description")) {
                        descriptionDataInput = dataIn;
                    } else if (dataInName.equals("Content")) {
                        contentDataInput = dataIn;
                    } else if (dataInName.equals("Priority")) {
                        priorityDataInput = dataIn;
                    } else if (dataInName.equals("Locale")) {
                        localeDataInput = dataIn;
                    } else if (dataInName.equals("CreatedBy")) {
                        createdByDataInput = dataIn;
                    } else if (dataInName.equals("NotCompletedReassign")) {
                        notCompletedReassignInput = dataIn;
                    } else if (dataInName.equals("NotStartedReassign")) {
                        notStartedReassignInput = dataIn;
                    } else if (dataInName.equals("NotCompletedNotify")) {
                        notCompletedNotificationInput = dataIn;
                    } else if (dataInName.equals("NotStartedNotify")) {
                        notStartedNotificationInput = dataIn;
                    }
                }
            }
        }
    }
    // data outputs
    String dataoutputset = marshallDataOutputSet(task, properties, Arrays.asList("mioutputCollection"));
    // assignments
    StringBuilder associationBuff = new StringBuilder();
    List<DataInputAssociation> inputAssociations = task.getDataInputAssociations();
    List<DataOutputAssociation> outputAssociations = task.getDataOutputAssociations();
    List<String> uniDirectionalAssociations = new ArrayList<String>();
    // List<String> biDirectionalAssociations = new ArrayList<String>();
    for (DataInputAssociation datain : inputAssociations) {
        boolean proceed = true;
        if (task.getLoopCharacteristics() != null) {
            MultiInstanceLoopCharacteristics taskMultiLoop = (MultiInstanceLoopCharacteristics) task.getLoopCharacteristics();
            // dont include associations that include mi loop data inputs
            if (taskMultiLoop.getInputDataItem() != null && taskMultiLoop.getInputDataItem().getId() != null) {
                if (datain.getSourceRef() != null && datain.getSourceRef().size() > 0 && datain.getSourceRef().get(0).getId().equals(taskMultiLoop.getInputDataItem().getId())) {
                    proceed = false;
                }
            }
            // dont include associations that include loopDataInputRef as target
            if (taskMultiLoop.getLoopDataInputRef() != null) {
                if (datain.getTargetRef().equals(taskMultiLoop.getLoopDataInputRef())) {
                    proceed = false;
                }
            }
        }
        if (proceed) {
            String lhsAssociation = "";
            if (datain.getSourceRef() != null && datain.getSourceRef().size() > 0) {
                if (datain.getTransformation() != null && datain.getTransformation().getBody() != null) {
                    lhsAssociation = datain.getTransformation().getBody();
                } else {
                    lhsAssociation = datain.getSourceRef().get(0).getId();
                }
            }
            String rhsAssociation = "";
            if (datain.getTargetRef() != null) {
                rhsAssociation = ((DataInput) datain.getTargetRef()).getName();
            }
            // boolean isBiDirectional = false;
            boolean isAssignment = false;
            if (datain.getAssignment() != null && datain.getAssignment().size() > 0) {
                isAssignment = true;
            }
            // }
            if (isAssignment) {
                // only know how to deal with formal expressions
                if (datain.getAssignment().get(0).getFrom() instanceof FormalExpression) {
                    String associationValue = ((FormalExpression) datain.getAssignment().get(0).getFrom()).getBody();
                    if (associationValue == null) {
                        associationValue = "";
                    }
                    // don't include properties that have their independent input editors
                    if (isCustomElement((String) properties.get("taskname"), preProcessingData)) {
                        if (!(rhsAssociation.equals("TaskName"))) {
                            String replacer = encodeAssociationValue(associationValue);
                            associationBuff.append("[din]" + rhsAssociation).append("=").append(replacer);
                            associationBuff.append(",");
                            properties.put(rhsAssociation.toLowerCase(), associationValue);
                        }
                    } else {
                        if (!(task instanceof UserTask) || !(rhsAssociation.equals("GroupId") || rhsAssociation.equals("Skippable") || rhsAssociation.equals("Comment") || rhsAssociation.equals("Description") || rhsAssociation.equals("Priority") || rhsAssociation.equals("Content") || rhsAssociation.equals("TaskName") || rhsAssociation.equals("Locale") || rhsAssociation.equals("CreatedBy") || rhsAssociation.equals("NotCompletedReassign") || rhsAssociation.equals("NotStartedReassign") || rhsAssociation.equals("NotCompletedNotify") || rhsAssociation.equals("NotStartedNotify"))) {
                            String replacer = encodeAssociationValue(associationValue);
                            associationBuff.append("[din]" + rhsAssociation).append("=").append(replacer);
                            associationBuff.append(",");
                            properties.put(rhsAssociation.toLowerCase(), associationValue);
                        }
                    }
                    if (rhsAssociation.equalsIgnoreCase("TaskName")) {
                        properties.put("taskname", associationValue);
                    }
                    if (task instanceof UserTask && datain.getAssignment().get(0).getTo() != null && ((FormalExpression) datain.getAssignment().get(0).getTo()).getBody() != null && datain.getAssignment().get(0).getFrom() != null) {
                        String toBody = ((FormalExpression) datain.getAssignment().get(0).getTo()).getBody();
                        String fromBody = ((FormalExpression) datain.getAssignment().get(0).getFrom()).getBody();
                        if (toBody != null) {
                            if (groupDataInput != null && toBody.equals(groupDataInput.getId())) {
                                properties.put("groupid", fromBody == null ? "" : fromBody);
                            } else if (skippableDataInput != null && toBody.equals(skippableDataInput.getId())) {
                                properties.put("skippable", fromBody);
                            } else if (commentDataInput != null && toBody.equals(commentDataInput.getId())) {
                                properties.put("subject", fromBody);
                            } else if (descriptionDataInput != null && toBody.equals(descriptionDataInput.getId())) {
                                properties.put("description", fromBody);
                            } else if (priorityDataInput != null && toBody.equals(priorityDataInput.getId())) {
                                properties.put("priority", fromBody == null ? "" : fromBody);
                            } else if (contentDataInput != null && toBody.equals(contentDataInput.getId())) {
                                properties.put("content", fromBody);
                            } else if (localeDataInput != null && toBody.equals(localeDataInput.getId())) {
                                properties.put("locale", fromBody);
                            } else if (createdByDataInput != null && toBody.equals(createdByDataInput.getId())) {
                                properties.put("createdby", fromBody);
                            } else if (notCompletedReassignInput != null && toBody.equals(notCompletedReassignInput.getId())) {
                                properties.put("tmpreassignmentnotcompleted", updateReassignmentAndNotificationInput(fromBody, "not-completed"));
                            } else if (notStartedReassignInput != null && toBody.equals(notStartedReassignInput.getId())) {
                                properties.put("tmpreassignmentnotstarted", updateReassignmentAndNotificationInput(fromBody, "not-started"));
                            } else if (notCompletedNotificationInput != null && toBody.equals(notCompletedNotificationInput.getId())) {
                                properties.put("tmpnotificationnotcompleted", updateReassignmentAndNotificationInput(fromBody, "not-completed"));
                            } else if (notStartedNotificationInput != null && toBody.equals(notStartedNotificationInput.getId())) {
                                properties.put("tmpnotificationnotstarted", updateReassignmentAndNotificationInput(fromBody, "not-started"));
                            }
                        }
                    }
                }
            } else // else if(isBiDirectional) {
            // associationBuff.append(lhsAssociation).append("<->").append(rhsAssociation);
            // associationBuff.append(",");
            // biDirectionalAssociations.add(lhsAssociation + "," + rhsAssociation);
            // }
            {
                if (lhsAssociation != null && lhsAssociation.length() > 0) {
                    associationBuff.append("[din]" + lhsAssociation).append("->").append(rhsAssociation);
                    associationBuff.append(",");
                    uniDirectionalAssociations.add(lhsAssociation + "," + rhsAssociation);
                }
                uniDirectionalAssociations.add(lhsAssociation + "," + rhsAssociation);
            // if(contentDataInput != null) {
            // if(rhsAssociation.equals(contentDataInput.getName())) {
            // properties.put("content", lhsAssociation);
            // }
            // }
            }
        }
    }
    if (properties.get("tmpreassignmentnotcompleted") != null && ((String) properties.get("tmpreassignmentnotcompleted")).length() > 0 && properties.get("tmpreassignmentnotstarted") != null && ((String) properties.get("tmpreassignmentnotstarted")).length() > 0) {
        properties.put("reassignment", properties.get("tmpreassignmentnotcompleted") + "^" + properties.get("tmpreassignmentnotstarted"));
    } else if (properties.get("tmpreassignmentnotcompleted") != null && ((String) properties.get("tmpreassignmentnotcompleted")).length() > 0) {
        properties.put("reassignment", properties.get("tmpreassignmentnotcompleted"));
    } else if (properties.get("tmpreassignmentnotstarted") != null && ((String) properties.get("tmpreassignmentnotstarted")).length() > 0) {
        properties.put("reassignment", properties.get("tmpreassignmentnotstarted"));
    }
    if (properties.get("tmpnotificationnotcompleted") != null && ((String) properties.get("tmpnotificationnotcompleted")).length() > 0 && properties.get("tmpnotificationnotstarted") != null && ((String) properties.get("tmpnotificationnotstarted")).length() > 0) {
        properties.put("notifications", properties.get("tmpnotificationnotcompleted") + "^" + properties.get("tmpnotificationnotstarted"));
    } else if (properties.get("tmpnotificationnotcompleted") != null && ((String) properties.get("tmpnotificationnotcompleted")).length() > 0) {
        properties.put("notifications", properties.get("tmpnotificationnotcompleted"));
    } else if (properties.get("tmpnotificationnotstarted") != null && ((String) properties.get("tmpnotificationnotstarted")).length() > 0) {
        properties.put("notifications", properties.get("tmpnotificationnotstarted"));
    }
    for (DataOutputAssociation dataout : outputAssociations) {
        boolean proceed = true;
        if (task.getLoopCharacteristics() != null) {
            MultiInstanceLoopCharacteristics taskMultiLoop = (MultiInstanceLoopCharacteristics) task.getLoopCharacteristics();
            // dont include associations that include mi loop data outputs
            if (taskMultiLoop.getOutputDataItem() != null && taskMultiLoop.getOutputDataItem().getId() != null) {
                if (dataout.getTargetRef().getId().equals(taskMultiLoop.getOutputDataItem().getId())) {
                    proceed = false;
                }
            }
            // dont include associations that include loopDataOutputRef as source
            if (taskMultiLoop.getLoopDataOutputRef() != null) {
                if (dataout.getSourceRef().get(0).equals(taskMultiLoop.getLoopDataOutputRef())) {
                    proceed = false;
                }
            }
        }
        if (proceed) {
            if (dataout.getSourceRef().size() > 0) {
                String lhsAssociation = ((DataOutput) dataout.getSourceRef().get(0)).getName();
                String rhsAssociation = dataout.getTargetRef().getId();
                boolean wasBiDirectional = false;
                // }
                if (dataout.getTransformation() != null && dataout.getTransformation().getBody() != null) {
                    rhsAssociation = encodeAssociationValue(dataout.getTransformation().getBody());
                }
                if (!wasBiDirectional) {
                    if (lhsAssociation != null && lhsAssociation.length() > 0) {
                        associationBuff.append("[dout]" + lhsAssociation).append("->").append(rhsAssociation);
                        associationBuff.append(",");
                    }
                }
            }
        }
    }
    String assignmentString = associationBuff.toString();
    if (assignmentString.endsWith(",")) {
        assignmentString = assignmentString.substring(0, assignmentString.length() - 1);
    }
    properties.put("assignments", assignmentString);
    setAssignmentsInfoProperty(null, datainputset, null, dataoutputset, assignmentString, properties);
    // on-entry and on-exit actions
    ScriptTypeListValue onEntryActions = getOnEntryActions(task.getExtensionValues());
    ScriptTypeListValue onExitActions = getOnExitActions(task.getExtensionValues());
    if (!onEntryActions.isEmpty()) {
        properties.put(ONENTRYACTIONS, new ScriptTypeListTypeSerializer().serialize(onEntryActions));
    }
    if (!onExitActions.isEmpty()) {
        properties.put(ONEXITACTIONS, new ScriptTypeListTypeSerializer().serialize(onExitActions));
    }
    // simulation properties
    setSimulationProperties(task.getId(), properties);
    // marshall the node out
    if (isCustomElement((String) properties.get("taskname"), preProcessingData)) {
        marshallNode(task, properties, (String) properties.get("taskname"), plane, generator, xOffset, yOffset);
    } else {
        marshallNode(task, properties, "Task", plane, generator, xOffset, yOffset);
    }
}
Also used : DataOutput(org.eclipse.bpmn2.DataOutput) ServiceTask(org.eclipse.bpmn2.ServiceTask) BusinessRuleTask(org.eclipse.bpmn2.BusinessRuleTask) GlobalBusinessRuleTask(org.eclipse.bpmn2.GlobalBusinessRuleTask) PotentialOwner(org.eclipse.bpmn2.PotentialOwner) ArrayList(java.util.ArrayList) Operation(org.eclipse.bpmn2.Operation) LinkedHashMap(java.util.LinkedHashMap) Entry(java.util.Map.Entry) ManualTask(org.eclipse.bpmn2.ManualTask) GlobalManualTask(org.eclipse.bpmn2.GlobalManualTask) MultiInstanceLoopCharacteristics(org.eclipse.bpmn2.MultiInstanceLoopCharacteristics) DataOutputAssociation(org.eclipse.bpmn2.DataOutputAssociation) ScriptTypeListTypeSerializer(org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.ScriptTypeListTypeSerializer) ReceiveTask(org.eclipse.bpmn2.ReceiveTask) ResourceRole(org.eclipse.bpmn2.ResourceRole) GlobalUserTask(org.eclipse.bpmn2.GlobalUserTask) UserTask(org.eclipse.bpmn2.UserTask) ItemAwareElement(org.eclipse.bpmn2.ItemAwareElement) FormalExpression(org.eclipse.bpmn2.FormalExpression) FeatureMap(org.eclipse.emf.ecore.util.FeatureMap) DataInput(org.eclipse.bpmn2.DataInput) InputSet(org.eclipse.bpmn2.InputSet) GlobalScriptTask(org.eclipse.bpmn2.GlobalScriptTask) ScriptTask(org.eclipse.bpmn2.ScriptTask) RootElement(org.eclipse.bpmn2.RootElement) SendTask(org.eclipse.bpmn2.SendTask) DataObject(org.eclipse.bpmn2.DataObject) Interface(org.eclipse.bpmn2.Interface) DataInputAssociation(org.eclipse.bpmn2.DataInputAssociation) ScriptTypeListValue(org.kie.workbench.common.stunner.bpmn.definition.property.task.ScriptTypeListValue)

Aggregations

Bounds (org.eclipse.dd.dc.Bounds)16 AdHocSubProcess (org.eclipse.bpmn2.AdHocSubProcess)15 SubProcess (org.eclipse.bpmn2.SubProcess)15 ArrayList (java.util.ArrayList)12 BPMNShape (org.eclipse.bpmn2.di.BPMNShape)12 Process (org.eclipse.bpmn2.Process)11 DataObject (org.eclipse.bpmn2.DataObject)10 FlowElement (org.eclipse.bpmn2.FlowElement)9 BPMNEdge (org.eclipse.bpmn2.di.BPMNEdge)9 LinkedHashMap (java.util.LinkedHashMap)8 DataInputAssociation (org.eclipse.bpmn2.DataInputAssociation)8 DataOutputAssociation (org.eclipse.bpmn2.DataOutputAssociation)8 SequenceFlow (org.eclipse.bpmn2.SequenceFlow)8 Point (org.eclipse.dd.dc.Point)8 DiagramElement (org.eclipse.dd.di.DiagramElement)8 Artifact (org.eclipse.bpmn2.Artifact)7 BPMNPlane (org.eclipse.bpmn2.di.BPMNPlane)7 Entry (java.util.Map.Entry)6 FeatureMap (org.eclipse.emf.ecore.util.FeatureMap)6 Association (org.eclipse.bpmn2.Association)5