mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-17 23:13:04 +00:00
Added getEntryByValue method
This commit is contained in:
@@ -9,7 +9,8 @@ import { RemoteDataBuildService } from '../cache/builders/remote-data-build.serv
|
|||||||
@Injectable()
|
@Injectable()
|
||||||
export class AuthorityService extends IntegrationService {
|
export class AuthorityService extends IntegrationService {
|
||||||
protected linkPath = 'authorities';
|
protected linkPath = 'authorities';
|
||||||
protected browseEndpoint = 'entries';
|
protected entriesEndpoint = 'entries';
|
||||||
|
protected entryValueEndpoint = 'entryValues';
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
protected responseCache: ResponseCacheService,
|
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';
|
import { getMockRemoteDataBuildService } from '../../shared/mocks/mock-remote-data-build.service';
|
||||||
|
|
||||||
const LINK_NAME = 'authorities';
|
const LINK_NAME = 'authorities';
|
||||||
const BROWSE = 'entries';
|
const ENTRIES = 'entries';
|
||||||
|
const ENTRY_VALUE = 'entryValue';
|
||||||
|
|
||||||
class TestService extends IntegrationService {
|
class TestService extends IntegrationService {
|
||||||
protected linkPath = LINK_NAME;
|
protected linkPath = LINK_NAME;
|
||||||
protected browseEndpoint = BROWSE;
|
protected entriesEndpoint = ENTRIES;
|
||||||
|
protected entryValueEndpoint = ENTRY_VALUE;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
protected responseCache: ResponseCacheService,
|
protected responseCache: ResponseCacheService,
|
||||||
|
@@ -16,7 +16,8 @@ export abstract class IntegrationService {
|
|||||||
protected abstract requestService: RequestService;
|
protected abstract requestService: RequestService;
|
||||||
protected abstract rdbService: RemoteDataBuildService;
|
protected abstract rdbService: RemoteDataBuildService;
|
||||||
protected abstract linkPath: string;
|
protected abstract linkPath: string;
|
||||||
protected abstract browseEndpoint: string;
|
protected abstract entriesEndpoint: string;
|
||||||
|
protected abstract entryValueEndpoint: string;
|
||||||
protected abstract halService: HALEndpointService;
|
protected abstract halService: HALEndpointService;
|
||||||
|
|
||||||
protected getData(request: GetRequest): Observable<IntegrationData> {
|
protected getData(request: GetRequest): Observable<IntegrationData> {
|
||||||
@@ -37,12 +38,12 @@ export abstract class IntegrationService {
|
|||||||
.distinctUntilChanged());
|
.distinctUntilChanged());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected getIntegrationHref(endpoint, options: IntegrationSearchOptions = new IntegrationSearchOptions()): string {
|
protected getEntriesHref(endpoint, options: IntegrationSearchOptions = new IntegrationSearchOptions()): string {
|
||||||
let result;
|
let result;
|
||||||
const args = [];
|
const args = [];
|
||||||
|
|
||||||
if (hasValue(options.name)) {
|
if (hasValue(options.name)) {
|
||||||
result = `${endpoint}/${options.name}/${this.browseEndpoint}`;
|
result = `${endpoint}/${options.name}/${this.entriesEndpoint}`;
|
||||||
} else {
|
} else {
|
||||||
result = endpoint;
|
result = endpoint;
|
||||||
}
|
}
|
||||||
@@ -78,9 +79,30 @@ export abstract class IntegrationService {
|
|||||||
return result;
|
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> {
|
public getEntriesByName(options: IntegrationSearchOptions): Observable<IntegrationData> {
|
||||||
return this.halService.getEndpoint(this.linkPath)
|
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))
|
.filter((href: string) => isNotEmpty(href))
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
.map((endpointURL: string) => new IntegrationRequest(this.requestService.generateRequestId(), endpointURL))
|
.map((endpointURL: string) => new IntegrationRequest(this.requestService.generateRequestId(), endpointURL))
|
||||||
@@ -89,4 +111,14 @@ export abstract class IntegrationService {
|
|||||||
.distinctUntilChanged();
|
.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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user