Skip to content
Snippets Groups Projects
Commit dd439109 authored by Kristof De Langhe's avatar Kristof De Langhe
Browse files

54472: Send normalized collections/communities instead of FormData

parent 1fc93591
No related branches found
No related tags found
No related merge requests found
......@@ -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<Collection>) => {
if (rd.hasSucceeded) {
......
......@@ -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<DSpaceObject>) => {
if (rd.hasSucceeded) {
......
......@@ -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<TNormalized extends NormalizedObject, TDomain> {
protected abstract requestService: RequestService;
......@@ -128,7 +130,7 @@ export abstract class DataService<TNormalized extends NormalizedObject, TDomain>
}
}
create(dso: TDomain, parentUUID: string): Observable<RemoteData<TDomain>> {
create(dso: TNormalized, parentUUID: string): Observable<RemoteData<TDomain>> {
const requestId = this.requestService.generateRequestId();
const endpoint$ = this.halService.getEndpoint(this.linkPath).pipe(
isNotEmptyOperator(),
......@@ -136,9 +138,11 @@ export abstract class DataService<TNormalized extends NormalizedObject, TDomain>
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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment