Skip to content

Commit 2c51116

Browse files
ryanjdewMarkLogic Builder
authored andcommitted
DHFPROD-7452: Restrict property warnings to property being edited
1 parent a77e7b9 commit 2c51116

File tree

13 files changed

+81
-37
lines changed

13 files changed

+81
-37
lines changed

marklogic-data-hub-central/src/main/java/com/marklogic/hub/central/controllers/steps/MergingStepController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ public ResponseEntity<JsonNode> calculateMergingActivity(@PathVariable String st
8888
@ResponseBody
8989
@ApiOperation(value = "Validate the merging step")
9090
@Secured("ROLE_readMerging")
91-
public ResponseEntity<JsonNode> validateMatchingStep(@PathVariable String stepName, @RequestParam(required = false, defaultValue = "settings") String view) {
92-
return ResponseEntity.ok(MasteringService.on(getHubClient().getFinalClient()).validateMergingStep(stepName, view));
91+
public ResponseEntity<JsonNode> validateMergingStep(@PathVariable String stepName, @RequestParam(required = false, defaultValue = "settings") String view, @RequestParam(required = false) String entityPropertyPath) {
92+
return ResponseEntity.ok(MasteringService.on(getHubClient().getFinalClient()).validateMergingStep(stepName, view, entityPropertyPath));
9393
}
9494

9595
private StepService newService() {

marklogic-data-hub-central/ui/e2e/cypress/integration/curation/curate/mergeWarnings.spec.tsx

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,33 +111,36 @@ describe("Validate Merge warnings", () => {
111111
cy.contains(mergeStep1);
112112
});
113113
it("Click on merge rule Address and validate warnings", () => {
114-
cy.findByText("Address").click();
114+
cy.findAllByText("Address").first().click();
115115
cy.get("[name=\"maxValues\"]").first().check();
116116
mergeRuleModal.saveButton().click();
117-
mergeRuleModal.alertMessage().should("have.text", "Warning: The current merge settings might produce merged documents that are inconsistent with the entity type\nIn the entity type Person, the property or properties Address, DateOfBirth, ZipCode, id, SSN, lname, desc, fname allows only a single value.\nIn every merge rule for the property Address, DateOfBirth, ZipCode, id, SSN, lname, desc, fname set Max Values or Max Sources to 1.");
117+
mergeRuleModal.alertMessage().should("have.text", "Warning: The current merge settings might produce merged documents that are inconsistent with the entity type\nIn the entity type Person, the property or properties Address allows only a single value.\nIn every merge rule for the property Address set Max Values or Max Sources to 1.");
118118
mergeRuleModal.alertDescription().should("have.text", "Please set max values for property to 1 on merge to avoid an invalid entity instance.");
119119
mergeRuleModal.ruleMaxValuesInput("1");
120120
mergeRuleModal.saveButton().click();
121-
mergeRuleModal.alertMessage().should("have.text", "Warning: The current merge settings might produce merged documents that are inconsistent with the entity type\nIn the entity type Person, the property or properties DateOfBirth, ZipCode, id, SSN, lname, desc, fname allows only a single value.\nIn every merge rule for the property DateOfBirth, ZipCode, id, SSN, lname, desc, fname set Max Values or Max Sources to 1.");
122-
mergeRuleModal.alertDescription().should("have.text", "Please set max values for property to 1 on merge to avoid an invalid entity instance.");
121+
curatePage.alertMessage().should("not.exist");
122+
cy.findAllByText("Address").first().click();
123+
cy.get("[name=\"maxValues\"]").first().check();
123124
mergeRuleModal.ruleMaxValuesInput("0");
124125
mergeRuleModal.ruleMaxScoreInput("1");
125126
mergeRuleModal.saveButton().click();
126-
mergeRuleModal.alertMessage().should("have.text", "Warning: The current merge settings might produce merged documents that are inconsistent with the entity type\nIn the entity type Person, the property or properties DateOfBirth, ZipCode, id, SSN, lname, desc, fname allows only a single value.\nIn every merge rule for the property DateOfBirth, ZipCode, id, SSN, lname, desc, fname set Max Values or Max Sources to 1.");
127-
mergeRuleModal.alertDescription().should("have.text", "Please set max values for property to 1 on merge to avoid an invalid entity instance.");
127+
curatePage.alertMessage().should("not.exist");
128+
cy.findAllByText("Address").first().click();
129+
cy.get("[name=\"maxValues\"]").first().check();
128130
mergeRuleModal.ruleMaxScoreInput("0");
129131
mergeRuleModal.saveButton().click();
130-
mergeRuleModal.alertMessage().should("have.text", "Warning: The current merge settings might produce merged documents that are inconsistent with the entity type\nIn the entity type Person, the property or properties Address, DateOfBirth, ZipCode, id, SSN, lname, desc, fname allows only a single value.\nIn every merge rule for the property Address, DateOfBirth, ZipCode, id, SSN, lname, desc, fname set Max Values or Max Sources to 1.");
132+
mergeRuleModal.alertMessage().should("have.text", "Warning: The current merge settings might produce merged documents that are inconsistent with the entity type\nIn the entity type Person, the property or properties Address allows only a single value.\nIn every merge rule for the property Address set Max Values or Max Sources to 1.");
131133
mergeRuleModal.alertDescription().should("have.text", "Please set max values for property to 1 on merge to avoid an invalid entity instance.");
132134
mergeRuleModal.ruleMaxValuesInput("1");
133135
mergeRuleModal.ruleMaxScoreInput("2");
134136
mergeRuleModal.saveButton().click();
135-
mergeRuleModal.alertMessage().should("have.text", "Warning: The current merge settings might produce merged documents that are inconsistent with the entity type\nIn the entity type Person, the property or properties DateOfBirth, ZipCode, id, SSN, lname, desc, fname allows only a single value.\nIn every merge rule for the property DateOfBirth, ZipCode, id, SSN, lname, desc, fname set Max Values or Max Sources to 1.");
136-
mergeRuleModal.alertDescription().should("have.text", "Please set max values for property to 1 on merge to avoid an invalid entity instance.");
137+
curatePage.alertMessage().should("not.exist");
138+
cy.findAllByText("Address").first().click();
139+
cy.get("[name=\"maxValues\"]").first().check();
137140
mergeRuleModal.ruleMaxValuesInput("2");
138141
mergeRuleModal.ruleMaxScoreInput("2");
139142
mergeRuleModal.saveButton().click();
140-
mergeRuleModal.alertMessage().should("have.text", "Warning: The current merge settings might produce merged documents that are inconsistent with the entity type\nIn the entity type Person, the property or properties Address, DateOfBirth, ZipCode, id, SSN, lname, desc, fname allows only a single value.\nIn every merge rule for the property Address, DateOfBirth, ZipCode, id, SSN, lname, desc, fname set Max Values or Max Sources to 1.");
143+
mergeRuleModal.alertMessage().should("have.text", "Warning: The current merge settings might produce merged documents that are inconsistent with the entity type\nIn the entity type Person, the property or properties Address allows only a single value.\nIn every merge rule for the property Address set Max Values or Max Sources to 1.");
141144
mergeRuleModal.alertDescription().should("have.text", "Please set max values for property to 1 on merge to avoid an invalid entity instance.");
142145
//Will uncomment once DHFPROD-7452 is fixed
143146
/* mergeRuleModal.selectMergeTypeDropdown("Strategy");
@@ -160,7 +163,7 @@ describe("Validate Merge warnings", () => {
160163
cy.findByText("Address").click();
161164
mergeRuleModal.alertMessage().should("not.exist");
162165
mergeRuleModal.saveButton().click();
163-
mergeRuleModal.alertMessage().should("have.text", "Warning: The current merge settings might produce merged documents that are inconsistent with the entity type\nIn the entity type Person, the property or properties Address, DateOfBirth, id, SSN, lname, desc, fname allows only a single value.\nIn every merge rule for the property Address, DateOfBirth, id, SSN, lname, desc, fname set Max Values or Max Sources to 1.");
166+
mergeRuleModal.alertMessage().should("have.text", "Warning: The current merge settings might produce merged documents that are inconsistent with the entity type\nIn the entity type Person, the property or properties Address allows only a single value.\nIn every merge rule for the property Address set Max Values or Max Sources to 1.");
164167
mergeRuleModal.alertDescription().should("have.text", "Please set max values for property to 1 on merge to avoid an invalid entity instance.");
165168
mergeRuleModal.cancelButton().click();
166169
cy.findAllByText("retain-single-value").eq(0).click();
@@ -170,7 +173,7 @@ describe("Validate Merge warnings", () => {
170173
cy.wait(1000);
171174
cy.findByText("Address").click();
172175
mergeRuleModal.saveButton().click();
173-
mergeRuleModal.alertMessage().should("have.text", "Warning: The current merge settings might produce merged documents that are inconsistent with the entity type\nIn the entity type Person, the property or properties Address, DateOfBirth, ZipCode, id, SSN, lname, desc, fname allows only a single value.\nIn every merge rule for the property Address, DateOfBirth, ZipCode, id, SSN, lname, desc, fname set Max Values or Max Sources to 1.");
176+
mergeRuleModal.alertMessage().should("have.text", "Warning: The current merge settings might produce merged documents that are inconsistent with the entity type\nIn the entity type Person, the property or properties Address allows only a single value.\nIn every merge rule for the property Address set Max Values or Max Sources to 1.");
174177
mergeRuleModal.alertDescription().should("have.text", "Please set max values for property to 1 on merge to avoid an invalid entity instance.");
175178
mergeRuleModal.cancelButton().click();
176179
});

marklogic-data-hub-central/ui/src/api/merging.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ export const updateMergingArtifact = async (merging) => {
1515
}
1616
};
1717

18-
export const getMergingRulesWarnings = async (merging) => {
18+
export const getMergingRulesWarnings = async (merging, newMergeRule) => {
1919
try {
20-
let warningResponse = await axios.get(`/api/steps/merging/${merging.name}/validate?view=rules`);
20+
let filter = `&entityPropertyPath=${newMergeRule.entityPropertyPath}`;
21+
let warningResponse = await axios.get(`/api/steps/merging/${merging.name}/validate?view=rules${filter}`);
2122
if (warningResponse.status === 200) {
2223
return warningResponse;
2324
} else {

marklogic-data-hub-central/ui/src/components/entities/merging/add-merge-rule/merge-rule-dialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ const MergeRuleDialog: React.FC<Props> = (props) => {
469469
newStepArtifact.mergeRules[index] = newMergeRules;
470470
await updateMergingArtifact(newStepArtifact);
471471
updateActiveStepArtifact(newStepArtifact);
472-
let warnings= await getMergingRulesWarnings(newStepArtifact);
472+
let warnings= await getMergingRulesWarnings(newStepArtifact, newMergeRules);
473473
if (warnings !== undefined) { setValidationWarnings(warnings.data); }
474474
}
475475
};

marklogic-data-hub-central/ui/src/components/entities/merging/merging-step-detail/merging-step-detail.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,17 @@ const MergingStepDetail: React.FC = () => {
226226
];
227227

228228
for (let key of mergingStep.mergeRules) {
229-
for (let key1 of mergingStep.mergeStrategies) {
230-
if (key.mergeStrategyName === key1.strategyName && commonStrategyNames.indexOf(key.mergeStrategyName)=== -1) {
231-
commonStrategyNames.push(key.mergeStrategyName);
229+
if (mergingStep.mergeStrategies) {
230+
for (let key1 of mergingStep.mergeStrategies) {
231+
if (key.mergeStrategyName === key1.strategyName && commonStrategyNames.indexOf(key.mergeStrategyName) === -1) {
232+
commonStrategyNames.push(key.mergeStrategyName);
233+
}
232234
}
233235
}
234236
}
235237

236238

237-
mergingStep && mergingStep.mergeStrategies.length > 0 && mergingStep.mergeStrategies.forEach((i) => {
239+
mergingStep && mergingStep.mergeStrategies && mergingStep.mergeStrategies.length > 0 && mergingStep.mergeStrategies.forEach((i) => {
238240
mergeStrategiesData.push(
239241
{
240242
strategyName: i["strategyName"],

marklogic-data-hub/src/main/java/com/marklogic/hub/dataservices/MasteringService.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,17 +188,18 @@ private com.fasterxml.jackson.databind.JsonNode getDefaultCollections(BaseProxy.
188188
}
189189

190190
@Override
191-
public com.fasterxml.jackson.databind.JsonNode validateMergingStep(String stepName, String view) {
191+
public com.fasterxml.jackson.databind.JsonNode validateMergingStep(String stepName, String view, String entityPropertyPath) {
192192
return validateMergingStep(
193-
this.req_validateMergingStep.on(this.dbClient), stepName, view
193+
this.req_validateMergingStep.on(this.dbClient), stepName, view, entityPropertyPath
194194
);
195195
}
196-
private com.fasterxml.jackson.databind.JsonNode validateMergingStep(BaseProxy.DBFunctionRequest request, String stepName, String view) {
196+
private com.fasterxml.jackson.databind.JsonNode validateMergingStep(BaseProxy.DBFunctionRequest request, String stepName, String view, String entityPropertyPath) {
197197
return BaseProxy.JsonDocumentType.toJsonNode(
198198
request
199199
.withParams(
200200
BaseProxy.atomicParam("stepName", false, BaseProxy.StringType.fromString(stepName)),
201-
BaseProxy.atomicParam("view", false, BaseProxy.StringType.fromString(view))
201+
BaseProxy.atomicParam("view", false, BaseProxy.StringType.fromString(view)),
202+
BaseProxy.atomicParam("entityPropertyPath", true, BaseProxy.StringType.fromString(entityPropertyPath))
202203
).responseSingle(false, Format.JSON)
203204
);
204205
}
@@ -271,8 +272,9 @@ private com.fasterxml.jackson.databind.JsonNode validateMergingStep(BaseProxy.DB
271272
*
272273
* @param stepName provides input
273274
* @param view Designates the view the messages are for. Valid values are 'settings' or 'rules'
275+
* @param entityPropertyPath Restricts property warnings to a given entity property path
274276
* @return Returns an array of zero or more warning objects; each object has "level" and "message" properties
275277
*/
276-
com.fasterxml.jackson.databind.JsonNode validateMergingStep(String stepName, String view);
278+
com.fasterxml.jackson.databind.JsonNode validateMergingStep(String stepName, String view, String entityPropertyPath);
277279

278280
}

marklogic-data-hub/src/main/resources/ml-modules/root/data-hub/5/data-services/mastering/validateMergingStep.api

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
"name": "view",
1111
"desc": "Designates the view the messages are for. Valid values are 'settings' or 'rules'",
1212
"datatype": "string"
13+
},
14+
{
15+
"name": "entityPropertyPath",
16+
"desc": "Restricts property warnings to a given entity property path",
17+
"datatype": "string",
18+
"nullable": true
1319
}
1420
],
1521
"return": {

marklogic-data-hub/src/main/resources/ml-modules/root/data-hub/5/data-services/mastering/validateMergingStep.sjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
const validateMergeLib = require("/data-hub/5/data-services/mastering/validateMergingStepLib.sjs");
1919

20-
var stepName, view;
20+
var stepName, view, entityPropertyPath;
2121

2222
xdmp.securityAssert("http://marklogic.com/data-hub/privileges/read-match-merge", "execute");
2323

@@ -52,7 +52,7 @@ if (view === "settings") {
5252
}
5353
}
5454
} else if (view === "rules") {
55-
let propertyWarnings = validateMergeLib.propertiesWarning(step);
55+
let propertyWarnings = validateMergeLib.propertiesWarning(step, entityPropertyPath);
5656
if (propertyWarnings) {
5757
warnings.push(propertyWarnings);
5858
}

marklogic-data-hub/src/main/resources/ml-modules/root/data-hub/5/data-services/mastering/validateMergingStepLib.sjs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,19 @@
1818
const mergingOptions = require("/com.marklogic.smart-mastering/survivorship/merging/options.xqy");
1919
const common = require("/data-hub/5/data-services/mastering/validateStepCommonLib.sjs");
2020

21-
function propertiesWarning(mergeStep) {
21+
function propertiesWarning(mergeStep, entityPropertyPath) {
2222
let compiledOptions = mergingOptions.compileMergeOptions(mergeStep, true);
2323
let mergeRulesInfo = compiledOptions.mergeRulesInfo ? Sequence.from([compiledOptions.mergeRulesInfo]).toArray() : [];
2424
let nonCompliantRules = mergeRulesInfo.filter((ruleInfo) => {
2525
let allowsMultipleValues = ruleInfo.allowsMultipleValues;
2626
let ruleObject = ruleInfo.mergeRule ? ruleInfo.mergeRule.toObject() : null;
27-
let valuesLimitedToOne = ruleObject && (ruleObject.maxValues === "1" || ruleObject.maxSources === "1");
28-
return !(allowsMultipleValues || valuesLimitedToOne);
27+
let valuesLimitedToOne = ruleObject && (fn.string(ruleObject.maxValues) === "1" || fn.string(ruleObject.maxSources) === "1");
28+
let ruleFilteredOut = false;
29+
if (entityPropertyPath) {
30+
let ruleEntityPropertyPath = ruleObject ? ruleObject.entityPropertyPath : "";
31+
ruleFilteredOut = ruleEntityPropertyPath !== entityPropertyPath;
32+
}
33+
return !(ruleFilteredOut || allowsMultipleValues || valuesLimitedToOne);
2934
});
3035
let nonCompliantRuleProperties = nonCompliantRules.map((ruleInfo) => {
3136
return ruleInfo.propertyName;

marklogic-data-hub/src/test/ml-modules/root/test/suites/data-hub/5/data-services/mastering/previewMatchingActivity/setup.xqy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ xdmp:sleep(250);
1616
xquery version "1.0-ml";
1717
import module namespace hub-test = "http://marklogic.com/data-hub/test" at "/test/data-hub-test-helper.xqy";
1818
import module namespace test = "http://marklogic.com/test" at "/test/test-helper.xqy";
19-
hub-test:load-artifacts($test:__CALLER_FILE__)
19+
hub-test:load-artifacts($test:__CALLER_FILE__);

0 commit comments

Comments
 (0)