我尝试按照Marklogic上的教程创建我们自己的CPF。我几乎复制并粘贴了xdmp:log之外的所有代码和大部分功能。一旦完成任务,中央公积金就会结束任务。marklogic的文档可以在这里找到Getting Started with a Simple CPF Application
如果我做错了什么,我会在这里发布我的代码和我所做的事情。
=Documents Used=
add-last-updated.xqy添加到模块DB中的=>
xquery version "1.0-ml";
import module namespace cpf="http://marklogic.com/cpf"
at "/MarkLogic/cpf/cpf.xqy";
declare variable $cpf:document-uri as xs:string external;
declare variable $cpf:transition as node() external;
if (cpf:check-transition($cpf:document-uri,$cpf:transition)) then try {
let $doc := fn:doc($cpf:document-uri)
return
xdmp:node-insert-child(
$doc/book,
<last-updated>{fn:current-dateTime()}</last-updated>
),
xdmp:log( "add last-updated ran OK" ),
cpf:success($cpf:document-uri, $cpf:transition, ())
} catch ($e) {
cpf:failure($cpf:document-uri, $cpf:transition, $e, ())
}
else ()add-copyright.xqy添加到模块DB中的=>
xquery version "1.0-ml";
import module namespace cpf = "http://marklogic.com/cpf"
at "/MarkLogic/cpf/cpf.xqy";
declare variable $cpf:document-uri as xs:string external;
declare variable $cpf:transition as node() external;
if (cpf:check-transition($cpf:document-uri,$cpf:transition)) then try {
let $doc := fn:doc( $cpf:document-uri )
return
xdmp:node-insert-child(
$doc/book,
<copyright>
<year>2010</year>
<holder>The Publisher</holder>
</copyright>),
xdmp:log( "add copyright ran OK" ),
cpf:success( $cpf:document-uri, $cpf:transition, () )
}
catch ($e) {
cpf:failure( $cpf:document-uri, $cpf:transition, $e, () )
}
else ()copyright.xml =>已添加到管道中并附加到“默认文档”域
<pipeline xmlns="http://marklogic.com/cpf/pipelines">
<pipeline-name>Copyright Pipeline</pipeline-name>
<pipeline-description>Pipeline to test CPF</pipeline-description>
<success-action>
<module>/MarkLogic/cpf/actions/success-action.xqy</module>
</success-action>
<failure-action>
<module>/MarkLogic/cpf/actions/failure-action.xqy</module>
</failure-action>
<state-transition>
<annotation>
When a document containing ‘book' as a root element is created,
add a ‘copyright' statement.
</annotation>
<state>http://marklogic.com/states/initial</state>
<on-success>http://marklogic.com/states/done</on-success>
<on-failure>http://marklogic.com/states/error</on-failure>
<execute>
<condition>
<module>/MarkLogic/cpf/actions/namespace-condition.xqy</module>
<options xmlns="/MarkLogic/cpf/actions/namespace-condition.xqy">
<root-element>book</root-element>
<namespace/>
</options>
</condition>
<action>
<module>add-copyright.xqy</module>
</action>
</execute>
</state-transition>
<state-transition>
<annotation>
When a document containing ‘book' as a root element is updated,
add a ‘last-updated' element
</annotation>
<state>http://marklogic.com/states/updated</state>
<on-success>http://marklogic.com/states/done</on-success>
<on-failure>http://marklogic.com/states/error</on-failure>
<execute>
<condition>
<module>/MarkLogic/cpf/actions/namespace-condition.xqy</module>
<options xmlns="/MarkLogic/cpf/actions/namespace-condition.xqy">
<root-element>book</root-element>
<namespace/>
</options>
</condition>
<action>
<module>add-last-updated.xqy</module>
</action>
</execute>
</state-transition>
</pipeline>=Tested Using=
xquery version "1.0-ml";
let $contents :=
<book>
<bookTitle>All About George</bookTitle>
<chapter1>
<chapterTitle>Curious George</chapterTitle>
<para>
George Washington crossed the Delaware to see what was on the other side.
</para>
</chapter1>
</book>
return
xdmp:document-insert("/content.xml", $contents)一般来说,代码可以正常工作,文档在第一次插入时会被编辑输出,如下所示,但是MarkLogic/Data/ logs /8000_ErrorLog中的日志没有更新。此外,当我尝试将xdmp:log放在xdmp: node -insert-child之上时,CPF过早地停止,并且节点不会被编辑。我非常感谢任何建议,以帮助解决这个问题。
<book>
<bookTitle>All About George</bookTitle>
<chapter1>
<chapterTitle>Curious George</chapterTitle>
<para>
George Washington crossed the Delaware to see what was on the other side.
</para>
</chapter1>
<copyright>
<year>2010</year>
<holder>The Publisher</holder>
</copyright>
</book>=Update=
我遵循mholstege建议,删除了我的"return“和"let”语句,并按照grtjn的建议删除了日志。从那里我意识到日志被推入到"TaskServer_Error“日志中。对于我来说,这是一个愚蠢的问题,谢谢你的帮助。
发布于 2019-02-23 00:56:57
您格式化代码的方式告诉我,您认为xdmp:log和cpf:success行属于return,但事实并非如此:只有return之后的第一个表达式才是。因此,当您重新排序这些行时,您可能会在此模块上得到一个未定义的变量静态错误。您实际上并不需要let和return:您只需将use doc($document-uri)/book直接放在xdmp:node-replace调用中即可。然后,您可以随意重新排序序列。如果希望xdmp:node-replace和xdmp:log位于$doc变量的作用域中,请用括号将该表达式序列括起来。
https://stackoverflow.com/questions/54823627
复制相似问题