FollowLink addition to bitstream/bundle models

This commit is contained in:
jonas-atmire
2020-08-05 11:01:56 +02:00
parent 8b639bc7ba
commit 97ce951bd8
3 changed files with 30 additions and 1 deletions

View File

@@ -6,6 +6,7 @@ import { find } from 'rxjs/operators';
import { hasValue } from '../shared/empty.util';
import { Bitstream } from '../core/shared/bitstream.model';
import { BitstreamDataService } from '../core/data/bitstream-data.service';
import {followLink, FollowLinkConfig} from "../shared/utils/follow-link-config.model";
/**
* This class represents a resolver that requests a specific bitstream before the route is activated
@@ -23,9 +24,19 @@ export class BitstreamPageResolver implements Resolve<RemoteData<Bitstream>> {
* or an error if something went wrong
*/
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<RemoteData<Bitstream>> {
return this.bitstreamService.findById(route.params.id)
return this.bitstreamService.findById(route.params.id, ...this.followLinks)
.pipe(
find((RD) => hasValue(RD.error) || RD.hasSucceeded),
);
}
/**
* Method that returns the follow links to already resolve
* The self links defined in this list are expected to be requested somewhere in the near future
* Requesting them as embeds will limit the number of requests
*/
get followLinks(): Array<FollowLinkConfig<Bitstream>> {
return [
followLink('bundle', undefined, true, followLink('item'))
];
}
}

View File

@@ -8,6 +8,8 @@ import { BITSTREAM } from './bitstream.resource-type';
import { DSpaceObject } from './dspace-object.model';
import { HALLink } from './hal-link.model';
import { HALResource } from './hal-resource.model';
import {BUNDLE} from './bundle.resource-type';
import {Bundle} from './bundle.model';
@typedObject
@inheritSerialization(DSpaceObject)
@@ -57,4 +59,10 @@ export class Bitstream extends DSpaceObject implements HALResource {
@link(BITSTREAM_FORMAT, false, 'format')
format?: Observable<RemoteData<BitstreamFormat>>;
/**
* The owning bundle for this Bitstream
* Will be undefined unless the bundle{@link HALLink} has been resolved.
*/
@link(BUNDLE)
bundle?: Observable<RemoteData<Bundle>>;
}

View File

@@ -10,6 +10,8 @@ import { RemoteData } from '../data/remote-data';
import { PaginatedList } from '../data/paginated-list';
import { BITSTREAM } from './bitstream.resource-type';
import { Bitstream } from './bitstream.model';
import {ITEM} from './item.resource-type';
import {Item} from './item.model';
@typedObject
@inheritSerialization(DSpaceObject)
@@ -24,6 +26,7 @@ export class Bundle extends DSpaceObject {
self: HALLink;
primaryBitstream: HALLink;
bitstreams: HALLink;
item: HALLink;
};
/**
@@ -39,4 +42,11 @@ export class Bundle extends DSpaceObject {
*/
@link(BITSTREAM, true)
bitstreams?: Observable<RemoteData<PaginatedList<Bitstream>>>;
/**
* The owning item for this Bundle
* Will be undefined unless the Item{@link HALLink} has been resolved.
*/
@link(ITEM)
item?: Observable<RemoteData<Item>>;
}