Added mocks for all model types, added CollectionDataService

This commit is contained in:
Art Lowel
2017-02-14 14:40:57 +01:00
parent c3214595ef
commit c8fb98760d
30 changed files with 1129 additions and 162 deletions

View File

@@ -0,0 +1,67 @@
import { autoserialize, autoserializeAs } from "cerialize";
import { Metadatum } from "./metadatum.model"
import { isEmpty, isNotEmpty } from "../../shared/empty.util";
/**
* An abstract model class for a DSpaceObject.
*/
export abstract class DSpaceObject {
/**
* The identifier of this DSpaceObject
*/
@autoserialize
id: string;
/**
* A string representing the kind of DSpaceObject, e.g. community, item, …
*/
type: string;
/**
* The name for this DSpaceObject
*/
@autoserialize
name: string;
/**
* An array containing all metadata of this DSpaceObject
*/
@autoserializeAs(Metadatum)
metadata: Array<Metadatum>;
/**
* An array of DSpaceObjects that are direct parents of this DSpaceObject
*/
parents: Array<DSpaceObject>;
/**
* The DSpaceObject that owns this DSpaceObject
*/
owner: DSpaceObject;
/**
* Find a metadata field by key and language
*
* 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
*/
findMetadata(key: string, language?: string): string {
const metadatum = this.metadata
.find((metadatum: Metadatum) => {
return metadatum.key === key &&
(isEmpty(language) || metadatum.language === language)
});
if (isNotEmpty(metadatum)) {
return metadatum.value;
}
else {
return undefined;
}
}
}