Skip to content
This repository was archived by the owner on Nov 9, 2022. It is now read-only.

Commit 6071ff9

Browse files
committed
Fixes #1
1 parent 368f5ed commit 6071ff9

File tree

15 files changed

+339
-75
lines changed

15 files changed

+339
-75
lines changed

.project

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
<arguments>
1111
</arguments>
1212
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.wst.validation.validationbuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
1318
</buildSpec>
1419
<natures>
1520
<nature>org.eclipse.bpmn2.modeler.core.bpmn2Nature</nature>

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,5 +135,5 @@ to your code.
135135

136136
### Further information
137137

138-
[issue tracker]: https://github.com/adamfowleruk/marklogicworkflow/issues
139-
[.editorconfig]: http://editorconfig.org/
138+
- [issue tracker](https://github.com/adamfowleruk/marklogicworkflow/issues)
139+
- [.editorconfig](http://editorconfig.org/)

data/examples/bpmn2/011_gateways_test.bpmn

Lines changed: 95 additions & 32 deletions
Large diffs are not rendered by default.

data/examples/bpmn2/021-initiating-attachment.bpmn

Lines changed: 119 additions & 18 deletions
Large diffs are not rendered by default.

documentation/SPRINTS.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ steps if a duplicate is found. Requires search (by property hash AND not (same u
4242
- DONE Evaluation: Support for fn:doc(/process/attachments/attachment[@name="default"]/uri/text())/some/path/to/property style evaluation
4343
- DONE Evaluation: replace $processData or $wf:process with fn:doc($processUri) everywhere in xpath expression
4444
- DONE can use fn:current-dateTime - Evaluation: Support for 'now' date time assignment to variable
45-
- Activity: Set process variable activity with multiple from and to (simple XPath evaluation)
45+
- DEFERRED Activity: Set process variable activity with multiple from and to (simple XPath evaluation)
4646
- See if there is an equivalent BPMN2 method - may just be a variable assignment on each step instead
4747
- Create import step for this BPMN2 method
4848
- Create CPF action to represent this
@@ -65,7 +65,7 @@ steps if a duplicate is found. Requires search (by property hash AND not (same u
6565
- DONE processinbox.xqy
6666
- DONE processqueue.xqy
6767
- TEST support for roles (processroleinbox.xqy) on user tasks (For BD)
68-
- TEST BPMN2: send task -> 1 of 2: send Email (Implemented as an example message driven task)
68+
- DONE BPMN2: send task -> 1 of 2: send Email (Implemented as an example message driven task)
6969
- DONE Test scripts for automating install, create, get, update, complete via REST API
7070
- DONE Bug: Change process model URI folder to include major and minor - else doing process doc update may run new pipeline instead of old one
7171
- DONE Bug: Multiple wf:status properties on in process process, complete and running
@@ -75,6 +75,7 @@ steps if a duplicate is found. Requires search (by property hash AND not (same u
7575
- Incident Management Account Manager Only
7676
- Incident Management Process Engine only
7777
- DONE basic documentation for supported step types and their configuration (STEPS.md)
78+
- DONE Scripting - change $wf:process/ replacement to $wf:process external variable declaration (much less buggy to implement)
7879

7980
## Sprint 2 - Process Orchestration
8081

@@ -85,7 +86,6 @@ steps if a duplicate is found. Requires search (by property hash AND not (same u
8586
- BPMN2: call activity (process or global task)
8687
- BPMN2: parallel gateway -> fork to or synchronise from all flow paths
8788
- BPMN2: complex gateway -> E.g. 3 of 5 incoming routes required in order to activate gateway
88-
- CPF: Invoke CPF pipeline
8989
- BPMN2: service task -> invoke service and process response
9090
- Update Eclipse Modeler palette
9191
- Enterprise features

documentation/STEPS.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,16 @@ To create an operation:-
100100
- You can name these anything you like, be sure to provide a name and an implementation name
101101
- Set the Out Message to point to an XML Schema definition that consists of your message
102102

103-
TODO Document how the VALUE not SCHEMA for this message is created (read BPMN2 spec and examples).
103+
104+
*WARNING: If you type 'RejectedEmail' as the name of the Out Message, then MarkLogic workflow will check the MODULES
105+
database for a document called /workflowengine/assets/PROCESSNAME/MAJORVERSION/MINORVERSION/RejectedEmail.xml. If this
106+
document does not exist, it will check in the major version folder, and failing that in the process name folder. This is
107+
because (unbelievably) BPMN2 does not support data modelling, and such the structure of the message is out of scope of
108+
the modelling tool. It is possible to add a 'structure' definition in BPMN2 that points to a fixed XML message, BUT this
109+
is not supported by any modelling tool! Only XML Schema (for the structure of the email, not the template) is supported.*
110+
111+
The format of the outgoing email message (Out Message) can be found in the
112+
[xdmp:email online docs](http://docs.marklogic.com/xdmp:email).
104113

105114
Now go back and edit the Send Task:-
106115
- Left click on the send task
@@ -113,6 +122,10 @@ Now go back and edit the Send Task:-
113122

114123
Save the process diagram (validates your configuration of the task - no red stars mean it's configured properly).
115124

125+
For configuring a local mail agent to test this task, see [The CentOS website](http://wiki.centos.org/HowTos/postfix#head-c02f30bf0669d9b47a6c14c114243338b5ea1f27). Don't forget to set an
126+
alias pointing 'admin' at your local linux machine's logged in user - you can then use Thunderbird to receive email
127+
from the sample processes.
128+
116129
## Additional notes
117130

118131
There are some configuration elements that are true across multiple steps. These are documented below.

modules/app/models/workflow-import.xqy

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -661,11 +661,14 @@ declare function m:bpmn2-to-cpf($pname as xs:string, $doc as element(b2:definiti
661661

662662
(: Send email example - sendTask.xqy :)
663663
for $state in $start/b2:sendTask
664-
let $message := $doc/b2:message[@id = $state/@messageRef]
664+
let $messageText := xs:string($doc/b2:message[@id = $state/@messageRef]/@name)
665+
(:
665666
let $item := $doc/b2:itemDefinition[@id = $message/@itemRef]
666667
let $structureRef := xs:string($item/@structureRef)
667-
let $messageXml := () (: TODO get actual message value, followed by replacement(s) :)
668+
668669
let $operation := $doc/b2:interface/b2:operation[@id = $state/@operationRef]
670+
:)
671+
669672
let $route := xs:string($state/b2:outgoing[1]) (: TODO support split here? :)
670673
let $rc :=
671674
if (fn:contains($route,":")) then
@@ -679,10 +682,7 @@ declare function m:bpmn2-to-cpf($pname as xs:string, $doc as element(b2:definiti
679682
$failureState,(),
680683
p:action("/workflowengine/actions/sendTask.xqy","BPMN2 Send Task: "||xs:string($state/@name),
681684
<options xmlns="/workflowengine/actions/sendTask.xqy">
682-
{ (: Message :)
683-
$messageXml
684-
(: TODO distinguish between email message and web service invocation (fire and forget) :)
685-
}
685+
<wf:message>{$messageText}</wf:message>
686686
</options>
687687
),()
688688
)

modules/app/models/workflow-util.xqy

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,24 @@ declare function m:getProcessUri($processId as xs:string) as xs:string? {
5858
(fn:collection("http://marklogic.com/workflow/processes")/wf:process[./@id = $processId]/fn:base-uri(.))
5959
};
6060

61+
declare function m:getProcessAsset($processUri as xs:string,$assetname as xs:string) as node()? {
62+
xdmp:eval(
63+
'xquery version "1.0-ml";declare namespace wf="http://marklogic.com/workflow";' ||
64+
'declare variable $wf:process as element(wf:process) external;' ||
65+
'declare variable $wf:assetname as xs:string external;' ||
66+
'(fn:doc("/workflowengine/assets/" || xs:string($wf:process/@name) || "/" || xs:string($wf:process/@major) || "/" || xs:string($wf:process/@minor) || "/" || $wf:assetname ),' ||
67+
' fn:doc("/workflowengine/assets/" || xs:string($wf:process/@name) || "/" || xs:string($wf:process/@major) || "/" || $wf:assetname ),' ||
68+
' fn:doc("/workflowengine/assets/" || xs:string($wf:process/@name) || "/" || $wf:assetname )' ||
69+
')[1]'
70+
,
71+
(xs:QName("wf:process"),fn:doc($processUri)/wf:process,xs:QName("wf:assetname"),$assetname),
72+
<options xmlns="xdmp:eval">
73+
<database>{xdmp:modules-database()}</database>
74+
<isolation>different-transaction</isolation>
75+
</options>
76+
) (: MUST be executed in the modules DB - where the assets live :)
77+
};
78+
6179

6280

6381

@@ -247,7 +265,10 @@ declare function m:metric($processUri as xs:string,$state as xs:string,$start as
247265
)
248266
};
249267

250-
declare function m:evaluate($processUri as xs:string,$namespaces as element(wf:namespace)*,$xpath as xs:string) as xs:boolean {
268+
(:
269+
: The below has been replaced by an eval (m:evaluate), which bypasses the string replacement approach
270+
271+
declare function m:evaluateOLD($processUri as xs:string,$namespaces as element(wf:namespace)*,$xpath as xs:string) as xs:boolean {
251272
252273
let $_ := xdmp:log("In wfu:evaluate")
253274
@@ -276,3 +297,42 @@ declare function m:evaluate($processUri as xs:string,$namespaces as element(wf:n
276297
return
277298
$result
278299
};
300+
:)
301+
302+
declare function m:evaluate($processUri as xs:string,$namespaces as element(wf:namespace)*,$xpath as xs:string) as xs:boolean {
303+
let $ns :=
304+
for $namespace in $namespaces
305+
return
306+
if (fn:not(fn:empty($namespace/@short/text())) and fn:not(fn:empty($namespace/@long/text()))) then
307+
"declare namespace " || $namespace/@short/text() || ' = "' || $namespace/@long/text() || '"; '
308+
else ""
309+
let $xquery :=
310+
'xquery version "1.0-ml";declare namespace wf="http://marklogic.com/workflow";' || $ns ||
311+
'declare variable $wf:process as element(wf:process) external;' ||
312+
$xpath
313+
let $_ := xdmp:log($xquery)
314+
return
315+
xdmp:eval($xquery,
316+
(xs:QName("wf:process"),fn:doc($processUri)/wf:process),
317+
<options xmlns="xdmp:eval">
318+
<isolation>different-transaction</isolation>
319+
</options>
320+
)
321+
};
322+
323+
declare function m:evaluateXml($processUri as xs:string,$namespaces as element(wf:namespace)*,$xmlText as xs:string,$params as node()*) as node()* {
324+
let $xquery := 'xquery version "1.0-ml";declare namespace wf="http://marklogic.com/workflow";' ||
325+
'declare variable $wf:process as element(wf:process) external;' || $xmlText
326+
let $_ := xdmp:log("wfu:evaluateXml: xquery: " || $xquery)
327+
let $result :=
328+
xdmp:eval($xquery,
329+
(xs:QName("wf:process"),fn:doc($processUri)/wf:process), (: TODO accept external params without having blank params of () in the eval call :)
330+
<options xmlns="xdmp:eval">
331+
<isolation>different-transaction</isolation>
332+
</options>
333+
)
334+
let $_ := xdmp:log("wfu:evaluateXml: result:-")
335+
let $_ := xdmp:log($result)
336+
let $_ := xdmp:log("wfu:evaluateXml: Complete. Returning...")
337+
return $result
338+
};

modules/workflowengine/actions/sendTask.xqy

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ declare variable $cpf:options as element() external;
2222
<wf:namespaces>
2323
<wf:namespace short="xh" long="http://some/xml/ns" />
2424
</wf:namespaces>
25-
<wf:message xmlns:wf="http://marklogic.com/workflow">
26-
XML SMTP MESSSAGE FORMAT AS PER xdmp:email with {/wf:process/some/parameter} replacements.
27-
</wf:message>
25+
<wf:message>EmailTest</wf:message>
2826
</options>
2927
</action>
3028
</execute>
@@ -38,18 +36,26 @@ try {
3836
let $ns := ($cpf:options/wf:namespaces/wf:namespace,<wf:namespace short="wf" long="http://marklogic.com/workflow" />)
3937
(: Default namespace is same as process doc :) (: TODO mix in those from BPMN2 doc :)
4038

41-
let $message := $cpf:options/wf:message/node() (: XML send email format from xdmp:email :)
42-
43-
(: TODO perform active parameter replacements withing text of email :)
44-
39+
let $message := xs:string($cpf:options/wf:message) (: XML send email format from xdmp:email :)
4540
let $_ := xdmp:log("sendTask: Email message:-")
4641
let $_ := xdmp:log($message)
4742

4843

44+
let $messageText := wfu:getProcessAsset($cpf:document-uri,$message || ".txt")/text() (: This is a text file!!! Not XML :)
45+
let $_ := xdmp:log($messageText)
46+
47+
(: Perform replacements across returned content :)
48+
let $messageXml := wfu:evaluateXml($cpf:document-uri,$ns,$messageText, ()) (: TODO pass in real parameters, like to and from email etc.? Or just do inside template? :)
49+
50+
51+
let $_ := xdmp:log("sendTask: Email message result XML:-")
52+
let $_ := xdmp:log($messageXml)
53+
54+
4955
(: If still none, throw failure message (misconfiguration) :)
5056
return
5157
(
52-
xdmp:email($message)
58+
xdmp:email($messageXml)
5359
,
5460
wfu:complete( $cpf:document-uri, $cpf:transition, (), $st )
5561
)

modules/workflowengine/actions/startEvent.xqy

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import module namespace cpf = "http://marklogic.com/cpf" at "/MarkLogic/cpf/cpf.
44
import module namespace wfu="http://marklogic.com/workflow-util" at "/app/models/workflow-util.xqy";
55

66
declare namespace wf="http://marklogic.com/workflow";
7+
declare namespace p="http://marklogic.com/cpf/pipelines";
78

89
declare variable $cpf:document-uri as xs:string external;
910
declare variable $cpf:transition as node() external;
@@ -28,9 +29,18 @@ declare variable $cpf:options as element() external;
2829

2930
try {
3031
let $st := fn:current-dateTime()
32+
let $_ := xdmp:log($cpf:transition)
33+
let $parts := fn:tokenize($cpf:transition/p:state/text(),"/")
34+
let $_ := xdmp:log($parts)
35+
let $processinfo := fn:tokenize($parts[fn:last() - 1],"__")
36+
let $_ := xdmp:log($processinfo)
3137
return
3238
(
3339
(: set initial Workflow properties :)
40+
xdmp:node-insert-child(fn:doc($cpf:document-uri)/wf:process,attribute title {$parts[fn:last() - 1]}),
41+
xdmp:node-insert-child(fn:doc($cpf:document-uri)/wf:process,attribute name {$processinfo[1]}),
42+
xdmp:node-insert-child(fn:doc($cpf:document-uri)/wf:process,attribute major {$processinfo[2]}),
43+
xdmp:node-insert-child(fn:doc($cpf:document-uri)/wf:process,attribute minor {$processinfo[3]}),
3444
xdmp:document-add-properties($cpf:document-uri,
3545
(
3646
<wf:start>{fn:current-dateTime()}</wf:start>

0 commit comments

Comments
 (0)