Search in sources :

Example 1 with PotentialOwner

use of org.eclipse.bpmn2.PotentialOwner 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)

Example 2 with PotentialOwner

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

the class Bpmn2JsonUnmarshaller method applyUserTaskProperties.

protected void applyUserTaskProperties(UserTask task, Map<String, String> properties) {
    setLastUserTaskID(task);
    if (properties.get("actors") != null && properties.get("actors").length() > 0) {
        String[] allActors = properties.get("actors").split(",\\s*");
        for (String actor : allActors) {
            PotentialOwner po = Bpmn2Factory.eINSTANCE.createPotentialOwner();
            ResourceAssignmentExpression rae = Bpmn2Factory.eINSTANCE.createResourceAssignmentExpression();
            FormalExpression fe = Bpmn2Factory.eINSTANCE.createFormalExpression();
            fe.setBody(actor);
            rae.setExpression(fe);
            po.setResourceAssignmentExpression(rae);
            task.getResources().add(po);
        }
    }
    if (properties.get("script_language") != null && properties.get("script_language").length() > 0) {
        String scriptLanguage = getScriptLanguageFormat(properties);
        ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
        EAttributeImpl scriptLanguageElement = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "scriptFormat", false, false);
        SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(scriptLanguageElement, scriptLanguage);
        task.getAnyAttribute().add(extensionEntry);
    }
    if (properties.get("groupid") != null && properties.get("groupid").length() > 0) {
        if (task.getIoSpecification() == null) {
            InputOutputSpecification iospec = Bpmn2Factory.eINSTANCE.createInputOutputSpecification();
            task.setIoSpecification(iospec);
        }
        List<DataInput> dataInputs = task.getIoSpecification().getDataInputs();
        boolean foundGroupIdInput = false;
        DataInput foundInput = null;
        for (DataInput din : dataInputs) {
            if (din.getName().equals("GroupId")) {
                foundGroupIdInput = true;
                foundInput = din;
                break;
            }
        }
        if (!foundGroupIdInput) {
            DataInput d = Bpmn2Factory.eINSTANCE.createDataInput();
            d.setId(task.getId() + "_" + "GroupId" + "InputX");
            d.setName("GroupId");
            task.getIoSpecification().getDataInputs().add(d);
            foundInput = d;
            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(d);
        }
        boolean foundGroupIdAssociation = false;
        List<DataInputAssociation> inputAssociations = task.getDataInputAssociations();
        for (DataInputAssociation da : inputAssociations) {
            if (da.getTargetRef() != null && da.getTargetRef().getId().equals(foundInput.getId())) {
                foundGroupIdAssociation = true;
                ((FormalExpression) da.getAssignment().get(0).getFrom()).setBody(wrapInCDATABlock(properties.get("groupid")));
            }
        }
        if (!foundGroupIdAssociation) {
            DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
            dia.setTargetRef(foundInput);
            Assignment a = Bpmn2Factory.eINSTANCE.createAssignment();
            FormalExpression groupFromExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
            groupFromExpression.setBody(wrapInCDATABlock(properties.get("groupid")));
            FormalExpression groupToExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
            groupToExpression.setBody(foundInput.getId());
            a.setFrom(groupFromExpression);
            a.setTo(groupToExpression);
            dia.getAssignment().add(a);
            task.getDataInputAssociations().add(dia);
        }
    }
    // default to true if not set
    String skippableStr = (properties.get("skippable") == null ? "true" : properties.get("skippable"));
    if (skippableStr.length() > 0) {
        if (task.getIoSpecification() == null) {
            InputOutputSpecification iospec = Bpmn2Factory.eINSTANCE.createInputOutputSpecification();
            task.setIoSpecification(iospec);
        }
        List<DataInput> dataInputs = task.getIoSpecification().getDataInputs();
        boolean foundSkippableInput = false;
        DataInput foundInput = null;
        for (DataInput din : dataInputs) {
            if (din.getName().equals("Skippable")) {
                foundSkippableInput = true;
                foundInput = din;
                break;
            }
        }
        if (!foundSkippableInput) {
            DataInput d = Bpmn2Factory.eINSTANCE.createDataInput();
            d.setId(task.getId() + "_" + "Skippable" + "InputX");
            d.setName("Skippable");
            task.getIoSpecification().getDataInputs().add(d);
            foundInput = d;
            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(d);
        }
        boolean foundSkippableAssociation = false;
        List<DataInputAssociation> inputAssociations = task.getDataInputAssociations();
        for (DataInputAssociation da : inputAssociations) {
            if (da.getTargetRef() != null && da.getTargetRef().getId().equals(foundInput.getId())) {
                foundSkippableAssociation = true;
                ((FormalExpression) da.getAssignment().get(0).getFrom()).setBody(skippableStr);
            }
        }
        if (!foundSkippableAssociation) {
            DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
            dia.setTargetRef(foundInput);
            Assignment a = Bpmn2Factory.eINSTANCE.createAssignment();
            FormalExpression skippableFromExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
            skippableFromExpression.setBody(skippableStr);
            FormalExpression skippableToExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
            skippableToExpression.setBody(foundInput.getId());
            a.setFrom(skippableFromExpression);
            a.setTo(skippableToExpression);
            dia.getAssignment().add(a);
            task.getDataInputAssociations().add(dia);
        }
    }
    if (properties.get("subject") != null && properties.get("subject").length() > 0) {
        if (task.getIoSpecification() == null) {
            InputOutputSpecification iospec = Bpmn2Factory.eINSTANCE.createInputOutputSpecification();
            task.setIoSpecification(iospec);
        }
        List<DataInput> dataInputs = task.getIoSpecification().getDataInputs();
        boolean foundCommentInput = false;
        DataInput foundInput = null;
        for (DataInput din : dataInputs) {
            if (din.getName().equals("Comment")) {
                foundCommentInput = true;
                foundInput = din;
                break;
            }
        }
        if (!foundCommentInput) {
            DataInput d = Bpmn2Factory.eINSTANCE.createDataInput();
            d.setId(task.getId() + "_" + "Comment" + "InputX");
            d.setName("Comment");
            task.getIoSpecification().getDataInputs().add(d);
            foundInput = d;
            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(d);
        }
        boolean foundCommentAssociation = false;
        List<DataInputAssociation> inputAssociations = task.getDataInputAssociations();
        for (DataInputAssociation da : inputAssociations) {
            if (da.getTargetRef() != null && da.getTargetRef().getId().equals(foundInput.getId())) {
                foundCommentAssociation = true;
                ((FormalExpression) da.getAssignment().get(0).getFrom()).setBody(wrapInCDATABlock(properties.get("subject")));
            }
        }
        if (!foundCommentAssociation) {
            DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
            dia.setTargetRef(foundInput);
            Assignment a = Bpmn2Factory.eINSTANCE.createAssignment();
            FormalExpression commentFromExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
            commentFromExpression.setBody(wrapInCDATABlock(properties.get("subject")));
            FormalExpression commentToExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
            commentToExpression.setBody(foundInput.getId());
            a.setFrom(commentFromExpression);
            a.setTo(commentToExpression);
            dia.getAssignment().add(a);
            task.getDataInputAssociations().add(dia);
        }
    }
    if (properties.get("description") != null && properties.get("description").length() > 0) {
        if (task.getIoSpecification() == null) {
            InputOutputSpecification iospec = Bpmn2Factory.eINSTANCE.createInputOutputSpecification();
            task.setIoSpecification(iospec);
        }
        List<DataInput> dataInputs = task.getIoSpecification().getDataInputs();
        boolean foundDescriptionInput = false;
        DataInput foundInput = null;
        for (DataInput din : dataInputs) {
            if (din.getName().equals("Description")) {
                foundDescriptionInput = true;
                foundInput = din;
                break;
            }
        }
        if (!foundDescriptionInput) {
            DataInput d = Bpmn2Factory.eINSTANCE.createDataInput();
            d.setId(task.getId() + "_" + "Description" + "InputX");
            d.setName("Description");
            task.getIoSpecification().getDataInputs().add(d);
            foundInput = d;
            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(d);
        }
        boolean foundDescriptionAssociation = false;
        List<DataInputAssociation> inputAssociations = task.getDataInputAssociations();
        for (DataInputAssociation da : inputAssociations) {
            if (da.getTargetRef() != null && da.getTargetRef().getId().equals(foundInput.getId())) {
                foundDescriptionAssociation = true;
                ((FormalExpression) da.getAssignment().get(0).getFrom()).setBody(wrapInCDATABlock(properties.get("description")));
            }
        }
        if (!foundDescriptionAssociation) {
            DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
            dia.setTargetRef(foundInput);
            Assignment a = Bpmn2Factory.eINSTANCE.createAssignment();
            FormalExpression descriptionFromExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
            descriptionFromExpression.setBody(wrapInCDATABlock(properties.get("description")));
            FormalExpression descriptionToExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
            descriptionToExpression.setBody(foundInput.getId());
            a.setFrom(descriptionFromExpression);
            a.setTo(descriptionToExpression);
            dia.getAssignment().add(a);
            task.getDataInputAssociations().add(dia);
        }
    }
    if (properties.get("priority") != null && properties.get("priority").length() > 0) {
        if (task.getIoSpecification() == null) {
            InputOutputSpecification iospec = Bpmn2Factory.eINSTANCE.createInputOutputSpecification();
            task.setIoSpecification(iospec);
        }
        List<DataInput> dataInputs = task.getIoSpecification().getDataInputs();
        boolean foundPriorityInput = false;
        DataInput foundInput = null;
        for (DataInput din : dataInputs) {
            if (din.getName().equals("Priority")) {
                foundPriorityInput = true;
                foundInput = din;
                break;
            }
        }
        if (!foundPriorityInput) {
            DataInput d = Bpmn2Factory.eINSTANCE.createDataInput();
            d.setId(task.getId() + "_" + "Priority" + "InputX");
            d.setName("Priority");
            task.getIoSpecification().getDataInputs().add(d);
            foundInput = d;
            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(d);
        }
        boolean foundPriorityAssociation = false;
        List<DataInputAssociation> inputAssociations = task.getDataInputAssociations();
        for (DataInputAssociation da : inputAssociations) {
            if (da.getTargetRef() != null && da.getTargetRef().getId().equals(foundInput.getId())) {
                foundPriorityAssociation = true;
                ((FormalExpression) da.getAssignment().get(0).getFrom()).setBody(properties.get("priority"));
            }
        }
        if (!foundPriorityAssociation) {
            DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
            dia.setTargetRef(foundInput);
            Assignment a = Bpmn2Factory.eINSTANCE.createAssignment();
            FormalExpression priorityFromExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
            priorityFromExpression.setBody(properties.get("priority"));
            FormalExpression priorityToExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
            priorityToExpression.setBody(foundInput.getId());
            a.setFrom(priorityFromExpression);
            a.setTo(priorityToExpression);
            dia.getAssignment().add(a);
            task.getDataInputAssociations().add(dia);
        }
    }
    if (properties.get("content") != null && properties.get("content").length() > 0) {
        if (task.getIoSpecification() == null) {
            InputOutputSpecification iospec = Bpmn2Factory.eINSTANCE.createInputOutputSpecification();
            OutputSet outSet = Bpmn2Factory.eINSTANCE.createOutputSet();
            iospec.getOutputSets().add(outSet);
            task.setIoSpecification(iospec);
        }
        List<DataInput> dataInputs = task.getIoSpecification().getDataInputs();
        boolean foundContentInput = false;
        DataInput foundInput = null;
        for (DataInput din : dataInputs) {
            if (din.getName().equals("Content")) {
                foundContentInput = true;
                foundInput = din;
                break;
            }
        }
        if (!foundContentInput) {
            DataInput d = Bpmn2Factory.eINSTANCE.createDataInput();
            d.setId(task.getId() + "_" + "Content" + "InputX");
            d.setName("Content");
            task.getIoSpecification().getDataInputs().add(d);
            foundInput = d;
            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(d);
        }
        boolean foundContentAssociation = false;
        List<DataInputAssociation> inputAssociations = task.getDataInputAssociations();
        for (DataInputAssociation da : inputAssociations) {
            if (da.getTargetRef() != null && da.getTargetRef().getId().equals(foundInput.getId())) {
                foundContentAssociation = true;
                ((FormalExpression) da.getAssignment().get(0).getFrom()).setBody(wrapInCDATABlock(properties.get("content")));
            }
        }
        if (!foundContentAssociation) {
            DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
            dia.setTargetRef(foundInput);
            Assignment a = Bpmn2Factory.eINSTANCE.createAssignment();
            FormalExpression contentFromExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
            contentFromExpression.setBody(wrapInCDATABlock(properties.get("content")));
            FormalExpression contentToExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
            contentToExpression.setBody(foundInput.getId());
            a.setFrom(contentFromExpression);
            a.setTo(contentToExpression);
            dia.getAssignment().add(a);
            task.getDataInputAssociations().add(dia);
        }
    }
    if (properties.get("locale") != null && properties.get("locale").length() > 0) {
        if (task.getIoSpecification() == null) {
            InputOutputSpecification iospec = Bpmn2Factory.eINSTANCE.createInputOutputSpecification();
            task.setIoSpecification(iospec);
        }
        List<DataInput> dataInputs = task.getIoSpecification().getDataInputs();
        boolean foundLocaleInput = false;
        DataInput foundInput = null;
        for (DataInput din : dataInputs) {
            if (din.getName().equals("Locale")) {
                foundLocaleInput = true;
                foundInput = din;
                break;
            }
        }
        if (!foundLocaleInput) {
            DataInput d = Bpmn2Factory.eINSTANCE.createDataInput();
            d.setId(task.getId() + "_" + "Locale" + "InputX");
            d.setName("Locale");
            task.getIoSpecification().getDataInputs().add(d);
            foundInput = d;
            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(d);
        }
        boolean foundLocaleAssociation = false;
        List<DataInputAssociation> inputAssociations = task.getDataInputAssociations();
        for (DataInputAssociation da : inputAssociations) {
            if (da.getTargetRef() != null && da.getTargetRef().getId().equals(foundInput.getId())) {
                foundLocaleAssociation = true;
                ((FormalExpression) da.getAssignment().get(0).getFrom()).setBody(wrapInCDATABlock(properties.get("locale")));
            }
        }
        if (!foundLocaleAssociation) {
            DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
            dia.setTargetRef(foundInput);
            Assignment a = Bpmn2Factory.eINSTANCE.createAssignment();
            FormalExpression localeFromExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
            localeFromExpression.setBody(wrapInCDATABlock(properties.get("locale")));
            FormalExpression localeToExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
            localeToExpression.setBody(foundInput.getId());
            a.setFrom(localeFromExpression);
            a.setTo(localeToExpression);
            dia.getAssignment().add(a);
            task.getDataInputAssociations().add(dia);
        }
    }
    if (properties.get("createdby") != null && properties.get("createdby").length() > 0) {
        if (task.getIoSpecification() == null) {
            InputOutputSpecification iospec = Bpmn2Factory.eINSTANCE.createInputOutputSpecification();
            task.setIoSpecification(iospec);
        }
        List<DataInput> dataInputs = task.getIoSpecification().getDataInputs();
        boolean foundCreatedByInput = false;
        DataInput foundInput = null;
        for (DataInput din : dataInputs) {
            if (din.getName().equals("CreatedBy")) {
                foundCreatedByInput = true;
                foundInput = din;
                break;
            }
        }
        if (!foundCreatedByInput) {
            DataInput d = Bpmn2Factory.eINSTANCE.createDataInput();
            d.setId(task.getId() + "_" + "CreatedBy" + "InputX");
            d.setName("CreatedBy");
            task.getIoSpecification().getDataInputs().add(d);
            foundInput = d;
            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(d);
        }
        boolean foundCreatedByAssociation = false;
        List<DataInputAssociation> inputAssociations = task.getDataInputAssociations();
        for (DataInputAssociation da : inputAssociations) {
            if (da.getTargetRef() != null && da.getTargetRef().getId().equals(foundInput.getId())) {
                foundCreatedByAssociation = true;
                ((FormalExpression) da.getAssignment().get(0).getFrom()).setBody(wrapInCDATABlock(properties.get("createdby")));
            }
        }
        if (!foundCreatedByAssociation) {
            DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
            dia.setTargetRef(foundInput);
            Assignment a = Bpmn2Factory.eINSTANCE.createAssignment();
            FormalExpression createdByFromExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
            createdByFromExpression.setBody(wrapInCDATABlock(properties.get("createdby")));
            FormalExpression createdByToExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
            createdByToExpression.setBody(foundInput.getId());
            a.setFrom(createdByFromExpression);
            a.setTo(createdByToExpression);
            dia.getAssignment().add(a);
            task.getDataInputAssociations().add(dia);
        }
    }
    // reassignments
    if (properties.get("reassignment") != null && properties.get("reassignment").length() > 0) {
        if (task.getIoSpecification() == null) {
            InputOutputSpecification iospec = Bpmn2Factory.eINSTANCE.createInputOutputSpecification();
            task.setIoSpecification(iospec);
        }
        List<DataInput> dataInputs = task.getIoSpecification().getDataInputs();
        boolean foundNotCompletedReassignmentsInput = false;
        boolean foundNotStartedReassignmentsInput = false;
        DataInput foundNotCompletedDataInput = null;
        DataInput foundNotStartedDataInput = null;
        for (DataInput din : dataInputs) {
            if (din.getName().equals("NotCompletedReassign")) {
                foundNotCompletedReassignmentsInput = true;
                foundNotCompletedDataInput = din;
            }
            if (din.getName().equals("NotStartedReassign")) {
                foundNotStartedReassignmentsInput = true;
                foundNotStartedDataInput = din;
            }
        }
        if (!foundNotCompletedReassignmentsInput) {
            DataInput d = Bpmn2Factory.eINSTANCE.createDataInput();
            d.setId(task.getId() + "_" + "NotCompletedReassign" + "InputX");
            d.setName("NotCompletedReassign");
            task.getIoSpecification().getDataInputs().add(d);
            foundNotCompletedDataInput = d;
            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(d);
        }
        if (!foundNotStartedReassignmentsInput) {
            DataInput d = Bpmn2Factory.eINSTANCE.createDataInput();
            d.setId(task.getId() + "_" + "NotStartedReassign" + "InputX");
            d.setName("NotStartedReassign");
            task.getIoSpecification().getDataInputs().add(d);
            foundNotStartedDataInput = d;
            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(d);
        }
        boolean foundNotCompletedReassignmentAssociation = false;
        boolean foundNotStartedReassignmentAssociation = false;
        List<DataInputAssociation> inputAssociations = task.getDataInputAssociations();
        for (DataInputAssociation da : inputAssociations) {
            if (da.getTargetRef() != null && da.getTargetRef().getId().equals(foundNotCompletedDataInput.getId())) {
                foundNotCompletedReassignmentAssociation = true;
                ((FormalExpression) da.getAssignment().get(0).getFrom()).setBody(getReassignmentsAndNotificationsForType(properties.get("reassignment"), "not-completed"));
            }
            if (da.getTargetRef() != null && da.getTargetRef().getId().equals(foundNotStartedDataInput.getId())) {
                foundNotStartedReassignmentAssociation = true;
                ((FormalExpression) da.getAssignment().get(0).getFrom()).setBody(getReassignmentsAndNotificationsForType(properties.get("reassignment"), "not-started"));
            }
        }
        if (!foundNotCompletedReassignmentAssociation) {
            DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
            dia.setTargetRef(foundNotCompletedDataInput);
            Assignment a = Bpmn2Factory.eINSTANCE.createAssignment();
            FormalExpression notCompletedFromExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
            notCompletedFromExpression.setBody(getReassignmentsAndNotificationsForType(properties.get("reassignment"), "not-completed"));
            FormalExpression notCompletedToExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
            notCompletedToExpression.setBody(foundNotCompletedDataInput.getId());
            a.setFrom(notCompletedFromExpression);
            a.setTo(notCompletedToExpression);
            dia.getAssignment().add(a);
            task.getDataInputAssociations().add(dia);
        }
        if (!foundNotStartedReassignmentAssociation) {
            DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
            dia.setTargetRef(foundNotStartedDataInput);
            Assignment a = Bpmn2Factory.eINSTANCE.createAssignment();
            FormalExpression notStartedFromExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
            notStartedFromExpression.setBody(getReassignmentsAndNotificationsForType(properties.get("reassignment"), "not-started"));
            FormalExpression notStartedToExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
            notStartedToExpression.setBody(foundNotStartedDataInput.getId());
            a.setFrom(notStartedFromExpression);
            a.setTo(notStartedToExpression);
            dia.getAssignment().add(a);
            task.getDataInputAssociations().add(dia);
        }
    }
    // start notifications
    if (properties.get("notifications") != null && properties.get("notifications").length() > 0) {
        if (task.getIoSpecification() == null) {
            InputOutputSpecification iospec = Bpmn2Factory.eINSTANCE.createInputOutputSpecification();
            task.setIoSpecification(iospec);
        }
        List<DataInput> dataInputs = task.getIoSpecification().getDataInputs();
        boolean foundNotCompletedNotificationsInput = false;
        boolean foundNotStartedNotificationsInput = false;
        DataInput foundNotCompletedDataInput = null;
        DataInput foundNotStartedDataInput = null;
        for (DataInput din : dataInputs) {
            if (din.getName().equals("NotCompletedNotify")) {
                foundNotCompletedNotificationsInput = true;
                foundNotCompletedDataInput = din;
            }
            if (din.getName().equals("NotStartedNotify")) {
                foundNotStartedNotificationsInput = true;
                foundNotStartedDataInput = din;
            }
        }
        if (!foundNotCompletedNotificationsInput) {
            DataInput d = Bpmn2Factory.eINSTANCE.createDataInput();
            d.setId(task.getId() + "_" + "NotCompletedNotify" + "InputX");
            d.setName("NotCompletedNotify");
            task.getIoSpecification().getDataInputs().add(d);
            foundNotCompletedDataInput = d;
            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(d);
        }
        if (!foundNotStartedNotificationsInput) {
            DataInput d = Bpmn2Factory.eINSTANCE.createDataInput();
            d.setId(task.getId() + "_" + "NotStartedNotify" + "InputX");
            d.setName("NotStartedNotify");
            task.getIoSpecification().getDataInputs().add(d);
            foundNotStartedDataInput = d;
            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(d);
        }
        boolean foundNotCompletedNotificationAssociation = false;
        boolean foundNotStartedNotificationAssociation = false;
        List<DataInputAssociation> inputAssociations = task.getDataInputAssociations();
        for (DataInputAssociation da : inputAssociations) {
            if (da.getTargetRef() != null && da.getTargetRef().getId().equals(foundNotCompletedDataInput.getId())) {
                foundNotCompletedNotificationAssociation = true;
                ((FormalExpression) da.getAssignment().get(0).getFrom()).setBody(getReassignmentsAndNotificationsForType(properties.get("notifications"), "not-completed"));
            }
            if (da.getTargetRef() != null && da.getTargetRef().getId().equals(foundNotStartedDataInput.getId())) {
                foundNotStartedNotificationAssociation = true;
                ((FormalExpression) da.getAssignment().get(0).getFrom()).setBody(getReassignmentsAndNotificationsForType(properties.get("notifications"), "not-started"));
            }
        }
        if (!foundNotCompletedNotificationAssociation) {
            DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
            dia.setTargetRef(foundNotCompletedDataInput);
            Assignment a = Bpmn2Factory.eINSTANCE.createAssignment();
            FormalExpression notCompletedFromExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
            notCompletedFromExpression.setBody(getReassignmentsAndNotificationsForType(properties.get("notifications"), "not-completed"));
            FormalExpression notCompletedToExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
            notCompletedToExpression.setBody(foundNotCompletedDataInput.getId());
            a.setFrom(notCompletedFromExpression);
            a.setTo(notCompletedToExpression);
            dia.getAssignment().add(a);
            task.getDataInputAssociations().add(dia);
        }
        if (!foundNotStartedNotificationAssociation) {
            DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
            dia.setTargetRef(foundNotStartedDataInput);
            Assignment a = Bpmn2Factory.eINSTANCE.createAssignment();
            FormalExpression notStartedFromExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
            notStartedFromExpression.setBody(getReassignmentsAndNotificationsForType(properties.get("notifications"), "not-started"));
            FormalExpression notStartedToExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
            notStartedToExpression.setBody(foundNotStartedDataInput.getId());
            a.setFrom(notStartedFromExpression);
            a.setTo(notStartedToExpression);
            dia.getAssignment().add(a);
            task.getDataInputAssociations().add(dia);
        }
    }
    // revisit data assignments
    if (task.getDataInputAssociations() != null) {
        List<DataInputAssociation> dataInputAssociations = task.getDataInputAssociations();
        List<DataInputAssociation> incompleteAssociations = new ArrayList<DataInputAssociation>();
        for (DataInputAssociation dia : dataInputAssociations) {
            DataInput targetInput = (DataInput) dia.getTargetRef();
            if (targetInput != null && targetInput.getName() != null) {
                if (targetInput.getName().equals("GroupId") && (properties.get("groupid") == null || properties.get("groupid").length() == 0)) {
                    incompleteAssociations.add(dia);
                } else if (targetInput.getName().equalsIgnoreCase("Skippable") && (skippableStr == null || skippableStr.length() == 0)) {
                    incompleteAssociations.add(dia);
                } else if (targetInput.getName().equalsIgnoreCase("Comment") && (properties.get("subject") == null || properties.get("subject").length() == 0)) {
                    incompleteAssociations.add(dia);
                } else if (targetInput.getName().equalsIgnoreCase("Description") && (properties.get("description") == null || properties.get("description").length() == 0)) {
                    incompleteAssociations.add(dia);
                } else if (targetInput.getName().equalsIgnoreCase("Priority") && (properties.get("priority") == null || properties.get("priority").length() == 0)) {
                    incompleteAssociations.add(dia);
                } else if (targetInput.getName().equalsIgnoreCase("Content") && (properties.get("content") == null || properties.get("content").length() == 0)) {
                    incompleteAssociations.add(dia);
                } else if (targetInput.getName().equalsIgnoreCase("Locale") && (properties.get("locale") == null || properties.get("locale").length() == 0)) {
                    incompleteAssociations.add(dia);
                } else if (targetInput.getName().equalsIgnoreCase("CreatedBy") && (properties.get("createdby") == null || properties.get("createdby").length() == 0)) {
                    incompleteAssociations.add(dia);
                } else if (targetInput.getName().equalsIgnoreCase("NotCompletedReassign") && (properties.get("reassignment") == null || properties.get("reassignment").length() == 0)) {
                    incompleteAssociations.add(dia);
                } else if (targetInput.getName().equalsIgnoreCase("NotStartedReassign") && (properties.get("reassignment") == null || properties.get("reassignment").length() == 0)) {
                    incompleteAssociations.add(dia);
                } else if (targetInput.getName().equalsIgnoreCase("NotCompletedNotify") && (properties.get("notifications") == null || properties.get("notifications").length() == 0)) {
                    incompleteAssociations.add(dia);
                } else if (targetInput.getName().equalsIgnoreCase("NotStartedNotify") && (properties.get("notifications") == null || properties.get("notifications").length() == 0)) {
                    incompleteAssociations.add(dia);
                }
            }
        }
        for (DataInputAssociation tr : incompleteAssociations) {
            if (task.getDataInputAssociations() != null) {
                task.getDataInputAssociations().remove(tr);
            }
        }
    }
    List<DataInput> toRemoveDataInputs = new ArrayList<DataInput>();
    if (task.getIoSpecification() != null && task.getIoSpecification().getDataInputs() != null) {
        List<DataInput> taskDataInputs = task.getIoSpecification().getDataInputs();
        for (DataInput din : taskDataInputs) {
            if (din.getName().equals("GroupId") && (properties.get("groupid") == null || properties.get("groupid").length() == 0)) {
                toRemoveDataInputs.add(din);
            } else if (din.getName().equalsIgnoreCase("Skippable") && (skippableStr == null || skippableStr.length() == 0)) {
                toRemoveDataInputs.add(din);
            } else if (din.getName().equalsIgnoreCase("Comment") && (properties.get("subject") == null || properties.get("subject").length() == 0)) {
                toRemoveDataInputs.add(din);
            } else if (din.getName().equalsIgnoreCase("Description") && (properties.get("description") == null || properties.get("description").length() == 0)) {
                toRemoveDataInputs.add(din);
            } else if (din.getName().equalsIgnoreCase("Priority") && (properties.get("priority") == null || properties.get("priority").length() == 0)) {
                toRemoveDataInputs.add(din);
            } else if (din.getName().equalsIgnoreCase("Content") && (properties.get("content") == null || properties.get("content").length() == 0)) {
                toRemoveDataInputs.add(din);
            } else if (din.getName().equalsIgnoreCase("Locale") && (properties.get("locale") == null || properties.get("locale").length() == 0)) {
                toRemoveDataInputs.add(din);
            } else if (din.getName().equalsIgnoreCase("CreatedBy") && (properties.get("createdby") == null || properties.get("createdby").length() == 0)) {
                toRemoveDataInputs.add(din);
            } else if (din.getName().equalsIgnoreCase("NotCompletedReassign") && (properties.get("reassignment") == null || properties.get("reassignment").length() == 0)) {
                toRemoveDataInputs.add(din);
            } else if (din.getName().equalsIgnoreCase("NotStartedReassign") && (properties.get("reassignment") == null || properties.get("reassignment").length() == 0)) {
                toRemoveDataInputs.add(din);
            } else if (din.getName().equalsIgnoreCase("NotCompletedNotify") && (properties.get("notifications") == null || properties.get("notifications").length() == 0)) {
                toRemoveDataInputs.add(din);
            } else if (din.getName().equalsIgnoreCase("NotStartedNotify") && (properties.get("notifications") == null || properties.get("notifications").length() == 0)) {
                toRemoveDataInputs.add(din);
            }
        }
    }
    for (DataInput trdin : toRemoveDataInputs) {
        if (task.getIoSpecification() != null && task.getIoSpecification().getDataInputs() != null) {
            if (task.getIoSpecification().getInputSets().size() > 0) {
                task.getIoSpecification().getInputSets().get(0).getDataInputRefs().remove(trdin);
            }
        }
        task.getIoSpecification().getDataInputs().remove(trdin);
    }
    // simulation properties
    ResourceParameters resourceParameters = BpsimFactory.eINSTANCE.createResourceParameters();
    if (properties.get("quantity") != null && properties.get("quantity").length() > 0) {
        Parameter quantityParam = BpsimFactory.eINSTANCE.createParameter();
        FloatingParameterType quantityValueParam = BpsimFactory.eINSTANCE.createFloatingParameterType();
        DecimalFormat twoDForm = new DecimalFormat("#.##");
        quantityValueParam.setValue(Double.valueOf(twoDForm.format(Double.valueOf(properties.get("quantity")))));
        quantityParam.getParameterValue().add(quantityValueParam);
        resourceParameters.setQuantity(quantityParam);
    }
    if (properties.get("workinghours") != null && properties.get("workinghours").length() > 0) {
        Parameter workingHoursParam = BpsimFactory.eINSTANCE.createParameter();
        FloatingParameterType workingHoursValueParam = BpsimFactory.eINSTANCE.createFloatingParameterType();
        DecimalFormat twoDForm = new DecimalFormat("#.##");
        workingHoursValueParam.setValue(Double.valueOf(twoDForm.format(Double.valueOf(properties.get("workinghours")))));
        workingHoursParam.getParameterValue().add(workingHoursValueParam);
        resourceParameters.setAvailability(workingHoursParam);
    }
    if (_simulationElementParameters.containsKey(task.getId())) {
        _simulationElementParameters.get(task.getId()).add(resourceParameters);
    } else {
        List<EObject> values = new ArrayList<EObject>();
        values.add(resourceParameters);
        _simulationElementParameters.put(task.getId(), values);
    }
}
Also used : OutputSet(org.eclipse.bpmn2.OutputSet) ResourceAssignmentExpression(org.eclipse.bpmn2.ResourceAssignmentExpression) InputOutputSpecification(org.eclipse.bpmn2.InputOutputSpecification) DecimalFormat(java.text.DecimalFormat) PotentialOwner(org.eclipse.bpmn2.PotentialOwner) ArrayList(java.util.ArrayList) FormalExpression(org.eclipse.bpmn2.FormalExpression) ResourceParameters(bpsim.ResourceParameters) FloatingParameterType(bpsim.FloatingParameterType) DataInput(org.eclipse.bpmn2.DataInput) InputSet(org.eclipse.bpmn2.InputSet) Assignment(org.eclipse.bpmn2.Assignment) EAttributeImpl(org.eclipse.emf.ecore.impl.EAttributeImpl) EObject(org.eclipse.emf.ecore.EObject) Parameter(bpsim.Parameter) SimpleFeatureMapEntry(org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry) ExtendedMetaData(org.eclipse.emf.ecore.util.ExtendedMetaData) DataInputAssociation(org.eclipse.bpmn2.DataInputAssociation)

Example 3 with PotentialOwner

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

the class UserTaskPropertyWriter method setActors.

public void setActors(Actors actors) {
    for (String actor : fromActorString(actors.getValue())) {
        PotentialOwner potentialOwner = bpmn2.createPotentialOwner();
        potentialOwner.setId("_" + UUID.randomUUID().toString());
        FormalExpression formalExpression = bpmn2.createFormalExpression();
        formalExpression.setBody(actor);
        ResourceAssignmentExpression resourceAssignmentExpression = bpmn2.createResourceAssignmentExpression();
        resourceAssignmentExpression.setExpression(formalExpression);
        potentialOwner.setResourceAssignmentExpression(resourceAssignmentExpression);
        task.getResources().add(potentialOwner);
    }
}
Also used : ResourceAssignmentExpression(org.eclipse.bpmn2.ResourceAssignmentExpression) PotentialOwner(org.eclipse.bpmn2.PotentialOwner) FormalExpression(org.eclipse.bpmn2.FormalExpression)

Example 4 with PotentialOwner

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

the class UserTaskPropertyWriterTest method getActors.

public List<Pair<String, String>> getActors(UserTask userTask) {
    // get the user task actors
    List<ResourceRole> roles = userTask.getResources();
    List<Pair<String, String>> actors = new ArrayList<>();
    for (ResourceRole role : roles) {
        if (role instanceof PotentialOwner) {
            FormalExpression fe = (FormalExpression) role.getResourceAssignmentExpression().getExpression();
            actors.add(new Pair<>(fe.getBody(), role.getId()));
        }
    }
    return actors;
}
Also used : ResourceRole(org.eclipse.bpmn2.ResourceRole) ArrayList(java.util.ArrayList) PotentialOwner(org.eclipse.bpmn2.PotentialOwner) FormalExpression(org.eclipse.bpmn2.FormalExpression) Pair(com.github.javaparser.utils.Pair)

Example 5 with PotentialOwner

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

the class UserTaskPropertyReader method getActors.

public Actors getActors() {
    // get the user task actors
    List<ResourceRole> roles = task.getResources();
    List<String> users = new ArrayList<>();
    for (ResourceRole role : roles) {
        if (role instanceof PotentialOwner) {
            FormalExpression fe = (FormalExpression) role.getResourceAssignmentExpression().getExpression();
            users.add(fe.getBody());
        }
    }
    return new Actors(renderActors(users));
}
Also used : ResourceRole(org.eclipse.bpmn2.ResourceRole) ArrayList(java.util.ArrayList) PotentialOwner(org.eclipse.bpmn2.PotentialOwner) Actors(org.kie.workbench.common.stunner.bpmn.definition.property.assignee.Actors) FormalExpression(org.eclipse.bpmn2.FormalExpression)

Aggregations

FormalExpression (org.eclipse.bpmn2.FormalExpression)5 PotentialOwner (org.eclipse.bpmn2.PotentialOwner)5 ArrayList (java.util.ArrayList)4 ResourceRole (org.eclipse.bpmn2.ResourceRole)3 DataInput (org.eclipse.bpmn2.DataInput)2 DataInputAssociation (org.eclipse.bpmn2.DataInputAssociation)2 InputSet (org.eclipse.bpmn2.InputSet)2 ResourceAssignmentExpression (org.eclipse.bpmn2.ResourceAssignmentExpression)2 FloatingParameterType (bpsim.FloatingParameterType)1 Parameter (bpsim.Parameter)1 ResourceParameters (bpsim.ResourceParameters)1 Pair (com.github.javaparser.utils.Pair)1 DecimalFormat (java.text.DecimalFormat)1 LinkedHashMap (java.util.LinkedHashMap)1 Entry (java.util.Map.Entry)1 Assignment (org.eclipse.bpmn2.Assignment)1 BusinessRuleTask (org.eclipse.bpmn2.BusinessRuleTask)1 DataObject (org.eclipse.bpmn2.DataObject)1 DataOutput (org.eclipse.bpmn2.DataOutput)1 DataOutputAssociation (org.eclipse.bpmn2.DataOutputAssociation)1