From 395004c6961bb0b7ab2fe2a91d76c0affc24a43c Mon Sep 17 00:00:00 2001 From: jasquat Date: Wed, 17 Aug 2022 12:55:14 -0400 Subject: [PATCH] added message variable but need to fix setting it and payload w/ burnettk cullerton --- app/app.js | 2 +- app/spiffworkflow/messages/MessageHelpers.js | 42 ++- .../MessageCorrelationsArray.js | 2 +- .../propertiesPanel/MessagePayload.js | 17 +- .../messages/propertiesPanel/MessageSelect.js | 11 +- .../propertiesPanel/MessageVariable.js | 76 ++++ .../MessagesPropertiesProvider.js | 82 ++-- app/spiffworkflow/moddle/spiffworkflow.json | 13 +- test/spec/bpmn/simple_collab.bpmn | 351 +++++++----------- 9 files changed, 330 insertions(+), 266 deletions(-) create mode 100644 app/spiffworkflow/messages/propertiesPanel/MessageVariable.js diff --git a/app/app.js b/app/app.js index ca3d573..950be18 100644 --- a/app/app.js +++ b/app/app.js @@ -4,7 +4,7 @@ import { BpmnPropertiesProviderModule, } from 'bpmn-js-properties-panel'; import FileSaver from 'file-saver'; -import diagramXML from '../test/spec/bpmn/collaboration.bpmn'; +import diagramXML from '../test/spec/bpmn/simple_collab.bpmn'; import spiffworkflow from './spiffworkflow'; const modelerEl = document.getElementById('modeler'); diff --git a/app/spiffworkflow/messages/MessageHelpers.js b/app/spiffworkflow/messages/MessageHelpers.js index 4bf91fb..61f16c4 100644 --- a/app/spiffworkflow/messages/MessageHelpers.js +++ b/app/spiffworkflow/messages/MessageHelpers.js @@ -15,6 +15,14 @@ export function getRoot(element) { return element; } +export function isMessageElement(shapeElement) { + return ( + is(shapeElement, 'bpmn:SendTask') || + is(shapeElement, 'bpmn:ReceiveTask') || + isMessageEvent(shapeElement) + ); +} + export function isMessageEvent(shapeElement) { const { eventDefinitions } = shapeElement.businessObject; if (eventDefinitions && eventDefinitions[0]) { @@ -23,26 +31,39 @@ export function isMessageEvent(shapeElement) { return false; } -export function getMessageRefElement(businessObject) { - if (businessObject.$type === 'bpmn:IntermediateThrowEvent') { - const messageEventDefinition = businessObject.eventDefinitions[0]; +export function canReceiveMessage(shapeElement) { + if (is(shapeElement, 'bpmn:ReceiveTask')) { + return true; + } + if (isMessageEvent(shapeElement)) { + return ( + is(shapeElement, 'bpmn:StartEvent') || is(shapeElement, 'bpmn:CatchEvent') + ); + } + return false; +} + +export function getMessageRefElement(shapeElement) { + if (isMessageEvent(shapeElement)) { + const messageEventDefinition = + shapeElement.businessObject.eventDefinitions[0]; if (messageEventDefinition && messageEventDefinition.messageRef) { return messageEventDefinition.messageRef; } } else if ( - businessObject.$type === 'bpmn:SendTask' && - businessObject.messageRef + isMessageElement(shapeElement) && + shapeElement.businessObject.messageRef ) { - return businessObject.messageRef; + return shapeElement.businessObject.messageRef; } - return ''; + return null; } -export function findFormalExpressions(businessObject) { +export function findFormalExpressions(shapeElement) { const formalExpressions = []; - const messageRef = getMessageRefElement(businessObject); + const messageRef = getMessageRefElement(shapeElement); if (messageRef) { - const root = getRoot(businessObject); + const root = getRoot(shapeElement.businessObject); if (root.$type === 'bpmn:Definitions') { for (const childElement of root.rootElements) { if (childElement.$type === 'bpmn:CorrelationProperty') { @@ -99,7 +120,6 @@ export function findCorrelationKeys(element) { if (rootElement.$type === 'bpmn:Collaboration') { const currentKeys = rootElement.correlationKeys; for (const correlationKey in currentKeys) { - const correlationProperties = []; const currentCorrelation = rootElement.correlationKeys[correlationKey]; const currentProperty = {}; currentProperty.name = currentCorrelation.name; diff --git a/app/spiffworkflow/messages/propertiesPanel/MessageCorrelationsArray.js b/app/spiffworkflow/messages/propertiesPanel/MessageCorrelationsArray.js index 7a7e127..db2f483 100644 --- a/app/spiffworkflow/messages/propertiesPanel/MessageCorrelationsArray.js +++ b/app/spiffworkflow/messages/propertiesPanel/MessageCorrelationsArray.js @@ -16,7 +16,7 @@ export function MessageCorrelationsArray(props) { const { commandStack } = props; // const { elementRegistry } = props; - const formalExpressions = findFormalExpressions(element.businessObject); + const formalExpressions = findFormalExpressions(element); const items = formalExpressions.map((formalExpression) => { const id = `correlation-${formalExpression.correlationId}`; const entries = MessageCorrelationGroup({ diff --git a/app/spiffworkflow/messages/propertiesPanel/MessagePayload.js b/app/spiffworkflow/messages/propertiesPanel/MessagePayload.js index 9e1e592..ffbdeee 100644 --- a/app/spiffworkflow/messages/propertiesPanel/MessagePayload.js +++ b/app/spiffworkflow/messages/propertiesPanel/MessagePayload.js @@ -10,12 +10,11 @@ import { */ export function MessagePayload(props) { const shapeElement = props.element; - const { commandStack } = props; const debounce = useService('debounceInput'); const getMessagePayloadObject = () => { const { businessObject } = shapeElement; - const taskMessage = getMessageRefElement(businessObject); + const taskMessage = getMessageRefElement(shapeElement); const messages = findMessageModdleElements(businessObject); if (taskMessage) { for (const message of messages) { @@ -37,28 +36,26 @@ export function MessagePayload(props) { const getValue = () => { const messagePayloadObject = getMessagePayloadObject(); if (messagePayloadObject) { - return messagePayloadObject.payload; + return messagePayloadObject.messagePayload; } return ''; }; const setValue = (value) => { const { businessObject } = shapeElement; - let MessagePayloadObject = getMessagePayloadObject(); - if (!MessagePayloadObject) { - MessagePayloadObject = businessObject.$model.create( + let messagePayloadObject = getMessagePayloadObject(); + if (!messagePayloadObject) { + messagePayloadObject = businessObject.$model.create( 'spiffworkflow:messagePayload' ); - // if (type !== SCRIPT_TYPE.bpmn) { if (!businessObject.extensionElements) { businessObject.extensionElements = businessObject.$model.create( 'bpmn:ExtensionElements' ); } - businessObject.extensionElements.get('values').push(MessagePayloadObject); - // } + businessObject.extensionElements.get('values').push(messagePayloadObject); } - MessagePayloadObject.payload = value; + messagePayloadObject.messagePayload = value; }; return ( diff --git a/app/spiffworkflow/messages/propertiesPanel/MessageSelect.js b/app/spiffworkflow/messages/propertiesPanel/MessageSelect.js index 7dd9209..8dd7748 100644 --- a/app/spiffworkflow/messages/propertiesPanel/MessageSelect.js +++ b/app/spiffworkflow/messages/propertiesPanel/MessageSelect.js @@ -3,6 +3,7 @@ import { SelectEntry } from '@bpmn-io/properties-panel'; import { findMessageModdleElements, getMessageRefElement, + isMessageEvent, } from '../MessageHelpers'; /** @@ -14,7 +15,8 @@ export function MessageSelect(props) { const debounce = useService('debounceInput'); const getValue = () => { - const messageRefElement = getMessageRefElement(shapeElement.businessObject); + const messageRefElement = getMessageRefElement(shapeElement); + console.log('messageRefElement', messageRefElement); if (messageRefElement) { return messageRefElement.id; } @@ -27,7 +29,7 @@ export function MessageSelect(props) { const messages = findMessageModdleElements(shapeElement.businessObject); for (const message of messages) { if (message.id === value) { - if (businessObject.$type === 'bpmn:IntermediateThrowEvent') { + if (isMessageEvent(shapeElement)) { const messageEventDefinition = businessObject.eventDefinitions[0]; messageEventDefinition.messageRef = message; // call this to update the other elements in the props panel like payload @@ -35,7 +37,10 @@ export function MessageSelect(props) { element: shapeElement, moddleElement: businessObject, }); - } else if (businessObject.$type === 'bpmn:SendTask') { + } else if ( + businessObject.$type === 'bpmn:ReceiveTask' || + businessObject.$type === 'bpmn:SendTask' + ) { commandStack.execute('element.updateModdleProperties', { element: shapeElement, moddleElement: businessObject, diff --git a/app/spiffworkflow/messages/propertiesPanel/MessageVariable.js b/app/spiffworkflow/messages/propertiesPanel/MessageVariable.js new file mode 100644 index 0000000..a13edeb --- /dev/null +++ b/app/spiffworkflow/messages/propertiesPanel/MessageVariable.js @@ -0,0 +1,76 @@ +import { useService } from 'bpmn-js-properties-panel'; +import { TextFieldEntry } from '@bpmn-io/properties-panel'; +import { + findMessageModdleElements, + getMessageRefElement, +} from '../MessageHelpers'; + +/** + * Allows the creation, or editing of messageVariable at the bpmn:sendTask level of a BPMN document. + */ +export function MessageVariable(props) { + const shapeElement = props.element; + const debounce = useService('debounceInput'); + + const getMessageVariableObject = () => { + const { businessObject } = shapeElement; + const taskMessage = getMessageRefElement(shapeElement); + const messages = findMessageModdleElements(businessObject); + if (taskMessage) { + for (const message of messages) { + if (message.id === taskMessage.id) { + const { extensionElements } = message; + if (extensionElements) { + return message.extensionElements + .get('values') + .filter(function getInstanceOfType(e) { + return e.$instanceOf('spiffworkflow:messageVariable'); + })[0]; + } + } + } + } + return null; + }; + + const getValue = () => { + const messageVariableObject = getMessageVariableObject(); + // console.log('messageVariableObject', messageVariableObject); + if (messageVariableObject) { + return messageVariableObject.messageVariable; + } + return ''; + }; + + const setValue = (value) => { + const { businessObject } = shapeElement; + let messageVariableObject = getMessageVariableObject(); + // console.log('messageVariableObject', messageVariableObject); + if (!messageVariableObject) { + messageVariableObject = businessObject.$model.create( + 'spiffworkflow:messageVariable' + ); + if (!businessObject.extensionElements) { + businessObject.extensionElements = businessObject.$model.create( + 'bpmn:ExtensionElements' + ); + } + businessObject.extensionElements + .get('values') + .push(messageVariableObject); + } + messageVariableObject.messageVariable = value; + }; + + return ( + + ); +} diff --git a/app/spiffworkflow/messages/propertiesPanel/MessagesPropertiesProvider.js b/app/spiffworkflow/messages/propertiesPanel/MessagesPropertiesProvider.js index 8470c3e..1681623 100644 --- a/app/spiffworkflow/messages/propertiesPanel/MessagesPropertiesProvider.js +++ b/app/spiffworkflow/messages/propertiesPanel/MessagesPropertiesProvider.js @@ -3,8 +3,9 @@ import { is } from 'bpmn-js/lib/util/ModelUtil'; import { CorrelationKeysArray } from './CorrelationKeysArray'; import { MessageSelect } from './MessageSelect'; import { MessagePayload } from './MessagePayload'; +import { MessageVariable } from './MessageVariable'; import { MessageCorrelationsArray } from './MessageCorrelationsArray'; -import { isMessageEvent } from '../MessageHelpers'; +import { isMessageElement, canReceiveMessage } from '../MessageHelpers'; const LOW_PRIORITY = 500; @@ -27,9 +28,11 @@ export default function MessagesPropertiesProvider( elementRegistry ) ); - } else if (is(element, 'bpmn:SendTask') || isMessageEvent(element)) { + } else if (isMessageElement(element)) { const messageIndex = findEntry(groups, 'message'); - groups.splice(messageIndex, 1); + if (messageIndex) { + groups.splice(messageIndex, 1); + } groups.push( createMessageGroup( element, @@ -97,37 +100,52 @@ function createMessageGroup( commandStack, elementRegistry ) { + const entries = [ + { + id: 'selectMessage', + element, + component: MessageSelect, + isEdited: isTextFieldEntryEdited, + moddle, + commandStack, + }, + ]; + + if (canReceiveMessage(element)) { + entries.push({ + id: 'messageVariable', + element, + component: MessageVariable, + isEdited: isTextFieldEntryEdited, + moddle, + commandStack, + }); + } else { + entries.push({ + id: 'messagePayload', + element, + component: MessagePayload, + isEdited: isTextFieldEntryEdited, + moddle, + commandStack, + }); + } + + entries.push({ + id: 'messageCorrelations', + label: translate('Message Correlations'), + component: ListGroup, + ...MessageCorrelationsArray({ + element, + moddle, + commandStack, + elementRegistry, + }), + }); + return { id: 'messages', label: translate('Message'), - entries: [ - { - id: 'selectMessage', - element, - component: MessageSelect, - isEdited: isTextFieldEntryEdited, - moddle, - commandStack, - }, - { - id: 'messagePayload', - element, - component: MessagePayload, - isEdited: isTextFieldEntryEdited, - moddle, - commandStack, - }, - { - id: 'messageCorrelations', - label: translate('Message Correlations'), - component: ListGroup, - ...MessageCorrelationsArray({ - element, - moddle, - commandStack, - elementRegistry, - }), - }, - ], + entries, }; } diff --git a/app/spiffworkflow/moddle/spiffworkflow.json b/app/spiffworkflow/moddle/spiffworkflow.json index 61d3adc..896cfbb 100644 --- a/app/spiffworkflow/moddle/spiffworkflow.json +++ b/app/spiffworkflow/moddle/spiffworkflow.json @@ -31,7 +31,18 @@ "superClass": [ "Element" ], "properties": [ { - "name": "payload", + "name": "messagePayload", + "isBody": true, + "type": "String" + } + ] + }, + { + "name": "messageVariable", + "superClass": [ "Element" ], + "properties": [ + { + "name": "messageVariable", "isBody": true, "type": "String" } diff --git a/test/spec/bpmn/simple_collab.bpmn b/test/spec/bpmn/simple_collab.bpmn index 699091e..9495bcd 100644 --- a/test/spec/bpmn/simple_collab.bpmn +++ b/test/spec/bpmn/simple_collab.bpmn @@ -1,209 +1,146 @@ - - - - - - - - invoice_id - invoice_date - invoice_total - - - payment_id - payment_date - payment_total - - - - - - - { - 'invoice': { 'id': my_invoice_id, 'date': my_invoice_date, 'total': my_invoice_total } - } - - - - - - - - { 'payment': - { - 'id': my_payment_id, - 'date': my_payment_date, - 'total': my_payment_total, - 'invoice_id': invoice_id, - 'invoice_date': invoice_data, - 'invoice_amount': invoice_amount, - } - } - - - - - - - invoice.invoice_id - - - payment.invoice_id - - - - - - invoice.total - - - payment.invoice_amount - - - - - - invoice.date - - - payment.invoice_date - - - - - - payment.id - - - - - - Flow_1bl6jeh - - - Flow_1bl6jeh - Flow_1vgtrb2 - - - - - Flow_1f0m6hd - - - Flow_1vgtrb2 - Flow_1ygtaxw - - - - - Flow_1ygtaxw - Flow_1f0m6hd - - - - - Flow_1bnzzx2 - - - - - - - Flow_11malws - - - Flow_07sdx2y - Flow_11malws - - - - Flow_1bnzzx2 - Flow_07sdx2y - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + message_correlation_property + + + + + to + + + from.name + + + + + Flow_176e02g + + + + + + Flow_176e02g + Flow_037vpjk + + + Flow_037vpjk + Flow_1qgz6p0 + + + + Flow_1qgz6p0 + + + + + {"to": "the_recipient1" } + + + + + {"from": {"name": "the_sender"}} + + + + + Flow_0505x87 + + + + Flow_1273yit + + + + + Flow_0505x87 + Flow_1273yit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +