[MarkLogic Dev General] Need help with some java code to update values in a CPF file

Loren Cahlander loren.cahlander at easymetahub.com
Fri Feb 10 12:39:53 PST 2017


Hello,


I have the following CPF module in my system:


(:
 Copyright (c) 2017. EasyMetaHub, LLC - All Rights Reserved
 Unauthorized copying of this file, via any medium is strictly prohibited
 Proprietary and confidential
:)
xquery version "1.0-ml";

import module namespace cpf="http://marklogic.com/cpf" 
  at "/MarkLogic/cpf/cpf.xqy";

declare namespace mm="http://easymetahub.com/metamodel";

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)
        let $url := fn:concat("http://localhost:8080/easymetahub/HarvestJDBCData?url=", $cpf:document-uri)
        let $results := xdmp:http-get($url, <options xmlns="xdmp:http"></options>)
        return
            xdmp:node-replace($doc/harvest/state, <state>processed</state>),
            xdmp:log( "harvest JDBC data ran OK" ),
            cpf:success($cpf:document-uri, $cpf:transition, ())
    } catch ($e) {
        cpf:failure($cpf:document-uri, $cpf:transition, $e, ())
    }
else ()



The java code calls the following to get the $cpf:document-uri

ContentSource cs = null;
Session session = null;
RequestOptions options = null;

cs = ContentSourceFactory.newContentSource(new URI("xcc://admin:admin@localhost:9020"));
session = cs.newSession();
options = new RequestOptions();

options.setQueryLanguage("xquery");

Request request = null;
ResultSequence rs = null;
XdmNode item = null;


request = session.newAdhocQuery("doc (\"" + serviceURL + "\")/harvest", options);
request.setOptions(options);
rs = session.submitRequest(request);
item =  (XdmNode) rs.next().getItem();

Node harvestNode = (Node) item.asW3cNode();

I am then trying to update the counter for the processed and errors as well as listing the documents that were created in the system during the harvest.  The following code fails.

if (isSuccess) {
    Request successrequest = null;
    successrequest = session.newAdhocQuery("xdmp:node-replace(doc (\"" + serviceURL + "\")/harvest/processing/processed/count, <count>" + successes + "</count>", options);
    successrequest.setOptions(options);
    updaters = session.submitRequest(successrequest);
    successrequest = session.newAdhocQuery("xdmp:node-insert-after(doc (\"" + serviceURL + "\")/harvest/processing/processed/count, <document>" + entityPath + "</document>", options);
    successrequest.setOptions(options);
    updaters = session.submitRequest(successrequest);
}

if (isFailure) {
    Request failurerequest = null;
    failurerequest = session.newAdhocQuery("xdmp:node-replace(doc (\"" + serviceURL + "\")/harvest/processing/errors/count, <count>" + failures + "</count>", options);
    failurerequest.setOptions(options);
    updaters = session.submitRequest(failurerequest);
    failurerequest = session.newAdhocQuery("xdmp:node-insert-after(doc (\"" + serviceURL + "\")/harvest/processing/errors/count, <document>" + entityPath + "</document>", options);
    failurerequest.setOptions(options);
    updaters = session.submitRequest(failurerequest);
}


Does anyone have any suggestions?

Thank you,

Loren Cahlander

CTO | Easy Meta Hub LLC.

4819 Emperor Blvd, Suite 400, Durham, NC 27703 
651-747-6910 | loren.cahlander at easymetahub.com <mailto:loren.cahlander at easymetahub.com> | https://www.linkedin.com/in/lorencahlander <https://www.linkedin.com/in/lorencahlander> | @lcahlander 
www.easymetahub.com <http://www.easymetahub.com/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://developer.marklogic.com/pipermail/general/attachments/20170210/066c2560/attachment.html 


More information about the General mailing list