Skip to content
Snippets Groups Projects
Commit 4836fd9e authored by Art Lowel's avatar Art Lowel
Browse files

ensure object cache uses responseMsToLive from request

parent 604e99ee
No related branches found
No related tags found
No related merge requests found
......@@ -25,7 +25,7 @@ export class AuthResponseParsingService extends BaseResponseParsingService imple
parse(request: RestRequest, data: DSpaceRESTV2Response): RestResponse {
if (isNotEmpty(data.payload) && isNotEmpty(data.payload._links) && (data.statusCode === 200)) {
const response = this.process<NormalizedObject<AuthStatus>>(data.payload, request.uuid);
const response = this.process<NormalizedObject<AuthStatus>>(data.payload, request);
return new AuthStatusResponse(response, data.statusCode, data.statusText);
} else {
return new AuthStatusResponse(data.payload as NormalizedAuthStatus, data.statusCode, data.statusText);
......
......@@ -24,7 +24,7 @@ export class ConfigResponseParsingService extends BaseResponseParsingService imp
parse(request: RestRequest, data: DSpaceRESTV2Response): RestResponse {
if (isNotEmpty(data.payload) && isNotEmpty(data.payload._links) && (data.statusCode === 201 || data.statusCode === 200)) {
const configDefinition = this.process<ConfigObject>(data.payload, request.uuid);
const configDefinition = this.process<ConfigObject>(data.payload, request);
return new ConfigSuccessResponse(configDefinition, data.statusCode, data.statusText, this.processPageInfo(data.payload));
} else {
return new ErrorResponse(
......
......@@ -9,6 +9,7 @@ import { PaginatedList } from './paginated-list';
import { isRestDataObject, isRestPaginatedList } from '../cache/builders/normalized-object-build.service';
import { ResourceType } from '../shared/resource-type';
import { getMapsToType } from '../cache/builders/build-decorators';
import { RestRequest } from './request.models';
/* tslint:disable:max-classes-per-file */
export abstract class BaseResponseParsingService {
......@@ -16,14 +17,14 @@ export abstract class BaseResponseParsingService {
protected abstract objectCache: ObjectCacheService;
protected abstract toCache: boolean;
protected process<ObjectDomain>(data: any, requestUUID: string): any {
protected process<ObjectDomain>(data: any, request: RestRequest): any {
if (isNotEmpty(data)) {
if (hasNoValue(data) || (typeof data !== 'object')) {
return data;
} else if (isRestPaginatedList(data)) {
return this.processPaginatedList(data, requestUUID);
return this.processPaginatedList(data, request);
} else if (Array.isArray(data)) {
return this.processArray(data, requestUUID);
return this.processArray(data, request);
} else if (isRestDataObject(data)) {
const object = this.deserialize(data);
if (isNotEmpty(data._embedded)) {
......@@ -31,7 +32,7 @@ export abstract class BaseResponseParsingService {
.keys(data._embedded)
.filter((property) => data._embedded.hasOwnProperty(property))
.forEach((property) => {
const parsedObj = this.process<ObjectDomain>(data._embedded[property], requestUUID);
const parsedObj = this.process<ObjectDomain>(data._embedded[property], request);
if (isNotEmpty(parsedObj)) {
if (isRestPaginatedList(data._embedded[property])) {
object[property] = parsedObj;
......@@ -45,7 +46,7 @@ export abstract class BaseResponseParsingService {
});
}
this.cache(object, requestUUID);
this.cache(object, request);
return object;
}
const result = {};
......@@ -53,14 +54,14 @@ export abstract class BaseResponseParsingService {
.filter((property) => data.hasOwnProperty(property))
.filter((property) => hasValue(data[property]))
.forEach((property) => {
result[property] = this.process(data[property], requestUUID);
result[property] = this.process(data[property], request);
});
return result;
}
}
protected processPaginatedList<ObjectDomain>(data: any, requestUUID: string): PaginatedList<ObjectDomain> {
protected processPaginatedList<ObjectDomain>(data: any, request: RestRequest): PaginatedList<ObjectDomain> {
const pageInfo: PageInfo = this.processPageInfo(data);
let list = data._embedded;
......@@ -70,14 +71,14 @@ export abstract class BaseResponseParsingService {
} else if (!Array.isArray(list)) {
list = this.flattenSingleKeyObject(list);
}
const page: ObjectDomain[] = this.processArray(list, requestUUID);
const page: ObjectDomain[] = this.processArray(list, request);
return new PaginatedList<ObjectDomain>(pageInfo, page, );
}
protected processArray<ObjectDomain>(data: any, requestUUID: string): ObjectDomain[] {
protected processArray<ObjectDomain>(data: any, request: RestRequest): ObjectDomain[] {
let array: ObjectDomain[] = [];
data.forEach((datum) => {
array = [...array, this.process(datum, requestUUID)];
array = [...array, this.process(datum, request)];
}
);
return array;
......@@ -104,17 +105,17 @@ export abstract class BaseResponseParsingService {
}
}
protected cache<ObjectDomain>(obj, requestUUID) {
protected cache<ObjectDomain>(obj, request: RestRequest) {
if (this.toCache) {
this.addToObjectCache(obj, requestUUID);
this.addToObjectCache(obj, request);
}
}
protected addToObjectCache(co: CacheableObject, requestUUID: string): void {
protected addToObjectCache(co: CacheableObject, request: RestRequest): void {
if (hasNoValue(co) || hasNoValue(co.self)) {
throw new Error('The server returned an invalid object');
}
this.objectCache.add(co, this.EnvConfig.cache.msToLive.default, requestUUID);
this.objectCache.add(co, hasValue(request.responseMsToLive) ? request.responseMsToLive : this.EnvConfig.cache.msToLive.default, request.uuid);
}
processPageInfo(payload: any): PageInfo {
......
......@@ -30,7 +30,7 @@ export class DSOResponseParsingService extends BaseResponseParsingService implem
if (hasValue(data.payload) && hasValue(data.payload.page) && data.payload.page.totalElements === 0) {
processRequestDTO = { page: [] };
} else {
processRequestDTO = this.process<NormalizedObject<DSpaceObject>>(data.payload, request.uuid);
processRequestDTO = this.process<NormalizedObject<DSpaceObject>>(data.payload, request);
}
let objectList = processRequestDTO;
......
......@@ -148,8 +148,7 @@ export class RequestService {
*/
configure<T extends CacheableObject>(request: RestRequest): void {
const isGetRequest = request.method === RestRequestMethod.GET;
const isSubmission = request instanceof SubmissionRequest;
if (!isGetRequest || !this.isCachedOrPending(request) || isSubmission) {
if (!isGetRequest || !this.isCachedOrPending(request)) {
this.dispatchRequest(request);
if (isGetRequest) {
this.trackRequestsOnTheirWayToTheStore(request);
......
......@@ -28,7 +28,7 @@ export class EpersonResponseParsingService extends BaseResponseParsingService im
parse(request: RestRequest, data: DSpaceRESTV2Response): RestResponse {
if (isNotEmpty(data.payload) && isNotEmpty(data.payload._links)) {
const epersonDefinition = this.process<DSpaceObject>(data.payload, request.href);
const epersonDefinition = this.process<DSpaceObject>(data.payload, request);
return new EpersonSuccessResponse(epersonDefinition[Object.keys(epersonDefinition)[0]], data.statusCode, data.statusText, this.processPageInfo(data.payload));
} else {
return new ErrorResponse(
......
......@@ -27,7 +27,7 @@ export class IntegrationResponseParsingService extends BaseResponseParsingServic
parse(request: RestRequest, data: DSpaceRESTV2Response): RestResponse {
if (isNotEmpty(data.payload) && isNotEmpty(data.payload._links)) {
const dataDefinition = this.process<IntegrationModel>(data.payload, request.uuid);
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(
......
......@@ -91,7 +91,7 @@ export class SubmissionResponseParsingService extends BaseResponseParsingService
if (isNotEmpty(data.payload)
&& isNotEmpty(data.payload._links)
&& this.isSuccessStatus(data.statusCode)) {
const dataDefinition = this.processResponse<SubmissionObject | ConfigObject>(data.payload, request.href);
const dataDefinition = this.processResponse<SubmissionObject | ConfigObject>(data.payload, request);
return new SubmissionSuccessResponse(dataDefinition, data.statusCode, data.statusText, this.processPageInfo(data.payload));
} else if (isEmpty(data.payload) && this.isSuccessStatus(data.statusCode)) {
return new SubmissionSuccessResponse(null, data.statusCode, data.statusText);
......@@ -109,11 +109,11 @@ export class SubmissionResponseParsingService extends BaseResponseParsingService
* Parses response and normalize it
*
* @param {DSpaceRESTV2Response} data
* @param {string} requestHref
* @param {RestRequest} request
* @returns {any[]}
*/
protected processResponse<ObjectDomain>(data: any, requestHref: string): any[] {
const dataDefinition = this.process<ObjectDomain>(data, requestHref);
protected processResponse<ObjectDomain>(data: any, request: RestRequest): any[] {
const dataDefinition = this.process<ObjectDomain>(data, request);
const normalizedDefinition = Array.of();
const processedList = Array.isArray(dataDefinition) ? dataDefinition : Array.of(dataDefinition);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment