我试图使用Marklogic Java API将xquery转换加载到Modules DB中。最初,我以前使用正常工作的同一段代码来加载Javascript转换(.sjs)。 现在,当我尝试使用相同的代码加载xquery转换时,它不起作用。
我的Xquery转换:
xquery version "1.0-ml";
module namespace test =
"http://marklogic.com/rest-api/transform/deepan";
declare function test:transform(
$context as map:map,
$params as map:map,
$content as map:map
) as map:map*
{
let $jsoncont := xdmp:from-json-string($content)
let $inputval := "fname,lname"
let $orig-value := map:get($jsoncont, "value")
let $jscode := "var simple = require('/wdsUtils.sjs');
var content, input;
simple.createUri(content,input);"
let $uri := xdmp:javascript-eval($jscode,('content',$orig-value,'input',$inputval))
map:put($content, "uri",$uri)
map:put($content, "value",$orig-value)
return $content
};
我要加载转换的Java代码:
private static final String TRANSFORM_NAME = "sec";
static String HOST = "localhost";
static int PORT = 8136;
static String USER = "admin";
static String PASSWORD = "admin";
private static DatabaseClient client =
DatabaseClientFactory.newClient(
HOST, PORT, new DigestAuthContext(USER, PASSWORD));
public static void loadLookup() throws FileNotFoundException
{
TransformExtensionsManager extensionsManager=client.newServerConfigManager().newTransformExtensionsManager();
FileInputStream fileInputStream=new FileInputStream("C:/Users/deepan/Desktop/sec.xqy");
//System.out.println(fileInputStream.toString());
InputStreamHandle handle=new InputStreamHandle(fileInputStream);
//extensionsManager.writeJavascriptTransform(TRANSFORM_NAME, handle);
extensionsManager.writeXQueryTransform(TRANSFORM_NAME, handle);
client.release();
}
例外:
Exception in thread "main" com.marklogic.client.FailedRequestException: Local message: config/transforms write failed: Bad Request. Server Message: RESTAPI-INVALIDCONTENT: (err:FOER0000) Invalid content: invalid sec extension: could not parse XQuery extension sec; please see the server error log for detail XDMP-UNEXPECTED: (err:XPST0003) Unexpected token syntax error, unexpected Dollar_; sec either is not a valid module or does not provide extension functions (transform) in the http://marklogic.com/rest-api/transform/sec namespace
at com.marklogic.client.impl.OkHttpServices.putPostValueImpl(OkHttpServices.java:2890)
at com.marklogic.client.impl.OkHttpServices.putValue(OkHttpServices.java:2757)
at com.marklogic.client.impl.TransformExtensionsImpl.writeTransform(TransformExtensionsImpl.java:356)
at com.marklogic.client.impl.TransformExtensionsImpl.writeXQueryTransform(TransformExtensionsImpl.java:255)
at com.marklogic.client.impl.TransformExtensionsImpl.writeXQueryTransform(TransformExtensionsImpl.java:249)
at com.example.batch.Transform.loadLookup(Transform.java:33)
at com.example.batch.Transform.main(Transform.java:40)
答案 0 :(得分:1)
似乎您的代码中有语法错误。更改为此,它应该可以工作:
...
let $uri := xdmp:javascript-eval($jscode, ('content', $orig-value, 'input', $inputval))
let $_ := map:put($content, "uri", $uri)
let $_ := map:put($content, "value", $orig-value)
return $content
...
我在map:put表达式前面添加了let $_ :=
。
您的名称空间名称(秒)和转换名称(deepan)也不匹配:
module namespace test =
"http://marklogic.com/rest-api/transform/sec";
declare function test:transform
...
转换函数的另外一个接口必须与此匹配:
declare function yourNS:transform(
$context as map:map,
$params as map:map,
$content as document-node())
as document-node()
将您的更改为以下内容:
declare function test:transform(
$context as map:map,
$params as map:map,
$content as document-node()
) as document-node()
更多信息here。