diff --git a/resources/i18n/en.json5 b/resources/i18n/en.json5 index a9078373ae..f83ed568da 100644 --- a/resources/i18n/en.json5 +++ b/resources/i18n/en.json5 @@ -159,7 +159,7 @@ "collection.edit.tabs.roles.head": "Assign Roles", "collection.edit.tabs.roles.title": "Collection Edit - Roles", "collection.edit.tabs.source.external": "This collection harvests its content from an external source", - "collection.edit.tabs.source.form.errors.provider.required": "You must provide a set id of the target collection.", + "collection.edit.tabs.source.form.errors.oaiSource.required": "You must provide a set id of the target collection.", "collection.edit.tabs.source.form.harvestType": "Content being harvested", "collection.edit.tabs.source.form.head": "Configure an external source", "collection.edit.tabs.source.form.metadataConfigId": "Metadata Format", @@ -478,6 +478,7 @@ "loading.browse-by-page": "Loading page...", "loading.collection": "Loading collection...", "loading.collections": "Loading collections...", + "loading.content-source": "Loading content source...", "loading.community": "Loading community...", "loading.default": "Loading...", "loading.item": "Loading item...", diff --git a/src/app/+collection-page/edit-collection-page/collection-source/collection-source.component.html b/src/app/+collection-page/edit-collection-page/collection-source/collection-source.component.html index d02637ed80..dfcd6e3166 100644 --- a/src/app/+collection-page/edit-collection-page/collection-source/collection-source.component.html +++ b/src/app/+collection-page/edit-collection-page/collection-source/collection-source.component.html @@ -18,11 +18,12 @@

{{ 'collection.edit.tabs.source.head' | translate }}

-
+
-

{{ 'collection.edit.tabs.source.form.head' | translate }}

+ +

{{ 'collection.edit.tabs.source.form.head' | translate }}

{ if (update) { const field = update.field as ContentSource; - const defaultConfigId = this.contentSource.metadataConfigs[0].id; + let defaultConfigId; + if (hasValue(this.contentSource) && isNotEmpty(this.contentSource.metadataConfigs)) { + defaultConfigId = this.contentSource.metadataConfigs[0].id; + } this.formGroup.patchValue({ oaiSourceContainer: { oaiSource: field.oaiSource @@ -355,9 +366,14 @@ export class CollectionSourceComponent extends AbstractTrackableComponent implem map((col) => col.payload.uuid), switchMap((uuid) => this.collectionService.updateContentSource(uuid, this.contentSource)), take(1) - ).subscribe((contentSource: ContentSource) => { - this.initializeOriginalContentSource(contentSource); - this.notificationsService.success(this.getNotificationTitle('saved'), this.getNotificationContent('saved')); + ).subscribe((result: ContentSource | INotification) => { + if (hasValue((result as any).harvestType)) { + this.clearNotifications(); + this.initializeOriginalContentSource(result as ContentSource); + this.displayedNotifications.push(this.notificationsService.success(this.getNotificationTitle('saved'), this.getNotificationContent('saved'))); + } else { + this.displayedNotifications.push(result as INotification); + } }); } @@ -419,6 +435,16 @@ export class CollectionSourceComponent extends AbstractTrackableComponent implem this.objectUpdatesService.saveAddFieldUpdate(this.url, cloneDeep(this.contentSource)); } + /** + * Clear possible active notifications + */ + clearNotifications() { + this.displayedNotifications.forEach((notification: INotification) => { + this.notificationsService.remove(notification); + }); + this.displayedNotifications = []; + } + /** * Make sure open subscriptions are closed */ diff --git a/src/app/core/data/collection-data.service.ts b/src/app/core/data/collection-data.service.ts index 94860e5df7..e53b684539 100644 --- a/src/app/core/data/collection-data.service.ts +++ b/src/app/core/data/collection-data.service.ts @@ -38,6 +38,7 @@ import { ResponseParsingService } from './parsing.service'; import { GenericConstructor } from '../shared/generic-constructor'; import { DSpaceObject } from '../shared/dspace-object.model'; import { PaginatedSearchOptions } from '../../+search-page/paginated-search-options.model'; +import { INotification } from '../../shared/notifications/models/notification.model'; @Injectable() export class CollectionDataService extends ComColDataService { @@ -140,7 +141,7 @@ export class CollectionDataService extends ComColDataService { * @param collectionId * @param contentSource */ - updateContentSource(collectionId: string, contentSource: ContentSource): Observable { + updateContentSource(collectionId: string, contentSource: ContentSource): Observable { const requestId = this.requestService.generateRequestId(); const serializedContentSource = new DSpaceRESTv2Serializer(ContentSource).serialize(contentSource); const request$ = this.getHarvesterEndpoint(collectionId).pipe( @@ -166,9 +167,9 @@ export class CollectionDataService extends ComColDataService { 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)); + return 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)); + return this.notificationsService.error(this.translate.instant(this.errorTitle), (response as any).errorMessage, new NotificationOptions(-1)); } } } else { @@ -176,10 +177,11 @@ export class CollectionDataService extends ComColDataService { } }), isNotEmptyOperator(), - map((response: ContentSourceSuccessResponse) => { - if (isNotEmpty(response.contentsource)) { - return response.contentsource; + map((response: ContentSourceSuccessResponse | INotification) => { + if (isNotEmpty((response as any).contentsource)) { + return (response as ContentSourceSuccessResponse).contentsource; } + return response as INotification; }) ); } diff --git a/src/app/core/data/content-source-response-parsing.service.ts b/src/app/core/data/content-source-response-parsing.service.ts index 649a8f9b96..4e0490148b 100644 --- a/src/app/core/data/content-source-response-parsing.service.ts +++ b/src/app/core/data/content-source-response-parsing.service.ts @@ -20,8 +20,8 @@ export class ContentSourceResponseParsingService implements ResponseParsingServi const deserialized = new DSpaceRESTv2Serializer(ContentSource).deserialize(payload); let metadataConfigs = []; - if (payload._embedded && payload._embedded.metadata_configs && payload._embedded.metadata_configs.configs) { - metadataConfigs = new DSpaceRESTv2Serializer(MetadataConfig).serializeArray(payload._embedded.metadata_configs.configs); + if (payload._embedded && payload._embedded.harvestermetadata && payload._embedded.harvestermetadata.configs) { + metadataConfigs = new DSpaceRESTv2Serializer(MetadataConfig).serializeArray(payload._embedded.harvestermetadata.configs); } deserialized.metadataConfigs = metadataConfigs;