refactored items, bundles and bitstreams, test builders

This commit is contained in:
Art Lowel
2019-12-11 17:18:08 +01:00
parent 8af72cb1d3
commit ad4e8eeb8c
58 changed files with 746 additions and 340 deletions

View File

@@ -1,19 +1,11 @@
import { map, startWith, filter, switchMap } from 'rxjs/operators';
import { Observable } from 'rxjs';
import { isEmpty } from '../../shared/empty.util';
import { DEFAULT_ENTITY_TYPE } from '../../shared/metadata-representation/metadata-representation.decorator';
import { ListableObject } from '../../shared/object-collection/shared/listable-object.model';
import { DSpaceObject } from './dspace-object.model';
import { Collection } from './collection.model';
import { RemoteData } from '../data/remote-data';
import { Bitstream } from './bitstream.model';
import { hasValueOperator, isNotEmpty, isEmpty } from '../../shared/empty.util';
import { PaginatedList } from '../data/paginated-list';
import { Relationship } from './item-relationships/relationship.model';
import { ResourceType } from './resource-type';
import { getAllSucceededRemoteData, getSucceededRemoteData } from './operators';
import { Bundle } from './bundle.model';
import { GenericConstructor } from './generic-constructor';
import { ListableObject } from '../../shared/object-collection/shared/listable-object.model';
import { DEFAULT_ENTITY_TYPE } from '../../shared/metadata-representation/metadata-representation.decorator';
import { HALLink } from './HALLink.model';
import { ResourceType } from './resource-type';
/**
* Class representing a DSpace Item
@@ -46,77 +38,13 @@ export class Item extends DSpaceObject {
*/
isWithdrawn: boolean;
/**
* An array of Collections that are direct parents of this Item
*/
parents: Observable<RemoteData<Collection[]>>;
/**
* The Collection that owns this Item
*/
owningCollection: Observable<RemoteData<Collection>>;
get owner(): Observable<RemoteData<Collection>> {
return this.owningCollection;
}
/**
* Bitstream bundles within this item
*/
bundles: Observable<RemoteData<PaginatedList<Bundle>>>;
relationships: Observable<RemoteData<PaginatedList<Relationship>>>;
/**
* Retrieves the thumbnail of this item
* @returns {Observable<Bitstream>} the primaryBitstream of the 'THUMBNAIL' bundle
*/
getThumbnail(): Observable<Bitstream> {
// TODO: currently this just picks the first thumbnail
// should be adjusted when we have a way to determine
// the primary thumbnail from rest
return this.getBitstreamsByBundleName('THUMBNAIL').pipe(
filter((thumbnails) => isNotEmpty(thumbnails)),
map((thumbnails) => thumbnails[0]),)
}
/**
* Retrieves the thumbnail for the given original of this item
* @returns {Observable<Bitstream>} the primaryBitstream of the 'THUMBNAIL' bundle
*/
getThumbnailForOriginal(original: Bitstream): Observable<Bitstream> {
return this.getBitstreamsByBundleName('THUMBNAIL').pipe(
map((files) => {
return files.find((thumbnail) => thumbnail.name.startsWith(original.name))
}),startWith(undefined),);
}
/**
* Retrieves all files that should be displayed on the item page of this item
* @returns {Observable<Array<Observable<Bitstream>>>} an array of all Bitstreams in the 'ORIGINAL' bundle
*/
getFiles(): Observable<Bitstream[]> {
return this.getBitstreamsByBundleName('ORIGINAL');
}
/**
* Retrieves bitstreams by bundle name
* @param bundleName The name of the Bundle that should be returned
* @returns {Observable<Bitstream[]>} the bitstreams with the given bundleName
* TODO now that bitstreams can be paginated this should move to the server
* see https://github.com/DSpace/dspace-angular/issues/332
*/
getBitstreamsByBundleName(bundleName: string): Observable<Bitstream[]> {
return this.bundles.pipe(
getSucceededRemoteData(),
map((rd: RemoteData<PaginatedList<Bundle>>) => rd.payload.page.find((bundle: Bundle) => bundle.name === bundleName)),
hasValueOperator(),
switchMap((bundle: Bundle) => bundle.bitstreams),
getAllSucceededRemoteData(),
map((rd: RemoteData<PaginatedList<Bitstream>>) => rd.payload.page),
startWith([])
);
}
_links: {
self: HALLink;
parents: HALLink;
owningCollection: HALLink;
bundles: HALLink;
relationships: HALLink;
};
/**
* Method that returns as which type of object this object should be rendered