mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00

* [DURACOM-304] Refactored item-bitstreams.component by removing page size of 9999 * [DURACOM-304] Refactored edit-bitstream-page.component by removing page size of 9999 * [DURACOM-304] Refactored scripts-select.component by using infinite scroll instead of page size 9999 * [DURACOM-304] Refactored dynamic-list.component.ts by removing page size of 9999 * [DURACOM-304] Refactored relationship-type-data.service.ts by removing page size of 9999 * [DURACOM-304] removed unneeded selectAll method (dynamic-lookup-relation-search-tab.component) * [DURACOM-304] Refactored submission-section-cc-licenses.component.ts by removing page size of 9999 * [DURACOM-304] lint fix * [DURACOM-304] test fix * [DURACOM-304] fix accessibility issue on scripts-select * [DURACOM-304] Refactor of bundle-data.service.ts by removing page size of 9999 * [DURACOM-304] other fix related to accessibility * [DURACOM-304] lint fix * [DURACOM-304] resolve conflicts * [DURACOM-304] fix lint * [DURACOM-304] add support for findAll method in dynamic-scrollable-dropdown.component.ts * [DURACOM-304] refactor to use lazy data provider * [DURACOM-304] improve loading logic for cc-licenses section and dynamic-list * [DURACOM-304] refactor, fix dynamic-list.component loading * [DURACOM-304] remove br --------- Co-authored-by: Alisa Ismailati <alisa.ismailati@4science.com>
186 lines
8.1 KiB
TypeScript
186 lines
8.1 KiB
TypeScript
import { Injectable } from '@angular/core';
|
|
import { Operation } from 'fast-json-patch';
|
|
import { Observable } from 'rxjs';
|
|
import {
|
|
map,
|
|
switchMap,
|
|
take,
|
|
} from 'rxjs/operators';
|
|
|
|
import { hasValue } from '../../shared/empty.util';
|
|
import { PaginatedSearchOptions } from '../../shared/search/models/paginated-search-options.model';
|
|
import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
|
|
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
|
|
import { ObjectCacheService } from '../cache/object-cache.service';
|
|
import { Bitstream } from '../shared/bitstream.model';
|
|
import { Bundle } from '../shared/bundle.model';
|
|
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
|
import { Item } from '../shared/item.model';
|
|
import { IdentifiableDataService } from './base/identifiable-data.service';
|
|
import {
|
|
PatchData,
|
|
PatchDataImpl,
|
|
} from './base/patch-data';
|
|
import { DSOChangeAnalyzer } from './dso-change-analyzer.service';
|
|
import { FindListOptions } from './find-list-options.model';
|
|
import { PaginatedList } from './paginated-list.model';
|
|
import { RemoteData } from './remote-data';
|
|
import { GetRequest } from './request.models';
|
|
import { RequestService } from './request.service';
|
|
import { RequestEntryState } from './request-entry-state.model';
|
|
import { RestRequestMethod } from './rest-request-method';
|
|
|
|
/**
|
|
* A service to retrieve {@link Bundle}s from the REST API
|
|
*/
|
|
@Injectable({ providedIn: 'root' })
|
|
export class BundleDataService extends IdentifiableDataService<Bundle> implements PatchData<Bundle> {
|
|
private bitstreamsEndpoint = 'bitstreams';
|
|
|
|
private patchData: PatchDataImpl<Bundle>;
|
|
|
|
constructor(
|
|
protected requestService: RequestService,
|
|
protected rdbService: RemoteDataBuildService,
|
|
protected objectCache: ObjectCacheService,
|
|
protected halService: HALEndpointService,
|
|
protected comparator: DSOChangeAnalyzer<Bundle>,
|
|
) {
|
|
super('bundles', requestService, rdbService, objectCache, halService);
|
|
|
|
this.patchData = new PatchDataImpl<Bundle>(this.linkPath, requestService, rdbService, objectCache, halService, comparator, this.responseMsToLive, this.constructIdEndpoint);
|
|
}
|
|
|
|
/**
|
|
* Retrieve all {@link Bundle}s in the given {@link Item}
|
|
*
|
|
* @param item the {@link Item} the {@link Bundle}s are a part of
|
|
* @param options the {@link FindListOptions} for the request
|
|
* @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's
|
|
* no valid cached version. Defaults to true
|
|
* @param reRequestOnStale Whether or not the request should automatically be re-
|
|
* requested after the response becomes stale
|
|
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
|
|
* {@link HALLink}s should be automatically resolved
|
|
*/
|
|
findAllByItem(item: Item, options?: FindListOptions, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Bundle>[]): Observable<RemoteData<PaginatedList<Bundle>>> {
|
|
return this.findListByHref(item._links.bundles.href, options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
|
|
}
|
|
|
|
/**
|
|
* Retrieve a {@link Bundle} in the given {@link Item} by name
|
|
*
|
|
* @param item the {@link Item} the {@link Bundle}s are a part of
|
|
* @param bundleName the name of the {@link Bundle} to retrieve
|
|
* @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's
|
|
* no valid cached version. Defaults to true
|
|
* @param reRequestOnStale Whether or not the request should automatically be re-
|
|
* requested after the response becomes stale
|
|
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which
|
|
* {@link HALLink}s should be automatically resolved
|
|
* @param options the {@link FindListOptions} for the request
|
|
*/
|
|
// TODO should be implemented rest side
|
|
findByItemAndName(item: Item, bundleName: string, useCachedVersionIfAvailable = true, reRequestOnStale = true, options?: FindListOptions, ...linksToFollow: FollowLinkConfig<Bundle>[]): Observable<RemoteData<Bundle>> {
|
|
//Since we filter by bundleName where the pagination options are not indicated we need to load all the possible bundles.
|
|
// This is a workaround, in substitution of the previously recursive call with expand
|
|
const paginationOptions = options ?? { elementsPerPage: 9999 };
|
|
return this.findAllByItem(item, paginationOptions, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow).pipe(
|
|
map((rd: RemoteData<PaginatedList<Bundle>>) => {
|
|
if (hasValue(rd.payload) && hasValue(rd.payload.page)) {
|
|
const matchingBundle = rd.payload.page.find((bundle: Bundle) =>
|
|
bundle.name === bundleName);
|
|
if (hasValue(matchingBundle)) {
|
|
return new RemoteData(
|
|
rd.timeCompleted,
|
|
rd.msToLive,
|
|
rd.lastUpdated,
|
|
RequestEntryState.Success,
|
|
null,
|
|
matchingBundle,
|
|
200,
|
|
);
|
|
} else {
|
|
return new RemoteData(
|
|
rd.timeCompleted,
|
|
rd.msToLive,
|
|
rd.lastUpdated,
|
|
RequestEntryState.Error,
|
|
`The bundle with name ${bundleName} was not found.`,
|
|
null,
|
|
404,
|
|
);
|
|
}
|
|
} else {
|
|
return rd as any;
|
|
}
|
|
}),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Get the bitstreams endpoint for a bundle
|
|
* @param bundleId
|
|
* @param searchOptions
|
|
*/
|
|
getBitstreamsEndpoint(bundleId: string, searchOptions?: PaginatedSearchOptions): Observable<string> {
|
|
return this.getBrowseEndpoint().pipe(
|
|
switchMap((href: string) => this.halService.getEndpoint(this.bitstreamsEndpoint, `${href}/${bundleId}`)),
|
|
map((href) => searchOptions ? searchOptions.toRestUrl(href) : href),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Get a bundle's bitstreams using paginated search options
|
|
* @param bundleId The bundle's ID
|
|
* @param searchOptions The search options to use
|
|
* @param linksToFollow The {@link FollowLinkConfig}s for the request
|
|
*/
|
|
getBitstreams(bundleId: string, searchOptions?: PaginatedSearchOptions, ...linksToFollow: FollowLinkConfig<Bitstream>[]): Observable<RemoteData<PaginatedList<Bitstream>>> {
|
|
const hrefObs = this.getBitstreamsEndpoint(bundleId, searchOptions);
|
|
|
|
hrefObs.pipe(
|
|
take(1),
|
|
).subscribe((href) => {
|
|
const request = new GetRequest(this.requestService.generateRequestId(), href);
|
|
this.requestService.send(request, true);
|
|
});
|
|
|
|
return this.rdbService.buildList<Bitstream>(hrefObs, ...linksToFollow);
|
|
}
|
|
|
|
/**
|
|
* Commit current object changes to the server
|
|
* @param method The RestRequestMethod for which de server sync buffer should be committed
|
|
*/
|
|
public commitUpdates(method?: RestRequestMethod): void {
|
|
this.patchData.commitUpdates(method);
|
|
}
|
|
|
|
/**
|
|
* Send a patch request for a specified object
|
|
* @param {T} object The object to send a patch request for
|
|
* @param {Operation[]} operations The patch operations to be performed
|
|
*/
|
|
public patch(object: Bundle, operations: Operation[]): Observable<RemoteData<Bundle>> {
|
|
return this.patchData.patch(object, operations);
|
|
}
|
|
|
|
/**
|
|
* Add a new patch to the object cache
|
|
* The patch is derived from the differences between the given object and its version in the object cache
|
|
* @param {DSpaceObject} object The given object
|
|
*/
|
|
public update(object: Bundle): Observable<RemoteData<Bundle>> {
|
|
return this.patchData.update(object);
|
|
}
|
|
|
|
/**
|
|
* Return a list of operations representing the difference between an object and its latest value in the cache.
|
|
* @param object the object to resolve to a list of patch operations
|
|
*/
|
|
public createPatchFromCache(object: Bundle): Observable<Operation[]> {
|
|
return this.patchData.createPatchFromCache(object);
|
|
}
|
|
}
|