Skip to content

Commit 75b383b

Browse files
committed
more plugins for the hr-hub example
fixing the way vet works for collectors
1 parent d70e261 commit 75b383b

File tree

15 files changed

+243
-8
lines changed

15 files changed

+243
-8
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"id": "32920",
3+
"firstName": "Rosanne",
4+
"lastName": "Henckle",
5+
"dateOfBirth": "05/19/1979",
6+
"hireDate": "11/12/2015",
7+
"salaryHistory": [
8+
{
9+
"effectiveDate": "11/12/2015",
10+
"salary": 63439
11+
},
12+
{
13+
"effectiveDate": "01/14/2016",
14+
"salary": 66300
15+
}
16+
]
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"id": "34324",
3+
"firstName": "Robert",
4+
"lastName": "Smith",
5+
"dateOfBirth": "01/01/1981",
6+
"hireDate": "09/01/2014",
7+
"salaryHistory": [
8+
{
9+
"effectiveDate": "09/01/2014",
10+
"salary": 59832
11+
},
12+
{
13+
"effectiveDate": "09/14/2015",
14+
"salary": 60832
15+
}
16+
]
17+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
return cts.uris(null, null, cts.collectionQuery('hr-json-dumps'));
10+
}
11+
12+
module.exports = {
13+
collect: collect
14+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Create Content Plugin
3+
*
4+
* @param id - the identifier returned by the collector
5+
* @param content - your final content
6+
* @param headers - an array of header objects
7+
* @param triples - an array of triples
8+
* @param options - an object containing options. Options are sent from Java
9+
*
10+
* @return - your content
11+
*/
12+
function createContent(id, content, headers, triples, options) {
13+
var root = cts.doc(id).root;
14+
15+
// for xml we need to use xpath
16+
if (xdmp.nodeKind(root) === 'element') {
17+
return root.xpath('/*:envelope/*:content/node()');
18+
}
19+
// for json we need to return the content
20+
else {
21+
return root.content;
22+
}
23+
}
24+
25+
module.exports = {
26+
createContent: createContent
27+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?xml version="1.0" ?><flow xmlns="http://marklogic.com/data-hub"><name>create-employees-from-json-dumps</name><entity>Employee</entity><type>conformance</type><complexity>simple</complexity><data-format>application/json</data-format><plugins></plugins></flow>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Create Headers Plugin
3+
*
4+
* @param id - the identifier returned by the collector
5+
* @param content - your final content
6+
* @param headers - an array of header objects
7+
* @param triples - an array of triples
8+
* @param options - an object containing options. Options are sent from Java
9+
*
10+
* @return - an array of header objects
11+
*/
12+
function createHeaders(id, content, headers, triples, options) {
13+
var latest = xs.date('1900-01-01');
14+
var salary;
15+
16+
// console.log(content);
17+
for (var i = 0; i < content.salaryHistory.length; i++) {
18+
var history = content.salaryHistory[i];
19+
// console.log('history: ' + i);
20+
// console.log(history);
21+
var date = xs.date(xdmp.parseDateTime('[M01]/[D01]/[Y0001]', history.effectiveDate));
22+
if (date.gt(latest)) {
23+
salary = history.salary;
24+
}
25+
}
26+
27+
return [
28+
{
29+
employeeId: content.id
30+
},
31+
{
32+
hireDate: xs.date(xdmp.parseDateTime('[M01]/[D01]/[Y0001]', content.hireDate))
33+
},
34+
{
35+
salary: xs.int(salary)
36+
}
37+
];
38+
}
39+
40+
module.exports = {
41+
createHeaders: createHeaders
42+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Create Triples Plugin
3+
*
4+
* @param id - the identifier returned by the collector
5+
* @param content - your final content
6+
* @param headers - an array of header objects
7+
* @param triples - an array of triples
8+
* @param options - an object containing options. Options are sent from Java
9+
*
10+
* @return - an array of triples
11+
*/
12+
function createTriples(id, content, headers, triples, options) {
13+
return [];
14+
}
15+
16+
module.exports = {
17+
createTriples: createTriples
18+
};
19+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*~
2+
* Writer Plugin
3+
*
4+
* @param id - the identifier returned by the collector
5+
* @param envelope - the final envelope
6+
* @param options - a map containing options. Options are sent from Java
7+
*
8+
* @return - zero or more header nodes
9+
*/
10+
function write(id, content, options) {
11+
xdmp.documentInsert(id, content, [], ['json-employee']);
12+
}
13+
14+
module.exports = {
15+
write: write
16+
};
17+

examples/hr-hub/plugins/entities/Employee/conformance/create-employees/collector/collector.sjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88
function collect(options) {
99
var y = [];
10-
for (var x of fn.collection()) {
10+
for (var x of fn.collection('hr-csv-dumps')) {
1111
var empid = x.root.content.emp_id;
1212
if (empid) {
1313
y.push(empid);

examples/hr-hub/plugins/entities/Employee/conformance/create-employees/headers/headers.sjs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,17 @@
1010
* @return - an array of header objects
1111
*/
1212
function createHeaders(id, content, headers, triples, options) {
13-
return [];
13+
return [
14+
{
15+
employeeId: content.emp_id
16+
},
17+
{
18+
hireDate: xs.date(xdmp.parseDateTime('[M01]/[D01]/[Y0001]', content.hire_date))
19+
},
20+
{
21+
salary: xs.int(content.base_salary) + xs.int(content.bonus)
22+
}
23+
];
1424
}
1525

1626
module.exports = {

0 commit comments

Comments
 (0)