diff --git a/src/app/+collection-page/create-collection-page/create-collection-page.component.ts b/src/app/+collection-page/create-collection-page/create-collection-page.component.ts index 93c3c16646..6cca8f1d09 100644 --- a/src/app/+collection-page/create-collection-page/create-collection-page.component.ts +++ b/src/app/+collection-page/create-collection-page/create-collection-page.component.ts @@ -10,7 +10,7 @@ import { Router } from '@angular/router'; import { DSOSuccessResponse, ErrorResponse } from '../../core/cache/response-cache.models'; import { Observable } from 'rxjs/Observable'; import { ResponseCacheEntry } from '../../core/cache/response-cache.reducer'; -import { map } from 'rxjs/operators'; +import { map, take } from 'rxjs/operators'; import { RemoteData } from '../../core/data/remote-data'; import { isNotEmpty } from '../../shared/empty.util'; import { DSpaceObject } from '../../core/shared/dspace-object.model'; @@ -36,7 +36,7 @@ export class CreateCollectionPageComponent { } onSubmit(data: any) { - this.parentUUID$.subscribe((uuid: string) => { + this.parentUUID$.pipe(take(1)).subscribe((uuid: string) => { const collection = Object.assign(new Collection(), { name: data.name, metadata: [ @@ -45,20 +45,13 @@ export class CreateCollectionPageComponent { { key: 'dc.rights', value: data.copyright }, { key: 'dc.rights.license', value: data.license } // TODO: metadata for news and provenance - ], - owner: Observable.of(new RemoteData(false, false, true, null, Object.assign(new Community(), { - id: uuid, - uuid: uuid - }))) + ] }); - this.collectionDataService.create(collection).subscribe((rd: RemoteData) => { + this.collectionDataService.create(collection, uuid).pipe(take(1)).subscribe((rd: RemoteData) => { if (rd.hasSucceeded) { this.router.navigateByUrl(''); } }); - // this.collectionDataService.createSimple(collection).subscribe((httpEvent: HttpEvent<{}>) => { - // console.log(httpEvent); - // }); }); } diff --git a/src/app/+community-page/create-community-page/create-community-page.component.ts b/src/app/+community-page/create-community-page/create-community-page.component.ts index 9a4730f74f..afb90141c9 100644 --- a/src/app/+community-page/create-community-page/create-community-page.component.ts +++ b/src/app/+community-page/create-community-page/create-community-page.component.ts @@ -30,7 +30,7 @@ export class CreateCommunityPageComponent { } onSubmit(data: any) { - this.parentUUID$.subscribe((uuid: string) => { + this.parentUUID$.pipe(take(1)).subscribe((uuid: string) => { const community = Object.assign(new Community(), { name: data.name, metadata: [ @@ -38,13 +38,9 @@ export class CreateCommunityPageComponent { { key: 'dc.description.abstract', value: data.description }, { key: 'dc.rights', value: data.copyright } // TODO: metadata for news - ], - owner: Observable.of(new RemoteData(false, false, true, null, Object.assign(new Community(), { - id: uuid, - uuid: uuid - }))) + ] }); - this.communityDataService.create(community).pipe(take(1)).subscribe((rd: RemoteData) => { + this.communityDataService.create(community, uuid).pipe(take(1)).subscribe((rd: RemoteData) => { if (rd.hasSucceeded) { this.router.navigateByUrl(''); } diff --git a/src/app/core/data/comcol-data.service.ts b/src/app/core/data/comcol-data.service.ts index c9dff8fbe1..8519bb2b25 100644 --- a/src/app/core/data/comcol-data.service.ts +++ b/src/app/core/data/comcol-data.service.ts @@ -66,25 +66,20 @@ export abstract class ComColDataService { - return comcol.owner.pipe( - map((rd: RemoteData) => { - const form: any = { - name: comcol.name - }; - if (rd.payload.id) { - form.parent = rd.payload.id; + public buildFormData(comcol, parentUUID): FormData { + const form: FormData = new FormData(); + form.append('name', comcol.name); + if (isNotEmpty(parentUUID)) { + form.append('parent', parentUUID); + } + if (comcol.metadata) { + for (const i of Object.keys(comcol.metadata)) { + if (isNotEmpty(comcol.metadata[i].value)) { + form.append(comcol.metadata[i].key, comcol.metadata[i].value); } - if (comcol.metadata) { - for (const i of Object.keys(comcol.metadata)) { - if (isNotEmpty(comcol.metadata[i].value)) { - form[comcol.metadata[i].key] = comcol.metadata[i].value; - } - } - } - return form; - }) - ); + } + } + return form; } } diff --git a/src/app/core/data/data.service.ts b/src/app/core/data/data.service.ts index fb3002b5d7..b2946b2164 100644 --- a/src/app/core/data/data.service.ts +++ b/src/app/core/data/data.service.ts @@ -117,7 +117,7 @@ export abstract class DataService return this.rdbService.buildSingle(href); } - public create(dso: TDomain): Observable> { + public create(dso: TDomain, parentUUID: string): Observable> { const requestId = this.requestService.generateRequestId(); const endpoint$ = this.halService.getEndpoint(this.linkPath).pipe( isNotEmptyOperator(), @@ -126,8 +126,7 @@ export abstract class DataService const request$ = endpoint$.pipe( take(1), - withLatestFrom(this.buildCreateBody(dso)), - map(([endpoint, formdata]) => new CreateRequest(requestId, endpoint, this.buildFormData(formdata))), + map((endpoint: string) => new CreateRequest(requestId, endpoint, this.buildFormData(dso, parentUUID))), configureRequest(this.requestService) ); @@ -154,31 +153,6 @@ export abstract class DataService return this.rdbService.toRemoteDataObservable(requestEntry$, responseCache$, payload$); } - public createSimple(dso: TDomain): Observable> { - const endpoint$ = this.halService.getEndpoint(this.linkPath).pipe( - isNotEmptyOperator(), - distinctUntilChanged() - ); - - return endpoint$.pipe( - withLatestFrom(this.buildCreateBody(dso)), - switchMap(([endpoint, form]) => { - const req = new HttpRequest('POST', endpoint, this.buildFormData(form)); - return this.http.request(req); - }) - ); - } - - public abstract buildCreateBody(dso: TDomain): Observable; - - protected buildFormData(form: any): FormData { - const formdata = new FormData(); - for (const param in form) { - if (form.hasOwnProperty(param)) { - formdata.append(param, form[param]); - } - } - return formdata; - } + public abstract buildFormData(dso: TDomain, parentUUID: string): FormData; } diff --git a/src/app/core/data/dspace-object-data.service.ts b/src/app/core/data/dspace-object-data.service.ts index ecf52098ee..14540d0782 100644 --- a/src/app/core/data/dspace-object-data.service.ts +++ b/src/app/core/data/dspace-object-data.service.ts @@ -38,7 +38,7 @@ class DataServiceImpl extends DataService return endpoint.replace(/\{\?uuid\}/,`?uuid=${resourceID}`); } - buildCreateBody(dso: DSpaceObject): Observable { + buildFormData(dso: DSpaceObject, parentUUID: string): FormData { return undefined; } } diff --git a/src/app/core/data/item-data.service.ts b/src/app/core/data/item-data.service.ts index 4c003e15c9..c3c32691ce 100644 --- a/src/app/core/data/item-data.service.ts +++ b/src/app/core/data/item-data.service.ts @@ -47,8 +47,8 @@ export class ItemDataService extends DataService { } } - buildCreateBody(dso: Item): Observable { - // TODO: Build http body for creating an Item on the REST service + buildFormData(dso: Item, parentUUID: string): FormData { + // TODO: build FormData for creating an Item return undefined; }