1
0
Files
yel-dspace-angular/src/app/core/shared/dspace-object.model.ts
Giuseppe Digilio ab42f4b190 Merge remote-tracking branch 'remotes/origin/master' into submission
# Conflicts:
#	src/app/+item-page/edit-item-page/item-status/item-status.component.spec.ts
#	src/app/core/cache/builders/remote-data-build.service.ts
#	src/app/core/core.effects.ts
#	src/app/core/core.reducers.ts
#	src/app/core/data/comcol-data.service.spec.ts
#	src/app/core/data/data.service.spec.ts
#	src/app/core/data/data.service.ts
#	src/app/core/shared/dspace-object.model.ts
#	src/app/shared/shared.module.ts
#	src/styles/_custom_variables.scss
2019-03-08 09:52:47 +01:00

127 lines
4.3 KiB
TypeScript

import { Observable } from 'rxjs';
import { MetadataMap, MetadataValue, MetadataValueFilter, MetadatumViewModel } from './metadata.models';
import { Metadata } from './metadata.utils';
import { isUndefined } from '../../shared/empty.util';
import { CacheableObject } from '../cache/object-cache.reducer';
import { RemoteData } from '../data/remote-data';
import { ResourceType } from './resource-type';
import { ListableObject } from '../../shared/object-collection/shared/listable-object.model';
/**
* An abstract model class for a DSpaceObject.
*/
export class DSpaceObject implements CacheableObject, ListableObject {
private _name: string;
self: string;
/**
* The human-readable identifier of this DSpaceObject
*/
id: string;
/**
* The universally unique identifier of this DSpaceObject
*/
uuid: string;
/**
* A string representing the kind of DSpaceObject, e.g. community, item, …
*/
type: ResourceType;
/**
* The name for this DSpaceObject
*/
get name(): string {
return (isUndefined(this._name)) ? this.firstMetadataValue('dc.title') : this._name;
}
/**
* The name for this DSpaceObject
*/
set name(name) {
this._name = name;
}
/**
* All metadata of this DSpaceObject
*/
metadata: MetadataMap;
/**
* Retrieve the current metadata as a list of MetadatumViewModels
*/
get metadataAsList(): MetadatumViewModel[] {
return Metadata.toViewModelList(this.metadata);
}
/**
* An array of DSpaceObjects that are direct parents of this DSpaceObject
*/
parents: Observable<RemoteData<DSpaceObject[]>>;
/**
* The DSpaceObject that owns this DSpaceObject
*/
owner: Observable<RemoteData<DSpaceObject>>;
/**
* Gets all matching metadata 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 {MetadataValue[]} the matching values or an empty array.
*/
allMetadata(keyOrKeys: string | string[], valueFilter?: MetadataValueFilter): MetadataValue[] {
return Metadata.all(this.metadata, keyOrKeys, valueFilter);
}
/**
* Like [[allMetadata]], but only returns string values.
*
* @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.
*/
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);
}
}