Skip to content

Commit

Permalink
#31: Updated Scoring for OData Standard Display Names
Browse files Browse the repository at this point in the history
  • Loading branch information
darnjo committed Sep 12, 2023
1 parent 080e450 commit 5e6844d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,4 @@ dist

# TernJS port file
.tern-port
.DS_Store
30 changes: 7 additions & 23 deletions lib/process-metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ const parseLookupName = (lookupName = '') => {
const FQDNSeparator = '.';
return {
lookupName:
lookupName?.slice(lookupName?.lastIndexOf(FQDNSeparator) + 1) || null,
lookupName?.slice(lookupName?.lastIndexOf(FQDNSeparator) + 1) ?? null,
lookupNameFQDN:
lookupName?.slice(0, lookupName?.lastIndexOf(FQDNSeparator)) || null,
lookupName?.slice(0, lookupName?.lastIndexOf(FQDNSeparator)) ?? null,
lookupNameWithFQDN: lookupName,
};
};
Expand Down Expand Up @@ -151,7 +151,7 @@ const buildStandardLookupValueMap = (lookups = []) => {
const { lookupName, lookupValue, standardDisplayName, annotations } =
item;

if (!(lookupName && (standardDisplayName || lookupValue))) return cache;
if (!(lookupName && (standardDisplayName ?? lookupValue))) return cache;
if (!cache[lookupName]) cache[lookupName] = {};

//add entry for the standard lookup value
Expand Down Expand Up @@ -224,7 +224,7 @@ const getTransformedLookups = (metadataReportJson = {}) => {
const referenceLookups =
referenceMetadataJson?.lookups?.filter(
(lookup) => !isReferencePlaceholderValue(lookup)
) || [];
) ?? [];

const referenceLookupNameValueMap =
buildStandardLookupValueMap(referenceLookups);
Expand All @@ -233,7 +233,7 @@ const getTransformedLookups = (metadataReportJson = {}) => {
const lookupMap = buildLookupMap(metadataReportJson?.lookups);

return Object.values(
(metadataReportJson?.fields || [])
(metadataReportJson?.fields ?? [])
.filter(isLookupField)
.flatMap((field = {}) => {
const { resourceName, fieldName, type: fieldType } = field;
Expand All @@ -250,11 +250,11 @@ const getTransformedLookups = (metadataReportJson = {}) => {
referenceFieldMap[resourceName][fieldName];

const { lookupName: resoLookupName } =
parseLookupName(standardField?.type) || {};
parseLookupName(standardField?.type) ?? {};

//get lookup maps for the given item
const standardLookupValueMap =
referenceLookupNameValueMap[resoLookupName] || {};
referenceLookupNameValueMap[resoLookupName] ?? {};

if (!lookupMap[lookupName]) {
return [];
Expand All @@ -264,7 +264,6 @@ const getTransformedLookups = (metadataReportJson = {}) => {
const {
lookupValue,
lookupNameWithFQDN: lookupName,
annotations,
type,
} = lookup;

Expand All @@ -282,21 +281,6 @@ const getTransformedLookups = (metadataReportJson = {}) => {
};
}

const standardDisplayName =
findStandardDisplayNameAnnotation(annotations);
const standardDisplayNameMatch =
standardDisplayName &&
standardLookupValueMap[standardDisplayName];
if (standardDisplayNameMatch) {
return {
lookupName,
lookupValue: standardDisplayName,
type,
standardRESO: true,
standardDisplayName,
};
}

//otherwise the lookup is local
return { lookupName, lookupValue, type, standardRESO: false };
});
Expand Down

0 comments on commit 5e6844d

Please sign in to comment.