|
| 1 | +/* eslint-disable max-classes-per-file */ |
| 2 | +import { Observable } from 'rxjs'; |
| 3 | +import { Injectable } from '@angular/core'; |
| 4 | +import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model'; |
| 5 | +import { ResponseParsingService } from '../data/parsing.service'; |
| 6 | +import { RemoteData } from '../data/remote-data'; |
| 7 | +import { GetRequest } from '../data/request.models'; |
| 8 | +import { RequestService } from '../data/request.service'; |
| 9 | +import { GenericConstructor } from '../shared/generic-constructor'; |
| 10 | +import { HALEndpointService } from '../shared/hal-endpoint.service'; |
| 11 | +import { SearchResponseParsingService } from '../data/search-response-parsing.service'; |
| 12 | +import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; |
| 13 | +import { RestRequest } from '../data/rest-request.model'; |
| 14 | +import { BaseDataService } from '../data/base/base-data.service'; |
| 15 | +import { FindListOptions } from '../data/find-list-options.model'; |
| 16 | +import { Duplicate } from '../../shared/object-list/duplicate-data/duplicate.model'; |
| 17 | +import { PaginatedList } from '../data/paginated-list.model'; |
| 18 | +import { RequestParam } from '../cache/models/request-param.model'; |
| 19 | +import { ObjectCacheService } from '../cache/object-cache.service'; |
| 20 | +import { SearchData, SearchDataImpl } from '../data/base/search-data'; |
| 21 | +import { DUPLICATE } from '../../shared/object-list/duplicate-data/duplicate.resource-type'; |
| 22 | +import { dataService } from '../data/base/data-service.decorator'; |
| 23 | + |
| 24 | + |
| 25 | +/** |
| 26 | + * Service that handles search requests for potential duplicate items. |
| 27 | + * This uses the /api/submission/duplicates endpoint to look for other archived or in-progress items (if user |
| 28 | + * has READ permission) that match the item (for the given uuid). |
| 29 | + * Matching is configured in the backend in dspace/config/modulesduplicate-detection.cfg |
| 30 | + * The returned results are small preview 'stubs' of items, and displayed in either a submission section |
| 31 | + * or the workflow pooled/claimed task page. |
| 32 | + * |
| 33 | + */ |
| 34 | +@Injectable() |
| 35 | +@dataService(DUPLICATE) |
| 36 | +export class SubmissionDuplicateDataService extends BaseDataService<Duplicate> implements SearchData<Duplicate> { |
| 37 | + |
| 38 | + /** |
| 39 | + * The ResponseParsingService constructor name |
| 40 | + */ |
| 41 | + private parser: GenericConstructor<ResponseParsingService> = SearchResponseParsingService; |
| 42 | + |
| 43 | + /** |
| 44 | + * The RestRequest constructor name |
| 45 | + */ |
| 46 | + private request: GenericConstructor<RestRequest> = GetRequest; |
| 47 | + |
| 48 | + /** |
| 49 | + * SearchData interface to implement |
| 50 | + * @private |
| 51 | + */ |
| 52 | + private searchData: SearchData<Duplicate>; |
| 53 | + |
| 54 | + /** |
| 55 | + * Subscription to unsubscribe from |
| 56 | + */ |
| 57 | + private sub; |
| 58 | + |
| 59 | + constructor( |
| 60 | + protected requestService: RequestService, |
| 61 | + protected rdbService: RemoteDataBuildService, |
| 62 | + protected objectCache: ObjectCacheService, |
| 63 | + protected halService: HALEndpointService, |
| 64 | + ) { |
| 65 | + super('duplicates', requestService, rdbService, objectCache, halService); |
| 66 | + this.searchData = new SearchDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.responseMsToLive); |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * Implement the searchBy method to return paginated lists of Duplicate resources |
| 71 | + * |
| 72 | + * @param searchMethod the search method name |
| 73 | + * @param options find list options |
| 74 | + * @param useCachedVersionIfAvailable whether to use cached version if available |
| 75 | + * @param reRequestOnStale whether to rerequest results on stale |
| 76 | + * @param linksToFollow links to follow in results |
| 77 | + */ |
| 78 | + searchBy(searchMethod: string, options?: FindListOptions, useCachedVersionIfAvailable?: boolean, reRequestOnStale?: boolean, ...linksToFollow: FollowLinkConfig<Duplicate>[]): Observable<RemoteData<PaginatedList<Duplicate>>> { |
| 79 | + return this.searchData.searchBy(searchMethod, options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow); |
| 80 | + } |
| 81 | + |
| 82 | + /** |
| 83 | + * Helper method to get the duplicates endpoint |
| 84 | + * @protected |
| 85 | + */ |
| 86 | + protected getEndpoint(): Observable<string> { |
| 87 | + return this.halService.getEndpoint(this.linkPath); |
| 88 | + } |
| 89 | + |
| 90 | + /** |
| 91 | + * Method to set service options |
| 92 | + * @param {GenericConstructor<ResponseParsingService>} parser The ResponseParsingService constructor name |
| 93 | + * @param {boolean} request The RestRequest constructor name |
| 94 | + */ |
| 95 | + setServiceOptions(parser: GenericConstructor<ResponseParsingService>, request: GenericConstructor<RestRequest>) { |
| 96 | + if (parser) { |
| 97 | + this.parser = parser; |
| 98 | + } |
| 99 | + if (request) { |
| 100 | + this.request = request; |
| 101 | + } |
| 102 | + } |
| 103 | + |
| 104 | + /** |
| 105 | + * Find duplicates for a given item UUID. Locates and returns results from the /api/submission/duplicates/search/findByItem |
| 106 | + * SearchRestMethod, which is why this implements SearchData<Duplicate> and searchBy |
| 107 | + * |
| 108 | + * @param uuid the item UUID |
| 109 | + * @param options any find list options e.g. paging |
| 110 | + * @param useCachedVersionIfAvailable whether to use cached version if available |
| 111 | + * @param reRequestOnStale whether to rerequest results on stale |
| 112 | + * @param linksToFollow links to follow in results |
| 113 | + */ |
| 114 | + public findDuplicates(uuid: string, options?: FindListOptions, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Duplicate>[]): Observable<RemoteData<PaginatedList<Duplicate>>> { |
| 115 | + const searchParams = [new RequestParam('uuid', uuid)]; |
| 116 | + let findListOptions = new FindListOptions(); |
| 117 | + if (options) { |
| 118 | + findListOptions = Object.assign(new FindListOptions(), options); |
| 119 | + } |
| 120 | + if (findListOptions.searchParams) { |
| 121 | + findListOptions.searchParams = [...findListOptions.searchParams, ...searchParams]; |
| 122 | + } else { |
| 123 | + findListOptions.searchParams = searchParams; |
| 124 | + } |
| 125 | + |
| 126 | + // Return actual search/findByItem results |
| 127 | + return this.searchBy('findByItem', findListOptions, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow); |
| 128 | + |
| 129 | + } |
| 130 | + |
| 131 | + /** |
| 132 | + * Unsubscribe from the subscription |
| 133 | + */ |
| 134 | + ngOnDestroy(): void { |
| 135 | + if (this.sub !== undefined) { |
| 136 | + this.sub.unsubscribe(); |
| 137 | + } |
| 138 | + } |
| 139 | +} |
0 commit comments