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

54472: form-data intermediate commit

parent 2740f690
Branches
Tags
No related merge requests found
...@@ -66,19 +66,23 @@ export abstract class ComColDataService<TNormalized extends NormalizedObject, TD ...@@ -66,19 +66,23 @@ export abstract class ComColDataService<TNormalized extends NormalizedObject, TD
} }
} }
public buildCreateParams(comcol): Observable<string> { public buildCreateBody(comcol): Observable<any> {
return comcol.owner.pipe( return comcol.owner.pipe(
map((rd: RemoteData<Community | Collection>) => { map((rd: RemoteData<Community | Collection>) => {
let urlParams = '?name=' + comcol.name; const form: any = {
name: comcol.name
};
if (rd.payload.id) { if (rd.payload.id) {
urlParams += '&parent=' + rd.payload.id; form.parent = rd.payload.id;
} }
if (comcol.metadata) { if (comcol.metadata) {
for (const i of Object.keys(comcol.metadata)) { for (const i of Object.keys(comcol.metadata)) {
urlParams += '&' + comcol.metadata[i].key + '=' + comcol.metadata[i].value; if (isNotEmpty(comcol.metadata[i].value)) {
form[comcol.metadata[i].key] = comcol.metadata[i].value;
}
} }
} }
return urlParams; return form;
}) })
); );
} }
......
...@@ -14,24 +14,21 @@ import { ...@@ -14,24 +14,21 @@ import {
FindAllRequest, FindAllRequest,
FindByIDRequest, FindByIDRequest,
GetRequest, GetRequest,
PostRequest,
RestRequest RestRequest
} from './request.models'; } from './request.models';
import { RequestService } from './request.service'; import { RequestService } from './request.service';
import { NormalizedObject } from '../cache/models/normalized-object.model'; import { NormalizedObject } from '../cache/models/normalized-object.model';
import { distinctUntilChanged, map, share, switchMap, take, withLatestFrom } from 'rxjs/operators'; import { distinctUntilChanged, map, take, withLatestFrom } from 'rxjs/operators';
import { import {
configureRequest, configureRequest,
filterSuccessfulResponses, getRequestFromSelflink, getRequestFromUUID, filterSuccessfulResponses,
getResponseFromSelflink getResponseFromSelflink
} from '../shared/operators'; } from '../shared/operators';
import { ResponseCacheEntry } from '../cache/response-cache.reducer'; import { ResponseCacheEntry } from '../cache/response-cache.reducer';
import { HttpOptions } from '../dspace-rest-v2/dspace-rest-v2.service'; import { HttpOptions } from '../dspace-rest-v2/dspace-rest-v2.service';
import { HttpHeaders } from '@angular/common/http'; import { HttpHeaders } from '@angular/common/http';
import { DSOSuccessResponse, ErrorResponse, GenericSuccessResponse } from '../cache/response-cache.models'; import { ErrorResponse, GenericSuccessResponse } from '../cache/response-cache.models';
import { AuthService } from '../auth/auth.service'; import { AuthService } from '../auth/auth.service';
import { Collection } from '../shared/collection.model';
import { Community } from '../shared/community.model';
import { NotificationsService } from '../../shared/notifications/notifications.service'; import { NotificationsService } from '../../shared/notifications/notifications.service';
import { NotificationOptions } from '../../shared/notifications/models/notification-options.model'; import { NotificationOptions } from '../../shared/notifications/models/notification-options.model';
...@@ -123,19 +120,18 @@ export abstract class DataService<TNormalized extends NormalizedObject, TDomain> ...@@ -123,19 +120,18 @@ export abstract class DataService<TNormalized extends NormalizedObject, TDomain>
const requestId = this.requestService.generateRequestId(); const requestId = this.requestService.generateRequestId();
const endpoint$ = this.halService.getEndpoint(this.linkPath).pipe( const endpoint$ = this.halService.getEndpoint(this.linkPath).pipe(
isNotEmptyOperator(), isNotEmptyOperator(),
distinctUntilChanged(), distinctUntilChanged()
withLatestFrom(this.buildCreateParams(dso)),
map(([endpointURL, params]) => endpointURL + params)
); );
const request$ = endpoint$.pipe( const request$ = endpoint$.pipe(
take(1), take(1),
map((endpoint) => { withLatestFrom(this.buildCreateBody(dso)),
map(([endpoint, formdata]) => {
const options: HttpOptions = Object.create({}); const options: HttpOptions = Object.create({});
const headers = new HttpHeaders(); let headers = new HttpHeaders();
headers.append('Authentication', this.authService.buildAuthHeader()); headers = headers.append('Content-Type','multipart/form-data');
options.headers = headers; options.headers = headers;
return new CreateRequest(requestId, endpoint, options); return new CreateRequest(requestId, endpoint, formdata, options);
}), }),
configureRequest(this.requestService) configureRequest(this.requestService)
); );
...@@ -162,6 +158,6 @@ export abstract class DataService<TNormalized extends NormalizedObject, TDomain> ...@@ -162,6 +158,6 @@ export abstract class DataService<TNormalized extends NormalizedObject, TDomain>
return this.rdbService.toRemoteDataObservable(requestEntry$, responseCache$, payload$); return this.rdbService.toRemoteDataObservable(requestEntry$, responseCache$, payload$);
} }
public abstract buildCreateParams(dso: TDomain): Observable<string>; public abstract buildCreateBody(dso: TDomain): Observable<any>;
} }
...@@ -36,7 +36,7 @@ class DataServiceImpl extends DataService<NormalizedDSpaceObject, DSpaceObject> ...@@ -36,7 +36,7 @@ class DataServiceImpl extends DataService<NormalizedDSpaceObject, DSpaceObject>
return endpoint.replace(/\{\?uuid\}/,`?uuid=${resourceID}`); return endpoint.replace(/\{\?uuid\}/,`?uuid=${resourceID}`);
} }
buildCreateParams(dso: DSpaceObject): Observable<string> { buildCreateBody(dso: DSpaceObject): Observable<FormData> {
return undefined; return undefined;
} }
} }
......
...@@ -45,8 +45,8 @@ export class ItemDataService extends DataService<NormalizedItem, Item> { ...@@ -45,8 +45,8 @@ export class ItemDataService extends DataService<NormalizedItem, Item> {
} }
} }
buildCreateParams(dso: Item): Observable<string> { buildCreateBody(dso: Item): Observable<FormData> {
// TODO: Build parameters for creating an Item on the REST service // TODO: Build http body for creating an Item on the REST service
return undefined; return undefined;
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment