Skip to content

Commit 1206d61

Browse files
committed
[TLC-674] Update duplicate data service to use searchBy method
1 parent 1e36a10 commit 1206d61

1 file changed

Lines changed: 38 additions & 10 deletions

File tree

src/app/core/submission/submission-duplicate-data.service.ts

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* eslint-disable max-classes-per-file */
22
import { Observable } from 'rxjs';
33
import { Injectable } from '@angular/core';
4-
import { map } from 'rxjs/operators';
54
import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
65
import { ResponseParsingService } from '../data/parsing.service';
76
import { RemoteData } from '../data/remote-data';
@@ -18,6 +17,7 @@ import { Duplicate } from '../../shared/object-list/duplicate-data/duplicate.mod
1817
import { PaginatedList } from '../data/paginated-list.model';
1918
import { RequestParam } from '../cache/models/request-param.model';
2019
import { ObjectCacheService } from '../cache/object-cache.service';
20+
import { SearchData, SearchDataImpl } from '../data/base/search-data';
2121

2222

2323
/**
@@ -30,7 +30,7 @@ import { ObjectCacheService } from '../cache/object-cache.service';
3030
*
3131
*/
3232
@Injectable()
33-
export class SubmissionDuplicateDataService extends BaseDataService<Duplicate> {
33+
export class SubmissionDuplicateDataService extends BaseDataService<Duplicate> implements SearchData<Duplicate> {
3434

3535
/**
3636
* The ResponseParsingService constructor name
@@ -42,6 +42,12 @@ export class SubmissionDuplicateDataService extends BaseDataService<Duplicate> {
4242
*/
4343
private request: GenericConstructor<RestRequest> = GetRequest;
4444

45+
/**
46+
* SearchData interface to implement
47+
* @private
48+
*/
49+
private searchData: SearchData<Duplicate>;
50+
4551
/**
4652
* Subscription to unsubscribe from
4753
*/
@@ -54,8 +60,26 @@ export class SubmissionDuplicateDataService extends BaseDataService<Duplicate> {
5460
protected halService: HALEndpointService,
5561
) {
5662
super('duplicates', requestService, rdbService, objectCache, halService);
63+
this.searchData = new SearchDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.responseMsToLive);
64+
}
65+
66+
/**
67+
* Implement the searchBy method to return paginated lists of Duplicate resources
68+
*
69+
* @param searchMethod the search method name
70+
* @param options find list options
71+
* @param useCachedVersionIfAvailable whether to use cached version if available
72+
* @param reRequestOnStale whether to rerequest results on stale
73+
* @param linksToFollow links to follow in results
74+
*/
75+
searchBy(searchMethod: string, options?: FindListOptions, useCachedVersionIfAvailable?: boolean, reRequestOnStale?: boolean, ...linksToFollow: FollowLinkConfig<Duplicate>[]): Observable<RemoteData<PaginatedList<Duplicate>>> {
76+
return this.searchData.searchBy(searchMethod, options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
5777
}
5878

79+
/**
80+
* Helper method to get the duplicates endpoint
81+
* @protected
82+
*/
5983
protected getEndpoint(): Observable<string> {
6084
return this.halService.getEndpoint(this.linkPath);
6185
}
@@ -74,13 +98,16 @@ export class SubmissionDuplicateDataService extends BaseDataService<Duplicate> {
7498
}
7599
}
76100

77-
private getSearchUrl(): Observable<string> {
78-
const href$ = this.getEndpoint();
79-
return href$.pipe(
80-
map((href) => href + '/search')
81-
);
82-
}
83-
101+
/**
102+
* Find duplicates for a given item UUID. Locates and returns results from the /api/submission/duplicates/search/findByItem
103+
* SearchRestMethod, which is why this implements SearchData<Duplicate> and searchBy
104+
*
105+
* @param uuid the item UUID
106+
* @param options any find list options e.g. paging
107+
* @param useCachedVersionIfAvailable whether to use cached version if available
108+
* @param reRequestOnStale whether to rerequest results on stale
109+
* @param linksToFollow links to follow in results
110+
*/
84111
public findDuplicates(uuid: string, options?: FindListOptions, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Duplicate>[]): Observable<RemoteData<PaginatedList<Duplicate>>> {
85112
const searchParams = [new RequestParam('uuid', uuid)];
86113
let findListOptions = new FindListOptions();
@@ -93,7 +120,8 @@ export class SubmissionDuplicateDataService extends BaseDataService<Duplicate> {
93120
findListOptions.searchParams = searchParams;
94121
}
95122

96-
return this.findListByHref(this.getSearchUrl(), findListOptions, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
123+
// Perform the actual search by search
124+
return this.searchBy('findByItem', findListOptions, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
97125
}
98126

99127
/**

0 commit comments

Comments
 (0)