From fda083137a2854daaf780a523d39a3fb699937c8 Mon Sep 17 00:00:00 2001 From: Kristof De Langhe Date: Thu, 5 Dec 2019 15:48:54 +0100 Subject: [PATCH] 67611: Import external entry as new entity pt1 --- resources/i18n/en.json5 | 2 ++ src/app/core/data/item-data.service.ts | 29 +++++++++++++++++++ ...ynamic-form-control-container.component.ts | 14 +++++++-- ...namic-lookup-relation-modal.component.html | 2 ++ ...dynamic-lookup-relation-modal.component.ts | 1 + ...-relation-external-source-tab.component.ts | 6 ++++ ...l-source-entry-import-modal.component.html | 12 ++++++-- ...nal-source-entry-import-modal.component.ts | 27 +++++++++++++++-- 8 files changed, 84 insertions(+), 9 deletions(-) diff --git a/resources/i18n/en.json5 b/resources/i18n/en.json5 index fe7949d8b1..16d5d64bd9 100644 --- a/resources/i18n/en.json5 +++ b/resources/i18n/en.json5 @@ -1533,6 +1533,8 @@ "submission.sections.describe.relationship-lookup.external-source.import-modal.cancel": "Cancel", + "submission.sections.describe.relationship-lookup.external-source.import-modal.collection": "Select a collection to import new entries to", + "submission.sections.describe.relationship-lookup.external-source.import-modal.entities": "Entities", "submission.sections.describe.relationship-lookup.external-source.import-modal.entities.new": "Import as a new local entity", diff --git a/src/app/core/data/item-data.service.ts b/src/app/core/data/item-data.service.ts index e616cb8020..b5f16227a8 100644 --- a/src/app/core/data/item-data.service.ts +++ b/src/app/core/data/item-data.service.ts @@ -37,6 +37,7 @@ import { HttpOptions } from '../dspace-rest-v2/dspace-rest-v2.service'; import { Collection } from '../shared/collection.model'; import { RemoteData } from './remote-data'; import { PaginatedList } from './paginated-list'; +import { ExternalSourceEntry } from '../shared/external-source-entry.model'; @Injectable() export class ItemDataService extends DataService { @@ -247,4 +248,32 @@ export class ItemDataService extends DataService { map((request: RequestEntry) => request.response) ); } + + /** + * Import an external source entry into a collection + * @param externalSourceEntry + * @param collectionId + */ + public importExternalSourceEntry(externalSourceEntry: ExternalSourceEntry, collectionId: string): Observable { + const options: HttpOptions = Object.create({}); + let headers = new HttpHeaders(); + headers = headers.append('Content-Type', 'text/uri-list'); + options.headers = headers; + + const requestId = this.requestService.generateRequestId(); + const href$ = this.halService.getEndpoint(this.linkPath).pipe(map((href) => `${href}?owningCollection=${collectionId}`)); + + href$.pipe( + find((href: string) => hasValue(href)), + map((href: string) => { + const request = new PostRequest(requestId, href, externalSourceEntry.self, options); + this.requestService.configure(request); + }) + ).subscribe(); + + return this.requestService.getByUUID(requestId).pipe( + find((request: RequestEntry) => request.completed), + map((request: RequestEntry) => request.response) + ); + } } diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.ts index b78385dc62..d6e3a97a11 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/ds-dynamic-form-control-container.component.ts @@ -101,6 +101,7 @@ import { ItemSearchResult } from '../../../object-collection/shared/item-search- import { ItemMetadataRepresentation } from '../../../../core/shared/metadata-representation/item/item-metadata-representation.model'; import { MetadataValue } from '../../../../core/shared/metadata.models'; import * as uuidv4 from 'uuid/v4'; +import { Collection } from '../../../../core/shared/collection.model'; export function dsDynamicFormControlMapFn(model: DynamicFormControlModel): Type | null { switch (model.type) { @@ -188,6 +189,7 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo hasRelationLookup: boolean; modalRef: NgbModalRef; item: Item; + collection: Collection; listId: string; searchConfig: string; selectedValues$: Observable (submissionObject.item as Observable>).pipe(getAllSucceededRemoteData(), getRemoteDataPayload()))); + getRemoteDataPayload() + ); + + const item$ = submissionObject$.pipe(switchMap((submissionObject: SubmissionObject) => (submissionObject.item as Observable>).pipe(getAllSucceededRemoteData(), getRemoteDataPayload()))); + const collection$ = submissionObject$.pipe(switchMap((submissionObject: SubmissionObject) => (submissionObject.collection as Observable>).pipe(getAllSucceededRemoteData(), getRemoteDataPayload()))); this.subs.push(item$.subscribe((item) => this.item = item)); + this.subs.push(collection$.subscribe((collection) => this.collection = collection)); this.relationService.getRelatedItemsByLabel(this.item, this.model.relationship.relationshipType).pipe( map((items: RemoteData>) => items.payload.page.map((item) => Object.assign(new ItemSearchResult(), { indexableObject: item }))), @@ -325,6 +332,7 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo modalComp.label = this.model.label; modalComp.metadataFields = this.model.metadataFields; modalComp.item = this.item; + modalComp.collection = this.collection; } removeSelection(object: SearchResult) { diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component.html b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component.html index 4c87ac8bdb..1773661486 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component.html +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component.html @@ -26,6 +26,8 @@ ; context: Context; diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/external-source-tab/dynamic-lookup-relation-external-source-tab.component.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/external-source-tab/dynamic-lookup-relation-external-source-tab.component.ts index 18dfa4277f..dfdb1508fc 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/external-source-tab/dynamic-lookup-relation-external-source-tab.component.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/external-source-tab/dynamic-lookup-relation-external-source-tab.component.ts @@ -20,6 +20,8 @@ import { ExternalSourceEntryImportModalComponent } from './external-source-entry import { Subscription } from 'rxjs/internal/Subscription'; import { hasValue } from '../../../../../empty.util'; import { SelectableListService } from '../../../../../object-list/selectable-list/selectable-list.service'; +import { Item } from '../../../../../../core/shared/item.model'; +import { Collection } from '../../../../../../core/shared/collection.model'; @Component({ selector: 'ds-dynamic-lookup-relation-external-source-tab', @@ -40,6 +42,8 @@ import { SelectableListService } from '../../../../../object-list/selectable-lis export class DsDynamicLookupRelationExternalSourceTabComponent implements OnInit, OnDestroy { @Input() label: string; @Input() listId: string; + @Input() item: Item; + @Input() collection: Collection; @Input() relationship: RelationshipOptions; @Input() repeatable: boolean; @Input() context: Context; @@ -103,6 +107,8 @@ export class DsDynamicLookupRelationExternalSourceTabComponent implements OnInit }); const modalComp = this.modalRef.componentInstance; modalComp.externalSourceEntry = entry; + modalComp.item = this.item; + modalComp.collection = this.collection; modalComp.relationship = this.relationship; this.importObjectSub = modalComp.importedObject.subscribe((object) => { this.selectableListService.selectSingle(this.listId, object); diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/external-source-tab/external-source-entry-import-modal/external-source-entry-import-modal.component.html b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/external-source-tab/external-source-entry-import-modal/external-source-entry-import-modal.component.html index 348b7eae18..ffb3aabde8 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/external-source-tab/external-source-entry-import-modal/external-source-entry-import-modal.component.html +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/external-source-tab/external-source-entry-import-modal/external-source-entry-import-modal.component.html @@ -13,7 +13,13 @@

{{ ('submission.sections.describe.relationship-lookup.external-source.import-modal.select' | translate) }}

-
+
+
+ + +
+
+
{{ ('submission.sections.describe.relationship-lookup.external-source.import-modal.entities' | translate) }}
-
+
@@ -37,7 +43,7 @@
{{ ('submission.sections.describe.relationship-lookup.external-source.import-modal.authority' | translate) }}
-
+
diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/external-source-tab/external-source-entry-import-modal/external-source-entry-import-modal.component.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/external-source-tab/external-source-entry-import-modal/external-source-entry-import-modal.component.ts index f8b7b07184..acd1fa59ea 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/external-source-tab/external-source-entry-import-modal/external-source-entry-import-modal.component.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/external-source-tab/external-source-entry-import-modal/external-source-entry-import-modal.component.ts @@ -15,7 +15,8 @@ import { CollectionElementLinkType } from '../../../../../../object-collection/c import { Context } from '../../../../../../../core/shared/context.model'; import { SelectableListService } from '../../../../../../object-list/selectable-list/selectable-list.service'; import { ListableObject } from '../../../../../../object-collection/shared/listable-object.model'; -import { take } from 'rxjs/operators'; +import { Collection } from '../../../../../../../core/shared/collection.model'; +import { ItemDataService } from '../../../../../../../core/data/item-data.service'; /** * The possible types of import for the external entry @@ -39,6 +40,21 @@ export class ExternalSourceEntryImportModalComponent implements OnInit { */ externalSourceEntry: ExternalSourceEntry; + /** + * The item in submission + */ + item: Item; + + /** + * The collection the user is submitting in + */ + collection: Collection; + + /** + * The ID of the collection to import entries to + */ + collectionId: string; + /** * The current relationship-options used for filtering results */ @@ -106,13 +122,15 @@ export class ExternalSourceEntryImportModalComponent implements OnInit { constructor(public modal: NgbActiveModal, public lookupRelationService: LookupRelationService, - private selectService: SelectableListService) { + private selectService: SelectableListService, + private itemService: ItemDataService) { } ngOnInit(): void { this.uri = Metadata.first(this.externalSourceEntry.metadata, 'dc.identifier.uri'); this.searchOptions = Object.assign(new PaginatedSearchOptions({ query: 'sarah' })); this.localEntitiesRD$ = this.lookupRelationService.getLocalResults(this.relationship, this.searchOptions); + this.collectionId = this.collection.id; } /** @@ -162,7 +180,10 @@ export class ExternalSourceEntryImportModalComponent implements OnInit { * Create and import a new entity from the external entry */ importNewEntity() { - this.importedObject.emit(this.externalSourceEntry); + console.log(this.collection); + this.itemService.importExternalSourceEntry(this.externalSourceEntry, this.collectionId).subscribe((response) => { + console.log(response); + }); } /**