use of org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.ScriptTypeListTypeSerializer in project kie-wb-common by kiegroup.
the class Bpmn2JsonUnmarshaller method applyOnExitActions.
protected void applyOnExitActions(BaseElement element, Map<String, String> properties) {
if (properties.get("onexitactions") != null && properties.get("onexitactions").length() > 0) {
ScriptTypeListValue onExitActions = new ScriptTypeListTypeSerializer().parse(properties.get("onexitactions"));
if (!onExitActions.isEmpty()) {
ScriptTypeValue onExitAction = onExitActions.getValues().get(0);
if (onExitAction.getScript() != null && !onExitAction.getScript().isEmpty()) {
OnExitScriptType onExitScript = DroolsFactory.eINSTANCE.createOnExitScriptType();
onExitScript.setScript(wrapInCDATABlock(onExitAction.getScript()));
String scriptLanguage = Utils.getScriptLanguageFormat(onExitAction.getLanguage());
if (scriptLanguage == null) {
// default to java
scriptLanguage = "http://www.java.com/java";
}
onExitScript.setScriptFormat(scriptLanguage);
if (element.getExtensionValues() == null || element.getExtensionValues().size() < 1) {
ExtensionAttributeValue extensionElement = Bpmn2Factory.eINSTANCE.createExtensionAttributeValue();
element.getExtensionValues().add(extensionElement);
}
FeatureMap.Entry extensionElementEntry = new SimpleFeatureMapEntry((Internal) DroolsPackage.Literals.DOCUMENT_ROOT__ON_EXIT_SCRIPT, onExitScript);
element.getExtensionValues().get(0).getValue().add(extensionElementEntry);
}
}
}
}
use of org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.ScriptTypeListTypeSerializer in project kie-wb-common by kiegroup.
the class BPMNDiagramMarshallerBase method init.
@SuppressWarnings("unchecked")
protected void init() {
initMocks(this);
// Work Items.
workItemDefinitionMockRegistry = new WorkItemDefinitionMockRegistry();
definitionManager = mock(DefinitionManager.class);
adapterManager = mock(AdapterManager.class);
adapterRegistry = mock(AdapterRegistry.class);
rulesManager = mock(RuleManager.class);
cloneManager = mock(CloneManager.class);
// Graph utils.
when(definitionManager.adapters()).thenReturn(adapterManager);
when(adapterManager.registry()).thenReturn(adapterRegistry);
DefinitionUtils definitionUtils1 = new DefinitionUtils(definitionManager, applicationFactoryManager);
testScopeModelFactory = new TestScopeModelFactory(new BPMNDefinitionSet.BPMNDefinitionSetBuilder().build());
// Definition manager.
final BackendDefinitionAdapter definitionAdapter = new BackendDefinitionAdapter(definitionUtils1);
final BackendDefinitionSetAdapter definitionSetAdapter = new BackendDefinitionSetAdapter(definitionAdapter);
final BackendPropertySetAdapter propertySetAdapter = new BackendPropertySetAdapter();
final BackendPropertyAdapter propertyAdapter = new BackendPropertyAdapter();
when(adapterManager.forDefinitionSet()).thenReturn(definitionSetAdapter);
when(adapterManager.forDefinition()).thenReturn(definitionAdapter);
when(adapterManager.forPropertySet()).thenReturn(propertySetAdapter);
when(adapterManager.forProperty()).thenReturn(propertyAdapter);
when(adapterRegistry.getDefinitionSetAdapter(any(Class.class))).thenReturn(definitionSetAdapter);
when(adapterRegistry.getDefinitionAdapter(any(Class.class))).thenReturn(definitionAdapter);
when(adapterRegistry.getPropertySetAdapter(any(Class.class))).thenReturn(propertySetAdapter);
when(adapterRegistry.getPropertyAdapter(any(Class.class))).thenReturn(propertyAdapter);
GraphCommandManager commandManager1 = new GraphCommandManagerImpl(null, null, null);
GraphCommandFactory commandFactory1 = new GraphCommandFactory();
connectionEdgeFactory = new EdgeFactoryImpl(definitionManager);
viewNodeFactory = new NodeFactoryImpl(definitionUtils1);
bpmnGraphFactory = new GraphFactoryImpl(definitionManager);
doAnswer(invocationOnMock -> {
String id = (String) invocationOnMock.getArguments()[0];
return testScopeModelFactory.build(id);
}).when(applicationFactoryManager).newDefinition(anyString());
doAnswer(invocationOnMock -> {
String uuid = (String) invocationOnMock.getArguments()[0];
String id = (String) invocationOnMock.getArguments()[1];
if (BPMNDefinitionSet.class.getName().equals(id)) {
return bpmnGraphFactory.build(uuid, BPMN_DEF_SET_ID);
}
Object model = testScopeModelFactory.accepts(id) ? testScopeModelFactory.build(id) : null;
if (null != model) {
Class<? extends ElementFactory> element = BackendDefinitionAdapter.getGraphFactory(model.getClass());
if (element.isAssignableFrom(NodeFactory.class)) {
return viewNodeFactory.build(uuid, model);
} else if (element.isAssignableFrom(EdgeFactory.class)) {
return connectionEdgeFactory.build(uuid, model);
}
}
return null;
}).when(applicationFactoryManager).newElement(anyString(), anyString());
doAnswer(invocationOnMock -> {
String uuid = (String) invocationOnMock.getArguments()[0];
Class type = (Class) invocationOnMock.getArguments()[1];
String id = BindableAdapterUtils.getGenericClassName(type);
if (BPMNDefinitionSet.class.equals(type)) {
return bpmnGraphFactory.build(uuid, BPMN_DEF_SET_ID);
}
Object model = testScopeModelFactory.accepts(id) ? testScopeModelFactory.build(id) : null;
if (null != model) {
Class<? extends ElementFactory> element = BackendDefinitionAdapter.getGraphFactory(model.getClass());
if (element.isAssignableFrom(NodeFactory.class)) {
return viewNodeFactory.build(uuid, model);
} else if (element.isAssignableFrom(EdgeFactory.class)) {
return connectionEdgeFactory.build(uuid, model);
}
}
return null;
}).when(applicationFactoryManager).newElement(anyString(), any(Class.class));
doAnswer(invocationOnMock -> {
String uuid = (String) invocationOnMock.getArguments()[0];
String defSetId = (String) invocationOnMock.getArguments()[1];
final Graph graph = (Graph) applicationFactoryManager.newElement(uuid, defSetId);
final DiagramImpl result = new DiagramImpl(uuid, new MetadataImpl.MetadataImplBuilder(defSetId).build());
result.setGraph(graph);
return result;
}).when(applicationFactoryManager).newDiagram(anyString(), anyString(), any(Metadata.class));
// Bpmn 2 oryx stuff.
Bpmn2OryxIdMappings oryxIdMappings = new Bpmn2OryxIdMappings(definitionManager, () -> workItemDefinitionMockRegistry);
StringTypeSerializer stringTypeSerializer = new StringTypeSerializer();
BooleanTypeSerializer booleanTypeSerializer = new BooleanTypeSerializer();
ColorTypeSerializer colorTypeSerializer = new ColorTypeSerializer();
DoubleTypeSerializer doubleTypeSerializer = new DoubleTypeSerializer();
IntegerTypeSerializer integerTypeSerializer = new IntegerTypeSerializer();
EnumTypeSerializer enumTypeSerializer = new EnumTypeSerializer(definitionUtils1);
AssignmentsTypeSerializer assignmentsTypeSerializer = new AssignmentsTypeSerializer();
VariablesTypeSerializer variablesTypeSerializer = new VariablesTypeSerializer();
TimerSettingsTypeSerializer timerSettingsTypeSerializer = new TimerSettingsTypeSerializer();
ScriptTypeTypeSerializer scriptTypeTypeSerializer = new ScriptTypeTypeSerializer();
ScriptTypeListTypeSerializer scriptTypeListTypeSerializer = new ScriptTypeListTypeSerializer();
List<Bpmn2OryxPropertySerializer<?>> propertySerializers = new LinkedList<>();
propertySerializers.add(stringTypeSerializer);
propertySerializers.add(booleanTypeSerializer);
propertySerializers.add(colorTypeSerializer);
propertySerializers.add(doubleTypeSerializer);
propertySerializers.add(integerTypeSerializer);
propertySerializers.add(enumTypeSerializer);
propertySerializers.add(assignmentsTypeSerializer);
propertySerializers.add(variablesTypeSerializer);
propertySerializers.add(timerSettingsTypeSerializer);
propertySerializers.add(scriptTypeTypeSerializer);
propertySerializers.add(scriptTypeListTypeSerializer);
Bpmn2OryxPropertyManager oryxPropertyManager = new Bpmn2OryxPropertyManager(propertySerializers);
Bpmn2OryxManager oryxManager = new Bpmn2OryxManager(oryxIdMappings, oryxPropertyManager);
oryxManager.init();
// Marshalling factories.
BPMNGraphObjectBuilderFactory objectBuilderFactory = new BPMNGraphObjectBuilderFactory(definitionManager, oryxManager, () -> workItemDefinitionMockRegistry);
taskMorphDefinition = new TaskTypeMorphDefinition();
Collection<MorphDefinition> morphDefinitions = new ArrayList<MorphDefinition>() {
{
add(taskMorphDefinition);
}
};
BackendBindableMorphAdapter<Object> morphAdapter = new BackendBindableMorphAdapter(definitionUtils1, applicationFactoryManager, cloneManager, morphDefinitions);
when(adapterRegistry.getMorphAdapter(eq(UserTask.class))).thenReturn(morphAdapter);
when(adapterRegistry.getMorphAdapter(eq(NoneTask.class))).thenReturn(morphAdapter);
when(adapterRegistry.getMorphAdapter(eq(ScriptTask.class))).thenReturn(morphAdapter);
when(adapterRegistry.getMorphAdapter(eq(BusinessRuleTask.class))).thenReturn(morphAdapter);
GraphIndexBuilder<?> indexBuilder = new MapIndexBuilder();
when(rulesManager.evaluate(any(RuleSet.class), any(RuleEvaluationContext.class))).thenReturn(new DefaultRuleViolations());
// The work item definition registry.
WorkItemDefinitionBackendRegistry widRegistry = mock(WorkItemDefinitionBackendRegistry.class);
when(widRegistry.getRegistry()).thenReturn(workItemDefinitionMockRegistry);
when(widRegistry.items()).thenReturn(workItemDefinitionMockRegistry.items());
when(widRegistry.load(any(Metadata.class))).thenReturn(widRegistry);
doAnswer(invocationOnMock -> workItemDefinitionMockRegistry.get((String) invocationOnMock.getArguments()[0])).when(widRegistry).get(anyString());
// The tested BPMN marshaller.
oldMarshaller = new BPMNDiagramMarshaller(new XMLEncoderDiagramMetadataMarshaller(), objectBuilderFactory, definitionManager, indexBuilder, oryxManager, applicationFactoryManager, rulesManager, commandManager1, commandFactory1, widRegistry);
// Graph utils.
when(definitionManager.adapters()).thenReturn(adapterManager);
when(adapterManager.registry()).thenReturn(adapterRegistry);
// initApplicationFactoryManagerAlt();
when(rulesManager.evaluate(any(RuleSet.class), any(RuleEvaluationContext.class))).thenReturn(new DefaultRuleViolations());
DefinitionUtils definitionUtils = new DefinitionUtils(definitionManager, applicationFactoryManager);
TestScopeModelFactory testScopeModelFactory = new TestScopeModelFactory(new BPMNDefinitionSet.BPMNDefinitionSetBuilder().build());
// Definition manager.
mockAdapterManager(definitionAdapter, definitionSetAdapter, propertySetAdapter, propertyAdapter);
mockAdapterRegistry(definitionAdapter, definitionSetAdapter, propertySetAdapter, propertyAdapter);
applicationFactoryManager = new MockApplicationFactoryManager(definitionManager, new GraphFactoryImpl(definitionManager), testScopeModelFactory, new EdgeFactoryImpl(definitionManager), new NodeFactoryImpl(definitionUtils));
GraphCommandManagerImpl commandManager = new GraphCommandManagerImpl(null, null, null);
GraphCommandFactory commandFactory = new GraphCommandFactory();
// The tested BPMN marshaller.
newMarshaller = new BPMNDirectDiagramMarshaller(new XMLEncoderDiagramMetadataMarshaller(), definitionManager, rulesManager, applicationFactoryManager, commandFactory, commandManager);
}
use of org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.ScriptTypeListTypeSerializer in project kie-wb-common by kiegroup.
the class Bpmn2JsonMarshaller method marshallCallActivity.
protected void marshallCallActivity(CallActivity callActivity, BPMNPlane plane, JsonGenerator generator, float xOffset, float yOffset, Map<String, Object> flowElementProperties) throws JsonGenerationException, IOException {
Map<String, Object> properties = new LinkedHashMap<String, Object>(flowElementProperties);
Iterator<FeatureMap.Entry> iter = callActivity.getAnyAttribute().iterator();
while (iter.hasNext()) {
FeatureMap.Entry entry = iter.next();
if (entry.getEStructuralFeature().getName().equals("independent")) {
properties.put(INDEPENDENT, entry.getValue());
}
if (entry.getEStructuralFeature().getName().equals("waitForCompletion")) {
properties.put(WAITFORCOMPLETION, entry.getValue());
}
}
if (callActivity.getCalledElement() != null && callActivity.getCalledElement().length() > 0) {
properties.put(CALLEDELEMENT, callActivity.getCalledElement());
}
// custom async
String customAsyncMetaData = Utils.getMetaDataValue(callActivity.getExtensionValues(), "customAsync");
String customAsync = (customAsyncMetaData != null && customAsyncMetaData.length() > 0) ? customAsyncMetaData : "false";
properties.put(ISASYNC, customAsync);
// data inputs
String datainputset = marshallDataInputSet(callActivity, properties);
// data outputs
String dataoutputset = marshallDataOutputSet(callActivity, properties);
// assignments
StringBuilder associationBuff = new StringBuilder();
List<DataInputAssociation> inputAssociations = callActivity.getDataInputAssociations();
List<DataOutputAssociation> outputAssociations = callActivity.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(callActivity.getExtensionValues());
ScriptTypeListValue onExitActions = getOnExitActions(callActivity.getExtensionValues());
if (!onEntryActions.isEmpty()) {
properties.put(ONENTRYACTIONS, new ScriptTypeListTypeSerializer().serialize(onEntryActions));
}
if (!onExitActions.isEmpty()) {
properties.put(ONEXITACTIONS, new ScriptTypeListTypeSerializer().serialize(onExitActions));
}
// simulation properties
setSimulationProperties(callActivity.getId(), properties);
marshallNode(callActivity, properties, "ReusableSubprocess", plane, generator, xOffset, yOffset);
}
use of org.kie.workbench.common.stunner.bpmn.backend.marshall.json.oryx.property.ScriptTypeListTypeSerializer 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();
}
Aggregations