use of org.eclipse.bpmn2.ItemAwareElement in project kie-wb-common by kiegroup.
the class Bpmn2JsonMarshaller method marshallTask.
protected void marshallTask(Task task, BPMNPlane plane, JsonGenerator generator, float xOffset, float yOffset, String preProcessingData, Definitions def, Map<String, Object> flowElementProperties) throws JsonGenerationException, IOException {
Map<String, Object> properties = new LinkedHashMap<String, Object>(flowElementProperties);
String taskType = "None";
if (task instanceof BusinessRuleTask) {
taskType = "Business Rule";
Iterator<FeatureMap.Entry> iter = task.getAnyAttribute().iterator();
while (iter.hasNext()) {
FeatureMap.Entry entry = iter.next();
if (entry.getEStructuralFeature().getName().equals("ruleFlowGroup")) {
properties.put("ruleflowgroup", entry.getValue());
}
}
} else if (task instanceof ScriptTask) {
setScriptProperties((ScriptTask) task, properties);
taskType = "Script";
} else if (task instanceof ServiceTask) {
taskType = "Service";
ServiceTask serviceTask = (ServiceTask) task;
if (serviceTask.getOperationRef() != null && serviceTask.getImplementation() != null) {
properties.put("serviceimplementation", serviceTask.getImplementation());
properties.put("serviceoperation", serviceTask.getOperationRef().getName() == null ? serviceTask.getOperationRef().getImplementationRef() : serviceTask.getOperationRef().getName());
if (def != null) {
List<RootElement> roots = def.getRootElements();
for (RootElement root : roots) {
if (root instanceof Interface) {
Interface inter = (Interface) root;
List<Operation> interOperations = inter.getOperations();
for (Operation interOper : interOperations) {
if (interOper.getId().equals(serviceTask.getOperationRef().getId())) {
properties.put("serviceinterface", inter.getName() == null ? inter.getImplementationRef() : inter.getName());
}
}
}
}
}
}
} else if (task instanceof ManualTask) {
taskType = "Manual";
} else if (task instanceof UserTask) {
taskType = "User";
// get the user task actors
List<ResourceRole> roles = task.getResources();
StringBuilder sb = new StringBuilder();
for (ResourceRole role : roles) {
if (role instanceof PotentialOwner) {
FormalExpression fe = (FormalExpression) ((PotentialOwner) role).getResourceAssignmentExpression().getExpression();
if (fe.getBody() != null && fe.getBody().length() > 0) {
sb.append(fe.getBody());
sb.append(",");
}
}
}
if (sb.length() > 0) {
sb.setLength(sb.length() - 1);
}
properties.put("actors", sb.toString());
} else if (task instanceof SendTask) {
taskType = "Send";
SendTask st = (SendTask) task;
if (st.getMessageRef() != null) {
properties.put("messageref", st.getMessageRef().getId());
}
} else if (task instanceof ReceiveTask) {
taskType = "Receive";
ReceiveTask rt = (ReceiveTask) task;
if (rt.getMessageRef() != null) {
properties.put("messageref", rt.getMessageRef().getId());
}
}
// custom async
String customAsyncMetaData = Utils.getMetaDataValue(task.getExtensionValues(), "customAsync");
String customAsync = (customAsyncMetaData != null && customAsyncMetaData.length() > 0) ? customAsyncMetaData : "false";
properties.put("isasync", customAsync);
// custom autostart
String customAutoStartMetaData = Utils.getMetaDataValue(task.getExtensionValues(), "customAutoStart");
String customAutoStart = (customAutoStartMetaData != null && customAutoStartMetaData.length() > 0) ? customAutoStartMetaData : "false";
properties.put("customautostart", customAutoStart);
// backwards compatibility with jbds editor
boolean foundTaskName = false;
if (task instanceof UserTask && task.getIoSpecification() != null && task.getIoSpecification().getDataInputs() != null) {
List<DataInput> taskDataInputs = task.getIoSpecification().getDataInputs();
for (DataInput din : taskDataInputs) {
if (din.getName() != null && din.getName().equals("TaskName")) {
List<DataInputAssociation> taskDataInputAssociations = task.getDataInputAssociations();
for (DataInputAssociation dia : taskDataInputAssociations) {
if (dia.getTargetRef() != null && dia.getTargetRef().getId().equals(din.getId()) && dia.getAssignment() != null && !dia.getAssignment().isEmpty() && dia.getAssignment().get(0).getFrom() != null) {
properties.put("taskname", ((FormalExpression) dia.getAssignment().get(0).getFrom()).getBody());
foundTaskName = true;
}
}
break;
}
}
}
if (!foundTaskName) {
// try the drools specific attribute set on the task
Iterator<FeatureMap.Entry> iter = task.getAnyAttribute().iterator();
while (iter.hasNext()) {
FeatureMap.Entry entry = iter.next();
if (entry.getEStructuralFeature().getName().equals("taskName")) {
String tname = (String) entry.getValue();
if (tname != null && tname.length() > 0) {
properties.put("taskname", tname);
}
}
}
}
// check if we are dealing with a custom task
boolean isCustomElement = isCustomElement((String) properties.get("taskname"), preProcessingData);
if (isCustomElement) {
properties.put("tasktype", properties.get("taskname"));
} else {
properties.put("tasktype", taskType);
}
// multiple instance
if (task.getLoopCharacteristics() != null) {
properties.put("multipleinstance", "true");
MultiInstanceLoopCharacteristics taskmi = (MultiInstanceLoopCharacteristics) task.getLoopCharacteristics();
if (taskmi.getLoopDataInputRef() != null) {
ItemAwareElement iedatainput = taskmi.getLoopDataInputRef();
List<DataInputAssociation> taskInputAssociations = task.getDataInputAssociations();
for (DataInputAssociation dia : taskInputAssociations) {
if (dia.getTargetRef().equals(iedatainput)) {
properties.put("multipleinstancecollectioninput", dia.getSourceRef().get(0).getId());
break;
}
}
}
if (taskmi.getLoopDataOutputRef() != null) {
ItemAwareElement iedataoutput = taskmi.getLoopDataOutputRef();
List<DataOutputAssociation> taskOutputAssociations = task.getDataOutputAssociations();
for (DataOutputAssociation dout : taskOutputAssociations) {
if (dout.getSourceRef().get(0).equals(iedataoutput)) {
properties.put("multipleinstancecollectionoutput", dout.getTargetRef().getId());
break;
}
}
}
if (taskmi.getInputDataItem() != null && taskmi.getInputDataItem().getItemSubjectRef() != null) {
List<DataInput> taskDataInputs = task.getIoSpecification().getDataInputs();
for (DataInput din : taskDataInputs) {
if (din != null && din.getItemSubjectRef() != null && taskmi.getInputDataItem() != null && taskmi.getInputDataItem().getItemSubjectRef() != null) {
if (din.getItemSubjectRef().getId().equals(taskmi.getInputDataItem().getItemSubjectRef().getId())) {
properties.put("multipleinstancedatainput", din.getName());
}
}
}
}
if (taskmi.getOutputDataItem() != null && taskmi.getOutputDataItem().getItemSubjectRef() != null) {
List<DataOutput> taskDataOutputs = task.getIoSpecification().getDataOutputs();
for (DataOutput dout : taskDataOutputs) {
if (dout != null && dout.getItemSubjectRef() != null && taskmi.getOutputDataItem() != null && taskmi.getOutputDataItem().getItemSubjectRef() != null) {
if (dout.getItemSubjectRef().getId().equals(taskmi.getOutputDataItem().getItemSubjectRef().getId())) {
properties.put("multipleinstancedataoutput", dout.getName());
}
}
}
}
if (taskmi.getCompletionCondition() != null) {
if (taskmi.getCompletionCondition() instanceof FormalExpression) {
properties.put("multipleinstancecompletioncondition", ((FormalExpression) taskmi.getCompletionCondition()).getBody());
}
}
} else {
properties.put("multipleinstance", "false");
}
// data inputs
List<String> disallowedInputs = new ArrayList<String>();
disallowedInputs.add("miinputCollection");
if ((task instanceof UserTask) || isCustomElement) {
disallowedInputs.add("TaskName");
}
String datainputset = marshallDataInputSet(task, properties, disallowedInputs);
DataInput groupDataInput = null;
DataInput skippableDataInput = null;
DataInput commentDataInput = null;
DataInput descriptionDataInput = null;
DataInput contentDataInput = null;
DataInput priorityDataInput = null;
DataInput localeDataInput = null;
DataInput createdByDataInput = null;
DataInput notCompletedReassignInput = null;
DataInput notStartedReassignInput = null;
DataInput notCompletedNotificationInput = null;
DataInput notStartedNotificationInput = null;
if (task.getIoSpecification() != null) {
List<InputSet> inputSetList = task.getIoSpecification().getInputSets();
for (InputSet inset : inputSetList) {
List<DataInput> dataInputList = inset.getDataInputRefs();
for (DataInput dataIn : dataInputList) {
// dont add "TaskName" as that is added manually
String dataInName = dataIn.getName();
if (task instanceof UserTask && dataInName != null) {
if (dataInName.equals("GroupId")) {
groupDataInput = dataIn;
} else if (dataInName.equals("Skippable")) {
skippableDataInput = dataIn;
} else if (dataInName.equals("Comment")) {
commentDataInput = dataIn;
} else if (dataInName.equals("Description")) {
descriptionDataInput = dataIn;
} else if (dataInName.equals("Content")) {
contentDataInput = dataIn;
} else if (dataInName.equals("Priority")) {
priorityDataInput = dataIn;
} else if (dataInName.equals("Locale")) {
localeDataInput = dataIn;
} else if (dataInName.equals("CreatedBy")) {
createdByDataInput = dataIn;
} else if (dataInName.equals("NotCompletedReassign")) {
notCompletedReassignInput = dataIn;
} else if (dataInName.equals("NotStartedReassign")) {
notStartedReassignInput = dataIn;
} else if (dataInName.equals("NotCompletedNotify")) {
notCompletedNotificationInput = dataIn;
} else if (dataInName.equals("NotStartedNotify")) {
notStartedNotificationInput = dataIn;
}
}
}
}
}
// data outputs
String dataoutputset = marshallDataOutputSet(task, properties, Arrays.asList("mioutputCollection"));
// assignments
StringBuilder associationBuff = new StringBuilder();
List<DataInputAssociation> inputAssociations = task.getDataInputAssociations();
List<DataOutputAssociation> outputAssociations = task.getDataOutputAssociations();
List<String> uniDirectionalAssociations = new ArrayList<String>();
// List<String> biDirectionalAssociations = new ArrayList<String>();
for (DataInputAssociation datain : inputAssociations) {
boolean proceed = true;
if (task.getLoopCharacteristics() != null) {
MultiInstanceLoopCharacteristics taskMultiLoop = (MultiInstanceLoopCharacteristics) task.getLoopCharacteristics();
// dont include associations that include mi loop data inputs
if (taskMultiLoop.getInputDataItem() != null && taskMultiLoop.getInputDataItem().getId() != null) {
if (datain.getSourceRef() != null && datain.getSourceRef().size() > 0 && datain.getSourceRef().get(0).getId().equals(taskMultiLoop.getInputDataItem().getId())) {
proceed = false;
}
}
// dont include associations that include loopDataInputRef as target
if (taskMultiLoop.getLoopDataInputRef() != null) {
if (datain.getTargetRef().equals(taskMultiLoop.getLoopDataInputRef())) {
proceed = false;
}
}
}
if (proceed) {
String lhsAssociation = "";
if (datain.getSourceRef() != null && datain.getSourceRef().size() > 0) {
if (datain.getTransformation() != null && datain.getTransformation().getBody() != null) {
lhsAssociation = datain.getTransformation().getBody();
} else {
lhsAssociation = datain.getSourceRef().get(0).getId();
}
}
String rhsAssociation = "";
if (datain.getTargetRef() != null) {
rhsAssociation = ((DataInput) datain.getTargetRef()).getName();
}
// boolean isBiDirectional = false;
boolean isAssignment = false;
if (datain.getAssignment() != null && datain.getAssignment().size() > 0) {
isAssignment = true;
}
// }
if (isAssignment) {
// only know how to deal with formal expressions
if (datain.getAssignment().get(0).getFrom() instanceof FormalExpression) {
String associationValue = ((FormalExpression) datain.getAssignment().get(0).getFrom()).getBody();
if (associationValue == null) {
associationValue = "";
}
// don't include properties that have their independent input editors
if (isCustomElement((String) properties.get("taskname"), preProcessingData)) {
if (!(rhsAssociation.equals("TaskName"))) {
String replacer = encodeAssociationValue(associationValue);
associationBuff.append("[din]" + rhsAssociation).append("=").append(replacer);
associationBuff.append(",");
properties.put(rhsAssociation.toLowerCase(), associationValue);
}
} else {
if (!(task instanceof UserTask) || !(rhsAssociation.equals("GroupId") || rhsAssociation.equals("Skippable") || rhsAssociation.equals("Comment") || rhsAssociation.equals("Description") || rhsAssociation.equals("Priority") || rhsAssociation.equals("Content") || rhsAssociation.equals("TaskName") || rhsAssociation.equals("Locale") || rhsAssociation.equals("CreatedBy") || rhsAssociation.equals("NotCompletedReassign") || rhsAssociation.equals("NotStartedReassign") || rhsAssociation.equals("NotCompletedNotify") || rhsAssociation.equals("NotStartedNotify"))) {
String replacer = encodeAssociationValue(associationValue);
associationBuff.append("[din]" + rhsAssociation).append("=").append(replacer);
associationBuff.append(",");
properties.put(rhsAssociation.toLowerCase(), associationValue);
}
}
if (rhsAssociation.equalsIgnoreCase("TaskName")) {
properties.put("taskname", associationValue);
}
if (task instanceof UserTask && datain.getAssignment().get(0).getTo() != null && ((FormalExpression) datain.getAssignment().get(0).getTo()).getBody() != null && datain.getAssignment().get(0).getFrom() != null) {
String toBody = ((FormalExpression) datain.getAssignment().get(0).getTo()).getBody();
String fromBody = ((FormalExpression) datain.getAssignment().get(0).getFrom()).getBody();
if (toBody != null) {
if (groupDataInput != null && toBody.equals(groupDataInput.getId())) {
properties.put("groupid", fromBody == null ? "" : fromBody);
} else if (skippableDataInput != null && toBody.equals(skippableDataInput.getId())) {
properties.put("skippable", fromBody);
} else if (commentDataInput != null && toBody.equals(commentDataInput.getId())) {
properties.put("subject", fromBody);
} else if (descriptionDataInput != null && toBody.equals(descriptionDataInput.getId())) {
properties.put("description", fromBody);
} else if (priorityDataInput != null && toBody.equals(priorityDataInput.getId())) {
properties.put("priority", fromBody == null ? "" : fromBody);
} else if (contentDataInput != null && toBody.equals(contentDataInput.getId())) {
properties.put("content", fromBody);
} else if (localeDataInput != null && toBody.equals(localeDataInput.getId())) {
properties.put("locale", fromBody);
} else if (createdByDataInput != null && toBody.equals(createdByDataInput.getId())) {
properties.put("createdby", fromBody);
} else if (notCompletedReassignInput != null && toBody.equals(notCompletedReassignInput.getId())) {
properties.put("tmpreassignmentnotcompleted", updateReassignmentAndNotificationInput(fromBody, "not-completed"));
} else if (notStartedReassignInput != null && toBody.equals(notStartedReassignInput.getId())) {
properties.put("tmpreassignmentnotstarted", updateReassignmentAndNotificationInput(fromBody, "not-started"));
} else if (notCompletedNotificationInput != null && toBody.equals(notCompletedNotificationInput.getId())) {
properties.put("tmpnotificationnotcompleted", updateReassignmentAndNotificationInput(fromBody, "not-completed"));
} else if (notStartedNotificationInput != null && toBody.equals(notStartedNotificationInput.getId())) {
properties.put("tmpnotificationnotstarted", updateReassignmentAndNotificationInput(fromBody, "not-started"));
}
}
}
}
} else // else if(isBiDirectional) {
// associationBuff.append(lhsAssociation).append("<->").append(rhsAssociation);
// associationBuff.append(",");
// biDirectionalAssociations.add(lhsAssociation + "," + rhsAssociation);
// }
{
if (lhsAssociation != null && lhsAssociation.length() > 0) {
associationBuff.append("[din]" + lhsAssociation).append("->").append(rhsAssociation);
associationBuff.append(",");
uniDirectionalAssociations.add(lhsAssociation + "," + rhsAssociation);
}
uniDirectionalAssociations.add(lhsAssociation + "," + rhsAssociation);
// if(contentDataInput != null) {
// if(rhsAssociation.equals(contentDataInput.getName())) {
// properties.put("content", lhsAssociation);
// }
// }
}
}
}
if (properties.get("tmpreassignmentnotcompleted") != null && ((String) properties.get("tmpreassignmentnotcompleted")).length() > 0 && properties.get("tmpreassignmentnotstarted") != null && ((String) properties.get("tmpreassignmentnotstarted")).length() > 0) {
properties.put("reassignment", properties.get("tmpreassignmentnotcompleted") + "^" + properties.get("tmpreassignmentnotstarted"));
} else if (properties.get("tmpreassignmentnotcompleted") != null && ((String) properties.get("tmpreassignmentnotcompleted")).length() > 0) {
properties.put("reassignment", properties.get("tmpreassignmentnotcompleted"));
} else if (properties.get("tmpreassignmentnotstarted") != null && ((String) properties.get("tmpreassignmentnotstarted")).length() > 0) {
properties.put("reassignment", properties.get("tmpreassignmentnotstarted"));
}
if (properties.get("tmpnotificationnotcompleted") != null && ((String) properties.get("tmpnotificationnotcompleted")).length() > 0 && properties.get("tmpnotificationnotstarted") != null && ((String) properties.get("tmpnotificationnotstarted")).length() > 0) {
properties.put("notifications", properties.get("tmpnotificationnotcompleted") + "^" + properties.get("tmpnotificationnotstarted"));
} else if (properties.get("tmpnotificationnotcompleted") != null && ((String) properties.get("tmpnotificationnotcompleted")).length() > 0) {
properties.put("notifications", properties.get("tmpnotificationnotcompleted"));
} else if (properties.get("tmpnotificationnotstarted") != null && ((String) properties.get("tmpnotificationnotstarted")).length() > 0) {
properties.put("notifications", properties.get("tmpnotificationnotstarted"));
}
for (DataOutputAssociation dataout : outputAssociations) {
boolean proceed = true;
if (task.getLoopCharacteristics() != null) {
MultiInstanceLoopCharacteristics taskMultiLoop = (MultiInstanceLoopCharacteristics) task.getLoopCharacteristics();
// dont include associations that include mi loop data outputs
if (taskMultiLoop.getOutputDataItem() != null && taskMultiLoop.getOutputDataItem().getId() != null) {
if (dataout.getTargetRef().getId().equals(taskMultiLoop.getOutputDataItem().getId())) {
proceed = false;
}
}
// dont include associations that include loopDataOutputRef as source
if (taskMultiLoop.getLoopDataOutputRef() != null) {
if (dataout.getSourceRef().get(0).equals(taskMultiLoop.getLoopDataOutputRef())) {
proceed = false;
}
}
}
if (proceed) {
if (dataout.getSourceRef().size() > 0) {
String lhsAssociation = ((DataOutput) dataout.getSourceRef().get(0)).getName();
String rhsAssociation = dataout.getTargetRef().getId();
boolean wasBiDirectional = false;
// }
if (dataout.getTransformation() != null && dataout.getTransformation().getBody() != null) {
rhsAssociation = encodeAssociationValue(dataout.getTransformation().getBody());
}
if (!wasBiDirectional) {
if (lhsAssociation != null && lhsAssociation.length() > 0) {
associationBuff.append("[dout]" + lhsAssociation).append("->").append(rhsAssociation);
associationBuff.append(",");
}
}
}
}
}
String assignmentString = associationBuff.toString();
if (assignmentString.endsWith(",")) {
assignmentString = assignmentString.substring(0, assignmentString.length() - 1);
}
properties.put("assignments", assignmentString);
setAssignmentsInfoProperty(null, datainputset, null, dataoutputset, assignmentString, properties);
// on-entry and on-exit actions
ScriptTypeListValue onEntryActions = getOnEntryActions(task.getExtensionValues());
ScriptTypeListValue onExitActions = getOnExitActions(task.getExtensionValues());
if (!onEntryActions.isEmpty()) {
properties.put(ONENTRYACTIONS, new ScriptTypeListTypeSerializer().serialize(onEntryActions));
}
if (!onExitActions.isEmpty()) {
properties.put(ONEXITACTIONS, new ScriptTypeListTypeSerializer().serialize(onExitActions));
}
// simulation properties
setSimulationProperties(task.getId(), properties);
// marshall the node out
if (isCustomElement((String) properties.get("taskname"), preProcessingData)) {
marshallNode(task, properties, (String) properties.get("taskname"), plane, generator, xOffset, yOffset);
} else {
marshallNode(task, properties, "Task", plane, generator, xOffset, yOffset);
}
}
use of org.eclipse.bpmn2.ItemAwareElement in project kie-wb-common by kiegroup.
the class Bpmn2JsonMarshaller method marshallItemAwareElements.
private void marshallItemAwareElements(Activity activity, List<? extends ItemAwareElement> elements, StringBuilder buffer, List<String> disallowedNames) {
for (ItemAwareElement element : elements) {
String name = null;
if (element instanceof DataInput) {
name = ((DataInput) element).getName();
}
if (element instanceof DataOutput) {
name = ((DataOutput) element).getName();
}
if (name != null && !name.isEmpty() && !disallowedNames.contains(name)) {
buffer.append(name);
if (element.getItemSubjectRef() != null && element.getItemSubjectRef().getStructureRef() != null && !element.getItemSubjectRef().getStructureRef().isEmpty()) {
buffer.append(":").append(element.getItemSubjectRef().getStructureRef());
} else if (activity.eContainer() instanceof SubProcess) {
// BZ1247105: for Outputs on Tasks inside sub-processes
String dtype = getAnyAttributeValue(element, "dtype");
if (dtype != null && !dtype.isEmpty()) {
buffer.append(":").append(dtype);
}
}
buffer.append(",");
}
}
}
use of org.eclipse.bpmn2.ItemAwareElement in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method applyCallActivityProperties.
protected void applyCallActivityProperties(CallActivity callActivity, Map<String, String> properties) {
if (properties.get("name") != null) {
callActivity.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("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")));
}
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);
}
// }
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);
}
// }
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);
}
}
use of org.eclipse.bpmn2.ItemAwareElement in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method applySubProcessProperties.
protected void applySubProcessProperties(SubProcess sp, Map<String, String> properties) {
if (properties.get("name") != null) {
sp.setName(StringEscapeUtils.escapeXml(properties.get("name")).replaceAll("\\r\\n|\\r|\\n", " "));
// add unescaped and untouched name value as extension element as well
Utils.setMetaDataExtensionValue(sp, "elementname", wrapInCDATABlock(properties.get("name").replaceAll("\\\\n", "\n")));
} else {
sp.setName("");
}
// process on-entry and on-exit actions as custom elements
applyOnEntryActions(sp, properties);
applyOnExitActions(sp, properties);
// isAsync metadata
if (properties.get("isasync") != null && properties.get("isasync").length() > 0 && properties.get("isasync").equals("true")) {
Utils.setMetaDataExtensionValue(sp, "customAsync", wrapInCDATABlock(properties.get("isasync")));
}
if (sp.getIoSpecification() == null) {
InputOutputSpecification iospec = Bpmn2Factory.eINSTANCE.createInputOutputSpecification();
sp.setIoSpecification(iospec);
}
parseAssignmentsInfo(properties);
// data input set
applyDataInputProperties(sp, properties, new HashMap<String, DataInput>());
// data output set
applyDataOutputProperties(sp, properties);
// assignments
if (properties.get("assignments") != null && properties.get("assignments").length() > 0 && sp.getIoSpecification() != null) {
String[] allAssignments = properties.get("assignments").split(",\\s*");
for (String assignment : allAssignments) {
if (assignment.contains("=")) {
String[] assignmentParts = assignment.split("=\\s*");
String fromPart = assignmentParts[0];
if (fromPart.startsWith("[din]")) {
fromPart = fromPart.substring(5, fromPart.length());
}
DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
if (sp.getIoSpecification() != null && sp.getIoSpecification().getDataOutputs() != null) {
List<DataInput> dataInputs = sp.getIoSpecification().getDataInputs();
for (DataInput di : dataInputs) {
if (di.getId().equals(sp.getId() + "_" + fromPart + "InputX")) {
dia.setTargetRef(di);
if (di.getName().equals("TaskName")) {
break;
}
}
}
}
Assignment a = Bpmn2Factory.eINSTANCE.createAssignment();
FormalExpression fromExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
if (assignmentParts.length > 1) {
String replacer = decodeAssociationValue(assignmentParts[1]);
fromExpression.setBody(wrapInCDATABlock(replacer));
} else {
fromExpression.setBody("");
}
FormalExpression toExpression = Bpmn2Factory.eINSTANCE.createFormalExpression();
toExpression.setBody(dia.getTargetRef().getId());
a.setFrom(fromExpression);
a.setTo(toExpression);
dia.getAssignment().add(a);
sp.getDataInputAssociations().add(dia);
// } else if(assignment.contains("<->")) {
// String[] assignmentParts = assignment.split( "<->\\s*" );
// DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
// DataOutputAssociation doa = Bpmn2Factory.eINSTANCE.createDataOutputAssociation();
//
// ItemAwareElement ie = Bpmn2Factory.eINSTANCE.createItemAwareElement();
// ie.setId(assignmentParts[0]);
// dia.getSourceRef().add(ie);
// doa.setTargetRef(ie);
//
// List<DataInput> dataInputs = sp.getIoSpecification().getDataInputs();
// for(DataInput di : dataInputs) {
// if(di.getId().equals(sp.getId() + "_" + assignmentParts[1] + "InputX")) {
// dia.setTargetRef(di);
// break;
// }
// }
// List<DataOutput> dataOutputs = sp.getIoSpecification().getDataOutputs();
// for(DataOutput dout : dataOutputs) {
// if(dout.getId().equals(sp.getId() + "_" + assignmentParts[1] + "OutputX")) {
// doa.getSourceRef().add(dout);
// break;
// }
// }
//
// sp.getDataInputAssociations().add(dia);
// sp.getDataOutputAssociations().add(doa);
} else if (assignment.contains("->")) {
String[] assignmentParts = assignment.split("->\\s*");
String fromPart = assignmentParts[0];
boolean isDataInput = false;
boolean isDataOutput = false;
if (fromPart.startsWith("[din]")) {
fromPart = fromPart.substring(5, fromPart.length());
isDataInput = true;
}
if (fromPart.startsWith("[dout]")) {
fromPart = fromPart.substring(6, fromPart.length());
isDataOutput = true;
}
List<DataOutput> dataOutputs = sp.getIoSpecification().getDataOutputs();
if (isDataOutput) {
DataOutputAssociation doa = Bpmn2Factory.eINSTANCE.createDataOutputAssociation();
for (DataOutput dout : dataOutputs) {
if (dout.getId().equals(sp.getId() + "_" + fromPart + "OutputX")) {
doa.getSourceRef().add(dout);
break;
}
}
ItemAwareElement ie = Bpmn2Factory.eINSTANCE.createItemAwareElement();
ie.setId(assignmentParts[1]);
doa.setTargetRef(ie);
sp.getDataOutputAssociations().add(doa);
} else if (isDataInput) {
DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
// association from process var to dataInput var
ItemAwareElement ie = Bpmn2Factory.eINSTANCE.createItemAwareElement();
ie.setId(fromPart);
dia.getSourceRef().add(ie);
List<DataInput> dataInputs = sp.getIoSpecification().getDataInputs();
for (DataInput di : dataInputs) {
if (di.getId().equals(sp.getId() + "_" + assignmentParts[1] + "InputX")) {
dia.setTargetRef(di);
break;
}
}
sp.getDataInputAssociations().add(dia);
}
} else {
// TODO throw exception here?
}
}
}
// loop characteristics input
if (properties.get("mitrigger") != null && properties.get("mitrigger").equals("true")) {
if (properties.get("multipleinstancecollectioninput") != null && properties.get("multipleinstancecollectioninput").length() > 0) {
String miDataInputStr = properties.get("multipleinstancedatainput");
if (miDataInputStr == null || miDataInputStr.length() < 1) {
miDataInputStr = "defaultDataInput";
}
if (sp.getIoSpecification() == null) {
InputOutputSpecification iospec = Bpmn2Factory.eINSTANCE.createInputOutputSpecification();
sp.setIoSpecification(iospec);
} else {
sp.getIoSpecification().getDataInputs().clear();
sp.getIoSpecification().getDataOutputs().clear();
sp.getDataInputAssociations().clear();
sp.getDataOutputAssociations().clear();
}
InputSet inset = sp.getIoSpecification().getInputSets().get(0);
DataInput multiInput = Bpmn2Factory.eINSTANCE.createDataInput();
multiInput.setId(sp.getId() + "_" + "input");
multiInput.setName(properties.get("multipleinstancecollectioninput"));
sp.getIoSpecification().getDataInputs().add(multiInput);
inset.getDataInputRefs().add(multiInput);
DataInputAssociation dia = Bpmn2Factory.eINSTANCE.createDataInputAssociation();
ItemAwareElement ie = Bpmn2Factory.eINSTANCE.createItemAwareElement();
ie.setId(properties.get("multipleinstancecollectioninput"));
dia.getSourceRef().add(ie);
dia.setTargetRef(multiInput);
sp.getDataInputAssociations().add(dia);
MultiInstanceLoopCharacteristics loopCharacteristics = Bpmn2Factory.eINSTANCE.createMultiInstanceLoopCharacteristics();
loopCharacteristics.setLoopDataInputRef(multiInput);
DataInput din = Bpmn2Factory.eINSTANCE.createDataInput();
din.setId(miDataInputStr);
ItemDefinition itemDef = Bpmn2Factory.eINSTANCE.createItemDefinition();
itemDef.setId(sp.getId() + "_" + "multiInstanceItemType");
din.setItemSubjectRef(itemDef);
_subprocessItemDefs.put(itemDef.getId(), itemDef);
loopCharacteristics.setInputDataItem(din);
// loop characteristics output
if (properties.get("multipleinstancecollectionoutput") != null && properties.get("multipleinstancecollectionoutput").length() > 0) {
String miDataOutputStr = properties.get("multipleinstancedataoutput");
if (miDataOutputStr == null || miDataOutputStr.length() < 1) {
miDataOutputStr = "defaultDataOutput";
}
OutputSet outset = sp.getIoSpecification().getOutputSets().get(0);
DataOutput multiOutput = Bpmn2Factory.eINSTANCE.createDataOutput();
multiOutput.setId(sp.getId() + "_" + "output");
multiOutput.setName(properties.get("multipleinstancecollectionoutput"));
sp.getIoSpecification().getDataOutputs().add(multiOutput);
outset.getDataOutputRefs().add(multiOutput);
DataOutputAssociation doa = Bpmn2Factory.eINSTANCE.createDataOutputAssociation();
ItemAwareElement ie2 = Bpmn2Factory.eINSTANCE.createItemAwareElement();
ie2.setId(properties.get("multipleinstancecollectionoutput"));
doa.getSourceRef().add(multiOutput);
doa.setTargetRef(ie2);
sp.getDataOutputAssociations().add(doa);
loopCharacteristics.setLoopDataOutputRef(multiOutput);
DataOutput don = Bpmn2Factory.eINSTANCE.createDataOutput();
don.setId(miDataOutputStr);
ItemDefinition itemDef2 = Bpmn2Factory.eINSTANCE.createItemDefinition();
itemDef2.setId(sp.getId() + "_" + "multiInstanceItemType");
don.setItemSubjectRef(itemDef2);
_subprocessItemDefs.put(itemDef2.getId(), itemDef2);
loopCharacteristics.setOutputDataItem(don);
}
// loop characteristics completion condition
if (properties.get("multipleinstancecompletioncondition") != null && !properties.get("multipleinstancecompletioncondition").isEmpty()) {
FormalExpression expr = Bpmn2Factory.eINSTANCE.createFormalExpression();
expr.setBody(properties.get("multipleinstancecompletioncondition"));
loopCharacteristics.setCompletionCondition(expr);
}
sp.setLoopCharacteristics(loopCharacteristics);
} else {
MultiInstanceLoopCharacteristics loopCharacteristics = Bpmn2Factory.eINSTANCE.createMultiInstanceLoopCharacteristics();
sp.setLoopCharacteristics(loopCharacteristics);
}
}
// properties
if (properties.get("vardefs") != null && properties.get("vardefs").length() > 0) {
String[] vardefs = properties.get("vardefs").split(",\\s*");
for (String vardef : vardefs) {
Property prop = Bpmn2Factory.eINSTANCE.createProperty();
ItemDefinition itemdef = Bpmn2Factory.eINSTANCE.createItemDefinition();
// check if we define a structure ref in the definition
if (vardef.contains(":")) {
String[] vardefParts = vardef.split(":\\s*");
prop.setId(vardefParts[0]);
itemdef.setId("_" + prop.getId() + "Item");
boolean haveKPI = false;
String kpiValue = "";
if (vardefParts.length == 3) {
itemdef.setStructureRef(vardefParts[1]);
if (vardefParts[2].equals("true")) {
haveKPI = true;
kpiValue = vardefParts[2];
}
}
if (vardefParts.length == 2) {
if (vardefParts[1].equals("true") || vardefParts[1].equals("false")) {
if (vardefParts[1].equals("true")) {
haveKPI = true;
kpiValue = vardefParts[1];
}
} else {
itemdef.setStructureRef(vardefParts[1]);
}
}
if (haveKPI) {
Utils.setMetaDataExtensionValue(prop, "customKPI", wrapInCDATABlock(kpiValue));
}
} else {
prop.setId(vardef);
itemdef.setId("_" + prop.getId() + "Item");
}
prop.setItemSubjectRef(itemdef);
sp.getProperties().add(prop);
_subprocessItemDefs.put(itemdef.getId(), itemdef);
}
}
// event subprocess
if (sp instanceof EventSubprocess) {
sp.setTriggeredByEvent(true);
}
// simulation
if (properties.get("distributiontype") != null && properties.get("distributiontype").length() > 0) {
TimeParameters timeParams = BpsimFactory.eINSTANCE.createTimeParameters();
Parameter processingTimeParam = BpsimFactory.eINSTANCE.createParameter();
if (properties.get("distributiontype").equals("normal")) {
NormalDistributionType normalDistributionType = BpsimFactory.eINSTANCE.createNormalDistributionType();
normalDistributionType.setStandardDeviation(Double.valueOf(properties.get("standarddeviation")));
normalDistributionType.setMean(Double.valueOf(properties.get("mean")));
processingTimeParam.getParameterValue().add(normalDistributionType);
} else if (properties.get("distributiontype").equals("uniform")) {
UniformDistributionType uniformDistributionType = BpsimFactory.eINSTANCE.createUniformDistributionType();
uniformDistributionType.setMax(Double.valueOf(properties.get("max")));
uniformDistributionType.setMin(Double.valueOf(properties.get("min")));
processingTimeParam.getParameterValue().add(uniformDistributionType);
// random distribution not supported in bpsim 1.0
// } else if(properties.get("distributiontype").equals("random")) {
// RandomDistributionType randomDistributionType = BpsimFactory.eINSTANCE.createRandomDistributionType();
// randomDistributionType.setMax(Double.valueOf(properties.get("max")));
// randomDistributionType.setMin(Double.valueOf(properties.get("min")));
// processingTimeParam.getParameterValue().add(randomDistributionType);
} else if (properties.get("distributiontype").equals("poisson")) {
PoissonDistributionType poissonDistributionType = BpsimFactory.eINSTANCE.createPoissonDistributionType();
poissonDistributionType.setMean(Double.valueOf(properties.get("mean")));
processingTimeParam.getParameterValue().add(poissonDistributionType);
}
// }
if (properties.get("waittime") != null) {
Parameter waittimeParam = BpsimFactory.eINSTANCE.createParameter();
FloatingParameterType waittimeParamValue = BpsimFactory.eINSTANCE.createFloatingParameterType();
DecimalFormat twoDForm = new DecimalFormat("#.##");
waittimeParamValue.setValue(Double.valueOf(twoDForm.format(Double.valueOf(properties.get("waittime")))));
waittimeParam.getParameterValue().add(waittimeParamValue);
timeParams.setWaitTime(waittimeParam);
}
timeParams.setProcessingTime(processingTimeParam);
if (_simulationElementParameters.containsKey(sp.getId())) {
_simulationElementParameters.get(sp.getId()).add(timeParams);
} else {
List<EObject> values = new ArrayList<EObject>();
values.add(timeParams);
_simulationElementParameters.put(sp.getId(), values);
}
}
CostParameters costParameters = BpsimFactory.eINSTANCE.createCostParameters();
if (properties.get("unitcost") != null && properties.get("unitcost").length() > 0) {
Parameter unitcostParam = BpsimFactory.eINSTANCE.createParameter();
FloatingParameterType unitCostParameterValue = BpsimFactory.eINSTANCE.createFloatingParameterType();
unitCostParameterValue.setValue(new Double(properties.get("unitcost")));
unitcostParam.getParameterValue().add(unitCostParameterValue);
costParameters.setUnitCost(unitcostParam);
}
// }
if (_simulationElementParameters.containsKey(sp.getId())) {
_simulationElementParameters.get(sp.getId()).add(costParameters);
} else {
List<EObject> values = new ArrayList<EObject>();
values.add(costParameters);
_simulationElementParameters.put(sp.getId(), values);
}
}
use of org.eclipse.bpmn2.ItemAwareElement 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);
}
}
}
Aggregations