diff --git a/src/app/core/integration/authority.service.ts b/src/app/core/integration/authority.service.ts index 515a0da378270935a0120fa6584ef13688c20f6d..02c1141d2a6eec35319e1c68ab71a6e582685fa7 100644 --- a/src/app/core/integration/authority.service.ts +++ b/src/app/core/integration/authority.service.ts @@ -9,7 +9,8 @@ import { RemoteDataBuildService } from '../cache/builders/remote-data-build.serv @Injectable() export class AuthorityService extends IntegrationService { protected linkPath = 'authorities'; - protected browseEndpoint = 'entries'; + protected entriesEndpoint = 'entries'; + protected entryValueEndpoint = 'entryValues'; constructor( protected responseCache: ResponseCacheService, diff --git a/src/app/core/integration/integration.service.spec.ts b/src/app/core/integration/integration.service.spec.ts index 745bf8bb8e065a9583587b3abf6496e131cd5a5f..b357c2e99ec634b2aea3b0c1ad4c9499a021a814 100644 --- a/src/app/core/integration/integration.service.spec.ts +++ b/src/app/core/integration/integration.service.spec.ts @@ -13,11 +13,13 @@ import { RemoteDataBuildService } from '../cache/builders/remote-data-build.serv import { getMockRemoteDataBuildService } from '../../shared/mocks/mock-remote-data-build.service'; const LINK_NAME = 'authorities'; -const BROWSE = 'entries'; +const ENTRIES = 'entries'; +const ENTRY_VALUE = 'entryValue'; class TestService extends IntegrationService { protected linkPath = LINK_NAME; - protected browseEndpoint = BROWSE; + protected entriesEndpoint = ENTRIES; + protected entryValueEndpoint = ENTRY_VALUE; constructor( protected responseCache: ResponseCacheService, diff --git a/src/app/core/integration/integration.service.ts b/src/app/core/integration/integration.service.ts index 8e39f2a82def3a2043629a7322f148fadc1ea7a3..e69e488f0736496395c012845fbead5d3910c4eb 100644 --- a/src/app/core/integration/integration.service.ts +++ b/src/app/core/integration/integration.service.ts @@ -16,7 +16,8 @@ export abstract class IntegrationService { protected abstract requestService: RequestService; protected abstract rdbService: RemoteDataBuildService; protected abstract linkPath: string; - protected abstract browseEndpoint: string; + protected abstract entriesEndpoint: string; + protected abstract entryValueEndpoint: string; protected abstract halService: HALEndpointService; protected getData(request: GetRequest): Observable<IntegrationData> { @@ -37,12 +38,12 @@ export abstract class IntegrationService { .distinctUntilChanged()); } - protected getIntegrationHref(endpoint, options: IntegrationSearchOptions = new IntegrationSearchOptions()): string { + protected getEntriesHref(endpoint, options: IntegrationSearchOptions = new IntegrationSearchOptions()): string { let result; const args = []; if (hasValue(options.name)) { - result = `${endpoint}/${options.name}/${this.browseEndpoint}`; + result = `${endpoint}/${options.name}/${this.entriesEndpoint}`; } else { result = endpoint; } @@ -78,9 +79,30 @@ export abstract class IntegrationService { return result; } + protected getEntryValueHref(endpoint, options: IntegrationSearchOptions = new IntegrationSearchOptions()): string { + let result; + const args = []; + + if (hasValue(options.name) && hasValue(options.query)) { + result = `${endpoint}/${options.name}/${this.entryValueEndpoint}/${options.query}`; + } else { + result = endpoint; + } + + if (hasValue(options.metadata)) { + args.push(`metadata=${options.metadata}`); + } + + if (isNotEmpty(args)) { + result = `${result}?${args.join('&')}`; + } + + return result; + } + public getEntriesByName(options: IntegrationSearchOptions): Observable<IntegrationData> { return this.halService.getEndpoint(this.linkPath) - .map((endpoint: string) => this.getIntegrationHref(endpoint, options)) + .map((endpoint: string) => this.getEntriesHref(endpoint, options)) .filter((href: string) => isNotEmpty(href)) .distinctUntilChanged() .map((endpointURL: string) => new IntegrationRequest(this.requestService.generateRequestId(), endpointURL)) @@ -89,4 +111,14 @@ export abstract class IntegrationService { .distinctUntilChanged(); } + public getEntryByValue(options: IntegrationSearchOptions): Observable<IntegrationData> { + return this.halService.getEndpoint(this.linkPath) + .map((endpoint: string) => this.getEntryValueHref(endpoint, options)) + .filter((href: string) => isNotEmpty(href)) + .distinctUntilChanged() + .map((endpointURL: string) => new IntegrationRequest(this.requestService.generateRequestId(), endpointURL)) + .do((request: GetRequest) => this.requestService.configure(request)) + .flatMap((request: GetRequest) => this.getData(request)) + .distinctUntilChanged(); + } }