List of usage examples for org.apache.commons.lang3 StringEscapeUtils escapeXml
@Deprecated public static final String escapeXml(final String input)
Escapes the characters in a String using XML entities.
For example: "bread" & "butter" => "bread" & "butter" .
From source file:org.kie.workbench.common.stunner.bpmn.backend.legacy.Bpmn2JsonUnmarshaller.java
protected void applyDataStoreProperties(DataStore da, Map<String, String> properties) { if (properties.get("name") != null) { da.setName(StringEscapeUtils.escapeXml(properties.get("name")).replaceAll("\\r\\n|\\r|\\n", " ")); // add unescaped and untouched name value as extension element as well Utils.setMetaDataExtensionValue(da, "elementname", wrapInCDATABlock(properties.get("name").replaceAll("\\\\n", "\n"))); } else {//ww w .java 2 s . c om da.setName(""); } }
From source file:org.kie.workbench.common.stunner.bpmn.backend.legacy.Bpmn2JsonUnmarshaller.java
protected void applyDataObjectProperties(DataObject da, Map<String, String> properties) { if (properties.get("name") != null && properties.get("name").length() > 0) { da.setName(StringEscapeUtils.escapeXml(properties.get("name")).replaceAll("\\r\\n|\\r|\\n", " ")); // add unescaped and untouched name value as extension element as well Utils.setMetaDataExtensionValue(da, "elementname", wrapInCDATABlock(properties.get("name").replaceAll("\\\\n", "\n"))); } else {// www.j a v a2 s .com // we need a name, use id instead da.setName(da.getId()); } boolean haveCustomType = false; if (properties.get("customtype") != null && properties.get("customtype").length() > 0) { ExtendedMetaData metadata = ExtendedMetaData.INSTANCE; EAttributeImpl extensionAttribute = (EAttributeImpl) metadata .demandFeature("http://www.jboss.org/drools", "datype", false, false); SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("customtype")); da.getAnyAttribute().add(extensionEntry); haveCustomType = true; } if (properties.get("standardtype") != null && properties.get("standardtype").length() > 0 && !haveCustomType) { ExtendedMetaData metadata = ExtendedMetaData.INSTANCE; EAttributeImpl extensionAttribute = (EAttributeImpl) metadata .demandFeature("http://www.jboss.org/drools", "datype", false, false); SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("standardtype")); da.getAnyAttribute().add(extensionEntry); } }
From source file:org.kie.workbench.common.stunner.bpmn.backend.legacy.Bpmn2JsonUnmarshaller.java
protected void applyTextAnnotationProperties(TextAnnotation ta, Map<String, String> properties) { if (properties.get("name") != null) { ta.setText(StringEscapeUtils.escapeXml(properties.get("name")).replaceAll("\\r\\n|\\r|\\n", " ")); // add unescaped and untouched name value as extension element as well Utils.setMetaDataExtensionValue(ta, "elementname", wrapInCDATABlock(properties.get("name").replaceAll("\\\\n", "\n"))); } else {//from w ww . j a v a 2 s . co m ta.setText(""); } // default ta.setTextFormat("text/plain"); if (properties.get("bordercolor") != null && properties.get("bordercolor").length() > 0) { if (!(_elementColors.containsKey(ta.getId()))) { List<String> colorsList = new ArrayList<String>(); colorsList.add("bordercolor:" + properties.get("bordercolor")); _elementColors.put(ta.getId(), colorsList); } else { _elementColors.get(ta.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")); ta.getAnyAttribute().add(extensionEntry); } if (properties.get("fontcolor") != null && properties.get("fontcolor").length() > 0) { if (!(_elementColors.containsKey(ta.getId()))) { List<String> colorsList = new ArrayList<String>(); colorsList.add("fontcolor:" + properties.get("fontcolor")); _elementColors.put(ta.getId(), colorsList); } else { _elementColors.get(ta.getId()).add("fontcolor:" + properties.get("fontcolor")); } } }
From source file:org.kie.workbench.common.stunner.bpmn.backend.legacy.Bpmn2JsonUnmarshaller.java
protected void applyEventProperties(Event event, Map<String, String> properties) { if (properties.get("name") != null) { event.setName(StringEscapeUtils.escapeXml(properties.get("name")).replaceAll("\\r\\n|\\r|\\n", " ")); // add unescaped and untouched name value as extension element as well Utils.setMetaDataExtensionValue(event, "elementname", wrapInCDATABlock(properties.get("name").replaceAll("\\\\n", "\n"))); } else {/*from w w w . j a v a2 s . c o m*/ event.setName(""); } if (properties.get("auditing") != null && !"".equals(properties.get("auditing"))) { Auditing audit = Bpmn2Factory.eINSTANCE.createAuditing(); audit.getDocumentation().add(createDocumentation(properties.get("auditing"))); event.setAuditing(audit); } if (properties.get("monitoring") != null && !"".equals(properties.get("monitoring"))) { Monitoring monitoring = Bpmn2Factory.eINSTANCE.createMonitoring(); monitoring.getDocumentation().add(createDocumentation(properties.get("monitoring"))); event.setMonitoring(monitoring); } }
From source file:org.kie.workbench.common.stunner.bpmn.backend.legacy.Bpmn2JsonUnmarshaller.java
protected void applyGlobalTaskProperties(GlobalTask globalTask, Map<String, String> properties) { if (properties.get("name") != null) { globalTask// w w w .j a va2 s . co m .setName(StringEscapeUtils.escapeXml(properties.get("name")).replaceAll("\\r\\n|\\r|\\n", " ")); } else { globalTask.setName(""); } // add unescaped and untouched name value as extension element as well Utils.setMetaDataExtensionValue(globalTask, "elementname", wrapInCDATABlock(properties.get("name").replaceAll("\\\\n", "\n"))); }
From source file:org.kie.workbench.common.stunner.bpmn.backend.legacy.Bpmn2JsonUnmarshaller.java
protected void applyProcessProperties(Process process, Map<String, String> properties) { if (properties.get("processn") != null) { process.setName(StringEscapeUtils.escapeXml(properties.get("processn"))); } else {/* w w w .j a v a 2s .c o m*/ process.setName(""); } if (properties.get("auditing") != null && !"".equals(properties.get("auditing"))) { Auditing audit = Bpmn2Factory.eINSTANCE.createAuditing(); audit.getDocumentation().add(createDocumentation(properties.get("auditing"))); process.setAuditing(audit); } process.setProcessType(ProcessType.getByName(properties.get("processtype"))); process.setIsClosed(Boolean.parseBoolean(properties.get("isclosed"))); process.setIsExecutable(Boolean.parseBoolean(properties.get("executable"))); // get the drools-specific extension packageName attribute to Process if defined if (properties.get("package") != null && properties.get("package").length() > 0) { ExtendedMetaData metadata = ExtendedMetaData.INSTANCE; EAttributeImpl extensionAttribute = (EAttributeImpl) metadata .demandFeature("http://www.jboss.org/drools", "packageName", false, false); SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("package")); process.getAnyAttribute().add(extensionEntry); } // add version attrbute to process if (properties.get("version") != null && properties.get("version").length() > 0) { ExtendedMetaData metadata = ExtendedMetaData.INSTANCE; EAttributeImpl extensionAttribute = (EAttributeImpl) metadata .demandFeature("http://www.jboss.org/drools", "version", false, false); SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("version")); process.getAnyAttribute().add(extensionEntry); } if (properties.get("monitoring") != null && !"".equals(properties.get("monitoring"))) { Monitoring monitoring = Bpmn2Factory.eINSTANCE.createMonitoring(); monitoring.getDocumentation().add(createDocumentation(properties.get("monitoring"))); process.setMonitoring(monitoring); } // import extension elements if (properties.get("imports") != null && properties.get("imports").length() > 0) { String[] allImports = properties.get("imports").split(",\\s*"); for (String importStr : allImports) { String[] importParts = importStr.split("\\|\\s*"); // sample 'com.sample.Myclass|default,location|namespace|wsdl if (importParts.length == 2 || importParts.length == 3) { if (importParts[1] != null && importParts[1].equals("default")) { ImportType importType = DroolsFactory.eINSTANCE.createImportType(); importType.setName(importParts[0]); if (process.getExtensionValues() == null || process.getExtensionValues().size() < 1) { ExtensionAttributeValue extensionElement = Bpmn2Factory.eINSTANCE .createExtensionAttributeValue(); process.getExtensionValues().add(extensionElement); } FeatureMap.Entry extensionElementEntry = new SimpleFeatureMapEntry( (Internal) DroolsPackage.Literals.DOCUMENT_ROOT__IMPORT, importType); process.getExtensionValues().get(0).getValue().add(extensionElementEntry); } else { Import imp = Bpmn2Factory.eINSTANCE.createImport(); imp.setImportType("http://schemas.xmlsoap.org/wsdl/"); imp.setLocation(importParts[0]); imp.setNamespace(importParts[1]); _wsdlImports.add(imp); } } else { // just default (support legacy) ImportType importType = DroolsFactory.eINSTANCE.createImportType(); importType.setName(importStr); if (process.getExtensionValues() == null || process.getExtensionValues().size() < 1) { ExtensionAttributeValue extensionElement = Bpmn2Factory.eINSTANCE .createExtensionAttributeValue(); process.getExtensionValues().add(extensionElement); } FeatureMap.Entry extensionElementEntry = new SimpleFeatureMapEntry( (Internal) DroolsPackage.Literals.DOCUMENT_ROOT__IMPORT, importType); process.getExtensionValues().get(0).getValue().add(extensionElementEntry); } } } // globals extension elements if (properties.get("globals") != null && properties.get("globals").length() > 0) { String[] allGlobals = properties.get("globals").split(",\\s*"); for (String globalStr : allGlobals) { String[] globalParts = globalStr.split(":\\s*"); // identifier:type if (globalParts.length == 2) { GlobalType globalType = DroolsFactory.eINSTANCE.createGlobalType(); globalType.setIdentifier(globalParts[0]); globalType.setType(globalParts[1]); if (process.getExtensionValues() == null || process.getExtensionValues().size() < 1) { ExtensionAttributeValue extensionElement = Bpmn2Factory.eINSTANCE .createExtensionAttributeValue(); process.getExtensionValues().add(extensionElement); } FeatureMap.Entry extensionElementEntry = new SimpleFeatureMapEntry( (Internal) DroolsPackage.Literals.DOCUMENT_ROOT__GLOBAL, globalType); process.getExtensionValues().get(0).getValue().add(extensionElementEntry); } else if (globalParts.length == 1) { GlobalType globalType = DroolsFactory.eINSTANCE.createGlobalType(); globalType.setIdentifier(globalParts[0]); globalType.setType("Object"); if (process.getExtensionValues() == null || process.getExtensionValues().size() < 1) { ExtensionAttributeValue extensionElement = Bpmn2Factory.eINSTANCE .createExtensionAttributeValue(); process.getExtensionValues().add(extensionElement); } FeatureMap.Entry extensionElementEntry = new SimpleFeatureMapEntry( (Internal) DroolsPackage.Literals.DOCUMENT_ROOT__GLOBAL, globalType); process.getExtensionValues().get(0).getValue().add(extensionElementEntry); } } } // simulation properties if (properties.get("timeunit") != null && properties.get("timeunit").length() > 0) { _simulationScenarioParameters.setBaseTimeUnit(TimeUnit.getByName(properties.get("timeunit"))); } if (properties.get("currency") != null && properties.get("currency").length() > 0) { _simulationScenarioParameters.setBaseCurrencyUnit(properties.get("currency")); } }
From source file:org.kie.workbench.common.stunner.bpmn.backend.legacy.Bpmn2JsonUnmarshaller.java
protected void applyLaneProperties(Lane lane, Map<String, String> properties) { if (properties.get("name") != null) { lane.setName(StringEscapeUtils.escapeXml(properties.get("name")).replaceAll("\\r\\n|\\r|\\n", " ")); // add unescaped and untouched name value as extension element as well Utils.setMetaDataExtensionValue(lane, "elementname", wrapInCDATABlock(properties.get("name").replaceAll("\\\\n", "\n"))); } else {/* www . j a v a 2 s. co m*/ lane.setName(""); } }
From source file:org.kie.workbench.common.stunner.bpmn.backend.legacy.Bpmn2JsonUnmarshaller.java
protected void applyCallActivityProperties(CallActivity callActivity, Map<String, String> properties) { if (properties.get("name") != null) { callActivity//from w w w . j av a2 s. c o m .setName(StringEscapeUtils.escapeXml(properties.get("name")).replaceAll("\\r\\n|\\r|\\n", " ")); // add unescaped and untouched name value as extension element as well Utils.setMetaDataExtensionValue(callActivity, "elementname", wrapInCDATABlock(properties.get("name").replaceAll("\\\\n", "\n"))); } else { callActivity.setName(""); } if (properties.get("isCase") != null) { Utils.setMetaDataExtensionValue(callActivity, "case", wrapInCDATABlock(properties.get("isCase"))); } if (properties.get("independent") != null && properties.get("independent").length() > 0) { ExtendedMetaData metadata = ExtendedMetaData.INSTANCE; EAttributeImpl extensionAttribute = (EAttributeImpl) metadata .demandFeature("http://www.jboss.org/drools", "independent", false, false); SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("independent")); callActivity.getAnyAttribute().add(extensionEntry); } if (properties.get("waitforcompletion") != null && properties.get("waitforcompletion").length() > 0) { ExtendedMetaData metadata = ExtendedMetaData.INSTANCE; EAttributeImpl extensionAttribute = (EAttributeImpl) metadata .demandFeature("http://www.jboss.org/drools", "waitForCompletion", false, false); SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("waitforcompletion")); callActivity.getAnyAttribute().add(extensionEntry); } if (properties.get("calledelement") != null && properties.get("calledelement").length() > 0) { callActivity.setCalledElement(properties.get("calledelement")); } // isAsync metadata if (properties.get("isasync") != null && properties.get("isasync").length() > 0 && properties.get("isasync").equals("true")) { Utils.setMetaDataExtensionValue(callActivity, "customAsync", wrapInCDATABlock(properties.get("isasync"))); } // adHocAutostart metadata if (properties.get("customautostart") != null && properties.get("customautostart").length() > 0 && properties.get("customautostart").equals("true")) { Utils.setMetaDataExtensionValue(callActivity, "customAutoStart", wrapInCDATABlock(properties.get("customautostart"))); } parseAssignmentsInfo(properties); //callActivity data input set applyDataInputProperties(callActivity, properties, new HashMap<String, DataInput>()); //callActivity data output set applyDataOutputProperties(callActivity, properties); //callActivity assignments if (properties.get("assignments") != null && properties.get("assignments").length() > 0) { String[] allAssignments = properties.get("assignments").split(",\\s*"); for (String assignment : allAssignments) { if (assignment.contains("=")) { String[] assignmentParts = assignment.split("=\\s*"); DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation(); String fromPart = assignmentParts[0]; if (fromPart.startsWith("[din]")) { fromPart = fromPart.substring(5, fromPart.length()); } boolean foundTaskName = false; if (callActivity.getIoSpecification() != null && callActivity.getIoSpecification().getDataOutputs() != null) { List<DataInput> dataInputs = callActivity.getIoSpecification().getDataInputs(); for (DataInput di : dataInputs) { if (di.getId().equals(callActivity.getId() + "_" + fromPart + "InputX")) { dia.setTargetRef(di); if (di.getName().equals("TaskName")) { foundTaskName = true; 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); callActivity.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 = callActivity.getIoSpecification().getDataInputs(); // for(DataInput di : dataInputs) { // if(di.getId().equals(callActivity.getId() + "_" + assignmentParts[1] + "InputX")) { // dia.setTargetRef(di); // break; // } // } // List<DataOutput> dataOutputs = callActivity.getIoSpecification().getDataOutputs(); // for(DataOutput dout : dataOutputs) { // if(dout.getId().equals(callActivity.getId() + "_" + assignmentParts[1] + "OutputX")) { // doa.getSourceRef().add(dout); // break; // } // } // // callActivity.getDataInputAssociations().add(dia); // callActivity.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 = callActivity.getIoSpecification().getDataOutputs(); if (isDataOutput) { // doing data output DataOutputAssociation doa = Bpmn2Factory.eINSTANCE.createDataOutputAssociation(); for (DataOutput dout : dataOutputs) { if (dout.getId().equals(callActivity.getId() + "_" + fromPart + "OutputX")) { doa.getSourceRef().add(dout); break; } } ItemAwareElement ie = Bpmn2Factory.eINSTANCE.createItemAwareElement(); ie.setId(assignmentParts[1]); doa.setTargetRef(ie); callActivity.getDataOutputAssociations().add(doa); } else if (isDataInput) { // doing data input 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 = callActivity.getIoSpecification().getDataInputs(); for (DataInput di : dataInputs) { if (di.getId().equals(callActivity.getId() + "_" + assignmentParts[1] + "InputX")) { dia.setTargetRef(di); break; } } callActivity.getDataInputAssociations().add(dia); } } else { // TODO throw exception here? } } } // process on-entry and on-exit actions as custom elements applyOnEntryActions(callActivity, properties); applyOnExitActions(callActivity, properties); // 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); } // individual time unit not supported in bpsim 1.0 // if(properties.get("timeunit") != null) { // timeParams.setTimeUnit(TimeUnit.getByName(properties.get("timeunit"))); // } 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(callActivity.getId())) { _simulationElementParameters.get(callActivity.getId()).add(timeParams); } else { List<EObject> values = new ArrayList<EObject>(); values.add(timeParams); _simulationElementParameters.put(callActivity.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); } // no individual currency unit supported in bpsim 1.0 // if(properties.get("currency") != null && properties.get("currency").length() > 0) { // costParameters.setCurrencyUnit(properties.get("currency")); // } if (_simulationElementParameters.containsKey(callActivity.getId())) { _simulationElementParameters.get(callActivity.getId()).add(costParameters); } else { List<EObject> values = new ArrayList<EObject>(); values.add(costParameters); _simulationElementParameters.put(callActivity.getId(), values); } }
From source file:org.kie.workbench.common.stunner.bpmn.backend.legacy.Bpmn2JsonUnmarshaller.java
protected void applyTaskProperties(Task task, Map<String, String> properties, String preProcessingData) { if (properties.get("name") != null) { task.setName(StringEscapeUtils.escapeXml(properties.get("name")).replaceAll("\\r\\n|\\r|\\n", " ")); } else {//w ww. jav a2 s . c om task.setName(""); } // add unescaped and untouched name value as extension element as well Utils.setMetaDataExtensionValue(task, "elementname", wrapInCDATABlock(properties.get("name").replaceAll("\\\\n", "\n"))); DataInput taskNameDataInput = null; if (properties.get("taskname") != null && properties.get("taskname").length() > 0) { if (isCustomElement(properties.get("tasktype"), preProcessingData)) { // add kiegroup-specific attribute "taskName" ExtendedMetaData metadata = ExtendedMetaData.INSTANCE; EAttributeImpl extensionAttribute = (EAttributeImpl) metadata .demandFeature("http://www.jboss.org/drools", "taskName", false, false); SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("taskname").replaceAll("&", "").replaceAll(" ", "")); task.getAnyAttribute().add(extensionEntry); } // map the taskName to iospecification taskNameDataInput = Bpmn2Factory.eINSTANCE.createDataInput(); taskNameDataInput.setId(task.getId() + "_TaskNameInputX"); taskNameDataInput.setName("TaskName"); // Make the DataInput a String ExtendedMetaData metadata = ExtendedMetaData.INSTANCE; EAttributeImpl extensionAttribute = (EAttributeImpl) metadata .demandFeature("http://www.jboss.org/drools", "dtype", false, false); SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, "String"); taskNameDataInput.getAnyAttribute().add(extensionEntry); if (task.getIoSpecification() == null) { InputOutputSpecification iospec = Bpmn2Factory.eINSTANCE.createInputOutputSpecification(); task.setIoSpecification(iospec); } task.getIoSpecification().getDataInputs().add(taskNameDataInput); // taskName also needs to be in dataInputAssociation DataInputAssociation taskNameDataInputAssociation = Bpmn2Factory.eINSTANCE.createDataInputAssociation(); taskNameDataInputAssociation.setTargetRef(taskNameDataInput); Assignment taskNameAssignment = Bpmn2Factory.eINSTANCE.createAssignment(); FormalExpression fromExp = Bpmn2Factory.eINSTANCE.createFormalExpression(); fromExp.setBody(properties.get("taskname").replaceAll("&", "").replaceAll(" ", "")); taskNameAssignment.setFrom(fromExp); FormalExpression toExp = Bpmn2Factory.eINSTANCE.createFormalExpression(); toExp.setBody(task.getId() + "_TaskNameInputX"); taskNameAssignment.setTo(toExp); taskNameDataInputAssociation.getAssignment().add(taskNameAssignment); task.getDataInputAssociations().add(taskNameDataInputAssociation); } //process lanes if (properties.get("lanes") != null && properties.get("lanes").length() > 0) { ExtendedMetaData metadata = ExtendedMetaData.INSTANCE; EAttributeImpl extensionAttribute = (EAttributeImpl) metadata .demandFeature("http://www.jboss.org/drools", "lanes", false, false); SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("lanes")); task.getAnyAttribute().add(extensionEntry); } // isAsync metadata if (properties.get("isasync") != null && properties.get("isasync").length() > 0 && properties.get("isasync").equals("true")) { Utils.setMetaDataExtensionValue(task, "customAsync", wrapInCDATABlock(properties.get("isasync"))); } // autostart metadata if (properties.get("customautostart") != null && properties.get("customautostart").length() > 0 && properties.get("customautostart").equals("true")) { Utils.setMetaDataExtensionValue(task, "customAutoStart", wrapInCDATABlock(properties.get("customautostart"))); } parseAssignmentsInfo(properties); //process data input set Map<String, DataInput> alreadyProcessedInputs = new HashMap<String, DataInput>(); alreadyProcessedInputs.put("TaskName", taskNameDataInput); applyDataInputProperties(task, properties, alreadyProcessedInputs); for (DataInput processedInput : alreadyProcessedInputs.values()) { if (processedInput != null) { task.getIoSpecification().getInputSets().get(0).getDataInputRefs().add(processedInput); } } //process data output set applyDataOutputProperties(task, properties); //process assignments if (properties.get("assignments") != null && properties.get("assignments").length() > 0) { String[] allAssignments = properties.get("assignments").split(",\\s*"); for (String assignment : allAssignments) { if (assignment.contains("=")) { String[] assignmentParts = assignment.split("=\\s*"); String fromPart = assignmentParts[0]; if (fromPart.startsWith("[din]")) { fromPart = fromPart.substring(5, fromPart.length()); } DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation(); boolean foundTaskName = false; if (task.getIoSpecification() != null && task.getIoSpecification().getDataOutputs() != null) { List<DataInput> dataInputs = task.getIoSpecification().getDataInputs(); for (DataInput di : dataInputs) { if (di.getId().equals(task.getId() + "_" + fromPart + (fromPart.endsWith("InputX") ? "" : "InputX"))) { dia.setTargetRef(di); if (di.getName().equals("TaskName")) { foundTaskName = true; break; } } } } // if we are dealing with TaskName and none has been defined, add it if (fromPart.equals("TaskName") && !foundTaskName) { DataInput assignmentTaskNameDataInput = Bpmn2Factory.eINSTANCE.createDataInput(); assignmentTaskNameDataInput.setId(task.getId() + "_TaskNameInputX"); assignmentTaskNameDataInput.setName("TaskName"); if (task.getIoSpecification() == null) { InputOutputSpecification iospec = Bpmn2Factory.eINSTANCE .createInputOutputSpecification(); task.setIoSpecification(iospec); } task.getIoSpecification().getDataInputs().add(assignmentTaskNameDataInput); dia.setTargetRef(assignmentTaskNameDataInput); InputSet inset = task.getIoSpecification().getInputSets().get(0); inset.getDataInputRefs().add(assignmentTaskNameDataInput); } Assignment a = Bpmn2Factory.eINSTANCE.createAssignment(); FormalExpression fromExpression = Bpmn2Factory.eINSTANCE.createFormalExpression(); if (assignmentParts.length > 1) { String replacer = decodeAssociationValue(assignmentParts[1]); fromExpression.setBody(wrapInCDATABlock(replacer)); } else { // for custom workitem properties check individually for values if (properties.get(fromPart.toLowerCase()) != null && properties.get(fromPart.toLowerCase()).length() > 0) { fromExpression.setBody(properties.get(fromPart.toLowerCase())); } else { fromExpression.setBody(""); } } FormalExpression toExpression = Bpmn2Factory.eINSTANCE.createFormalExpression(); toExpression.setBody(dia.getTargetRef().getId()); a.setFrom(fromExpression); a.setTo(toExpression); dia.getAssignment().add(a); task.getDataInputAssociations().add(dia); // } else if(assignment.contains("<->")) { // String[] assignmentParts = assignment.split( "<->\\s*" ); // DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation(); // DataOutputAssociation doa = Bpmn2Factory.eINSTANCE.createDataOutputAssociation(); // // ItemAwareElement ie = Bpmn2Factory.eINSTANCE.createItemAwareElement(); // ie.setId(assignmentParts[0]); // dia.getSourceRef().add(ie); // doa.setTargetRef(ie); // // List<DataInput> dataInputs = task.getIoSpecification().getDataInputs(); // for(DataInput di : dataInputs) { // if(di.getId().equals(task.getId() + "_" + assignmentParts[1] + (assignmentParts[1].endsWith("InputX") ? "" : "InputX"))) { // dia.setTargetRef(di); // break; // } // } // List<DataOutput> dataOutputs = task.getIoSpecification().getDataOutputs(); // for(DataOutput dout : dataOutputs) { // if(dout.getId().equals(task.getId() + "_" + assignmentParts[1] + (assignmentParts[1].endsWith("OutputX") ? "" : "OutputX"))) { // doa.getSourceRef().add(dout); // break; // } // } // task.getDataInputAssociations().add(dia); // task.getDataOutputAssociations().add(doa); } else if (assignment.contains("->")) { String[] assignmentParts = assignment.split("->\\s*"); String fromPart = assignmentParts[0]; boolean isDataInput = false; boolean isDataOutput = false; if (fromPart.startsWith("[din]")) { fromPart = fromPart.substring(5, fromPart.length()); isDataInput = true; } if (fromPart.startsWith("[dout]")) { fromPart = fromPart.substring(6, fromPart.length()); isDataOutput = true; } List<DataOutput> dataOutputs = task.getIoSpecification().getDataOutputs(); if (isDataOutput) { DataOutputAssociation doa = Bpmn2Factory.eINSTANCE.createDataOutputAssociation(); for (DataOutput dout : dataOutputs) { if (dout.getId().equals(task.getId() + "_" + fromPart + (fromPart.endsWith("OutputX") ? "" : "OutputX"))) { doa.getSourceRef().add(dout); break; } } ItemAwareElement ie = Bpmn2Factory.eINSTANCE.createItemAwareElement(); ie.setId(assignmentParts[1]); doa.setTargetRef(ie); task.getDataOutputAssociations().add(doa); } else if (isDataInput) { DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation(); // association from process var to dataInput var ItemAwareElement ie = Bpmn2Factory.eINSTANCE.createItemAwareElement(); ie.setId(fromPart); dia.getSourceRef().add(ie); List<DataInput> dataInputs = task.getIoSpecification().getDataInputs(); for (DataInput di : dataInputs) { if (di.getId().equals(task.getId() + "_" + assignmentParts[1] + (assignmentParts[1].endsWith("InputX") ? "" : "InputX"))) { dia.setTargetRef(di); break; } } task.getDataInputAssociations().add(dia); } } else { // TODO throw exception here? } } // check if multiple taskname datainput associations exist and remove them List<DataInputAssociation> dataInputAssociations = task.getDataInputAssociations(); boolean haveTaskNameInput = false; for (Iterator<DataInputAssociation> itr = dataInputAssociations.iterator(); itr.hasNext();) { DataInputAssociation da = itr.next(); if (da.getAssignment() != null && da.getAssignment().size() > 0) { Assignment a = da.getAssignment().get(0); if (((FormalExpression) a.getTo()).getBody().equals(task.getId() + "_TaskNameInputX")) { if (!haveTaskNameInput) { haveTaskNameInput = true; } else { itr.remove(); } } } } } // process on-entry and on-exit actions as custom elements applyOnEntryActions(task, properties); applyOnExitActions(task, properties); // multi instance if (properties.get("multipleinstance") != null && properties.get("multipleinstance").length() > 0 && properties.get("multipleinstance").equals("true")) { // will be revisited at end ExtendedMetaData metadata = ExtendedMetaData.INSTANCE; EAttributeImpl extensionAttribute = (EAttributeImpl) metadata .demandFeature("http://www.jboss.org/drools", "mitask", false, false); StringBuffer buff = new StringBuffer(); buff.append((properties.get("multipleinstancecollectioninput") != null && properties.get("multipleinstancecollectioninput").length() > 0) ? properties.get("multipleinstancecollectioninput") : " "); buff.append("@"); buff.append((properties.get("multipleinstancecollectionoutput") != null && properties.get("multipleinstancecollectionoutput").length() > 0) ? properties.get("multipleinstancecollectionoutput") : " "); buff.append("@"); buff.append((properties.get("multipleinstancedatainput") != null && properties.get("multipleinstancedatainput").length() > 0) ? properties.get("multipleinstancedatainput") : " "); buff.append("@"); buff.append((properties.get("multipleinstancedataoutput") != null && properties.get("multipleinstancedataoutput").length() > 0) ? properties.get("multipleinstancedataoutput") : " "); buff.append("@"); buff.append((properties.get("multipleinstancecompletioncondition") != null && properties.get("multipleinstancecompletioncondition").length() > 0) ? properties.get("multipleinstancecompletioncondition") : " "); SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, buff.toString()); task.getAnyAttribute().add(extensionEntry); } // simulation if (properties.get("distributiontype") != null && properties.get("distributiontype").length() > 0) { TimeParameters timeParams = BpsimFactory.eINSTANCE.createTimeParameters(); Parameter processingTimeParam = BpsimFactory.eINSTANCE.createParameter(); if (properties.get("distributiontype").equals("normal")) { NormalDistributionType normalDistributionType = BpsimFactory.eINSTANCE .createNormalDistributionType(); normalDistributionType.setStandardDeviation(Double.valueOf(properties.get("standarddeviation"))); normalDistributionType.setMean(Double.valueOf(properties.get("mean"))); processingTimeParam.getParameterValue().add(normalDistributionType); } else if (properties.get("distributiontype").equals("uniform")) { UniformDistributionType uniformDistributionType = BpsimFactory.eINSTANCE .createUniformDistributionType(); uniformDistributionType.setMax(Double.valueOf(properties.get("max"))); uniformDistributionType.setMin(Double.valueOf(properties.get("min"))); processingTimeParam.getParameterValue().add(uniformDistributionType); // random distribution not supported in bpsim 1.0 // } else if(properties.get("distributiontype").equals("random")) { // RandomDistributionType randomDistributionType = BpsimFactory.eINSTANCE.createRandomDistributionType(); // randomDistributionType.setMax(Double.valueOf(properties.get("max"))); // randomDistributionType.setMin(Double.valueOf(properties.get("min"))); // processingTimeParam.getParameterValue().add(randomDistributionType); } else if (properties.get("distributiontype").equals("poisson")) { PoissonDistributionType poissonDistributionType = BpsimFactory.eINSTANCE .createPoissonDistributionType(); poissonDistributionType.setMean(Double.valueOf(properties.get("mean"))); processingTimeParam.getParameterValue().add(poissonDistributionType); } // individual time unit not supported in bpsim 1.0 // if(properties.get("timeunit") != null) { // timeParams.setTimeUnit(TimeUnit.getByName(properties.get("timeunit"))); // } if (properties.get("waittime") != null) { Parameter waittimeParam = BpsimFactory.eINSTANCE.createParameter(); FloatingParameterType waittimeParamValue = BpsimFactory.eINSTANCE.createFloatingParameterType(); DecimalFormat twoDForm = new DecimalFormat("#.##"); waittimeParamValue .setValue(Double.valueOf(twoDForm.format(Double.valueOf(properties.get("waittime"))))); waittimeParam.getParameterValue().add(waittimeParamValue); timeParams.setWaitTime(waittimeParam); } timeParams.setProcessingTime(processingTimeParam); if (_simulationElementParameters.containsKey(task.getId())) { _simulationElementParameters.get(task.getId()).add(timeParams); } else { List<EObject> values = new ArrayList<EObject>(); values.add(timeParams); _simulationElementParameters.put(task.getId(), values); } } CostParameters costParameters = BpsimFactory.eINSTANCE.createCostParameters(); if (properties.get("unitcost") != null && properties.get("unitcost").length() > 0) { Parameter unitcostParam = BpsimFactory.eINSTANCE.createParameter(); FloatingParameterType unitCostParameterValue = BpsimFactory.eINSTANCE.createFloatingParameterType(); unitCostParameterValue.setValue(new Double(properties.get("unitcost"))); unitcostParam.getParameterValue().add(unitCostParameterValue); costParameters.setUnitCost(unitcostParam); } // no individual currency unit supported in bpsim 1.0 // if(properties.get("currency") != null && properties.get("currency").length() > 0) { // costParameters.setCurrencyUnit(properties.get("currency")); // } if (_simulationElementParameters.containsKey(task.getId())) { _simulationElementParameters.get(task.getId()).add(costParameters); } else { List<EObject> values = new ArrayList<EObject>(); values.add(costParameters); _simulationElementParameters.put(task.getId(), values); } }
From source file:org.kie.workbench.common.stunner.bpmn.backend.legacy.Bpmn2JsonUnmarshaller.java
protected void applyGatewayProperties(Gateway gateway, Map<String, String> properties) { if (properties.get("name") != null && properties.get("name").length() > 0) { gateway.setName(StringEscapeUtils.escapeXml(properties.get("name")).replaceAll("\\r\\n|\\r|\\n", " ")); // add unescaped and untouched name value as extension element as well Utils.setMetaDataExtensionValue(gateway, "elementname", wrapInCDATABlock(properties.get("name").replaceAll("\\\\n", "\n"))); } else {//from w ww . j a v a 2 s . c o m gateway.setName(""); } if (properties.get("defaultgate") != null && (gateway instanceof InclusiveGateway || gateway instanceof ExclusiveGateway)) { ExtendedMetaData metadata = ExtendedMetaData.INSTANCE; EAttributeImpl extensionAttribute = (EAttributeImpl) metadata .demandFeature("http://www.jboss.org/drools", "dg", false, false); SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, properties.get("defaultgate")); gateway.getAnyAttribute().add(extensionEntry); } }