mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
Added http status text to rest response object and fixed tests
This commit is contained in:
@@ -1,14 +1,11 @@
|
|||||||
import { TestBed, fakeAsync, tick } from '@angular/core/testing';
|
import { TestBed } from '@angular/core/testing';
|
||||||
import { RouterTestingModule } from '@angular/router/testing';
|
import { RouterTestingModule } from '@angular/router/testing';
|
||||||
|
|
||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
import { SearchService } from './search.service';
|
import { SearchService } from './search.service';
|
||||||
import { ItemDataService } from './../../core/data/item-data.service';
|
|
||||||
import { ViewMode } from '../../+search-page/search-options.model';
|
import { ViewMode } from '../../+search-page/search-options.model';
|
||||||
import { RouteService } from '../../shared/services/route.service';
|
|
||||||
import { GLOBAL_CONFIG } from '../../../config';
|
|
||||||
import { RemoteDataBuildService } from '../../core/cache/builders/remote-data-build.service';
|
import { RemoteDataBuildService } from '../../core/cache/builders/remote-data-build.service';
|
||||||
import { ActivatedRoute, Router, UrlTree } from '@angular/router';
|
import { ActivatedRoute, Router, UrlTree } from '@angular/router';
|
||||||
import { RequestService } from '../../core/data/request.service';
|
import { RequestService } from '../../core/data/request.service';
|
||||||
@@ -17,19 +14,15 @@ import { ActivatedRouteStub } from '../../shared/testing/active-router-stub';
|
|||||||
import { RouterStub } from '../../shared/testing/router-stub';
|
import { RouterStub } from '../../shared/testing/router-stub';
|
||||||
import { HALEndpointService } from '../../core/shared/hal-endpoint.service';
|
import { HALEndpointService } from '../../core/shared/hal-endpoint.service';
|
||||||
import { Observable } from 'rxjs/Observable';
|
import { Observable } from 'rxjs/Observable';
|
||||||
|
import 'rxjs/add/observable/of';
|
||||||
|
import 'rxjs/add/observable/combineLatest';
|
||||||
import { PaginatedSearchOptions } from '../paginated-search-options.model';
|
import { PaginatedSearchOptions } from '../paginated-search-options.model';
|
||||||
import { RemoteData } from '../../core/data/remote-data';
|
import { RemoteData } from '../../core/data/remote-data';
|
||||||
import { PaginatedList } from '../../core/data/paginated-list';
|
|
||||||
import { SearchResult } from '../search-result.model';
|
|
||||||
import { DSpaceObject } from '../../core/shared/dspace-object.model';
|
|
||||||
import { ResponseCacheEntry } from '../../core/cache/response-cache.reducer';
|
import { ResponseCacheEntry } from '../../core/cache/response-cache.reducer';
|
||||||
import { RequestEntry } from '../../core/data/request.reducer';
|
import { RequestEntry } from '../../core/data/request.reducer';
|
||||||
import { getMockRequestService } from '../../shared/mocks/mock-request.service';
|
import { getMockRequestService } from '../../shared/mocks/mock-request.service';
|
||||||
import { getMockResponseCacheService } from '../../shared/mocks/mock-response-cache.service';
|
import { getMockResponseCacheService } from '../../shared/mocks/mock-response-cache.service';
|
||||||
import {
|
import { FacetConfigSuccessResponse, SearchSuccessResponse } from '../../core/cache/response-cache.models';
|
||||||
FacetConfigSuccessResponse, RestResponse,
|
|
||||||
SearchSuccessResponse
|
|
||||||
} from '../../core/cache/response-cache.models';
|
|
||||||
import { SearchQueryResponse } from './search-query-response.model';
|
import { SearchQueryResponse } from './search-query-response.model';
|
||||||
import { SearchFilterConfig } from './search-filter-config.model';
|
import { SearchFilterConfig } from './search-filter-config.model';
|
||||||
|
|
||||||
@@ -157,7 +150,7 @@ describe('SearchService', () => {
|
|||||||
const endPoint = 'http://endpoint.com/test/test';
|
const endPoint = 'http://endpoint.com/test/test';
|
||||||
const searchOptions = new PaginatedSearchOptions();
|
const searchOptions = new PaginatedSearchOptions();
|
||||||
const queryResponse = Object.assign(new SearchQueryResponse(), { objects: [] });
|
const queryResponse = Object.assign(new SearchQueryResponse(), { objects: [] });
|
||||||
const response = new SearchSuccessResponse(queryResponse, '200');
|
const response = new SearchSuccessResponse(queryResponse, 200,'OK');
|
||||||
const responseEntry = Object.assign(new ResponseCacheEntry(), { response: response });
|
const responseEntry = Object.assign(new ResponseCacheEntry(), { response: response });
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
spyOn((searchService as any).halService, 'getEndpoint').and.returnValue(Observable.of(endPoint));
|
spyOn((searchService as any).halService, 'getEndpoint').and.returnValue(Observable.of(endPoint));
|
||||||
@@ -187,7 +180,7 @@ describe('SearchService', () => {
|
|||||||
describe('when getConfig is called without a scope', () => {
|
describe('when getConfig is called without a scope', () => {
|
||||||
const endPoint = 'http://endpoint.com/test/config';
|
const endPoint = 'http://endpoint.com/test/config';
|
||||||
const filterConfig = [new SearchFilterConfig()];
|
const filterConfig = [new SearchFilterConfig()];
|
||||||
const response = new FacetConfigSuccessResponse(filterConfig, '200');
|
const response = new FacetConfigSuccessResponse(filterConfig, 200, 'OK');
|
||||||
const responseEntry = Object.assign(new ResponseCacheEntry(), { response: response });
|
const responseEntry = Object.assign(new ResponseCacheEntry(), { response: response });
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
spyOn((searchService as any).halService, 'getEndpoint').and.returnValue(Observable.of(endPoint));
|
spyOn((searchService as any).halService, 'getEndpoint').and.returnValue(Observable.of(endPoint));
|
||||||
@@ -219,7 +212,7 @@ describe('SearchService', () => {
|
|||||||
const scope = 'test';
|
const scope = 'test';
|
||||||
const requestUrl = endPoint + '?scope=' + scope;
|
const requestUrl = endPoint + '?scope=' + scope;
|
||||||
const filterConfig = [new SearchFilterConfig()];
|
const filterConfig = [new SearchFilterConfig()];
|
||||||
const response = new FacetConfigSuccessResponse(filterConfig, '200');
|
const response = new FacetConfigSuccessResponse(filterConfig, 200, 'OK');
|
||||||
const responseEntry = Object.assign(new ResponseCacheEntry(), { response: response });
|
const responseEntry = Object.assign(new ResponseCacheEntry(), { response: response });
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
spyOn((searchService as any).halService, 'getEndpoint').and.returnValue(Observable.of(endPoint));
|
spyOn((searchService as any).halService, 'getEndpoint').and.returnValue(Observable.of(endPoint));
|
||||||
|
@@ -40,12 +40,14 @@ describe('ConfigResponseParsingService', () => {
|
|||||||
expires: 1526318322000
|
expires: 1526318322000
|
||||||
},
|
},
|
||||||
} as AuthStatus,
|
} as AuthStatus,
|
||||||
statusCode: '200'
|
statusCode: 200,
|
||||||
|
statusText: '200'
|
||||||
};
|
};
|
||||||
|
|
||||||
const validResponse1 = {
|
const validResponse1 = {
|
||||||
payload: {},
|
payload: {},
|
||||||
statusCode: '404'
|
statusCode: 404,
|
||||||
|
statusText: '404'
|
||||||
};
|
};
|
||||||
|
|
||||||
const validResponse2 = {
|
const validResponse2 = {
|
||||||
@@ -95,7 +97,9 @@ describe('ConfigResponseParsingService', () => {
|
|||||||
self: 'https://hasselt-dspace.dev01.4science.it/dspace-spring-rest/api/authn/status'
|
self: 'https://hasselt-dspace.dev01.4science.it/dspace-spring-rest/api/authn/status'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
statusCode: '200'
|
statusCode: 200,
|
||||||
|
statusText: '200'
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
it('should return a AuthStatusResponse if data contains a valid AuthStatus object as payload', () => {
|
it('should return a AuthStatusResponse if data contains a valid AuthStatus object as payload', () => {
|
||||||
|
@@ -27,9 +27,9 @@ export class AuthResponseParsingService extends BaseResponseParsingService imple
|
|||||||
parse(request: RestRequest, data: DSpaceRESTV2Response): RestResponse {
|
parse(request: RestRequest, data: DSpaceRESTV2Response): RestResponse {
|
||||||
if (isNotEmpty(data.payload) && isNotEmpty(data.payload._links) && (data.statusCode === 200)) {
|
if (isNotEmpty(data.payload) && isNotEmpty(data.payload._links) && (data.statusCode === 200)) {
|
||||||
const response = this.process<AuthStatus, AuthType>(data.payload, request.href);
|
const response = this.process<AuthStatus, AuthType>(data.payload, request.href);
|
||||||
return new AuthStatusResponse(response[Object.keys(response)[0]][0], data.statusCode);
|
return new AuthStatusResponse(response[Object.keys(response)[0]][0], data.statusCode, data.statusText);
|
||||||
} else {
|
} else {
|
||||||
return new AuthStatusResponse(data.payload as AuthStatus, data.statusCode);
|
return new AuthStatusResponse(data.payload as AuthStatus, data.statusCode, data.statusText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -93,7 +93,7 @@ export class RemoteDataBuildService {
|
|||||||
isSuccessful = resEntry.response.isSuccessful;
|
isSuccessful = resEntry.response.isSuccessful;
|
||||||
const errorMessage = isSuccessful === false ? (resEntry.response as ErrorResponse).errorMessage : undefined;
|
const errorMessage = isSuccessful === false ? (resEntry.response as ErrorResponse).errorMessage : undefined;
|
||||||
if (hasValue(errorMessage)) {
|
if (hasValue(errorMessage)) {
|
||||||
error = new RemoteDataError(resEntry.response.statusCode.toString(), errorMessage);
|
error = new RemoteDataError((resEntry.response as ErrorResponse).statusText, errorMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,16 +226,16 @@ export class RemoteDataBuildService {
|
|||||||
}).filter((e: string) => hasValue(e))
|
}).filter((e: string) => hasValue(e))
|
||||||
.join(', ');
|
.join(', ');
|
||||||
|
|
||||||
const statusCode: string = arr
|
const statusText: string = arr
|
||||||
.map((d: RemoteData<T>) => d.error)
|
.map((d: RemoteData<T>) => d.error)
|
||||||
.map((e: RemoteDataError, idx: number) => {
|
.map((e: RemoteDataError, idx: number) => {
|
||||||
if (hasValue(e)) {
|
if (hasValue(e)) {
|
||||||
return `[${idx}]: ${e.statusCode}`;
|
return `[${idx}]: ${e.statusText}`;
|
||||||
}
|
}
|
||||||
}).filter((c: string) => hasValue(c))
|
}).filter((c: string) => hasValue(c))
|
||||||
.join(', ');
|
.join(', ');
|
||||||
|
|
||||||
const error = new RemoteDataError(statusCode, errorMessage);
|
const error = new RemoteDataError(statusText, errorMessage);
|
||||||
|
|
||||||
const payload: T[] = arr.map((d: RemoteData<T>) => d.payload);
|
const payload: T[] = arr.map((d: RemoteData<T>) => d.payload);
|
||||||
|
|
||||||
|
60
src/app/core/cache/response-cache.models.ts
vendored
60
src/app/core/cache/response-cache.models.ts
vendored
@@ -19,6 +19,7 @@ export class RestResponse {
|
|||||||
constructor(
|
constructor(
|
||||||
public isSuccessful: boolean,
|
public isSuccessful: boolean,
|
||||||
public statusCode: number,
|
public statusCode: number,
|
||||||
|
public statusText: string
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -27,9 +28,10 @@ export class DSOSuccessResponse extends RestResponse {
|
|||||||
constructor(
|
constructor(
|
||||||
public resourceSelfLinks: string[],
|
public resourceSelfLinks: string[],
|
||||||
public statusCode: number,
|
public statusCode: number,
|
||||||
|
public statusText: string,
|
||||||
public pageInfo?: PageInfo
|
public pageInfo?: PageInfo
|
||||||
) {
|
) {
|
||||||
super(true, statusCode);
|
super(true, statusCode, statusText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,9 +39,10 @@ export class RegistryMetadataschemasSuccessResponse extends RestResponse {
|
|||||||
constructor(
|
constructor(
|
||||||
public metadataschemasResponse: RegistryMetadataschemasResponse,
|
public metadataschemasResponse: RegistryMetadataschemasResponse,
|
||||||
public statusCode: number,
|
public statusCode: number,
|
||||||
|
public statusText: string,
|
||||||
public pageInfo?: PageInfo
|
public pageInfo?: PageInfo
|
||||||
) {
|
) {
|
||||||
super(true, statusCode);
|
super(true, statusCode, statusText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,9 +50,10 @@ export class RegistryMetadatafieldsSuccessResponse extends RestResponse {
|
|||||||
constructor(
|
constructor(
|
||||||
public metadatafieldsResponse: RegistryMetadatafieldsResponse,
|
public metadatafieldsResponse: RegistryMetadatafieldsResponse,
|
||||||
public statusCode: number,
|
public statusCode: number,
|
||||||
|
public statusText: string,
|
||||||
public pageInfo?: PageInfo
|
public pageInfo?: PageInfo
|
||||||
) {
|
) {
|
||||||
super(true, statusCode);
|
super(true, statusCode, statusText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,18 +61,20 @@ export class RegistryBitstreamformatsSuccessResponse extends RestResponse {
|
|||||||
constructor(
|
constructor(
|
||||||
public bitstreamformatsResponse: RegistryBitstreamformatsResponse,
|
public bitstreamformatsResponse: RegistryBitstreamformatsResponse,
|
||||||
public statusCode: number,
|
public statusCode: number,
|
||||||
|
public statusText: string,
|
||||||
public pageInfo?: PageInfo
|
public pageInfo?: PageInfo
|
||||||
) {
|
) {
|
||||||
super(true, statusCode);
|
super(true, statusCode, statusText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class MetadataschemaSuccessResponse extends RestResponse {
|
export class MetadataschemaSuccessResponse extends RestResponse {
|
||||||
constructor(
|
constructor(
|
||||||
public metadataschema: MetadataSchema,
|
public metadataschema: MetadataSchema,
|
||||||
public statusCode: number
|
public statusCode: number,
|
||||||
|
public statusText: string,
|
||||||
) {
|
) {
|
||||||
super(true, statusCode);
|
super(true, statusCode, statusText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,18 +82,20 @@ export class SearchSuccessResponse extends RestResponse {
|
|||||||
constructor(
|
constructor(
|
||||||
public results: SearchQueryResponse,
|
public results: SearchQueryResponse,
|
||||||
public statusCode: number,
|
public statusCode: number,
|
||||||
|
public statusText: string,
|
||||||
public pageInfo?: PageInfo
|
public pageInfo?: PageInfo
|
||||||
) {
|
) {
|
||||||
super(true, statusCode);
|
super(true, statusCode, statusText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class FacetConfigSuccessResponse extends RestResponse {
|
export class FacetConfigSuccessResponse extends RestResponse {
|
||||||
constructor(
|
constructor(
|
||||||
public results: SearchFilterConfig[],
|
public results: SearchFilterConfig[],
|
||||||
public statusCode: number
|
public statusCode: number,
|
||||||
|
public statusText: string,
|
||||||
) {
|
) {
|
||||||
super(true, statusCode);
|
super(true, statusCode, statusText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,8 +107,9 @@ export class FacetValueSuccessResponse extends RestResponse {
|
|||||||
constructor(
|
constructor(
|
||||||
public results: FacetValue[],
|
public results: FacetValue[],
|
||||||
public statusCode: number,
|
public statusCode: number,
|
||||||
|
public statusText: string,
|
||||||
public pageInfo?: PageInfo) {
|
public pageInfo?: PageInfo) {
|
||||||
super(true, statusCode);
|
super(true, statusCode, statusText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,8 +117,9 @@ export class FacetValueMapSuccessResponse extends RestResponse {
|
|||||||
constructor(
|
constructor(
|
||||||
public results: FacetValueMap,
|
public results: FacetValueMap,
|
||||||
public statusCode: number,
|
public statusCode: number,
|
||||||
|
public statusText: string
|
||||||
) {
|
) {
|
||||||
super(true, statusCode);
|
super(true, statusCode, statusText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,8 +131,9 @@ export class EndpointMapSuccessResponse extends RestResponse {
|
|||||||
constructor(
|
constructor(
|
||||||
public endpointMap: EndpointMap,
|
public endpointMap: EndpointMap,
|
||||||
public statusCode: number,
|
public statusCode: number,
|
||||||
|
public statusText: string
|
||||||
) {
|
) {
|
||||||
super(true, statusCode);
|
super(true, statusCode, statusText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,9 +141,10 @@ export class GenericSuccessResponse<T> extends RestResponse {
|
|||||||
constructor(
|
constructor(
|
||||||
public payload: T,
|
public payload: T,
|
||||||
public statusCode: number,
|
public statusCode: number,
|
||||||
|
public statusText: string,
|
||||||
public pageInfo?: PageInfo
|
public pageInfo?: PageInfo
|
||||||
) {
|
) {
|
||||||
super(true, statusCode);
|
super(true, statusCode, statusText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,7 +152,7 @@ export class ErrorResponse extends RestResponse {
|
|||||||
errorMessage: string;
|
errorMessage: string;
|
||||||
|
|
||||||
constructor(error: RequestError) {
|
constructor(error: RequestError) {
|
||||||
super(false, error.statusText);
|
super(false, error.statusCode, error.statusText);
|
||||||
console.error(error);
|
console.error(error);
|
||||||
this.errorMessage = error.message;
|
this.errorMessage = error.message;
|
||||||
}
|
}
|
||||||
@@ -150,9 +162,10 @@ export class ConfigSuccessResponse extends RestResponse {
|
|||||||
constructor(
|
constructor(
|
||||||
public configDefinition: ConfigObject[],
|
public configDefinition: ConfigObject[],
|
||||||
public statusCode: number,
|
public statusCode: number,
|
||||||
|
public statusText: string,
|
||||||
public pageInfo?: PageInfo
|
public pageInfo?: PageInfo
|
||||||
) {
|
) {
|
||||||
super(true, statusCode);
|
super(true, statusCode, statusText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,9 +174,10 @@ export class AuthStatusResponse extends RestResponse {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public response: AuthStatus,
|
public response: AuthStatus,
|
||||||
public statusCode: number
|
public statusCode: number,
|
||||||
|
public statusText: string,
|
||||||
) {
|
) {
|
||||||
super(true, statusCode);
|
super(true, statusCode, statusText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,9 +185,10 @@ export class IntegrationSuccessResponse extends RestResponse {
|
|||||||
constructor(
|
constructor(
|
||||||
public dataDefinition: IntegrationModel[],
|
public dataDefinition: IntegrationModel[],
|
||||||
public statusCode: number,
|
public statusCode: number,
|
||||||
|
public statusText: string,
|
||||||
public pageInfo?: PageInfo
|
public pageInfo?: PageInfo
|
||||||
) {
|
) {
|
||||||
super(true, statusCode);
|
super(true, statusCode, statusText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,9 +196,10 @@ export class PostPatchSuccessResponse extends RestResponse {
|
|||||||
constructor(
|
constructor(
|
||||||
public dataDefinition: any[],
|
public dataDefinition: any[],
|
||||||
public statusCode: number,
|
public statusCode: number,
|
||||||
|
public statusText: string,
|
||||||
public pageInfo?: PageInfo
|
public pageInfo?: PageInfo
|
||||||
) {
|
) {
|
||||||
super(true, statusCode);
|
super(true, statusCode, statusText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,9 +207,10 @@ export class SubmissionSuccessResponse extends RestResponse {
|
|||||||
constructor(
|
constructor(
|
||||||
public dataDefinition: Array<NormalizedObject | ConfigObject | string>,
|
public dataDefinition: Array<NormalizedObject | ConfigObject | string>,
|
||||||
public statusCode: number,
|
public statusCode: number,
|
||||||
|
public statusText: string,
|
||||||
public pageInfo?: PageInfo
|
public pageInfo?: PageInfo
|
||||||
) {
|
) {
|
||||||
super(true, statusCode);
|
super(true, statusCode, statusText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,9 +218,10 @@ export class EpersonSuccessResponse extends RestResponse {
|
|||||||
constructor(
|
constructor(
|
||||||
public epersonDefinition: NormalizedObject[],
|
public epersonDefinition: NormalizedObject[],
|
||||||
public statusCode: number,
|
public statusCode: number,
|
||||||
|
public statusText: string,
|
||||||
public pageInfo?: PageInfo
|
public pageInfo?: PageInfo
|
||||||
) {
|
) {
|
||||||
super(true, statusCode);
|
super(true, statusCode, statusText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -28,13 +28,13 @@ describe('responseCacheReducer', () => {
|
|||||||
const testState: ResponseCacheState = {
|
const testState: ResponseCacheState = {
|
||||||
[keys[0]]: {
|
[keys[0]]: {
|
||||||
key: keys[0],
|
key: keys[0],
|
||||||
response: new RestResponse(true, '200'),
|
response: new RestResponse(true, 200, 'OK'),
|
||||||
timeAdded: new Date().getTime(),
|
timeAdded: new Date().getTime(),
|
||||||
msToLive: msToLive
|
msToLive: msToLive
|
||||||
},
|
},
|
||||||
[keys[1]]: {
|
[keys[1]]: {
|
||||||
key: keys[1],
|
key: keys[1],
|
||||||
response: new RestResponse(true, '200'),
|
response: new RestResponse(true, 200, 'OK'),
|
||||||
timeAdded: new Date().getTime(),
|
timeAdded: new Date().getTime(),
|
||||||
msToLive: msToLive
|
msToLive: msToLive
|
||||||
}
|
}
|
||||||
@@ -65,7 +65,7 @@ describe('responseCacheReducer', () => {
|
|||||||
describe('ADD', () => {
|
describe('ADD', () => {
|
||||||
const addTimeAdded = new Date().getTime();
|
const addTimeAdded = new Date().getTime();
|
||||||
const addMsToLive = 5;
|
const addMsToLive = 5;
|
||||||
const addResponse = new RestResponse(true, '200');
|
const addResponse = new RestResponse(true, 200, 'OK');
|
||||||
const action = new ResponseCacheAddAction(keys[0], addResponse, addTimeAdded, addMsToLive);
|
const action = new ResponseCacheAddAction(keys[0], addResponse, addTimeAdded, addMsToLive);
|
||||||
|
|
||||||
it('should perform the action without affecting the previous state', () => {
|
it('should perform the action without affecting the previous state', () => {
|
||||||
|
@@ -2,6 +2,7 @@ import { Store } from '@ngrx/store';
|
|||||||
|
|
||||||
import { ResponseCacheService } from './response-cache.service';
|
import { ResponseCacheService } from './response-cache.service';
|
||||||
import { Observable } from 'rxjs/Observable';
|
import { Observable } from 'rxjs/Observable';
|
||||||
|
import 'rxjs/add/observable/of';
|
||||||
import { CoreState } from '../core.reducers';
|
import { CoreState } from '../core.reducers';
|
||||||
import { RestResponse } from './response-cache.models';
|
import { RestResponse } from './response-cache.models';
|
||||||
import { ResponseCacheEntry } from './response-cache.reducer';
|
import { ResponseCacheEntry } from './response-cache.reducer';
|
||||||
@@ -15,7 +16,7 @@ describe('ResponseCacheService', () => {
|
|||||||
const validCacheEntry = (key) => {
|
const validCacheEntry = (key) => {
|
||||||
return {
|
return {
|
||||||
key: key,
|
key: key,
|
||||||
response: new RestResponse(true, '200'),
|
response: new RestResponse(true, 200,'OK'),
|
||||||
timeAdded: timestamp,
|
timeAdded: timestamp,
|
||||||
msToLive: 24 * 60 * 60 * 1000 // a day
|
msToLive: 24 * 60 * 60 * 1000 // a day
|
||||||
}
|
}
|
||||||
@@ -23,7 +24,7 @@ describe('ResponseCacheService', () => {
|
|||||||
const invalidCacheEntry = (key) => {
|
const invalidCacheEntry = (key) => {
|
||||||
return {
|
return {
|
||||||
key: key,
|
key: key,
|
||||||
response: new RestResponse(true, '200'),
|
response: new RestResponse(true, 200,'OK'),
|
||||||
timeAdded: 0,
|
timeAdded: 0,
|
||||||
msToLive: 0
|
msToLive: 0
|
||||||
}
|
}
|
||||||
|
@@ -101,7 +101,8 @@ describe('BrowseEntriesResponseParsingService', () => {
|
|||||||
number: 0
|
number: 0
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
statusCode: '200'
|
statusCode: 200,
|
||||||
|
statusText: 'OK'
|
||||||
} as DSpaceRESTV2Response;
|
} as DSpaceRESTV2Response;
|
||||||
|
|
||||||
const invalidResponseNotAList = {
|
const invalidResponseNotAList = {
|
||||||
@@ -120,11 +121,12 @@ describe('BrowseEntriesResponseParsingService', () => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
statusCode: '200'
|
statusCode: 200,
|
||||||
|
statusText: 'OK'
|
||||||
} as DSpaceRESTV2Response;
|
} as DSpaceRESTV2Response;
|
||||||
|
|
||||||
const invalidResponseStatusCode = {
|
const invalidResponseStatusCode = {
|
||||||
payload: {}, statusCode: '500'
|
payload: {}, statusCode: 500, statusText: 'Internal Server Error'
|
||||||
} as DSpaceRESTV2Response;
|
} as DSpaceRESTV2Response;
|
||||||
|
|
||||||
it('should return a GenericSuccessResponse if data contains a valid browse entries response', () => {
|
it('should return a GenericSuccessResponse if data contains a valid browse entries response', () => {
|
||||||
|
@@ -34,12 +34,12 @@ export class BrowseEntriesResponseParsingService extends BaseResponseParsingServ
|
|||||||
&& Array.isArray(data.payload._embedded[Object.keys(data.payload._embedded)[0]])) {
|
&& Array.isArray(data.payload._embedded[Object.keys(data.payload._embedded)[0]])) {
|
||||||
const serializer = new DSpaceRESTv2Serializer(BrowseEntry);
|
const serializer = new DSpaceRESTv2Serializer(BrowseEntry);
|
||||||
const browseEntries = serializer.deserializeArray(data.payload._embedded[Object.keys(data.payload._embedded)[0]]);
|
const browseEntries = serializer.deserializeArray(data.payload._embedded[Object.keys(data.payload._embedded)[0]]);
|
||||||
return new GenericSuccessResponse(browseEntries, data.statusCode, this.processPageInfo(data.payload));
|
return new GenericSuccessResponse(browseEntries, data.statusCode, data.statusText, this.processPageInfo(data.payload));
|
||||||
} else {
|
} else {
|
||||||
return new ErrorResponse(
|
return new ErrorResponse(
|
||||||
Object.assign(
|
Object.assign(
|
||||||
new Error('Unexpected response from browse endpoint'),
|
new Error('Unexpected response from browse endpoint'),
|
||||||
{ statusText: data.statusCode }
|
{ statusCode: data.statusCode, statusText: data.statusText }
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -48,7 +48,7 @@ describe('BrowseResponseParsingService', () => {
|
|||||||
},
|
},
|
||||||
_links: { self: { href: 'https://rest.api/discover/browses' } },
|
_links: { self: { href: 'https://rest.api/discover/browses' } },
|
||||||
page: { size: 20, totalElements: 2, totalPages: 1, number: 0 }
|
page: { size: 20, totalElements: 2, totalPages: 1, number: 0 }
|
||||||
}, statusCode: '200'
|
}, statusCode: 200, statusText: 'OK'
|
||||||
} as DSpaceRESTV2Response;
|
} as DSpaceRESTV2Response;
|
||||||
|
|
||||||
const invalidResponse1 = {
|
const invalidResponse1 = {
|
||||||
@@ -71,21 +71,21 @@ describe('BrowseResponseParsingService', () => {
|
|||||||
},
|
},
|
||||||
_links: { self: { href: 'https://rest.api/discover/browses' } },
|
_links: { self: { href: 'https://rest.api/discover/browses' } },
|
||||||
page: { size: 20, totalElements: 2, totalPages: 1, number: 0 }
|
page: { size: 20, totalElements: 2, totalPages: 1, number: 0 }
|
||||||
}, statusCode: '200'
|
}, statusCode: 200, statusText: 'OK'
|
||||||
} as DSpaceRESTV2Response;
|
} as DSpaceRESTV2Response;
|
||||||
|
|
||||||
const invalidResponse2 = {
|
const invalidResponse2 = {
|
||||||
payload: {
|
payload: {
|
||||||
_links: { self: { href: 'https://rest.api/discover/browses' } },
|
_links: { self: { href: 'https://rest.api/discover/browses' } },
|
||||||
page: { size: 20, totalElements: 2, totalPages: 1, number: 0 }
|
page: { size: 20, totalElements: 2, totalPages: 1, number: 0 }
|
||||||
}, statusCode: '200'
|
}, statusCode: 200, statusText: 'OK'
|
||||||
} as DSpaceRESTV2Response ;
|
} as DSpaceRESTV2Response ;
|
||||||
|
|
||||||
const invalidResponse3 = {
|
const invalidResponse3 = {
|
||||||
payload: {
|
payload: {
|
||||||
_links: { self: { href: 'https://rest.api/discover/browses' } },
|
_links: { self: { href: 'https://rest.api/discover/browses' } },
|
||||||
page: { size: 20, totalElements: 2, totalPages: 1, number: 0 }
|
page: { size: 20, totalElements: 2, totalPages: 1, number: 0 }
|
||||||
}, statusCode: '500'
|
}, statusCode: 500, statusText: 'Internal Server Error'
|
||||||
} as DSpaceRESTV2Response;
|
} as DSpaceRESTV2Response;
|
||||||
|
|
||||||
const definitions = [
|
const definitions = [
|
||||||
|
@@ -15,12 +15,12 @@ export class BrowseResponseParsingService implements ResponseParsingService {
|
|||||||
&& Array.isArray(data.payload._embedded[Object.keys(data.payload._embedded)[0]])) {
|
&& Array.isArray(data.payload._embedded[Object.keys(data.payload._embedded)[0]])) {
|
||||||
const serializer = new DSpaceRESTv2Serializer(BrowseDefinition);
|
const serializer = new DSpaceRESTv2Serializer(BrowseDefinition);
|
||||||
const browseDefinitions = serializer.deserializeArray(data.payload._embedded[Object.keys(data.payload._embedded)[0]]);
|
const browseDefinitions = serializer.deserializeArray(data.payload._embedded[Object.keys(data.payload._embedded)[0]]);
|
||||||
return new GenericSuccessResponse(browseDefinitions, data.statusCode);
|
return new GenericSuccessResponse(browseDefinitions, data.statusCode, data.statusText);
|
||||||
} else {
|
} else {
|
||||||
return new ErrorResponse(
|
return new ErrorResponse(
|
||||||
Object.assign(
|
Object.assign(
|
||||||
new Error('Unexpected response from browse endpoint'),
|
new Error('Unexpected response from browse endpoint'),
|
||||||
{ statusText: data.statusCode }
|
{ statusCode: data.statusCode, statusText: data.statusText }
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -121,12 +121,14 @@ describe('ConfigResponseParsingService', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
statusCode:'200'
|
statusCode: 200,
|
||||||
|
statusText: 'OK'
|
||||||
};
|
};
|
||||||
|
|
||||||
const invalidResponse1 = {
|
const invalidResponse1 = {
|
||||||
payload: {},
|
payload: {},
|
||||||
statusCode:'200'
|
statusCode: 200,
|
||||||
|
statusText: 'OK'
|
||||||
};
|
};
|
||||||
|
|
||||||
const invalidResponse2 = {
|
const invalidResponse2 = {
|
||||||
@@ -150,14 +152,15 @@ describe('ConfigResponseParsingService', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
statusCode:'200'
|
statusCode: 200,
|
||||||
|
statusText: 'OK'
|
||||||
};
|
};
|
||||||
|
|
||||||
const invalidResponse3 = {
|
const invalidResponse3 = {
|
||||||
payload: {
|
payload: {
|
||||||
_links: { self: { href: 'https://rest.api/config/submissiondefinitions/traditional' } },
|
_links: { self: { href: 'https://rest.api/config/submissiondefinitions/traditional' } },
|
||||||
page: { size: 20, totalElements: 2, totalPages: 1, number: 0 }
|
page: { size: 20, totalElements: 2, totalPages: 1, number: 0 }
|
||||||
}, statusCode: '500'
|
}, statusCode: 500, statusText: 'Internal Server Error'
|
||||||
};
|
};
|
||||||
|
|
||||||
const definitions = [
|
const definitions = [
|
||||||
|
@@ -29,12 +29,12 @@ export class ConfigResponseParsingService extends BaseResponseParsingService imp
|
|||||||
parse(request: RestRequest, data: DSpaceRESTV2Response): RestResponse {
|
parse(request: RestRequest, data: DSpaceRESTV2Response): RestResponse {
|
||||||
if (isNotEmpty(data.payload) && isNotEmpty(data.payload._links) && (data.statusCode === 201 || data.statusCode === 200)) {
|
if (isNotEmpty(data.payload) && isNotEmpty(data.payload._links) && (data.statusCode === 201 || data.statusCode === 200)) {
|
||||||
const configDefinition = this.process<ConfigObject,ConfigType>(data.payload, request.href);
|
const configDefinition = this.process<ConfigObject,ConfigType>(data.payload, request.href);
|
||||||
return new ConfigSuccessResponse(configDefinition[Object.keys(configDefinition)[0]], data.statusCode, this.processPageInfo(data.payload));
|
return new ConfigSuccessResponse(configDefinition[Object.keys(configDefinition)[0]], data.statusCode, data.statusText, this.processPageInfo(data.payload));
|
||||||
} else {
|
} else {
|
||||||
return new ErrorResponse(
|
return new ErrorResponse(
|
||||||
Object.assign(
|
Object.assign(
|
||||||
new Error('Unexpected response from config endpoint'),
|
new Error('Unexpected response from config endpoint'),
|
||||||
{ statusText: data.statusCode }
|
{ statusCode: data.statusCode, statusText: data.statusText }
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -28,7 +28,7 @@ export class DSOResponseParsingService extends BaseResponseParsingService implem
|
|||||||
parse(request: RestRequest, data: DSpaceRESTV2Response): RestResponse {
|
parse(request: RestRequest, data: DSpaceRESTV2Response): RestResponse {
|
||||||
const processRequestDTO = this.process<NormalizedObject,ResourceType>(data.payload, request.href);
|
const processRequestDTO = this.process<NormalizedObject,ResourceType>(data.payload, request.href);
|
||||||
const selfLinks = this.flattenSingleKeyObject(processRequestDTO).map((no) => no.self);
|
const selfLinks = this.flattenSingleKeyObject(processRequestDTO).map((no) => no.self);
|
||||||
return new DSOSuccessResponse(selfLinks, data.statusCode, this.processPageInfo(data.payload))
|
return new DSOSuccessResponse(selfLinks, data.statusCode, data.statusText, this.processPageInfo(data.payload))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -20,12 +20,12 @@ export class EndpointMapResponseParsingService implements ResponseParsingService
|
|||||||
for (const link of Object.keys(links)) {
|
for (const link of Object.keys(links)) {
|
||||||
links[link] = links[link].href;
|
links[link] = links[link].href;
|
||||||
}
|
}
|
||||||
return new EndpointMapSuccessResponse(links, data.statusCode);
|
return new EndpointMapSuccessResponse(links, data.statusCode, data.statusText);
|
||||||
} else {
|
} else {
|
||||||
return new ErrorResponse(
|
return new ErrorResponse(
|
||||||
Object.assign(
|
Object.assign(
|
||||||
new Error('Unexpected response from root endpoint'),
|
new Error('Unexpected response from root endpoint'),
|
||||||
{ statusText: data.statusCode }
|
{ statusCode: data.statusCode, statusText: data.statusText }
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -27,6 +27,6 @@ export class FacetConfigResponseParsingService extends BaseResponseParsingServic
|
|||||||
const config = data.payload._embedded.facets;
|
const config = data.payload._embedded.facets;
|
||||||
const serializer = new DSpaceRESTv2Serializer(SearchFilterConfig);
|
const serializer = new DSpaceRESTv2Serializer(SearchFilterConfig);
|
||||||
const facetConfig = serializer.deserializeArray(config);
|
const facetConfig = serializer.deserializeArray(config);
|
||||||
return new FacetConfigSuccessResponse(facetConfig, data.statusCode);
|
return new FacetConfigSuccessResponse(facetConfig, data.statusCode, data.statusText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -37,10 +37,10 @@ export class FacetValueMapResponseParsingService extends BaseResponseParsingServ
|
|||||||
payload._embedded.facets.map((facet) => {
|
payload._embedded.facets.map((facet) => {
|
||||||
const values = facet._embedded.values.map((value) => {value.search = value._links.search.href; return value;});
|
const values = facet._embedded.values.map((value) => {value.search = value._links.search.href; return value;});
|
||||||
const facetValues = serializer.deserializeArray(values);
|
const facetValues = serializer.deserializeArray(values);
|
||||||
const valuesResponse = new FacetValueSuccessResponse(facetValues, data.statusCode, this.processPageInfo(data.payload));
|
const valuesResponse = new FacetValueSuccessResponse(facetValues, data.statusCode, data.statusText, this.processPageInfo(data.payload));
|
||||||
facetMap[facet.name] = valuesResponse;
|
facetMap[facet.name] = valuesResponse;
|
||||||
});
|
});
|
||||||
|
|
||||||
return new FacetValueMapSuccessResponse(facetMap, data.statusCode);
|
return new FacetValueMapSuccessResponse(facetMap, data.statusCode, data.statusText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -33,6 +33,6 @@ export class FacetValueResponseParsingService extends BaseResponseParsingService
|
|||||||
// const values = payload._embedded.values.map((value) => {value.search = value._links.search.href; return value;});
|
// const values = payload._embedded.values.map((value) => {value.search = value._links.search.href; return value;});
|
||||||
|
|
||||||
const facetValues = serializer.deserializeArray(payload._embedded.values);
|
const facetValues = serializer.deserializeArray(payload._embedded.values);
|
||||||
return new FacetValueSuccessResponse(facetValues, data.statusCode, this.processPageInfo(data.payload));
|
return new FacetValueSuccessResponse(facetValues, data.statusCode, data.statusText, this.processPageInfo(data.payload));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -13,7 +13,7 @@ export class MetadataschemaParsingService implements ResponseParsingService {
|
|||||||
const payload = data.payload;
|
const payload = data.payload;
|
||||||
|
|
||||||
const deserialized = new DSpaceRESTv2Serializer(MetadataSchema).deserialize(payload);
|
const deserialized = new DSpaceRESTv2Serializer(MetadataSchema).deserialize(payload);
|
||||||
return new MetadataschemaSuccessResponse(deserialized, data.statusCode);
|
return new MetadataschemaSuccessResponse(deserialized, data.statusCode, data.statusText);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -19,7 +19,7 @@ export class RegistryBitstreamformatsResponseParsingService implements ResponseP
|
|||||||
payload.bitstreamformats = bitstreamformats;
|
payload.bitstreamformats = bitstreamformats;
|
||||||
|
|
||||||
const deserialized = new DSpaceRESTv2Serializer(RegistryBitstreamformatsResponse).deserialize(payload);
|
const deserialized = new DSpaceRESTv2Serializer(RegistryBitstreamformatsResponse).deserialize(payload);
|
||||||
return new RegistryBitstreamformatsSuccessResponse(deserialized, data.statusCode, this.dsoParser.processPageInfo(data.payload.page));
|
return new RegistryBitstreamformatsSuccessResponse(deserialized, data.statusCode, data.statusText, this.dsoParser.processPageInfo(data.payload.page));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -28,7 +28,7 @@ export class RegistryMetadatafieldsResponseParsingService implements ResponsePar
|
|||||||
payload.metadatafields = metadatafields;
|
payload.metadatafields = metadatafields;
|
||||||
|
|
||||||
const deserialized = new DSpaceRESTv2Serializer(RegistryMetadatafieldsResponse).deserialize(payload);
|
const deserialized = new DSpaceRESTv2Serializer(RegistryMetadatafieldsResponse).deserialize(payload);
|
||||||
return new RegistryMetadatafieldsSuccessResponse(deserialized, data.statusCode, this.dsoParser.processPageInfo(data.payload.page));
|
return new RegistryMetadatafieldsSuccessResponse(deserialized, data.statusCode, data.statusText, this.dsoParser.processPageInfo(data.payload.page));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -19,7 +19,7 @@ export class RegistryMetadataschemasResponseParsingService implements ResponsePa
|
|||||||
payload.metadataschemas = metadataschemas;
|
payload.metadataschemas = metadataschemas;
|
||||||
|
|
||||||
const deserialized = new DSpaceRESTv2Serializer(RegistryMetadataschemasResponse).deserialize(payload);
|
const deserialized = new DSpaceRESTv2Serializer(RegistryMetadataschemasResponse).deserialize(payload);
|
||||||
return new RegistryMetadataschemasSuccessResponse(deserialized, data.statusCode, this.dsoParser.processPageInfo(data.payload.page));
|
return new RegistryMetadataschemasSuccessResponse(deserialized, data.statusCode, data.statusText, this.dsoParser.processPageInfo(data.payload.page));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
export class RemoteDataError {
|
export class RemoteDataError {
|
||||||
constructor(
|
constructor(
|
||||||
public statusCode: string,
|
public statusText: string,
|
||||||
public message: string
|
public message: string
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
@@ -303,6 +303,7 @@ export class EpersonRequest extends GetRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class RequestError extends Error {
|
export class RequestError extends Error {
|
||||||
statusText: number;
|
statusCode: number;
|
||||||
|
statusText: string;
|
||||||
}
|
}
|
||||||
/* tslint:enable:max-classes-per-file */
|
/* tslint:enable:max-classes-per-file */
|
||||||
|
@@ -39,7 +39,8 @@ export class SearchResponseParsingService implements ResponseParsingService {
|
|||||||
.map((dso) => Object.assign({}, dso, { _embedded: undefined }))
|
.map((dso) => Object.assign({}, dso, { _embedded: undefined }))
|
||||||
.map((dso) => this.dsoParser.parse(request, {
|
.map((dso) => this.dsoParser.parse(request, {
|
||||||
payload: dso,
|
payload: dso,
|
||||||
statusCode: data.statusCode
|
statusCode: data.statusCode,
|
||||||
|
statusText: data.statusText
|
||||||
}))
|
}))
|
||||||
.map((obj) => obj.resourceSelfLinks)
|
.map((obj) => obj.resourceSelfLinks)
|
||||||
.reduce((combined, thisElement) => [...combined, ...thisElement], []);
|
.reduce((combined, thisElement) => [...combined, ...thisElement], []);
|
||||||
@@ -56,6 +57,6 @@ export class SearchResponseParsingService implements ResponseParsingService {
|
|||||||
}));
|
}));
|
||||||
payload.objects = objects;
|
payload.objects = objects;
|
||||||
const deserialized = new DSpaceRESTv2Serializer(SearchQueryResponse).deserialize(payload);
|
const deserialized = new DSpaceRESTv2Serializer(SearchQueryResponse).deserialize(payload);
|
||||||
return new SearchSuccessResponse(deserialized, data.statusCode, this.dsoParser.processPageInfo(data.payload));
|
return new SearchSuccessResponse(deserialized, data.statusCode, data.statusText, this.dsoParser.processPageInfo(data.payload));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -8,5 +8,6 @@ export interface DSpaceRESTV2Response {
|
|||||||
page?: any;
|
page?: any;
|
||||||
},
|
},
|
||||||
headers?: HttpHeaders,
|
headers?: HttpHeaders,
|
||||||
statusCode: number
|
statusCode: number,
|
||||||
|
statusText: string
|
||||||
}
|
}
|
||||||
|
@@ -30,17 +30,19 @@ describe('DSpaceRESTv2Service', () => {
|
|||||||
const mockPayload = {
|
const mockPayload = {
|
||||||
page: 1
|
page: 1
|
||||||
};
|
};
|
||||||
const mockStatusCode = 'GREAT';
|
const mockStatusCode = 200;
|
||||||
|
const mockStatusText = 'GREAT';
|
||||||
|
|
||||||
dSpaceRESTv2Service.get(url).subscribe((response) => {
|
dSpaceRESTv2Service.get(url).subscribe((response) => {
|
||||||
expect(response).toBeTruthy();
|
expect(response).toBeTruthy();
|
||||||
expect(response.statusCode).toEqual(mockStatusCode);
|
expect(response.statusCode).toEqual(mockStatusCode);
|
||||||
|
expect(response.statusText).toEqual(mockStatusText);
|
||||||
expect(response.payload.page).toEqual(mockPayload.page);
|
expect(response.payload.page).toEqual(mockPayload.page);
|
||||||
});
|
});
|
||||||
|
|
||||||
const req = httpMock.expectOne(url);
|
const req = httpMock.expectOne(url);
|
||||||
expect(req.request.method).toBe('GET');
|
expect(req.request.method).toBe('GET');
|
||||||
req.flush(mockPayload, { statusText: mockStatusCode});
|
req.flush(mockPayload, { status: mockStatusCode, statusText: mockStatusText});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -1,5 +1,4 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { Request } from '@angular/http';
|
|
||||||
import { HttpClient, HttpHeaders, HttpParams, HttpResponse } from '@angular/common/http'
|
import { HttpClient, HttpHeaders, HttpParams, HttpResponse } from '@angular/common/http'
|
||||||
import { Observable } from 'rxjs/Observable';
|
import { Observable } from 'rxjs/Observable';
|
||||||
import { RestRequestMethod } from '../data/request.models';
|
import { RestRequestMethod } from '../data/request.models';
|
||||||
@@ -37,7 +36,7 @@ export class DSpaceRESTv2Service {
|
|||||||
*/
|
*/
|
||||||
get(absoluteURL: string): Observable<DSpaceRESTV2Response> {
|
get(absoluteURL: string): Observable<DSpaceRESTV2Response> {
|
||||||
return this.http.get(absoluteURL, { observe: 'response' })
|
return this.http.get(absoluteURL, { observe: 'response' })
|
||||||
.map((res: HttpResponse<any>) => ({ payload: res.body, statusCode: res.statusText }))
|
.map((res: HttpResponse<any>) => ({ payload: res.body, statusCode: res.status, statusText: res.statusText }))
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.log('Error: ', err);
|
console.log('Error: ', err);
|
||||||
return Observable.throw(err);
|
return Observable.throw(err);
|
||||||
@@ -67,7 +66,7 @@ export class DSpaceRESTv2Service {
|
|||||||
requestOptions.responseType = options.responseType;
|
requestOptions.responseType = options.responseType;
|
||||||
}
|
}
|
||||||
return this.http.request(method, url, requestOptions)
|
return this.http.request(method, url, requestOptions)
|
||||||
.map((res) => ({ payload: res.body, headers: res.headers, statusCode: res.status }))
|
.map((res) => ({ payload: res.body, headers: res.headers, statusCode: res.status, statusText: res.statusText }))
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.log('Error: ', err);
|
console.log('Error: ', err);
|
||||||
return Observable.throw(err);
|
return Observable.throw(err);
|
||||||
|
@@ -29,12 +29,12 @@ export class EpersonResponseParsingService extends BaseResponseParsingService im
|
|||||||
parse(request: RestRequest, data: DSpaceRESTV2Response): RestResponse {
|
parse(request: RestRequest, data: DSpaceRESTV2Response): RestResponse {
|
||||||
if (isNotEmpty(data.payload) && isNotEmpty(data.payload._links)) {
|
if (isNotEmpty(data.payload) && isNotEmpty(data.payload._links)) {
|
||||||
const epersonDefinition = this.process<NormalizedObject,ResourceType>(data.payload, request.href);
|
const epersonDefinition = this.process<NormalizedObject,ResourceType>(data.payload, request.href);
|
||||||
return new EpersonSuccessResponse(epersonDefinition[Object.keys(epersonDefinition)[0]], data.statusCode, this.processPageInfo(data.payload));
|
return new EpersonSuccessResponse(epersonDefinition[Object.keys(epersonDefinition)[0]], data.statusCode, data.statusText, this.processPageInfo(data.payload));
|
||||||
} else {
|
} else {
|
||||||
return new ErrorResponse(
|
return new ErrorResponse(
|
||||||
Object.assign(
|
Object.assign(
|
||||||
new Error('Unexpected response from EPerson endpoint'),
|
new Error('Unexpected response from EPerson endpoint'),
|
||||||
{statusText: data.statusCode}
|
{statusCode: data.statusCode, statusText: data.statusText}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -22,14 +22,20 @@ describe('IntegrationResponseParsingService', () => {
|
|||||||
const integrationEndpoint = 'https://rest.api/integration/authorities';
|
const integrationEndpoint = 'https://rest.api/integration/authorities';
|
||||||
const entriesEndpoint = `${integrationEndpoint}/${name}/entries?query=${query}&metadata=${metadata}&uuid=${uuid}`;
|
const entriesEndpoint = `${integrationEndpoint}/${name}/entries?query=${query}&metadata=${metadata}&uuid=${uuid}`;
|
||||||
|
|
||||||
|
let validRequest;
|
||||||
|
|
||||||
|
let validResponse;
|
||||||
|
|
||||||
|
let invalidResponse1;
|
||||||
|
|
||||||
|
let invalidResponse2;
|
||||||
|
|
||||||
|
let definitions;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
service = new IntegrationResponseParsingService(EnvConfig, objectCacheService);
|
service = new IntegrationResponseParsingService(EnvConfig, objectCacheService);
|
||||||
});
|
validRequest = new IntegrationRequest('69f375b5-19f4-4453-8c7a-7dc5c55aafbb', entriesEndpoint);
|
||||||
|
validResponse = {
|
||||||
describe('parse', () => {
|
|
||||||
const validRequest = new IntegrationRequest('69f375b5-19f4-4453-8c7a-7dc5c55aafbb', entriesEndpoint);
|
|
||||||
|
|
||||||
const validResponse = {
|
|
||||||
payload: {
|
payload: {
|
||||||
page: {
|
page: {
|
||||||
number: 0,
|
number: 0,
|
||||||
@@ -81,15 +87,15 @@ describe('IntegrationResponseParsingService', () => {
|
|||||||
self: 'https://rest.api/integration/authorities/type/entries'
|
self: 'https://rest.api/integration/authorities/type/entries'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
statusCode: '200'
|
statusCode: 200,
|
||||||
|
statusText: 'OK'
|
||||||
};
|
};
|
||||||
|
invalidResponse1 = {
|
||||||
const invalidResponse1 = {
|
|
||||||
payload: {},
|
payload: {},
|
||||||
statusCode: '200'
|
statusCode: 400,
|
||||||
|
statusText: 'Bad Request'
|
||||||
};
|
};
|
||||||
|
invalidResponse2 = {
|
||||||
const invalidResponse2 = {
|
|
||||||
payload: {
|
payload: {
|
||||||
page: {
|
page: {
|
||||||
number: 0,
|
number: 0,
|
||||||
@@ -139,10 +145,10 @@ describe('IntegrationResponseParsingService', () => {
|
|||||||
},
|
},
|
||||||
_links: {}
|
_links: {}
|
||||||
},
|
},
|
||||||
statusCode: '200'
|
statusCode: 500,
|
||||||
|
statusText: 'Internal Server Error'
|
||||||
};
|
};
|
||||||
|
definitions = [
|
||||||
const definitions = [
|
|
||||||
Object.assign(new AuthorityValueModel(), {
|
Object.assign(new AuthorityValueModel(), {
|
||||||
display: 'One',
|
display: 'One',
|
||||||
id: 'One',
|
id: 'One',
|
||||||
@@ -174,6 +180,9 @@ describe('IntegrationResponseParsingService', () => {
|
|||||||
value: 'Five'
|
value: 'Five'
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('parse', () => {
|
||||||
|
|
||||||
it('should return a IntegrationSuccessResponse if data contains a valid endpoint response', () => {
|
it('should return a IntegrationSuccessResponse if data contains a valid endpoint response', () => {
|
||||||
const response = service.parse(validRequest, validResponse);
|
const response = service.parse(validRequest, validResponse);
|
||||||
|
@@ -32,13 +32,14 @@ export class IntegrationResponseParsingService extends BaseResponseParsingServic
|
|||||||
|
|
||||||
parse(request: RestRequest, data: DSpaceRESTV2Response): RestResponse {
|
parse(request: RestRequest, data: DSpaceRESTV2Response): RestResponse {
|
||||||
if (isNotEmpty(data.payload) && isNotEmpty(data.payload._links)) {
|
if (isNotEmpty(data.payload) && isNotEmpty(data.payload._links)) {
|
||||||
|
console.log(request);
|
||||||
const dataDefinition = this.process<IntegrationModel,IntegrationType>(data.payload, request.href);
|
const dataDefinition = this.process<IntegrationModel,IntegrationType>(data.payload, request.href);
|
||||||
return new IntegrationSuccessResponse(dataDefinition[Object.keys(dataDefinition)[0]], data.statusCode, this.processPageInfo(data.payload));
|
return new IntegrationSuccessResponse(dataDefinition[Object.keys(dataDefinition)[0]], data.statusCode, data.statusText, this.processPageInfo(data.payload));
|
||||||
} else {
|
} else {
|
||||||
return new ErrorResponse(
|
return new ErrorResponse(
|
||||||
Object.assign(
|
Object.assign(
|
||||||
new Error('Unexpected response from Integration endpoint'),
|
new Error('Unexpected response from Integration endpoint'),
|
||||||
{statusText: data.statusCode}
|
{statusCode: data.statusCode, statusText: data.statusText}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { async, TestBed } from '@angular/core/testing';
|
import { TestBed } from '@angular/core/testing';
|
||||||
import { RegistryService } from './registry.service';
|
import { RegistryService } from './registry.service';
|
||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
import { ResponseCacheService } from '../cache/response-cache.service';
|
import { ResponseCacheService } from '../cache/response-cache.service';
|
||||||
@@ -7,21 +7,19 @@ import { RemoteDataBuildService } from '../cache/builders/remote-data-build.serv
|
|||||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||||
import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model';
|
import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model';
|
||||||
import { Observable } from 'rxjs/Observable';
|
import { Observable } from 'rxjs/Observable';
|
||||||
|
import 'rxjs/add/observable/of';
|
||||||
|
import 'rxjs/add/observable/combineLatest';
|
||||||
import { ResponseCacheEntry } from '../cache/response-cache.reducer';
|
import { ResponseCacheEntry } from '../cache/response-cache.reducer';
|
||||||
import { RequestEntry } from '../data/request.reducer';
|
import { RequestEntry } from '../data/request.reducer';
|
||||||
import { RemoteData } from '../data/remote-data';
|
import { RemoteData } from '../data/remote-data';
|
||||||
import { PaginatedList } from '../data/paginated-list';
|
|
||||||
import { PageInfo } from '../shared/page-info.model';
|
import { PageInfo } from '../shared/page-info.model';
|
||||||
import { GetRequest } from '../data/request.models';
|
|
||||||
import { URLCombiner } from '../url-combiner/url-combiner';
|
|
||||||
import { getMockRequestService } from '../../shared/mocks/mock-request.service';
|
import { getMockRequestService } from '../../shared/mocks/mock-request.service';
|
||||||
import { getMockResponseCacheService } from '../../shared/mocks/mock-response-cache.service';
|
import { getMockResponseCacheService } from '../../shared/mocks/mock-response-cache.service';
|
||||||
import {
|
import {
|
||||||
RegistryBitstreamformatsSuccessResponse,
|
RegistryBitstreamformatsSuccessResponse,
|
||||||
RegistryMetadatafieldsSuccessResponse, RegistryMetadataschemasSuccessResponse,
|
RegistryMetadatafieldsSuccessResponse,
|
||||||
SearchSuccessResponse
|
RegistryMetadataschemasSuccessResponse
|
||||||
} from '../cache/response-cache.models';
|
} from '../cache/response-cache.models';
|
||||||
import { SearchQueryResponse } from '../../+search-page/search-service/search-query-response.model';
|
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import { RegistryMetadataschemasResponse } from './registry-metadataschemas-response.model';
|
import { RegistryMetadataschemasResponse } from './registry-metadataschemas-response.model';
|
||||||
import { RegistryMetadatafieldsResponse } from './registry-metadatafields-response.model';
|
import { RegistryMetadatafieldsResponse } from './registry-metadatafields-response.model';
|
||||||
@@ -161,7 +159,7 @@ describe('RegistryService', () => {
|
|||||||
|
|
||||||
describe('when requesting metadataschemas', () => {
|
describe('when requesting metadataschemas', () => {
|
||||||
const queryResponse = Object.assign(new RegistryMetadataschemasResponse(), { metadataschemas: mockSchemasList, page: pageInfo });
|
const queryResponse = Object.assign(new RegistryMetadataschemasResponse(), { metadataschemas: mockSchemasList, page: pageInfo });
|
||||||
const response = new RegistryMetadataschemasSuccessResponse(queryResponse, '200', pageInfo);
|
const response = new RegistryMetadataschemasSuccessResponse(queryResponse, 200, 'OK', pageInfo);
|
||||||
const responseEntry = Object.assign(new ResponseCacheEntry(), { response: response });
|
const responseEntry = Object.assign(new ResponseCacheEntry(), { response: response });
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@@ -191,7 +189,7 @@ describe('RegistryService', () => {
|
|||||||
|
|
||||||
describe('when requesting metadataschema by name', () => {
|
describe('when requesting metadataschema by name', () => {
|
||||||
const queryResponse = Object.assign(new RegistryMetadataschemasResponse(), { metadataschemas: mockSchemasList, page: pageInfo });
|
const queryResponse = Object.assign(new RegistryMetadataschemasResponse(), { metadataschemas: mockSchemasList, page: pageInfo });
|
||||||
const response = new RegistryMetadataschemasSuccessResponse(queryResponse, '200', pageInfo);
|
const response = new RegistryMetadataschemasSuccessResponse(queryResponse, 200, 'OK', pageInfo);
|
||||||
const responseEntry = Object.assign(new ResponseCacheEntry(), { response: response });
|
const responseEntry = Object.assign(new ResponseCacheEntry(), { response: response });
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@@ -221,7 +219,7 @@ describe('RegistryService', () => {
|
|||||||
|
|
||||||
describe('when requesting metadatafields', () => {
|
describe('when requesting metadatafields', () => {
|
||||||
const queryResponse = Object.assign(new RegistryMetadatafieldsResponse(), { metadatafields: mockFieldsList, page: pageInfo });
|
const queryResponse = Object.assign(new RegistryMetadatafieldsResponse(), { metadatafields: mockFieldsList, page: pageInfo });
|
||||||
const response = new RegistryMetadatafieldsSuccessResponse(queryResponse, '200', pageInfo);
|
const response = new RegistryMetadatafieldsSuccessResponse(queryResponse, 200, 'OK', pageInfo);
|
||||||
const responseEntry = Object.assign(new ResponseCacheEntry(), { response: response });
|
const responseEntry = Object.assign(new ResponseCacheEntry(), { response: response });
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@@ -251,7 +249,7 @@ describe('RegistryService', () => {
|
|||||||
|
|
||||||
describe('when requesting bitstreamformats', () => {
|
describe('when requesting bitstreamformats', () => {
|
||||||
const queryResponse = Object.assign(new RegistryBitstreamformatsResponse(), { bitstreamformats: mockFieldsList, page: pageInfo });
|
const queryResponse = Object.assign(new RegistryBitstreamformatsResponse(), { bitstreamformats: mockFieldsList, page: pageInfo });
|
||||||
const response = new RegistryBitstreamformatsSuccessResponse(queryResponse, '200', pageInfo);
|
const response = new RegistryBitstreamformatsSuccessResponse(queryResponse, 200, 'OK', pageInfo);
|
||||||
const responseEntry = Object.assign(new ResponseCacheEntry(), { response: response });
|
const responseEntry = Object.assign(new ResponseCacheEntry(), { response: response });
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@@ -35,15 +35,15 @@ export class SubmissionResponseParsingService extends BaseResponseParsingService
|
|||||||
&& isNotEmpty(data.payload._links)
|
&& isNotEmpty(data.payload._links)
|
||||||
&& (data.statusCode === 201 || data.statusCode === 200)) {
|
&& (data.statusCode === 201 || data.statusCode === 200)) {
|
||||||
const dataDefinition = this.processResponse<NormalizedObject | ConfigObject, SubmissionResourceType>(data.payload, request.href);
|
const dataDefinition = this.processResponse<NormalizedObject | ConfigObject, SubmissionResourceType>(data.payload, request.href);
|
||||||
return new SubmissionSuccessResponse(dataDefinition[Object.keys(dataDefinition)[0]], data.statusCode, this.processPageInfo(data.payload));
|
return new SubmissionSuccessResponse(dataDefinition[Object.keys(dataDefinition)[0]], data.statusCode, data.statusText, this.processPageInfo(data.payload));
|
||||||
} else if (isEmpty(data.payload) && data.statusCode === 204) {
|
} else if (isEmpty(data.payload) && data.statusCode === 204) {
|
||||||
// Response from a DELETE request
|
// Response from a DELETE request
|
||||||
return new SubmissionSuccessResponse(null, data.statusCode);
|
return new SubmissionSuccessResponse(null, data.statusCode, data.statusText);
|
||||||
} else {
|
} else {
|
||||||
return new ErrorResponse(
|
return new ErrorResponse(
|
||||||
Object.assign(
|
Object.assign(
|
||||||
new Error('Unexpected response from server'),
|
new Error('Unexpected response from server'),
|
||||||
{statusText: data.statusCode}
|
{statusCode: data.statusCode, statusText: data.statusText}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user