Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#65: Update helper methods with version #66

Merged
merged 7 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions lib/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,14 @@ const getIdxLookups = (fields, lookups, version = CURRENT_DD_VERSION) => {

const getLastPart = (str, char) => str.substr(str.lastIndexOf(char) + 1);

const getAdvertisedCountPerResourcesByType = ({ fields, lookups, version }) => {
const getAdvertisedCountPerResourcesByType = ({ fields, lookups, version = CURRENT_DD_VERSION }) => {
const reducedFields = fields.reduce(function (r, a) {
r[a.resourceName] = r[a.resourceName] || [];
r[a.resourceName].push(a);
return r;
}, Object.create(null));
const advertisedCount = {};
const idxLookups = getIdxLookups(fields, lookups, version);
const idxLookups = getIdxLookups(fields, lookups, version ?? CURRENT_DD_VERSION);
mohit-s96 marked this conversation as resolved.
Show resolved Hide resolved
for (const [key, value] of Object.entries(reducedFields)) {
advertisedCount[key] = { fields: {}, lookups: {} };
advertisedCount[key][FIELDS] = { total: 0, reso: 0, idx: 0, local: 0 };
Expand Down Expand Up @@ -264,7 +264,7 @@ const getIdxCounts = (fields, lookups, version = CURRENT_DD_VERSION) => {
/* iDXLookups
lookups of unique IDX fields with any of types ["String List, Single", String List, Multi]
*/
const iDXLookups = getIdxLookups(fields, lookups, version);
const iDXLookups = getIdxLookups(fields, lookups, version ?? CURRENT_DD_VERSION);
mohit-s96 marked this conversation as resolved.
Show resolved Hide resolved
const iDXLookupsCount = iDXLookups.length;
return { iDXFieldsCount, iDXResourcesCount, iDXLookupsCount };
};
Expand All @@ -282,10 +282,10 @@ const getFieldsCount = (fields, version = CURRENT_DD_VERSION) => {
};
};

const getResourcesCount = fields => {
const getResourcesCount = (fields, version = CURRENT_DD_VERSION) => {
mohit-s96 marked this conversation as resolved.
Show resolved Hide resolved
const resources = [...new Set(fields.map(field => field.resourceName))];
const totalResourcesCount = resources.length;
const standardResourcesCount = resources.filter(resource => getStandardResources().some(x => x === resource)).length;
const standardResourcesCount = resources.filter(resource => getStandardResources(version ?? CURRENT_DD_VERSION).some(x => x === resource)).length;
const localResourcesCount = totalResourcesCount - standardResourcesCount;
return { standardResourcesCount, localResourcesCount, totalResourcesCount };
};
Expand Down Expand Up @@ -355,5 +355,6 @@ module.exports = {
getLookupMap,
getStandardMetadata,
reportTypes,
CATEGORIES
CATEGORIES,
CURRENT_DD_VERSION
};
9 changes: 5 additions & 4 deletions lib/process-metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const {
getAdvertisedCountPerResourcesByType,
getMetadata,
getStandardMetadata,
CURRENT_DD_VERSION,
} = require('./common');

const ANNOTATION_TERM_STANDARD_NAME = 'RESO.OData.Metadata.StandardName';
Expand Down Expand Up @@ -34,10 +35,10 @@ const processMetadataReport = (

return {
...transformedMetadataReportJson,
...getFieldsCount(fields, reportInfo.version),
...getResourcesCount(fields),
...getFieldsCount(fields, reportInfo.version ?? CURRENT_DD_VERSION),
mohit-s96 marked this conversation as resolved.
Show resolved Hide resolved
...getResourcesCount(fields, reportInfo?.version ?? CURRENT_DD_VERSION),
...getLookupsCount(transformedMetadataReportJson.lookups),
mohit-s96 marked this conversation as resolved.
Show resolved Hide resolved
...getIdxCounts(fields, referenceLookups, reportInfo.version),
...getIdxCounts(fields, referenceLookups, reportInfo.version ?? CURRENT_DD_VERSION),
advertised: getAdvertisedCountPerResourcesByType(
transformedMetadataReportJson
),
Expand Down Expand Up @@ -215,7 +216,7 @@ const isReferencePlaceholderValue = ({ lookupValue = '' }) =>
const getTransformedLookups = (metadataReportJson = {}) => {
if (!metadataReportJson?.lookups) return [];

const referenceMetadataJson = getMetadata(metadataReportJson.version);
const referenceMetadataJson = getMetadata(metadataReportJson.version ?? CURRENT_DD_VERSION);
const referenceFieldMap = buildFieldMap(referenceMetadataJson);

//remove placeholder values added to the reference metadata for open enumerations without values
Expand Down
Loading