use of org.eclipse.bpmn2.FormalExpression in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method applyTimerEventProperties.
protected void applyTimerEventProperties(TimerEventDefinition timerEventDef, Map<String, String> properties) {
String timeDate;
String timeDuration;
String timeCycle;
String timeCycleLanguage;
String timerSettings;
timerSettings = properties.get(TIMERSETTINGS);
if (timerSettings != null && !"".equals(timerSettings)) {
TimerSettingsValue timerSettingsObj = new TimerSettingsTypeSerializer().parse(timerSettings);
timeDate = timerSettingsObj.getTimeDate();
timeDuration = timerSettingsObj.getTimeDuration();
timeCycle = timerSettingsObj.getTimeCycle();
timeCycleLanguage = timerSettingsObj.getTimeCycleLanguage();
} else {
timeDate = properties.get(TIMEDATE);
timeDuration = properties.get(TIMEDURATION);
timeCycle = properties.get(TIMECYCLE);
timeCycleLanguage = properties.get(TIMECYCLELANGUAGE);
}
if (timeDate != null && !"".equals(timeDate)) {
FormalExpression timeDateExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
timeDateExpression.setBody(timeDate);
timerEventDef.setTimeDate(timeDateExpression);
}
if (timeDuration != null && !"".equals(timeDuration)) {
FormalExpression timeDurationExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
timeDurationExpression.setBody(timeDuration);
timerEventDef.setTimeDuration(timeDurationExpression);
}
if (timeCycle != null && !"".equals(timeCycle)) {
FormalExpression timeCycleExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
timeCycleExpression.setBody(timeCycle);
if (timeCycleLanguage != null && timeCycleLanguage.length() > 0) {
timeCycleExpression.setLanguage(timeCycleLanguage);
}
timerEventDef.setTimeCycle(timeCycleExpression);
}
}
use of org.eclipse.bpmn2.FormalExpression in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method applyAdHocSubProcessProperties.
protected void applyAdHocSubProcessProperties(AdHocSubProcess ahsp, Map<String, String> properties) {
if (properties.get("adhocordering") != null) {
if (properties.get("adhocordering").equals("Parallel")) {
ahsp.setOrdering(AdHocOrdering.PARALLEL);
} else {
ahsp.setOrdering(AdHocOrdering.SEQUENTIAL);
}
}
String adHocCompletionCondition = properties.get("adhoccompletioncondition");
if (adHocCompletionCondition != null) {
ScriptTypeValue value = new ScriptTypeTypeSerializer().parse(adHocCompletionCondition);
FormalExpression completionConditionExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
String completionExpression = value.getScript();
if (completionExpression == null || completionExpression.isEmpty()) {
// default to autocomplete
completionExpression = "autocomplete";
}
completionConditionExpression.setBody(wrapInCDATABlock(completionExpression));
String languageFormat = Utils.getScriptLanguageFormat(value.getLanguage());
if (languageFormat == null) {
// default to mvel
languageFormat = "mvel";
}
completionConditionExpression.setLanguage(languageFormat);
ahsp.setCompletionCondition(completionConditionExpression);
}
}
use of org.eclipse.bpmn2.FormalExpression in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method revisitMultiInstanceTasks.
public void revisitMultiInstanceTasks(Definitions def) {
try {
List<RootElement> rootElements = def.getRootElements();
for (RootElement root : rootElements) {
if (root instanceof Process) {
Process process = (Process) root;
List<FlowElement> flowElements = process.getFlowElements();
for (FlowElement fe : flowElements) {
if (fe instanceof Task) {
Task task = (Task) fe;
Iterator<FeatureMap.Entry> iter = task.getAnyAttribute().iterator();
while (iter.hasNext()) {
FeatureMap.Entry entry = iter.next();
if (entry.getEStructuralFeature().getName().equals("mitask")) {
String multiValue = (String) entry.getValue();
String[] multiValueParts = multiValue.split("@");
if (multiValueParts != null && multiValueParts.length == 5) {
String miCollectionInput = (multiValueParts[0].equals(" ") ? "" : multiValueParts[0]);
String miCollectionOutput = (multiValueParts[1].equals(" ") ? "" : multiValueParts[1]);
String miDataInput = (multiValueParts[2].equals(" ") ? "" : multiValueParts[2]);
String miDataOutput = (multiValueParts[3].equals(" ") ? "" : multiValueParts[3]);
String miCompletionCondition = (multiValueParts[4].equals(" ") ? "" : multiValueParts[4]);
MultiInstanceLoopCharacteristics loopCharacteristics = Bpmn2Factory.eINSTANCE.createMultiInstanceLoopCharacteristics();
if (miCollectionInput != null && miCollectionInput.length() > 0) {
List<Property> properties = process.getProperties();
for (Property prop : properties) {
if (prop.getId() != null && prop.getId().equals(miCollectionInput)) {
DataInput miCollectionInputDI = Bpmn2Factory.eINSTANCE.createDataInput();
miCollectionInputDI.setName("miinputCollection");
ItemDefinition miCollectionInputDIItemDefinition = this.getMessageItemDefinition(def.getRootElements(), prop.getId());
miCollectionInputDI.setItemSubjectRef(miCollectionInputDIItemDefinition);
task.getIoSpecification().getDataInputs().add(miCollectionInputDI);
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(miCollectionInputDI);
loopCharacteristics.setLoopDataInputRef(miCollectionInputDI);
DataInputAssociation miCollectionInputDataInputAssociation = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
miCollectionInputDataInputAssociation.getSourceRef().add(prop);
miCollectionInputDataInputAssociation.setTargetRef(miCollectionInputDI);
task.getDataInputAssociations().add(miCollectionInputDataInputAssociation);
break;
}
}
}
if (miCollectionOutput != null && miCollectionOutput.length() > 0) {
List<Property> properties = process.getProperties();
for (Property prop : properties) {
if (prop.getId() != null && prop.getId().equals(miCollectionOutput)) {
DataOutput miCollectionOutputDI = Bpmn2Factory.eINSTANCE.createDataOutput();
miCollectionOutputDI.setName("mioutputCollection");
ItemDefinition miCollectionOutputDIItemDefinition = this.getMessageItemDefinition(def.getRootElements(), prop.getId());
miCollectionOutputDI.setItemSubjectRef(miCollectionOutputDIItemDefinition);
task.getIoSpecification().getDataOutputs().add(miCollectionOutputDI);
if (task.getIoSpecification().getOutputSets() == null || task.getIoSpecification().getOutputSets().size() < 1) {
OutputSet outset = Bpmn2Factory.eINSTANCE.createOutputSet();
task.getIoSpecification().getOutputSets().add(outset);
}
task.getIoSpecification().getOutputSets().get(0).getDataOutputRefs().add(miCollectionOutputDI);
loopCharacteristics.setLoopDataOutputRef(miCollectionOutputDI);
DataOutputAssociation miCollectionInputDataOutputAssociation = Bpmn2Factory.eINSTANCE.createDataOutputAssociation();
miCollectionInputDataOutputAssociation.setTargetRef(prop);
miCollectionInputDataOutputAssociation.getSourceRef().add(miCollectionOutputDI);
task.getDataOutputAssociations().add(miCollectionInputDataOutputAssociation);
break;
}
}
}
if (miDataInput != null && miDataInput.length() > 0) {
List<DataInput> dins = task.getIoSpecification().getDataInputs();
for (DataInput di : dins) {
if (di.getName().equals(miDataInput)) {
DataInput inputDataItemObj = Bpmn2Factory.eINSTANCE.createDataInput();
inputDataItemObj.setId("miDataInputX");
inputDataItemObj.setItemSubjectRef(di.getItemSubjectRef());
loopCharacteristics.setInputDataItem(inputDataItemObj);
break;
}
}
}
if (miDataOutput != null && miDataOutput.length() > 0) {
List<DataOutput> douts = task.getIoSpecification().getDataOutputs();
for (DataOutput dout : douts) {
if (dout.getName().equals(miDataOutput)) {
DataOutput outputDataItemObj = Bpmn2Factory.eINSTANCE.createDataOutput();
outputDataItemObj.setId("miDataOutputX");
outputDataItemObj.setItemSubjectRef(dout.getItemSubjectRef());
loopCharacteristics.setOutputDataItem(outputDataItemObj);
break;
}
}
}
if (miCompletionCondition != null && !miCompletionCondition.isEmpty()) {
FormalExpression expr = Bpmn2Factory.eINSTANCE.createFormalExpression();
expr.setBody(miCompletionCondition);
loopCharacteristics.setCompletionCondition(expr);
}
task.setLoopCharacteristics(loopCharacteristics);
if (miDataInput != null && miDataInput.length() > 0 && ((MultiInstanceLoopCharacteristics) task.getLoopCharacteristics()).getInputDataItem() != null) {
DataInputAssociation dias = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
dias.getSourceRef().add(((MultiInstanceLoopCharacteristics) task.getLoopCharacteristics()).getInputDataItem());
List<DataInput> dins = task.getIoSpecification().getDataInputs();
for (DataInput di : dins) {
if (di.getName().equals(miDataInput)) {
dias.setTargetRef(di);
task.getDataInputAssociations().add(dias);
break;
}
}
}
if (miDataOutput != null && miDataOutput.length() > 0 && ((MultiInstanceLoopCharacteristics) task.getLoopCharacteristics()).getOutputDataItem() != null) {
DataOutputAssociation dout = Bpmn2Factory.eINSTANCE.createDataOutputAssociation();
dout.setTargetRef(((MultiInstanceLoopCharacteristics) task.getLoopCharacteristics()).getOutputDataItem());
List<DataOutput> douts = task.getIoSpecification().getDataOutputs();
for (DataOutput dou : douts) {
if (dou.getName().equals(miDataOutput)) {
dout.getSourceRef().add(dou);
task.getDataOutputAssociations().add(dout);
break;
}
}
}
}
}
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.eclipse.bpmn2.FormalExpression in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method applyThrowEventProperties.
protected void applyThrowEventProperties(ThrowEvent event, Map<String, String> properties) {
parseAssignmentsInfo(properties);
if (properties.get("datainput") != null && properties.get("datainput").trim().length() > 0) {
String[] allDataInputs = properties.get("datainput").split(",\\s*");
InputSet inset = Bpmn2Factory.eINSTANCE.createInputSet();
for (String dataInput : allDataInputs) {
if (dataInput.trim().length() > 0) {
DataInput nextInput = Bpmn2Factory.eINSTANCE.createDataInput();
String[] dataInputParts = dataInput.split(":\\s*");
if (dataInputParts.length == 2) {
nextInput.setId(event.getId() + "_" + dataInputParts[0] + (dataInputParts[0].endsWith("InputX") ? "" : "InputX"));
nextInput.setName(dataInputParts[0]);
ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "dtype", false, false);
SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, dataInputParts[1]);
nextInput.getAnyAttribute().add(extensionEntry);
} else {
nextInput.setId(event.getId() + "_" + dataInput + (dataInput.endsWith("InputX") ? "" : "InputX"));
nextInput.setName(dataInput);
ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
EAttributeImpl extensionAttribute = (EAttributeImpl) metadata.demandFeature("http://www.jboss.org/drools", "dtype", false, false);
SimpleFeatureMapEntry extensionEntry = new SimpleFeatureMapEntry(extensionAttribute, "Object");
nextInput.getAnyAttribute().add(extensionEntry);
}
event.getDataInputs().add(nextInput);
inset.getDataInputRefs().add(nextInput);
}
}
event.setInputSet(inset);
}
if (properties.get("datainputassociations") != null && properties.get("datainputassociations").length() > 0) {
String[] allAssignments = properties.get("datainputassociations").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 (event.getInputSet() != null) {
List<DataInput> dataInputs = event.getInputSet().getDataInputRefs();
for (DataInput di : dataInputs) {
if (di.getId().equals(event.getId() + "_" + fromPart + (fromPart.endsWith("InputX") ? "" : "InputX"))) {
dia.setTargetRef(di);
}
}
}
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);
event.getDataInputAssociation().add(dia);
} 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 (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 = event.getInputSet().getDataInputRefs();
for (DataInput di : dataInputs) {
if (di.getId().equals(event.getId() + "_" + assignmentParts[1] + (assignmentParts[1].endsWith("InputX") ? "" : "InputX"))) {
dia.setTargetRef(di);
break;
}
}
event.getDataInputAssociation().add(dia);
}
} else {
// TODO throw exception here?
}
}
}
// signal scope metadata
if (properties.get("signalscope") != null && properties.get("signalscope").length() > 0 && !properties.get("signalscope").equals("default")) {
Utils.setMetaDataExtensionValue(event, "customScope", wrapInCDATABlock(properties.get("signalscope")));
}
try {
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 (IndexOutOfBoundsException e) {
// TODO we dont want to barf here as test for example do not define event definitions in the bpmn2....
}
// 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);
}
}
}
use of org.eclipse.bpmn2.FormalExpression in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method applyTaskProperties.
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 {
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);
}
// }
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);
}
// }
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);
}
}
Aggregations