mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
[TLC-674] Update duplicate data service to use searchBy method
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
/* eslint-disable max-classes-per-file */
|
/* eslint-disable max-classes-per-file */
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { map } from 'rxjs/operators';
|
|
||||||
import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
|
import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
|
||||||
import { ResponseParsingService } from '../data/parsing.service';
|
import { ResponseParsingService } from '../data/parsing.service';
|
||||||
import { RemoteData } from '../data/remote-data';
|
import { RemoteData } from '../data/remote-data';
|
||||||
@@ -18,6 +17,7 @@ import { Duplicate } from '../../shared/object-list/duplicate-data/duplicate.mod
|
|||||||
import { PaginatedList } from '../data/paginated-list.model';
|
import { PaginatedList } from '../data/paginated-list.model';
|
||||||
import { RequestParam } from '../cache/models/request-param.model';
|
import { RequestParam } from '../cache/models/request-param.model';
|
||||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||||
|
import { SearchData, SearchDataImpl } from '../data/base/search-data';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -30,7 +30,7 @@ import { ObjectCacheService } from '../cache/object-cache.service';
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SubmissionDuplicateDataService extends BaseDataService<Duplicate> {
|
export class SubmissionDuplicateDataService extends BaseDataService<Duplicate> implements SearchData<Duplicate> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The ResponseParsingService constructor name
|
* The ResponseParsingService constructor name
|
||||||
@@ -42,6 +42,12 @@ export class SubmissionDuplicateDataService extends BaseDataService<Duplicate> {
|
|||||||
*/
|
*/
|
||||||
private request: GenericConstructor<RestRequest> = GetRequest;
|
private request: GenericConstructor<RestRequest> = GetRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SearchData interface to implement
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
private searchData: SearchData<Duplicate>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subscription to unsubscribe from
|
* Subscription to unsubscribe from
|
||||||
*/
|
*/
|
||||||
@@ -54,8 +60,26 @@ export class SubmissionDuplicateDataService extends BaseDataService<Duplicate> {
|
|||||||
protected halService: HALEndpointService,
|
protected halService: HALEndpointService,
|
||||||
) {
|
) {
|
||||||
super('duplicates', requestService, rdbService, objectCache, halService);
|
super('duplicates', requestService, rdbService, objectCache, halService);
|
||||||
|
this.searchData = new SearchDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.responseMsToLive);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implement the searchBy method to return paginated lists of Duplicate resources
|
||||||
|
*
|
||||||
|
* @param searchMethod the search method name
|
||||||
|
* @param options find list options
|
||||||
|
* @param useCachedVersionIfAvailable whether to use cached version if available
|
||||||
|
* @param reRequestOnStale whether to rerequest results on stale
|
||||||
|
* @param linksToFollow links to follow in results
|
||||||
|
*/
|
||||||
|
searchBy(searchMethod: string, options?: FindListOptions, useCachedVersionIfAvailable?: boolean, reRequestOnStale?: boolean, ...linksToFollow: FollowLinkConfig<Duplicate>[]): Observable<RemoteData<PaginatedList<Duplicate>>> {
|
||||||
|
return this.searchData.searchBy(searchMethod, options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to get the duplicates endpoint
|
||||||
|
* @protected
|
||||||
|
*/
|
||||||
protected getEndpoint(): Observable<string> {
|
protected getEndpoint(): Observable<string> {
|
||||||
return this.halService.getEndpoint(this.linkPath);
|
return this.halService.getEndpoint(this.linkPath);
|
||||||
}
|
}
|
||||||
@@ -74,13 +98,16 @@ export class SubmissionDuplicateDataService extends BaseDataService<Duplicate> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private getSearchUrl(): Observable<string> {
|
/**
|
||||||
const href$ = this.getEndpoint();
|
* Find duplicates for a given item UUID. Locates and returns results from the /api/submission/duplicates/search/findByItem
|
||||||
return href$.pipe(
|
* SearchRestMethod, which is why this implements SearchData<Duplicate> and searchBy
|
||||||
map((href) => href + '/search')
|
*
|
||||||
);
|
* @param uuid the item UUID
|
||||||
}
|
* @param options any find list options e.g. paging
|
||||||
|
* @param useCachedVersionIfAvailable whether to use cached version if available
|
||||||
|
* @param reRequestOnStale whether to rerequest results on stale
|
||||||
|
* @param linksToFollow links to follow in results
|
||||||
|
*/
|
||||||
public findDuplicates(uuid: string, options?: FindListOptions, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Duplicate>[]): Observable<RemoteData<PaginatedList<Duplicate>>> {
|
public findDuplicates(uuid: string, options?: FindListOptions, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Duplicate>[]): Observable<RemoteData<PaginatedList<Duplicate>>> {
|
||||||
const searchParams = [new RequestParam('uuid', uuid)];
|
const searchParams = [new RequestParam('uuid', uuid)];
|
||||||
let findListOptions = new FindListOptions();
|
let findListOptions = new FindListOptions();
|
||||||
@@ -93,7 +120,8 @@ export class SubmissionDuplicateDataService extends BaseDataService<Duplicate> {
|
|||||||
findListOptions.searchParams = searchParams;
|
findListOptions.searchParams = searchParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.findListByHref(this.getSearchUrl(), findListOptions, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
|
// Perform the actual search by search
|
||||||
|
return this.searchBy('findByItem', findListOptions, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user