use of org.eclipse.emf.ecore.util.ExtendedMetaData in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method applyGatewayProperties.
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 {
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);
}
}
use of org.eclipse.emf.ecore.util.ExtendedMetaData in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method applyBaseElementProperties.
protected void applyBaseElementProperties(BaseElement baseElement, Map<String, String> properties) {
if (properties.get("documentation") != null && !"".equals(properties.get("documentation"))) {
if (baseElement instanceof Definitions) {
this.processDocs = properties.get("documentation");
} else {
baseElement.getDocumentation().add(createDocumentation(wrapInCDATABlock(properties.get("documentation"))));
}
}
if (baseElement.getId() == null || baseElement.getId().length() < 1) {
baseElement.setId(properties.get("resourceId"));
}
if (properties.get("bgcolor") != null && properties.get("bgcolor").length() > 0) {
if (!(_elementColors.containsKey(baseElement.getId()))) {
List<String> colorsList = new ArrayList<String>();
colorsList.add("bgcolor:" + properties.get("bgcolor"));
_elementColors.put(baseElement.getId(), colorsList);
} else {
_elementColors.get(baseElement.getId()).add("bgcolor:" + properties.get("bgcolor"));
}
}
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"));
baseElement.getAnyAttribute().add(extensionEntry);
}
if (properties.get("bordercolor") != null && properties.get("bordercolor").length() > 0) {
if (!(_elementColors.containsKey(baseElement.getId()))) {
List<String> colorsList = new ArrayList<String>();
colorsList.add("bordercolor:" + properties.get("bordercolor"));
_elementColors.put(baseElement.getId(), colorsList);
} else {
_elementColors.get(baseElement.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"));
baseElement.getAnyAttribute().add(extensionEntry);
}
if (properties.get("fontcolor") != null && properties.get("fontcolor").length() > 0) {
if (!(_elementColors.containsKey(baseElement.getId()))) {
List<String> colorsList = new ArrayList<String>();
colorsList.add("fontcolor:" + properties.get("fontcolor"));
_elementColors.put(baseElement.getId(), colorsList);
} else {
_elementColors.get(baseElement.getId()).add("fontcolor:" + properties.get("fontcolor"));
}
}
}
use of org.eclipse.emf.ecore.util.ExtendedMetaData in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method applyTextAnnotationProperties.
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 {
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"));
}
}
}
use of org.eclipse.emf.ecore.util.ExtendedMetaData 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);
}
}
}
use of org.eclipse.emf.ecore.util.ExtendedMetaData in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method applyDataOutputProperties.
private void applyDataOutputProperties(Activity activity, Map<String, String> properties) {
if (properties.get("dataoutputset") != null && properties.get("dataoutputset").trim().length() > 0) {
String[] allDataOutputs = properties.get("dataoutputset").split(",\\s*");
if (activity.getIoSpecification() == null) {
InputOutputSpecification iospec = Bpmn2Factory.eINSTANCE.createInputOutputSpecification();
activity.setIoSpecification(iospec);
}
OutputSet outset = Bpmn2Factory.eINSTANCE.createOutputSet();
for (String dataOutput : allDataOutputs) {
if (dataOutput.trim().length() > 0) {
DataOutput nextOut = Bpmn2Factory.eINSTANCE.createDataOutput();
String[] dataOutputParts = dataOutput.split(":\\s*");
if (dataOutputParts.length == 2) {
nextOut.setId(activity.getId() + "_" + dataOutputParts[0] + (dataOutputParts[0].endsWith("OutputX") ? "" : "OutputX"));
nextOut.setName(dataOutputParts[0]);
ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "dtype", false, false);
SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, dataOutputParts[1]);
nextOut.getAnyAttribute().add(extensionEntry);
} else {
nextOut.setId(activity.getId() + "_" + dataOutput + (dataOutput.endsWith("OutputX") ? "" : "OutputX"));
nextOut.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");
nextOut.getAnyAttribute().add(extensionEntry);
}
activity.getIoSpecification().getDataOutputs().add(nextOut);
outset.getDataOutputRefs().add(nextOut);
}
}
activity.getIoSpecification().getOutputSets().add(outset);
} else {
if (activity.getIoSpecification() != null) {
activity.getIoSpecification().getOutputSets().add(Bpmn2Factory.eINSTANCE.createOutputSet());
}
}
}
Aggregations