mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 07:23:03 +00:00
Merge remote-tracking branch 'remotes/origin/master' into submission
# Conflicts: # package.json # src/app/+item-page/edit-item-page/item-delete/item-delete.component.spec.ts # src/app/+item-page/edit-item-page/item-private/item-private.component.spec.ts # src/app/+item-page/edit-item-page/item-public/item-public.component.spec.ts # src/app/+item-page/edit-item-page/item-reinstate/item-reinstate.component.spec.ts # src/app/+item-page/edit-item-page/item-withdraw/item-withdraw.component.spec.ts # src/app/+item-page/edit-item-page/simple-item-action/abstract-simple-item-action.component.spec.ts # src/app/+search-page/search-service/search.service.spec.ts # src/app/core/auth/auth-response-parsing.service.spec.ts # src/app/core/auth/auth-response-parsing.service.ts # src/app/core/cache/builders/remote-data-build.service.ts # src/app/core/cache/response-cache.reducer.spec.ts # src/app/core/cache/response-cache.service.spec.ts # src/app/core/cache/response.models.ts # src/app/core/config/config-response-parsing.service.ts # src/app/core/core.effects.ts # src/app/core/core.module.ts # src/app/core/core.reducers.ts # src/app/core/data/base-response-parsing.service.ts # src/app/core/data/data.service.ts # src/app/core/data/item-data.service.spec.ts # src/app/core/data/request.models.ts # src/app/core/data/request.service.spec.ts # src/app/core/data/request.service.ts # src/app/core/integration/integration-response-parsing.service.spec.ts # src/app/core/integration/integration-response-parsing.service.ts # src/app/core/integration/integration.service.ts # src/app/core/metadata/metadata.service.spec.ts # src/app/core/registry/registry.service.spec.ts # src/app/core/shared/hal-endpoint.service.ts # src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control.component.ts # src/app/shared/mocks/mock-response-cache.service.ts # src/app/shared/shared.module.ts
This commit is contained in:
@@ -8,15 +8,7 @@ import { GenericConstructor } from '../shared/generic-constructor';
|
||||
import { PaginatedList } from './paginated-list';
|
||||
import { ResourceType } from '../shared/resource-type';
|
||||
import { RESTURLCombiner } from '../url-combiner/rest-url-combiner';
|
||||
|
||||
function isObjectLevel(halObj: any) {
|
||||
return isNotEmpty(halObj._links) && hasValue(halObj._links.self);
|
||||
}
|
||||
|
||||
function isPaginatedResponse(halObj: any) {
|
||||
return hasValue(halObj.page) && hasValue(halObj._embedded);
|
||||
}
|
||||
|
||||
import { isRestDataObject, isRestPaginatedList } from '../cache/builders/normalized-object-build.service';
|
||||
/* tslint:disable:max-classes-per-file */
|
||||
|
||||
export abstract class BaseResponseParsingService {
|
||||
@@ -25,16 +17,15 @@ 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);
|
||||
} else if (isRestPaginatedList(data)) {
|
||||
return this.processPaginatedList(data, requestUUID);
|
||||
} else if (Array.isArray(data)) {
|
||||
return this.processArray(data, requestHref);
|
||||
} else if (isObjectLevel(data)) {
|
||||
return this.processArray(data, requestUUID);
|
||||
} else if (isRestDataObject(data)) {
|
||||
data = this.fixBadEPersonRestResponse(data);
|
||||
const object = this.deserialize(data);
|
||||
if (isNotEmpty(data._embedded)) {
|
||||
@@ -42,12 +33,12 @@ 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])) {
|
||||
if (isRestPaginatedList(data._embedded[property])) {
|
||||
object[property] = parsedObj;
|
||||
object[property].page = parsedObj.page.map((obj) => this.retrieveObjectOrUrl(obj));
|
||||
} else if (isObjectLevel(data._embedded[property])) {
|
||||
} else if (isRestDataObject(data._embedded[property])) {
|
||||
object[property] = this.retrieveObjectOrUrl(parsedObj);
|
||||
} else if (Array.isArray(parsedObj)) {
|
||||
object[property] = parsedObj.map((obj) => this.retrieveObjectOrUrl(obj))
|
||||
@@ -56,7 +47,7 @@ export abstract class BaseResponseParsingService {
|
||||
});
|
||||
}
|
||||
|
||||
this.cache(object, requestHref);
|
||||
this.cache(object, requestUUID);
|
||||
return object;
|
||||
}
|
||||
const result = {};
|
||||
@@ -64,14 +55,14 @@ export abstract class BaseResponseParsingService {
|
||||
.filter((property) => data.hasOwnProperty(property))
|
||||
.filter((property) => hasValue(data[property]))
|
||||
.forEach((property) => {
|
||||
result[property] = this.process(data[property], requestHref);
|
||||
result[property] = this.process(data[property], requestUUID);
|
||||
});
|
||||
return result;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
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 +70,14 @@ export abstract class BaseResponseParsingService {
|
||||
if (!Array.isArray(list)) {
|
||||
list = this.flattenSingleKeyObject(list);
|
||||
}
|
||||
const page: ObjectDomain[] = this.processArray(list, requestHref);
|
||||
return new PaginatedList<ObjectDomain>(pageInfo, page);
|
||||
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;
|
||||
@@ -113,17 +104,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, requestHref);
|
||||
this.objectCache.add(co, this.EnvConfig.cache.msToLive.default, requestUUID);
|
||||
}
|
||||
|
||||
processPageInfo(payload: any): PageInfo {
|
||||
@@ -149,7 +140,6 @@ export abstract class BaseResponseParsingService {
|
||||
|
||||
protected retrieveObjectOrUrl(obj: any): any {
|
||||
return this.toCache ? obj.self : obj;
|
||||
// return obj.self;
|
||||
}
|
||||
|
||||
// TODO Remove when https://jira.duraspace.org/browse/DS-4006 is fixed
|
||||
|
Reference in New Issue
Block a user