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

@@ -0,0 +1,65 @@
import { Bitstream } from "../../shared/bitstream.model";
import { ObjectCacheService } from "../object-cache.service";
import { ResponseCacheService } from "../response-cache.service";
import { RequestService } from "../../data/request.service";
import { Store } from "@ngrx/store";
import { CoreState } from "../../core.reducers";
import { NormalizedBitstream } from "./normalized-bitstream.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";
export class BitstreamBuilder {
constructor(
protected objectCache: ObjectCacheService,
protected responseCache: ResponseCacheService,
protected requestService: RequestService,
protected store: Store<CoreState>,
protected href: string,
protected normalized: NormalizedBitstream
) {
}
build(): Bitstream {
let links: any = {};
//TODO
return Object.assign(new Bitstream(), this.normalized, links);
}
}
export class BitstreamRDBuilder extends SingleRemoteDataBuilder<Bitstream, NormalizedBitstream> {
constructor(
objectCache: ObjectCacheService,
responseCache: ResponseCacheService,
requestService: RequestService,
store: Store<CoreState>,
href: string
) {
super(objectCache, responseCache, requestService, store, href, NormalizedBitstream);
}
protected normalizedToDomain(normalized: NormalizedBitstream): Bitstream {
return new BitstreamBuilder(this.objectCache, this.responseCache, this.requestService, this.store, this.href, normalized).build();
}
}
export class BitstreamListRDBuilder extends ListRemoteDataBuilder<Bitstream, NormalizedBitstream> {
constructor(
objectCache: ObjectCacheService,
responseCache: ResponseCacheService,
requestService: RequestService,
store: Store<CoreState>,
href: string
) {
super(objectCache, responseCache, requestService, store, href, NormalizedBitstream);
}
protected normalizedToDomain(normalized: NormalizedBitstream): Bitstream {
return new BitstreamBuilder(this.objectCache, this.responseCache, this.requestService, this.store, this.href, normalized).build();
}
}

View File

@@ -0,0 +1,93 @@
import { Bundle } from "../../shared/bundle.model";
import { ObjectCacheService } from "../object-cache.service";
import { ResponseCacheService } from "../response-cache.service";
import { RequestService } from "../../data/request.service";
import { Store } from "@ngrx/store";
import { CoreState } from "../../core.reducers";
import { NormalizedBundle } from "./normalized-bundle.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 { BitstreamRDBuilder } from "./bitstream-builder";
import { NormalizedBitstream } from "./normalized-bitstream.model";
export class BundleBuilder {
constructor(
protected objectCache: ObjectCacheService,
protected responseCache: ResponseCacheService,
protected requestService: RequestService,
protected store: Store<CoreState>,
protected href: string,
protected normalized: NormalizedBundle
) {
}
build(): Bundle {
let links: any = {};
if (hasValue(this.normalized.bitstreams)) {
//for some reason the dispatches in the forEach don't
//fire without this timeout. A zone issue?
setTimeout(() => {
this.normalized.bitstreams.forEach((href: string) => {
const isCached = this.objectCache.hasBySelfLink(href);
const isPending = this.requestService.isPending(href);
if (!(isCached || isPending)) {
const request = new Request(href, NormalizedBitstream);
this.store.dispatch(new RequestConfigureAction(request));
this.store.dispatch(new RequestExecuteAction(href));
}
});
}, 0);
links.bitstreams = this.normalized.bitstreams.map((href: string) => {
return new BitstreamRDBuilder(
this.objectCache,
this.responseCache,
this.requestService,
this.store,
href
).build();
});
}
return Object.assign(new Bundle(), this.normalized, links);
}
}
export class BundleRDBuilder extends SingleRemoteDataBuilder<Bundle, NormalizedBundle> {
constructor(
objectCache: ObjectCacheService,
responseCache: ResponseCacheService,
requestService: RequestService,
store: Store<CoreState>,
href: string
) {
super(objectCache, responseCache, requestService, store, href, NormalizedBundle);
}
protected normalizedToDomain(normalized: NormalizedBundle): Bundle {
return new BundleBuilder(this.objectCache, this.responseCache, this.requestService, this.store, this.href, normalized).build();
}
}
export class BundleListRDBuilder extends ListRemoteDataBuilder<Bundle, NormalizedBundle> {
constructor(
objectCache: ObjectCacheService,
responseCache: ResponseCacheService,
requestService: RequestService,
store: Store<CoreState>,
href: string
) {
super(objectCache, responseCache, requestService, store, href, NormalizedBundle);
}
protected normalizedToDomain(normalized: NormalizedBundle): Bundle {
return new BundleBuilder(this.objectCache, this.responseCache, this.requestService, this.store, this.href, normalized).build();
}
}

View File

@@ -11,6 +11,7 @@ import { NormalizedCollection } from "./normalized-collection.model";
import { Request } from "../../data/request.models";
import { ListRemoteDataBuilder, SingleRemoteDataBuilder } from "./remote-data-builder";
import { ItemRDBuilder } from "./item-builder";
import { NormalizedItem } from "./normalized-item.model";
export class CollectionBuilder {
@@ -20,28 +21,26 @@ export class CollectionBuilder {
protected requestService: RequestService,
protected store: Store<CoreState>,
protected href: string,
protected nc: NormalizedCollection
protected normalized: NormalizedCollection
) {
}
build(): Collection {
let links: any = {};
if (hasValue(this.nc.items)) {
this.nc.items.forEach((href: string) => {
if (hasValue(this.normalized.items)) {
this.normalized.items.forEach((href: string) => {
const isCached = this.objectCache.hasBySelfLink(href);
const isPending = this.requestService.isPending(href);
console.log('href', href, 'isCached', isCached, "isPending", isPending);
if (!(isCached || isPending)) {
const request = new Request(href, Item);
const request = new Request(href, NormalizedItem);
this.store.dispatch(new RequestConfigureAction(request));
this.store.dispatch(new RequestExecuteAction(href));
}
});
links.items = this.nc.items.map((href: string) => {
links.items = this.normalized.items.map((href: string) => {
return new ItemRDBuilder(
this.objectCache,
this.responseCache,
@@ -52,7 +51,7 @@ export class CollectionBuilder {
});
}
return Object.assign(new Collection(), this.nc, links);
return Object.assign(new Collection(), this.normalized, links);
}
}

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);
}
}

View File

@@ -1,4 +1,4 @@
import { inheritSerialization } from "cerialize";
import { autoserialize, inheritSerialization } from "cerialize";
import { NormalizedDSpaceObject } from "./normalized-dspace-object.model";
@inheritSerialization(NormalizedDSpaceObject)
@@ -6,6 +6,7 @@ export class NormalizedBundle extends NormalizedDSpaceObject {
/**
* The primary bitstream of this Bundle
*/
@autoserialize
primaryBitstream: string;
/**
@@ -18,4 +19,6 @@ export class NormalizedBundle extends NormalizedDSpaceObject {
*/
owner: string;
@autoserialize
bitstreams: Array<string>;
}

View File

@@ -35,4 +35,6 @@ export class NormalizedItem extends NormalizedDSpaceObject {
*/
owner: string;
@autoserialize
bundles: Array<string>;
}

View File

@@ -2,13 +2,14 @@ import { inheritSerialization } from "cerialize";
import { DSpaceObject } from "./dspace-object.model";
import { Bitstream } from "./bitstream.model";
import { Item } from "./item.model";
import { RemoteData } from "../data/remote-data";
@inheritSerialization(DSpaceObject)
export class Bundle extends DSpaceObject {
/**
* The primary bitstream of this Bundle
*/
primaryBitstream: Bitstream;
primaryBitstream: RemoteData<Bitstream>;
/**
* An array of Items that are direct parents of this Bundle
@@ -20,4 +21,6 @@ export class Bundle extends DSpaceObject {
*/
owner: Item;
bitstreams: Array<RemoteData<Bitstream>>
}

View File

@@ -1,6 +1,8 @@
import { inheritSerialization, autoserialize } from "cerialize";
import { DSpaceObject } from "./dspace-object.model";
import { Collection } from "./collection.model";
import { RemoteData } from "../data/remote-data";
import { Bundle } from "./bundle.model";
@inheritSerialization(DSpaceObject)
export class Item extends DSpaceObject {
@@ -36,4 +38,6 @@ export class Item extends DSpaceObject {
*/
owner: Collection;
bundles: Array<RemoteData<Bundle>>
}

View File

@@ -1,7 +1,7 @@
export const BITSTREAMS = [
{
"_links": {
"self": { "href": "/bitstreams/43c57c2b-206f-4645-8c8f-5f10c84b09fa" },
"self": { "href": "/bitstreams/3678" },
"bundle": { "href": "/bundles/35e0606d-5e18-4f9c-aa61-74fc751cc3f9" },
"retrieve": { "href": "/bitstreams/43c57c2b-206f-4645-8c8f-5f10c84b09fa/retrieve" }
},
@@ -22,7 +22,7 @@ export const BITSTREAMS = [
},
{
"_links": {
"self": { "href": "/bitstreams/1a013ecc-fb25-4689-a44f-f1383ad26632" },
"self": { "href": "/bitstreams/8842" },
"bundle": { "href": "/bundles/a469c57a-abcf-45c3-83e4-b187ebd708fd" },
"retrieve": { "href": "/rest/bitstreams/1a013ecc-fb25-4689-a44f-f1383ad26632/retrieve" }
},

View File

@@ -1,12 +1,12 @@
export const BUNDLES = [
{
"_links": {
"self": { "href": "/bundles/35e0606d-5e18-4f9c-aa61-74fc751cc3f9" },
"self": { "href": "/bundles/2355" },
"items": [
{ "href": "/items/8871" }
],
"bitstreams": [
{ "href": "/bitstreams/43c57c2b-206f-4645-8c8f-5f10c84b09fa" },
{ "href": "/bitstreams/3678" },
],
"primaryBitstream": { "href": "/bitstreams/43c57c2b-206f-4645-8c8f-5f10c84b09fa" }
},
@@ -19,12 +19,12 @@ export const BUNDLES = [
},
{
"_links": {
"self": { "href": "/bundles/a469c57a-abcf-45c3-83e4-b187ebd708fd" },
"self": { "href": "/bundles/5687" },
"items": [
{ "href": "/items/8871" }
],
"bitstreams": [
{ "href": "/bitstreams/1a013ecc-fb25-4689-a44f-f1383ad26632" },
{ "href": "/bitstreams/8842" },
],
"primaryBitstream": { "href": "/bitstreams/1a013ecc-fb25-4689-a44f-f1383ad26632" }
},

View File

@@ -14,10 +14,10 @@ export const ITEMS = [
],
"bundles": [
{
"href": "/bundles/35e0606d-5e18-4f9c-aa61-74fc751cc3f9"
"href": "/bundles/2355"
},
{
"href": "/bundles/a469c57a-abcf-45c3-83e4-b187ebd708fd"
"href": "/bundles/5687"
}
]
},
@@ -106,10 +106,10 @@ export const ITEMS = [
],
"bundles": [
{
"href": "/bundles/b0176baa-d52e-4c20-a8e6-d586f2c70c76"
"href": "/bundles/2355"
},
{
"href": "/bundles/40b1cd3f-07ad-4ca6-9716-132671f93a15"
"href": "/bundles/5687"
}
]
},

View File

@@ -13,7 +13,6 @@ import { CoreModule } from "../../app/core/core.module";
import { StoreModule, Store } from "@ngrx/store";
import { RouterStoreModule } from "@ngrx/router-store";
import { StoreDevtoolsModule } from "@ngrx/store-devtools";
import { rootReducer, AppState, NGRX_CACHE_KEY } from '../../app/app.reducers';
import { effects } from '../../app/app.effects';
@@ -59,7 +58,6 @@ export const UNIVERSAL_KEY = 'UNIVERSAL_CACHE';
AppModule,
StoreModule.provideStore(rootReducer),
RouterStoreModule.connectRouter(),
StoreDevtoolsModule.instrumentOnlyWithExtension(),
effects
],
providers: [