Skip to content

Commit 1dd8b71

Browse files
ryanjdewMarkLogic Builder
authored andcommitted
DHFPROD-8379: Fix mapping related entities with same property name
1 parent c2abde3 commit 1dd8b71

File tree

8 files changed

+208
-12
lines changed

8 files changed

+208
-12
lines changed

marklogic-data-hub-central/ui/src/components/entities/mapping/entity-map-table/entity-map-table.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,7 @@ const EntityMapTable: React.FC<Props> = (props) => {
12721272
}}
12731273
dataTestid={`searchInput-entity`}
12741274
placeholder={`Search name`}
1275-
value={searchedKeys[0]}
1275+
value={searchedKeys[0] || ""}
12761276
onChange={e => setSearchedKeys(e.target.value ? [e.target.value] : [])}
12771277
onPressEnter={(enter) => enter ? searchedKeys?.length > 0 ? "" : false : null}
12781278
className={styles.searchInput}

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ const MappingStepDetail: React.FC = () => {
541541
let entEntityTempData: any = [];
542542
let uriKey = EntityTableKeyIndex + 1;
543543
EntityTableKeyIndex++;
544-
let nestedEntityProps = extractNestedEntityData(entProps, entEntityTempData);
544+
let nestedEntityProps = extractNestedEntityData(entProps, entEntityTempData, rootEntityName);
545545
nestedEntityProps.unshift({key: uriKey, name: "URI", type: "", isProperty: false, filterName: "URI", filterMatch: false}); //add URI field to front of properties
546546
setEntityTypeProperties([...nestedEntityProps]);
547547
setTargetRelatedMappings(resp.data[0]["relatedEntityMappings"]);
@@ -555,7 +555,7 @@ const MappingStepDetail: React.FC = () => {
555555
let contextKey = EntityTableKeyIndex + 1;
556556
uriKey = contextKey + 1;
557557
EntityTableKeyIndex += 2;
558-
let relatedEntityProps = extractNestedEntityData(relatedEntProps, relatedEntityTempData);
558+
let relatedEntityProps = extractNestedEntityData(relatedEntProps, relatedEntityTempData, relatedEntityName);
559559
relatedEntityProps.unshift({key: uriKey, name: "URI", type: "", isProperty: false, filterName: "URI", filterMatch: false}); //add URI field to front of properties
560560
relatedEntityProps.unshift({key: contextKey, name: "Context", type: "", isProperty: false, filterName: "Context", filterMatch: false}); //add Context field to front of properties
561561
relatedEntities.push({entityType: entityObject.entityType, entityModel: entityObject.entityModel, entityLabel: entityObject.mappingTitle, entityMappingId: entityObject.entityMappingId, relatedEntityMappings: entityObject.relatedEntityMappings, entityProps: relatedEntityProps});
@@ -580,8 +580,7 @@ const MappingStepDetail: React.FC = () => {
580580
};
581581

582582

583-
const extractNestedEntityData = (entProps, nestedEntityData: Array<any>, parentKey = "") => {
584-
583+
const extractNestedEntityData = (entProps, nestedEntityData: Array<any>, entityTitle: string, parentKey = "") => {
585584
Object.keys(entProps).forEach(key => {
586585
let val = entProps[key];
587586
let propty;
@@ -591,7 +590,7 @@ const MappingStepDetail: React.FC = () => {
591590
EntityTableKeyIndex = EntityTableKeyIndex + 1;
592591
if (val.$ref || val.items.$ref) {
593592
let ref = val.$ref ? val.$ref : val.items.$ref;
594-
tgtRefs[parentKey] = ref;
593+
tgtRefs[`${entityTitle ? entityTitle + "/": ""}${parentKey}`] = ref;
595594
}
596595

597596
propty = {
@@ -604,7 +603,7 @@ const MappingStepDetail: React.FC = () => {
604603
children: []
605604
};
606605
nestedEntityData.push(propty);
607-
extractNestedEntityData(val.subProperties, propty.children, parentKey);
606+
extractNestedEntityData(val.subProperties, propty.children, entityTitle, parentKey);
608607
parentKey = (parentKey.indexOf("/") !== -1) ? parentKey.substring(0, parentKey.lastIndexOf("/")) : "";
609608

610609
} else {
@@ -838,14 +837,14 @@ const MappingStepDetail: React.FC = () => {
838837
return obj;
839838
};
840839

841-
const getTgtEntityTypesInMap = (mapExp, parentKey = "") => {
840+
const getTgtEntityTypesInMap = (mapExp, entityType: string, parentKey = "") => {
842841
Object.keys(mapExp).forEach(key => {
843842
let val = mapExp[key];
844843
if (val.constructor.name === "Object") {
845844
if (val.hasOwnProperty("properties")) {
846845
let tempKey = parentKey ? parentKey + "/" + key : key;
847-
val["targetEntityType"] = tgtEntityReferences[tempKey];
848-
getTgtEntityTypesInMap(val.properties, tempKey);
846+
val["targetEntityType"] = tgtEntityReferences[`${entityType ? entityType + "/": ""}${tempKey}`];
847+
getTgtEntityTypesInMap(val.properties, entityType, tempKey);
849848
}
850849
}
851850
});
@@ -974,7 +973,7 @@ const MappingStepDetail: React.FC = () => {
974973
}}
975974
dataTestid={`searchInput-source`}
976975
placeholder={`Search name`}
977-
value={searchedKeys[0]}
976+
value={searchedKeys[0] || ""}
978977
onChange={e => setSearchedKeys(e.target.value ? [e.target.value] : [])}
979978
onPressEnter={(enter) => enter ? searchedKeys?.length > 0 ? "" : false : null}
980979
className={styles.searchInput}
@@ -1253,10 +1252,11 @@ const MappingStepDetail: React.FC = () => {
12531252

12541253
const saveMapping = async (mapObject, entityMappingId, updatedContext, updatedUri, relatedEntityModel) => {
12551254
let obj = {};
1255+
let entityName = curationOptions.activeStep.entityName;
12561256
Object.keys(mapObject).forEach(key => {
12571257
convertMapExpToMapArt(obj, key, {"sourcedFrom": mapObject[key]});
12581258
});
1259-
await getTgtEntityTypesInMap(obj);
1259+
await getTgtEntityTypesInMap(obj, entityName);
12601260
let {lastUpdated, properties, ...dataPayload} = savedMappingArt;
12611261
if (entityMappingId) {
12621262
if (!dataPayload.relatedEntityMappings) {
@@ -1708,6 +1708,7 @@ const MappingStepDetail: React.FC = () => {
17081708
/>
17091709
{relatedEntityTypeProperties.map((entity, i) => relatedEntitiesSelected.map(selectedEntity => selectedEntity.entityMappingId).includes(entity.entityMappingId) ?
17101710
<EntityMapTable
1711+
key={`relatedEntity-${i}`}
17111712
setScrollRef={setRef}
17121713
executeScroll={executeScroll}
17131714
mapResp={mapResp}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
xquery version "1.0-ml";
2+
import module namespace hub-test = "http://marklogic.com/data-hub/test" at "/test/data-hub-test-helper.xqy";
3+
hub-test:reset-hub()
4+
5+
;
6+
7+
xquery version "1.0-ml";
8+
import module namespace hub-test = "http://marklogic.com/data-hub/test" at "/test/data-hub-test-helper.xqy";
9+
import module namespace test = "http://marklogic.com/test" at "/test/test-helper.xqy";
10+
hub-test:load-entities($test:__CALLER_FILE__)
11+
12+
;
13+
14+
xquery version "1.0-ml";
15+
import module namespace hub-test = "http://marklogic.com/data-hub/test" at "/test/data-hub-test-helper.xqy";
16+
import module namespace test = "http://marklogic.com/test" at "/test/test-helper.xqy";
17+
hub-test:load-non-entities($test:__CALLER_FILE__)
18+
19+
;
20+
21+
xquery version "1.0-ml";
22+
import module namespace hub-test = "http://marklogic.com/data-hub/test" at "/test/data-hub-test-helper.xqy";
23+
hub-test:wait-for-indexes();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"info": {
3+
"title": "Cat",
4+
"draft": false,
5+
"version": "1.0.0",
6+
"baseUri": "http://example.org/"
7+
},
8+
"definitions": {
9+
"Cat": {
10+
"properties": {
11+
"id": {
12+
"datatype": "string",
13+
"facetable": false,
14+
"sortable": false,
15+
"collation": "http://marklogic.com/collation/codepoint"
16+
},
17+
"favourite_food": {
18+
"$ref": "#/definitions/CatFood"
19+
}
20+
},
21+
"primaryKey": "id"
22+
},
23+
"CatFood": {
24+
"properties": {
25+
"brand": {
26+
"datatype": "string",
27+
"facetable": false,
28+
"sortable": false,
29+
"collation": "http://marklogic.com/collation/codepoint"
30+
}
31+
}
32+
}
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"info": {
3+
"title": "Dog",
4+
"draft": false,
5+
"version": "1.0.0",
6+
"baseUri": "http://example.org/"
7+
},
8+
"definitions": {
9+
"Dog": {
10+
"properties": {
11+
"id": {
12+
"datatype": "string",
13+
"facetable": false,
14+
"sortable": false,
15+
"collation": "http://marklogic.com/collation/codepoint"
16+
},
17+
"hates_cats": {
18+
"datatype": "array",
19+
"facetable": false,
20+
"sortable": false,
21+
"items": {
22+
"datatype": "string",
23+
"relatedEntityType": "http://example.org/Cat-1.0.0/Cat",
24+
"joinPropertyName": "id"
25+
}
26+
},
27+
"favourite_food": {
28+
"$ref": "#/definitions/DogFood"
29+
}
30+
},
31+
"primaryKey": "id"
32+
},
33+
"DogFood": {
34+
"properties": {
35+
"brand": {
36+
"datatype": "string",
37+
"facetable": false,
38+
"sortable": false,
39+
"collation": "http://marklogic.com/collation/codepoint"
40+
}
41+
}
42+
}
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"collections": [
3+
"MapCat",
4+
"Cat"
5+
],
6+
"additionalCollections": [ ],
7+
"permissions": "data-hub-common,read,data-hub-common,update",
8+
"batchSize": 100,
9+
"validateEntity": "doNotValidate",
10+
"targetFormat": "JSON",
11+
"attachSourceDocument": false,
12+
"sourceRecordScope": "instanceOnly",
13+
"name": "MapCat",
14+
"targetEntityType": "http://example.org/Cat-1.0.0/Cat",
15+
"description": "",
16+
"collection": "cat",
17+
"selectedSource": "collection",
18+
"sourceQuery": "cts.collectionQuery(['cat'])",
19+
"targetDatabase": "data-hub-FINAL",
20+
"headers": { },
21+
"interceptors": [ ],
22+
"provenanceGranularityLevel": "off",
23+
"customHook": { },
24+
"sourceDatabase": "data-hub-STAGING",
25+
"stepDefinitionName": "entity-services-mapping",
26+
"stepDefinitionType": "mapping",
27+
"stepId": "MapCat-mapping",
28+
"acceptsBatch": true,
29+
"lastUpdated": "2022-01-24T15:30:01.026789Z",
30+
"uriExpression": "$URI",
31+
"properties": {
32+
"id": {
33+
"sourcedFrom": "id"
34+
},
35+
"favourite_food": {
36+
"sourcedFrom": "food"
37+
}
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"collections": [
3+
"MapDog",
4+
"Dog"
5+
],
6+
"additionalCollections": [ ],
7+
"permissions": "data-hub-common,read,data-hub-common,update",
8+
"batchSize": 100,
9+
"validateEntity": "doNotValidate",
10+
"targetFormat": "JSON",
11+
"attachSourceDocument": false,
12+
"sourceRecordScope": "instanceOnly",
13+
"name": "MapDog",
14+
"targetEntityType": "http://example.org/Dog-1.0.0/Dog",
15+
"description": "",
16+
"collection": "dog",
17+
"selectedSource": "collection",
18+
"sourceQuery": "cts.collectionQuery(['dog'])",
19+
"targetDatabase": "data-hub-FINAL",
20+
"headers": { },
21+
"interceptors": [ ],
22+
"provenanceGranularityLevel": "off",
23+
"customHook": { },
24+
"sourceDatabase": "data-hub-STAGING",
25+
"stepDefinitionName": "entity-services-mapping",
26+
"stepDefinitionType": "mapping",
27+
"stepId": "MapDog-mapping",
28+
"acceptsBatch": true,
29+
"lastUpdated": "2022-01-24T15:30:25.891426Z",
30+
"uriExpression": "$URI",
31+
"properties": {
32+
"id": {
33+
"sourcedFrom": "id"
34+
},
35+
"favourite_food": {
36+
"sourcedFrom": "food"
37+
}
38+
}
39+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
const test = require("/test/test-helper.xqy");
4+
5+
const esMappingLib = require("/data-hub/5/builtins/steps/mapping/entity-services/lib.sjs");
6+
let assertions = [];
7+
8+
9+
let output = esMappingLib.buildMappingXML(cts.doc("/steps/mapping/MapDog.step.json"), []);
10+
11+
assertions.push(test.assertTrue(fn.exists(output)));
12+
output = esMappingLib.buildMappingXML(cts.doc("/steps/mapping/MapCat.step.json"), []);
13+
14+
assertions.push(test.assertTrue(fn.exists(output)));
15+
16+
assertions;

0 commit comments

Comments
 (0)