mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
64503: Content Source PUT request on form submit
This commit is contained in:
@@ -131,6 +131,8 @@
|
|||||||
"collection.page.browse.recent.head": "Recent Submissions",
|
"collection.page.browse.recent.head": "Recent Submissions",
|
||||||
"collection.page.license": "License",
|
"collection.page.license": "License",
|
||||||
"collection.page.news": "News",
|
"collection.page.news": "News",
|
||||||
|
"collection.source.update.notifications.error.content": "The provided settings have been tested and didn't work.",
|
||||||
|
"collection.source.update.notifications.error.title": "Server Error",
|
||||||
"community.create.head": "Create a Community",
|
"community.create.head": "Create a Community",
|
||||||
"community.create.sub-head": "Create a Sub-Community for Community {{ parent }}",
|
"community.create.sub-head": "Create a Sub-Community for Community {{ parent }}",
|
||||||
"community.delete.cancel": "Cancel",
|
"community.delete.cancel": "Cancel",
|
||||||
|
@@ -331,9 +331,16 @@ export class CollectionSourceComponent extends AbstractTrackableComponent implem
|
|||||||
* Submit the edited Content Source to the REST API, re-initialize the field update and display a notification
|
* Submit the edited Content Source to the REST API, re-initialize the field update and display a notification
|
||||||
*/
|
*/
|
||||||
onSubmit() {
|
onSubmit() {
|
||||||
// TODO: Fetch field update and send to REST API
|
this.collectionRD$.pipe(
|
||||||
|
getSucceededRemoteData(),
|
||||||
|
map((col) => col.payload.uuid),
|
||||||
|
switchMap((uuid) => this.collectionService.updateContentSource(uuid, this.contentSource)),
|
||||||
|
take(1)
|
||||||
|
).subscribe((contentSource: ContentSource) => {
|
||||||
|
this.contentSource = contentSource;
|
||||||
this.initializeOriginalContentSource();
|
this.initializeOriginalContentSource();
|
||||||
this.notificationsService.success(this.getNotificationTitle('saved'), this.getNotificationContent('saved'));
|
this.notificationsService.success(this.getNotificationTitle('saved'), this.getNotificationContent('saved'));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -12,21 +12,33 @@ import { CommunityDataService } from './community-data.service';
|
|||||||
import { RequestService } from './request.service';
|
import { RequestService } from './request.service';
|
||||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||||
import { HttpClient } from '@angular/common/http';
|
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||||
import { NormalizedObjectBuildService } from '../cache/builders/normalized-object-build.service';
|
import { NormalizedObjectBuildService } from '../cache/builders/normalized-object-build.service';
|
||||||
import { DSOChangeAnalyzer } from './dso-change-analyzer.service';
|
import { DSOChangeAnalyzer } from './dso-change-analyzer.service';
|
||||||
import { Observable } from 'rxjs/internal/Observable';
|
import { Observable } from 'rxjs/internal/Observable';
|
||||||
import { ContentSourceRequest, FindAllOptions, RestRequest } from './request.models';
|
import { ContentSourceRequest, FindAllOptions, RestRequest, UpdateContentSourceRequest } from './request.models';
|
||||||
import { RemoteData } from './remote-data';
|
import { RemoteData } from './remote-data';
|
||||||
import { PaginatedList } from './paginated-list';
|
import { PaginatedList } from './paginated-list';
|
||||||
import { ContentSource } from '../shared/content-source.model';
|
import { ContentSource } from '../shared/content-source.model';
|
||||||
import { configureRequest, filterSuccessfulResponses, getRequestFromRequestHref } from '../shared/operators';
|
import {
|
||||||
import { ContentSourceSuccessResponse } from '../cache/response.models';
|
configureRequest,
|
||||||
|
filterSuccessfulResponses,
|
||||||
|
getRequestFromRequestHref,
|
||||||
|
getResponseFromEntry
|
||||||
|
} from '../shared/operators';
|
||||||
|
import { ContentSourceSuccessResponse, RestResponse } from '../cache/response.models';
|
||||||
|
import { HttpOptions } from '../dspace-rest-v2/dspace-rest-v2.service';
|
||||||
|
import { DSpaceRESTv2Serializer } from '../dspace-rest-v2/dspace-rest-v2.serializer';
|
||||||
|
import { hasValue, isNotEmpty, isNotEmptyOperator } from '../../shared/empty.util';
|
||||||
|
import { NotificationOptions } from '../../shared/notifications/models/notification-options.model';
|
||||||
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CollectionDataService extends ComColDataService<Collection> {
|
export class CollectionDataService extends ComColDataService<Collection> {
|
||||||
protected linkPath = 'collections';
|
protected linkPath = 'collections';
|
||||||
protected forceBypassCache = false;
|
protected forceBypassCache = false;
|
||||||
|
protected errorTitle = 'collection.source.update.notifications.error.title';
|
||||||
|
protected contentSourceError = 'collection.source.update.notifications.error.content';
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
protected requestService: RequestService,
|
protected requestService: RequestService,
|
||||||
@@ -38,7 +50,8 @@ export class CollectionDataService extends ComColDataService<Collection> {
|
|||||||
protected halService: HALEndpointService,
|
protected halService: HALEndpointService,
|
||||||
protected notificationsService: NotificationsService,
|
protected notificationsService: NotificationsService,
|
||||||
protected http: HttpClient,
|
protected http: HttpClient,
|
||||||
protected comparator: DSOChangeAnalyzer<Collection>
|
protected comparator: DSOChangeAnalyzer<Collection>,
|
||||||
|
protected translate: TranslateService
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
@@ -77,4 +90,48 @@ export class CollectionDataService extends ComColDataService<Collection> {
|
|||||||
map((response: ContentSourceSuccessResponse) => response.contentsource)
|
map((response: ContentSourceSuccessResponse) => response.contentsource)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateContentSource(collectionId: string, contentSource: ContentSource): Observable<ContentSource> {
|
||||||
|
const requestId = this.requestService.generateRequestId();
|
||||||
|
const serializedContentSource = new DSpaceRESTv2Serializer(ContentSource).serialize(contentSource);
|
||||||
|
const request$ = this.getHarvesterEndpoint(collectionId).pipe(
|
||||||
|
take(1),
|
||||||
|
map((href: string) => {
|
||||||
|
const options: HttpOptions = Object.create({});
|
||||||
|
let headers = new HttpHeaders();
|
||||||
|
headers = headers.append('Content-Type', 'application/json');
|
||||||
|
options.headers = headers;
|
||||||
|
return new UpdateContentSourceRequest(requestId, href, JSON.stringify(serializedContentSource), options);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
// Execute the post/put request
|
||||||
|
request$.pipe(
|
||||||
|
configureRequest(this.requestService)
|
||||||
|
).subscribe();
|
||||||
|
|
||||||
|
// Return updated ContentSource
|
||||||
|
return this.requestService.getByUUID(requestId).pipe(
|
||||||
|
getResponseFromEntry(),
|
||||||
|
map((response: RestResponse) => {
|
||||||
|
if (!response.isSuccessful) {
|
||||||
|
if (hasValue((response as any).errorMessage)) {
|
||||||
|
if (response.statusCode === 422) {
|
||||||
|
this.notificationsService.error(this.translate.instant(this.errorTitle), this.translate.instant(this.contentSourceError), new NotificationOptions(-1));
|
||||||
|
} else {
|
||||||
|
this.notificationsService.error(this.translate.instant(this.errorTitle), (response as any).errorMessage, new NotificationOptions(-1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
isNotEmptyOperator(),
|
||||||
|
map((response: ContentSourceSuccessResponse) => {
|
||||||
|
if (isNotEmpty(response.contentsource)) {
|
||||||
|
return response.contentsource;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -369,6 +369,16 @@ export class ContentSourceRequest extends GetRequest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class UpdateContentSourceRequest extends PutRequest {
|
||||||
|
constructor(uuid: string, href: string, public body?: any, public options?: HttpOptions) {
|
||||||
|
super(uuid, href, body, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
getResponseParser(): GenericConstructor<ResponseParsingService> {
|
||||||
|
return ContentSourceResponseParsingService;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request to delete an object based on its identifier
|
* Request to delete an object based on its identifier
|
||||||
*/
|
*/
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { autoserialize, autoserializeAs } from 'cerialize';
|
import { autoserialize, autoserializeAs, deserializeAs, deserialize } from 'cerialize';
|
||||||
|
|
||||||
export enum ContentSourceHarvestType {
|
export enum ContentSourceHarvestType {
|
||||||
None = 'NONE',
|
None = 'NONE',
|
||||||
@@ -15,7 +15,7 @@ export class ContentSource {
|
|||||||
* Unique identifier, this is necessary to store the ContentSource in FieldUpdates
|
* Unique identifier, this is necessary to store the ContentSource in FieldUpdates
|
||||||
* Because the ContentSource coming from the REST API doesn't have a UUID, we're using the selflink
|
* Because the ContentSource coming from the REST API doesn't have a UUID, we're using the selflink
|
||||||
*/
|
*/
|
||||||
@autoserializeAs('self')
|
@deserializeAs('self')
|
||||||
uuid: string;
|
uuid: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -46,6 +46,6 @@ export class ContentSource {
|
|||||||
/**
|
/**
|
||||||
* The REST link to itself
|
* The REST link to itself
|
||||||
*/
|
*/
|
||||||
@autoserialize
|
@deserialize
|
||||||
self: string;
|
self: string;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user