added builders for bundles and bitstreams

This commit is contained in:
Art Lowel
2017-04-24 13:43:54 +02:00
parent fd441aec15
commit f8d6e96e44
12 changed files with 220 additions and 25 deletions

View File

@@ -6,6 +6,11 @@ import { Store } from "@ngrx/store";
import { CoreState } from "../../core.reducers";
import { NormalizedItem } from "./normalized-item.model";
import { ListRemoteDataBuilder, SingleRemoteDataBuilder } from "./remote-data-builder";
import { Request } from "../../data/request.models";
import { hasValue } from "../../../shared/empty.util";
import { RequestConfigureAction, RequestExecuteAction } from "../../data/request.actions";
import { BundleRDBuilder } from "./bundle-builder";
import { NormalizedBundle } from "./normalized-bundle.model";
export class ItemBuilder {
@@ -15,13 +20,36 @@ export class ItemBuilder {
protected requestService: RequestService,
protected store: Store<CoreState>,
protected href: string,
protected nc: NormalizedItem
protected normalized: NormalizedItem
) {
}
build(): Item {
//TODO
return Object.assign(new Item(), this.nc);
let links: any = {};
if (hasValue(this.normalized.bundles)) {
this.normalized.bundles.forEach((href: string) => {
const isCached = this.objectCache.hasBySelfLink(href);
const isPending = this.requestService.isPending(href);
if (!(isCached || isPending)) {
const request = new Request(href, NormalizedBundle);
this.store.dispatch(new RequestConfigureAction(request));
this.store.dispatch(new RequestExecuteAction(href));
}
});
links.bundles = this.normalized.bundles.map((href: string) => {
return new BundleRDBuilder(
this.objectCache,
this.responseCache,
this.requestService,
this.store,
href
).build();
});
}
return Object.assign(new Item(), this.normalized, links);
}
}