Skip to content
Snippets Groups Projects
Commit 5995f87e authored by Giuseppe Digilio's avatar Giuseppe Digilio
Browse files

Added getEntryByValue method

parent 8efa2cfc
Branches
Tags
No related merge requests found
......@@ -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,
......
......@@ -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,
......
......@@ -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();
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment