From 1f643cda9a82b487d793074f76f00d6e56e18a53 Mon Sep 17 00:00:00 2001 From: dtziotzios Date: Tue, 26 Mar 2019 16:45:27 +0200 Subject: [PATCH] Adds export as Docx functionality on Datsets --- .../controllers/DatasetWizardController.java | 15 +++++++++++++++ .../dataset-wizard/dataset-wizard.service.ts | 5 +++++ .../dataset-wizard/dataset-wizard.component.html | 2 ++ .../dataset-wizard/dataset-wizard.component.scss | 7 +++++-- .../dataset-wizard/dataset-wizard.component.ts | 12 ++++++++++++ 5 files changed, 39 insertions(+), 2 deletions(-) diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetWizardController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetWizardController.java index c79dfd0ac..6f9cf262d 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetWizardController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetWizardController.java @@ -80,6 +80,21 @@ public class DatasetWizardController extends BaseController { return this.datasetManager.getDocument(id, visibilityRuleService, contentType); } + else if (contentType.equals("application/msword")){ + File file = datasetManager.getWordDocument(this.environment, id, this.getApiContext().getUtilitiesService().getVisibilityRuleService()); + InputStream resource = new FileInputStream(file); + HttpHeaders responseHeaders = new HttpHeaders(); + responseHeaders.setContentLength(file.length()); + responseHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM); + responseHeaders.set("Content-Disposition", "attachment;filename=" + file.getName() + ".docx"); + responseHeaders.set("Access-Control-Expose-Headers", "Content-Disposition"); + responseHeaders.get("Access-Control-Expose-Headers").add("Content-Type"); + byte[] content = IOUtils.toByteArray(resource); + + return new ResponseEntity<>(content, + responseHeaders, + HttpStatus.OK); + } else { DatasetWizardModel dataset = this.datasetManager.getSingle(id); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).payload(dataset)); diff --git a/dmp-frontend/src/app/core/services/dataset-wizard/dataset-wizard.service.ts b/dmp-frontend/src/app/core/services/dataset-wizard/dataset-wizard.service.ts index 4e5e294e9..6b0d058ff 100644 --- a/dmp-frontend/src/app/core/services/dataset-wizard/dataset-wizard.service.ts +++ b/dmp-frontend/src/app/core/services/dataset-wizard/dataset-wizard.service.ts @@ -45,6 +45,11 @@ export class DatasetWizardService { return this.httpClient.get(this.actionUrl + 'getPDF/' + id, { responseType: 'blob', observe: 'response', headers: this.headers }); } + public downloadDOCX(id: string): Observable> { + let headerDocx: HttpHeaders = this.headers.set('Content-Type', 'application/msword') + return this.httpClient.get(this.actionUrl + id, { responseType: 'blob', observe: 'response', headers: headerDocx }); + } + public downloadXML(id: string): Observable> { let headerXml: HttpHeaders = this.headers.set('Content-Type', 'application/xml') return this.httpClient.get(this.actionUrl + id, { responseType: 'blob', observe: 'response', headers: headerXml }); // + 'getXml/' diff --git a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.html b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.html index 8c85c9e7f..67575a798 100644 --- a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.html +++ b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.html @@ -29,6 +29,8 @@ 'DATASET-WIZARD.ACTIONS.SAVE-AND-FINALISE' | translate }} +
diff --git a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.scss b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.scss index 56bc9cb23..545c569b1 100644 --- a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.scss +++ b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.scss @@ -2,11 +2,9 @@ .step-container { margin-top: 1em; } - .external-item-card { margin-top: 1em; } - .external-item-action-row, .description-action-row { margin-top: 1em; @@ -36,4 +34,9 @@ margin-bottom: 15px; margin-right: 15px; } + .downloadDOCX { + margin-top: 15px; + margin-bottom: 15px; + margin-right: 15px; + } } diff --git a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.ts b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.ts index 9ade1b6b3..39170e736 100644 --- a/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.ts +++ b/dmp-frontend/src/app/ui/dataset/dataset-wizard/dataset-wizard.component.ts @@ -325,6 +325,18 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr }); } + downloadDOCX(): void { + this.datasetWizardService.downloadDOCX(this.itemId) + .pipe(takeUntil(this._destroyed)) + .subscribe(response => { + const blob = new Blob([response.body], { type: 'application/msword' }); + const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); + + FileSaver.saveAs(blob, filename); + }); + + } + downloadXML(): void { this.datasetWizardService.downloadXML(this.itemId) .pipe(takeUntil(this._destroyed))