diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/DMPs.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/DMPs.java index 0a5488575..2ce1d7161 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/DMPs.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/DMPs.java @@ -5,7 +5,6 @@ import eu.eudat.configurations.dynamicproject.DynamicProjectConfiguration; import eu.eudat.criteria.DMPCriteria; import eu.eudat.data.dao.criteria.DynamicFieldsCriteria; import eu.eudat.data.dao.criteria.RequestItem; -import eu.eudat.data.dao.entities.DMPDao; import eu.eudat.data.entities.DMP; import eu.eudat.data.query.items.table.dmp.DataManagementPlanTableRequest; import eu.eudat.data.query.items.table.dmp.DataManagmentPlanPublicTableRequest; @@ -15,7 +14,6 @@ import eu.eudat.logic.managers.DataManagementPlanManager; import eu.eudat.logic.managers.DatasetManager; import eu.eudat.logic.security.claims.ClaimedAuthorities; import eu.eudat.logic.services.ApiContext; -import eu.eudat.logic.services.forms.VisibilityRuleService; import eu.eudat.logic.services.operations.DatabaseRepository; import eu.eudat.models.data.dmp.DataManagementPlan; import eu.eudat.models.data.helpermodels.Tuple; @@ -25,8 +23,6 @@ import eu.eudat.models.data.listingmodels.DataManagementPlanListingModel; import eu.eudat.models.data.listingmodels.DataManagementPlanOverviewModel; import eu.eudat.models.data.security.Principal; import eu.eudat.query.DMPQuery; -import eu.eudat.query.ProjectQuery; -import eu.eudat.query.UserQuery; import eu.eudat.types.ApiMessageCode; import eu.eudat.types.Authorities; import org.springframework.beans.factory.annotation.Autowired; @@ -46,7 +42,6 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; -import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.UUID; @@ -89,10 +84,8 @@ public class DMPs extends BaseController { @RequestMapping(method = RequestMethod.GET, value = {"{id}"}) public @ResponseBody - ResponseEntity getSingle(@PathVariable String id, @RequestHeader("Content-Type") String contentType, Principal principal) throws IllegalAccessException, InterruptedException, InstantiationException, IOException { + ResponseEntity getSingle(@PathVariable String id, @RequestHeader("Content-Type") String contentType, Principal principal) throws IllegalAccessException, InstantiationException, IOException { if (contentType.equals("application/xml") || contentType.equals("application/msword")) { //|| contentType.equals("application/pdf") - DMPDao dmpDao = this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao(); - VisibilityRuleService visibilityRuleService = this.getApiContext().getUtilitiesService().getVisibilityRuleService(); ResponseEntity document = this.dataManagementPlanManager.getDocument(id, contentType); return document; } else { @@ -101,16 +94,22 @@ public class DMPs extends BaseController { } } + @RequestMapping(method = RequestMethod.GET, value = {"rda/{id}"}) + public @ResponseBody + ResponseEntity getRDAJsonDocument(@PathVariable String id, Principal principal) throws IOException { + return this.dataManagementPlanManager.getRDAJsonDocument(id); + } + @RequestMapping(method = RequestMethod.GET, value = {"/overview/{id}"}) public @ResponseBody - ResponseEntity getOverviewSingle(@PathVariable String id, Principal principal) throws IllegalAccessException, InterruptedException, InstantiationException, IOException { + ResponseEntity getOverviewSingle(@PathVariable String id, Principal principal) throws IllegalAccessException, InstantiationException { DataManagementPlanOverviewModel dataManagementPlan = this.dataManagementPlanManager.getOverviewSingle(id, principal); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan)); } @RequestMapping(method = RequestMethod.GET, value = {"/public/{id}"}) public @ResponseBody - ResponseEntity getSinglePublic(@PathVariable String id) throws IllegalAccessException, InterruptedException, InstantiationException, IOException { + ResponseEntity getSinglePublic(@PathVariable String id) { try { eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlan = this.dataManagementPlanManager.getSinglePublic(id, this.dynamicProjectConfiguration); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan)); diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java index f3882167b..68f31faa2 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java @@ -1,5 +1,6 @@ package eu.eudat.logic.managers; +import com.fasterxml.jackson.databind.ObjectMapper; import eu.eudat.configurations.dynamicproject.DynamicProjectConfiguration; import eu.eudat.configurations.dynamicproject.entities.Property; import eu.eudat.data.dao.criteria.*; @@ -706,7 +707,6 @@ public class DataManagementPlanManager { // Get DatasetProfiles from DMP to add to XML. for (DatasetProfile datasetProfile : dmp.getAssociatedDmps()) { - Element researcherElement = xmlDoc.createElement("researcher"); Element profile = xmlDoc.createElement("profile"); Element profileLabel = xmlDoc.createElement("profilelabel"); profileLabel.setTextContent(datasetProfile.getLabel()); @@ -729,10 +729,39 @@ public class DataManagementPlanManager { return fileEnvelope; } - public ResponseEntity getDocument(String id, String contentType) throws InstantiationException, InterruptedException, IllegalAccessException, IOException{ + public ResponseEntity getRDAJsonDocument(String id) throws IOException { + eu.eudat.data.entities.DMP dmp = databaseRepository.getDmpDao().find(UUID.fromString(id)); + DmpRDAExportModel dmpExport = new DmpRDAExportModel().fromDataModel(dmp); + RDAExportModel rdaExportModel = new RDAExportModel(); + rdaExportModel.setDmp(dmpExport); + + ObjectMapper mapper = new ObjectMapper(); + String fileName = dmp.getLabel(); + fileName = fileName.replaceAll("[^a-zA-Z0-9+ ]", ""); + File file = new File(fileName); + try { + mapper.writeValue(file, rdaExportModel); + } + catch (IOException e) { + e.printStackTrace(); + } + + 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()); + responseHeaders.set("Access-Control-Expose-Headers", "Content-Disposition"); + responseHeaders.get("Access-Control-Expose-Headers").add("Content-Type"); + + byte[] content = org.apache.poi.util.IOUtils.toByteArray(resource); + resource.close(); + Files.deleteIfExists(file.toPath()); + return new ResponseEntity<>(content, responseHeaders, HttpStatus.OK); + } + + public ResponseEntity getDocument(String id, String contentType) throws InstantiationException, IllegalAccessException, IOException { File file; - VisibilityRuleService visibilityRuleService = this.utilitiesService.getVisibilityRuleService(); - DMPDao dmpDao = databaseRepository.getDmpDao(); switch (contentType){ case "application/xml": file = getXmlDocument(id).getFile(); diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/ContactIdRDAExportModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/ContactIdRDAExportModel.java new file mode 100644 index 000000000..009025a20 --- /dev/null +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/ContactIdRDAExportModel.java @@ -0,0 +1,20 @@ +package eu.eudat.models.data.dmp; + +public class ContactIdRDAExportModel { + private String contact_id; + private String contact_id_type; + + public String getContact_id() { + return contact_id; + } + public void setContact_id(String contact_id) { + this.contact_id = contact_id; + } + + public String getContact_id_type() { + return contact_id_type; + } + public void setContact_id_type(String contact_id_type) { + this.contact_id_type = contact_id_type; + } +} diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/ContactRDAExportModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/ContactRDAExportModel.java new file mode 100644 index 000000000..92b35b13f --- /dev/null +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/ContactRDAExportModel.java @@ -0,0 +1,46 @@ +package eu.eudat.models.data.dmp; + +import eu.eudat.data.entities.UserInfo; +import eu.eudat.models.DataModel; + +public class ContactRDAExportModel { + private String mail; + private String name; + private ContactIdRDAExportModel contact_id; + + public String getMail() { + return mail; + } + public void setMail(String mail) { + this.mail = mail; + } + + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + + public ContactIdRDAExportModel getContact_id() { + return contact_id; + } + public void setContact_id(ContactIdRDAExportModel contact_id) { + this.contact_id = contact_id; + } + + + public ContactRDAExportModel fromDataModel(UserInfo entity) { + this.mail = entity.getEmail(); + this.name = entity.getName(); + // TODO: we should use a contact_id and not our UUID. + if (!entity.getId().toString().isEmpty()) { + this.contact_id = new ContactIdRDAExportModel(); + this.contact_id.setContact_id(entity.getId().toString()); + } + else { + this.contact_id = null; + } + return this; + } +} diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/DmpRDAExportModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/DmpRDAExportModel.java new file mode 100644 index 000000000..e472df57a --- /dev/null +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/DmpRDAExportModel.java @@ -0,0 +1,91 @@ +package eu.eudat.models.data.dmp; + +import eu.eudat.data.entities.DMP; +import eu.eudat.data.entities.UserDMP; +import eu.eudat.models.DataModel; + +import java.util.Date; +import java.util.UUID; + +public class DmpRDAExportModel { + private UUID id; + private String title; + private String description; + private Date created; + private Date modified; + //private project; + private ContactRDAExportModel contact; + private String language; + private String ethical_issues_exist; + + public UUID getId() { + return id; + } + public void setId(UUID id) { + this.id = id; + } + + public String getTitle() { + return title; + } + public void setTitle(String title) { + this.title = title; + } + + public String getDescription() { + return description; + } + public void setDescription(String description) { + this.description = description; + } + + public Date getCreated() { + return created; + } + public void setCreated(Date created) { + this.created = created; + } + + public Date getModified() { + return modified; + } + public void setModified(Date modified) { + this.modified = modified; + } + + public ContactRDAExportModel getContact() { + return contact; + } + public void setContact(ContactRDAExportModel contact) { + this.contact = contact; + } + + public String getLanguage() { + return language; + } + public void setLanguage(String language) { + this.language = language; + } + + public String getEthical_issues_exist() { + return ethical_issues_exist; + } + public void setEthical_issues_exist(String ethical_issues_exist) { + this.ethical_issues_exist = ethical_issues_exist; + } + + + public DmpRDAExportModel fromDataModel(DMP entity) { + this.id = entity.getId(); + this.title = entity.getLabel(); + this.description = entity.getDescription(); + this.created = entity.getCreated(); + this.modified = entity.getModified(); + this.contact = new ContactRDAExportModel().fromDataModel(entity.getUsers().stream().filter(x -> x.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser()); + // Mock up data on "language" and "ethical_issues" for now. + this.language = "en"; + this.ethical_issues_exist = "no"; + + return this; + } +} diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/RDAExportModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/RDAExportModel.java new file mode 100644 index 000000000..77421c5ad --- /dev/null +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/dmp/RDAExportModel.java @@ -0,0 +1,12 @@ +package eu.eudat.models.data.dmp; + +public class RDAExportModel { + private DmpRDAExportModel dmp; + + public DmpRDAExportModel getDmp() { + return dmp; + } + public void setDmp(DmpRDAExportModel dmp) { + this.dmp = dmp; + } +} diff --git a/dmp-frontend/src/app/core/services/dmp/dmp.service.ts b/dmp-frontend/src/app/core/services/dmp/dmp.service.ts index 9a8c03301..49d8fab6c 100644 --- a/dmp-frontend/src/app/core/services/dmp/dmp.service.ts +++ b/dmp-frontend/src/app/core/services/dmp/dmp.service.ts @@ -97,6 +97,10 @@ export class DmpService { return this.httpClient.get(this.actionUrl + 'getPDF/' + id, { responseType: 'blob', observe: 'response', headers: headerPdf }); } + public downloadJson(id: string): Observable> { + return this.httpClient.get(this.actionUrl + 'rda/' + id, { responseType: 'blob', observe: 'response' }); + } + public uploadXml(fileList: FileList, dmpTitle: string): Observable { const formData: FormData = new FormData(); if (fileList instanceof FileList) { diff --git a/dmp-frontend/src/app/library/export-method-dialog/export-method-dialog.component.html b/dmp-frontend/src/app/library/export-method-dialog/export-method-dialog.component.html index 3657eeb48..a307749c8 100644 --- a/dmp-frontend/src/app/library/export-method-dialog/export-method-dialog.component.html +++ b/dmp-frontend/src/app/library/export-method-dialog/export-method-dialog.component.html @@ -6,8 +6,9 @@
close
-
-
-
+
+
+
+
diff --git a/dmp-frontend/src/app/library/export-method-dialog/export-method-dialog.component.ts b/dmp-frontend/src/app/library/export-method-dialog/export-method-dialog.component.ts index 4219841e7..0fe216670 100644 --- a/dmp-frontend/src/app/library/export-method-dialog/export-method-dialog.component.ts +++ b/dmp-frontend/src/app/library/export-method-dialog/export-method-dialog.component.ts @@ -3,34 +3,37 @@ import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material'; @Component({ - selector: 'app-export-method-dialog', - templateUrl: './export-method-dialog.component.html', - styleUrls: ['./export-method-dialog.component.scss'] + selector: 'app-export-method-dialog', + templateUrl: './export-method-dialog.component.html', + styleUrls: ['./export-method-dialog.component.scss'] }) export class ExportMethodDialogComponent implements OnInit { - constructor( - public dialogRef: MatDialogRef, - @Inject(MAT_DIALOG_DATA) public data: any - ) { } + constructor( + public dialogRef: MatDialogRef, + @Inject(MAT_DIALOG_DATA) public data: any + ) { } - ngOnInit() { - } + ngOnInit() { + } - close() { - this.dialogRef.close(false); - } + close() { + this.dialogRef.close(false); + } - downloadXML() { - this.dialogRef.close("xml"); - } + downloadXML() { + this.dialogRef.close("xml"); + } - downloadDocument() { - this.dialogRef.close("doc"); - } + downloadDocument() { + this.dialogRef.close("doc"); + } - downloadPdf() { - this.dialogRef.close("pdf"); - } + downloadPdf() { + this.dialogRef.close("pdf"); + } + downloadJson() { + this.dialogRef.close("json"); + } } diff --git a/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.ts b/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.ts index da7dd6b16..4116ef80a 100644 --- a/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.ts +++ b/dmp-frontend/src/app/ui/dmp/editor/dmp-editor.component.ts @@ -319,7 +319,8 @@ export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadC message: "Download as:", XMLButton: "XML", documentButton: "Document", - pdfButton: "PDF" + pdfButton: "PDF", + jsonButton: "JSON" } }); dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => { @@ -329,6 +330,8 @@ export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadC this.downloadXml(this.dmp.id); } else if (result == "doc") { this.downloadDocx(this.dmp.id); + } else if (result == "json") { + this.downloadJson(this.dmp.id) } }); } @@ -339,7 +342,6 @@ export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadC .subscribe(response => { const blob = new Blob([response.body], { type: 'application/xml' }); const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); - FileSaver.saveAs(blob, filename); }); } @@ -350,7 +352,6 @@ export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadC .subscribe(response => { const blob = new Blob([response.body], { type: 'application/msword' }); const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); - FileSaver.saveAs(blob, filename); }); } @@ -361,11 +362,20 @@ export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadC .subscribe(response => { const blob = new Blob([response.body], { type: 'application/pdf' }); const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); - FileSaver.saveAs(blob, filename); }); } + downloadJson(id: string) { + this.dmpService.downloadJson(id) + .pipe(takeUntil(this._destroyed)) + .subscribe(response => { + const blob = new Blob([response.body], { type: 'application/json' }); + const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); + FileSaver.saveAs(blob, filename); + }) + } + getFilenameFromContentDispositionHeader(header: string): string { const regex: RegExp = new RegExp(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/g);