Skip to content

Commit

Permalink
UILD-410: update URIs to fix Sonar security hotspots (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
SKarolFolio authored Nov 20, 2024
1 parent 2d74e62 commit 510e1ad
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 25 deletions.
6 changes: 6 additions & 0 deletions src/common/constants/bibframe.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '__';
Expand Down
10 changes: 10 additions & 0 deletions src/common/constants/bibframeMapping.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
14 changes: 5 additions & 9 deletions src/common/helpers/common.helper.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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;

Expand All @@ -44,8 +44,7 @@ export const getPropertyTemplateType = ({
return localType;
};

// TODO: potentially clean up
export const getAdvancedFieldType = (struct: Record<string, any>): AdvancedFieldType => {
export const getAdvancedFieldType = (struct: Record<string, unknown>): AdvancedFieldType => {
// ProfileEntry
if (struct?.configType === AdvancedFieldType.profile) return AdvancedFieldType.profile;

Expand Down Expand Up @@ -76,9 +75,6 @@ export const getAdvancedFieldType = (struct: Record<string, any>): AdvancedField
default:
return AdvancedFieldType.__fallback;
}

// TODO: REF -> META. HIDE
// in old handled by index = 0 & setAsGroup
}

return AdvancedFieldType.__fallback;
Expand Down
4 changes: 2 additions & 2 deletions src/common/helpers/record.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown>[]
recordContents[block!]?.[BFLITE_URIS.TITLE] as unknown as Record<string, unknown>[]
)?.find(obj => Object.hasOwn(obj, uri));

if (selectedTitleContainer) {
Expand All @@ -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) => {
Expand Down
29 changes: 15 additions & 14 deletions src/common/services/recordNormalizing/recordProcessingMap.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { BFLITE_URIS } from '@common/constants/bibframeMapping.constants';
import {
wrapWithContainer,
extractValue,
Expand All @@ -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'),
},
Expand All @@ -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',
),
},
Expand Down

0 comments on commit 510e1ad

Please sign in to comment.