From 510e1ad1b6b23d80a3e41a8d2f28f36f2d8f4e50 Mon Sep 17 00:00:00 2001 From: Siarhei Karol <135722306+SKarolFolio@users.noreply.github.com> Date: Wed, 20 Nov 2024 14:14:37 +0500 Subject: [PATCH] UILD-410: update URIs to fix Sonar security hotspots (#37) --- src/common/constants/bibframe.constants.ts | 6 ++++ .../constants/bibframeMapping.constants.ts | 10 +++++++ src/common/helpers/common.helper.ts | 14 ++++----- src/common/helpers/record.helper.ts | 4 +-- .../recordNormalizing/recordProcessingMap.ts | 29 ++++++++++--------- 5 files changed, 38 insertions(+), 25 deletions(-) diff --git a/src/common/constants/bibframe.constants.ts b/src/common/constants/bibframe.constants.ts index 786cd4c3..16c8a4a9 100644 --- a/src/common/constants/bibframe.constants.ts +++ b/src/common/constants/bibframe.constants.ts @@ -122,6 +122,12 @@ export const PROVISION_ACTIVITY_OPTIONS = [ 'http://bibfra.me/vocab/marc/manufacture', ]; +export const BF2_PROPERTY_URIS = { + HAS_INSTANCE: 'http://id.loc.gov/ontologies/bibframe/hasInstance', + INSTANCE_OF: 'http://id.loc.gov/ontologies/bibframe/instanceOf', + HAS_ITEM: 'http://id.loc.gov/ontologies/bibframe/hasItem', +}; + export const BFID_DELIMITER = ':'; export const BF_URI_DELIMITER = '/'; export const ENTRY_DELIMITER = '__'; diff --git a/src/common/constants/bibframeMapping.constants.ts b/src/common/constants/bibframeMapping.constants.ts index 3b6f9b75..f226a839 100644 --- a/src/common/constants/bibframeMapping.constants.ts +++ b/src/common/constants/bibframeMapping.constants.ts @@ -23,6 +23,16 @@ export const BFLITE_URIS = { PROVIDER_PLACE: 'http://bibfra.me/vocab/lite/providerPlace', CLASSIFICATION: 'http://bibfra.me/vocab/lite/classification', PROVISION_ACTIVITY: 'https://bibfra.me/vocab/marc/provisionActivity', + TITLE: 'http://bibfra.me/vocab/marc/title', + MAIN_TITLE: 'http://bibfra.me/vocab/marc/mainTitle', + PRODUCTION: 'http://bibfra.me/vocab/marc/production', + PUBLICATION: 'http://bibfra.me/vocab/marc/publication', + DISTRIBUTION: 'http://bibfra.me/vocab/marc/distribution', + MANUFACTURE: 'http://bibfra.me/vocab/marc/manufacture', + COPYRIGHT: 'http://bibfra.me/vocab/marc/copyright', + ISSUANCE: 'http://bibfra.me/vocab/marc/issuance', + LANGUAGE: 'http://bibfra.me/vocab/lite/language', + DATE: 'http://bibfra.me/vocab/lite/date' }; export const BF2_URIS = { diff --git a/src/common/helpers/common.helper.ts b/src/common/helpers/common.helper.ts index b95b1770..b71fe0f8 100644 --- a/src/common/helpers/common.helper.ts +++ b/src/common/helpers/common.helper.ts @@ -1,3 +1,4 @@ +import { BF2_PROPERTY_URIS } from '@common/constants/bibframe.constants'; import { lookupConfig } from '@common/constants/lookup.constants'; import { BaseFieldType, AdvancedFieldType } from '@common/constants/uiControls.constants'; @@ -18,14 +19,13 @@ export const getPropertyTemplateType = ({ }: PropertyTemplate): FieldType => { // these meta componets are structural things, like add new instances/items. etc if ( - propertyURI === 'http://id.loc.gov/ontologies/bibframe/hasInstance' || - propertyURI === 'http://id.loc.gov/ontologies/bibframe/instanceOf' + propertyURI === BF2_PROPERTY_URIS.HAS_INSTANCE || + propertyURI === BF2_PROPERTY_URIS.INSTANCE_OF ) return BaseFieldType.META; // we handle this structural thing elsewhere - // TODO: ^ no idea what this means - if (propertyURI === 'http://id.loc.gov/ontologies/bibframe/hasItem') return BaseFieldType.HIDE; + if (propertyURI === BF2_PROPERTY_URIS.HAS_ITEM) return BaseFieldType.HIDE; if (valueTemplateRefs.length > 0) return BaseFieldType.REF; @@ -44,8 +44,7 @@ export const getPropertyTemplateType = ({ return localType; }; -// TODO: potentially clean up -export const getAdvancedFieldType = (struct: Record): AdvancedFieldType => { +export const getAdvancedFieldType = (struct: Record): AdvancedFieldType => { // ProfileEntry if (struct?.configType === AdvancedFieldType.profile) return AdvancedFieldType.profile; @@ -76,9 +75,6 @@ export const getAdvancedFieldType = (struct: Record): AdvancedField default: return AdvancedFieldType.__fallback; } - - // TODO: REF -> META. HIDE - // in old handled by index = 0 & setAsGroup } return AdvancedFieldType.__fallback; diff --git a/src/common/helpers/record.helper.ts b/src/common/helpers/record.helper.ts index 020ba6e0..11959980 100644 --- a/src/common/helpers/record.helper.ts +++ b/src/common/helpers/record.helper.ts @@ -159,7 +159,7 @@ export const getRecordTitle = (record: RecordEntry) => { TITLE_CONTAINER_URIS.every(uri => { const selectedTitleContainer = ( - recordContents[block!]?.['http://bibfra.me/vocab/marc/title'] as unknown as Record[] + recordContents[block!]?.[BFLITE_URIS.TITLE] as unknown as Record[] )?.find(obj => Object.hasOwn(obj, uri)); if (selectedTitleContainer) { @@ -169,7 +169,7 @@ export const getRecordTitle = (record: RecordEntry) => { return !selectedTitleContainer; }); - return selectedTitle?.['http://bibfra.me/vocab/marc/mainTitle']?.[0]; + return selectedTitle?.[BFLITE_URIS.MAIN_TITLE]?.[0]; }; export const getAdjustedRecordContents = ({ record, block, reference, asClone }: IGetAdjustedRecordContents) => { diff --git a/src/common/services/recordNormalizing/recordProcessingMap.ts b/src/common/services/recordNormalizing/recordProcessingMap.ts index 95244987..02f59c0b 100644 --- a/src/common/services/recordNormalizing/recordProcessingMap.ts +++ b/src/common/services/recordNormalizing/recordProcessingMap.ts @@ -1,3 +1,4 @@ +import { BFLITE_URIS } from '@common/constants/bibframeMapping.constants'; import { wrapWithContainer, extractValue, @@ -10,32 +11,32 @@ import { } from './recordProcessingCases'; const processProvisionActivity = (record: RecordEntry, blockKey: string, groupKey: string) => - wrapWithContainer(record, blockKey, groupKey, 'https://bibfra.me/vocab/marc/provisionActivity'); + wrapWithContainer(record, blockKey, groupKey, BFLITE_URIS.PROVISION_ACTIVITY); export const RECORD_NORMALIZING_CASES = { - 'http://bibfra.me/vocab/marc/production': { + [BFLITE_URIS.PRODUCTION]: { process: processProvisionActivity, }, - 'http://bibfra.me/vocab/marc/publication': { + [BFLITE_URIS.PUBLICATION]: { process: processProvisionActivity, }, - 'http://bibfra.me/vocab/marc/distribution': { + [BFLITE_URIS.DISTRIBUTION]: { process: processProvisionActivity, }, - 'http://bibfra.me/vocab/marc/manufacture': { + [BFLITE_URIS.MANUFACTURE]: { process: processProvisionActivity, }, - 'http://bibfra.me/vocab/marc/copyright': { + [BFLITE_URIS.COPYRIGHT]: { process: (record: RecordEntry, blockKey: string, groupKey: string) => - extractValue(record, blockKey, groupKey, 'http://bibfra.me/vocab/lite/date'), + extractValue(record, blockKey, groupKey, BFLITE_URIS.DATE), }, - 'http://bibfra.me/vocab/marc/issuance': { + [BFLITE_URIS.ISSUANCE]: { process: wrapSimpleLookupData, }, _notes: { process: notesMapping, }, - 'http://bibfra.me/vocab/lite/extent': { + [BFLITE_URIS.EXTENT]: { process: (record: RecordEntry, blockKey: string, groupKey: string) => processComplexGroupValues(record, blockKey, groupKey, '_extent'), }, @@ -45,25 +46,25 @@ export const RECORD_NORMALIZING_CASES = { _contributorReference: { process: processCreator, }, - 'http://bibfra.me/vocab/marc/summary': { + [BFLITE_URIS.SUMMARY]: { process: (record: RecordEntry, blockKey: string, groupKey: string) => processComplexGroupValues(record, blockKey, groupKey, '_notes'), }, - 'http://bibfra.me/vocab/marc/tableOfContents': { + [BFLITE_URIS.TABLE_OF_CONTENTS]: { process: (record: RecordEntry, blockKey: string, groupKey: string) => processComplexGroupValues(record, blockKey, groupKey, '_notes'), }, - 'http://bibfra.me/vocab/lite/language': { + [BFLITE_URIS.LANGUAGE]: { process: (record: RecordEntry, blockKey: string, groupKey: string) => processComplexGroupWithLookup(record, blockKey, groupKey, '_language'), }, - 'http://bibfra.me/vocab/lite/classification': { + [BFLITE_URIS.CLASSIFICATION]: { process: (record: RecordEntry, blockKey: string, groupKey: string) => extractDropdownOption( record, blockKey, groupKey, - 'http://bibfra.me/vocab/marc/source', + BFLITE_URIS.SOURCE, '_assigningSourceReference', ), },