mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-12 12:33:07 +00:00
[TLC-674] Refactor Basic Duplicate detection endpoint / data service
This commit is contained in:
@@ -198,6 +198,7 @@ import { NotifyRequestsStatus } from '../item-page/simple/notify-requests-status
|
||||
import { LdnService } from '../admin/admin-ldn-services/ldn-services-model/ldn-services.model';
|
||||
import { Itemfilter } from '../admin/admin-ldn-services/ldn-services-model/ldn-service-itemfilters';
|
||||
import { SubmissionCoarNotifyConfig } from '../submission/sections/section-coar-notify/submission-coar-notify.config';
|
||||
import { DuplicateDataService } from './data/duplicate-search.service';
|
||||
|
||||
/**
|
||||
* When not in production, endpoint responses can be mocked for testing purposes
|
||||
@@ -234,6 +235,7 @@ const PROVIDERS = [
|
||||
HALEndpointService,
|
||||
HostWindowService,
|
||||
ItemDataService,
|
||||
DuplicateDataService,
|
||||
MetadataService,
|
||||
ObjectCacheService,
|
||||
PaginationComponentOptions,
|
||||
|
101
src/app/core/data/duplicate-search.service.ts
Normal file
101
src/app/core/data/duplicate-search.service.ts
Normal file
@@ -0,0 +1,101 @@
|
||||
/* 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 './parsing.service';
|
||||
import { RemoteData } from './remote-data';
|
||||
import { GetRequest } from './request.models';
|
||||
import { RequestService } from './request.service';
|
||||
import { GenericConstructor } from '../shared/generic-constructor';
|
||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||
import { SearchResponseParsingService } from './search-response-parsing.service';
|
||||
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
|
||||
import { RestRequest } from './rest-request.model';
|
||||
import { BaseDataService } from './base/base-data.service';
|
||||
import { FindListOptions } from './find-list-options.model';
|
||||
import { Duplicate } from '../../shared/object-list/duplicate-data/duplicate.model';
|
||||
import { PaginatedList } from './paginated-list.model';
|
||||
import { RequestParam } from '../cache/models/request-param.model';
|
||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||
|
||||
|
||||
/**
|
||||
* Service that performs all general actions that have to do with the search page
|
||||
*/
|
||||
@Injectable()
|
||||
export class DuplicateDataService extends BaseDataService<Duplicate> {
|
||||
|
||||
/**
|
||||
* The ResponseParsingService constructor name
|
||||
*/
|
||||
private parser: GenericConstructor<ResponseParsingService> = SearchResponseParsingService;
|
||||
|
||||
/**
|
||||
* The RestRequest constructor name
|
||||
*/
|
||||
private request: GenericConstructor<RestRequest> = GetRequest;
|
||||
|
||||
/**
|
||||
* Subscription to unsubscribe from
|
||||
*/
|
||||
private sub;
|
||||
|
||||
constructor(
|
||||
protected requestService: RequestService,
|
||||
protected rdbService: RemoteDataBuildService,
|
||||
protected objectCache: ObjectCacheService,
|
||||
protected halService: HALEndpointService,
|
||||
) {
|
||||
super('duplicates', requestService, rdbService, objectCache, halService);
|
||||
}
|
||||
|
||||
protected getEndpoint(): Observable<string> {
|
||||
return this.halService.getEndpoint(this.linkPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to set service options
|
||||
* @param {GenericConstructor<ResponseParsingService>} parser The ResponseParsingService constructor name
|
||||
* @param {boolean} request The RestRequest constructor name
|
||||
*/
|
||||
setServiceOptions(parser: GenericConstructor<ResponseParsingService>, request: GenericConstructor<RestRequest>) {
|
||||
if (parser) {
|
||||
this.parser = parser;
|
||||
}
|
||||
if (request) {
|
||||
this.request = request;
|
||||
}
|
||||
}
|
||||
|
||||
private getSearchUrl(): Observable<string> {
|
||||
const href$ = this.getEndpoint();
|
||||
return href$.pipe(
|
||||
map((href) => href + '/search')
|
||||
);
|
||||
}
|
||||
|
||||
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();
|
||||
if (options) {
|
||||
findListOptions = Object.assign(new FindListOptions(), options);
|
||||
}
|
||||
if (findListOptions.searchParams) {
|
||||
findListOptions.searchParams = [...findListOptions.searchParams, ...searchParams];
|
||||
} else {
|
||||
findListOptions.searchParams = searchParams;
|
||||
}
|
||||
|
||||
return this.findListByHref(this.getSearchUrl(), findListOptions, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsubscribe from the subscription
|
||||
*/
|
||||
ngOnDestroy(): void {
|
||||
if (this.sub !== undefined) {
|
||||
this.sub.unsubscribe();
|
||||
}
|
||||
}
|
||||
}
|
@@ -24,6 +24,7 @@ import { Context } from '../../../../core/shared/context.model';
|
||||
import { Duplicate } from '../../duplicate-data/duplicate.model';
|
||||
import { PaginatedList } from '../../../../core/data/paginated-list.model';
|
||||
import { ItemDataService } from '../../../../core/data/item-data.service';
|
||||
import { DuplicateDataService } from '../../../../core/data/duplicate-search.service';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-claimed-search-result-list-element',
|
||||
@@ -69,6 +70,7 @@ export class ClaimedSearchResultListElementComponent extends SearchResultListEle
|
||||
public dsoNameService: DSONameService,
|
||||
protected objectCache: ObjectCacheService,
|
||||
protected itemDataService: ItemDataService,
|
||||
protected duplicateDataService: DuplicateDataService,
|
||||
@Inject(APP_CONFIG) protected appConfig: AppConfig
|
||||
) {
|
||||
super(truncatableService, dsoNameService, appConfig);
|
||||
@@ -99,7 +101,7 @@ export class ClaimedSearchResultListElementComponent extends SearchResultListEle
|
||||
tap((itemRD: RemoteData<Item>) => {
|
||||
if (isNotEmpty(itemRD) && itemRD.hasSucceeded) {
|
||||
this.item$.next(itemRD.payload);
|
||||
this.duplicates$ = this.itemDataService.findDuplicates(itemRD.payload.uuid).pipe(
|
||||
this.duplicates$ = this.duplicateDataService.findDuplicates(itemRD.payload.uuid).pipe(
|
||||
getFirstCompletedRemoteData(),
|
||||
map((remoteData: RemoteData<PaginatedList<Duplicate>>) => {
|
||||
if (remoteData.hasSucceeded) {
|
||||
|
@@ -25,6 +25,7 @@ import { Context } from '../../../../core/shared/context.model';
|
||||
import { PaginatedList } from '../../../../core/data/paginated-list.model';
|
||||
import { Duplicate } from '../../duplicate-data/duplicate.model';
|
||||
import { ItemDataService } from '../../../../core/data/item-data.service';
|
||||
import { DuplicateDataService } from '../../../../core/data/duplicate-search.service';
|
||||
|
||||
/**
|
||||
* This component renders pool task object for the search result in the list view.
|
||||
@@ -79,6 +80,7 @@ export class PoolSearchResultListElementComponent extends SearchResultListElemen
|
||||
public dsoNameService: DSONameService,
|
||||
protected objectCache: ObjectCacheService,
|
||||
protected itemDataService: ItemDataService,
|
||||
protected duplicateDataService: DuplicateDataService,
|
||||
@Inject(APP_CONFIG) protected appConfig: AppConfig
|
||||
) {
|
||||
super(truncatableService, dsoNameService, appConfig);
|
||||
@@ -109,7 +111,8 @@ export class PoolSearchResultListElementComponent extends SearchResultListElemen
|
||||
tap((itemRD: RemoteData<Item>) => {
|
||||
if (isNotEmpty(itemRD) && itemRD.hasSucceeded) {
|
||||
this.item$.next(itemRD.payload);
|
||||
this.duplicates$ = this.itemDataService.findDuplicates(itemRD.payload.uuid).pipe(
|
||||
// Find duplicates for this item
|
||||
this.duplicates$ = this.duplicateDataService.findDuplicates(itemRD.payload.uuid).pipe(
|
||||
getFirstCompletedRemoteData(),
|
||||
map((remoteData: RemoteData<PaginatedList<Duplicate>>) => {
|
||||
if (remoteData.hasSucceeded) {
|
||||
@@ -120,7 +123,7 @@ export class PoolSearchResultListElementComponent extends SearchResultListElemen
|
||||
})
|
||||
);
|
||||
}
|
||||
})
|
||||
}),
|
||||
).subscribe();
|
||||
|
||||
this.showThumbnails = this.appConfig.browseBy.showThumbnails;
|
||||
|
Reference in New Issue
Block a user