Skip to content

Commit 70ca237

Browse files
committed
updating hr-hub example
1 parent fe1e17b commit 70ca237

File tree

7 files changed

+100
-85
lines changed

7 files changed

+100
-85
lines changed

examples/hr-hub/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The data are separated into 2 folders under the input/ folder.
1414
```
1515

1616
# TLDR; How do I run it?
17-
Check out the [HR Hub Tutorial](https://marklogic-community.github.io/marklogic-data-hub/) on the Datahub Site.
17+
Check out the [HR Hub Tutorial](https://marklogic-community.github.io/marklogic-data-hub/getting-started-1x) on the Datahub Site.
1818

1919
# Global Corp
2020
Global Corp has exported the Employee data from a relational database. They are provided to you as csv files, one for each table.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"info" : {
3+
"title" : "Employee",
4+
"version" : "0.0.1"
5+
},
6+
"definitions" : {
7+
"Employee" : {
8+
"required" : [ ],
9+
"rangeIndex" : [ ],
10+
"wordLexicon" : [ ],
11+
"properties" : { }
12+
}
13+
}
14+
}
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/*:content/node()');
16-
}
17-
// for json we need to return the content
18-
else if (root && root.content) {
19-
return root.content;
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/writer/writer.sjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @return - nothing
99
*/
1010
function write(id, envelope, options) {
11-
xdmp.documentInsert(id, envelope, [], ['json-employee']);
11+
xdmp.documentInsert(id, envelope, xdmp.defaultPermissions(), options.flow);
1212
}
1313

1414
module.exports = write;
Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +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-
var y = [];
12-
for (var x of fn.collection('load-global-corp')) {
13-
var empid = x.root.content.emp_id;
14-
if (empid) {
15-
y.push(empid);
16-
}
17-
}
18-
return fn.distinctValues(xdmp.arrayValues(y));
19-
}
20-
21-
module.exports = {
22-
collect: collect
23-
};
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.content) {
18-
if (doc.root.content.hasOwnProperty(key)) {
19-
content[key] = doc.root.content[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/writer/writer.sjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @return - nothing
99
*/
1010
function write(id, envelope, options) {
11-
xdmp.documentInsert('/employees/' + id + '.json', envelope);
11+
xdmp.documentInsert('/employees/' + id + '.json', envelope, xdmp.defaultPermissions(), options.flow);
1212
}
1313

1414
module.exports = write;

0 commit comments

Comments
 (0)