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 f3dbff9c1f..a8ee329a0f 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 @@ -9,6 +9,8 @@ import { Observable } from 'rxjs'; import { take } from 'rxjs/operators'; import { RemoteData } from '../../core/data/remote-data'; import { isNotEmpty } from '../../shared/empty.util'; +import { NormalizedCollection } from '../../core/cache/models/normalized-collection.model'; +import { ResourceType } from '../../core/shared/resource-type'; @Component({ selector: 'ds-create-collection', @@ -36,7 +38,7 @@ export class CreateCollectionPageComponent { onSubmit(data: any) { this.parentUUID$.pipe(take(1)).subscribe((uuid: string) => { - const collection = Object.assign(new Collection(), { + const collection = Object.assign(new NormalizedCollection(), { name: data.name, metadata: [ { key: 'dc.description', value: data.introductory }, @@ -44,7 +46,8 @@ export class CreateCollectionPageComponent { { key: 'dc.rights', value: data.copyright }, { key: 'dc.rights.license', value: data.license } // TODO: metadata for news and provenance - ] + ], + type: ResourceType.Collection }); this.collectionDataService.create(collection, uuid).subscribe((rd: RemoteData) => { if (rd.hasSucceeded) { 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 8c75af0d64..0d97f24028 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 @@ -8,6 +8,8 @@ import { RemoteData } from '../../core/data/remote-data'; import { isNotEmpty } from '../../shared/empty.util'; import { DSpaceObject } from '../../core/shared/dspace-object.model'; import { take } from 'rxjs/operators'; +import { ResourceType } from '../../core/shared/resource-type'; +import { NormalizedCommunity } from '../../core/cache/models/normalized-community.model'; @Component({ selector: 'ds-create-community', @@ -34,14 +36,15 @@ export class CreateCommunityPageComponent { onSubmit(data: any) { this.parentUUID$.pipe(take(1)).subscribe((uuid: string) => { - const community = Object.assign(new Community(), { + const community = Object.assign(new NormalizedCommunity(), { name: data.name, metadata: [ { key: 'dc.description', value: data.introductory }, { key: 'dc.description.abstract', value: data.description }, { key: 'dc.rights', value: data.copyright } // TODO: metadata for news - ] + ], + type: ResourceType.Community }); this.communityDataService.create(community, uuid).pipe(take(1)).subscribe((rd: RemoteData) => { if (rd.hasSucceeded) { diff --git a/src/app/core/data/data.service.ts b/src/app/core/data/data.service.ts index 6a82577aa5..db3882ac08 100644 --- a/src/app/core/data/data.service.ts +++ b/src/app/core/data/data.service.ts @@ -30,6 +30,8 @@ import { } from '../shared/operators'; import { DSOSuccessResponse, ErrorResponse, RestResponse } from '../cache/response.models'; import { NotificationOptions } from '../../shared/notifications/models/notification-options.model'; +import { DSpaceRESTv2Serializer } from '../dspace-rest-v2/dspace-rest-v2.serializer'; +import { NormalizedObjectFactory } from '../cache/models/normalized-object-factory'; export abstract class DataService { protected abstract requestService: RequestService; @@ -128,7 +130,7 @@ export abstract class DataService } } - create(dso: TDomain, parentUUID: string): Observable> { + create(dso: TNormalized, parentUUID: string): Observable> { const requestId = this.requestService.generateRequestId(); const endpoint$ = this.halService.getEndpoint(this.linkPath).pipe( isNotEmptyOperator(), @@ -136,9 +138,11 @@ export abstract class DataService map((endpoint: string) => parentUUID ? `${endpoint}?parent=${parentUUID}` : endpoint) ); + const serializedDso = new DSpaceRESTv2Serializer(NormalizedObjectFactory.getConstructor(dso.type)).serialize(dso); + const request$ = endpoint$.pipe( take(1), - map((endpoint: string) => new CreateRequest(requestId, endpoint, dso)) + map((endpoint: string) => new CreateRequest(requestId, endpoint, JSON.stringify(serializedDso))) ); // Execute the post request