Skip to content

Commit 44a3298

Browse files
ryanjdewMarkLogic Builder
authored andcommitted
DHFPROD-7303: add primary key to default selected properties
1 parent 959ab2a commit 44a3298

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

marklogic-data-hub/src/main/resources/ml-modules/root/data-hub/5/entities/entity-search-lib.sjs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ function buildAllMetadata(parentPropertyName, entityModel, entityName) {
9393
const isStructuredProperty = property.datatype != "array" && property["$ref"];
9494
const isStructuredArrayProperty = property.datatype == "array" && (property["items"] && property["items"]["$ref"]);
9595

96+
const isPrimaryKey = propertyName === entityType.primaryKey;
97+
9698
const propertyMetadata = {};
9799
const propertyMetadataObject = {};
98100

@@ -132,7 +134,12 @@ function buildAllMetadata(parentPropertyName, entityModel, entityName) {
132134
granularPropertyMetadata = Object.assign({},granularPropertyMetadata, metaData["granularPropertyMetadata"]);
133135
}
134136
granularPropertyMetadata[propertyMetadataObject["propertyPath"]] = propertyMetadataObject;
135-
allPropertiesMetadata.push(propertyMetadata);
137+
// Ensure the primary key property goes first in the array so it is selected by default
138+
if (isPrimaryKey) {
139+
allPropertiesMetadata.unshift(propertyMetadata);
140+
} else {
141+
allPropertiesMetadata.push(propertyMetadata);
142+
}
136143
}
137144

138145
const allMetadata = {};

marklogic-data-hub/src/test/ml-modules/root/test/suites/data-hub/5/data-services/entitySearch/searchResultFacetsTest.sjs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,24 @@ function datahubSourceNameAndTypeFacetsTest() {
66
const options = hent.dumpSearchOptions(fn.doc("/entities/Customer.entity.json").toObject(), true);
77
const searchResults = fn.head(search.search('', options));
88

9-
return[
9+
return [
1010
test.assertEqual("testSourceForCustomer", xs.string(fn.head(searchResults.xpath("/*:facet[@name = 'sourceName']/*:facet-value[1]/text()")))),
1111
test.assertEqual("testSourceForCustomerXML", xs.string(fn.head(searchResults.xpath("/*:facet[@name = 'sourceName']/*:facet-value[2]/text()")))),
1212
test.assertEqual("testSourceType", xs.string(fn.head(searchResults.xpath("/*:facet[@name = 'sourceType']/*:facet-value[1]/text()")))),
1313
test.assertEqual("testSourceTypeXML", xs.string(fn.head(searchResults.xpath("/*:facet[@name = 'sourceType']/*:facet-value[2]/text()"))))
1414
];
1515
}
1616

17+
function selectedPropertiesTransformTest() {
18+
const searchResultsTransform = require('/marklogic.rest.transform/hubEntitySearchTransform/assets/transform.sjs');
19+
const transformedResults = searchResultsTransform.transform({}, { entityName: 'Customer'}, xdmp.toJSON({ results: []}));
20+
21+
return[
22+
test.assertTrue(transformedResults.selectedPropertyDefinitions && transformedResults.selectedPropertyDefinitions.length >= 1, `There should be at least one selected property. Results: ${xdmp.toJsonString(transformedResults)}`),
23+
test.assertEqual("customerId", transformedResults.selectedPropertyDefinitions[0].propertyLabel, `The first selected property should be the primary key. selectedPropertiesDefinition[0]: ${xdmp.toJsonString(transformedResults.selectedPropertyDefinitions[0])}`)
24+
];
25+
}
26+
1727
[]
18-
.concat(datahubSourceNameAndTypeFacetsTest());
28+
.concat(datahubSourceNameAndTypeFacetsTest())
29+
.concat(selectedPropertiesTransformTest());

marklogic-data-hub/src/test/ml-modules/root/test/suites/data-hub/5/data-services/entitySearch/test-data/entities/Customer.entity.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
],
1212
"primaryKey": "customerId",
1313
"properties": {
14-
"customerId": {
15-
"datatype": "integer"
16-
},
1714
"name": {
1815
"datatype": "string",
1916
"collation": "http://marklogic.com/collation/codepoint"
@@ -41,6 +38,10 @@
4138
},
4239
"customerSince": {
4340
"datatype": "date"
41+
},
42+
"customerId": {
43+
"datatype": "integer",
44+
"description": "This is supposed to be last to test that the primary key is always included"
4445
}
4546
}
4647
},

0 commit comments

Comments
 (0)