Skip to content

Commit

Permalink
Merged in task/dspace-cris-2023_02_x/DSC-2140 (pull request DSpace#2689)
Browse files Browse the repository at this point in the history
Task/dspace cris 2023 02 x/DSC-2140

Approved-by: Francesco Molinaro
  • Loading branch information
Andrea Barbasso authored and FrancescoMolinaro committed Jan 13, 2025
2 parents 867f416 + 3c08054 commit 02e29eb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
19 changes: 18 additions & 1 deletion src/app/core/shared/metadata.utils.spec.ts
Original file line number Diff line number Diff line change
@@ -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(), {
Expand Down Expand Up @@ -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();
});
});

});
11 changes: 7 additions & 4 deletions src/app/core/shared/metadata.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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).
*
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down

0 comments on commit 02e29eb

Please sign in to comment.