Skip to content

Commit

Permalink
[TLC-674] Update duplicate data service to use searchBy method
Browse files Browse the repository at this point in the history
  • Loading branch information
kshepherd committed Mar 3, 2024
1 parent 1e36a10 commit 1206d61
Showing 1 changed file with 38 additions and 10 deletions.
48 changes: 38 additions & 10 deletions src/app/core/submission/submission-duplicate-data.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable max-classes-per-file */
import { Observable } from 'rxjs';
import { Injectable } from '@angular/core';
import { map } from 'rxjs/operators';
import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
import { ResponseParsingService } from '../data/parsing.service';
import { RemoteData } from '../data/remote-data';
Expand All @@ -18,6 +17,7 @@ import { Duplicate } from '../../shared/object-list/duplicate-data/duplicate.mod
import { PaginatedList } from '../data/paginated-list.model';
import { RequestParam } from '../cache/models/request-param.model';
import { ObjectCacheService } from '../cache/object-cache.service';
import { SearchData, SearchDataImpl } from '../data/base/search-data';


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

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

/**
* SearchData interface to implement
* @private
*/
private searchData: SearchData<Duplicate>;

/**
* Subscription to unsubscribe from
*/
Expand All @@ -54,8 +60,26 @@ export class SubmissionDuplicateDataService extends BaseDataService<Duplicate> {
protected halService: HALEndpointService,
) {
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> {
return this.halService.getEndpoint(this.linkPath);
}
Expand All @@ -74,13 +98,16 @@ export class SubmissionDuplicateDataService extends BaseDataService<Duplicate> {
}
}

private getSearchUrl(): Observable<string> {
const href$ = this.getEndpoint();
return href$.pipe(
map((href) => href + '/search')
);
}

/**
* Find duplicates for a given item UUID. Locates and returns results from the /api/submission/duplicates/search/findByItem
* SearchRestMethod, which is why this implements SearchData<Duplicate> and searchBy
*
* @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>>> {
const searchParams = [new RequestParam('uuid', uuid)];
let findListOptions = new FindListOptions();
Expand All @@ -93,7 +120,8 @@ export class SubmissionDuplicateDataService extends BaseDataService<Duplicate> {
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);
}

/**
Expand Down

0 comments on commit 1206d61

Please sign in to comment.