[WIP] create deposit interface and implement multiple deposit repositories
This commit is contained in:
parent
49ce0efb40
commit
7dd2030eb3
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>eu.eudat</groupId>
|
||||
<artifactId>dmp-backend</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>depositinterface</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,122 @@
|
|||
package eu.eudat.depositinterface.models;
|
||||
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class DMPDepositModel {
|
||||
private UUID id;
|
||||
private int version;
|
||||
private String label;
|
||||
private String description;
|
||||
private boolean isPublic;
|
||||
private Set<UserDMPDepositModel> users;
|
||||
private Set<OrganisationDepositModel> organisations;
|
||||
private Set<ResearcherDepositModel> researchers;
|
||||
private GrantDepositModel grant;
|
||||
private File pdfFile;
|
||||
private String pdfFileName;
|
||||
private ResponseEntity<byte[]> rdaJson;
|
||||
private String previousDOI;
|
||||
private String extraProperties;
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getVersion() {
|
||||
return version;
|
||||
}
|
||||
public void setVersion(int version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public boolean isPublic() {
|
||||
return isPublic;
|
||||
}
|
||||
public void setPublic(boolean aPublic) {
|
||||
isPublic = aPublic;
|
||||
}
|
||||
|
||||
public Set<UserDMPDepositModel> getUsers() {
|
||||
return users;
|
||||
}
|
||||
public void setUsers(Set<UserDMPDepositModel> users) {
|
||||
this.users = users;
|
||||
}
|
||||
|
||||
public Set<OrganisationDepositModel> getOrganisations() {
|
||||
return organisations;
|
||||
}
|
||||
public void setOrganisations(Set<OrganisationDepositModel> organisations) {
|
||||
this.organisations = organisations;
|
||||
}
|
||||
|
||||
public Set<ResearcherDepositModel> getResearchers() {
|
||||
return researchers;
|
||||
}
|
||||
public void setResearchers(Set<ResearcherDepositModel> researchers) {
|
||||
this.researchers = researchers;
|
||||
}
|
||||
|
||||
public GrantDepositModel getGrant() {
|
||||
return grant;
|
||||
}
|
||||
public void setGrant(GrantDepositModel grant) {
|
||||
this.grant = grant;
|
||||
}
|
||||
|
||||
public File getPdfFile() {
|
||||
return pdfFile;
|
||||
}
|
||||
public void setPdfFile(File pdfFile) {
|
||||
this.pdfFile = pdfFile;
|
||||
}
|
||||
|
||||
public String getPdfFileName() {
|
||||
return pdfFileName;
|
||||
}
|
||||
public void setPdfFileName(String pdfFileName) {
|
||||
this.pdfFileName = pdfFileName;
|
||||
}
|
||||
|
||||
public ResponseEntity<byte[]> getRdaJson() {
|
||||
return rdaJson;
|
||||
}
|
||||
public void setRdaJson(ResponseEntity<byte[]> rdaJson) {
|
||||
this.rdaJson = rdaJson;
|
||||
}
|
||||
|
||||
public String getPreviousDOI() {
|
||||
return previousDOI;
|
||||
}
|
||||
public void setPreviousDOI(String previousDOI) {
|
||||
this.previousDOI = previousDOI;
|
||||
}
|
||||
|
||||
public String getExtraProperties() {
|
||||
return extraProperties;
|
||||
}
|
||||
public void setExtraProperties(String extraProperties) {
|
||||
this.extraProperties = extraProperties;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package eu.eudat.depositinterface.models;
|
||||
|
||||
public class FunderDepositModel {
|
||||
private String label;
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package eu.eudat.depositinterface.models;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class GrantDepositModel {
|
||||
private UUID id;
|
||||
private String reference;
|
||||
private FunderDepositModel funder;
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getReference() {
|
||||
return reference;
|
||||
}
|
||||
public void setReference(String reference) {
|
||||
this.reference = reference;
|
||||
}
|
||||
|
||||
public FunderDepositModel getFunder() {
|
||||
return funder;
|
||||
}
|
||||
public void setFunder(FunderDepositModel funder) {
|
||||
this.funder = funder;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package eu.eudat.depositinterface.models;
|
||||
|
||||
public class OrganisationDepositModel {
|
||||
private String label;
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package eu.eudat.depositinterface.models;
|
||||
|
||||
public class ResearcherDepositModel {
|
||||
private String label;
|
||||
private String reference;
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public String getReference() {
|
||||
return reference;
|
||||
}
|
||||
public void setReference(String reference) {
|
||||
this.reference = reference;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package eu.eudat.depositinterface.models;
|
||||
|
||||
public class UserDMPDepositModel {
|
||||
|
||||
public enum UserDMPRoles {
|
||||
OWNER(0), USER(1);
|
||||
|
||||
private int value;
|
||||
|
||||
UserDMPRoles(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
public static UserDMPRoles fromInteger(int value) {
|
||||
switch (value) {
|
||||
case 0:
|
||||
return OWNER;
|
||||
case 1:
|
||||
return USER;
|
||||
default:
|
||||
throw new RuntimeException("Unsupported User Dmp Role Message Code");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private UserInfoDepositModel user;
|
||||
private Integer role;
|
||||
|
||||
public UserInfoDepositModel getUser() {
|
||||
return user;
|
||||
}
|
||||
public void setUser(UserInfoDepositModel user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public Integer getRole() {
|
||||
return role;
|
||||
}
|
||||
public void setRole(Integer role) {
|
||||
this.role = role;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package eu.eudat.depositinterface.models;
|
||||
|
||||
public class UserInfoDepositModel {
|
||||
private String name;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package eu.eudat.depositinterface.repository;
|
||||
|
||||
import eu.eudat.depositinterface.models.DMPDepositModel;
|
||||
|
||||
public interface RepositoryDeposit {
|
||||
|
||||
String deposit(DMPDepositModel dmpDepositModel, boolean update, String repositoryAccessToken) throws Exception;
|
||||
|
||||
//authenticate();
|
||||
|
||||
RepositoryDepositConfiguration getConfiguration();
|
||||
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
package eu.eudat.depositinterface.repository;
|
||||
|
||||
public class RepositoryDepositConfiguration {
|
||||
|
||||
public enum DepositAccountStatus {
|
||||
SystemDeposit(0), UserDeposit(1), BothWaysDeposit(2);
|
||||
|
||||
private int value;
|
||||
|
||||
DepositAccountStatus(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public static DepositAccountStatus fromInteger(int value) {
|
||||
switch (value) {
|
||||
case 0:
|
||||
return SystemDeposit;
|
||||
case 1:
|
||||
return UserDeposit;
|
||||
case 2:
|
||||
return BothWaysDeposit;
|
||||
default:
|
||||
throw new RuntimeException("Unsupported Deposit Account Status");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int depositAccountStatus;
|
||||
private String repositoryId;
|
||||
private String accessToken;
|
||||
private String repositoryUrl;
|
||||
private String repositoryLoginAccessTokenUrl;
|
||||
private String repositoryLoginClientId;
|
||||
private String repositoryLoginClientSecret;
|
||||
private String repositoryLoginRedirectUri; //
|
||||
|
||||
public int getDepositAccountStatus() {
|
||||
return depositAccountStatus;
|
||||
}
|
||||
public void setDepositAccountStatus(int depositAccountStatus) {
|
||||
this.depositAccountStatus = depositAccountStatus;
|
||||
}
|
||||
|
||||
public String getRepositoryId() {
|
||||
return repositoryId;
|
||||
}
|
||||
public void setRepositoryId(String repositoryId) {
|
||||
this.repositoryId = repositoryId;
|
||||
}
|
||||
|
||||
public String getAccessToken() {
|
||||
return accessToken;
|
||||
}
|
||||
public void setAccessToken(String accessToken) {
|
||||
this.accessToken = accessToken;
|
||||
}
|
||||
|
||||
public String getRepositoryUrl() {
|
||||
return repositoryUrl;
|
||||
}
|
||||
public void setRepositoryUrl(String repositoryUrl) {
|
||||
this.repositoryUrl = repositoryUrl;
|
||||
}
|
||||
|
||||
public String getRepositoryLoginAccessTokenUrl() {
|
||||
return repositoryLoginAccessTokenUrl;
|
||||
}
|
||||
public void setRepositoryLoginAccessTokenUrl(String repositoryLoginAccessTokenUrl) {
|
||||
this.repositoryLoginAccessTokenUrl = repositoryLoginAccessTokenUrl;
|
||||
}
|
||||
|
||||
public String getRepositoryLoginClientId() {
|
||||
return repositoryLoginClientId;
|
||||
}
|
||||
public void setRepositoryLoginClientId(String repositoryLoginClientId) {
|
||||
this.repositoryLoginClientId = repositoryLoginClientId;
|
||||
}
|
||||
|
||||
public String getRepositoryLoginClientSecret() {
|
||||
return repositoryLoginClientSecret;
|
||||
}
|
||||
public void setRepositoryLoginClientSecret(String repositoryLoginClientSecret) {
|
||||
this.repositoryLoginClientSecret = repositoryLoginClientSecret;
|
||||
}
|
||||
|
||||
public String getRepositoryLoginRedirectUri() {
|
||||
return repositoryLoginRedirectUri;
|
||||
}
|
||||
public void setRepositoryLoginRedirectUri(String repositoryLoginRedirectUri) {
|
||||
this.repositoryLoginRedirectUri = repositoryLoginRedirectUri;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
artifactId=depositinterface
|
||||
groupId=eu.eudat
|
||||
version=1.0-SNAPSHOT
|
|
@ -18,6 +18,7 @@
|
|||
<module>web</module>
|
||||
<module>data</module>
|
||||
<module>elastic</module>
|
||||
<module>depositinterface</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
|
|
|
@ -26,13 +26,16 @@
|
|||
<artifactId>queryable</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>eu.eudat</groupId>
|
||||
<artifactId>elastic</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>eu.eudat</groupId>
|
||||
<artifactId>depositinterface</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
|
@ -219,6 +222,9 @@
|
|||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<layout>ZIP</layout>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
|
|
@ -8,7 +8,7 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
|
|||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
|
||||
@SpringBootApplication
|
||||
@SpringBootApplication(scanBasePackages = {"eu.eudat", "eu.eudat.depositinterface"})
|
||||
@EnableAsync
|
||||
public class EuDatApplication extends SpringBootServletInitializer {
|
||||
private static final Logger logger = LoggerFactory.getLogger(EuDatApplication.class);
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package eu.eudat.controllers;
|
||||
|
||||
import eu.eudat.logic.managers.DepositManager;
|
||||
import eu.eudat.logic.security.claims.ClaimedAuthorities;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
||||
import eu.eudat.models.data.security.Principal;
|
||||
import eu.eudat.types.ApiMessageCode;
|
||||
import eu.eudat.types.Authorities;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
@RequestMapping(value = {"/api/deposit/"})
|
||||
public class DepositController extends BaseController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(DepositController.class);
|
||||
|
||||
private DepositManager depositManager;
|
||||
|
||||
@Autowired
|
||||
public DepositController(ApiContext apiContext, DepositManager depositManager){
|
||||
super(apiContext);
|
||||
this.depositManager = depositManager;
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, value = {"/repos"})
|
||||
public @ResponseBody
|
||||
ResponseEntity<ResponseItem<List<String>>> getAvailableRepos(@ClaimedAuthorities(claims = {Authorities.ADMIN, Authorities.MANAGER, Authorities.USER, Authorities.ANONYMOUS}) Principal principal) throws Exception {
|
||||
List<String> ids = this.depositManager.getAvailableRepos();
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<String>>().status(ApiMessageCode.NO_MESSAGE).payload(ids));
|
||||
}
|
||||
}
|
|
@ -15,6 +15,8 @@ import eu.eudat.data.enumeration.notification.NotifyState;
|
|||
import eu.eudat.data.query.items.table.dataset.DatasetTableRequest;
|
||||
import eu.eudat.data.query.items.table.datasetprofile.DatasetProfileTableRequestItem;
|
||||
import eu.eudat.data.query.items.table.dmp.DataManagementPlanTableRequest;
|
||||
import eu.eudat.depositinterface.models.DMPDepositModel;
|
||||
import eu.eudat.depositinterface.repository.RepositoryDeposit;
|
||||
import eu.eudat.elastic.criteria.DmpCriteria;
|
||||
import eu.eudat.elastic.entities.Collaborator;
|
||||
import eu.eudat.elastic.entities.Dmp;
|
||||
|
@ -29,6 +31,7 @@ import eu.eudat.logic.builders.entity.UserInfoBuilder;
|
|||
import eu.eudat.logic.mapper.elastic.DmpMapper;
|
||||
import eu.eudat.logic.mapper.elastic.criteria.DmpCriteriaMapper;
|
||||
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
|
||||
import eu.eudat.logic.security.repositorydeposit.mapper.DMPToDepositMapper;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
import eu.eudat.logic.services.forms.VisibilityRuleService;
|
||||
import eu.eudat.logic.services.forms.VisibilityRuleServiceImpl;
|
||||
|
@ -57,8 +60,6 @@ import eu.eudat.models.data.project.ProjectDMPEditorModel;
|
|||
import eu.eudat.models.data.security.Principal;
|
||||
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
|
||||
import eu.eudat.models.data.userinfo.UserListingModel;
|
||||
import eu.eudat.models.deposit.zenodo.ZenodoDeposit;
|
||||
import eu.eudat.models.deposit.zenodo.mapper.DMPToZenodoMapper;
|
||||
import eu.eudat.queryable.QueryableList;
|
||||
import eu.eudat.types.Authorities;
|
||||
import eu.eudat.types.MetricNames;
|
||||
|
@ -70,11 +71,8 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
import org.springframework.web.client.HttpServerErrorException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.w3c.dom.Document;
|
||||
|
@ -114,9 +112,11 @@ public class DataManagementPlanManager {
|
|||
private UserManager userManager;
|
||||
private final MetricsManager metricsManager;
|
||||
private final ConfigLoader configLoader;
|
||||
private List<RepositoryDeposit> repositoriesDeposit;
|
||||
|
||||
@Autowired
|
||||
public DataManagementPlanManager(ApiContext apiContext, DatasetManager datasetManager, Environment environment, RDAManager rdaManager, UserManager userManager, MetricsManager metricsManager, ConfigLoader configLoader) {
|
||||
public DataManagementPlanManager(ApiContext apiContext, DatasetManager datasetManager, Environment environment, RDAManager rdaManager, UserManager userManager,
|
||||
MetricsManager metricsManager, ConfigLoader configLoader, List<RepositoryDeposit> repositoriesDeposit) {
|
||||
this.apiContext = apiContext;
|
||||
this.datasetManager = datasetManager;
|
||||
this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository();
|
||||
|
@ -126,6 +126,7 @@ public class DataManagementPlanManager {
|
|||
this.metricsManager = metricsManager;
|
||||
this.configLoader = configLoader;
|
||||
this.objectMapper = new ObjectMapper();
|
||||
this.repositoriesDeposit = repositoriesDeposit;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -2064,6 +2065,20 @@ public class DataManagementPlanManager {
|
|||
/*if (dmp.getDoi() != null)
|
||||
throw new Exception("DMP already has a DOI");*/
|
||||
|
||||
FileEnvelope file = getWordDocument(id.toString(), principal, configLoader);
|
||||
String name = file.getFilename().substring(0, file.getFilename().length() - 5);
|
||||
File pdfFile = PDFUtils.convertToPDF(file, environment);
|
||||
String fileName = name + ".pdf";
|
||||
ResponseEntity<byte[]> jsonFile;
|
||||
try {
|
||||
jsonFile = getRDAJsonDocument(id.toString(), principal);
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
String previousDOI = this.getPreviousDOI(dmp.getGroupId(), dmp.getId());
|
||||
|
||||
DMPDepositModel dmpDepositModel = DMPToDepositMapper.fromDMP(dmp, pdfFile, fileName, jsonFile, previousDOI);
|
||||
|
||||
String zenodoToken = "";
|
||||
try {
|
||||
if (this.userManager.isDOITokenValid(principal)) {
|
||||
|
@ -2072,136 +2087,18 @@ public class DataManagementPlanManager {
|
|||
} catch (NonValidTokenException e) {
|
||||
zenodoToken = this.environment.getProperty("zenodo.access_token");
|
||||
}
|
||||
// First step, post call to Zenodo, to create the entry.
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
ZenodoDeposit deposit = DMPToZenodoMapper.fromDMP(dmp, environment, configLoader);
|
||||
//if (Objects.requireNonNull(environment.getProperty("spring.profiles.active")).contains("devel")) {
|
||||
String json = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(deposit);
|
||||
logger.info(json);
|
||||
//}
|
||||
HttpEntity<ZenodoDeposit> request = new HttpEntity<>(deposit, headers);
|
||||
Map createResponse;
|
||||
LinkedHashMap<String, String> links;
|
||||
String previousDOI = this.getPreviousDOI(dmp.getGroupId(), dmp.getId());
|
||||
String unpublishedUrl = null;
|
||||
String publishUrl;
|
||||
String finalDoi;
|
||||
try {
|
||||
|
||||
if (previousDOI == null) {
|
||||
String createUrl = this.environment.getProperty("zenodo.url") + "deposit/depositions" + "?access_token=" + zenodoToken;
|
||||
createResponse = restTemplate.postForEntity(createUrl, request, Map.class).getBody();
|
||||
links = (LinkedHashMap<String, String>) createResponse.get("links");
|
||||
finalDoi = (String) createResponse.get("conceptdoi");
|
||||
} else {
|
||||
unpublishedUrl = this.getUnpublishedDOI(previousDOI, zenodoToken, dmp.getVersion());
|
||||
if (unpublishedUrl == null) {
|
||||
//It requires more than one step to create a new version
|
||||
//First, get the deposit related to the concept DOI
|
||||
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");
|
||||
//Second, make the new version (not in the links?)
|
||||
String newVersionUrl = links.get("self") + "/actions/newversion" + "?access_token=" + zenodoToken;
|
||||
createResponse = restTemplate.postForObject(newVersionUrl, null, Map.class);
|
||||
links = (LinkedHashMap<String, String>) createResponse.get("links");
|
||||
//Third, get the new deposit
|
||||
String latestDraftUrl = links.get("latest_draft") + "?access_token=" + zenodoToken;
|
||||
createResponse = restTemplate.getForObject(latestDraftUrl, Map.class);
|
||||
links = (LinkedHashMap<String, String>) createResponse.get("links");
|
||||
finalDoi = (String) createResponse.get("conceptdoi");
|
||||
//At this point it might fail to perform the next requests so enclose them with try catch
|
||||
try {
|
||||
//Forth, update the new deposit's metadata
|
||||
String updateUrl = links.get("self") + "?access_token=" + zenodoToken;
|
||||
restTemplate.put(updateUrl, request);
|
||||
//And finally remove pre-existing files from it
|
||||
String fileListUrl = links.get("self") + "/files" + "?access_token=" + zenodoToken;
|
||||
ResponseEntity<Map[]> fileListResponse = restTemplate.getForEntity(fileListUrl, Map[].class);
|
||||
for (Map file : fileListResponse.getBody()) {
|
||||
String fileDeleteUrl = links.get("self") + "/files/" + file.get("id") + "?access_token=" + zenodoToken;
|
||||
restTemplate.delete(fileDeleteUrl);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
//In case the last two steps fail delete the latest Deposit it in order to create a new one (only one at a time is allowed)
|
||||
restTemplate.delete(latestDraftUrl);
|
||||
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 (!update) {
|
||||
if (unpublishedUrl == null) {
|
||||
// Second step, add the file to the entry.
|
||||
FileEnvelope file = getWordDocument(id.toString(), principal, configLoader);
|
||||
String name = file.getFilename().substring(0, file.getFilename().length() - 5);
|
||||
File pdfFile = PDFUtils.convertToPDF(file, environment);
|
||||
String fileName = name + ".pdf";
|
||||
FileSystemResource fileSystemResource = new FileSystemResource(pdfFile);
|
||||
HttpEntity<FileSystemResource> addFileMapRequest = new HttpEntity<>(fileSystemResource, null);
|
||||
|
||||
String addFileUrl = links.get("bucket") + "/" + fileName + "?access_token=" + zenodoToken;
|
||||
restTemplate.put(addFileUrl, addFileMapRequest);
|
||||
Files.deleteIfExists(file.getFile().toPath());
|
||||
|
||||
ResponseEntity<byte[]> jsonFile;
|
||||
try {
|
||||
jsonFile = getRDAJsonDocument(id.toString(), principal);
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
UUID jsonFileUUID = UUID.randomUUID();
|
||||
File tempJsonFile = new File(this.environment.getProperty("temp.temp") + jsonFileUUID.toString() + ".json");
|
||||
try (FileOutputStream jsonFos = new FileOutputStream(tempJsonFile)) {
|
||||
jsonFos.write(jsonFile.getBody());
|
||||
jsonFos.flush();
|
||||
}
|
||||
fileSystemResource = new FileSystemResource(tempJsonFile);
|
||||
HttpHeaders jsonHeaders = new HttpHeaders();
|
||||
jsonHeaders.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
||||
addFileMapRequest = new HttpEntity<>(fileSystemResource, jsonHeaders);
|
||||
String jsonFileName = jsonFile.getHeaders().get("Content-Disposition").get(0).substring(jsonFile.getHeaders().get("Content-Disposition").get(0).lastIndexOf('=') + 1);
|
||||
addFileUrl = links.get("bucket") + "/" + jsonFileName + "?access_token=" + zenodoToken;
|
||||
restTemplate.put(addFileUrl, addFileMapRequest);
|
||||
Files.deleteIfExists(tempJsonFile.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()) {
|
||||
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");
|
||||
}
|
||||
|
||||
String finalDoi = null;
|
||||
for(RepositoryDeposit repo: this.repositoriesDeposit) { //temp
|
||||
finalDoi = repo.deposit(dmpDepositModel, update, zenodoToken);
|
||||
if (finalDoi != null) {
|
||||
dmp.setDoi(finalDoi);
|
||||
apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(dmp);
|
||||
}
|
||||
return finalDoi;
|
||||
} catch (HttpClientErrorException | HttpServerErrorException ex) {
|
||||
//ObjectMapper ob = new ObjectMapper();
|
||||
Map<String, String> parsedException = objectMapper.readValue(ex.getResponseBodyAsString(), HashMap.class);
|
||||
throw new IOException(parsedException.get("message"), ex);
|
||||
}
|
||||
Files.deleteIfExists(file.getFile().toPath());
|
||||
|
||||
return finalDoi;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
package eu.eudat.logic.managers;
|
||||
|
||||
import eu.eudat.depositinterface.repository.RepositoryDeposit;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class DepositManager {
|
||||
private static final Logger logger = LoggerFactory.getLogger(DepositManager.class);
|
||||
|
||||
private List<RepositoryDeposit> repositories;
|
||||
|
||||
@Autowired
|
||||
public DepositManager(List<RepositoryDeposit> repositories){
|
||||
this.repositories = repositories;
|
||||
}
|
||||
|
||||
public List<String> getAvailableRepos() {
|
||||
List<String> repos = new ArrayList<>();
|
||||
|
||||
// logger.info("\n\n-------REPOS------\n");
|
||||
// for (RepositoryDeposit r: this.repositories) {
|
||||
// logger.info("...Loaded Class: "
|
||||
// + r.getClass());
|
||||
// }
|
||||
// logger.info("\n-------------------------------");
|
||||
for (RepositoryDeposit r: this.repositories) {
|
||||
repos.add(r.getConfiguration().getRepositoryId());
|
||||
}
|
||||
|
||||
//repos.add("dummyId");
|
||||
return repos;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package eu.eudat.logic.proxy.config;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class DOIFunder {
|
||||
|
||||
@JsonProperty("Funder")
|
||||
private String funder;
|
||||
@JsonProperty("DOI")
|
||||
private String DOI;
|
||||
|
||||
public String getFunder() {
|
||||
return funder;
|
||||
}
|
||||
|
||||
public void setFunder(String funder) {
|
||||
this.funder = funder;
|
||||
}
|
||||
|
||||
public String getDOI() {
|
||||
return DOI;
|
||||
}
|
||||
|
||||
public void setDOI(String DOI) {
|
||||
this.DOI = DOI;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
package eu.eudat.logic.proxy.config.configloaders;
|
||||
|
||||
import eu.eudat.logic.proxy.config.DOIFunder;
|
||||
import eu.eudat.logic.proxy.config.ExternalUrls;
|
||||
import eu.eudat.logic.security.customproviders.ConfigurableProvider.entities.ConfigurableProviders;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
|
@ -15,5 +14,4 @@ public interface ConfigLoader {
|
|||
XWPFDocument getDatasetDocument();
|
||||
ConfigurableProviders getConfigurableProviders();
|
||||
Map<String, String> getKeyToSourceMap();
|
||||
List<DOIFunder> getDOIFunders();
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package eu.eudat.logic.proxy.config.configloaders;
|
|||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import eu.eudat.logic.proxy.config.DOIFunder;
|
||||
import eu.eudat.logic.proxy.config.ExternalUrls;
|
||||
import eu.eudat.logic.security.customproviders.ConfigurableProvider.entities.ConfigurableProviders;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
|
@ -41,7 +40,6 @@ public class DefaultConfigLoader implements ConfigLoader {
|
|||
private XWPFDocument datasetDocument;
|
||||
private ConfigurableProviders configurableProviders;
|
||||
private Map<String, String> keyToSourceMap;
|
||||
private List<DOIFunder> doiFunders = new ArrayList<>();
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
@ -239,18 +237,6 @@ public class DefaultConfigLoader implements ConfigLoader {
|
|||
return keyToSourceMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DOIFunder> getDOIFunders() {
|
||||
if (doiFunders == null || doiFunders.isEmpty()) {
|
||||
try {
|
||||
List<Map<String, Object>> tempdoiFunders = mapper.readValue(getStreamFromPath(environment.getProperty("configuration.doi_funder")), List.class);
|
||||
doiFunders = tempdoiFunders.stream().map(map -> mapper.convertValue(map, DOIFunder.class) ).collect(Collectors.toList());
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getLocalizedMessage(), e);
|
||||
}
|
||||
}
|
||||
return doiFunders;
|
||||
}
|
||||
|
||||
private Document getXmlDocumentFromFilePath(String filePath) {
|
||||
InputStream is = null;
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
package eu.eudat.logic.security.repositorydeposit.mapper;
|
||||
|
||||
import eu.eudat.data.entities.*;
|
||||
import eu.eudat.depositinterface.models.*;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class DMPToDepositMapper {
|
||||
|
||||
public static DMPDepositModel fromDMP(DMP entity, File pdfFile, String fileName, ResponseEntity<byte[]> jsonFile, String previousDOI) {
|
||||
DMPDepositModel deposit = new DMPDepositModel();
|
||||
deposit.setId(entity.getId());
|
||||
deposit.setVersion(entity.getVersion());
|
||||
deposit.setLabel(entity.getLabel());
|
||||
deposit.setDescription(entity.getDescription());
|
||||
deposit.setPublic(entity.isPublic());
|
||||
deposit.setUsers(entity.getUsers().stream().map(DMPToDepositMapper::fromUserDMP).collect(Collectors.toSet()));
|
||||
deposit.setOrganisations(entity.getOrganisations().stream().map(DMPToDepositMapper::fromOrganisation).collect(Collectors.toSet()));
|
||||
deposit.setResearchers(entity.getResearchers().stream().map(DMPToDepositMapper::fromResearcher).collect(Collectors.toSet()));
|
||||
deposit.setGrant(fromGrant(entity.getGrant()));
|
||||
|
||||
deposit.setPdfFile(pdfFile);
|
||||
deposit.setPdfFileName(fileName);
|
||||
deposit.setRdaJson(jsonFile);
|
||||
deposit.setPreviousDOI(previousDOI);
|
||||
|
||||
deposit.setExtraProperties(entity.getExtraProperties());
|
||||
return deposit;
|
||||
}
|
||||
|
||||
private static UserDMPDepositModel fromUserDMP(UserDMP entity){
|
||||
UserDMPDepositModel deposit = new UserDMPDepositModel();
|
||||
deposit.setUser(fromUserInfo(entity.getUser()));
|
||||
deposit.setRole(entity.getRole());
|
||||
return deposit;
|
||||
}
|
||||
|
||||
private static UserInfoDepositModel fromUserInfo(UserInfo entity){
|
||||
UserInfoDepositModel deposit = new UserInfoDepositModel();
|
||||
deposit.setName(entity.getName());
|
||||
return deposit;
|
||||
}
|
||||
|
||||
private static OrganisationDepositModel fromOrganisation(Organisation entity){
|
||||
OrganisationDepositModel deposit = new OrganisationDepositModel();
|
||||
deposit.setLabel(entity.getLabel());
|
||||
return deposit;
|
||||
}
|
||||
|
||||
private static ResearcherDepositModel fromResearcher(Researcher entity){
|
||||
ResearcherDepositModel deposit = new ResearcherDepositModel();
|
||||
deposit.setLabel(entity.getLabel());
|
||||
deposit.setReference(entity.getReference());
|
||||
return deposit;
|
||||
}
|
||||
|
||||
private static GrantDepositModel fromGrant(Grant entity){
|
||||
GrantDepositModel deposit = new GrantDepositModel();
|
||||
deposit.setId(entity.getId());
|
||||
deposit.setReference(entity.getReference());
|
||||
deposit.setFunder(fromFunder(entity.getFunder()));
|
||||
return deposit;
|
||||
}
|
||||
|
||||
private static FunderDepositModel fromFunder(Funder entity){
|
||||
FunderDepositModel deposit = new FunderDepositModel();
|
||||
deposit.setLabel(entity.getLabel());
|
||||
return deposit;
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package eu.eudat.models.deposit.zenodo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
|
||||
public enum ZenodoAccessRight {
|
||||
RESTRICTED("restricted"), EMBARGOED("embargoed"), OPEN("open");
|
||||
|
||||
private final String value;
|
||||
|
||||
ZenodoAccessRight(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@JsonValue
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package eu.eudat.models.deposit.zenodo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class ZenodoComunity {
|
||||
|
||||
private String identifier;
|
||||
|
||||
public String getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
public void setIdentifier(String identifier) {
|
||||
this.identifier = identifier;
|
||||
}
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
package eu.eudat.models.deposit.zenodo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class ZenodoContributor {
|
||||
private String name;
|
||||
private String type;
|
||||
private String affiliation;
|
||||
private String orcid;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getAffiliation() {
|
||||
return affiliation;
|
||||
}
|
||||
|
||||
public void setAffiliation(String affiliation) {
|
||||
this.affiliation = affiliation;
|
||||
}
|
||||
|
||||
public String getOrcid() {
|
||||
return orcid;
|
||||
}
|
||||
|
||||
public void setOrcid(String orcid) {
|
||||
this.orcid = orcid;
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package eu.eudat.models.deposit.zenodo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class ZenodoDeposit {
|
||||
|
||||
private ZenodoDepositMetadata metadata;
|
||||
|
||||
public ZenodoDepositMetadata getMetadata() {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
public void setMetadata(ZenodoDepositMetadata metadata) {
|
||||
this.metadata = metadata;
|
||||
}
|
||||
}
|
|
@ -1,159 +0,0 @@
|
|||
package eu.eudat.models.deposit.zenodo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class ZenodoDepositMetadata {
|
||||
|
||||
private String title;
|
||||
|
||||
@JsonProperty("upload_type")
|
||||
private String uploadType;
|
||||
|
||||
@JsonProperty("publication_type")
|
||||
private String publicationType;
|
||||
|
||||
private String description;
|
||||
|
||||
private String version;
|
||||
|
||||
private List<ZenodoComunity> communities;
|
||||
|
||||
@JsonProperty("access_right")
|
||||
private ZenodoAccessRight accessRight;
|
||||
|
||||
@JsonProperty("access_conditions")
|
||||
private String accessConditions;
|
||||
|
||||
@JsonProperty("embargo_date")
|
||||
private String embargoDate;
|
||||
|
||||
private String license;
|
||||
|
||||
@JsonProperty("related_identifiers")
|
||||
private List<ZenodoRelator> relatedIdentifiers;
|
||||
|
||||
private List<ZenodoContributor> contributors;
|
||||
|
||||
private List<ZenodoGrant> grants;
|
||||
|
||||
private List<ZenodoContributor> creators;
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getUploadType() {
|
||||
return uploadType;
|
||||
}
|
||||
|
||||
public void setUploadType(String uploadType) {
|
||||
this.uploadType = uploadType;
|
||||
}
|
||||
|
||||
public String getPublicationType() {
|
||||
return publicationType;
|
||||
}
|
||||
|
||||
public void setPublicationType(String publicationType) {
|
||||
this.publicationType = publicationType;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public List<ZenodoComunity> getCommunities() {
|
||||
return communities;
|
||||
}
|
||||
|
||||
public void setCommunities(List<ZenodoComunity> communities) {
|
||||
this.communities = communities;
|
||||
}
|
||||
|
||||
public ZenodoAccessRight getAccessRight() {
|
||||
return accessRight;
|
||||
}
|
||||
|
||||
public void setAccessRight(ZenodoAccessRight accessRight) {
|
||||
this.accessRight = accessRight;
|
||||
}
|
||||
|
||||
public String getAccessConditions() {
|
||||
return accessConditions;
|
||||
}
|
||||
|
||||
public void setAccessConditions(String accessConditions) {
|
||||
this.accessConditions = accessConditions;
|
||||
}
|
||||
|
||||
public String getEmbargoDate() {
|
||||
return embargoDate;
|
||||
}
|
||||
|
||||
public void setEmbargoDate(String embargoDate) {
|
||||
this.embargoDate = embargoDate;
|
||||
}
|
||||
|
||||
public String getLicense() {
|
||||
return license;
|
||||
}
|
||||
|
||||
public void setLicense(String license) {
|
||||
this.license = license;
|
||||
}
|
||||
|
||||
public List<ZenodoRelator> getRelatedIdentifiers() {
|
||||
return relatedIdentifiers;
|
||||
}
|
||||
|
||||
public void setRelatedIdentifiers(List<ZenodoRelator> relatedIdentifiers) {
|
||||
this.relatedIdentifiers = relatedIdentifiers;
|
||||
}
|
||||
|
||||
public List<ZenodoContributor> getContributors() {
|
||||
return contributors;
|
||||
}
|
||||
|
||||
public void setContributors(List<ZenodoContributor> contributors) {
|
||||
this.contributors = contributors;
|
||||
}
|
||||
|
||||
public List<ZenodoGrant> getGrants() {
|
||||
return grants;
|
||||
}
|
||||
|
||||
public void setGrants(List<ZenodoGrant> grants) {
|
||||
this.grants = grants;
|
||||
}
|
||||
|
||||
public List<ZenodoContributor> getCreators() {
|
||||
return creators;
|
||||
}
|
||||
|
||||
public void setCreators(List<ZenodoContributor> creators) {
|
||||
this.creators = creators;
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package eu.eudat.models.deposit.zenodo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class ZenodoGrant {
|
||||
private String id;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
package eu.eudat.models.deposit.zenodo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class ZenodoRelator {
|
||||
|
||||
private String identifier;
|
||||
private String relation;
|
||||
|
||||
public String getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
public void setIdentifier(String identifier) {
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
public String getRelation() {
|
||||
return relation;
|
||||
}
|
||||
|
||||
public void setRelation(String relation) {
|
||||
this.relation = relation;
|
||||
}
|
||||
}
|
|
@ -1,115 +0,0 @@
|
|||
package eu.eudat.models.deposit.zenodo.mapper;
|
||||
|
||||
import eu.eudat.data.entities.DMP;
|
||||
import eu.eudat.data.entities.Organisation;
|
||||
import eu.eudat.data.entities.UserDMP;
|
||||
import eu.eudat.logic.proxy.config.DOIFunder;
|
||||
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
|
||||
import eu.eudat.models.deposit.zenodo.*;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class DMPToZenodoMapper {
|
||||
|
||||
public static ZenodoDeposit fromDMP(DMP dmp, Environment environment, ConfigLoader configLoader) {
|
||||
Map<String, Object> extraProperties = dmp.getExtraProperties() != null ? new org.json.JSONObject(dmp.getExtraProperties()).toMap() : new HashMap<>();
|
||||
ZenodoDeposit deposit = new ZenodoDeposit();
|
||||
deposit.setMetadata(new ZenodoDepositMetadata());
|
||||
deposit.getMetadata().setTitle(dmp.getLabel());
|
||||
deposit.getMetadata().setUploadType("publication");
|
||||
deposit.getMetadata().setPublicationType("datamanagementplan");
|
||||
deposit.getMetadata().setDescription((dmp.getDescription() != null && !dmp.getDescription().isEmpty() ? dmp.getDescription() : "<p></p>"));
|
||||
deposit.getMetadata().setVersion(dmp.getVersion().toString());
|
||||
ZenodoComunity community = new ZenodoComunity();
|
||||
community.setIdentifier(environment.getProperty("zenodo.community"));
|
||||
deposit.getMetadata().setCommunities(Collections.singletonList(community));
|
||||
if (extraProperties.get("visible") == null) {
|
||||
deposit.getMetadata().setAccessRight(ZenodoAccessRight.RESTRICTED);
|
||||
deposit.getMetadata().setAccessConditions("");
|
||||
} else {
|
||||
if (((Boolean) extraProperties.get("visible"))) {
|
||||
Instant publicationDate = Instant.parse(extraProperties.get("publicDate").toString());
|
||||
if (publicationDate.isBefore(Instant.now())) {
|
||||
deposit.getMetadata().setAccessRight(ZenodoAccessRight.OPEN);
|
||||
} else {
|
||||
deposit.getMetadata().setAccessRight(ZenodoAccessRight.EMBARGOED);
|
||||
deposit.getMetadata().setEmbargoDate(publicationDate.toString());
|
||||
}
|
||||
|
||||
if (extraProperties.get("license") != null) {
|
||||
deposit.getMetadata().setLicense(((Map<?, ?>) extraProperties.get("license")).get("pid").toString());
|
||||
}
|
||||
} else {
|
||||
deposit.getMetadata().setAccessRight(ZenodoAccessRight.RESTRICTED);
|
||||
deposit.getMetadata().setAccessConditions("");
|
||||
}
|
||||
}
|
||||
if (dmp.isPublic()) {
|
||||
ZenodoRelator relator = new ZenodoRelator();
|
||||
relator.setIdentifier((environment.getProperty("dmp.domain") + "/external/zenodo/" + dmp.getId().toString()));
|
||||
relator.setRelation("isIdenticalTo");
|
||||
deposit.getMetadata().setRelatedIdentifiers(Collections.singletonList(relator));
|
||||
}
|
||||
deposit.getMetadata().setContributors(new LinkedList<>());
|
||||
List<ZenodoContributor> contributors = dmp.getUsers().stream().map(userDMP -> {
|
||||
ZenodoContributor contributor = new ZenodoContributor();
|
||||
contributor.setName(userDMP.getUser().getName());
|
||||
contributor.setType("ProjectMember");
|
||||
if (dmp.getOrganisations() != null && !dmp.getOrganisations().isEmpty()) {
|
||||
contributor.setAffiliation(dmp.getOrganisations()
|
||||
.stream().map(Organisation::getLabel).collect(Collectors.joining(", ")));
|
||||
} else {
|
||||
contributor.setAffiliation(environment.getProperty("zenodo.affiliation"));
|
||||
}
|
||||
return contributor;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
List<ZenodoContributor> researchers = dmp.getResearchers().stream().map(researcher -> {
|
||||
ZenodoContributor contributor = new ZenodoContributor();
|
||||
contributor.setName(researcher.getLabel());
|
||||
contributor.setType("Researcher");
|
||||
String referenceHead = researcher.getReference().split(":")[0];
|
||||
String referenceTail = researcher.getReference().replace(referenceHead + ":", "");
|
||||
contributor.setAffiliation(referenceHead);
|
||||
if (referenceHead.equalsIgnoreCase("ORCID")) {
|
||||
contributor.setOrcid(referenceTail);
|
||||
}
|
||||
return contributor;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
deposit.getMetadata().getContributors().addAll(contributors);
|
||||
deposit.getMetadata().getContributors().addAll(researchers);
|
||||
|
||||
if (dmp.getGrant().getReference() == null) {
|
||||
dmp.getGrant().setReference("dmp:" + dmp.getGrant().getId());
|
||||
}
|
||||
String grantReferenceHead = dmp.getGrant().getReference().split(":")[0];
|
||||
if (grantReferenceHead.equals("openaire")) {
|
||||
String grantReferenceTail = dmp.getGrant().getReference().split(":")[3];
|
||||
DOIFunder doiFunder = configLoader.getDOIFunders().stream()
|
||||
.filter(doiFunder1 -> dmp.getGrant().getFunder().getLabel().contains(doiFunder1.getFunder()) || doiFunder1.getFunder().contains(dmp.getGrant().getFunder().getLabel()))
|
||||
.findFirst().orElse(null);
|
||||
if (doiFunder != null) {
|
||||
String finalId = doiFunder.getDOI() + "::" + grantReferenceTail;
|
||||
ZenodoGrant grant = new ZenodoGrant();
|
||||
grant.setId(finalId);
|
||||
deposit.getMetadata().setGrants(Collections.singletonList(grant));
|
||||
}
|
||||
}
|
||||
ZenodoContributor creator = new ZenodoContributor();
|
||||
creator.setName(dmp.getUsers().stream().filter(userDMP -> userDMP.getRole().equals(UserDMP.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser().getName());
|
||||
if (dmp.getOrganisations() != null && !dmp.getOrganisations().isEmpty()) {
|
||||
creator.setAffiliation(dmp.getOrganisations()
|
||||
.stream().map(Organisation::getLabel).collect(Collectors.joining(", ")));
|
||||
} else {
|
||||
creator.setAffiliation(environment.getProperty("zenodo.affiliation"));
|
||||
}
|
||||
deposit.getMetadata().setCreators(Collections.singletonList(creator));
|
||||
|
||||
return deposit;
|
||||
}
|
||||
}
|
||||
|
|
@ -46,6 +46,7 @@ import { CollectionUtils } from './services/utilities/collection-utils.service';
|
|||
import { TypeUtils } from './services/utilities/type-utils.service';
|
||||
import { SpecialAuthGuard } from './special-auth-guard.service';
|
||||
import {PrefillingService} from "@app/core/services/prefilling.service";
|
||||
import { DepositRepositoriesService } from './services/deposit-repositories/deposit-repositories.service';
|
||||
//
|
||||
//
|
||||
// This is shared module that provides all the services. Its imported only once on the AppModule.
|
||||
|
@ -89,6 +90,7 @@ export class CoreServiceModule {
|
|||
FunderService,
|
||||
GrantFileUploadService,
|
||||
DmpService,
|
||||
DepositRepositoriesService,
|
||||
DmpProfileService,
|
||||
ExternalSourcesService,
|
||||
ExternalSourcesConfigurationService,
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { ConfigurationService } from '../configuration/configuration.service';
|
||||
import { BaseHttpService } from '../http/base-http.service';
|
||||
|
||||
@Injectable()
|
||||
export class DepositRepositoriesService {
|
||||
|
||||
private actionUrl: string;
|
||||
private headers = new HttpHeaders();
|
||||
|
||||
constructor(private http: BaseHttpService, private httpClient: HttpClient, private configurationService: ConfigurationService) {
|
||||
this.actionUrl = configurationService.server + 'deposit/';
|
||||
}
|
||||
|
||||
getAvailableRepos(): Observable<string[]> {
|
||||
return this.http.get<string[]>(this.actionUrl + 'repos/', { headers: this.headers });
|
||||
}
|
||||
}
|
|
@ -50,6 +50,7 @@ import { FormProgressIndicationComponent } from '../misc/dataset-description-for
|
|||
import { FormProgressIndicationModule } from '../misc/dataset-description-form/components/form-progress-indication/form-progress-indication.module';
|
||||
import { DatasetPreviewDialogComponent } from './dataset-preview/dataset-preview-dialog.component';
|
||||
import {RichTextEditorModule} from "@app/library/rich-text-editor/rich-text-editor.module";
|
||||
import { DmpDepositDialogComponent } from './editor/dmp-deposit-dialog/dmp-deposit-dialog.component';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
|
@ -103,7 +104,8 @@ import {RichTextEditorModule} from "@app/library/rich-text-editor/rich-text-edit
|
|||
FundingInfoComponent,
|
||||
DatasetInfoComponent,
|
||||
LicenseInfoComponent,
|
||||
DatasetPreviewDialogComponent
|
||||
DatasetPreviewDialogComponent,
|
||||
DmpDepositDialogComponent
|
||||
],
|
||||
entryComponents: [
|
||||
DmpInvitationDialogComponent,
|
||||
|
@ -119,7 +121,8 @@ import {RichTextEditorModule} from "@app/library/rich-text-editor/rich-text-edit
|
|||
StartNewDmpDialogComponent,
|
||||
StartNewDatasetDialogComponent,
|
||||
DatasetEditorDetailsComponent,
|
||||
DatasetPreviewDialogComponent
|
||||
DatasetPreviewDialogComponent,
|
||||
DmpDepositDialogComponent
|
||||
]
|
||||
})
|
||||
export class DmpModule { }
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
<div class="row d-flex flex-row">
|
||||
<div mat-dialog-title class="col-auto">{{ data.message }}</div>
|
||||
<div class="col-auto close-btn ml-auto" (click)="close()">
|
||||
<mat-icon>close</mat-icon>
|
||||
</div>
|
||||
</div>
|
||||
<div *ngIf="inputRepos.length > 0">
|
||||
<mat-form-field appearance="outline">
|
||||
<mat-select placeholder="Repositories" multiple>
|
||||
<mat-option *ngFor="let repo of inputRepos">
|
||||
{{ repo }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<div *ngIf="inputRepos.length === 0" class="emptyList">{{ 'DMP-FINALISE-DIALOG.EMPTY' | translate }} </div>
|
||||
|
||||
<div mat-dialog-actions class="d-flex justify-content-end mb-1">
|
||||
<div class="col-auto">
|
||||
<button mat-raised-button cdkFocusInitial (click)="close()" class="cancel-btn">{{ data.cancelButton }}</button>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<button mat-raised-button class="submit-btn" (click)="onSubmit()">{{ data.confirmButton }}</button>
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,35 @@
|
|||
import { Component, Inject, OnInit } from '@angular/core';
|
||||
import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
|
||||
import { BaseComponent } from '@common/base/base.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-dmp-deposit-dialog',
|
||||
templateUrl: './dmp-deposit-dialog.component.html',
|
||||
styleUrls: ['./dmp-deposit-dialog.component.scss']
|
||||
})
|
||||
export class DmpDepositDialogComponent extends BaseComponent implements OnInit {
|
||||
|
||||
inputRepos: string[];
|
||||
outputRepos: string[];
|
||||
|
||||
constructor(
|
||||
public dialogRef: MatDialogRef<DmpDepositDialogComponent>,
|
||||
@Inject(MAT_DIALOG_DATA) public data: any
|
||||
) {
|
||||
super();
|
||||
this.inputRepos = data['depositRepos'];
|
||||
this.outputRepos = [];
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
}
|
||||
|
||||
onSubmit() {
|
||||
this.dialogRef.close(this.outputRepos);
|
||||
}
|
||||
|
||||
close() {
|
||||
this.dialogRef.close(this.outputRepos);
|
||||
}
|
||||
|
||||
}
|
|
@ -141,7 +141,7 @@
|
|||
<hr class="hr-line">
|
||||
</div>
|
||||
</div>
|
||||
<div *ngIf="hasDoi(dmp) && isFinalizedDmp(dmp) && !this.isPublicView && isUserOwner" (click)="getDoi(dmp)" class="row ml-0 mr-0 pl-4 pb-3 d-flex align-items-center">
|
||||
<div *ngIf="hasDoi(dmp) && isFinalizedDmp(dmp) && !this.isPublicView && isUserOwner" (click)="deposit()" class="row ml-0 mr-0 pl-4 pb-3 d-flex align-items-center">
|
||||
<button mat-mini-fab class="frame-btn">
|
||||
<mat-icon class="mat-mini-fab-icon">archive</mat-icon>
|
||||
</button>
|
||||
|
|
|
@ -41,6 +41,8 @@ import { StartNewDmpDialogComponent } from '../start-new-dmp-dialogue/start-new-
|
|||
import { HttpClient } from '@angular/common/http';
|
||||
import { MatomoService } from '@app/core/services/matomo/matomo-service';
|
||||
import { PopupNotificationDialogComponent } from '@app/library/notification/popup/popup-notification.component';
|
||||
import { DepositRepositoriesService } from '@app/core/services/deposit-repositories/deposit-repositories.service';
|
||||
import { DmpDepositDialogComponent } from '../editor/dmp-deposit-dialog/dmp-deposit-dialog.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-dmp-overview',
|
||||
|
@ -68,12 +70,15 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit {
|
|||
@ViewChild('doi')
|
||||
doi: ElementRef;
|
||||
|
||||
depositRepos: String[];
|
||||
|
||||
formGroup: FormGroup;
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private dmpService: DmpService,
|
||||
private depositRepositoriesService: DepositRepositoriesService,
|
||||
private translate: TranslateService,
|
||||
private authentication: AuthService,
|
||||
private dialog: MatDialog,
|
||||
|
@ -578,6 +583,26 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit {
|
|||
});
|
||||
}
|
||||
|
||||
deposit(){
|
||||
this.depositRepositoriesService.getAvailableRepos()
|
||||
.pipe(takeUntil(this._destroyed))
|
||||
.subscribe(
|
||||
repos => {
|
||||
this.depositRepos = repos;
|
||||
}
|
||||
);
|
||||
const dialogRef = this.dialog.open(DmpDepositDialogComponent, {
|
||||
restoreFocus: false,
|
||||
autoFocus: false,
|
||||
data: {
|
||||
depositRepos: this.depositRepos,
|
||||
message: "Select repositories to deposit",//this.language.instant('GENERAL.CONFIRMATION-DIALOG.FINALIZE-ITEM'),
|
||||
confirmButton: "Proceed to authentication",//this.language.instant('DMP-FINALISE-DIALOG.SUBMIT'),
|
||||
cancelButton: "Cancel",//this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CANCEL'),
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
finalize(dmp: DmpOverviewModel) {
|
||||
|
||||
const dialogInputModel: DmpFinalizeDialogInput = {
|
||||
|
|
Loading…
Reference in New Issue