use of org.kie.workbench.common.stunner.bpmn.definition.property.task.ScriptTypeListValue in project kie-wb-common by kiegroup.
the class Bpmn2JsonMarshaller method getOnEntryActions.
public ScriptTypeListValue getOnEntryActions(final List<ExtensionAttributeValue> extensionValues) {
final ScriptTypeListValue onEntryActions = new ScriptTypeListValue();
ScriptTypeValue onEntryAction;
if (extensionValues != null && !extensionValues.isEmpty()) {
for (ExtensionAttributeValue extattrval : extensionValues) {
FeatureMap extensionElements = extattrval.getValue();
@SuppressWarnings("unchecked") List<OnEntryScriptType> onEntryExtensions = (List<OnEntryScriptType>) extensionElements.get(DroolsPackage.Literals.DOCUMENT_ROOT__ON_ENTRY_SCRIPT, true);
for (OnEntryScriptType onEntryScript : onEntryExtensions) {
onEntryAction = getOnEntryAction(onEntryScript);
if (onEntryAction.getScript() != null && !onEntryAction.getScript().isEmpty()) {
onEntryActions.addValue(onEntryAction);
}
}
}
}
return onEntryActions;
}
use of org.kie.workbench.common.stunner.bpmn.definition.property.task.ScriptTypeListValue in project kie-wb-common by kiegroup.
the class Bpmn2JsonMarshaller method marshallSubProcess.
protected void marshallSubProcess(SubProcess subProcess, 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);
if (subProcess.getName() != null) {
properties.put(NAME, StringEscapeUtils.unescapeXml(subProcess.getName()));
} else {
properties.put(NAME, "");
}
putDocumentationProperty(subProcess, properties);
// overwrite name if elementname extension element is present
String elementName = Utils.getMetaDataValue(subProcess.getExtensionValues(), "elementname");
if (elementName != null) {
properties.put(NAME, elementName);
}
if (subProcess instanceof AdHocSubProcess) {
setAdHocSubProcessProperties((AdHocSubProcess) subProcess, properties);
}
// custom async
String customAsyncMetaData = Utils.getMetaDataValue(subProcess.getExtensionValues(), "customAsync");
String customAsync = (customAsyncMetaData != null && customAsyncMetaData.length() > 0) ? customAsyncMetaData : "false";
properties.put(ISASYNC, customAsync);
// data inputs
String datainputset = marshallDataInputSet(subProcess, properties);
// data outputs
String dataoutputset = marshallDataOutputSet(subProcess, properties);
// assignments
StringBuilder associationBuff = new StringBuilder();
List<DataInputAssociation> inputAssociations = subProcess.getDataInputAssociations();
List<DataOutputAssociation> outputAssociations = subProcess.getDataOutputAssociations();
marshallDataInputAssociations(associationBuff, inputAssociations);
marshallDataOutputAssociations(associationBuff, outputAssociations);
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(subProcess.getExtensionValues());
ScriptTypeListValue onExitActions = getOnExitActions(subProcess.getExtensionValues());
if (!onEntryActions.isEmpty()) {
properties.put(ONENTRYACTIONS, new ScriptTypeListTypeSerializer().serialize(onEntryActions));
}
if (!onExitActions.isEmpty()) {
properties.put(ONEXITACTIONS, new ScriptTypeListTypeSerializer().serialize(onExitActions));
}
// loop characteristics
boolean haveValidLoopCharacteristics = false;
if (subProcess.getLoopCharacteristics() != null && subProcess.getLoopCharacteristics() instanceof MultiInstanceLoopCharacteristics) {
haveValidLoopCharacteristics = true;
properties.put(MITRIGGER, "true");
MultiInstanceLoopCharacteristics taskmi = (MultiInstanceLoopCharacteristics) subProcess.getLoopCharacteristics();
if (taskmi.getLoopDataInputRef() != null) {
ItemAwareElement iedatainput = taskmi.getLoopDataInputRef();
List<DataInputAssociation> taskInputAssociations = subProcess.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 = subProcess.getDataOutputAssociations();
for (DataOutputAssociation dout : taskOutputAssociations) {
if (dout.getSourceRef().get(0).equals(iedataoutput)) {
properties.put(MULTIPLEINSTANCECOLLECTIONOUTPUT, dout.getTargetRef().getId());
break;
}
}
}
if (taskmi.getInputDataItem() != null) {
List<DataInput> taskDataInputs = subProcess.getIoSpecification().getDataInputs();
for (DataInput din : taskDataInputs) {
if (din.getItemSubjectRef() == null) {
// for backward compatibility as the where only input supported
properties.put(MULTIPLEINSTANCEDATAINPUT, taskmi.getInputDataItem().getId());
}
if (din.getItemSubjectRef() != null && din.getItemSubjectRef().getId().equals(taskmi.getInputDataItem().getItemSubjectRef().getId())) {
properties.put(MULTIPLEINSTANCEDATAINPUT, din.getName());
break;
}
}
}
if (taskmi.getOutputDataItem() != null) {
List<DataOutput> taskDataOutputs = subProcess.getIoSpecification().getDataOutputs();
for (DataOutput dout : taskDataOutputs) {
if (dout.getItemSubjectRef() == null) {
properties.put(MULTIPLEINSTANCEDATAOUTPUT, taskmi.getOutputDataItem().getId());
break;
}
if (dout.getItemSubjectRef() != null && dout.getItemSubjectRef().getId().equals(taskmi.getOutputDataItem().getItemSubjectRef().getId())) {
properties.put(MULTIPLEINSTANCEDATAOUTPUT, dout.getName());
break;
}
}
}
if (taskmi.getCompletionCondition() != null) {
if (taskmi.getCompletionCondition() instanceof FormalExpression) {
properties.put(MULTIPLEINSTANCECOMPLETIONCONDITION, ((FormalExpression) taskmi.getCompletionCondition()).getBody());
}
}
}
// properties
List<Property> processProperties = subProcess.getProperties();
if (processProperties != null && processProperties.size() > 0) {
String propVal = "";
for (int i = 0; i < processProperties.size(); i++) {
Property p = processProperties.get(i);
String pKPI = Utils.getMetaDataValue(p.getExtensionValues(), "customKPI");
propVal += p.getId();
// check the structureRef value
if (p.getItemSubjectRef() != null && p.getItemSubjectRef().getStructureRef() != null) {
propVal += ":" + p.getItemSubjectRef().getStructureRef();
}
if (pKPI != null && pKPI.length() > 0) {
propVal += ":" + pKPI;
}
if (i != processProperties.size() - 1) {
propVal += ",";
}
}
properties.put(VARDEFS, propVal);
}
// simulation properties
setSimulationProperties(subProcess.getId(), properties);
marshallProperties(properties, generator);
generator.writeObjectFieldStart("stencil");
if (subProcess instanceof AdHocSubProcess) {
generator.writeObjectField("id", "AdHocSubprocess");
} else {
if (subProcess.isTriggeredByEvent()) {
generator.writeObjectField("id", "EventSubprocess");
} else {
if (haveValidLoopCharacteristics) {
generator.writeObjectField("id", "MultipleInstanceSubprocess");
} else {
generator.writeObjectField("id", "Subprocess");
}
}
}
generator.writeEndObject();
generator.writeArrayFieldStart("childShapes");
Bounds bounds = ((BPMNShape) findDiagramElement(plane, subProcess)).getBounds();
for (FlowElement flowElement : subProcess.getFlowElements()) {
if (coordianteManipulation) {
marshallFlowElement(flowElement, plane, generator, bounds.getX(), bounds.getY(), preProcessingData, def);
} else {
marshallFlowElement(flowElement, plane, generator, 0, 0, preProcessingData, def);
}
}
for (Artifact artifact : subProcess.getArtifacts()) {
if (coordianteManipulation) {
marshallArtifact(artifact, plane, generator, bounds.getX(), bounds.getY(), preProcessingData, def);
} else {
marshallArtifact(artifact, plane, generator, 0, 0, preProcessingData, def);
}
}
generator.writeEndArray();
generator.writeArrayFieldStart("outgoing");
for (BoundaryEvent boundaryEvent : subProcess.getBoundaryEventRefs()) {
generator.writeStartObject();
generator.writeObjectField("resourceId", boundaryEvent.getId());
generator.writeEndObject();
}
for (SequenceFlow outgoing : subProcess.getOutgoing()) {
generator.writeStartObject();
generator.writeObjectField("resourceId", outgoing.getId());
generator.writeEndObject();
}
Process process = (Process) plane.getBpmnElement();
writeAssociations(process, subProcess.getId(), generator);
// subprocess boundary events
List<BoundaryEvent> boundaryEvents = new ArrayList<BoundaryEvent>();
findBoundaryEvents(process, boundaryEvents);
for (BoundaryEvent be : boundaryEvents) {
if (be.getAttachedToRef().getId().equals(subProcess.getId())) {
generator.writeStartObject();
generator.writeObjectField("resourceId", be.getId());
generator.writeEndObject();
}
}
generator.writeEndArray();
generator.writeObjectFieldStart("bounds");
generator.writeObjectFieldStart("lowerRight");
generator.writeObjectField("x", bounds.getX() + bounds.getWidth() - xOffset);
generator.writeObjectField("y", bounds.getY() + bounds.getHeight() - yOffset);
generator.writeEndObject();
generator.writeObjectFieldStart("upperLeft");
generator.writeObjectField("x", bounds.getX() - xOffset);
generator.writeObjectField("y", bounds.getY() - yOffset);
generator.writeEndObject();
generator.writeEndObject();
}
use of org.kie.workbench.common.stunner.bpmn.definition.property.task.ScriptTypeListValue in project kie-wb-common by kiegroup.
the class HashCodeAndEqualityTest method testMultipleInstanceSubprocessEquals.
@Test
public void testMultipleInstanceSubprocessEquals() {
final String MULTIPLE_INSTANCE_COLLECTION_INPUT = "multiple Instance collection input";
final String MULTIPLE_INSTANCE_COLLECTION_OUTPUT = "multiple Instance collection output";
final String MULTIPLE_INSTANCE_DATA_INPUT = "multiple Instance collection input";
final String MULTIPLE_INSTANCE_DATA_OUTPUT = "multiple Instance collection output";
final String MULTIPLE_INSTANCE_COMPLETION_CONDITION = "multiple Instance completion condition";
final String OTHER_VALUE = "other value";
final ScriptTypeListValue ON_ENTRY_ACTION = new ScriptTypeListValue().addValue(new ScriptTypeValue("java", ""));
final ScriptTypeListValue ON_EXIT_ACTION = new ScriptTypeListValue().addValue(new ScriptTypeValue("java", ""));
final Boolean IS_ASYNC = true;
final MultipleInstanceSubprocessTaskExecutionSet A_EXECUTION_SET = new MultipleInstanceSubprocessTaskExecutionSet(new MultipleInstanceCollectionInput(MULTIPLE_INSTANCE_COLLECTION_INPUT), new MultipleInstanceCollectionOutput(MULTIPLE_INSTANCE_COLLECTION_OUTPUT), new MultipleInstanceDataInput(MULTIPLE_INSTANCE_DATA_INPUT), new MultipleInstanceDataOutput(MULTIPLE_INSTANCE_DATA_OUTPUT), new MultipleInstanceCompletionCondition(MULTIPLE_INSTANCE_COMPLETION_CONDITION), new OnEntryAction(ON_ENTRY_ACTION), new OnExitAction(ON_EXIT_ACTION), new MITrigger("true"), new IsAsync(IS_ASYNC));
final MultipleInstanceSubprocessTaskExecutionSet B_EXECUTION_SET = new MultipleInstanceSubprocessTaskExecutionSet(new MultipleInstanceCollectionInput(MULTIPLE_INSTANCE_COLLECTION_INPUT), new MultipleInstanceCollectionOutput(MULTIPLE_INSTANCE_COLLECTION_OUTPUT), new MultipleInstanceDataInput(MULTIPLE_INSTANCE_DATA_INPUT), new MultipleInstanceDataOutput(MULTIPLE_INSTANCE_DATA_OUTPUT), new MultipleInstanceCompletionCondition(MULTIPLE_INSTANCE_COMPLETION_CONDITION), new OnEntryAction(ON_ENTRY_ACTION), new OnExitAction(ON_EXIT_ACTION), new MITrigger("true"), new IsAsync(IS_ASYNC));
final MultipleInstanceSubprocessTaskExecutionSet C_EXECUTION_SET = new MultipleInstanceSubprocessTaskExecutionSet(new MultipleInstanceCollectionInput(OTHER_VALUE), new MultipleInstanceCollectionOutput(MULTIPLE_INSTANCE_COLLECTION_OUTPUT), new MultipleInstanceDataInput(MULTIPLE_INSTANCE_DATA_INPUT), new MultipleInstanceDataOutput(MULTIPLE_INSTANCE_DATA_OUTPUT), new MultipleInstanceCompletionCondition(MULTIPLE_INSTANCE_COMPLETION_CONDITION), new OnEntryAction(ON_ENTRY_ACTION), new OnExitAction(ON_EXIT_ACTION), new MITrigger("true"), new IsAsync(IS_ASYNC));
final MultipleInstanceSubprocessTaskExecutionSet D_EXECUTION_SET = new MultipleInstanceSubprocessTaskExecutionSet(new MultipleInstanceCollectionInput(MULTIPLE_INSTANCE_COLLECTION_INPUT), new MultipleInstanceCollectionOutput(OTHER_VALUE), new MultipleInstanceDataInput(MULTIPLE_INSTANCE_DATA_INPUT), new MultipleInstanceDataOutput(MULTIPLE_INSTANCE_DATA_OUTPUT), new MultipleInstanceCompletionCondition(MULTIPLE_INSTANCE_COMPLETION_CONDITION), new OnEntryAction(ON_ENTRY_ACTION), new OnExitAction(ON_EXIT_ACTION), new MITrigger("true"), new IsAsync(IS_ASYNC));
final MultipleInstanceSubprocessTaskExecutionSet E_EXECUTION_SET = new MultipleInstanceSubprocessTaskExecutionSet(new MultipleInstanceCollectionInput(MULTIPLE_INSTANCE_COLLECTION_INPUT), new MultipleInstanceCollectionOutput(MULTIPLE_INSTANCE_COLLECTION_OUTPUT), new MultipleInstanceDataInput(OTHER_VALUE), new MultipleInstanceDataOutput(MULTIPLE_INSTANCE_DATA_OUTPUT), new MultipleInstanceCompletionCondition(MULTIPLE_INSTANCE_COMPLETION_CONDITION), new OnEntryAction(ON_ENTRY_ACTION), new OnExitAction(ON_EXIT_ACTION), new MITrigger("true"), new IsAsync(IS_ASYNC));
final MultipleInstanceSubprocessTaskExecutionSet F_EXECUTION_SET = new MultipleInstanceSubprocessTaskExecutionSet(new MultipleInstanceCollectionInput(MULTIPLE_INSTANCE_COLLECTION_INPUT), new MultipleInstanceCollectionOutput(MULTIPLE_INSTANCE_COLLECTION_OUTPUT), new MultipleInstanceDataInput(MULTIPLE_INSTANCE_DATA_INPUT), new MultipleInstanceDataOutput(OTHER_VALUE), new MultipleInstanceCompletionCondition(MULTIPLE_INSTANCE_COMPLETION_CONDITION), new OnEntryAction(ON_ENTRY_ACTION), new OnExitAction(ON_EXIT_ACTION), new MITrigger("true"), new IsAsync(IS_ASYNC));
final MultipleInstanceSubprocessTaskExecutionSet G_EXECUTION_SET = new MultipleInstanceSubprocessTaskExecutionSet(new MultipleInstanceCollectionInput(MULTIPLE_INSTANCE_COLLECTION_INPUT), new MultipleInstanceCollectionOutput(MULTIPLE_INSTANCE_COLLECTION_OUTPUT), new MultipleInstanceDataInput(MULTIPLE_INSTANCE_DATA_INPUT), new MultipleInstanceDataOutput(MULTIPLE_INSTANCE_DATA_OUTPUT), new MultipleInstanceCompletionCondition(OTHER_VALUE), new OnEntryAction(ON_ENTRY_ACTION), new OnExitAction(ON_EXIT_ACTION), new MITrigger("true"), new IsAsync(IS_ASYNC));
final MultipleInstanceSubprocessTaskExecutionSet H_EXECUTION_SET = new MultipleInstanceSubprocessTaskExecutionSet(new MultipleInstanceCollectionInput(MULTIPLE_INSTANCE_COLLECTION_INPUT), new MultipleInstanceCollectionOutput(MULTIPLE_INSTANCE_COLLECTION_OUTPUT), new MultipleInstanceDataInput(MULTIPLE_INSTANCE_DATA_INPUT), new MultipleInstanceDataOutput(MULTIPLE_INSTANCE_DATA_OUTPUT), new MultipleInstanceCompletionCondition(MULTIPLE_INSTANCE_COMPLETION_CONDITION), new OnEntryAction(new ScriptTypeListValue().addValue(new ScriptTypeValue("other language", ""))), new OnExitAction(ON_EXIT_ACTION), new MITrigger("true"), new IsAsync(IS_ASYNC));
final MultipleInstanceSubprocessTaskExecutionSet I_EXECUTION_SET = new MultipleInstanceSubprocessTaskExecutionSet(new MultipleInstanceCollectionInput(MULTIPLE_INSTANCE_COLLECTION_INPUT), new MultipleInstanceCollectionOutput(MULTIPLE_INSTANCE_COLLECTION_OUTPUT), new MultipleInstanceDataInput(MULTIPLE_INSTANCE_DATA_INPUT), new MultipleInstanceDataOutput(MULTIPLE_INSTANCE_DATA_OUTPUT), new MultipleInstanceCompletionCondition(MULTIPLE_INSTANCE_COMPLETION_CONDITION), new OnEntryAction(ON_ENTRY_ACTION), new OnExitAction(new ScriptTypeListValue().addValue(new ScriptTypeValue("other language", ""))), new MITrigger("true"), new IsAsync(IS_ASYNC));
final MultipleInstanceSubprocessTaskExecutionSet J_EXECUTION_SET = new MultipleInstanceSubprocessTaskExecutionSet(new MultipleInstanceCollectionInput(MULTIPLE_INSTANCE_COLLECTION_INPUT), new MultipleInstanceCollectionOutput(MULTIPLE_INSTANCE_COLLECTION_OUTPUT), new MultipleInstanceDataInput(MULTIPLE_INSTANCE_DATA_INPUT), new MultipleInstanceDataOutput(MULTIPLE_INSTANCE_DATA_OUTPUT), new MultipleInstanceCompletionCondition(MULTIPLE_INSTANCE_COMPLETION_CONDITION), new OnEntryAction(ON_ENTRY_ACTION), new OnExitAction(ON_EXIT_ACTION), new MITrigger("true"), new IsAsync(false));
final String PROCESS_DATA = "some value";
final ProcessData A_PROCESS_DATA = new ProcessData(new ProcessVariables(PROCESS_DATA));
final ProcessData B_PROCESS_DATA = new ProcessData(new ProcessVariables("Other value"));
MultipleInstanceSubprocess.MultipleInstanceSubprocessBuilder builder = new MultipleInstanceSubprocess.MultipleInstanceSubprocessBuilder();
MultipleInstanceSubprocess a = builder.build();
a.setExecutionSet(A_EXECUTION_SET);
a.setProcessData(A_PROCESS_DATA);
builder = new MultipleInstanceSubprocess.MultipleInstanceSubprocessBuilder();
MultipleInstanceSubprocess b = builder.build();
b.setExecutionSet(B_EXECUTION_SET);
b.setProcessData(A_PROCESS_DATA);
builder = new MultipleInstanceSubprocess.MultipleInstanceSubprocessBuilder();
MultipleInstanceSubprocess c = builder.build();
c.setExecutionSet(C_EXECUTION_SET);
builder = new MultipleInstanceSubprocess.MultipleInstanceSubprocessBuilder();
MultipleInstanceSubprocess d = builder.build();
d.setExecutionSet(D_EXECUTION_SET);
builder = new MultipleInstanceSubprocess.MultipleInstanceSubprocessBuilder();
MultipleInstanceSubprocess e = builder.build();
e.setExecutionSet(E_EXECUTION_SET);
builder = new MultipleInstanceSubprocess.MultipleInstanceSubprocessBuilder();
MultipleInstanceSubprocess f = builder.build();
f.setExecutionSet(F_EXECUTION_SET);
builder = new MultipleInstanceSubprocess.MultipleInstanceSubprocessBuilder();
MultipleInstanceSubprocess g = builder.build();
g.setExecutionSet(G_EXECUTION_SET);
builder = new MultipleInstanceSubprocess.MultipleInstanceSubprocessBuilder();
MultipleInstanceSubprocess h = builder.build();
g.setExecutionSet(H_EXECUTION_SET);
builder = new MultipleInstanceSubprocess.MultipleInstanceSubprocessBuilder();
MultipleInstanceSubprocess i = builder.build();
g.setExecutionSet(I_EXECUTION_SET);
builder = new MultipleInstanceSubprocess.MultipleInstanceSubprocessBuilder();
MultipleInstanceSubprocess j = builder.build();
g.setExecutionSet(J_EXECUTION_SET);
assertEquals(a, a);
assertEquals(a, b);
assertNotEquals(a, c);
assertNotEquals(a, d);
assertNotEquals(a, e);
assertNotEquals(a, f);
assertNotEquals(a, g);
assertNotEquals(a, h);
assertNotEquals(a, i);
assertNotEquals(a, j);
assertNotEquals(a, 19);
assertNotEquals(a, null);
a.setExecutionSet(null);
assertNotEquals(a, b);
assertNotEquals(b, a);
a.setExecutionSet(A_EXECUTION_SET);
assertEquals(a, b);
a.setProcessData(null);
assertNotEquals(a, b);
assertNotEquals(b, a);
a.setExecutionSet(A_EXECUTION_SET);
a.setProcessData(A_PROCESS_DATA);
assertEquals(a, b);
a.setProcessData(B_PROCESS_DATA);
assertNotEquals(a, b);
assertNotEquals(b, a);
MultipleInstanceSubprocess.MultipleInstanceSubprocessBuilder builderMessage = new MultipleInstanceSubprocess.MultipleInstanceSubprocessBuilder();
MultipleInstanceSubprocess k = builderMessage.build();
assertNotEquals(a, k);
}
Aggregations