From d3ba1d2926abc022c41839c778b05e2a4fb9b93f Mon Sep 17 00:00:00 2001 From: Davide Negretti Date: Wed, 15 Jun 2022 12:42:02 +0200 Subject: [PATCH] [CST-5339] Rename ORCID service; add findById and findAllByHref --- src/app/core/core.module.ts | 4 +-- ...rvice.ts => orcid-history-data.service.ts} | 36 ++++++++++++++++++- .../orcid-queue/orcid-queue.component.spec.ts | 4 +-- .../orcid-queue/orcid-queue.component.ts | 4 +-- 4 files changed, 41 insertions(+), 7 deletions(-) rename src/app/core/orcid/{orcid-history.service.ts => orcid-history-data.service.ts} (58%) diff --git a/src/app/core/core.module.ts b/src/app/core/core.module.ts index 4ec4ca8592..90e326a4df 100644 --- a/src/app/core/core.module.ts +++ b/src/app/core/core.module.ts @@ -174,7 +174,7 @@ import { ResearcherProfileService } from './profile/researcher-profile.service'; import { ProfileClaimService } from '../profile-page/profile-claim/profile-claim.service'; import { ResearcherProfile } from './profile/model/researcher-profile.model'; import { OrcidQueueService } from './orcid/orcid-queue.service'; -import { OrcidHistoryService } from './orcid/orcid-history.service'; +import { OrcidHistoryDataService } from './orcid/orcid-history-data.service'; import { OrcidQueue } from './orcid/model/orcid-queue.model'; import { OrcidHistory } from './orcid/model/orcid-history.model'; @@ -306,7 +306,7 @@ const PROVIDERS = [ ResearcherProfileService, ProfileClaimService, OrcidQueueService, - OrcidHistoryService, + OrcidHistoryDataService, ]; /** diff --git a/src/app/core/orcid/orcid-history.service.ts b/src/app/core/orcid/orcid-history-data.service.ts similarity index 58% rename from src/app/core/orcid/orcid-history.service.ts rename to src/app/core/orcid/orcid-history-data.service.ts index 6658c63c9f..cef3efbe78 100644 --- a/src/app/core/orcid/orcid-history.service.ts +++ b/src/app/core/orcid/orcid-history-data.service.ts @@ -22,6 +22,9 @@ import { HttpOptions } from '../dspace-rest/dspace-rest.service'; import { CoreState } from '../core-state.model'; import { RestRequest } from '../data/rest-request.model'; import { sendRequest } from '../shared/request.operators'; +import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model'; +import { FindListOptions } from '../data/find-list-options.model'; +import { PaginatedList } from '../data/paginated-list.model'; /** * A private DataService implementation to delegate specific methods to. @@ -48,7 +51,7 @@ class OrcidHistoryServiceImpl extends DataService { */ @Injectable() @dataService(ORCID_HISTORY) -export class OrcidHistoryService { +export class OrcidHistoryDataService { dataService: OrcidHistoryServiceImpl; @@ -89,4 +92,35 @@ export class OrcidHistoryService { return this.halService.getEndpoint(this.dataService.linkPath); } + /** + * Returns an observable of {@link RemoteData} of an object, based on its ID, with a list of + * {@link FollowLinkConfig}, to automatically resolve {@link HALLink}s of the object + * @param id ID of object we want to retrieve + * @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's + * no valid cached version. Defaults to true + * @param reRequestOnStale Whether or not the request should automatically be re- + * requested after the response becomes stale + * @param linksToFollow List of {@link FollowLinkConfig} that indicate which + * {@link HALLink}s should be automatically resolved + */ + findById(id: string, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig[]): Observable> { + return this.dataService.findById(id, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow); + } + + /** + * Returns a list of observables of {@link RemoteData} of {@link OrcidHistory}s, based on an href, with a list of {@link FollowLinkConfig}, + * to automatically resolve {@link HALLink}s of the {@link OrcidHistory} + * @param href The url of object we want to retrieve + * @param findListOptions Find list options object + * @param useCachedVersionIfAvailable If this is true, the request will only be sent if there's + * no valid cached version. Defaults to true + * @param reRequestOnStale Whether or not the request should automatically be re- + * requested after the response becomes stale + * @param linksToFollow List of {@link FollowLinkConfig} that indicate which + * {@link HALLink}s should be automatically resolved + */ + findAllByHref(href: string, findListOptions: FindListOptions = {}, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig[]): Observable>> { + return this.dataService.findAllByHref(href, findListOptions, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow); + } + } diff --git a/src/app/item-page/orcid-page/orcid-queue/orcid-queue.component.spec.ts b/src/app/item-page/orcid-page/orcid-queue/orcid-queue.component.spec.ts index d460e541e6..accd5e57a5 100644 --- a/src/app/item-page/orcid-page/orcid-queue/orcid-queue.component.spec.ts +++ b/src/app/item-page/orcid-page/orcid-queue/orcid-queue.component.spec.ts @@ -9,7 +9,7 @@ import { PaginationService } from '../../../core/pagination/pagination.service'; import { PaginationServiceStub } from '../../../shared/testing/pagination-service.stub'; import { NotificationsService } from '../../../shared/notifications/notifications.service'; import { NotificationsServiceStub } from '../../../shared/testing/notifications-service.stub'; -import { OrcidHistoryService } from '../../../core/orcid/orcid-history.service'; +import { OrcidHistoryDataService } from '../../../core/orcid/orcid-history-data.service'; import { OrcidQueue } from '../../../core/orcid/model/orcid-queue.model'; import { createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils'; import { createPaginatedList } from '../../../shared/testing/utils.test'; @@ -115,7 +115,7 @@ describe('OrcidQueueComponent test suite', () => { declarations: [OrcidQueueComponent], providers: [ { provide: OrcidQueueService, useValue: orcidQueueServiceSpy }, - { provide: OrcidHistoryService, useValue: {} }, + { provide: OrcidHistoryDataService, useValue: {} }, { provide: PaginationService, useValue: new PaginationServiceStub() }, { provide: NotificationsService, useValue: new NotificationsServiceStub() }, ], diff --git a/src/app/item-page/orcid-page/orcid-queue/orcid-queue.component.ts b/src/app/item-page/orcid-page/orcid-queue/orcid-queue.component.ts index 7faa4f54cb..217e02bc1f 100644 --- a/src/app/item-page/orcid-page/orcid-queue/orcid-queue.component.ts +++ b/src/app/item-page/orcid-page/orcid-queue/orcid-queue.component.ts @@ -6,7 +6,7 @@ import { PaginatedList } from '../../../core/data/paginated-list.model'; import { RemoteData } from '../../../core/data/remote-data'; import { OrcidHistory } from '../../../core/orcid/model/orcid-history.model'; import { OrcidQueue } from '../../../core/orcid/model/orcid-queue.model'; -import { OrcidHistoryService } from '../../../core/orcid/orcid-history.service'; +import { OrcidHistoryDataService } from '../../../core/orcid/orcid-history-data.service'; import { OrcidQueueService } from '../../../core/orcid/orcid-queue.service'; import { PaginationService } from '../../../core/pagination/pagination.service'; import { getFinishedRemoteData, getFirstCompletedRemoteData } from '../../../core/shared/operators'; @@ -61,7 +61,7 @@ export class OrcidQueueComponent implements OnInit, OnDestroy { protected translateService: TranslateService, private paginationService: PaginationService, private notificationsService: NotificationsService, - private orcidHistoryService: OrcidHistoryService, + private orcidHistoryService: OrcidHistoryDataService, ) { } ngOnInit(): void {