Skip to content

Commit 821a053

Browse files
committed
fixed #513
also cleaned up some code. made all the ways to run flows use the same param names.
1 parent 6b6d2ff commit 821a053

File tree

68 files changed

+526
-406
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+526
-406
lines changed

examples/healthcare/plugins/entities/Patients/harmonize/final/main.xqy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ declare function plugin:main(
4949

5050
let $envelope := dhf:make-envelope($content, $headers, $triples, map:get($options, "dataFormat"))
5151
return
52-
(: explain: needed to call this way for static analysis :)
52+
(: writers must be invoked this way.
53+
see: https://github.com/marklogic-community/marklogic-data-hub/wiki/dhf-lib#run-writer :)
5354
dhf:run-writer(xdmp:function(xs:QName("writer:write")), $id, $envelope, $options)
5455
};

examples/healthcare/plugins/entities/Patients/input/hl7/main.xqy

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ declare function plugin:main(
4646
})
4747

4848
let $envelope := dhf:make-envelope($content, $headers, $triples, map:get($options, "dataFormat"))
49+
(:
50+
: log the final envelope as a trace
51+
: only fires if tracing is enabled
52+
:)
53+
let $_ := dhf:log-trace(dhf:writer-context($envelope))
4954
return
5055
$envelope
5156
};

examples/healthcare/plugins/entities/Patients/input/nppes/main.xqy

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ declare function plugin:main(
4646
})
4747

4848
let $envelope := dhf:make-envelope($content, $headers, $triples, map:get($options, "dataFormat"))
49+
(:
50+
: log the final envelope as a trace
51+
: only fires if tracing is enabled
52+
:)
53+
let $_ := dhf:log-trace(dhf:writer-context($envelope))
4954
return
5055
$envelope
5156
};
Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
/*
2-
* Create Content Plugin
3-
*
4-
* @param id - the identifier returned by the collector
5-
* @param options - an object containing options. Options are sent from Java
6-
*
7-
* @return - your content
8-
*/
9-
function createContent(id, options) {
10-
var doc = cts.doc(id);
11-
var root = doc.root;
12-
13-
// for xml we need to use xpath
14-
if (root && xdmp.nodeKind(root) === 'element') {
15-
return root.xpath('/*:envelope/*:instance/node()');
16-
}
17-
// for json we need to return the instance
18-
else if (root && root.envelope && root.envelope.instance) {
19-
return root.envelope.instance;
20-
}
21-
// for everything else
22-
else {
23-
return doc;
24-
}
25-
}
26-
27-
module.exports = {
28-
createContent: createContent
29-
};
1+
/*
2+
* Create Content Plugin
3+
*
4+
* @param id - the identifier returned by the collector
5+
* @param options - an object containing options. Options are sent from Java
6+
*
7+
* @return - your content
8+
*/
9+
function createContent(id, options) {
10+
var doc = cts.doc(id);
11+
var root = doc.root;
12+
13+
// for xml we need to use xpath
14+
if (root && xdmp.nodeKind(root) === 'element') {
15+
return root.xpath('/*:envelope/*:instance/node()');
16+
}
17+
// for json we need to return the instance
18+
else if (root && root.envelope && root.envelope.instance) {
19+
return root.envelope.instance;
20+
}
21+
// for everything else
22+
else {
23+
return doc;
24+
}
25+
}
26+
27+
module.exports = {
28+
createContent: createContent
29+
};

examples/hr-hub/plugins/entities/Employee/harmonize/harmonize-acme-tech/main.sjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ function main(id, options) {
3232

3333
var envelope = dhf.makeEnvelope(content, headers, triples, options.dataFormat);
3434

35-
// explain. needed to call this way for static analysis
35+
// writers must be invoked this way.
36+
// see: https://github.com/marklogic-community/marklogic-data-hub/wiki/dhf-lib#run-writer
3637
dhf.runWriter(xdmp.function(null, './writer/writer.sjs'), id, envelope, options);
3738
}
3839

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
/*
2-
* Collect IDs plugin
3-
*
4-
* @param options - a map containing options. Options are sent from Java
5-
*
6-
* @return - an array of ids or uris
7-
*/
8-
function collect(options) {
9-
10-
// grab a list of the unique employee IDs out of the JSON data
11-
// This is a really bad way to do this. Use a range index instead
12-
var y = [];
13-
for (var x of fn.collection('load-global-corp')) {
14-
var empid = x.root.envelope.instance.emp_id;
15-
if (empid) {
16-
y.push(empid);
17-
}
18-
}
19-
return fn.distinctValues(xdmp.arrayValues(y));
20-
}
21-
22-
module.exports = {
23-
collect: collect
24-
};
1+
/*
2+
* Collect IDs plugin
3+
*
4+
* @param options - a map containing options. Options are sent from Java
5+
*
6+
* @return - an array of ids or uris
7+
*/
8+
function collect(options) {
9+
10+
// grab a list of the unique employee IDs out of the JSON data
11+
// This is a really bad way to do this. Use a range index instead
12+
var y = [];
13+
for (var x of fn.collection('load-global-corp')) {
14+
var empid = x.root.envelope.instance.emp_id;
15+
if (empid) {
16+
y.push(empid);
17+
}
18+
}
19+
return fn.distinctValues(xdmp.arrayValues(y));
20+
}
21+
22+
module.exports = {
23+
collect: collect
24+
};
Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
/*
2-
* Create Content Plugin
3-
*
4-
* @param id - the identifier returned by the collector
5-
* @param options - an object containing options. Options are sent from Java
6-
*
7-
* @return - your content
8-
*/
9-
function createContent(id, options) {
10-
// start with an empty object
11-
content = {};
12-
13-
// find the documents matching the given employee id
14-
for (var doc of cts.search(cts.jsonPropertyValueQuery('emp_id', id))) {
15-
16-
// merge the keys and values from the found document into content
17-
for (var key in doc.root.envelope.instance) {
18-
if (doc.root.envelope.instance.hasOwnProperty(key)) {
19-
content[key] = doc.root.envelope.instance[key];
20-
}
21-
}
22-
}
23-
24-
// return the merged content
25-
return content;
26-
}
27-
28-
module.exports = {
29-
createContent: createContent
30-
};
1+
/*
2+
* Create Content Plugin
3+
*
4+
* @param id - the identifier returned by the collector
5+
* @param options - an object containing options. Options are sent from Java
6+
*
7+
* @return - your content
8+
*/
9+
function createContent(id, options) {
10+
// start with an empty object
11+
content = {};
12+
13+
// find the documents matching the given employee id
14+
for (var doc of cts.search(cts.jsonPropertyValueQuery('emp_id', id))) {
15+
16+
// merge the keys and values from the found document into content
17+
for (var key in doc.root.envelope.instance) {
18+
if (doc.root.envelope.instance.hasOwnProperty(key)) {
19+
content[key] = doc.root.envelope.instance[key];
20+
}
21+
}
22+
}
23+
24+
// return the merged content
25+
return content;
26+
}
27+
28+
module.exports = {
29+
createContent: createContent
30+
};

examples/hr-hub/plugins/entities/Employee/harmonize/harmonize-global-corp/main.sjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ function main(id, options) {
3232

3333
var envelope = dhf.makeEnvelope(content, headers, triples, options.dataFormat);
3434

35-
// explain. needed to call this way for static analysis
35+
// writers must be invoked this way.
36+
// see: https://github.com/marklogic-community/marklogic-data-hub/wiki/dhf-lib#run-writer
3637
dhf.runWriter(xdmp.function(null, './writer/writer.sjs'), id, envelope, options);
3738
}
3839

examples/hr-hub/plugins/entities/Employee/input/load-acme-tech/main.sjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ function main(id, rawContent, options) {
3131
return triplesPlugin.createTriples(id, content, headers, options);
3232
});
3333

34-
return dhf.makeEnvelope(content, headers, triples, options.dataFormat);
34+
var envelope = dhf.makeEnvelope(content, headers, triples, options.dataFormat);
35+
36+
// log the final envelope as a trace
37+
// only fires if tracing is enabled
38+
dhf.logTrace(dhf.writerContext(envelope));
39+
40+
return envelope;
3541
}
3642

3743
module.exports = {

examples/hr-hub/plugins/entities/Employee/input/load-global-corp/main.sjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ function main(id, rawContent, options) {
3131
return triplesPlugin.createTriples(id, content, headers, options);
3232
});
3333

34-
return dhf.makeEnvelope(content, headers, triples, options.dataFormat);
34+
var envelope = dhf.makeEnvelope(content, headers, triples, options.dataFormat);
35+
36+
// log the final envelope as a trace
37+
// only fires if tracing is enabled
38+
dhf.logTrace(dhf.writerContext(envelope));
39+
40+
return envelope;
3541
}
3642

3743
module.exports = {

0 commit comments

Comments
 (0)