mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-17 23:13:04 +00:00
finished embedded object fixes
This commit is contained in:
@@ -8,21 +8,17 @@ import { hasValue, isEmpty, isNotEmpty } from '../../../shared/empty.util';
|
||||
import { PaginatedList } from '../../data/paginated-list';
|
||||
import { RemoteData } from '../../data/remote-data';
|
||||
import { RemoteDataError } from '../../data/remote-data-error';
|
||||
import { GetRequest, RestRequest } from '../../data/request.models';
|
||||
import { GetRequest } from '../../data/request.models';
|
||||
import { RequestEntry } from '../../data/request.reducer';
|
||||
import { RequestService } from '../../data/request.service';
|
||||
import { DSpaceObject } from '../../shared/dspace-object.model';
|
||||
import { GenericConstructor } from '../../shared/generic-constructor';
|
||||
import { NormalizedDSpaceObject } from '../models/normalized-dspace-object.model';
|
||||
import { NormalizedObjectFactory } from '../models/normalized-object-factory';
|
||||
|
||||
import { CacheableObject } from '../object-cache.reducer';
|
||||
import { ObjectCacheService } from '../object-cache.service';
|
||||
import { DSOSuccessResponse, ErrorResponse, SearchSuccessResponse } from '../response-cache.models';
|
||||
import { DSOSuccessResponse, ErrorResponse } from '../response-cache.models';
|
||||
import { ResponseCacheEntry } from '../response-cache.reducer';
|
||||
import { ResponseCacheService } from '../response-cache.service';
|
||||
import { getMapsTo, getRelationMetadata, getRelationships } from './build-decorators';
|
||||
import { NormalizedObject } from '../models/normalized-object.model';
|
||||
import { PageInfo } from '../../shared/page-info.model';
|
||||
|
||||
@Injectable()
|
||||
export class RemoteDataBuildService {
|
||||
@@ -159,35 +155,43 @@ export class RemoteDataBuildService {
|
||||
const relationships = getRelationships(normalized.constructor) || [];
|
||||
|
||||
relationships.forEach((relationship: string) => {
|
||||
let result;
|
||||
if (hasValue(normalized[relationship])) {
|
||||
const { resourceType, isList } = getRelationMetadata(normalized, relationship);
|
||||
if (Array.isArray(normalized[relationship])) {
|
||||
normalized[relationship].forEach((href: string) => {
|
||||
const objectList = normalized[relationship].page || normalized[relationship];
|
||||
if (typeof objectList !== 'string') {
|
||||
objectList.forEach((href: string) => {
|
||||
this.requestService.configure(new GetRequest(this.requestService.generateRequestId(), href))
|
||||
});
|
||||
|
||||
const rdArr = [];
|
||||
normalized[relationship].forEach((href: string) => {
|
||||
objectList.forEach((href: string) => {
|
||||
rdArr.push(this.buildSingle(href));
|
||||
});
|
||||
|
||||
if (isList) {
|
||||
links[relationship] = this.aggregate(rdArr);
|
||||
result = this.aggregate(rdArr);
|
||||
} else if (rdArr.length === 1) {
|
||||
links[relationship] = rdArr[0];
|
||||
result = rdArr[0];
|
||||
}
|
||||
} else {
|
||||
this.requestService.configure(new GetRequest(this.requestService.generateRequestId(), normalized[relationship]));
|
||||
this.requestService.configure(new GetRequest(this.requestService.generateRequestId(), objectList));
|
||||
|
||||
// The rest API can return a single URL to represent a list of resources (e.g. /items/:id/bitstreams)
|
||||
// in that case only 1 href will be stored in the normalized obj (so the isArray above fails),
|
||||
// but it should still be built as a list
|
||||
if (isList) {
|
||||
links[relationship] = this.buildList(normalized[relationship]);
|
||||
result = this.buildList(objectList);
|
||||
} else {
|
||||
links[relationship] = this.buildSingle(normalized[relationship]);
|
||||
result = this.buildSingle(objectList);
|
||||
}
|
||||
}
|
||||
|
||||
if (hasValue(normalized[relationship].page)) {
|
||||
links[relationship] = this.aggregatePaginatedList(result, normalized[relationship].pageInfo);
|
||||
} else {
|
||||
links[relationship] = result;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -248,4 +252,8 @@ export class RemoteDataBuildService {
|
||||
})
|
||||
}
|
||||
|
||||
aggregatePaginatedList<T>(input: Observable<RemoteData<T[]>>, pageInfo: PageInfo): Observable<RemoteData<PaginatedList<T>>> {
|
||||
return input.map((rd) => Object.assign(rd, {payload: new PaginatedList(pageInfo, rd.payload)}));
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user