diff --git a/src/app/core/shared/metadata.utils.spec.ts b/src/app/core/shared/metadata.utils.spec.ts index f4348723001..dcb494d0124 100644 --- a/src/app/core/shared/metadata.utils.spec.ts +++ b/src/app/core/shared/metadata.utils.spec.ts @@ -1,7 +1,7 @@ import { isUndefined } from '../../shared/empty.util'; import { v4 as uuidv4 } from 'uuid'; import { MetadataMap, MetadataValue, MetadataValueFilter, MetadatumViewModel } from './metadata.models'; -import { Metadata } from './metadata.utils'; +import { Metadata, PLACEHOLDER_VALUE } from './metadata.utils'; const mdValue = (value: string, language?: string, authority?: string): MetadataValue => { return Object.assign(new MetadataValue(), { @@ -306,4 +306,21 @@ describe('Metadata', () => { testAllWithLimit(multiMap, 'dc.title', [dcTitle1], 1); }); }); + + describe('Placeholder values', () => { + it('should ignore placeholder values in get methods', () => { + const placeholderMd = mdValue(PLACEHOLDER_VALUE); + const key = 'dc.test.placeholder'; + const map = { 'dc.test.placeholder': [placeholderMd] }; + + expect(Metadata.all(map, key).length).toEqual(0); + expect(Metadata.allValues(map, key).length).toEqual(0); + expect(Metadata.has(map, key)).toBeFalsy(); + expect(Metadata.first(map, key)).toBeUndefined(); + expect(Metadata.firstValue(map, key)).toBeUndefined(); + expect(Metadata.hasValue(placeholderMd)).toBeFalsy(); + expect(Metadata.valueMatches(placeholderMd, null)).toBeFalsy(); + }); + }); + }); diff --git a/src/app/core/shared/metadata.utils.ts b/src/app/core/shared/metadata.utils.ts index ae5f85f582a..e6a73a138d9 100644 --- a/src/app/core/shared/metadata.utils.ts +++ b/src/app/core/shared/metadata.utils.ts @@ -14,6 +14,8 @@ import { validate as uuidValidate } from 'uuid'; export const AUTHORITY_GENERATE = 'will be generated::'; export const AUTHORITY_REFERENCE = 'will be referenced::'; +export const PLACEHOLDER_VALUE = '#PLACEHOLDER_PARENT_METADATA_VALUE#'; + /** * Utility class for working with DSpace object metadata. @@ -29,7 +31,6 @@ export const AUTHORITY_REFERENCE = 'will be referenced::'; * followed by any other (non-dc) metadata values. */ export class Metadata { - /** * Gets all matching metadata in the map(s). * @@ -152,11 +153,11 @@ export class Metadata { * Returns true if this Metadatum's value is defined */ public static hasValue(value: MetadataValue|string): boolean { - if (isEmpty(value)) { + if (isEmpty(value) || value === PLACEHOLDER_VALUE) { return false; } if (isObject(value) && value.hasOwnProperty('value')) { - return isNotEmpty(value.value); + return isNotEmpty(value.value) && value.value !== PLACEHOLDER_VALUE; } return true; } @@ -169,7 +170,9 @@ export class Metadata { * @returns {boolean} whether the filter matches, or true if no filter is given. */ public static valueMatches(mdValue: MetadataValue, filter: MetadataValueFilter) { - if (!filter) { + if (mdValue.value === PLACEHOLDER_VALUE) { + return false; + } else if (!filter) { return true; } else if (filter.language && filter.language !== mdValue.language) { return false;