Skip to content

Commit 02e29eb

Browse files
Andrea BarbassoFrancescoMolinaro
authored andcommitted
Merged in task/dspace-cris-2023_02_x/DSC-2140 (pull request DSpace#2689)
Task/dspace cris 2023 02 x/DSC-2140 Approved-by: Francesco Molinaro
2 parents 867f416 + 3c08054 commit 02e29eb

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

src/app/core/shared/metadata.utils.spec.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { isUndefined } from '../../shared/empty.util';
22
import { v4 as uuidv4 } from 'uuid';
33
import { MetadataMap, MetadataValue, MetadataValueFilter, MetadatumViewModel } from './metadata.models';
4-
import { Metadata } from './metadata.utils';
4+
import { Metadata, PLACEHOLDER_VALUE } from './metadata.utils';
55

66
const mdValue = (value: string, language?: string, authority?: string): MetadataValue => {
77
return Object.assign(new MetadataValue(), {
@@ -306,4 +306,21 @@ describe('Metadata', () => {
306306
testAllWithLimit(multiMap, 'dc.title', [dcTitle1], 1);
307307
});
308308
});
309+
310+
describe('Placeholder values', () => {
311+
it('should ignore placeholder values in get methods', () => {
312+
const placeholderMd = mdValue(PLACEHOLDER_VALUE);
313+
const key = 'dc.test.placeholder';
314+
const map = { 'dc.test.placeholder': [placeholderMd] };
315+
316+
expect(Metadata.all(map, key).length).toEqual(0);
317+
expect(Metadata.allValues(map, key).length).toEqual(0);
318+
expect(Metadata.has(map, key)).toBeFalsy();
319+
expect(Metadata.first(map, key)).toBeUndefined();
320+
expect(Metadata.firstValue(map, key)).toBeUndefined();
321+
expect(Metadata.hasValue(placeholderMd)).toBeFalsy();
322+
expect(Metadata.valueMatches(placeholderMd, null)).toBeFalsy();
323+
});
324+
});
325+
309326
});

src/app/core/shared/metadata.utils.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { validate as uuidValidate } from 'uuid';
1414

1515
export const AUTHORITY_GENERATE = 'will be generated::';
1616
export const AUTHORITY_REFERENCE = 'will be referenced::';
17+
export const PLACEHOLDER_VALUE = '#PLACEHOLDER_PARENT_METADATA_VALUE#';
18+
1719

1820
/**
1921
* Utility class for working with DSpace object metadata.
@@ -29,7 +31,6 @@ export const AUTHORITY_REFERENCE = 'will be referenced::';
2931
* followed by any other (non-dc) metadata values.
3032
*/
3133
export class Metadata {
32-
3334
/**
3435
* Gets all matching metadata in the map(s).
3536
*
@@ -152,11 +153,11 @@ export class Metadata {
152153
* Returns true if this Metadatum's value is defined
153154
*/
154155
public static hasValue(value: MetadataValue|string): boolean {
155-
if (isEmpty(value)) {
156+
if (isEmpty(value) || value === PLACEHOLDER_VALUE) {
156157
return false;
157158
}
158159
if (isObject(value) && value.hasOwnProperty('value')) {
159-
return isNotEmpty(value.value);
160+
return isNotEmpty(value.value) && value.value !== PLACEHOLDER_VALUE;
160161
}
161162
return true;
162163
}
@@ -169,7 +170,9 @@ export class Metadata {
169170
* @returns {boolean} whether the filter matches, or true if no filter is given.
170171
*/
171172
public static valueMatches(mdValue: MetadataValue, filter: MetadataValueFilter) {
172-
if (!filter) {
173+
if (mdValue.value === PLACEHOLDER_VALUE) {
174+
return false;
175+
} else if (!filter) {
173176
return true;
174177
} else if (filter.language && filter.language !== mdValue.language) {
175178
return false;

0 commit comments

Comments
 (0)