Search code examples
marklogicmarklogic-9marklogic-dhf

MarkLogic CPF- condition module in pipeline


MarkLogic version : 9.0-6.2

All documents in our DB are JSONs and we use Javascript to manipulate data. I am trying to create a pipeline that identifies whenever a Phone Number in the JSON document is updated (using a condition module) and then runs an action module. So far, I got the below code.

{
  "pipeline-name": "CPF async Test",
  "pipeline-description": "CPF Test",
  "success-action": {
      "module": "/MarkLogic/cpf/actions/success-action.xqy"
  },
  "failure-action": {
      "module": "/marklogic/cpf/actions/failure-action.xqy"
  },
  "status-transition": [
    {
      "annotation": "",
      "status": "updated",
      "on-success": "http://marklogic.com/states/done",
      "on-failure": "http://marklogic.com/states/error",
      "execute": [
         {
           "condition": {
           "module": ???
           },
           "action": {
           "module": "sleepTest.sjs"
          }
        }
     ]
   }
 ]
}
  1. When I tried to load this JSON as pipeline using admin console (with filter as filename.json), I am getting a message "Invalid input: No readable XML files found:"

    Should a pipeline be always XML?

  2. I am able to write (in JavaScript) and execute the action module successfully. I tested it within an XML pipeline. Can I write a condition module in JavaScript too?

  3. I am not sure if there is a built-in condition module provided by MarkLogic that identifies the changes to a property (by passing the property as parameter to the condition module). If yes, could you please point to the documentation? If I have to create a custom condition module, how can I pass old and new phone numbers to the module? How would the condition module look like, preferably in JavaScript?

Most of the documentation I found on CPF is XML/XQuery. Any pointers to JSON/JavaScript CPF documentation is appreciated.

Thanks in advance!


Solution

  • The example that @rjrudin pointed out only have CPF condition module in XQuery. Below is a comparison of the XQuery and the Server-side JavaScript versions (logging omitted):

    sample-condition.xqy link to the original on GitHub

    xquery version "1.0-ml";
    declare namespace cpf = "http://marklogic.com/cpf";
    declare variable $cpf:document-uri as xs:string external;
    (: your custom condition logic :)
    return true()  (: or false() :)
    

    sample-condition.sjs

    'use strict'
    const cpf = require('/MarkLogic/cpf/cpf')
    // your custom condition logic
    fn.true()  // or fn.false()
    

    Documentation: https://docs.marklogic.com/js/cpf