mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
[CST-3088] Removed authority and integration services
This commit is contained in:
14
src/app/core/cache/response.models.ts
vendored
14
src/app/core/cache/response.models.ts
vendored
@@ -5,11 +5,9 @@ import { PageInfo } from '../shared/page-info.model';
|
||||
import { ConfigObject } from '../config/models/config.model';
|
||||
import { FacetValue } from '../../shared/search/facet-value.model';
|
||||
import { SearchFilterConfig } from '../../shared/search/search-filter-config.model';
|
||||
import { IntegrationModel } from '../integration/models/integration.model';
|
||||
import { RegistryMetadataschemasResponse } from '../registry/registry-metadataschemas-response.model';
|
||||
import { RegistryMetadatafieldsResponse } from '../registry/registry-metadatafields-response.model';
|
||||
import { RegistryBitstreamformatsResponse } from '../registry/registry-bitstreamformats-response.model';
|
||||
import { PaginatedList } from '../data/paginated-list';
|
||||
import { SubmissionObject } from '../submission/models/submission-object.model';
|
||||
import { DSpaceObject } from '../shared/dspace-object.model';
|
||||
import { MetadataSchema } from '../metadata/metadata-schema.model';
|
||||
@@ -211,17 +209,6 @@ export class AuthStatusResponse extends RestResponse {
|
||||
}
|
||||
}
|
||||
|
||||
export class IntegrationSuccessResponse extends RestResponse {
|
||||
constructor(
|
||||
public dataDefinition: PaginatedList<IntegrationModel>,
|
||||
public statusCode: number,
|
||||
public statusText: string,
|
||||
public pageInfo?: PageInfo
|
||||
) {
|
||||
super(true, statusCode, statusText);
|
||||
}
|
||||
}
|
||||
|
||||
export class PostPatchSuccessResponse extends RestResponse {
|
||||
constructor(
|
||||
public dataDefinition: any,
|
||||
@@ -302,4 +289,5 @@ export class ContentSourceSuccessResponse extends RestResponse {
|
||||
super(true, statusCode, statusText);
|
||||
}
|
||||
}
|
||||
|
||||
/* tslint:enable:max-classes-per-file */
|
||||
|
@@ -9,7 +9,6 @@ import { ConfigResponseParsingService } from '../config/config-response-parsing.
|
||||
import { AuthResponseParsingService } from '../auth/auth-response-parsing.service';
|
||||
import { HttpOptions } from '../dspace-rest-v2/dspace-rest-v2.service';
|
||||
import { SubmissionResponseParsingService } from '../submission/submission-response-parsing.service';
|
||||
import { IntegrationResponseParsingService } from '../integration/integration-response-parsing.service';
|
||||
import { RestRequestMethod } from './rest-request-method';
|
||||
import { RequestParam } from '../cache/models/request-param.model';
|
||||
import { EpersonResponseParsingService } from '../eperson/eperson-response-parsing.service';
|
||||
@@ -26,13 +25,14 @@ import { VocabularyEntriesResponseParsingService } from '../submission/vocabular
|
||||
|
||||
// uuid and handle requests have separate endpoints
|
||||
export enum IdentifierType {
|
||||
UUID ='uuid',
|
||||
UUID = 'uuid',
|
||||
HANDLE = 'handle'
|
||||
}
|
||||
|
||||
export abstract class RestRequest {
|
||||
public responseMsToLive = 10 * 1000;
|
||||
public forceBypassCache = false;
|
||||
|
||||
constructor(
|
||||
public uuid: string,
|
||||
public href: string,
|
||||
@@ -42,13 +42,13 @@ export abstract class RestRequest {
|
||||
) {
|
||||
}
|
||||
|
||||
getResponseParser(): GenericConstructor<ResponseParsingService> {
|
||||
return DSOResponseParsingService;
|
||||
}
|
||||
|
||||
get toCache(): boolean {
|
||||
return this.responseMsToLive > 0;
|
||||
}
|
||||
|
||||
getResponseParser(): GenericConstructor<ResponseParsingService> {
|
||||
return DSOResponseParsingService;
|
||||
}
|
||||
}
|
||||
|
||||
export class GetRequest extends RestRequest {
|
||||
@@ -59,7 +59,7 @@ export class GetRequest extends RestRequest {
|
||||
public href: string,
|
||||
public body?: any,
|
||||
public options?: HttpOptions
|
||||
) {
|
||||
) {
|
||||
super(uuid, href, RestRequestMethod.GET, body, options)
|
||||
}
|
||||
}
|
||||
@@ -70,7 +70,7 @@ export class PostRequest extends RestRequest {
|
||||
public href: string,
|
||||
public body?: any,
|
||||
public options?: HttpOptions
|
||||
) {
|
||||
) {
|
||||
super(uuid, href, RestRequestMethod.POST, body)
|
||||
}
|
||||
}
|
||||
@@ -81,7 +81,7 @@ export class PutRequest extends RestRequest {
|
||||
public href: string,
|
||||
public body?: any,
|
||||
public options?: HttpOptions
|
||||
) {
|
||||
) {
|
||||
super(uuid, href, RestRequestMethod.PUT, body)
|
||||
}
|
||||
}
|
||||
@@ -92,7 +92,7 @@ export class DeleteRequest extends RestRequest {
|
||||
public href: string,
|
||||
public body?: any,
|
||||
public options?: HttpOptions
|
||||
) {
|
||||
) {
|
||||
super(uuid, href, RestRequestMethod.DELETE, body)
|
||||
}
|
||||
}
|
||||
@@ -103,7 +103,7 @@ export class OptionsRequest extends RestRequest {
|
||||
public href: string,
|
||||
public body?: any,
|
||||
public options?: HttpOptions
|
||||
) {
|
||||
) {
|
||||
super(uuid, href, RestRequestMethod.OPTIONS, body)
|
||||
}
|
||||
}
|
||||
@@ -114,7 +114,7 @@ export class HeadRequest extends RestRequest {
|
||||
public href: string,
|
||||
public body?: any,
|
||||
public options?: HttpOptions
|
||||
) {
|
||||
) {
|
||||
super(uuid, href, RestRequestMethod.HEAD, body)
|
||||
}
|
||||
}
|
||||
@@ -127,7 +127,7 @@ export class PatchRequest extends RestRequest {
|
||||
public href: string,
|
||||
public body?: any,
|
||||
public options?: HttpOptions
|
||||
) {
|
||||
) {
|
||||
super(uuid, href, RestRequestMethod.PATCH, body)
|
||||
}
|
||||
}
|
||||
@@ -242,16 +242,6 @@ export class AuthGetRequest extends GetRequest {
|
||||
}
|
||||
}
|
||||
|
||||
export class IntegrationRequest extends GetRequest {
|
||||
constructor(uuid: string, href: string) {
|
||||
super(uuid, href);
|
||||
}
|
||||
|
||||
getResponseParser(): GenericConstructor<ResponseParsingService> {
|
||||
return IntegrationResponseParsingService;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Request to create a MetadataSchema
|
||||
*/
|
||||
@@ -309,6 +299,7 @@ export class UpdateMetadataFieldRequest extends PutRequest {
|
||||
*/
|
||||
export class SubmissionRequest extends GetRequest {
|
||||
forceBypassCache = true;
|
||||
|
||||
constructor(uuid: string, href: string) {
|
||||
super(uuid, href);
|
||||
}
|
||||
@@ -456,4 +447,5 @@ export class RequestError extends Error {
|
||||
statusCode: number;
|
||||
statusText: string;
|
||||
}
|
||||
|
||||
/* tslint:enable:max-classes-per-file */
|
||||
|
@@ -1,21 +0,0 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
import { RequestService } from '../data/request.service';
|
||||
import { IntegrationService } from './integration.service';
|
||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
|
||||
|
||||
@Injectable()
|
||||
export class AuthorityService extends IntegrationService {
|
||||
protected linkPath = 'authorities';
|
||||
protected entriesEndpoint = 'entries';
|
||||
protected entryValueEndpoint = 'entryValues';
|
||||
|
||||
constructor(
|
||||
protected requestService: RequestService,
|
||||
protected rdbService: RemoteDataBuildService,
|
||||
protected halService: HALEndpointService) {
|
||||
super();
|
||||
}
|
||||
|
||||
}
|
@@ -1,12 +0,0 @@
|
||||
import { PageInfo } from '../shared/page-info.model';
|
||||
import { IntegrationModel } from './models/integration.model';
|
||||
|
||||
/**
|
||||
* A class to represent the data retrieved by an Integration service
|
||||
*/
|
||||
export class IntegrationData {
|
||||
constructor(
|
||||
public pageInfo: PageInfo,
|
||||
public payload: IntegrationModel[]
|
||||
) { }
|
||||
}
|
@@ -1,221 +0,0 @@
|
||||
import { Store } from '@ngrx/store';
|
||||
|
||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||
import { ErrorResponse, IntegrationSuccessResponse } from '../cache/response.models';
|
||||
import { CoreState } from '../core.reducers';
|
||||
import { PaginatedList } from '../data/paginated-list';
|
||||
import { IntegrationRequest } from '../data/request.models';
|
||||
import { PageInfo } from '../shared/page-info.model';
|
||||
import { IntegrationResponseParsingService } from './integration-response-parsing.service';
|
||||
import { AuthorityValue } from './models/authority.value';
|
||||
|
||||
describe('IntegrationResponseParsingService', () => {
|
||||
let service: IntegrationResponseParsingService;
|
||||
|
||||
const store = {} as Store<CoreState>;
|
||||
const objectCacheService = new ObjectCacheService(store, undefined);
|
||||
const name = 'type';
|
||||
const metadata = 'dc.type';
|
||||
const query = '';
|
||||
const uuid = 'd9d30c0c-69b7-4369-8397-ca67c888974d';
|
||||
const integrationEndpoint = 'https://rest.api/integration/authorities';
|
||||
const entriesEndpoint = `${integrationEndpoint}/${name}/entries?query=${query}&metadata=${metadata}&uuid=${uuid}`;
|
||||
let validRequest;
|
||||
|
||||
let validResponse;
|
||||
|
||||
let invalidResponse1;
|
||||
let invalidResponse2;
|
||||
let pageInfo;
|
||||
let definitions;
|
||||
|
||||
function initVars() {
|
||||
pageInfo = Object.assign(new PageInfo(), {
|
||||
elementsPerPage: 5,
|
||||
totalElements: 5,
|
||||
totalPages: 1,
|
||||
currentPage: 1,
|
||||
_links: {
|
||||
self: { href: 'https://rest.api/integration/authorities/type/entries' }
|
||||
}
|
||||
});
|
||||
definitions = new PaginatedList(pageInfo, [
|
||||
Object.assign(new AuthorityValue(), {
|
||||
type: 'authority',
|
||||
display: 'One',
|
||||
id: 'One',
|
||||
otherInformation: undefined,
|
||||
value: 'One'
|
||||
}),
|
||||
Object.assign(new AuthorityValue(), {
|
||||
type: 'authority',
|
||||
display: 'Two',
|
||||
id: 'Two',
|
||||
otherInformation: undefined,
|
||||
value: 'Two'
|
||||
}),
|
||||
Object.assign(new AuthorityValue(), {
|
||||
type: 'authority',
|
||||
display: 'Three',
|
||||
id: 'Three',
|
||||
otherInformation: undefined,
|
||||
value: 'Three'
|
||||
}),
|
||||
Object.assign(new AuthorityValue(), {
|
||||
type: 'authority',
|
||||
display: 'Four',
|
||||
id: 'Four',
|
||||
otherInformation: undefined,
|
||||
value: 'Four'
|
||||
}),
|
||||
Object.assign(new AuthorityValue(), {
|
||||
type: 'authority',
|
||||
display: 'Five',
|
||||
id: 'Five',
|
||||
otherInformation: undefined,
|
||||
value: 'Five'
|
||||
})
|
||||
]);
|
||||
validRequest = new IntegrationRequest('69f375b5-19f4-4453-8c7a-7dc5c55aafbb', entriesEndpoint);
|
||||
|
||||
validResponse = {
|
||||
payload: {
|
||||
page: {
|
||||
number: 0,
|
||||
size: 5,
|
||||
totalElements: 5,
|
||||
totalPages: 1
|
||||
},
|
||||
_embedded: {
|
||||
authorityEntries: [
|
||||
{
|
||||
display: 'One',
|
||||
id: 'One',
|
||||
otherInformation: {},
|
||||
type: 'authority',
|
||||
value: 'One'
|
||||
},
|
||||
{
|
||||
display: 'Two',
|
||||
id: 'Two',
|
||||
otherInformation: {},
|
||||
type: 'authority',
|
||||
value: 'Two'
|
||||
},
|
||||
{
|
||||
display: 'Three',
|
||||
id: 'Three',
|
||||
otherInformation: {},
|
||||
type: 'authority',
|
||||
value: 'Three'
|
||||
},
|
||||
{
|
||||
display: 'Four',
|
||||
id: 'Four',
|
||||
otherInformation: {},
|
||||
type: 'authority',
|
||||
value: 'Four'
|
||||
},
|
||||
{
|
||||
display: 'Five',
|
||||
id: 'Five',
|
||||
otherInformation: {},
|
||||
type: 'authority',
|
||||
value: 'Five'
|
||||
},
|
||||
],
|
||||
|
||||
},
|
||||
_links: {
|
||||
self: { href: 'https://rest.api/integration/authorities/type/entries' }
|
||||
}
|
||||
},
|
||||
statusCode: 200,
|
||||
statusText: 'OK'
|
||||
};
|
||||
|
||||
invalidResponse1 = {
|
||||
payload: {},
|
||||
statusCode: 400,
|
||||
statusText: 'Bad Request'
|
||||
};
|
||||
|
||||
invalidResponse2 = {
|
||||
payload: {
|
||||
page: {
|
||||
number: 0,
|
||||
size: 5,
|
||||
totalElements: 5,
|
||||
totalPages: 1
|
||||
},
|
||||
_embedded: {
|
||||
authorityEntries: [
|
||||
{
|
||||
display: 'One',
|
||||
id: 'One',
|
||||
otherInformation: {},
|
||||
type: 'authority',
|
||||
value: 'One'
|
||||
},
|
||||
{
|
||||
display: 'Two',
|
||||
id: 'Two',
|
||||
otherInformation: {},
|
||||
type: 'authority',
|
||||
value: 'Two'
|
||||
},
|
||||
{
|
||||
display: 'Three',
|
||||
id: 'Three',
|
||||
otherInformation: {},
|
||||
type: 'authority',
|
||||
value: 'Three'
|
||||
},
|
||||
{
|
||||
display: 'Four',
|
||||
id: 'Four',
|
||||
otherInformation: {},
|
||||
type: 'authority',
|
||||
value: 'Four'
|
||||
},
|
||||
{
|
||||
display: 'Five',
|
||||
id: 'Five',
|
||||
otherInformation: {},
|
||||
type: 'authority',
|
||||
value: 'Five'
|
||||
},
|
||||
],
|
||||
|
||||
},
|
||||
_links: {}
|
||||
},
|
||||
statusCode: 500,
|
||||
statusText: 'Internal Server Error'
|
||||
};
|
||||
}
|
||||
beforeEach(() => {
|
||||
initVars();
|
||||
service = new IntegrationResponseParsingService(objectCacheService);
|
||||
});
|
||||
|
||||
describe('parse', () => {
|
||||
it('should return a IntegrationSuccessResponse if data contains a valid endpoint response', () => {
|
||||
const response = service.parse(validRequest, validResponse);
|
||||
expect(response.constructor).toBe(IntegrationSuccessResponse);
|
||||
});
|
||||
|
||||
it('should return an ErrorResponse if data contains an invalid config endpoint response', () => {
|
||||
const response1 = service.parse(validRequest, invalidResponse1);
|
||||
const response2 = service.parse(validRequest, invalidResponse2);
|
||||
expect(response1.constructor).toBe(ErrorResponse);
|
||||
expect(response2.constructor).toBe(ErrorResponse);
|
||||
});
|
||||
|
||||
it('should return a IntegrationSuccessResponse with data definition', () => {
|
||||
const response = service.parse(validRequest, validResponse);
|
||||
expect((response as any).dataDefinition).toEqual(definitions);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
@@ -1,50 +0,0 @@
|
||||
import { Inject, Injectable } from '@angular/core';
|
||||
import { RestRequest } from '../data/request.models';
|
||||
import { ResponseParsingService } from '../data/parsing.service';
|
||||
import { DSpaceRESTV2Response } from '../dspace-rest-v2/dspace-rest-v2-response.model';
|
||||
import { ErrorResponse, IntegrationSuccessResponse, RestResponse } from '../cache/response.models';
|
||||
import { isNotEmpty } from '../../shared/empty.util';
|
||||
|
||||
import { BaseResponseParsingService } from '../data/base-response-parsing.service';
|
||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||
import { IntegrationModel } from './models/integration.model';
|
||||
import { AuthorityValue } from './models/authority.value';
|
||||
import { PaginatedList } from '../data/paginated-list';
|
||||
|
||||
@Injectable()
|
||||
export class IntegrationResponseParsingService extends BaseResponseParsingService implements ResponseParsingService {
|
||||
|
||||
protected toCache = true;
|
||||
|
||||
constructor(
|
||||
protected objectCache: ObjectCacheService,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
parse(request: RestRequest, data: DSpaceRESTV2Response): RestResponse {
|
||||
if (isNotEmpty(data.payload) && isNotEmpty(data.payload._links)) {
|
||||
const dataDefinition = this.process<IntegrationModel>(data.payload, request);
|
||||
return new IntegrationSuccessResponse(this.processResponse(dataDefinition), data.statusCode, data.statusText, this.processPageInfo(data.payload));
|
||||
} else {
|
||||
return new ErrorResponse(
|
||||
Object.assign(
|
||||
new Error('Unexpected response from Integration endpoint'),
|
||||
{statusCode: data.statusCode, statusText: data.statusText}
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected processResponse(data: PaginatedList<IntegrationModel>): any {
|
||||
const returnList = Array.of();
|
||||
data.page.forEach((item, index) => {
|
||||
if (item.type === AuthorityValue.type.value) {
|
||||
data.page[index] = Object.assign(new AuthorityValue(), item);
|
||||
}
|
||||
});
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
@@ -1,96 +0,0 @@
|
||||
import { cold, getTestScheduler } from 'jasmine-marbles';
|
||||
import { TestScheduler } from 'rxjs/testing';
|
||||
import { getMockRequestService } from '../../shared/mocks/request.service.mock';
|
||||
|
||||
import { RequestService } from '../data/request.service';
|
||||
import { IntegrationRequest } from '../data/request.models';
|
||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||
import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-service.stub';
|
||||
import { IntegrationService } from './integration.service';
|
||||
import { IntegrationSearchOptions } from './models/integration-options.model';
|
||||
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
|
||||
import { getMockRemoteDataBuildService } from '../../shared/mocks/remote-data-build.service.mock';
|
||||
|
||||
const LINK_NAME = 'authorities';
|
||||
const ENTRIES = 'entries';
|
||||
const ENTRY_VALUE = 'entryValue';
|
||||
|
||||
class TestService extends IntegrationService {
|
||||
protected linkPath = LINK_NAME;
|
||||
protected entriesEndpoint = ENTRIES;
|
||||
protected entryValueEndpoint = ENTRY_VALUE;
|
||||
|
||||
constructor(
|
||||
protected requestService: RequestService,
|
||||
protected rdbService: RemoteDataBuildService,
|
||||
protected halService: HALEndpointService) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
describe('IntegrationService', () => {
|
||||
let scheduler: TestScheduler;
|
||||
let service: TestService;
|
||||
let requestService: RequestService;
|
||||
let rdbService: RemoteDataBuildService;
|
||||
let halService: any;
|
||||
let findOptions: IntegrationSearchOptions;
|
||||
|
||||
const name = 'type';
|
||||
const metadata = 'dc.type';
|
||||
const query = '';
|
||||
const value = 'test';
|
||||
const uuid = 'd9d30c0c-69b7-4369-8397-ca67c888974d';
|
||||
const integrationEndpoint = 'https://rest.api/integration';
|
||||
const serviceEndpoint = `${integrationEndpoint}/${LINK_NAME}`;
|
||||
const entriesEndpoint = `${serviceEndpoint}/${name}/entries?query=${query}&metadata=${metadata}&uuid=${uuid}`;
|
||||
const entryValueEndpoint = `${serviceEndpoint}/${name}/entryValue/${value}?metadata=${metadata}`;
|
||||
|
||||
findOptions = new IntegrationSearchOptions(uuid, name, metadata);
|
||||
|
||||
function initTestService(): TestService {
|
||||
return new TestService(
|
||||
requestService,
|
||||
rdbService,
|
||||
halService
|
||||
);
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
requestService = getMockRequestService();
|
||||
rdbService = getMockRemoteDataBuildService();
|
||||
scheduler = getTestScheduler();
|
||||
halService = new HALEndpointServiceStub(integrationEndpoint);
|
||||
findOptions = new IntegrationSearchOptions(uuid, name, metadata, query);
|
||||
service = initTestService();
|
||||
|
||||
});
|
||||
|
||||
describe('getEntriesByName', () => {
|
||||
|
||||
it('should configure a new IntegrationRequest', () => {
|
||||
const expected = new IntegrationRequest(requestService.generateRequestId(), entriesEndpoint);
|
||||
scheduler.schedule(() => service.getEntriesByName(findOptions).subscribe());
|
||||
scheduler.flush();
|
||||
|
||||
expect(requestService.configure).toHaveBeenCalledWith(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getEntryByValue', () => {
|
||||
|
||||
it('should configure a new IntegrationRequest', () => {
|
||||
findOptions = new IntegrationSearchOptions(
|
||||
null,
|
||||
name,
|
||||
metadata,
|
||||
value);
|
||||
|
||||
const expected = new IntegrationRequest(requestService.generateRequestId(), entryValueEndpoint);
|
||||
scheduler.schedule(() => service.getEntryByValue(findOptions).subscribe());
|
||||
scheduler.flush();
|
||||
|
||||
expect(requestService.configure).toHaveBeenCalledWith(expected);
|
||||
});
|
||||
});
|
||||
});
|
@@ -1,121 +0,0 @@
|
||||
import { Observable, of as observableOf, throwError as observableThrowError } from 'rxjs';
|
||||
import { distinctUntilChanged, filter, map, mergeMap, tap } from 'rxjs/operators';
|
||||
import { RequestService } from '../data/request.service';
|
||||
import { IntegrationSuccessResponse } from '../cache/response.models';
|
||||
import { GetRequest, IntegrationRequest } from '../data/request.models';
|
||||
import { hasValue, isNotEmpty } from '../../shared/empty.util';
|
||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||
import { IntegrationData } from './integration-data';
|
||||
import { IntegrationSearchOptions } from './models/integration-options.model';
|
||||
import { getResponseFromEntry } from '../shared/operators';
|
||||
|
||||
export abstract class IntegrationService {
|
||||
protected request: IntegrationRequest;
|
||||
protected abstract requestService: RequestService;
|
||||
protected abstract linkPath: string;
|
||||
protected abstract entriesEndpoint: string;
|
||||
protected abstract entryValueEndpoint: string;
|
||||
protected abstract halService: HALEndpointService;
|
||||
|
||||
protected getData(request: GetRequest): Observable<IntegrationData> {
|
||||
return this.requestService.getByHref(request.href).pipe(
|
||||
getResponseFromEntry(),
|
||||
mergeMap((response: IntegrationSuccessResponse) => {
|
||||
if (response.isSuccessful && isNotEmpty(response)) {
|
||||
return observableOf(new IntegrationData(
|
||||
response.pageInfo,
|
||||
(response.dataDefinition) ? response.dataDefinition.page : []
|
||||
));
|
||||
} else if (!response.isSuccessful) {
|
||||
return observableThrowError(new Error(`Couldn't retrieve the integration data`));
|
||||
}
|
||||
}),
|
||||
distinctUntilChanged()
|
||||
);
|
||||
}
|
||||
|
||||
protected getEntriesHref(endpoint, options: IntegrationSearchOptions = new IntegrationSearchOptions()): string {
|
||||
let result;
|
||||
const args = [];
|
||||
|
||||
if (hasValue(options.name)) {
|
||||
result = `${endpoint}/${options.name}/${this.entriesEndpoint}`;
|
||||
} else {
|
||||
result = endpoint;
|
||||
}
|
||||
|
||||
if (hasValue(options.query)) {
|
||||
args.push(`query=${options.query}`);
|
||||
}
|
||||
|
||||
if (hasValue(options.metadata)) {
|
||||
args.push(`metadata=${options.metadata}`);
|
||||
}
|
||||
|
||||
if (hasValue(options.uuid)) {
|
||||
args.push(`uuid=${options.uuid}`);
|
||||
}
|
||||
|
||||
if (hasValue(options.currentPage) && typeof options.currentPage === 'number') {
|
||||
/* TODO: this is a temporary fix for the pagination start index (0 or 1) discrepancy between the rest and the frontend respectively */
|
||||
args.push(`page=${options.currentPage - 1}`);
|
||||
}
|
||||
|
||||
if (hasValue(options.elementsPerPage)) {
|
||||
args.push(`size=${options.elementsPerPage}`);
|
||||
}
|
||||
|
||||
if (hasValue(options.sort)) {
|
||||
args.push(`sort=${options.sort.field},${options.sort.direction}`);
|
||||
}
|
||||
|
||||
if (isNotEmpty(args)) {
|
||||
result = `${result}?${args.join('&')}`;
|
||||
}
|
||||
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).pipe(
|
||||
map((endpoint: string) => this.getEntriesHref(endpoint, options)),
|
||||
filter((href: string) => isNotEmpty(href)),
|
||||
distinctUntilChanged(),
|
||||
map((endpointURL: string) => new IntegrationRequest(this.requestService.generateRequestId(), endpointURL)),
|
||||
tap((request: GetRequest) => this.requestService.configure(request)),
|
||||
mergeMap((request: GetRequest) => this.getData(request)),
|
||||
distinctUntilChanged());
|
||||
}
|
||||
|
||||
public getEntryByValue(options: IntegrationSearchOptions): Observable<IntegrationData> {
|
||||
return this.halService.getEndpoint(this.linkPath).pipe(
|
||||
map((endpoint: string) => this.getEntryValueHref(endpoint, options)),
|
||||
filter((href: string) => isNotEmpty(href)),
|
||||
distinctUntilChanged(),
|
||||
map((endpointURL: string) => new IntegrationRequest(this.requestService.generateRequestId(), endpointURL)),
|
||||
tap((request: GetRequest) => this.requestService.configure(request)),
|
||||
mergeMap((request: GetRequest) => this.getData(request)),
|
||||
distinctUntilChanged());
|
||||
}
|
||||
|
||||
}
|
@@ -1,16 +0,0 @@
|
||||
export class AuthorityOptions {
|
||||
name: string;
|
||||
metadata: string;
|
||||
scope: string;
|
||||
closed: boolean;
|
||||
|
||||
constructor(name: string,
|
||||
metadata: string,
|
||||
scope: string,
|
||||
closed: boolean = false) {
|
||||
this.name = name;
|
||||
this.metadata = metadata;
|
||||
this.scope = scope;
|
||||
this.closed = closed;
|
||||
}
|
||||
}
|
@@ -1,10 +0,0 @@
|
||||
import { ResourceType } from '../../shared/resource-type';
|
||||
|
||||
/**
|
||||
* The resource type for AuthorityValue
|
||||
*
|
||||
* Needs to be in a separate file to prevent circular
|
||||
* dependencies in webpack.
|
||||
*/
|
||||
|
||||
export const AUTHORITY_VALUE = new ResourceType('authority');
|
@@ -1,92 +0,0 @@
|
||||
import { autoserialize, deserialize, inheritSerialization } from 'cerialize';
|
||||
import { isNotEmpty } from '../../../shared/empty.util';
|
||||
import { PLACEHOLDER_PARENT_METADATA } from '../../../shared/form/builder/ds-dynamic-form-ui/models/relation-group/dynamic-relation-group.model';
|
||||
import { OtherInformation } from '../../../shared/form/builder/models/form-field-metadata-value.model';
|
||||
import { typedObject } from '../../cache/builders/build-decorators';
|
||||
import { HALLink } from '../../shared/hal-link.model';
|
||||
import { MetadataValueInterface } from '../../shared/metadata.models';
|
||||
import { AUTHORITY_VALUE } from './authority.resource-type';
|
||||
import { IntegrationModel } from './integration.model';
|
||||
|
||||
/**
|
||||
* Class representing an authority object
|
||||
*/
|
||||
@typedObject
|
||||
@inheritSerialization(IntegrationModel)
|
||||
export class AuthorityValue extends IntegrationModel implements MetadataValueInterface {
|
||||
static type = AUTHORITY_VALUE;
|
||||
|
||||
/**
|
||||
* The identifier of this authority
|
||||
*/
|
||||
@autoserialize
|
||||
id: string;
|
||||
|
||||
/**
|
||||
* The display value of this authority
|
||||
*/
|
||||
@autoserialize
|
||||
display: string;
|
||||
|
||||
/**
|
||||
* The value of this authority
|
||||
*/
|
||||
@autoserialize
|
||||
value: string;
|
||||
|
||||
/**
|
||||
* An object containing additional information related to this authority
|
||||
*/
|
||||
@autoserialize
|
||||
otherInformation: OtherInformation;
|
||||
|
||||
/**
|
||||
* The language code of this authority value
|
||||
*/
|
||||
@autoserialize
|
||||
language: string;
|
||||
|
||||
/**
|
||||
* The {@link HALLink}s for this AuthorityValue
|
||||
*/
|
||||
@deserialize
|
||||
_links: {
|
||||
self: HALLink,
|
||||
};
|
||||
|
||||
/**
|
||||
* This method checks if authority has an identifier value
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
hasAuthority(): boolean {
|
||||
return isNotEmpty(this.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method checks if authority has a value
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
hasValue(): boolean {
|
||||
return isNotEmpty(this.value);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method checks if authority has related information object
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
hasOtherInformation(): boolean {
|
||||
return isNotEmpty(this.otherInformation);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method checks if authority has a placeholder as value
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
hasPlaceholder(): boolean {
|
||||
return this.hasValue() && this.value === PLACEHOLDER_PARENT_METADATA;
|
||||
}
|
||||
}
|
@@ -1,14 +0,0 @@
|
||||
import { SortOptions } from '../../cache/models/sort-options.model';
|
||||
|
||||
export class IntegrationSearchOptions {
|
||||
|
||||
constructor(public uuid: string = '',
|
||||
public name: string = '',
|
||||
public metadata: string = '',
|
||||
public query: string = '',
|
||||
public elementsPerPage?: number,
|
||||
public currentPage?: number,
|
||||
public sort?: SortOptions) {
|
||||
|
||||
}
|
||||
}
|
@@ -1,22 +0,0 @@
|
||||
import { autoserialize, deserialize } from 'cerialize';
|
||||
import { CacheableObject } from '../../cache/object-cache.reducer';
|
||||
import { HALLink } from '../../shared/hal-link.model';
|
||||
|
||||
export abstract class IntegrationModel implements CacheableObject {
|
||||
|
||||
@autoserialize
|
||||
self: string;
|
||||
|
||||
@autoserialize
|
||||
uuid: string;
|
||||
|
||||
@autoserialize
|
||||
public type: any;
|
||||
|
||||
@deserialize
|
||||
public _links: {
|
||||
self: HALLink,
|
||||
[name: string]: HALLink
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user