Search in sources :

Example 96 with EObject

use of org.eclipse.emf.ecore.EObject 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 97 with EObject

use of org.eclipse.emf.ecore.EObject in project kie-wb-common by kiegroup.

the class Bpmn2JsonUnmarshaller method applySubProcessProperties.

protected void applySubProcessProperties(SubProcess sp, Map<String, String> properties) {
    if (properties.get("name") != null) {
        sp.setName(StringEscapeUtils.escapeXml(properties.get("name")).replaceAll("\\r\\n|\\r|\\n", " "));
        // add unescaped and untouched name value as extension element as well
        Utils.setMetaDataExtensionValue(sp, "elementname", wrapInCDATABlock(properties.get("name").replaceAll("\\\\n", "\n")));
    } else {
        sp.setName("");
    }
    // process on-entry and on-exit actions as custom elements
    applyOnEntryActions(sp, properties);
    applyOnExitActions(sp, properties);
    // isAsync metadata
    if (properties.get("isasync") != null && properties.get("isasync").length() > 0 && properties.get("isasync").equals("true")) {
        Utils.setMetaDataExtensionValue(sp, "customAsync", wrapInCDATABlock(properties.get("isasync")));
    }
    if (sp.getIoSpecification() == null) {
        InputOutputSpecification iospec = Bpmn2Factory.eINSTANCE.createInputOutputSpecification();
        sp.setIoSpecification(iospec);
    }
    parseAssignmentsInfo(properties);
    // data input set
    applyDataInputProperties(sp, properties, new HashMap<String, DataInput>());
    // data output set
    applyDataOutputProperties(sp, properties);
    // assignments
    if (properties.get("assignments") != null && properties.get("assignments").length() > 0 && sp.getIoSpecification() != null) {
        String[] allAssignments = properties.get("assignments").split(",\\s*");
        for (String assignment : allAssignments) {
            if (assignment.contains("=")) {
                String[] assignmentParts = assignment.split("=\\s*");
                String fromPart = assignmentParts[0];
                if (fromPart.startsWith("[din]")) {
                    fromPart = fromPart.substring(5, fromPart.length());
                }
                DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
                if (sp.getIoSpecification() != null && sp.getIoSpecification().getDataOutputs() != null) {
                    List<DataInput> dataInputs = sp.getIoSpecification().getDataInputs();
                    for (DataInput di : dataInputs) {
                        if (di.getId().equals(sp.getId() + "_" + fromPart + "InputX")) {
                            dia.setTargetRef(di);
                            if (di.getName().equals("TaskName")) {
                                break;
                            }
                        }
                    }
                }
                Assignment a = Bpmn2Factory.eINSTANCE.createAssignment();
                FormalExpression fromExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
                if (assignmentParts.length > 1) {
                    String replacer = decodeAssociationValue(assignmentParts[1]);
                    fromExpression.setBody(wrapInCDATABlock(replacer));
                } else {
                    fromExpression.setBody("");
                }
                FormalExpression toExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
                toExpression.setBody(dia.getTargetRef().getId());
                a.setFrom(fromExpression);
                a.setTo(toExpression);
                dia.getAssignment().add(a);
                sp.getDataInputAssociations().add(dia);
            // } else if(assignment.contains("<->")) {
            // String[] assignmentParts = assignment.split( "<->\\s*" );
            // DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
            // DataOutputAssociation doa = Bpmn2Factory.eINSTANCE.createDataOutputAssociation();
            // 
            // ItemAwareElement ie = Bpmn2Factory.eINSTANCE.createItemAwareElement();
            // ie.setId(assignmentParts[0]);
            // dia.getSourceRef().add(ie);
            // doa.setTargetRef(ie);
            // 
            // List<DataInput> dataInputs = sp.getIoSpecification().getDataInputs();
            // for(DataInput di : dataInputs) {
            // if(di.getId().equals(sp.getId() + "_" + assignmentParts[1] + "InputX")) {
            // dia.setTargetRef(di);
            // break;
            // }
            // }
            // List<DataOutput> dataOutputs = sp.getIoSpecification().getDataOutputs();
            // for(DataOutput dout : dataOutputs) {
            // if(dout.getId().equals(sp.getId() + "_" + assignmentParts[1] + "OutputX")) {
            // doa.getSourceRef().add(dout);
            // break;
            // }
            // }
            // 
            // sp.getDataInputAssociations().add(dia);
            // sp.getDataOutputAssociations().add(doa);
            } else if (assignment.contains("->")) {
                String[] assignmentParts = assignment.split("->\\s*");
                String fromPart = assignmentParts[0];
                boolean isDataInput = false;
                boolean isDataOutput = false;
                if (fromPart.startsWith("[din]")) {
                    fromPart = fromPart.substring(5, fromPart.length());
                    isDataInput = true;
                }
                if (fromPart.startsWith("[dout]")) {
                    fromPart = fromPart.substring(6, fromPart.length());
                    isDataOutput = true;
                }
                List<DataOutput> dataOutputs = sp.getIoSpecification().getDataOutputs();
                if (isDataOutput) {
                    DataOutputAssociation doa = Bpmn2Factory.eINSTANCE.createDataOutputAssociation();
                    for (DataOutput dout : dataOutputs) {
                        if (dout.getId().equals(sp.getId() + "_" + fromPart + "OutputX")) {
                            doa.getSourceRef().add(dout);
                            break;
                        }
                    }
                    ItemAwareElement ie = Bpmn2Factory.eINSTANCE.createItemAwareElement();
                    ie.setId(assignmentParts[1]);
                    doa.setTargetRef(ie);
                    sp.getDataOutputAssociations().add(doa);
                } else if (isDataInput) {
                    DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
                    // association from process var to dataInput var
                    ItemAwareElement ie = Bpmn2Factory.eINSTANCE.createItemAwareElement();
                    ie.setId(fromPart);
                    dia.getSourceRef().add(ie);
                    List<DataInput> dataInputs = sp.getIoSpecification().getDataInputs();
                    for (DataInput di : dataInputs) {
                        if (di.getId().equals(sp.getId() + "_" + assignmentParts[1] + "InputX")) {
                            dia.setTargetRef(di);
                            break;
                        }
                    }
                    sp.getDataInputAssociations().add(dia);
                }
            } else {
            // TODO throw exception here?
            }
        }
    }
    // loop characteristics input
    if (properties.get("mitrigger") != null && properties.get("mitrigger").equals("true")) {
        if (properties.get("multipleinstancecollectioninput") != null && properties.get("multipleinstancecollectioninput").length() > 0) {
            String miDataInputStr = properties.get("multipleinstancedatainput");
            if (miDataInputStr == null || miDataInputStr.length() < 1) {
                miDataInputStr = "defaultDataInput";
            }
            if (sp.getIoSpecification() == null) {
                InputOutputSpecification iospec = Bpmn2Factory.eINSTANCE.createInputOutputSpecification();
                sp.setIoSpecification(iospec);
            } else {
                sp.getIoSpecification().getDataInputs().clear();
                sp.getIoSpecification().getDataOutputs().clear();
                sp.getDataInputAssociations().clear();
                sp.getDataOutputAssociations().clear();
            }
            InputSet inset = sp.getIoSpecification().getInputSets().get(0);
            DataInput multiInput = Bpmn2Factory.eINSTANCE.createDataInput();
            multiInput.setId(sp.getId() + "_" + "input");
            multiInput.setName(properties.get("multipleinstancecollectioninput"));
            sp.getIoSpecification().getDataInputs().add(multiInput);
            inset.getDataInputRefs().add(multiInput);
            DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
            ItemAwareElement ie = Bpmn2Factory.eINSTANCE.createItemAwareElement();
            ie.setId(properties.get("multipleinstancecollectioninput"));
            dia.getSourceRef().add(ie);
            dia.setTargetRef(multiInput);
            sp.getDataInputAssociations().add(dia);
            MultiInstanceLoopCharacteristics loopCharacteristics = Bpmn2Factory.eINSTANCE.createMultiInstanceLoopCharacteristics();
            loopCharacteristics.setLoopDataInputRef(multiInput);
            DataInput din = Bpmn2Factory.eINSTANCE.createDataInput();
            din.setId(miDataInputStr);
            ItemDefinition itemDef = Bpmn2Factory.eINSTANCE.createItemDefinition();
            itemDef.setId(sp.getId() + "_" + "multiInstanceItemType");
            din.setItemSubjectRef(itemDef);
            _subprocessItemDefs.put(itemDef.getId(), itemDef);
            loopCharacteristics.setInputDataItem(din);
            // loop characteristics output
            if (properties.get("multipleinstancecollectionoutput") != null && properties.get("multipleinstancecollectionoutput").length() > 0) {
                String miDataOutputStr = properties.get("multipleinstancedataoutput");
                if (miDataOutputStr == null || miDataOutputStr.length() < 1) {
                    miDataOutputStr = "defaultDataOutput";
                }
                OutputSet outset = sp.getIoSpecification().getOutputSets().get(0);
                DataOutput multiOutput = Bpmn2Factory.eINSTANCE.createDataOutput();
                multiOutput.setId(sp.getId() + "_" + "output");
                multiOutput.setName(properties.get("multipleinstancecollectionoutput"));
                sp.getIoSpecification().getDataOutputs().add(multiOutput);
                outset.getDataOutputRefs().add(multiOutput);
                DataOutputAssociation doa = Bpmn2Factory.eINSTANCE.createDataOutputAssociation();
                ItemAwareElement ie2 = Bpmn2Factory.eINSTANCE.createItemAwareElement();
                ie2.setId(properties.get("multipleinstancecollectionoutput"));
                doa.getSourceRef().add(multiOutput);
                doa.setTargetRef(ie2);
                sp.getDataOutputAssociations().add(doa);
                loopCharacteristics.setLoopDataOutputRef(multiOutput);
                DataOutput don = Bpmn2Factory.eINSTANCE.createDataOutput();
                don.setId(miDataOutputStr);
                ItemDefinition itemDef2 = Bpmn2Factory.eINSTANCE.createItemDefinition();
                itemDef2.setId(sp.getId() + "_" + "multiInstanceItemType");
                don.setItemSubjectRef(itemDef2);
                _subprocessItemDefs.put(itemDef2.getId(), itemDef2);
                loopCharacteristics.setOutputDataItem(don);
            }
            // loop characteristics completion condition
            if (properties.get("multipleinstancecompletioncondition") != null && !properties.get("multipleinstancecompletioncondition").isEmpty()) {
                FormalExpression expr = Bpmn2Factory.eINSTANCE.createFormalExpression();
                expr.setBody(properties.get("multipleinstancecompletioncondition"));
                loopCharacteristics.setCompletionCondition(expr);
            }
            sp.setLoopCharacteristics(loopCharacteristics);
        } else {
            MultiInstanceLoopCharacteristics loopCharacteristics = Bpmn2Factory.eINSTANCE.createMultiInstanceLoopCharacteristics();
            sp.setLoopCharacteristics(loopCharacteristics);
        }
    }
    // properties
    if (properties.get("vardefs") != null && properties.get("vardefs").length() > 0) {
        String[] vardefs = properties.get("vardefs").split(",\\s*");
        for (String vardef : vardefs) {
            Property prop = Bpmn2Factory.eINSTANCE.createProperty();
            ItemDefinition itemdef = Bpmn2Factory.eINSTANCE.createItemDefinition();
            // check if we define a structure ref in the definition
            if (vardef.contains(":")) {
                String[] vardefParts = vardef.split(":\\s*");
                prop.setId(vardefParts[0]);
                itemdef.setId("_" + prop.getId() + "Item");
                boolean haveKPI = false;
                String kpiValue = "";
                if (vardefParts.length == 3) {
                    itemdef.setStructureRef(vardefParts[1]);
                    if (vardefParts[2].equals("true")) {
                        haveKPI = true;
                        kpiValue = vardefParts[2];
                    }
                }
                if (vardefParts.length == 2) {
                    if (vardefParts[1].equals("true") || vardefParts[1].equals("false")) {
                        if (vardefParts[1].equals("true")) {
                            haveKPI = true;
                            kpiValue = vardefParts[1];
                        }
                    } else {
                        itemdef.setStructureRef(vardefParts[1]);
                    }
                }
                if (haveKPI) {
                    Utils.setMetaDataExtensionValue(prop, "customKPI", wrapInCDATABlock(kpiValue));
                }
            } else {
                prop.setId(vardef);
                itemdef.setId("_" + prop.getId() + "Item");
            }
            prop.setItemSubjectRef(itemdef);
            sp.getProperties().add(prop);
            _subprocessItemDefs.put(itemdef.getId(), itemdef);
        }
    }
    // event subprocess
    if (sp instanceof EventSubprocess) {
        sp.setTriggeredByEvent(true);
    }
    // simulation
    if (properties.get("distributiontype") != null && properties.get("distributiontype").length() > 0) {
        TimeParameters timeParams = BpsimFactory.eINSTANCE.createTimeParameters();
        Parameter processingTimeParam = BpsimFactory.eINSTANCE.createParameter();
        if (properties.get("distributiontype").equals("normal")) {
            NormalDistributionType normalDistributionType = BpsimFactory.eINSTANCE.createNormalDistributionType();
            normalDistributionType.setStandardDeviation(Double.valueOf(properties.get("standarddeviation")));
            normalDistributionType.setMean(Double.valueOf(properties.get("mean")));
            processingTimeParam.getParameterValue().add(normalDistributionType);
        } else if (properties.get("distributiontype").equals("uniform")) {
            UniformDistributionType uniformDistributionType = BpsimFactory.eINSTANCE.createUniformDistributionType();
            uniformDistributionType.setMax(Double.valueOf(properties.get("max")));
            uniformDistributionType.setMin(Double.valueOf(properties.get("min")));
            processingTimeParam.getParameterValue().add(uniformDistributionType);
        // random distribution not supported in bpsim 1.0
        // } else if(properties.get("distributiontype").equals("random")) {
        // RandomDistributionType randomDistributionType = BpsimFactory.eINSTANCE.createRandomDistributionType();
        // randomDistributionType.setMax(Double.valueOf(properties.get("max")));
        // randomDistributionType.setMin(Double.valueOf(properties.get("min")));
        // processingTimeParam.getParameterValue().add(randomDistributionType);
        } else if (properties.get("distributiontype").equals("poisson")) {
            PoissonDistributionType poissonDistributionType = BpsimFactory.eINSTANCE.createPoissonDistributionType();
            poissonDistributionType.setMean(Double.valueOf(properties.get("mean")));
            processingTimeParam.getParameterValue().add(poissonDistributionType);
        }
        // }
        if (properties.get("waittime") != null) {
            Parameter waittimeParam = BpsimFactory.eINSTANCE.createParameter();
            FloatingParameterType waittimeParamValue = BpsimFactory.eINSTANCE.createFloatingParameterType();
            DecimalFormat twoDForm = new DecimalFormat("#.##");
            waittimeParamValue.setValue(Double.valueOf(twoDForm.format(Double.valueOf(properties.get("waittime")))));
            waittimeParam.getParameterValue().add(waittimeParamValue);
            timeParams.setWaitTime(waittimeParam);
        }
        timeParams.setProcessingTime(processingTimeParam);
        if (_simulationElementParameters.containsKey(sp.getId())) {
            _simulationElementParameters.get(sp.getId()).add(timeParams);
        } else {
            List<EObject> values = new ArrayList<EObject>();
            values.add(timeParams);
            _simulationElementParameters.put(sp.getId(), values);
        }
    }
    CostParameters costParameters = BpsimFactory.eINSTANCE.createCostParameters();
    if (properties.get("unitcost") != null && properties.get("unitcost").length() > 0) {
        Parameter unitcostParam = BpsimFactory.eINSTANCE.createParameter();
        FloatingParameterType unitCostParameterValue = BpsimFactory.eINSTANCE.createFloatingParameterType();
        unitCostParameterValue.setValue(new Double(properties.get("unitcost")));
        unitcostParam.getParameterValue().add(unitCostParameterValue);
        costParameters.setUnitCost(unitcostParam);
    }
    // }
    if (_simulationElementParameters.containsKey(sp.getId())) {
        _simulationElementParameters.get(sp.getId()).add(costParameters);
    } else {
        List<EObject> values = new ArrayList<EObject>();
        values.add(costParameters);
        _simulationElementParameters.put(sp.getId(), values);
    }
}
Also used : DataOutput(org.eclipse.bpmn2.DataOutput) CostParameters(bpsim.CostParameters) NormalDistributionType(bpsim.NormalDistributionType) DecimalFormat(java.text.DecimalFormat) ItemDefinition(org.eclipse.bpmn2.ItemDefinition) ArrayList(java.util.ArrayList) Assignment(org.eclipse.bpmn2.Assignment) MultiInstanceLoopCharacteristics(org.eclipse.bpmn2.MultiInstanceLoopCharacteristics) EventSubprocess(org.eclipse.bpmn2.EventSubprocess) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) List(java.util.List) DataOutputAssociation(org.eclipse.bpmn2.DataOutputAssociation) Property(org.eclipse.bpmn2.Property) UniformDistributionType(bpsim.UniformDistributionType) OutputSet(org.eclipse.bpmn2.OutputSet) InputOutputSpecification(org.eclipse.bpmn2.InputOutputSpecification) ItemAwareElement(org.eclipse.bpmn2.ItemAwareElement) FormalExpression(org.eclipse.bpmn2.FormalExpression) FloatingParameterType(bpsim.FloatingParameterType) DataInput(org.eclipse.bpmn2.DataInput) InputSet(org.eclipse.bpmn2.InputSet) PoissonDistributionType(bpsim.PoissonDistributionType) Parameter(bpsim.Parameter) TimeParameters(bpsim.TimeParameters) DataInputAssociation(org.eclipse.bpmn2.DataInputAssociation)

Example 98 with EObject

use of org.eclipse.emf.ecore.EObject in project kie-wb-common by kiegroup.

the class Bpmn2JsonUnmarshaller method applySequenceFlowProperties.

protected void applySequenceFlowProperties(SequenceFlow sequenceFlow, Map<String, String> properties) {
    // sequence flow name is options
    if (properties.get("name") != null && !"".equals(properties.get("name"))) {
        sequenceFlow.setName(StringEscapeUtils.escapeXml(properties.get("name")).replaceAll("\\r\\n|\\r|\\n", " "));
        // add unescaped and untouched name value as extension eleent as well
        Utils.setMetaDataExtensionValue(sequenceFlow, "elementname", wrapInCDATABlock(properties.get("name").replaceAll("\\\\n", "\n")));
    }
    if (properties.get("bgcolor") != null && properties.get("bgcolor").length() > 0) {
        if (!(_elementColors.containsKey(sequenceFlow.getId()))) {
            List<String> colorsList = new ArrayList<String>();
            colorsList.add("bgcolor:" + properties.get("bgcolor"));
            _elementColors.put(sequenceFlow.getId(), colorsList);
        } else {
            _elementColors.get(sequenceFlow.getId()).add("bgcolor:" + properties.get("bgcolor"));
        }
    }
    if (properties.get("bordercolor") != null && properties.get("bordercolor").length() > 0) {
        if (!(_elementColors.containsKey(sequenceFlow.getId()))) {
            List<String> colorsList = new ArrayList<String>();
            colorsList.add("bordercolor:" + properties.get("bordercolor"));
            _elementColors.put(sequenceFlow.getId(), colorsList);
        } else {
            _elementColors.get(sequenceFlow.getId()).add("bordercolor:" + properties.get("bordercolor"));
        }
    }
    if (properties.get("fontsize") != null && properties.get("fontsize").length() > 0) {
        ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
        EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "fontsize", false, false);
        SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("fontsize"));
        sequenceFlow.getAnyAttribute().add(extensionEntry);
    }
    if (properties.get("fontcolor") != null && properties.get("fontcolor").length() > 0) {
        if (!(_elementColors.containsKey(sequenceFlow.getId()))) {
            List<String> colorsList = new ArrayList<String>();
            colorsList.add("fontcolor:" + properties.get("fontcolor"));
            _elementColors.put(sequenceFlow.getId(), colorsList);
        } else {
            _elementColors.get(sequenceFlow.getId()).add("fontcolor:" + properties.get("fontcolor"));
        }
    }
    // Custom extended auto connection property for Stunner.
    String sourceConnAutoPropertyName = Bpmn2OryxManager.MAGNET_AUTO_CONNECTION + Bpmn2OryxManager.SOURCE;
    String sourceConnAutoRaw = properties.get(sourceConnAutoPropertyName);
    if (null != sourceConnAutoRaw && Boolean.TRUE.equals(Boolean.parseBoolean(sourceConnAutoRaw))) {
        Utils.setMetaDataExtensionValue(sequenceFlow, sourceConnAutoPropertyName, Boolean.toString(true));
    }
    String targetConnAutoPropertyName = Bpmn2OryxManager.MAGNET_AUTO_CONNECTION + Bpmn2OryxManager.TARGET;
    String targetConnAutoRaw = properties.get(targetConnAutoPropertyName);
    if (null != targetConnAutoRaw && Boolean.TRUE.equals(Boolean.parseBoolean(targetConnAutoRaw))) {
        Utils.setMetaDataExtensionValue(sequenceFlow, targetConnAutoPropertyName, Boolean.toString(true));
    }
    if (properties.get("isselectable") != null && properties.get("isselectable").length() > 0) {
        ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
        EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "selectable", false, false);
        SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("isselectable"));
        sequenceFlow.getAnyAttribute().add(extensionEntry);
    }
    if (properties.get("auditing") != null && !"".equals(properties.get("auditing"))) {
        Auditing audit = Bpmn2Factory.eINSTANCE.createAuditing();
        audit.getDocumentation().add(createDocumentation(properties.get("auditing")));
        sequenceFlow.setAuditing(audit);
    }
    applySequenceFlowCondition(sequenceFlow, properties);
    if (properties.get("priority") != null && !"".equals(properties.get("priority"))) {
        ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
        EAttributeImpl priorityElement = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "priority", false, false);
        SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(priorityElement, properties.get("priority"));
        sequenceFlow.getAnyAttribute().add(extensionEntry);
    }
    if (properties.get("monitoring") != null && !"".equals(properties.get("monitoring"))) {
        Monitoring monitoring = Bpmn2Factory.eINSTANCE.createMonitoring();
        monitoring.getDocumentation().add(createDocumentation(properties.get("monitoring")));
        sequenceFlow.setMonitoring(monitoring);
    }
    sequenceFlow.setIsImmediate(Boolean.parseBoolean(properties.get("isimmediate")));
    // simulation properties
    if (properties.get("probability") != null && properties.get("probability").length() > 0) {
        ControlParameters controlParams = BpsimFactory.eINSTANCE.createControlParameters();
        Parameter probParam = BpsimFactory.eINSTANCE.createParameter();
        FloatingParameterType probParamValueParam = BpsimFactory.eINSTANCE.createFloatingParameterType();
        DecimalFormat twoDForm = new DecimalFormat("#.##");
        probParamValueParam.setValue(Double.valueOf(twoDForm.format(Double.valueOf(properties.get("probability")))));
        probParam.getParameterValue().add(probParamValueParam);
        controlParams.setProbability(probParam);
        if (_simulationElementParameters.containsKey(sequenceFlow.getId())) {
            _simulationElementParameters.get(sequenceFlow.getId()).add(controlParams);
        } else {
            List<EObject> values = new ArrayList<EObject>();
            values.add(controlParams);
            _simulationElementParameters.put(sequenceFlow.getId(), values);
        }
    }
}
Also used : DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) Auditing(org.eclipse.bpmn2.Auditing) FloatingParameterType(bpsim.FloatingParameterType) EAttributeImpl(org.eclipse.emf.ecore.impl.EAttributeImpl) EObject(org.eclipse.emf.ecore.EObject) ControlParameters(bpsim.ControlParameters) Parameter(bpsim.Parameter) SimpleFeatureMapEntry(org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry) ExtendedMetaData(org.eclipse.emf.ecore.util.ExtendedMetaData) Monitoring(org.eclipse.bpmn2.Monitoring)

Example 99 with EObject

use of org.eclipse.emf.ecore.EObject in project kie-wb-common by kiegroup.

the class Bpmn2JsonUnmarshaller method applyCatchEventProperties.

protected void applyCatchEventProperties(CatchEvent event, Map<String, String> properties) {
    parseAssignmentsInfo(properties);
    if (properties.get("dataoutput") != null && !"".equals(properties.get("dataoutput"))) {
        String[] allDataOutputs = properties.get("dataoutput").split(",\\s*");
        OutputSet outSet = Bpmn2Factory.eINSTANCE.createOutputSet();
        for (String dataOutput : allDataOutputs) {
            if (dataOutput.trim().length() > 0) {
                DataOutput nextOutput = Bpmn2Factory.eINSTANCE.createDataOutput();
                String[] doutputParts = dataOutput.split(":\\s*");
                if (doutputParts.length == 2) {
                    nextOutput.setId(event.getId() + "_" + doutputParts[0]);
                    nextOutput.setName(doutputParts[0]);
                    ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
                    EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "dtype", false, false);
                    SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, doutputParts[1]);
                    nextOutput.getAnyAttribute().add(extensionEntry);
                } else {
                    nextOutput.setId(event.getId() + "_" + dataOutput);
                    nextOutput.setName(dataOutput);
                    ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
                    EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "dtype", false, false);
                    SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, "Object");
                    nextOutput.getAnyAttribute().add(extensionEntry);
                }
                event.getDataOutputs().add(nextOutput);
                outSet.getDataOutputRefs().add(nextOutput);
            }
        }
        event.setOutputSet(outSet);
    }
    if (properties.get("boundarycancelactivity") != null) {
        ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
        EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "boundaryca", false, false);
        SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("boundarycancelactivity"));
        event.getAnyAttribute().add(extensionEntry);
    }
    // data output associations
    if (properties.get("dataoutputassociations") != null && !"".equals(properties.get("dataoutputassociations"))) {
        String[] allAssociations = properties.get("dataoutputassociations").split(",\\s*");
        for (String association : allAssociations) {
            // data outputs are uni-directional
            String[] associationParts = association.split("->\\s*");
            String fromPart = associationParts[0];
            if (fromPart.startsWith("[dout]")) {
                fromPart = fromPart.substring(6, fromPart.length());
            }
            DataOutputAssociation doa = Bpmn2Factory.eINSTANCE.createDataOutputAssociation();
            // for source refs we loop through already defined data outputs
            List<DataOutput> dataOutputs = event.getDataOutputs();
            if (dataOutputs != null) {
                for (DataOutput ddo : dataOutputs) {
                    if (ddo.getId().equals(event.getId() + "_" + fromPart)) {
                        doa.getSourceRef().add(ddo);
                    }
                }
            }
            // since we dont have the process vars defined yet..need to improvise
            ItemAwareElement e = Bpmn2Factory.eINSTANCE.createItemAwareElement();
            e.setId(associationParts[1]);
            doa.setTargetRef(e);
            event.getDataOutputAssociation().add(doa);
        }
    }
    try {
        if (event.getEventDefinitions() != null && event.getEventDefinitions().size() > 0) {
            EventDefinition ed = event.getEventDefinitions().get(0);
            if (ed instanceof TimerEventDefinition) {
                applyTimerEventProperties((TimerEventDefinition) ed, properties);
            } else if (ed instanceof SignalEventDefinition) {
                if (properties.get("signalref") != null && !"".equals(properties.get("signalref"))) {
                    ((SignalEventDefinition) ed).setSignalRef(properties.get("signalref"));
                // ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
                // EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature(
                // "http://www.jboss.org/drools", "signalrefname", false, false);
                // EStructuralFeatureImpl.SimpleFeatureMapEntry extensionEntry = new EStructuralFeatureImpl.SimpleFeatureMapEntry(extensionAttribute,
                // properties.get("signalref"));
                // ((SignalEventDefinition) event.getEventDefinitions().get(0)).getAnyAttribute().add(extensionEntry);
                }
            } else if (ed instanceof ErrorEventDefinition) {
                if (properties.get("errorref") != null && !"".equals(properties.get("errorref"))) {
                    ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
                    EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "erefname", false, false);
                    SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("errorref"));
                    ((ErrorEventDefinition) event.getEventDefinitions().get(0)).getAnyAttribute().add(extensionEntry);
                }
            } else if (ed instanceof ConditionalEventDefinition) {
                applyConditionalEventProperties((ConditionalEventDefinition) ed, properties);
            } else if (ed instanceof EscalationEventDefinition) {
                if (properties.get("escalationcode") != null && !"".equals(properties.get("escalationcode"))) {
                    ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
                    EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "esccode", false, false);
                    SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("escalationcode"));
                    ((EscalationEventDefinition) event.getEventDefinitions().get(0)).getAnyAttribute().add(extensionEntry);
                }
            } else if (ed instanceof MessageEventDefinition) {
                if (properties.get("messageref") != null && !"".equals(properties.get("messageref"))) {
                    ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
                    EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "msgref", false, false);
                    SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("messageref"));
                    ((MessageEventDefinition) event.getEventDefinitions().get(0)).getAnyAttribute().add(extensionEntry);
                }
            } else if (ed instanceof CompensateEventDefinition) {
                if (properties.get("activityref") != null && !"".equals(properties.get("activityref"))) {
                    ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
                    EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "actrefname", false, false);
                    SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("activityref"));
                    ((CompensateEventDefinition) event.getEventDefinitions().get(0)).getAnyAttribute().add(extensionEntry);
                }
            }
        }
    } catch (Exception e) {
        _logger.warn(e.getMessage());
    }
    // simulation
    if (properties.get("distributiontype") != null && properties.get("distributiontype").length() > 0) {
        TimeParameters timeParams = BpsimFactory.eINSTANCE.createTimeParameters();
        Parameter processingTimeParam = BpsimFactory.eINSTANCE.createParameter();
        if (properties.get("distributiontype").equals("normal")) {
            NormalDistributionType normalDistributionType = BpsimFactory.eINSTANCE.createNormalDistributionType();
            normalDistributionType.setStandardDeviation(Double.valueOf(properties.get("standarddeviation")));
            normalDistributionType.setMean(Double.valueOf(properties.get("mean")));
            processingTimeParam.getParameterValue().add(normalDistributionType);
        } else if (properties.get("distributiontype").equals("uniform")) {
            UniformDistributionType uniformDistributionType = BpsimFactory.eINSTANCE.createUniformDistributionType();
            uniformDistributionType.setMax(Double.valueOf(properties.get("max")));
            uniformDistributionType.setMin(Double.valueOf(properties.get("min")));
            processingTimeParam.getParameterValue().add(uniformDistributionType);
        // random distribution type not supported in bpsim 1.0
        // } else if(properties.get("distributiontype").equals("random")) {
        // RandomDistributionType randomDistributionType = DroolsFactory.eINSTANCE.createRandomDistributionType();
        // randomDistributionType.setMax(Double.valueOf(properties.get("max")));
        // randomDistributionType.setMin(Double.valueOf(properties.get("min")));
        // processingTimeParam.getParameterValue().add(randomDistributionType);
        } else if (properties.get("distributiontype").equals("poisson")) {
            PoissonDistributionType poissonDistributionType = BpsimFactory.eINSTANCE.createPoissonDistributionType();
            poissonDistributionType.setMean(Double.valueOf(properties.get("mean")));
            processingTimeParam.getParameterValue().add(poissonDistributionType);
        }
        // no specific time unit available in 1.0 bpsim - use global
        // if(properties.get("timeunit") != null) {
        // timeParams.setTimeUnit(TimeUnit.getByName(properties.get("timeunit")));
        // }
        timeParams.setProcessingTime(processingTimeParam);
        if (_simulationElementParameters.containsKey(event.getId())) {
            _simulationElementParameters.get(event.getId()).add(timeParams);
        } else {
            List<EObject> values = new ArrayList<EObject>();
            values.add(timeParams);
            _simulationElementParameters.put(event.getId(), values);
        }
    }
    if (properties.get("probability") != null && properties.get("probability").length() > 0) {
        ControlParameters controlParams = BpsimFactory.eINSTANCE.createControlParameters();
        Parameter probParam = BpsimFactory.eINSTANCE.createParameter();
        FloatingParameterType probParamValueParam = BpsimFactory.eINSTANCE.createFloatingParameterType();
        DecimalFormat twoDForm = new DecimalFormat("#.##");
        probParamValueParam.setValue(Double.valueOf(twoDForm.format(Double.valueOf(properties.get("probability")))));
        probParam.getParameterValue().add(probParamValueParam);
        controlParams.setProbability(probParam);
        if (_simulationElementParameters.containsKey(event.getId())) {
            _simulationElementParameters.get(event.getId()).add(controlParams);
        } else {
            List<EObject> values = new ArrayList<EObject>();
            values.add(controlParams);
            _simulationElementParameters.put(event.getId(), values);
        }
    }
}
Also used : DataOutput(org.eclipse.bpmn2.DataOutput) NormalDistributionType(bpsim.NormalDistributionType) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) EventDefinition(org.eclipse.bpmn2.EventDefinition) ConditionalEventDefinition(org.eclipse.bpmn2.ConditionalEventDefinition) EscalationEventDefinition(org.eclipse.bpmn2.EscalationEventDefinition) MessageEventDefinition(org.eclipse.bpmn2.MessageEventDefinition) ErrorEventDefinition(org.eclipse.bpmn2.ErrorEventDefinition) SignalEventDefinition(org.eclipse.bpmn2.SignalEventDefinition) CompensateEventDefinition(org.eclipse.bpmn2.CompensateEventDefinition) TimerEventDefinition(org.eclipse.bpmn2.TimerEventDefinition) EAttributeImpl(org.eclipse.emf.ecore.impl.EAttributeImpl) EObject(org.eclipse.emf.ecore.EObject) SignalEventDefinition(org.eclipse.bpmn2.SignalEventDefinition) SimpleFeatureMapEntry(org.eclipse.emf.ecore.impl.EStructuralFeatureImpl.SimpleFeatureMapEntry) DataOutputAssociation(org.eclipse.bpmn2.DataOutputAssociation) TimerEventDefinition(org.eclipse.bpmn2.TimerEventDefinition) UniformDistributionType(bpsim.UniformDistributionType) OutputSet(org.eclipse.bpmn2.OutputSet) ItemAwareElement(org.eclipse.bpmn2.ItemAwareElement) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) FloatingParameterType(bpsim.FloatingParameterType) PoissonDistributionType(bpsim.PoissonDistributionType) EscalationEventDefinition(org.eclipse.bpmn2.EscalationEventDefinition) ErrorEventDefinition(org.eclipse.bpmn2.ErrorEventDefinition) ControlParameters(bpsim.ControlParameters) ConditionalEventDefinition(org.eclipse.bpmn2.ConditionalEventDefinition) Parameter(bpsim.Parameter) MessageEventDefinition(org.eclipse.bpmn2.MessageEventDefinition) ExtendedMetaData(org.eclipse.emf.ecore.util.ExtendedMetaData) CompensateEventDefinition(org.eclipse.bpmn2.CompensateEventDefinition) TimeParameters(bpsim.TimeParameters)

Example 100 with EObject

use of org.eclipse.emf.ecore.EObject in project vorto by eclipse.

the class ProSystGenerator method generate.

@Override
public IGenerationResult generate(InformationModel infomodel, InvocationContext ctx, IVortoCodeGenProgressMonitor monitor) throws VortoCodeGeneratorException {
    GenerationResultZip zipOutputter = new GenerationResultZip(infomodel, getServiceKey());
    Set<EObject> visited = new HashSet<>();
    Set<String> exports = new HashSet<>();
    for (FunctionblockProperty fbp : infomodel.getProperties()) {
        Set<String> imports = new HashSet<>();
        FunctionBlock fb = fbp.getType().getFunctionblock();
        for (Entity entity : Utils.getReferencedEntities(fb)) {
            if (!visited.contains(entity)) {
                generateForEntity(infomodel, ctx, entity, zipOutputter);
                visited.add(entity);
            }
            imports.add(entity.getNamespace());
            exports.add(entity.getNamespace());
        }
        for (Enum en : Utils.getReferencedEnums(fb)) {
            if (!visited.contains(en)) {
                generateForEnum(infomodel, ctx, en, zipOutputter);
                visited.add(en);
            }
            imports.add(en.getNamespace());
            exports.add(en.getNamespace());
        }
        exports.add(infomodel.getNamespace());
        generateForFunctionBlock(infomodel, ctx, fbp.getType(), zipOutputter, imports.toArray(new String[imports.size()]));
    }
    generateEclipseProject(infomodel, ctx, zipOutputter, exports);
    return zipOutputter;
}
Also used : Enum(org.eclipse.vorto.core.api.model.datatype.Enum) Entity(org.eclipse.vorto.core.api.model.datatype.Entity) GenerationResultZip(org.eclipse.vorto.codegen.api.GenerationResultZip) EObject(org.eclipse.emf.ecore.EObject) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty) FunctionBlock(org.eclipse.vorto.core.api.model.functionblock.FunctionBlock) HashSet(java.util.HashSet)

Aggregations

EObject (org.eclipse.emf.ecore.EObject)7112 AntlrDatatypeRuleToken (org.eclipse.xtext.parser.antlr.AntlrDatatypeRuleToken)1950 Resource (org.eclipse.emf.ecore.resource.Resource)304 Test (org.junit.Test)301 IPropertiesEditionEvent (org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)262 PropertiesEditionEvent (org.eclipse.emf.eef.runtime.impl.notify.PropertiesEditionEvent)262 ArrayList (java.util.ArrayList)207 GridData (org.eclipse.swt.layout.GridData)198 SelectionEvent (org.eclipse.swt.events.SelectionEvent)190 URI (org.eclipse.emf.common.util.URI)189 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)187 InternalEObject (org.eclipse.emf.ecore.InternalEObject)181 ReferencesTable (org.eclipse.emf.eef.runtime.ui.widgets.ReferencesTable)162 ReferencesTableListener (org.eclipse.emf.eef.runtime.ui.widgets.ReferencesTable.ReferencesTableListener)162 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)138 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)128 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)127 List (java.util.List)125 XtextResource (org.eclipse.xtext.resource.XtextResource)124 EReference (org.eclipse.emf.ecore.EReference)96