Adds DMP export to JSON file (RDA template, not finished).
This commit is contained in:
parent
73bc31ed7c
commit
9911dcdac5
|
@ -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<byte[]> 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<DataManagementPlanOverviewModel>().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<DataManagementPlan>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan));
|
||||
|
|
|
@ -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<byte[]> getDocument(String id, String contentType) throws InstantiationException, InterruptedException, IllegalAccessException, IOException{
|
||||
public ResponseEntity<byte[]> 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<byte[]> 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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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<HttpResponse<Blob>> {
|
||||
return this.httpClient.get(this.actionUrl + 'rda/' + id, { responseType: 'blob', observe: 'response' });
|
||||
}
|
||||
|
||||
public uploadXml(fileList: FileList, dmpTitle: string): Observable<ContentType> {
|
||||
const formData: FormData = new FormData();
|
||||
if (fileList instanceof FileList) {
|
||||
|
|
|
@ -6,8 +6,9 @@
|
|||
<div class="col-auto close-btn" (click)="close()"><mat-icon>close</mat-icon></div>
|
||||
</div>
|
||||
<div class="row d-flex flex-row">
|
||||
<div class="col-4"><button mat-raised-button type="button" (click)="downloadXML()" >{{ data.XMLButton }}</button></div>
|
||||
<div class="col-4"><button mat-raised-button type="button" (click)="downloadDocument()">{{ data.documentButton }}</button></div>
|
||||
<div class="col-4"><button mat-raised-button type="button" (click)="downloadPdf()">{{ data.pdfButton }}</button></div>
|
||||
<div class="col-3"><button mat-raised-button type="button" (click)="downloadXML()" >{{ data.XMLButton }}</button></div>
|
||||
<div class="col-3"><button mat-raised-button type="button" (click)="downloadDocument()">{{ data.documentButton }}</button></div>
|
||||
<div class="col-3"><button mat-raised-button type="button" (click)="downloadPdf()">{{ data.pdfButton }}</button></div>
|
||||
<div class="col-3"><button mat-raised-button type="button" (click)="downloadJson()">{{ data.jsonButton }}</button></div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -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<ExportMethodDialogComponent>,
|
||||
@Inject(MAT_DIALOG_DATA) public data: any
|
||||
) { }
|
||||
constructor(
|
||||
public dialogRef: MatDialogRef<ExportMethodDialogComponent>,
|
||||
@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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue