From da7f90eb188f3e5bf5a3b1f86a4eedcdeb0819f1 Mon Sep 17 00:00:00 2001 From: George Kalampokis Date: Fri, 15 May 2020 16:19:35 +0300 Subject: [PATCH] When creating Zenodo DOI publish the DMP but keep the files under restricted access and don't give identifier back until it go public. Also add zenodo proxy for the identifier (ref #257) --- .../managers/DataManagementPlanManager.java | 70 +++++++++++++------ dmp-frontend/src/app/app-routing.module.ts | 10 ++- .../src/app/ui/external/external.module.ts | 15 ++++ .../src/app/ui/external/external.routing.ts | 31 ++++++++ .../ui/external/zenodo/zenodo.component.html | 0 .../ui/external/zenodo/zenodo.component.scss | 0 .../ui/external/zenodo/zenodo.component.ts | 27 +++++++ 7 files changed, 129 insertions(+), 24 deletions(-) create mode 100644 dmp-frontend/src/app/ui/external/external.module.ts create mode 100644 dmp-frontend/src/app/ui/external/external.routing.ts create mode 100644 dmp-frontend/src/app/ui/external/zenodo/zenodo.component.html create mode 100644 dmp-frontend/src/app/ui/external/zenodo/zenodo.component.scss create mode 100644 dmp-frontend/src/app/ui/external/zenodo/zenodo.component.ts 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 a2815c328..62f173179 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 @@ -794,7 +794,7 @@ public class DataManagementPlanManager { }); UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId()); sendNotification(dmp, user, NotificationType.DMP_PUBLISH); - this.createZenodoDoi(dmp.getId(), principal, null); + this.createZenodoDoi(dmp.getId(), principal, null, true); } public void makeFinalize(UUID id, Principal principal, DatasetsToBeFinalized datasetsToBeFinalized) throws Exception { @@ -1606,6 +1606,10 @@ public class DataManagementPlanManager { } public String createZenodoDoi(UUID id, Principal principal, ConfigLoader configLoader) throws Exception { + return this.createZenodoDoi(id, principal, configLoader, false); + } + + public String createZenodoDoi(UUID id, Principal principal, ConfigLoader configLoader, boolean update) throws Exception { DMP dmp = this.apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(id); if (!isUserOwnerOfDmp(dmp, principal)) throw new Exception("User is not authorized to invoke this action"); @@ -1635,9 +1639,16 @@ public class DataManagementPlanManager { dataBuilder.append(" \"publication_type\": \"datamanagementplan\",\n"); dataBuilder.append(" \"description\": \"").append((dmp.getDescription() != null && !dmp.getDescription().isEmpty() ? dmp.getDescription() : "

")).append("\",\n"); dataBuilder.append(" \"version\": \"").append(dmp.getVersion()).append("\",\n"); - dataBuilder.append(" \"related_identifiers\": [{\n"); - dataBuilder.append(" \t\t\"identifier\": \"").append((this.environment.getProperty("dmp.domain") + "/explore-plans/publicOverview/" + id.toString())).append("\",\n"); - dataBuilder.append(" \t\t\"relation\": \"isIdenticalTo\"}],\n"); + dataBuilder.append(" \"access_right\": \""); + if (dmp.isPublic()) { + dataBuilder.append("open\",\n"); + dataBuilder.append(" \"related_identifiers\": [{\n"); + dataBuilder.append(" \t\t\"identifier\": \"").append((this.environment.getProperty("dmp.domain") + "/external/zenodo/" + id.toString())).append("\",\n"); + dataBuilder.append(" \t\t\"relation\": \"isIdenticalTo\"}],\n"); + } else { + dataBuilder.append("restricted\",\n"); + dataBuilder.append(" \"access_conditions\": \"\",\n"); + } dataBuilder.append(" \"contributors\": ["); int i = 0; for(UserDMP userDMP: dmp.getUsers()) { @@ -1731,33 +1742,46 @@ public class DataManagementPlanManager { throw e; } } + else { + String listUrl = this.environment.getProperty("zenodo.url") + "deposit/depositions" + "?q=conceptdoi:\"" + previousDOI + "\"&access_token=" + zenodoToken; + ResponseEntity listResponses = restTemplate.getForEntity(listUrl, Map[].class); + createResponse = listResponses.getBody()[0]; + links = (LinkedHashMap) createResponse.get("links"); + } } - if (unpublishedUrl == null) { - // Second step, add the file to the entry. - HttpHeaders fileHeaders = new HttpHeaders(); - fileHeaders.setContentType(MediaType.MULTIPART_FORM_DATA); - LinkedMultiValueMap addFileMap = new LinkedMultiValueMap<>(); + if (!update) { + if (unpublishedUrl == null) { + // Second step, add the file to the entry. + HttpHeaders fileHeaders = new HttpHeaders(); + fileHeaders.setContentType(MediaType.MULTIPART_FORM_DATA); + LinkedMultiValueMap addFileMap = new LinkedMultiValueMap<>(); - FileEnvelope file = getWordDocument(id.toString(), principal, configLoader); - addFileMap.add("filename", file.getFilename()); - FileSystemResource fileSystemResource = new FileSystemResource(file.getFile()); - addFileMap.add("file", fileSystemResource); - HttpEntity> addFileMapRequest = new HttpEntity<>(addFileMap, fileHeaders); + FileEnvelope file = getWordDocument(id.toString(), principal, configLoader); + addFileMap.add("filename", file.getFilename()); + FileSystemResource fileSystemResource = new FileSystemResource(file.getFile()); + addFileMap.add("file", fileSystemResource); + HttpEntity> addFileMapRequest = new HttpEntity<>(addFileMap, fileHeaders); - String addFileUrl = links.get("files") + "?access_token=" + zenodoToken; - ResponseEntity addFileResponse = restTemplate.postForEntity(addFileUrl, addFileMapRequest, String.class); - Files.deleteIfExists(file.getFile().toPath()); + String addFileUrl = links.get("files") + "?access_token=" + zenodoToken; + ResponseEntity addFileResponse = restTemplate.postForEntity(addFileUrl, addFileMapRequest, String.class); + Files.deleteIfExists(file.getFile().toPath()); - // Third post call to Zenodo to publish the entry and return the DOI. - publishUrl = links.get("publish") + "?access_token=" + zenodoToken; - } else { - publishUrl = unpublishedUrl + "?access_token=" + zenodoToken; - } - if (dmp.isPublic()) { + // Third post call to Zenodo to publish the entry and return the DOI. + publishUrl = links.get("publish") + "?access_token=" + zenodoToken; + } else { + publishUrl = unpublishedUrl + "?access_token=" + zenodoToken; + } +// if (dmp.isPublic()) { Map publishResponce = restTemplate.postForObject(publishUrl, "", Map.class); finalDoi = (String) publishResponce.get("conceptdoi"); +// } + } else { + Map editResponce = restTemplate.postForObject(links.get("edit") + "?access_token=" + zenodoToken, "", Map.class); + restTemplate.put(links.get("self") + "?access_token=" + zenodoToken, request); + Map publishResponce = restTemplate.postForObject(links.get("publish") + "?access_token=" + zenodoToken, "", Map.class); + finalDoi = (String) publishResponce.get("conceptdoi"); } if (finalDoi != null) { diff --git a/dmp-frontend/src/app/app-routing.module.ts b/dmp-frontend/src/app/app-routing.module.ts index 3b1758d58..34afcecb2 100644 --- a/dmp-frontend/src/app/app-routing.module.ts +++ b/dmp-frontend/src/app/app-routing.module.ts @@ -222,7 +222,15 @@ const appRoutes: Routes = [ }, }, { path: 'reload', component: ReloadHelperComponent }, - { path: 'oauth2', component: Oauth2DialogComponent } + { path: 'oauth2', component: Oauth2DialogComponent }, + { + path: 'external', + loadChildren: () => import('./ui/external/external.module').then(m => m.ExternalModule), + data: { + breadcrumb: true, + + }, + } ]; @NgModule({ diff --git a/dmp-frontend/src/app/ui/external/external.module.ts b/dmp-frontend/src/app/ui/external/external.module.ts new file mode 100644 index 000000000..a9f47fb22 --- /dev/null +++ b/dmp-frontend/src/app/ui/external/external.module.ts @@ -0,0 +1,15 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { ZenodoComponent } from './zenodo/zenodo.component'; +import { ExternalRoutingModule } from './external.routing'; + + + +@NgModule({ + declarations: [ZenodoComponent], + imports: [ + CommonModule, + ExternalRoutingModule + ] +}) +export class ExternalModule { } diff --git a/dmp-frontend/src/app/ui/external/external.routing.ts b/dmp-frontend/src/app/ui/external/external.routing.ts new file mode 100644 index 000000000..36f598b4b --- /dev/null +++ b/dmp-frontend/src/app/ui/external/external.routing.ts @@ -0,0 +1,31 @@ + +import { NgModule } from '@angular/core'; +import { Routes, RouterModule } from '@angular/router'; +import { ZenodoComponent } from './zenodo/zenodo.component'; + + + +const routes: Routes = [ + { + path: '', + component: ZenodoComponent, + data: { + breadcrumb: true + }, + }, + { + path: 'zenodo/:id', + component: ZenodoComponent, + data: { + breadcrumb: true + }, + },]; + + + +@NgModule({ + imports: [RouterModule.forChild(routes)], + exports: [RouterModule] +}) + +export class ExternalRoutingModule { } diff --git a/dmp-frontend/src/app/ui/external/zenodo/zenodo.component.html b/dmp-frontend/src/app/ui/external/zenodo/zenodo.component.html new file mode 100644 index 000000000..e69de29bb diff --git a/dmp-frontend/src/app/ui/external/zenodo/zenodo.component.scss b/dmp-frontend/src/app/ui/external/zenodo/zenodo.component.scss new file mode 100644 index 000000000..e69de29bb diff --git a/dmp-frontend/src/app/ui/external/zenodo/zenodo.component.ts b/dmp-frontend/src/app/ui/external/zenodo/zenodo.component.ts new file mode 100644 index 000000000..5ce4e21f1 --- /dev/null +++ b/dmp-frontend/src/app/ui/external/zenodo/zenodo.component.ts @@ -0,0 +1,27 @@ +import { Component, OnInit } from '@angular/core'; +import { ActivatedRoute, Router, Params } from '@angular/router'; +import { BaseComponent } from '@common/base/base.component'; +import { takeUntil } from 'rxjs/operators'; + +@Component({ + selector: 'app-zenodo', + templateUrl: './zenodo.component.html', + styleUrls: ['./zenodo.component.scss'] +}) +export class ZenodoComponent extends BaseComponent implements OnInit { + + constructor( + private route: ActivatedRoute, + private router: Router, ) { + super(); + } + + ngOnInit() { + this.route.paramMap.pipe(takeUntil(this._destroyed)).subscribe((params: Params) => { + const id = params.params.id; + console.log(params.params); + this.router.navigate([`/explore-plans/publicOverview/${id}`]); + }); + } + +}