mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-10 19:43:04 +00:00
Merge remote-tracking branch 'remotes/origin/master' into submission
# Conflicts: # src/app/core/cache/models/normalized-object-factory.ts # src/app/core/cache/response.models.ts # src/app/core/data/registry-metadatafields-response-parsing.service.ts # src/app/core/data/registry-metadataschemas-response-parsing.service.ts # src/app/core/data/request.models.ts # src/app/core/data/request.service.ts # src/app/core/shared/collection.model.ts # src/app/core/shared/dspace-object.model.ts # src/app/core/shared/resource-type.ts
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { Metadatum } from './metadatum.model'
|
||||
import { MetadataMap, MetadataValue, MetadataValueFilter } from './metadata.interfaces';
|
||||
import { Metadata } from './metadata.model';
|
||||
import { isEmpty, isNotEmpty, isUndefined } from '../../shared/empty.util';
|
||||
import { CacheableObject } from '../cache/object-cache.reducer';
|
||||
import { RemoteData } from '../data/remote-data';
|
||||
@@ -37,7 +38,7 @@ export class DSpaceObject implements CacheableObject, ListableObject {
|
||||
* The name for this DSpaceObject
|
||||
*/
|
||||
get name(): string {
|
||||
return (isUndefined(this._name)) ? this.findMetadata('dc.title') : this._name;
|
||||
return (isUndefined(this._name)) ? this.firstMetadataValue('dc.title') : this._name;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -48,10 +49,10 @@ export class DSpaceObject implements CacheableObject, ListableObject {
|
||||
}
|
||||
|
||||
/**
|
||||
* An array containing all metadata of this DSpaceObject
|
||||
* All metadata of this DSpaceObject
|
||||
*/
|
||||
@autoserialize
|
||||
metadata: Metadatum[] = [];
|
||||
metadata: MetadataMap;
|
||||
|
||||
/**
|
||||
* An array of DSpaceObjects that are direct parents of this DSpaceObject
|
||||
@@ -64,41 +65,58 @@ export class DSpaceObject implements CacheableObject, ListableObject {
|
||||
owner: Observable<RemoteData<DSpaceObject>>;
|
||||
|
||||
/**
|
||||
* Find a metadata field by key and language
|
||||
* Gets all matching metadata in this DSpaceObject.
|
||||
*
|
||||
* This method returns the value of the first element
|
||||
* in the metadata array that matches the provided
|
||||
* key and language
|
||||
*
|
||||
* @param key
|
||||
* @param language
|
||||
* @return string
|
||||
* @param {string|string[]} keyOrKeys The metadata key(s) in scope. Wildcards are supported; see [[Metadata]].
|
||||
* @param {MetadataValueFilter} filter The value filter to use. If unspecified, no filtering will be done.
|
||||
* @returns {MetadataValue[]} the matching values or an empty array.
|
||||
*/
|
||||
findMetadata(key: string, language?: string): string {
|
||||
const metadatum = (this.metadata) ? this.metadata.find((m: Metadatum) => {
|
||||
return m.key === key && (isEmpty(language) || m.language === language)
|
||||
}) : null;
|
||||
if (isNotEmpty(metadatum)) {
|
||||
return metadatum.value;
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
allMetadata(keyOrKeys: string | string[], valueFilter?: MetadataValueFilter): MetadataValue[] {
|
||||
return Metadata.all(this.metadata, keyOrKeys, valueFilter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find metadata by an array of keys
|
||||
* Like [[allMetadata]], but only returns string values.
|
||||
*
|
||||
* This method returns the values of the element
|
||||
* in the metadata array that match the provided
|
||||
* key(s)
|
||||
*
|
||||
* @param key(s)
|
||||
* @return Array<Metadatum>
|
||||
* @param {string|string[]} keyOrKeys The metadata key(s) in scope. Wildcards are supported; see [[Metadata]].
|
||||
* @param {MetadataValueFilter} filter The value filter to use. If unspecified, no filtering will be done.
|
||||
* @returns {string[]} the matching string values or an empty array.
|
||||
*/
|
||||
filterMetadata(keys: string[]): Metadatum[] {
|
||||
return (this.metadata || []).filter((metadatum: Metadatum) => {
|
||||
return keys.some((key) => key === metadatum.key);
|
||||
});
|
||||
allMetadataValues(keyOrKeys: string | string[], valueFilter?: MetadataValueFilter): string[] {
|
||||
return Metadata.allValues(this.metadata, keyOrKeys, valueFilter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the first matching MetadataValue object in this DSpaceObject, or `undefined`.
|
||||
*
|
||||
* @param {string|string[]} keyOrKeys The metadata key(s) in scope. Wildcards are supported; see [[Metadata]].
|
||||
* @param {MetadataValueFilter} filter The value filter to use. If unspecified, no filtering will be done.
|
||||
* @returns {MetadataValue} the first matching value, or `undefined`.
|
||||
*/
|
||||
firstMetadata(keyOrKeys: string | string[], valueFilter?: MetadataValueFilter): MetadataValue {
|
||||
return Metadata.first(this.metadata, keyOrKeys, valueFilter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Like [[firstMetadata]], but only returns a string value, or `undefined`.
|
||||
*
|
||||
* @param {string|string[]} keyOrKeys The metadata key(s) in scope. Wildcards are supported; see [[Metadata]].
|
||||
* @param {MetadataValueFilter} filter The value filter to use. If unspecified, no filtering will be done.
|
||||
* @returns {string} the first matching string value, or `undefined`.
|
||||
*/
|
||||
firstMetadataValue(keyOrKeys: string | string[], valueFilter?: MetadataValueFilter): string {
|
||||
return Metadata.firstValue(this.metadata, keyOrKeys, valueFilter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for a matching metadata value in this DSpaceObject.
|
||||
*
|
||||
* @param {string|string[]} keyOrKeys The metadata key(s) in scope. Wildcards are supported; see [[Metadata]].
|
||||
* @param {MetadataValueFilter} filter The value filter to use. If unspecified, no filtering will be done.
|
||||
* @returns {boolean} whether a match is found.
|
||||
*/
|
||||
hasMetadata(keyOrKeys: string | string[], valueFilter?: MetadataValueFilter): boolean {
|
||||
return Metadata.has(this.metadata, keyOrKeys, valueFilter);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user