Skip to content

Commit e26ad91

Browse files
Aniela AmyMarkLogic Builder
authored andcommitted
DHFPROD-8136: Passing extra interceptors to flow if needed.
1 parent b3c7f04 commit e26ad91

File tree

7 files changed

+48
-8
lines changed

7 files changed

+48
-8
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ class Flow {
137137
));
138138
}
139139

140+
runFlow(flowName, jobId, contentArray, options, stepNumber) {
141+
runFlow(flowName, jobId, contentArray, options, stepNumber, null);
142+
}
140143
/**
141144
* It's unlikely that this actually runs a "flow", unless the flow consists of one step and only one transaction is
142145
* needed to run the step. More likely, this is really "process a batch of items for a step".
@@ -149,8 +152,9 @@ class Flow {
149152
* @param options Unfortunately this is not consistently defined; depending on the client, it's either the runtime
150153
* options provided by the user, or it's the already-combined options
151154
* @param stepNumber The number of the step within the given flow to run
155+
* @param interceptors Additional interceptors to run. Used with the merge REST endpoint
152156
*/
153-
runFlow(flowName, jobId, contentArray, options, stepNumber) {
157+
runFlow(flowName, jobId, contentArray, options, stepNumber, interceptors = []) {
154158
contentArray = contentArray || [];
155159
const theFlow = this.getFlow(flowName);
156160
if(!theFlow) {
@@ -177,10 +181,10 @@ class Flow {
177181
throw Error('Step '+stepNumber+' for the flow: '+flowName+' could not be found.');
178182
}
179183
const stepDefinition = this.stepDefinition.getStepDefinitionByNameAndType(flowStep.stepDefinitionName, flowStep.stepDefinitionType);
180-
181184
const stepExecutionContext = new StepExecutionContext(theFlow, stepNumber, stepDefinition, jobId, options);
182185
const combinedOptions = stepExecutionContext.combinedOptions;
183-
186+
// add any additional interceptors
187+
stepExecutionContext.flowStep.interceptors = (stepExecutionContext.flowStep.interceptors || []).concat(interceptors);
184188
const batchItems = contentArray.map(contentObject => contentObject.uri);
185189

186190
let outputContentArray;

marklogic-data-hub/src/main/resources/ml-modules/services/mlSmMerge.sjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ function post(context, params, input) {
4040
let stepDetails = datahub.flow.stepDefinition.getStepDefinitionByNameAndType(stepRef.stepDefinitionName, stepRef.stepDefinitionType) || {};
4141
// build combined options
4242
let flowOptions = flow.options || {};
43-
let stepRefOptions = stepRef.options || {};
44-
let stepDetailsOptions = stepDetails.options || {};
43+
let stepRefOptions = stepRef.options || stepRef;
44+
let stepDetailsOptions = stepDetails.options || stepDetails;
4545
let combinedOptions = Object.assign({}, stepDetailsOptions, flowOptions, stepRefOptions, inputOptions, params);
4646
let sourceDatabase = combinedOptions.sourceDatabase || config.FINALDATABASE;
4747

@@ -52,7 +52,8 @@ function post(context, params, input) {
5252
let uris = hubUtils.normalizeToArray(params.uri);
5353
let query = cts.documentQuery(uris);
5454
let content = hubUtils.queryToContentDescriptorArray(query, combinedOptions, sourceDatabase);
55-
let results = datahub.flow.runFlow(flowName, jobId, content, combinedOptions, stepNumber);
55+
let results = datahub.flow.runFlow(flowName, jobId, content, combinedOptions, stepNumber, stepRef.interceptors);
56+
5657
return {
5758
'success': results.errorCount === 0,
5859
'errors': results.errors,

marklogic-data-hub/src/test/ml-modules/root/test/suites/data-hub/5/smart-mastering/rest/mlSmMerge/post.sjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ const validResults = mlSmMergeRest.POST(context, validMergeParams, emptyDocument
1111

1212
assertions.push(
1313
test.assertTrue(validResults.success,"Merge should be successful"),
14-
test.assertEqual(2, validResults.mergedURIs.length)
14+
test.assertEqual(2, validResults.mergedURIs.length),
15+
test.assertTrue(validResults.mergedDocument.value.envelope.headers.interceptorCalled, "Interceptor should be called on merge.")
1516
);
1617

1718
const invalidMergeParams = { flowName: "CurateCustomerJSON", step: "1", uri: ["/content/customer1.json", "/content/customer2.json"] };

marklogic-data-hub/src/test/ml-modules/root/test/suites/data-hub/5/smart-mastering/rest/mlSmMerge/test-data/content/customer1.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"envelope": {
3+
"headers": {},
34
"instance": {
45
"info": {
56
"title": "Customer",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"envelope": {
3+
"headers": {},
4+
"instance": {
5+
"info": {
6+
"title": "Customer",
7+
"version": "0.0.1"
8+
},
9+
"Customer": {
10+
"customerId": 1
11+
}
12+
}
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
3+
var contentArray;
4+
var options;
5+
6+
contentArray.forEach(content => {
7+
if (content.value.root instanceof ObjectNode) {
8+
const contentValue = content.value.toObject();
9+
contentValue.envelope.headers.interceptorCalled = true;
10+
content.value = contentValue;
11+
}
12+
});

marklogic-data-hub/src/test/ml-modules/root/test/suites/data-hub/5/smart-mastering/rest/mlSmMerge/test-data/steps/merging/mergeCustomers.step.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,12 @@
1717
"lastUpdatedLocation": {},
1818
"mergeStrategies": [],
1919
"mergeRules": [],
20-
"targetCollections": {}
20+
"targetCollections": {},
21+
"interceptors" : [
22+
{
23+
"path": "/test/suites/data-hub/5/smart-mastering/rest/mlSmMerge/test-data/mergeInterceptor.sjs",
24+
"vars": {},
25+
"when": "beforeContentPersisted"
26+
}
27+
]
2128
}

0 commit comments

Comments
 (0)