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)

This commit is contained in:
George Kalampokis 2020-05-15 16:19:35 +03:00
parent cebf3935f3
commit da7f90eb18
7 changed files with 129 additions and 24 deletions

View File

@ -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() : "<p></p>")).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<Map[]> listResponses = restTemplate.getForEntity(listUrl, Map[].class);
createResponse = listResponses.getBody()[0];
links = (LinkedHashMap<String, String>) 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<String, Object> 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<String, Object> 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<MultiValueMap<String, Object>> 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<MultiValueMap<String, Object>> addFileMapRequest = new HttpEntity<>(addFileMap, fileHeaders);
String addFileUrl = links.get("files") + "?access_token=" + zenodoToken;
ResponseEntity<String> addFileResponse = restTemplate.postForEntity(addFileUrl, addFileMapRequest, String.class);
Files.deleteIfExists(file.getFile().toPath());
String addFileUrl = links.get("files") + "?access_token=" + zenodoToken;
ResponseEntity<String> 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<String, Object> publishResponce = restTemplate.postForObject(publishUrl, "", Map.class);
finalDoi = (String) publishResponce.get("conceptdoi");
// }
} else {
Map<String, Object> editResponce = restTemplate.postForObject(links.get("edit") + "?access_token=" + zenodoToken, "", Map.class);
restTemplate.put(links.get("self") + "?access_token=" + zenodoToken, request);
Map<String, Object> publishResponce = restTemplate.postForObject(links.get("publish") + "?access_token=" + zenodoToken, "", Map.class);
finalDoi = (String) publishResponce.get("conceptdoi");
}
if (finalDoi != null) {

View File

@ -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({

View File

@ -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 { }

View File

@ -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 { }

View File

@ -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}`]);
});
}
}