diff --git a/src/app/+collection-page/collection-page.component.html b/src/app/+collection-page/collection-page.component.html
index 12d5c200fd..11f406599a 100644
--- a/src/app/+collection-page/collection-page.component.html
+++ b/src/app/+collection-page/collection-page.component.html
@@ -32,6 +32,13 @@
+
+
+
* server response
+ * @param collectionId
+ * The owning collection id
*/
- public postToEndpoint(linkName: string, body: any, scopeId?: string, options?: HttpOptions): Observable {
+ public postToEndpoint(linkName: string, body: any, scopeId?: string, options?: HttpOptions, collectionId?: string): Observable {
const requestId = this.requestService.generateRequestId();
return this.halService.getEndpoint(linkName).pipe(
filter((href: string) => isNotEmpty(href)),
- map((endpointURL: string) => this.getEndpointByIDHref(endpointURL, scopeId)),
+ map((endpointURL: string) => this.getEndpointByIDHref(endpointURL, scopeId, collectionId)),
distinctUntilChanged(),
map((endpointURL: string) => new SubmissionPostRequest(requestId, endpointURL, body, options)),
tap((request: PostRequest) => this.requestService.configure(request)),
diff --git a/src/app/submission/submission.service.spec.ts b/src/app/submission/submission.service.spec.ts
index 3a95b0747b..1b346a56eb 100644
--- a/src/app/submission/submission.service.spec.ts
+++ b/src/app/submission/submission.service.spec.ts
@@ -401,6 +401,14 @@ describe('SubmissionService test suite', () => {
service.createSubmission();
expect((service as any).restService.postToEndpoint).toHaveBeenCalled();
+ expect((service as any).restService.postToEndpoint).toHaveBeenCalledWith('workspaceitems', {}, null, null, undefined);
+ });
+
+ it('should create a new submission with collection', () => {
+ service.createSubmission(collectionId);
+
+ expect((service as any).restService.postToEndpoint).toHaveBeenCalled();
+ expect((service as any).restService.postToEndpoint).toHaveBeenCalledWith('workspaceitems', {}, null, null, collectionId);
});
});
diff --git a/src/app/submission/submission.service.ts b/src/app/submission/submission.service.ts
index fa8024af53..1991e8b3f1 100644
--- a/src/app/submission/submission.service.ts
+++ b/src/app/submission/submission.service.ts
@@ -109,11 +109,13 @@ export class SubmissionService {
/**
* Perform a REST call to create a new workspaceitem and return response
*
+ * @param collectionId
+ * The owning collection id
* @return Observable
* observable of SubmissionObject
*/
- createSubmission(): Observable {
- return this.restService.postToEndpoint(this.workspaceLinkPath, {}).pipe(
+ createSubmission(collectionId?: string): Observable {
+ return this.restService.postToEndpoint(this.workspaceLinkPath, {}, null, null, collectionId).pipe(
map((workspaceitem: SubmissionObject) => workspaceitem[0]),
catchError(() => observableOf({})))
}
diff --git a/src/app/submission/submit/submission-submit.component.spec.ts b/src/app/submission/submit/submission-submit.component.spec.ts
index 771171a2d1..ca3316669f 100644
--- a/src/app/submission/submit/submission-submit.component.spec.ts
+++ b/src/app/submission/submit/submission-submit.component.spec.ts
@@ -1,6 +1,6 @@
import { async, ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
-import { Router } from '@angular/router';
+import { ActivatedRoute, Router } from '@angular/router';
import { NO_ERRORS_SCHEMA, ViewContainerRef } from '@angular/core';
import { of as observableOf } from 'rxjs';
@@ -14,6 +14,7 @@ import { getMockTranslateService } from '../../shared/mocks/mock-translate.servi
import { RouterStub } from '../../shared/testing/router-stub';
import { mockSubmissionObject } from '../../shared/mocks/mock-submission';
import { SubmissionSubmitComponent } from './submission-submit.component';
+import { ActivatedRouteStub } from '../../shared/testing/active-router-stub';
describe('SubmissionSubmitComponent Component', () => {
@@ -39,6 +40,7 @@ describe('SubmissionSubmitComponent Component', () => {
{ provide: SubmissionService, useClass: SubmissionServiceStub },
{ provide: TranslateService, useValue: getMockTranslateService() },
{ provide: Router, useValue: new RouterStub() },
+ { provide: ActivatedRoute, useValue: new ActivatedRouteStub() },
ViewContainerRef
],
schemas: [NO_ERRORS_SCHEMA]
diff --git a/src/app/submission/submit/submission-submit.component.ts b/src/app/submission/submit/submission-submit.component.ts
index 448ccf97e2..0aa0380a25 100644
--- a/src/app/submission/submit/submission-submit.component.ts
+++ b/src/app/submission/submit/submission-submit.component.ts
@@ -1,5 +1,5 @@
import { ChangeDetectorRef, Component, OnDestroy, OnInit, ViewContainerRef } from '@angular/core';
-import { Router } from '@angular/router';
+import { ActivatedRoute, Router } from '@angular/router';
import { Subscription } from 'rxjs';
@@ -27,6 +27,12 @@ export class SubmissionSubmitComponent implements OnDestroy, OnInit {
*/
public collectionId: string;
+ /**
+ * The collection id input to create a new submission
+ * @type {string}
+ */
+ public collectionParam: string;
+
/**
* The submission self url
* @type {string}
@@ -60,13 +66,18 @@ export class SubmissionSubmitComponent implements OnDestroy, OnInit {
* @param {Router} router
* @param {TranslateService} translate
* @param {ViewContainerRef} viewContainerRef
+ * @param {ActivatedRoute} route
*/
constructor(private changeDetectorRef: ChangeDetectorRef,
private notificationsService: NotificationsService,
private router: Router,
private submissionService: SubmissionService,
private translate: TranslateService,
- private viewContainerRef: ViewContainerRef) {
+ private viewContainerRef: ViewContainerRef,
+ private route: ActivatedRoute) {
+ this.route
+ .queryParams
+ .subscribe((params) => { this.collectionParam = (params.collection); });
}
/**
@@ -75,7 +86,7 @@ export class SubmissionSubmitComponent implements OnDestroy, OnInit {
ngOnInit() {
// NOTE execute the code on the browser side only, otherwise it is executed twice
this.subs.push(
- this.submissionService.createSubmission()
+ this.submissionService.createSubmission(this.collectionParam)
.subscribe((submissionObject: SubmissionObject) => {
// NOTE new submission is created on the browser side only
if (isNotNull(submissionObject)) {