From 395a78c360aa927b515ebf61d2f80083340cac4e Mon Sep 17 00:00:00 2001 From: Yana De Pauw Date: Tue, 28 May 2019 13:14:59 +0200 Subject: [PATCH] 62571: Update item move method --- .../item-move/item-move.component.ts | 5 ++++- src/app/core/data/item-data.service.ts | 22 ++++++++++++------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/app/+item-page/edit-item-page/item-move/item-move.component.ts b/src/app/+item-page/edit-item-page/item-move/item-move.component.ts index 7eb0e4c10e..4f6f9bbe08 100644 --- a/src/app/+item-page/edit-item-page/item-move/item-move.component.ts +++ b/src/app/+item-page/edit-item-page/item-move/item-move.component.ts @@ -17,6 +17,7 @@ import {getItemEditPath} from '../../item-page-routing.module'; import {Observable} from 'rxjs'; import {of as observableOf} from 'rxjs'; import { RestResponse } from '../../../core/cache/response.models'; +import { Collection } from '../../../core/shared/collection.model'; @Component({ selector: 'ds-item-move', @@ -34,6 +35,7 @@ export class ItemMoveComponent implements OnInit { itemRD$: Observable>; collectionSearchResults: Observable = observableOf([]); selectedCollection: string; + selectedCollectionObject: Collection; selectedCollectionId: string; itemId: string; @@ -92,6 +94,7 @@ export class ItemMoveComponent implements OnInit { onClick(data: any): void { this.selectedCollection = data.name; this.selectedCollectionId = data.id; + this.selectedCollectionObject = data; } /** @@ -105,7 +108,7 @@ export class ItemMoveComponent implements OnInit { * Moves the item to a new collection based on the selected collection */ moveCollection() { - this.itemDataService.moveToCollection(this.itemId, this.selectedCollectionId).pipe(first()).subscribe( + this.itemDataService.moveToCollection(this.itemId, this.selectedCollectionObject).pipe(first()).subscribe( (response: RestResponse) => { this.router.navigate([getItemEditPath(this.itemId)]); if (response.isSuccessful) { diff --git a/src/app/core/data/item-data.service.ts b/src/app/core/data/item-data.service.ts index 1e6f3e50de..9d686d98d1 100644 --- a/src/app/core/data/item-data.service.ts +++ b/src/app/core/data/item-data.service.ts @@ -12,15 +12,17 @@ import { URLCombiner } from '../url-combiner/url-combiner'; import { DataService } from './data.service'; import { RequestService } from './request.service'; import { HALEndpointService } from '../shared/hal-endpoint.service'; -import { DeleteByIDRequest, FindAllOptions, PatchRequest, PutRequest, RestRequest } from './request.models'; +import { FindAllOptions, PatchRequest, PutRequest, RestRequest } from './request.models'; import { ObjectCacheService } from '../cache/object-cache.service'; import { NotificationsService } from '../../shared/notifications/notifications.service'; import { DSOChangeAnalyzer } from './dso-change-analyzer.service'; -import { HttpClient } from '@angular/common/http'; +import { HttpClient, HttpHeaders } from '@angular/common/http'; import { NormalizedObjectBuildService } from '../cache/builders/normalized-object-build.service'; import { configureRequest, getRequestFromRequestHref } from '../shared/operators'; import { RequestEntry } from './request.reducer'; import { RestResponse } from '../cache/response.models'; +import { HttpOptions } from '../dspace-rest-v2/dspace-rest-v2.service'; +import { Collection } from '../shared/collection.model'; @Injectable() export class ItemDataService extends DataService { @@ -120,22 +122,26 @@ export class ItemDataService extends DataService { ); } - public getMoveItemEndpoint(itemId: string, collectionId?: string): Observable { + public getMoveItemEndpoint(itemId: string): Observable { return this.halService.getEndpoint(this.linkPath).pipe( map((endpoint: string) => this.getIDHref(endpoint, itemId)), - map((endpoint: string) => `${endpoint}/owningCollection/move/${collectionId ? `/${collectionId}` : ''}`) + map((endpoint: string) => `${endpoint}/owningCollection`) ); } - public moveToCollection(itemId: string, collectionId: string): Observable { - const requestId = this.requestService.generateRequestId(); + public moveToCollection(itemId: string, collection: Collection): Observable { + const options: HttpOptions = Object.create({}); + let headers = new HttpHeaders(); + headers = headers.append('Content-Type', 'text/uri-list'); + options.headers = headers; - const hrefObs = this.getMoveItemEndpoint(itemId, collectionId); + const requestId = this.requestService.generateRequestId(); + const hrefObs = this.getMoveItemEndpoint(itemId); hrefObs.pipe( find((href: string) => hasValue(href)), map((href: string) => { - const request = new PutRequest(requestId, href); + const request = new PutRequest(requestId, href, collection.self, options); this.requestService.configure(request); }) ).subscribe();