Skip to content

Commit d8f505d

Browse files
rahulvudutalamarklogic-builder
authored andcommitted
DHFPROD-10580: Source Header Fields Populated Incorrectly
1 parent 3f1a503 commit d8f505d

File tree

6 files changed

+32
-18
lines changed

6 files changed

+32
-18
lines changed

examples/reference-entity-model/src/main/ml-modules/root/custom-modules/ingestion/zipTransform/main.sjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
*/
66

77
function main(content, options) {
8-
const value = content.value.toObject();
8+
const value = content.value;
99

1010
// Concatenating latitude and longitude allows for a geospatial element index to be easily added
11-
value.geoPoint = value.latitude + " " + value.longitude;
11+
value.geoPoint = value.root.latitude + " " + value.root.longitude;
1212

1313
// "zipCode" is a bit more descriptive than "zip"
14-
value.zipCode = value.zip;
15-
delete value.zip;
14+
value.zipCode = value.root.zip;
15+
delete value.root.zip;
1616

1717
content.value = value;
1818
return content;

marklogic-data-hub/src/main/resources/ml-modules/root/data-hub/5/impl/flow-utils.mjs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -495,16 +495,17 @@ function evalSubstituteVal(value) {
495495
}
496496

497497
function createHeaders(options) {
498+
const newOptions = JSON.parse(JSON.stringify(options));
498499
let headers = {};
499-
for (let key in options.headers) {
500-
headers[key] = evalSubstituteVal(options.headers[key]);
500+
for (let key in newOptions.headers) {
501+
headers[key] = evalSubstituteVal(newOptions.headers[key]);
501502
}
502-
if (options.file) {
503-
headers["createdUsingFile"] = options.file;
503+
if (newOptions.file) {
504+
headers["createdUsingFile"] = newOptions.file;
504505
}
505506

506-
const sourceName = options.sourceName ? options.sourceName : null;
507-
const sourceType = options.sourceType ? options.sourceType : null;
507+
const sourceName = newOptions.sourceName ? newOptions.sourceName : null;
508+
const sourceType = newOptions.sourceType ? newOptions.sourceType : null;
508509

509510
if (headers["sources"] && !Array.isArray(headers["sources"])) {
510511
headers.sources = [headers.sources];

marklogic-data-hub/src/test/java/com/marklogic/hub/step/impl/IngestWithSourceNameAndSourceTypeTest.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void beforeEach() {
2626

2727
@Test
2828
void runDefaultIngestionWithSourceNameAndSourceType(){
29-
String path = "entity-reference-model/data/customers";
29+
String path = "entity-reference-model/data/employees";
3030
ObjectNode info = new ObjectMapper().createObjectNode();
3131
info.put("name", "sources-test");
3232
info.put("description", "step to test source name and source type");
@@ -49,14 +49,18 @@ void runDefaultIngestionWithSourceNameAndSourceType(){
4949
RunFlowResponse response = flowRunner.runFlow(inputs);
5050
flowRunner.awaitCompletion();
5151
assertEquals(JobStatus.FINISHED.toString(), response.getJobStatus());
52-
JsonNode sourceDoc = getStagingDoc("customer1.json");
53-
assertNotNull(sourceDoc);
54-
JsonNode sourcesNode = sourceDoc.get("envelope").get("headers").get("sources").get(0);
55-
assertEquals("sources-test", sourcesNode.get("name").asText());
5652

57-
sourcesNode = sourceDoc.get("envelope").get("headers").get("sources").get(1);
58-
assertEquals("sample-source", sourcesNode.get("datahubSourceName").asText());
59-
assertEquals("employee", sourcesNode.get("datahubSourceType").asText());
53+
for(int i=1; i<=3; i++) {
54+
JsonNode sourceDoc = getStagingDoc("employee" + i + ".json");
55+
assertNotNull(sourceDoc);
56+
assertEquals(2, sourceDoc.get("envelope").get("headers").get("sources").size(), "sources should contain name and only 1 object of sourceName and sourceType");
57+
JsonNode sourcesNode = sourceDoc.get("envelope").get("headers").get("sources").get(0);
58+
assertEquals("sources-test", sourcesNode.get("name").asText());
59+
60+
sourcesNode = sourceDoc.get("envelope").get("headers").get("sources").get(1);
61+
assertEquals("sample-source", sourcesNode.get("datahubSourceName").asText());
62+
assertEquals("employee", sourcesNode.get("datahubSourceType").asText());
63+
}
6064
}
6165

6266
@Test
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"EmployeeID": "1"
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"EmployeeID": "2"
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"EmployeeID": "3"
3+
}

0 commit comments

Comments
 (0)