alert - 使用 CPF (MarkLogic) 时出现 xdmp:log 错误
问题描述
我试图按照关于 Marklogic 的教程来创建我们自己的 CPF。我几乎复制并粘贴了所有代码,并且大多数功能都在 xdmp:log 之外工作。CPF 将在完成任务时结束它的任务。可以在此处找到来自 marklogic 的文档简单 CPF 应用程序入门
万一我做错了什么,我会在这里发布我的代码以及我做了什么。
=======使用的文件=======
add-last-updated.xqy => 添加到 Modules 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 => 添加到 Modules 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>
======测试使用======
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>
========更新========
我遵循 mholstege 的建议,删除了我的“return”和“let”语句,并按照 grtjn 的建议删除了日志。从那里我意识到日志被推送到“TaskServer_Error”日志中。对我来说是一个愚蠢的问题,感谢您的帮助。
解决方案
您格式化代码的方式向我表明您认为xdmp:log
andcpf:success
行属于return
,但事实并非如此:只有return
is 之后的第一个表达式。因此,当您重新排序行时,您可能会在此模块上遇到未定义的变量静态错误。你真的不需要let
and return
:你可以doc($document-uri)/book
直接在xdmp:node-replace
调用中使用。然后您可以随意重新排序序列。如果您希望 thexdmp:node-replace
和 the位于变量xdmp:log
的范围内,请$doc
在该表达式序列周围加上括号。
推荐阅读
- excel - VBS - 如何获取文件名的今天日期?
- perl - 如何存储和检索 perl 对象
- linux - 记录 Bash 交互,分别保存 STDIN、STDOUT
- html - 仅在图标而不是名称上切换类别导航
- android - 单击 ActionBar 菜单项时带有 Android ActionBar 的弹出对话框
- javascript - 使用 Node.js 将 createWriteStream txt 内容写入全局变量
- r - 将 ifelse() 添加到 Map 函数中
- crystal-lang - 重新启动“琥珀表”时记录全部删除
- python - Raspberry Pi 距离传感器的追溯
- uwp - 使用 WritableBitmap 时抛出 ObjectDisposedException