diff --git a/rest-api/ext/processmodel.xqy b/rest-api/ext/processmodel.xqy index b8b168a..7f9bbc4 100644 --- a/rest-api/ext/processmodel.xqy +++ b/rest-api/ext/processmodel.xqy @@ -69,7 +69,6 @@ function ext:put( let $enable := if (map:get($params,"enable") = "true") then fn:true() else fn:false() let $_ := xdmp:log("Enabled? : " || xs:string($enable)) - let $input := xdmp:unquote(xdmp:quote($input)) let $modelid := wfi:install-and-convert($input,map:get($params,"name"),(map:get($params,"major"),"1")[1],(map:get($params,"minor"),"0")[1], $enable ) let $out := SUCCESS{$modelid} diff --git a/src/app/models/lib-alerts.xqy b/src/app/models/lib-alerts.xqy index 3008b73..9679399 100644 --- a/src/app/models/lib-alerts.xqy +++ b/src/app/models/lib-alerts.xqy @@ -21,42 +21,31 @@ declare function ss:add-alert($shortname as xs:string,$query as schema-element(c declare function ss:do-create-config($shortname as xs:string) as xs:string { - xdmp:eval( - 'xquery version "1.0-ml"; declare namespace my="http://marklogic.com/alerts"; ' || - 'import module namespace ah = "http://marklogic.com/alerts/alerts" at "/app/models/lib-alerts.xqy";' || - 'import module namespace alert="http://marklogic.com/xdmp/alert" at "/MarkLogic/alert.xqy";' || - 'declare variable $my:shortname as xs:string external;' || - 'ah:create-config($my:shortname)', - (xs:QName("my:shortname"),$shortname), + xdmp:invoke-function( + function(){ + ss:create-config($shortname) + } + , different-transaction ) }; declare function ss:do-create-rule($alert-name as xs:string,$query as cts:query,$options as element()*) { - xdmp:eval( - 'xquery version "1.0-ml"; declare namespace my="http://marklogic.com/alerts"; ' || - 'import module namespace ah = "http://marklogic.com/alerts/alerts" at "/app/models/lib-alerts.xqy";' || - 'import module namespace alert="http://marklogic.com/xdmp/alert" at "/MarkLogic/alert.xqy";' || - 'declare variable $my:alert-name as xs:string external;' || - 'declare variable $my:query as cts:query external;' || - 'declare variable $my:options as element* external;' || - 'ah:create-rule($my:alert-name,$my:query,$my:options)', - (xs:QName("my:alert-name"),$alert-name,xs:QName("my:query"),$query,xs:QName("my:options"),$options), + xdmp:invoke-function( + function(){ + ss:create-rule($alert-name, $query, $options) + } + , different-transaction ) }; declare function ss:do-create-action($alert-name as xs:string,$alert-module as xs:string,$db as xs:unsignedLong,$options as element()*) { - xdmp:eval( - 'xquery version "1.0-ml"; declare namespace my="http://marklogic.com/alerts"; ' || - 'import module namespace ah = "http://marklogic.com/alerts/alerts" at "/app/models/lib-alerts.xqy";' || - 'import module namespace alert="http://marklogic.com/xdmp/alert" at "/MarkLogic/alert.xqy";' || - 'declare variable $my:alert-name as xs:string external;' || - 'declare variable $my:alert-module as xs:string external;' || - 'declare variable $my:db as xs:unsignedLong external;' || - 'declare variable $my:options as element* external;' || - 'ah:create-action($my:alert-name,$my:alert-module,$my:db,$my:options)', - (xs:QName("my:alert-name"),$alert-name,xs:QName("my:alert-module"),$alert-module,xs:QName("my:db"),$db,xs:QName("my:options"),$options), + xdmp:invoke-function( + function(){ + ss:create-action($alert-name, $alert-module, $db, $options) + } + , different-transaction ) }; diff --git a/src/app/models/lib-search-subscribe.xqy b/src/app/models/lib-search-subscribe.xqy index 347c856..76215f2 100644 --- a/src/app/models/lib-search-subscribe.xqy +++ b/src/app/models/lib-search-subscribe.xqy @@ -3,6 +3,8 @@ xquery version "1.0-ml"; module namespace ss = "http://marklogic.com/search/subscribe"; import module namespace alert="http://marklogic.com/xdmp/alert" at "/MarkLogic/alert.xqy"; +import module namespace dom = "http://marklogic.com/cpf/domains" at "/MarkLogic/cpf/domains.xqy"; +import module namespace p="http://marklogic.com/cpf/pipelines" at "/MarkLogic/cpf/pipelines.xqy"; declare namespace my="http://marklogic.com/alerts"; @@ -103,11 +105,12 @@ declare function ss:unsubscribe-and-delete-search($searchname,$notificationurl) declare function ss:save-subscribe-search($searchdoc as cts:query,$searchname as xs:string,$notificationurl as xs:string,$alert-detail as xs:string?,$content-type as xs:string?) { (: use current user on app server :) - ( xdmp:eval( - fn:concat('xquery version "1.0-ml"; declare namespace my="http://marklogic.com/alerts"; import module namespace ah = "http://marklogic.com/search/subscribe" at "/modules/lib-search-subscribe.xqy";', - 'declare variable $my:searchdoc as cts:query external;declare variable $my:searchname as xs:string external;', - 'ah:do-save($my:searchdoc,$my:searchname)'), - (xs:QName("my:searchdoc"),$searchdoc,xs:QName("my:searchname"),$searchname), + ( + xdmp:invoke-function( + function(){ + ss:do-save ($searchdoc, $searchname) + } + , different-transaction ) ,ss:do-subscribe-check($notificationurl,$searchname,$alert-detail,$content-type) @@ -159,39 +162,41 @@ declare function ss:do-subscribe-check($notificationurl as xs:string,$searchname declare function ss:do-add-action-rule($alert-name as xs:string,$notificationurl as xs:string,$alert-module as xs:string?,$alert-detail as xs:string,$content-type as xs:string,$searchname as xs:string,$cpf-domain as xs:string,$dbname as xs:string,$searchdoc as cts:query?) as xs:boolean { - let $e2 := xdmp:eval( - fn:concat('xquery version "1.0-ml"; declare namespace my="http://marklogic.com/alerts"; import module namespace ah = "http://marklogic.com/search/subscribe" at "/modules/lib-search-subscribe.xqy";', - 'declare variable $my:alert-name as xs:string external;declare variable $my:alert-module as xs:string external;declare variable $my:dbname as xs:string external;', - 'ah:create-action($my:alert-name,$my:alert-module,$my:dbname,())'), - (xs:QName("my:alert-name"),$alert-name,xs:QName("my:alert-module"),$alert-module,xs:QName("my:dbname"),$dbname), + let $e2 := xdmp:invoke-function( + function(){ + ss:create-action($alert-name, $alert-module, $dbname, ()) + } + , different-transaction ) - let $e3 := xdmp:eval( - fn:concat('xquery version "1.0-ml"; declare namespace my="http://marklogic.com/alerts"; import module namespace ah = "http://marklogic.com/search/subscribe" at "/modules/lib-search-subscribe.xqy";', - 'declare variable $my:alert-name as xs:string external;declare variable $my:alert-detail as xs:string external;declare variable $my:content-type as xs:string external;', - 'declare variable $my:notificationurl as xs:string external;declare variable $my:searchname as xs:string external;declare variable $my:searchdoc as cts:query external;', - 'ah:create-rule-notify($my:alert-name,$my:alert-detail,$my:content-type,$my:notificationurl,$my:searchname,$my:searchdoc)'), - (xs:QName("my:alert-name"),$alert-name,xs:QName("my:alert-detail"),$alert-detail,xs:QName("my:content-type"),$content-type,xs:QName("my:notificationurl"),$notificationurl, - xs:QName("my:searchname"),$searchname,xs:QName("my:searchdoc"),$searchdoc), + let $e3 := xdmp:invoke-function( + function(){ + ss:create-rule-notify($alert-name, $alert-detail, $content-type, $notificationurl, $searchname, $searchdoc) + } + , different-transaction ) return fn:true() }; declare function ss:do-subscribe($notificationurl as xs:string,$alert-module as xs:string?,$alert-detail as xs:string,$content-type as xs:string,$searchname as xs:string,$cpf-domain as xs:string,$dbname as xs:string,$searchdoc as cts:query?) as xs:boolean { - let $alert-name := xdmp:eval( - fn:concat('xquery version "1.0-ml"; declare namespace my="http://marklogic.com/alerts"; import module namespace ah = "http://marklogic.com/search/subscribe" at "/modules/lib-search-subscribe.xqy";', - 'declare variable $my:notificationurl as xs:string external;declare variable $my:searchname as xs:string external;', - 'ah:create-config($my:notificationurl,$my:searchname)'), - (xs:QName("my:notificationurl"),$notificationurl,xs:QName("my:searchname"),$searchname), + let $alert-name := xdmp:invoke-function( + function(){ + (: WARN: this eval counterpart is invalid now: + : ah:create-config($my:notificationurl,$my:searchname) + :) + ss:create-config($notificationurl) + } + , different-transaction ) + let $e2 := ss:do-add-action-rule($alert-name,$notificationurl ,$alert-module,$alert-detail,$content-type,$searchname,$cpf-domain,$dbname,$searchdoc) - let $e4 := xdmp:eval( - fn:concat('xquery version "1.0-ml"; declare namespace my="http://marklogic.com/alerts"; import module namespace ah = "http://marklogic.com/search/subscribe" at "/modules/lib-search-subscribe.xqy";', - 'declare variable $my:alert-name as xs:string external;declare variable $my:cpf-domain as xs:string external;', - 'ah:cpf-enable($my:alert-name,$my:cpf-domain)'), - (xs:QName("my:alert-name"),$alert-name,xs:QName("my:cpf-domain"),$cpf-domain), + let $e4 := xdmp:invoke-function( + function(){ + ss:cpf-enable($alert-name,$cpf-domain) + } + , different-transaction ) let $log := xdmp:log(fn:concat("SUBSCRIBE LOGS: ",$alert-name,$e2,$e4)) @@ -206,25 +211,13 @@ declare function ss:do-unsubscribe($notificationurl as xs:string,$searchname as return alert:rule-remove($alert-name,$rule/@id) - let $l := xdmp:eval( - fn:concat('xquery version "1.0-ml"; declare namespace my="http://marklogic.com/alerts"; import module namespace ah = "http://marklogic.com/search/subscribe" at "/modules/lib-search-subscribe.xqy";', - 'import module namespace alert="http://marklogic.com/xdmp/alert" at "/MarkLogic/alert.xqy";', - 'declare variable $my:alert-name as xs:string external;', - 'alert:config-set-cpf-domain-names(alert:config-get($my:alert-name), ())'), - (xs:QName("my:alert-name"),$alert-name), - different-transaction - )(:) - let $e1 := xdmp:eval( - fn:concat('xquery version "1.0-ml"; declare namespace my="http://marklogic.com/alerts"; import module namespace ah = "http://marklogic.com/search/subscribe" at "/modules/lib-search-subscribe.xqy";', - 'import module namespace alert="http://marklogic.com/xdmp/alert" at "/MarkLogic/alert.xqy";', - 'declare variable $my:alert-name as xs:string external;', - 'alert:config-delete($my:alert-name)'), - (xs:QName("my:alert-name"),$alert-name), + let $l := xdmp:invoke-function( + function(){ + alert:config-set-cpf-domain-names(alert:config-get($alert-name), ()) + } + , different-transaction ) - :) - (:) - let $d := alert:config-delete($alert-name):) return fn:true() }; @@ -271,72 +264,79 @@ declare function ss:get-alert($shortname as xs:string) as element(alert:config)? declare function ss:do-create-config($shortname as xs:string) as xs:string { let $rem := ss:check-remove-config($shortname) - return - xdmp:eval( - 'xquery version "1.0-ml"; declare namespace my="http://marklogic.com/alerts"; ' || - 'import module namespace ah = "http://marklogic.com/search/subscribe" at "/app/models/lib-search-subscribe.xqy";' || - 'import module namespace alert="http://marklogic.com/xdmp/alert" at "/MarkLogic/alert.xqy";' || - 'declare variable $my:shortname as xs:string external;' || - 'ah:create-config($my:shortname)', - (xs:QName("my:shortname"),$shortname), - different-transaction + return xdmp:invoke-function( + function(){ + ss:create-config($shortname) + } + , + + different-transaction + update-auto-commit + ) }; declare function ss:do-create-rule($alert-name as xs:string,$query as cts:query,$options as element()*) as empty-sequence() { - xdmp:eval( - 'xquery version "1.0-ml"; declare namespace my="http://marklogic.com/alerts"; ' || - 'import module namespace ah = "http://marklogic.com/search/subscribe" at "/app/models/lib-search-subscribe.xqy";' || - 'import module namespace alert="http://marklogic.com/xdmp/alert" at "/MarkLogic/alert.xqy";' || - 'declare variable $my:alert-name as xs:string external;' || - 'declare variable $my:query as cts:query external;' || - (:)'declare variable $my:options as element()* external;' ||:) - 'ah:create-rule($my:alert-name,$my:query,())', - (xs:QName("my:alert-name"),$alert-name,xs:QName("my:query"),$query (:,xs:QName("my:options"),($options) :) ), - different-transaction + xdmp:invoke-function( + function(){ + ss:create-rule($alert-name, $query, ()) + } + , + + different-transaction + update-auto-commit + ) }; declare function ss:do-create-action($alert-name as xs:string,$alert-module as xs:string,$dbname as xs:string?,$options as element()*) { - xdmp:eval( - 'xquery version "1.0-ml"; declare namespace my="http://marklogic.com/alerts"; ' || - 'import module namespace ah = "http://marklogic.com/search/subscribe" at "/app/models/lib-search-subscribe.xqy";' || - 'import module namespace alert="http://marklogic.com/xdmp/alert" at "/MarkLogic/alert.xqy";' || - 'declare variable $my:alert-name as xs:string external;' || - 'declare variable $my:alert-module as xs:string external;' || - 'declare variable $my:dbname as xs:string external;' || - 'declare variable $my:options as element()* external;' || - 'ah:create-action($my:alert-name,$my:alert-module,$my:dbname,$my:options)', - (xs:QName("my:alert-name"),$alert-name,xs:QName("my:alert-module"),$alert-module,xs:QName("my:dbname"),$dbname,xs:QName("my:options"),($options)), - different-transaction + xdmp:invoke-function( + function(){ + ss:create-action($alert-name, $alert-module, $dbname, $options) + } + , + + different-transaction + update-auto-commit + ) }; declare function ss:check-remove-config($shortname as xs:string) { let $alert-name := "/config/alerts/" || $shortname - let $config := alert:config-get($alert-name) + let $config := xdmp:invoke-function( + function(){ + alert:config-get($alert-name) + } + , + different-transaction + ) return if (fn:not(fn:empty($config))) then (: Check if config used in a cpf domain, if so remove it from that domain :) - let $unreg := xdmp:eval( - 'xquery version "1.0-ml"; declare namespace my="http://marklogic.com/alerts"; ' || - 'import module namespace alert="http://marklogic.com/xdmp/alert" at "/MarkLogic/alert.xqy";' || - 'declare variable $my:alert-name as xs:string external;' || - 'alert:config-insert(' || - ' alert:config-set-cpf-domain-names(alert:config-get($my:alert-name),())' || - ')', - (xs:QName("my:alert-name"),$alert-name), - different-transaction + let $unreg := xdmp:invoke-function( + function(){ + alert:config-insert( + alert:config-set-cpf-domain-names(alert:config-get($alert-name),()) + ) + } + , + + different-transaction + update-auto-commit + ) (: Do this for each domain - NA all done in one hit:) (: Now remove the alert config :) - return xdmp:eval( - 'xquery version "1.0-ml"; declare namespace my="http://marklogic.com/alerts"; ' || - 'import module namespace alert="http://marklogic.com/xdmp/alert" at "/MarkLogic/alert.xqy";' || - 'declare variable $my:alert-name as xs:string external;' || - 'alert:config-delete($my:alert-name)', - (xs:QName("my:alert-name"),$alert-name), - different-transaction + return xdmp:invoke-function( + function(){ + alert:config-delete($alert-name) + } + , + + different-transaction + update-auto-commit + ) else () }; @@ -397,10 +397,11 @@ declare function ss:create-domain($domainname as xs:string,$domaintype as xs:str let $remove := try { if (fn:not(fn:empty( - xdmp:eval( - 'xquery version "1.0-ml";declare namespace m="http://marklogic.com/alerts"; import module namespace dom = "http://marklogic.com/cpf/domains" at "/MarkLogic/cpf/domains.xqy";declare variable $m:processmodeluri as xs:string external; dom:get($m:processmodeluri)' - , - (xs:QName("my:processmodeluri"),$domainname), + xdmp:invoke-function( + function(){ + dom:get($domainname) + } + , {xdmp:triggers-database()} different-transaction @@ -408,16 +409,16 @@ declare function ss:create-domain($domainname as xs:string,$domaintype as xs:str ) ))) then let $_ := xdmp:log(" GOT DOMAIN TO REMOVE") - return - xdmp:eval( - 'xquery version "1.0-ml";declare namespace m="http://marklogic.com/alerts"; import module namespace dom = "http://marklogic.com/cpf/domains" at "/MarkLogic/cpf/domains.xqy";declare variable $m:processmodeluri as xs:string external;' - || - 'dom:remove($m:processmodeluri)' + return + xdmp:invoke-function( + function(){ + dom:remove($domainname) + } , - (xs:QName("my:processmodeluri"),$domainname), {xdmp:triggers-database()} different-transaction + update-auto-commit ) else @@ -429,38 +430,24 @@ declare function ss:create-domain($domainname as xs:string,$domaintype as xs:str (: Configure domain :) return - xdmp:eval( - 'xquery version "1.0-ml";declare namespace m="http://marklogic.com/alerts";' || - 'import module namespace p="http://marklogic.com/cpf/pipelines" at "/MarkLogic/cpf/pipelines.xqy"; '|| - 'import module namespace dom = "http://marklogic.com/cpf/domains" at "/MarkLogic/cpf/domains.xqy"; ' || - 'declare variable $m:pname as xs:string external;declare variable $m:pnames as xs:string* external;' || - 'declare variable $m:mdb as xs:unsignedLong external;'|| - 'declare variable $m:type as xs:string external;' || - 'declare variable $m:path as xs:string external;' || - 'declare variable $m:otherpipeline as xs:string external;' || - 'declare variable $m:depth as xs:string external;' || - 'let $_ := xdmp:log("In eval") ' || - (:)'let $pids := for $pn in $m:pnames ' || - ' return xs:unsignedLong(p:pipelines()[p:pipeline-name = $pn]/p:pipeline-id) ' || :) - 'let $pids := ' || - '(xs:unsignedLong(p:pipelines()[p:pipeline-name = "Status Change Handling"]/p:pipeline-id),xs:unsignedLong(p:pipelines()[p:pipeline-name = $m:otherpipeline]/p:pipeline-id))' || - 'let $_ := xdmp:log("second point")' || - 'let $ds := dom:domain-scope($m:type,$m:path,$m:depth) ' || - 'let $_ := xdmp:log("third point")' || - 'let $ec := dom:evaluation-context($m:mdb,"/")' || - 'let $_ := xdmp:log("fourth point")' || - 'let $dc := dom:create($m:pname,"Domain for "||$m:pname,' || - ' $ds,$ec,$pids,())' || - 'let $_ := xdmp:log("fifth point")' || - 'return $dc' + xdmp:invoke-function( + function(){ + let $pids := (xs:unsignedLong(p:pipelines()[p:pipeline-name = "Status Change Handling"]/p:pipeline-id),xs:unsignedLong(p:pipelines()[p:pipeline-name = $pipeline-names[2]]/p:pipeline-id)) + let $_ := xdmp:log("second point") + let $ds := dom:domain-scope($domaintype, $domainpath, $domaindepth) + let $_ := xdmp:log("third point") + let $ec := dom:evaluation-context(xdmp:database($modulesdb),"/") + let $_ := xdmp:log("fourth point") + let $dc := dom:create($domainname,"Domain for "||$domainname, + $ds,$ec,$pids,()) + let $_ := xdmp:log("fifth point") + return $dc + } , - (xs:QName("my:otherpipeline"),($pipeline-names[2]),xs:QName("my:mdb"),xdmp:database($modulesdb),xs:QName("my:pname"),$domainname, - xs:QName("my:type"),$domaintype,xs:QName("my:path"),$domainpath,xs:QName("my:depth"),$domaindepth - ), {xdmp:triggers-database()} + update-auto-commit different-transaction - ) (: end eval :) - + ) }; diff --git a/src/app/models/workflow-import.xqy b/src/app/models/workflow-import.xqy index 4739300..250b565 100644 --- a/src/app/models/workflow-import.xqy +++ b/src/app/models/workflow-import.xqy @@ -25,12 +25,18 @@ declare function m:install-and-convert($doc as node(),$filename as xs:string,$ma (: 1. Save document in to DB :) let $uri := "/workflow/models/" || $filename let $_ := - xdmp:eval('xquery version "1.0-ml";import module namespace m="http://marklogic.com/workflow-import" at "/app/models/workflow-import.xqy";declare variable $m:uri as xs:string external;declare variable $m:doc as node() external;' - || 'xdmp:document-insert($m:uri,$m:doc,xdmp:default-permissions(),(xdmp:default-collections(),"http://marklogic.com/workflow/model"))' + xdmp:invoke-function( + function(){ + xdmp:document-insert($uri + , $doc + , xdmp:default-permissions() + , (xdmp:default-collections(),"http://marklogic.com/workflow/model") + ) + } , - (xs:QName("m:uri"),$uri,xs:QName("m:doc"),$doc), different-transaction + update-auto-commit ) (: 2. Convert to CPF :) @@ -70,8 +76,11 @@ declare function m:ensureWorkflowPipelinesInstalled() as empty-sequence() { let $name := "MarkLogic Workflow Initial Selection" return try { - let $pexists := xdmp:eval('xquery version "1.0-ml";declare namespace m="http://marklogic.com/workflow"; import module namespace p="http://marklogic.com/cpf/pipelines" at "/MarkLogic/cpf/pipelines.xqy";declare variable $m:name as xs:string external;p:get($m:name)', - (xs:QName("wf:name"),$name), + let $pexists := xdmp:invoke-function( + function(){ + p:get($name) + } + , {xdmp:triggers-database()} different-transaction @@ -83,24 +92,46 @@ declare function m:ensureWorkflowPipelinesInstalled() as empty-sequence() { let $failureAction := p:action("/MarkLogic/cpf/actions/failure-action.xqy",(),()) let $wfInitialPid := - xdmp:eval('xquery version "1.0-ml";declare namespace m="http://marklogic.com/workflow"; import module namespace p="http://marklogic.com/cpf/pipelines" at "/MarkLogic/cpf/pipelines.xqy";declare variable $m:name as xs:string external;' - || - 'p:create($m:name,$m:name,p:action("/MarkLogic/cpf/actions/success-action.xqy",(),()),p:action("/MarkLogic/cpf/actions/failure-action.xqy",(),()),() (: status transitions :) ,(' - || - 'p:state-transition(xs:anyURI("http://marklogic.com/states/initial"),"",(),xs:anyURI("http://marklogic.com/states/error"),(),p:action("/workflowengine/actions/workflowInitialSelection.xqy","BPMN2 Workflow initial process step selection",()),())' - || ') (: state transitions :)) ' - , - (xs:QName("wf:name"),$name), - - {xdmp:triggers-database()} - different-transaction - + xdmp:invoke-function( + function(){ + p:create( + $m:name + , $m:name + , p:action("/MarkLogic/cpf/actions/success-action.xqy",(),()) + , p:action("/MarkLogic/cpf/actions/failure-action.xqy",(),()) + , () (: status transitions :) + , ( + p:state-transition( + xs:anyURI("http://marklogic.com/states/initial") + , "" + , () + , xs:anyURI("http://marklogic.com/states/error") + , () + , p:action( + "/workflowengine/actions/workflowInitialSelection.xqy" + ,"BPMN2 Workflow initial process step selection" + ,() + ) + , () + ) + ) ) + } + , + + {xdmp:triggers-database()} + different-transaction + update-auto-commit + + ) let $_ := xdmp:log("Installing workflow initial pipeline " || $name) let $_ := xdmp:log($wfInitialPid) let $wfInitial := - xdmp:eval('xquery version "1.0-ml";declare namespace m="http://marklogic.com/workflow"; import module namespace p="http://marklogic.com/cpf/pipelines" at "/MarkLogic/cpf/pipelines.xqy";declare variable $m:name as xs:string external;p:get($m:name)', - (xs:QName("wf:name"),$name), + xdmp:invoke-function( + function(){ + p:get($name) + } + , {xdmp:triggers-database()} different-transaction @@ -109,12 +140,15 @@ declare function m:ensureWorkflowPipelinesInstalled() as empty-sequence() { let $_ := xdmp:log("Workflow initial pipeline XML:-") let $_ := xdmp:log($wfInitial) let $installedPipelinePid := - - xdmp:eval('xquery version "1.0-ml";declare namespace m="http://marklogic.com/workflow"; import module namespace p="http://marklogic.com/cpf/pipelines" at "/MarkLogic/cpf/pipelines.xqy";declare variable $m:xml as element(p:pipeline) external;p:insert($m:xml)', - (xs:QName("wf:xml"),$wfInitial), + xdmp:invoke-function( + function(){ + p:insert($wfInitial) + } + , {xdmp:triggers-database()} different-transaction + update-auto-commit ) return () @@ -129,8 +163,11 @@ declare function m:convert-to-cpf($processmodeluri as xs:string,$major as xs:str (: 1. Create Pipeline from raw process model :) (: Determine type from root element :) let $pmap := - xdmp:eval('xquery version "1.0-ml";import module namespace m="http://marklogic.com/workflow-import" at "/app/models/workflow-import.xqy";declare variable $m:processmodeluri as xs:string external;declare variable $m:major as xs:string external;declare variable $m:minor as xs:string external;m:create($m:processmodeluri,$m:major,$m:minor)', - (xs:QName("m:processmodeluri"),$processmodeluri,xs:QName("m:major"),$major,xs:QName("m:minor"),$minor), + xdmp:invoke-function( + function(){ + m:create($processmodeluri, $major, $minor) + } + , different-transaction @@ -156,8 +193,11 @@ declare function m:convert-to-cpf($processmodeluri as xs:string,$major as xs:str (: 2. Get this pipeline's URI :) (: let $puri := "http://marklogic.com/cpf/pipelines/"||xs:string($localPipelineId)||".xml" :) let $puri := - xdmp:eval('xquery version "1.0-ml";import module namespace p="http://marklogic.com/cpf/pipelines" at "/MarkLogic/cpf/pipelines.xqy";import module namespace m="http://marklogic.com/workflow-import" at "/app/models/workflow-import.xqy";declare variable $m:id as xs:string external;p:get($m:id)/fn:base-uri(.)', - (xs:QName("m:id"),$pname), + xdmp:invoke-function( + function(){ + p:get($pname)/fn:base-uri(.) + } + , different-transaction @@ -166,13 +206,15 @@ declare function m:convert-to-cpf($processmodeluri as xs:string,$major as xs:str (: 3. Install pipeline in modules DB (so that CPF runs it) and get the MODULES DB PID (not content db pid as above) :) let $pid := - xdmp:eval('xquery version "1.0-ml";import module namespace m="http://marklogic.com/workflow-import" at "/app/models/workflow-import.xqy";declare variable $m:puri as xs:string external;m:install($m:puri)', - (xs:QName("m:puri"),$puri), + xdmp:invoke-function( + function(){ + m:install($puri) + } + , different-transaction ) - let $_ := xdmp:log("In wfi:convert-to-cpf: installed pid: " || $pid || " for pname: " || $pname) @@ -251,32 +293,46 @@ declare function m:create($processmodeluri as xs:string,$major as xs:string,$min let $removeDoc := try { (:if (fn:not(fn:empty(p:get($name)))) then:) - xdmp:eval('xquery version "1.0-ml";declare namespace m="http://marklogic.com/workflow"; import module namespace p="http://marklogic.com/cpf/pipelines" at "/MarkLogic/cpf/pipelines.xqy";declare variable $m:puri as xs:string external;( (: p:remove($m:puri), :) for $pn in p:pipelines()/p:pipeline-name return if (fn:substring(xs:string($pn),1,fn:string-length($m:puri)) = $m:puri) then (xdmp:log("Deleting pipeline: "||xs:string($pn)), p:remove(xs:string($pn)) ) else () )', - (xs:QName("wf:puri"),$name), + xdmp:invoke-function( + function(){ + ( + (: p:remove($name), :) + for $pn in p:pipelines()/p:pipeline-name + return if (fn:substring(xs:string($pn),1,fn:string-length($name)) = $name) then + ( + xdmp:log("Deleting pipeline: "||xs:string($pn)) + , p:remove(xs:string($pn)) + ) + else () + ) + } + , {xdmp:database()} different-transaction + update-auto-commit ) (: else () :) - } catch ($e) { () } (: catching pipeline throwing error if it doesn't exist. We can safely ignore this :) + } catch ($e) { + xdmp:log('delete encountered error: ' || xdmp:quote($e)) + } (: catching pipeline throwing error if it doesn't exist. We can safely ignore this :) (: NOTE above also removes all child pipelines too - those starting with PROCESS__MAJOR__MINOR :) let $_ := xdmp:log("wfi:create : Now recreating pipeline(s)") let $pmap := - xdmp:eval('xquery version "1.0-ml";import module namespace m="http://marklogic.com/workflow-import" at "/app/models/workflow-import.xqy";' - || 'declare variable $m:pname as xs:string external;' - || 'declare variable $m:root as element() external;' - || 'm:do-create($m:pname,$m:root)' - , - (xs:QName("m:pname"),$name,xs:QName("m:root"),$root), - - {xdmp:database()} - different-transaction - - ) (: TODO handle failure gracefully :) - + xdmp:invoke-function( + function(){ + m:do-create($name,$root) + } + , + + {xdmp:database()} + different-transaction + update-auto-commit + + ) (: TODO handle failure gracefully :) return $pmap @@ -308,17 +364,16 @@ declare function m:do-create($pipelineName as xs:string,$root as element()) as m (: ASync CPF utility routines :) declare function m:get-pipeline-id($pname as xs:string) as xs:unsignedLong { - xdmp:eval( - 'xquery version "1.0-ml";declare namespace m="http://marklogic.com/workflow"; ' || - 'import module namespace p="http://marklogic.com/cpf/pipelines" at "/MarkLogic/cpf/pipelines.xqy"; ' || - 'declare variable $m:processmodeluri as xs:string external; xs:unsignedLong(p:get($m:processmodeluri)/p:pipeline-id)' - , - (xs:QName("wf:processmodeluri"),$pname), - - {xdmp:triggers-database()} - different-transaction - - ) + xdmp:invoke-function( + function(){ + xs:unsignedLong(p:get($pname)/p:pipeline-id) + } + , + + {xdmp:triggers-database()} + different-transaction + + ) }; declare function m:install($puri as xs:string) as xs:unsignedLong { @@ -331,26 +386,45 @@ declare function m:install($puri as xs:string) as xs:unsignedLong { if (fn:not(fn:empty(p:get($puri)))) then let $_ := xdmp:log("wfi:install: Removing pipeline config: " || $puri) return - xdmp:eval('xquery version "1.0-ml";declare namespace m="http://marklogic.com/workflow"; import module namespace p="http://marklogic.com/cpf/pipelines" at "/MarkLogic/cpf/pipelines.xqy";declare variable $m:puri as xs:string external;( (: p:remove($m:puri), :) for $pn in p:pipelines()/p:pipeline-name return if (fn:substring(xs:string($pn),1,fn:string-length($m:puri)) = $m:puri) then (xdmp:log("Deleting pipeline: "||xs:string($pn)), p:remove(xs:string($pn)) ) else () )', - (xs:QName("wf:puri"),$puri), - - {xdmp:triggers-database()} - different-transaction - - ) + xdmp:invoke-function( + function(){ + ( + (: p:remove($puri), :) + for $pn in p:pipelines()/p:pipeline-name + return if (fn:substring(xs:string($pn),1,fn:string-length($puri)) = $puri) then + ( + xdmp:log("Deleting pipeline: "||xs:string($pn)) + , p:remove(xs:string($pn)) + ) + else () + ) + } + , + + {xdmp:triggers-database()} + different-transaction + update-auto-commit + + ) else () - } catch ($e) { () } (: catching pipeline throwing error if it doesn't exist. We can safely ignore this :) + } catch ($e) { + xdmp:log('delete encountered error: ' || xdmp:quote($e)) + } (: catching pipeline throwing error if it doesn't exist. We can safely ignore this :) let $_ := xdmp:log("wfi:install: Adding pipeline config: " || $puri) (: Recreate pipeline :) return - xdmp:eval('xquery version "1.0-ml";declare namespace m="http://marklogic.com/workflow"; import module namespace p="http://marklogic.com/cpf/pipelines" at "/MarkLogic/cpf/pipelines.xqy";declare variable $m:pxml as element(p:pipeline) external;p:insert($m:pxml)', - (xs:QName("wf:pxml"),$pxml), + xdmp:invoke-function( + function(){ + p:insert($pxml) + } + , {xdmp:triggers-database()} different-transaction + update-auto-commit ) }; @@ -370,28 +444,29 @@ declare function m:domain((: $processmodeluri as xs:string,$major as xs:string,$ let $remove := try { if (fn:not(fn:empty( - xdmp:eval( - 'xquery version "1.0-ml";declare namespace m="http://marklogic.com/workflow"; import module namespace dom = "http://marklogic.com/cpf/domains" at "/MarkLogic/cpf/domains.xqy";declare variable $m:processmodeluri as xs:string external; dom:get($m:processmodeluri)' - , - (xs:QName("wf:processmodeluri"),$pname), + xdmp:invoke-function( + function(){ + dom:get($pname) + } + , {xdmp:triggers-database()} different-transaction ) - ))) then - - let $_ := xdmp:log(" GOT DOMAIN TO REMOVE") - return - xdmp:eval( - 'xquery version "1.0-ml";declare namespace m="http://marklogic.com/workflow"; import module namespace dom = "http://marklogic.com/cpf/domains" at "/MarkLogic/cpf/domains.xqy";declare variable $m:processmodeluri as xs:string external;' - || - 'dom:remove($m:processmodeluri)' + ))) then + + let $_ := xdmp:log(" GOT DOMAIN TO REMOVE") + return + xdmp:invoke-function( + function(){ + dom:remove($pname) + } , - (xs:QName("wf:processmodeluri"),$pname), {xdmp:triggers-database()} different-transaction + update-auto-commit ) else @@ -400,21 +475,35 @@ declare function m:domain((: $processmodeluri as xs:string,$major as xs:string,$ (: Configure domain :) return - xdmp:eval( - 'xquery version "1.0-ml";declare namespace m="http://marklogic.com/workflow"; import module namespace p="http://marklogic.com/cpf/pipelines" at "/MarkLogic/cpf/pipelines.xqy"; import module namespace dom = "http://marklogic.com/cpf/domains" at "/MarkLogic/cpf/domains.xqy";declare variable $m:pname as xs:string external;declare variable $m:pid as xs:unsignedLong external;declare variable $m:mdb as xs:unsignedLong external;' - || - '(xdmp:log("calling dom:create for " || $m:pname), ' - || - 'dom:create($m:pname,"Execute process given a process data document for "||$m:pname,' - || - 'dom:domain-scope("directory","/workflow/processes/"||$m:pname||"/","1"),dom:evaluation-context($m:mdb,"/"),((for $pipe in p:pipelines()[p:pipeline-name = ("Status Change Handling","MarkLogic Workflow Initial Selection")]/p:pipeline-id return xs:unsignedLong($pipe)),$m:pid),())' - || - ')' + xdmp:invoke-function( + function(){ + ( + xdmp:log("calling dom:create for " || $m:pname) + , dom:create( + $pname + , "Execute process given a process data document for "||$pname + , dom:domain-scope( + "directory" + , "/workflow/processes/"||$pname||"/" + ,"1" + ) + , dom:evaluation-context($mdb,"/") + ,( + ( + for $pipe in p:pipelines()[p:pipeline-name = ("Status Change Handling","MarkLogic Workflow Initial Selection")]/p:pipeline-id + return xs:unsignedLong($pipe) + ) + ,$pid + ) + ,() + ) + ) + } , - (xs:QName("wf:pid"),$pid,xs:QName("wf:mdb"),$mdb,xs:QName("wf:pname"),$pname), {xdmp:triggers-database()} different-transaction + update-auto-commit ) }; diff --git a/src/app/models/workflow-util.xqy b/src/app/models/workflow-util.xqy index c1dd5cc..9270300 100644 --- a/src/app/models/workflow-util.xqy +++ b/src/app/models/workflow-util.xqy @@ -95,66 +95,59 @@ declare function m:getProcessInstanceAsset($processUri as xs:string,$assetname a }; declare function m:setProcessAsset($assetname as xs:string,$asset as node(), $processName as xs:string,$major as xs:string?,$minor as xs:string?) as xs:string { - xdmp:eval( - 'xquery version "1.0-ml";declare namespace wf="http://marklogic.com/workflow";' || - 'declare variable $wf:processName as xs:string external;' || - 'declare variable $wf:major as xs:string external;' || - 'declare variable $wf:minor as xs:string external;' || - 'declare variable $wf:assetname as xs:string external;' || - 'declare variable $wf:asset as node() external;' || - 'let $uri := "/workflowengine/assets/" || fn:string-join(($wf:processName,$wf:major,$wf:minor),"/") || "/" || $wf:assetname ' || - 'return (xdmp:document-insert($uri,$wf:asset),$uri)' - , (: TODO security permissions and properties for easy finding :) - - (xs:QName("wf:processName"),$processName,xs:QName("wf:assetname"),$assetname,xs:QName("wf:major"),$major, - xs:QName("wf:minor"),$minor,xs:QName("wf:asset"),$asset), - - {xdmp:modules-database()} - different-transaction - - ) (: MUST be executed in the modules DB - where the assets live :) + xdmp:invoke-function( + function(){ + let $uri := "/workflowengine/assets/" || fn:string-join(($processName, $major, $minor), "/") || "/" || $assetname + return ( + xdmp:document-insert($uri, $asset) + , $uri + ) + } + , + + {xdmp:modules-database()} + different-transaction + update-auto-commit + + ) (: MUST be executed in the modules DB - where the assets live :) }; declare function m:deleteProcessAsset($assetname as xs:string,$processName as xs:string,$major as xs:string?,$minor as xs:string?) as xs:string { - xdmp:eval( - 'xquery version "1.0-ml";declare namespace wf="http://marklogic.com/workflow";' || - 'declare variable $wf:processName as xs:string external;' || - 'declare variable $wf:major as xs:string external;' || - 'declare variable $wf:minor as xs:string external;' || - 'declare variable $wf:assetname as xs:string external;' || - 'let $uri := "/workflowengine/assets/" || fn:string-join(($wf:processName,$wf:major,$wf:minor),"/") || "/" || $wf:assetname ' || - 'return (xdmp:document-delete($uri),$uri)' - , (: TODO security test :) - - (xs:QName("wf:processName"),$processName,xs:QName("wf:assetname"),$assetname,xs:QName("wf:major"),$major, - xs:QName("wf:minor"),$minor), - - {xdmp:modules-database()} - different-transaction - - ) (: MUST be executed in the modules DB - where the assets live :) + xdmp:invoke-function( + function(){ + let $uri := "/workflowengine/assets/" || fn:string-join(($processName, $major, $minor),"/") || "/" || $assetname + return ( + xdmp:document-delete($uri) + , $uri + ) + } + , + + {xdmp:modules-database()} + different-transaction + update-auto-commit + + ) (: MUST be executed in the modules DB - where the assets live :) }; declare function m:getProcessAssets($assetname as xs:string?,$processName as xs:string,$major as xs:string?,$minor as xs:string?) as node()* { - xdmp:eval( - 'xquery version "1.0-ml";declare namespace wf="http://marklogic.com/workflow";' || - 'declare variable $wf:processName as xs:string external;' || - 'declare variable $wf:major as xs:string external;' || - 'declare variable $wf:minor as xs:string external;' || - 'declare variable $wf:assetname as xs:string external;' || - ' (fn:doc("/workflowengine/assets/" || $wf:processName || "/" || $wf:major || "/" || $wf:minor || "/" || $wf:assetname ),' || - ' fn:doc("/workflowengine/assets/" || $wf:processName || "/" || $wf:major || "/" || "/" || $wf:assetname ),' || - ' fn:doc("/workflowengine/assets/" || $wf:processName || "/" || $wf:assetname )' || - ')[1]' - (: TODO support blank asset name by listing all processes within processName's URI folder :) + xdmp:invoke-function( + function(){ + ( + fn:doc("/workflowengine/assets/" || $processName || "/" || $major || "/" || $minor || "/" || $assetname ) + (: WARN: is this double slash intentional? :) + , fn:doc("/workflowengine/assets/" || $processName || "/" || $major || "/" || "/" || $assetname ) + , fn:doc("/workflowengine/assets/" || $processName || "/" || $assetname ) + )[1] + (: TODO support blank asset name by listing all processes within processName's URI folder :) + } , - (xs:QName("wf:processName"),$processName,xs:QName("wf:assetname"),$assetname,xs:QName("wf:major"),$major,xs:QName("wf:minor"),$minor), - - {xdmp:modules-database()} - different-transaction - - ) (: MUST be executed in the modules DB - where the assets live :) + + {xdmp:modules-database()} + different-transaction + + ) (: MUST be executed in the modules DB - where the assets live :) }; @@ -356,14 +349,16 @@ declare function m:inProgress($processId as xs:string,$transition as xs:string) }; declare function m:transitionByPath($path as xs:string) as element(p:state-transition)? { - xdmp:eval('xquery version "1.0-ml";declare namespace m="http://marklogic.com/workflow"; import module namespace p="http://marklogic.com/cpf/pipelines" at "/MarkLogic/cpf/pipelines.xqy";declare variable $m:path as xs:string external;xdmp:unpath($m:path)', - (xs:QName("wf:path"),$path), + xdmp:invoke-function( + function(){ + xdmp:unpath($path) + } + , {xdmp:triggers-database()} different-transaction ) - (: :) }; declare function m:failure($processUri as xs:string,$transition as node(),$failureReason as element(error:error)?,$detail as node()*) as empty-sequence() { @@ -581,6 +576,8 @@ declare function m:evaluateOLD($processUri as xs:string,$namespaces as element(w return ($namespace/@short/text(),$namespace/@long/text()) let $_ := xdmp:log("Namespaces:-") let $_ := xdmp:log($ns) + + let $_ := xdmp:log('[m:evaluateOLD] evaluating: ' || xdmp:quote($xp)) let $result := xdmp:with-namespaces($ns, xdmp:eval('declare namespace wf="http://marklogic.com/workflow"; ' || $xp,(),())) let $_ := xdmp:log("wfu:evaluate: result:-") @@ -602,7 +599,7 @@ declare function m:evaluate($processUri as xs:string,$namespaces as element(wf:n 'xquery version "1.0-ml";declare namespace wf="http://marklogic.com/workflow";' || $ns || 'declare variable $wf:process as element(wf:process) external;' || $xpath - let $_ := xdmp:log($xquery) + let $_ := xdmp:log('[m:evaluate] evaluating: ' || xdmp:quote($xquery)) return xdmp:eval($xquery, (xs:QName("wf:process"),fn:doc($processUri)/wf:process), @@ -615,7 +612,7 @@ declare function m:evaluate($processUri as xs:string,$namespaces as element(wf:n declare function m:evaluateXml($processUri as xs:string,$namespaces as element(wf:namespace)*,$xmlText as xs:string,$params as node()*) as node()* { let $xquery := 'xquery version "1.0-ml";declare namespace wf="http://marklogic.com/workflow";' || 'declare variable $wf:process as element(wf:process) external;' || $xmlText - let $_ := xdmp:log("wfu:evaluateXml: xquery: " || $xquery) + let $_ := xdmp:log('[m:evaluateXml] evaluating: ' || xdmp:quote($xquery)) let $result := xdmp:eval($xquery, (xs:QName("wf:process"),fn:doc($processUri)/wf:process), (: TODO accept external params without having blank params of () in the eval call :)