Skip to content

Commit 0d42af3

Browse files
committed
[TLC-674] Refactor Basic Duplicate detection endpoint / data service
1 parent 911cf89 commit 0d42af3

4 files changed

Lines changed: 111 additions & 3 deletions

File tree

src/app/core/core.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ import { NotifyRequestsStatus } from '../item-page/simple/notify-requests-status
198198
import { LdnService } from '../admin/admin-ldn-services/ldn-services-model/ldn-services.model';
199199
import { Itemfilter } from '../admin/admin-ldn-services/ldn-services-model/ldn-service-itemfilters';
200200
import { SubmissionCoarNotifyConfig } from '../submission/sections/section-coar-notify/submission-coar-notify.config';
201+
import { DuplicateDataService } from './data/duplicate-search.service';
201202

202203
/**
203204
* When not in production, endpoint responses can be mocked for testing purposes
@@ -234,6 +235,7 @@ const PROVIDERS = [
234235
HALEndpointService,
235236
HostWindowService,
236237
ItemDataService,
238+
DuplicateDataService,
237239
MetadataService,
238240
ObjectCacheService,
239241
PaginationComponentOptions,
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/* eslint-disable max-classes-per-file */
2+
import { Observable } from 'rxjs';
3+
import { Injectable } from '@angular/core';
4+
import { map } from 'rxjs/operators';
5+
import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
6+
import { ResponseParsingService } from './parsing.service';
7+
import { RemoteData } from './remote-data';
8+
import { GetRequest } from './request.models';
9+
import { RequestService } from './request.service';
10+
import { GenericConstructor } from '../shared/generic-constructor';
11+
import { HALEndpointService } from '../shared/hal-endpoint.service';
12+
import { SearchResponseParsingService } from './search-response-parsing.service';
13+
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
14+
import { RestRequest } from './rest-request.model';
15+
import { BaseDataService } from './base/base-data.service';
16+
import { FindListOptions } from './find-list-options.model';
17+
import { Duplicate } from '../../shared/object-list/duplicate-data/duplicate.model';
18+
import { PaginatedList } from './paginated-list.model';
19+
import { RequestParam } from '../cache/models/request-param.model';
20+
import { ObjectCacheService } from '../cache/object-cache.service';
21+
22+
23+
/**
24+
* Service that performs all general actions that have to do with the search page
25+
*/
26+
@Injectable()
27+
export class DuplicateDataService extends BaseDataService<Duplicate> {
28+
29+
/**
30+
* The ResponseParsingService constructor name
31+
*/
32+
private parser: GenericConstructor<ResponseParsingService> = SearchResponseParsingService;
33+
34+
/**
35+
* The RestRequest constructor name
36+
*/
37+
private request: GenericConstructor<RestRequest> = GetRequest;
38+
39+
/**
40+
* Subscription to unsubscribe from
41+
*/
42+
private sub;
43+
44+
constructor(
45+
protected requestService: RequestService,
46+
protected rdbService: RemoteDataBuildService,
47+
protected objectCache: ObjectCacheService,
48+
protected halService: HALEndpointService,
49+
) {
50+
super('duplicates', requestService, rdbService, objectCache, halService);
51+
}
52+
53+
protected getEndpoint(): Observable<string> {
54+
return this.halService.getEndpoint(this.linkPath);
55+
}
56+
57+
/**
58+
* Method to set service options
59+
* @param {GenericConstructor<ResponseParsingService>} parser The ResponseParsingService constructor name
60+
* @param {boolean} request The RestRequest constructor name
61+
*/
62+
setServiceOptions(parser: GenericConstructor<ResponseParsingService>, request: GenericConstructor<RestRequest>) {
63+
if (parser) {
64+
this.parser = parser;
65+
}
66+
if (request) {
67+
this.request = request;
68+
}
69+
}
70+
71+
private getSearchUrl(): Observable<string> {
72+
const href$ = this.getEndpoint();
73+
return href$.pipe(
74+
map((href) => href + '/search')
75+
);
76+
}
77+
78+
public findDuplicates(uuid: string, options?: FindListOptions, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig<Duplicate>[]): Observable<RemoteData<PaginatedList<Duplicate>>> {
79+
const searchParams = [new RequestParam('uuid', uuid)];
80+
let findListOptions = new FindListOptions();
81+
if (options) {
82+
findListOptions = Object.assign(new FindListOptions(), options);
83+
}
84+
if (findListOptions.searchParams) {
85+
findListOptions.searchParams = [...findListOptions.searchParams, ...searchParams];
86+
} else {
87+
findListOptions.searchParams = searchParams;
88+
}
89+
90+
return this.findListByHref(this.getSearchUrl(), findListOptions, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
91+
}
92+
93+
/**
94+
* Unsubscribe from the subscription
95+
*/
96+
ngOnDestroy(): void {
97+
if (this.sub !== undefined) {
98+
this.sub.unsubscribe();
99+
}
100+
}
101+
}

src/app/shared/object-list/my-dspace-result-list-element/claimed-search-result/claimed-search-result-list-element.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { Context } from '../../../../core/shared/context.model';
2424
import { Duplicate } from '../../duplicate-data/duplicate.model';
2525
import { PaginatedList } from '../../../../core/data/paginated-list.model';
2626
import { ItemDataService } from '../../../../core/data/item-data.service';
27+
import { DuplicateDataService } from '../../../../core/data/duplicate-search.service';
2728

2829
@Component({
2930
selector: 'ds-claimed-search-result-list-element',
@@ -69,6 +70,7 @@ export class ClaimedSearchResultListElementComponent extends SearchResultListEle
6970
public dsoNameService: DSONameService,
7071
protected objectCache: ObjectCacheService,
7172
protected itemDataService: ItemDataService,
73+
protected duplicateDataService: DuplicateDataService,
7274
@Inject(APP_CONFIG) protected appConfig: AppConfig
7375
) {
7476
super(truncatableService, dsoNameService, appConfig);
@@ -99,7 +101,7 @@ export class ClaimedSearchResultListElementComponent extends SearchResultListEle
99101
tap((itemRD: RemoteData<Item>) => {
100102
if (isNotEmpty(itemRD) && itemRD.hasSucceeded) {
101103
this.item$.next(itemRD.payload);
102-
this.duplicates$ = this.itemDataService.findDuplicates(itemRD.payload.uuid).pipe(
104+
this.duplicates$ = this.duplicateDataService.findDuplicates(itemRD.payload.uuid).pipe(
103105
getFirstCompletedRemoteData(),
104106
map((remoteData: RemoteData<PaginatedList<Duplicate>>) => {
105107
if (remoteData.hasSucceeded) {

src/app/shared/object-list/my-dspace-result-list-element/pool-search-result/pool-search-result-list-element.component.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { Context } from '../../../../core/shared/context.model';
2525
import { PaginatedList } from '../../../../core/data/paginated-list.model';
2626
import { Duplicate } from '../../duplicate-data/duplicate.model';
2727
import { ItemDataService } from '../../../../core/data/item-data.service';
28+
import { DuplicateDataService } from '../../../../core/data/duplicate-search.service';
2829

2930
/**
3031
* This component renders pool task object for the search result in the list view.
@@ -79,6 +80,7 @@ export class PoolSearchResultListElementComponent extends SearchResultListElemen
7980
public dsoNameService: DSONameService,
8081
protected objectCache: ObjectCacheService,
8182
protected itemDataService: ItemDataService,
83+
protected duplicateDataService: DuplicateDataService,
8284
@Inject(APP_CONFIG) protected appConfig: AppConfig
8385
) {
8486
super(truncatableService, dsoNameService, appConfig);
@@ -109,7 +111,8 @@ export class PoolSearchResultListElementComponent extends SearchResultListElemen
109111
tap((itemRD: RemoteData<Item>) => {
110112
if (isNotEmpty(itemRD) && itemRD.hasSucceeded) {
111113
this.item$.next(itemRD.payload);
112-
this.duplicates$ = this.itemDataService.findDuplicates(itemRD.payload.uuid).pipe(
114+
// Find duplicates for this item
115+
this.duplicates$ = this.duplicateDataService.findDuplicates(itemRD.payload.uuid).pipe(
113116
getFirstCompletedRemoteData(),
114117
map((remoteData: RemoteData<PaginatedList<Duplicate>>) => {
115118
if (remoteData.hasSucceeded) {
@@ -120,7 +123,7 @@ export class PoolSearchResultListElementComponent extends SearchResultListElemen
120123
})
121124
);
122125
}
123-
})
126+
}),
124127
).subscribe();
125128

126129
this.showThumbnails = this.appConfig.browseBy.showThumbnails;

0 commit comments

Comments
 (0)