Skip to content

Commit a2cfe97

Browse files
committed
Merge pull request #107 from maeisabelle/79-RunFlowFromTransform
79 - Run-flow transform
2 parents 3bc2e9c + 39652d7 commit a2cfe97

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,50 @@ To generate eclipse project files run:
3939
`./gradlew eclipse`
4040

4141
Then import the project into eclipse
42+
43+
####Available Transforms
44+
Data Hub has provided several transforms that can be used when installed along with the created entities and flows in the MarkLogic server.
45+
####run-flow
46+
This transform can be used to run the flow when inserting document. It accepts the following `entity-name` and `flow-name`.
47+
48+
#####Use Cases:
49+
50+
1. Using [MarkLogic REST API PUT /v1/documents](http://docs.marklogic.com/REST/PUT/v1/documents)
51+
52+
`curl --anyauth --user <user>:<password> -X PUT -T <documentDirectory> -H "Content-type:<contentType>" 'http://<mlHost>:<port>/<version>/documents?uri=<uri>&transform=run-flow&trans:entity-name=<entityName>&trans:flow-name=<flowName>'`
53+
54+
Example:
55+
56+
`cat ./documents/employee1.xml`
57+
58+
`<employee xmlns="http://company.com/ns/employee">`
59+
`<id>1</id>`
60+
`</employee>`
61+
62+
To insert/update this document with uri '/employee1.xml' into the database 'data-hub-in-a-box-STAGING' (with host 'localhost' and port '8010'), given a user 'admin' with password 'admin' and rest-writer role AND to be able to run the flow 'IngestFlow' of the 'Customer' entity, run the following:
63+
64+
`curl --anyauth --user admin:admin -X PUT -T ./documents/employee1.xml -H "Content-type:application/xml" 'http://localhost:8010/LATEST/documents?uri=/employee1.xml&transform=run-flow&trans:entity-name=Customer&trans:flow-name=IngestFlow'`
65+
66+
This will create a document with uri '/employee1.xml'. The content will depend on the data format of the entity.
67+
68+
If it is JSON ('application/json'), the content will be:
69+
70+
`{`
71+
`"identifier": "/employee1.xml", `
72+
`"content": "<employee xmlns=\"http://company.com/ns/employee\">\n <id>1</id>\n</employee>"`
73+
`}`
74+
75+
Else if it is XML ('application/xml'), it will be:
76+
77+
`<?xml version="1.0" encoding="UTF-8"?>`
78+
`<envelope xmlns="http://marklogic.com/hub-in-a-box/envelope">`
79+
`<headers>`
80+
`</headers>`
81+
`<triples>`
82+
`</triples>`
83+
`<content>`
84+
`<employee xmlns="http://company.com/ns/employee">`
85+
`<id>1</id>`
86+
`</employee>`
87+
`</content>`
88+
`</envelope>`
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
xquery version "1.0-ml";
2+
3+
module namespace runFlow = "http://marklogic.com/rest-api/transform/run-flow";
4+
5+
import module namespace flow = "http://marklogic.com/hub-in-a-box/flow-lib"
6+
at "/com.marklogic.hub/lib/flow-lib.xqy";
7+
8+
declare function runFlow:transform(
9+
$context as map:map,
10+
$params as map:map,
11+
$content as document-node()
12+
) as document-node()
13+
{
14+
let $entityName := map:get($params, 'entity-name')
15+
let $flowName := map:get($params, 'flow-name')
16+
17+
let $flow := flow:get-flow($entityName,$flowName,())
18+
19+
let $uri := map:get($context, 'uri')
20+
21+
let $transformedContent := flow:run-plugins($flow, $uri, $content, $params)
22+
23+
return document { $transformedContent }
24+
25+
};

0 commit comments

Comments
 (0)