如何从数据库中获取文档并使用dmsdk将其传递给转换?

问题描述 投票:1回答:1

我需要从数据库中获取文档并使用dmsdk应用转换。我使用以下代码行成功从数据库中获取文档:

        QueryManager queryManager=client.newQueryManager();
        StructuredQueryBuilder sqb = queryManager.newStructuredQueryBuilder();
        StructuredQueryDefinition query =sqb.collection("test");

它返回文档的URI。但我的转换接受json对象作为输入。我需要传递json对象而不是uri。

我的转型:

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 document-node()
) as document-node()
{
    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))
    let $_ := map:put($content, "uri",$uri)
    let $_ := map:put($content, "value",$orig-value)
    return $content  

};

我的dmsdk代码:

    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 loadData(String txName)
    {
        QueryManager queryManager=client.newQueryManager();
        StructuredQueryBuilder sqb = queryManager.newStructuredQueryBuilder();
        StructuredQueryDefinition query =sqb.collection("test");
        DataMovementManager dmm = client.newDataMovementManager();
        QueryBatcher batcher = dmm.newQueryBatcher(query);

        batcher.withConsistentSnapshot();
        ServerTransform txform = new ServerTransform(txName);

        ApplyTransformListener transformListener = new ApplyTransformListener()
                .withTransform(txform)
                .withApplyResult(ApplyResult.REPLACE);

        batcher.onUrisReady(transformListener)          
                .onQueryFailure( exception -> exception.printStackTrace() );

        dmm.startJob(batcher);
    }

    public static void main(String[] args) 
    {
        loadData("deepan");
    }

例外:

01:09:10.819 [main] WARN com.marklogic.client.datamovement.ApplyTransformListener - Error: com.marklogic.client.FailedRequestException: Local message: failed to apply resource at internal/apply-transform: Bad Request. Server Message: XDMP-ARGTYPE: (err:XPTY0004) fn:doc(fn:doc("/one.json")) -- arg1 is not of type xs:string* in batch with urs ([/one.json, /three.json])
01:09:10.821 [pool-1-thread-2] DEBUG com.marklogic.client.impl.OkHttpServices - Query uris with structured query <query xmlns="http://marklogic.com/appservices/search" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:search="http://marklogic.com/appservices/search" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><collection-query><uri>test</uri></collection-query></query>
01:09:10.821 [pool-1-thread-2] DEBUG com.marklogic.client.impl.OkHttpServices - Getting internal/uris as text/uri-list
01:09:10.823 [pool-1-thread-1] DEBUG com.marklogic.client.impl.OkHttpServices - Query uris with structured query <query xmlns="http://marklogic.com/appservices/search" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:search="http://marklogic.com/appservices/search" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><collection-query><uri>test</uri></collection-query></query>
01:09:10.824 [pool-1-thread-1] DEBUG com.marklogic.client.impl.OkHttpServices - Getting internal/uris as text/uri-list
01:09:10.830 [pool-1-thread-2] DEBUG com.marklogic.client.impl.OkHttpServices - Posting internal/apply-transform
01:09:10.852 [pool-1-thread-2] WARN com.marklogic.client.datamovement.ApplyTransformListener - Error: com.marklogic.client.FailedRequestException: Local message: failed to apply resource at internal/apply-transform: Bad Request. Server Message: XDMP-ARGTYPE: (err:XPTY0004) fn:doc(fn:doc("/two.json")) -- arg1 is not of type xs:string* in batch with urs ([/two.json])
marklogic transformation marklogic-8 marklogic-9
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.