mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 07:23:03 +00:00
finished tests and docs
This commit is contained in:
@@ -25,14 +25,14 @@ export abstract class BaseResponseParsingService {
|
||||
protected abstract objectFactory: any;
|
||||
protected abstract toCache: boolean;
|
||||
|
||||
protected process<ObjectDomain, ObjectType>(data: any, requestHref: string): any {
|
||||
protected process<ObjectDomain, ObjectType>(data: any, requestUUID: string): any {
|
||||
if (isNotEmpty(data)) {
|
||||
if (hasNoValue(data) || (typeof data !== 'object')) {
|
||||
return data;
|
||||
} else if (isPaginatedResponse(data)) {
|
||||
return this.processPaginatedList(data, requestHref);
|
||||
return this.processPaginatedList(data, requestUUID);
|
||||
} else if (Array.isArray(data)) {
|
||||
return this.processArray(data, requestHref);
|
||||
return this.processArray(data, requestUUID);
|
||||
} else if (isObjectLevel(data)) {
|
||||
data = this.fixBadEPersonRestResponse(data);
|
||||
const object = this.deserialize(data);
|
||||
@@ -41,7 +41,7 @@ export abstract class BaseResponseParsingService {
|
||||
.keys(data._embedded)
|
||||
.filter((property) => data._embedded.hasOwnProperty(property))
|
||||
.forEach((property) => {
|
||||
const parsedObj = this.process<ObjectDomain, ObjectType>(data._embedded[property], requestHref);
|
||||
const parsedObj = this.process<ObjectDomain, ObjectType>(data._embedded[property], requestUUID);
|
||||
if (isNotEmpty(parsedObj)) {
|
||||
if (isPaginatedResponse(data._embedded[property])) {
|
||||
object[property] = parsedObj;
|
||||
@@ -55,7 +55,7 @@ export abstract class BaseResponseParsingService {
|
||||
});
|
||||
}
|
||||
|
||||
this.cache(object, requestHref);
|
||||
this.cache(object, requestUUID);
|
||||
return object;
|
||||
}
|
||||
const result = {};
|
||||
@@ -63,7 +63,7 @@ export abstract class BaseResponseParsingService {
|
||||
.filter((property) => data.hasOwnProperty(property))
|
||||
.filter((property) => hasValue(data[property]))
|
||||
.forEach((property) => {
|
||||
const obj = this.process(data[property], requestHref);
|
||||
const obj = this.process(data[property], requestUUID);
|
||||
result[property] = obj;
|
||||
});
|
||||
return result;
|
||||
@@ -71,7 +71,7 @@ export abstract class BaseResponseParsingService {
|
||||
}
|
||||
}
|
||||
|
||||
protected processPaginatedList<ObjectDomain, ObjectType>(data: any, requestHref: string): PaginatedList<ObjectDomain> {
|
||||
protected processPaginatedList<ObjectDomain, ObjectType>(data: any, requestUUID: string): PaginatedList<ObjectDomain> {
|
||||
const pageInfo: PageInfo = this.processPageInfo(data);
|
||||
let list = data._embedded;
|
||||
|
||||
@@ -79,14 +79,14 @@ export abstract class BaseResponseParsingService {
|
||||
if (!Array.isArray(list)) {
|
||||
list = this.flattenSingleKeyObject(list);
|
||||
}
|
||||
const page: ObjectDomain[] = this.processArray(list, requestHref);
|
||||
const page: ObjectDomain[] = this.processArray(list, requestUUID);
|
||||
return new PaginatedList<ObjectDomain>(pageInfo, page);
|
||||
}
|
||||
|
||||
protected processArray<ObjectDomain, ObjectType>(data: any, requestHref: string): ObjectDomain[] {
|
||||
protected processArray<ObjectDomain, ObjectType>(data: any, requestUUID: string): ObjectDomain[] {
|
||||
let array: ObjectDomain[] = [];
|
||||
data.forEach((datum) => {
|
||||
array = [...array, this.process(datum, requestHref)];
|
||||
array = [...array, this.process(datum, requestUUID)];
|
||||
}
|
||||
);
|
||||
return array;
|
||||
@@ -114,17 +114,17 @@ export abstract class BaseResponseParsingService {
|
||||
}
|
||||
}
|
||||
|
||||
protected cache<ObjectDomain, ObjectType>(obj, requestHref) {
|
||||
protected cache<ObjectDomain, ObjectType>(obj, requestUUID) {
|
||||
if (this.toCache) {
|
||||
this.addToObjectCache(obj, requestHref);
|
||||
this.addToObjectCache(obj, requestUUID);
|
||||
}
|
||||
}
|
||||
|
||||
protected addToObjectCache(co: CacheableObject, requestHref: string): void {
|
||||
protected addToObjectCache(co: CacheableObject, requestUUID: string): 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, requestHref);
|
||||
this.objectCache.add(co, this.EnvConfig.cache.msToLive.default, requestUUID);
|
||||
}
|
||||
|
||||
processPageInfo(payload: any): PageInfo {
|
||||
|
Reference in New Issue
Block a user