cleanup deposit since they are moved in another git repository

This commit is contained in:
Bernaldo Mihasi 2022-12-13 10:12:12 +02:00
parent 39d709f41d
commit d0cde3c4c4
35 changed files with 0 additions and 1894 deletions

View File

@ -1,72 +0,0 @@
<?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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.2</version>
<relativePath/>
</parent>
<groupId>eu.eudat.depositinterface</groupId>
<artifactId>dataverseRepository</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>dataverseRepository</name>
<properties>
<java.version>11</java.version>
</properties>
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>eu.eudat</groupId>
<artifactId>depositinterface</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.github.IQSS</groupId>
<artifactId>dataverse-client-java</artifactId>
<version>master-dv14-12-compatible-ge2dc343-7</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<mainClass>eu.eudat.EuDatApplication</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,5 +0,0 @@
package eu.eudat.depositinterface.dataverserepository.config;
public interface ConfigLoader {
DataverseConfig getDataverseConfig();
}

View File

@ -1,45 +0,0 @@
package eu.eudat.depositinterface.dataverserepository.config;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
@Service("dataverseConfigLoader")
public class ConfigLoaderImpl implements ConfigLoader{
private static final Logger logger = LoggerFactory.getLogger(ConfigLoaderImpl.class);
private static final ObjectMapper mapper = new ObjectMapper();
private DataverseConfig dataverseConfig;
@Autowired
private Environment environment;
@Override
public DataverseConfig getDataverseConfig() {
if(dataverseConfig == null){
try{
dataverseConfig = mapper.readValue(getStreamFromPath(environment.getProperty("configuration.dataverse")), DataverseConfig.class);
} catch (IOException e) {
logger.error(e.getLocalizedMessage(), e);
}
}
return dataverseConfig;
}
private InputStream getStreamFromPath(String filePath) {
try {
return new FileInputStream(filePath);
} catch (FileNotFoundException e) {
logger.info("loading from classpath");
return getClass().getClassLoader().getResourceAsStream(filePath);
}
}
}

View File

@ -1,106 +0,0 @@
package eu.eudat.depositinterface.dataverserepository.config;
import com.fasterxml.jackson.annotation.JsonProperty;
import eu.eudat.depositinterface.repository.RepositoryDepositConfiguration;
public class DataverseConfig {
private enum DepositType {
SystemDeposit(0), UserDeposit(1), BothWaysDeposit(2);
private final int value;
DepositType(int value) {
this.value = value;
}
public int getValue() {
return value;
}
public static DepositType fromInteger(int value) {
switch (value) {
case 0:
return SystemDeposit;
case 1:
return UserDeposit;
case 2:
return BothWaysDeposit;
default:
throw new RuntimeException("Unsupported Deposit Type");
}
}
}
@JsonProperty("depositType")
private int depositType;
@JsonProperty("repositoryId")
private String repositoryId;
@JsonProperty("apiToken")
private String apiToken;
@JsonProperty("repositoryUrl")
private String repositoryUrl;
@JsonProperty("repositoryRecordUrl")
private String repositoryRecordUrl;
@JsonProperty("server")
private String server;
@JsonProperty("parentDataverseAlias")
private String parentDataverseAlias;
public int getDepositType() {
return depositType;
}
public void setDepositType(int depositType) {
this.depositType = depositType;
}
public String getRepositoryId() {
return repositoryId;
}
public void setRepositoryId(String repositoryId) {
this.repositoryId = repositoryId;
}
public String getApiToken() {
return apiToken;
}
public void setApiToken(String apiToken) {
this.apiToken = apiToken;
}
public String getRepositoryUrl() {
return repositoryUrl;
}
public void setRepositoryUrl(String repositoryUrl) {
this.repositoryUrl = repositoryUrl;
}
public String getRepositoryRecordUrl() {
return repositoryRecordUrl;
}
public void setRepositoryRecordUrl(String repositoryRecordUrl) {
this.repositoryRecordUrl = repositoryRecordUrl;
}
public String getServer() {
return server;
}
public void setServer(String server) {
this.server = server;
}
public String getParentDataverseAlias() {
return parentDataverseAlias;
}
public void setParentDataverseAlias(String parentDataverseAlias) {
this.parentDataverseAlias = parentDataverseAlias;
}
public RepositoryDepositConfiguration toRepoConfig() {
RepositoryDepositConfiguration config = new RepositoryDepositConfiguration();
config.setDepositType(this.depositType);
config.setRepositoryId(this.repositoryId);
config.setRepositoryUrl(this.repositoryUrl);
config.setRepositoryRecordUrl(this.repositoryRecordUrl);
return config;
}
}

View File

@ -1,200 +0,0 @@
package eu.eudat.depositinterface.dataverserepository.interfaces;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.researchspace.dataverse.api.v1.DataverseAPI;
import com.researchspace.dataverse.api.v1.DataverseConfig;
import com.researchspace.dataverse.entities.*;
import com.researchspace.dataverse.entities.facade.DatasetAuthor;
import com.researchspace.dataverse.entities.facade.DatasetContact;
import com.researchspace.dataverse.entities.facade.DatasetDescription;
import com.researchspace.dataverse.entities.facade.DatasetFacade;
import com.researchspace.dataverse.http.DataverseAPIImpl;
import eu.eudat.depositinterface.dataverserepository.config.ConfigLoader;
import eu.eudat.depositinterface.models.DMPDepositModel;
import eu.eudat.depositinterface.repository.RepositoryDeposit;
import eu.eudat.depositinterface.repository.RepositoryDepositConfiguration;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.http.*;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.*;
import java.util.stream.Collectors;
import static com.researchspace.dataverse.entities.Version.MAJOR;
import static com.researchspace.dataverse.entities.Version.MINOR;
@Component
public class DataverseDeposit implements RepositoryDeposit {
private static final Logger logger = LoggerFactory.getLogger(DataverseDeposit.class);
private static final ObjectMapper objectMapper = new ObjectMapper();
private DataverseAPI api;
private boolean isApiSet;
private ConfigLoader configLoader;
private Environment environment;
@Autowired
public DataverseDeposit(ConfigLoader configLoader, Environment environment){
this.configLoader = configLoader;
this.environment = environment;
this.isApiSet = false;
}
private void setDataverseApi() throws MalformedURLException {
if(!this.isApiSet) {
this.api = new DataverseAPIImpl();
eu.eudat.depositinterface.dataverserepository.config.DataverseConfig jsonConfig = this.configLoader.getDataverseConfig();
DataverseConfig config = new DataverseConfig(new URL(jsonConfig.getServer()), jsonConfig.getApiToken(), jsonConfig.getParentDataverseAlias());
api.configure(config);
this.isApiSet = true;
}
}
@Override
public String deposit(DMPDepositModel dmpDepositModel, String repositoryAccessToken) throws Exception {
if(!this.isApiSet)
this.setDataverseApi();
String doi;
DatasetFacade dataset = DatasetFacade.builder()
.title(dmpDepositModel.getLabel())
.authors(dmpDepositModel.getUsers().stream().map(x -> DatasetAuthor.builder().authorName(x.getUser().getName()).build()).collect(Collectors.toList()))
.contacts(dmpDepositModel.getUsers().stream().map(x -> DatasetContact.builder().datasetContactEmail(x.getUser().getEmail()).build()).collect(Collectors.toList()))
.subject("Other")
.description(DatasetDescription.builder().description(dmpDepositModel.getDescription()).build())
.languages(new ArrayList<>())
.depositor("")
.build();
if(dmpDepositModel.getPreviousDOI() == null || dmpDepositModel.getPreviousDOI().isEmpty()){
Identifier id = this.api.getDataverseOperations().createDataset(dataset, this.configLoader.getDataverseConfig().getParentDataverseAlias());
doi = this.api.getDatasetOperations().getDataset(id).getDoiId().orElse(null);
this.uploadFiles(dmpDepositModel, doi);
this.api.getDatasetOperations().publishDataset(id, MAJOR);
}
else{
Map<String, Object> datasetJson = this.getDatasetIdentifier(dmpDepositModel.getPreviousDOI());
Identifier id = new Identifier();
id.setId(((Integer) datasetJson.get("id")).longValue());
JsonNode jsonNode = this.objectMapper.readTree(new JSONObject(datasetJson).toString());
List<JsonNode> files = jsonNode.findValues("dataFile");
for(JsonNode file: files){
int fileId = file.get("id").asInt();
this.deleteFile(fileId);
}
this.uploadFiles(dmpDepositModel, dmpDepositModel.getPreviousDOI());
this.api.getDatasetOperations().updateDataset(dataset, id);
DataverseResponse<PublishedDataset> publishedDataset = this.api.getDatasetOperations().publishDataset(id, MAJOR);
doi = publishedDataset.getData().getAuthority() + "/" + publishedDataset.getData().getIdentifier();
}
return doi;
}
private void deleteFile(int fileId){
HttpHeaders headers = this.createBasicAuthHeaders(this.configLoader.getDataverseConfig().getApiToken(), "");
String serverUrl = this.configLoader.getDataverseConfig().getServer() + "/dvn/api/data-deposit/v1.1/swordv2/edit-media/file/" + fileId;
RestTemplate restTemplate = new RestTemplate();
restTemplate.exchange(serverUrl, HttpMethod.DELETE, new HttpEntity<>(headers), Object.class);
}
private HttpHeaders createBasicAuthHeaders(String username, String password) {
return new HttpHeaders() {{
String auth = username + ":" + password;
byte[] encodedAuth = Base64.getEncoder().encode(
auth.getBytes(StandardCharsets.UTF_8));
String authHeader = "Basic " + new String(encodedAuth);
set("Authorization", authHeader);
}};
}
private void uploadFiles(DMPDepositModel dmpDepositModel, String doi) throws IOException {
this.uploadFile(dmpDepositModel.getPdfFileName(), dmpDepositModel.getPdfFile(), doi);
String contentDisposition = dmpDepositModel.getRdaJson().getHeaders().get("Content-Disposition").get(0);
String jsonFileName = contentDisposition.substring(contentDisposition.lastIndexOf('=') + 1);
File rdaJson = new File(this.environment.getProperty("storage.temp") + jsonFileName);
OutputStream output = new FileOutputStream(rdaJson);
try {
output.write(Objects.requireNonNull(dmpDepositModel.getRdaJson().getBody()));
output.flush();
output.close();
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
this.uploadFile(jsonFileName, rdaJson, doi);
Files.deleteIfExists(rdaJson.toPath());
if(dmpDepositModel.getSupportingFilesZip() != null) {
this.uploadFile(dmpDepositModel.getSupportingFilesZip().getName(), dmpDepositModel.getSupportingFilesZip(), doi);
}
}
private Map<String, Object> getDatasetIdentifier(String previousDOI) {
HttpHeaders headers = new HttpHeaders();
headers.set("X-Dataverse-key", this.configLoader.getDataverseConfig().getApiToken());
String serverUrl = this.configLoader.getDataverseConfig().getServer() + "/api/datasets/:persistentId?persistentId=doi:" + previousDOI;
RestTemplate restTemplate = new RestTemplate();
return (Map<String, Object>) restTemplate.exchange(serverUrl, HttpMethod.GET, new HttpEntity<>(headers), Map.class).getBody().get("data");
}
private void uploadFile(String filename, File file, String doi) throws IOException {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
headers.set("X-Dataverse-key", this.configLoader.getDataverseConfig().getApiToken());
MultiValueMap<String, String> fileMap = new LinkedMultiValueMap<>();
ContentDisposition contentDisposition = ContentDisposition
.builder("form-data")
.name("file")
.filename(filename)
.build();
fileMap.add(HttpHeaders.CONTENT_DISPOSITION, contentDisposition.toString());
HttpEntity<byte[]> fileEntity = new HttpEntity<>(Files.readAllBytes(file.toPath()), fileMap);
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
body.add("file", fileEntity);
body.add("jsonData", "{\"restrict\":\"false\", \"tabIngest\":\"false\"}");
HttpEntity<MultiValueMap<String, Object>> requestEntity
= new HttpEntity<>(body, headers);
String serverUrl = this.configLoader.getDataverseConfig().getServer() + "/api/datasets/:persistentId/add?persistentId=doi:" + doi;
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<Object> resp = restTemplate.postForEntity(serverUrl, requestEntity, Object.class);
}
@Override
public RepositoryDepositConfiguration getConfiguration() {
eu.eudat.depositinterface.dataverserepository.config.DataverseConfig dataverseConfig = this.configLoader.getDataverseConfig();
return dataverseConfig.toRepoConfig();
}
@Override
public String authenticate(String code) {
return null;
}
}

View File

@ -1,2 +0,0 @@
storage.temp=${DATAVERSE_TMP}
configuration.dataverse=${DATAVERSE_CONF}

View File

@ -1,9 +0,0 @@
{
"depositType": 0,
"repositoryId": "Dataverse",
"apiToken": "",
"repositoryUrl": "https://demo.dataverse.org/api/",
"repositoryRecordUrl": "https://demo.dataverse.org/dataset.xhtml?persistentId=doi:",
"server": "https://demo.dataverse.org",
"parentDataverseAlias": ""
}

View File

@ -1,25 +0,0 @@
<?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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.4</version>
<relativePath/>
</parent>
<groupId>eu.eudat</groupId>
<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>

View File

@ -1,130 +0,0 @@
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 File supportingFilesZip;
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 File getSupportingFilesZip() {
return supportingFilesZip;
}
public void setSupportingFilesZip(File supportingFilesZip) {
this.supportingFilesZip = supportingFilesZip;
}
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;
}
}

View File

@ -1,12 +0,0 @@
package eu.eudat.depositinterface.models;
public class FunderDepositModel {
private String label;
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
}

View File

@ -1,30 +0,0 @@
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;
}
}

View File

@ -1,12 +0,0 @@
package eu.eudat.depositinterface.models;
public class OrganisationDepositModel {
private String label;
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
}

View File

@ -1,20 +0,0 @@
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;
}
}

View File

@ -1,47 +0,0 @@
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;
}
}

View File

@ -1,20 +0,0 @@
package eu.eudat.depositinterface.models;
public class UserInfoDepositModel {
private String name;
private String email;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}

View File

@ -1,13 +0,0 @@
package eu.eudat.depositinterface.repository;
import eu.eudat.depositinterface.models.DMPDepositModel;
public interface RepositoryDeposit {
String deposit(DMPDepositModel dmpDepositModel, String repositoryAccessToken) throws Exception;
String authenticate(String code);
RepositoryDepositConfiguration getConfiguration();
}

View File

@ -1,112 +0,0 @@
package eu.eudat.depositinterface.repository;
public class RepositoryDepositConfiguration {
public enum DepositType {
SystemDeposit(0), UserDeposit(1), BothWaysDeposit(2);
private int value;
DepositType(int value) {
this.value = value;
}
public int getValue() {
return value;
}
public static DepositType fromInteger(int value) {
switch (value) {
case 0:
return SystemDeposit;
case 1:
return UserDeposit;
case 2:
return BothWaysDeposit;
default:
throw new RuntimeException("Unsupported Deposit Account Type");
}
}
}
private int depositType;
private String repositoryId;
private String accessToken;
private String repositoryUrl;
private String repositoryAuthorizationUrl;
private String repositoryRecordUrl;
private String repositoryAccessTokenUrl;
private String repositoryClientId;
private String repositoryClientSecret;
private String redirectUri;
public int getDepositType() {
return depositType;
}
public void setDepositType(int depositType) {
this.depositType = depositType;
}
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 getRepositoryAuthorizationUrl() {
return repositoryAuthorizationUrl;
}
public void setRepositoryAuthorizationUrl(String repositoryAuthorizationUrl) {
this.repositoryAuthorizationUrl = repositoryAuthorizationUrl;
}
public String getRepositoryRecordUrl() {
return repositoryRecordUrl;
}
public void setRepositoryRecordUrl(String repositoryRecordUrl) {
this.repositoryRecordUrl = repositoryRecordUrl;
}
public String getRepositoryAccessTokenUrl() {
return repositoryAccessTokenUrl;
}
public void setRepositoryAccessTokenUrl(String repositoryAccessTokenUrl) {
this.repositoryAccessTokenUrl = repositoryAccessTokenUrl;
}
public String getRepositoryClientId() {
return repositoryClientId;
}
public void setRepositoryClientId(String repositoryClientId) {
this.repositoryClientId = repositoryClientId;
}
public String getRepositoryClientSecret() {
return repositoryClientSecret;
}
public void setRepositoryClientSecret(String repositoryClientSecret) {
this.repositoryClientSecret = repositoryClientSecret;
}
public String getRedirectUri() {
return redirectUri;
}
public void setRedirectUri(String redirectUri) {
this.redirectUri = redirectUri;
}
}

View File

@ -1,3 +0,0 @@
artifactId=depositinterface
groupId=eu.eudat
version=1.0-SNAPSHOT

View File

@ -1,39 +0,0 @@
<?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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.2</version>
<relativePath/>
</parent>
<groupId>eu.eudat.depositinterface</groupId>
<artifactId>zenodoRepository</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>zenodoRepository</name>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>eu.eudat</groupId>
<artifactId>depositinterface</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20160810</version>
</dependency>
</dependencies>
</project>

View File

@ -1,8 +0,0 @@
package eu.eudat.depositinterface.zenodorepository.config;
import java.util.List;
public interface ConfigLoader {
List<DOIFunder> getDOIFunders();
ZenodoConfig getZenodoConfig();
}

View File

@ -1,60 +0,0 @@
package eu.eudat.depositinterface.zenodorepository.config;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service("zenodoConfigLoader")
public class ConfigLoaderImpl implements ConfigLoader{
private static final Logger logger = LoggerFactory.getLogger(ConfigLoaderImpl.class);
private static final ObjectMapper mapper = new ObjectMapper();
private List<DOIFunder> doiFunders = new ArrayList<>();
private ZenodoConfig zenodoConfig;
@Autowired
private Environment environment;
@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;
}
@Override
public ZenodoConfig getZenodoConfig() {
if (zenodoConfig == null) {
try {
zenodoConfig = mapper.readValue(getStreamFromPath("zenodo.json"), ZenodoConfig.class);
} catch (IOException e) {
logger.error(e.getLocalizedMessage(), e);
}
}
return zenodoConfig;
}
private InputStream getStreamFromPath(String filePath) {
try {
return new FileInputStream(filePath);
} catch (FileNotFoundException e) {
logger.info("loading from classpath");
return getClass().getClassLoader().getResourceAsStream(filePath);
}
}
}

View File

@ -1,27 +0,0 @@
package eu.eudat.depositinterface.zenodorepository.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;
}
}

View File

@ -1,140 +0,0 @@
package eu.eudat.depositinterface.zenodorepository.config;
import com.fasterxml.jackson.annotation.JsonProperty;
import eu.eudat.depositinterface.repository.RepositoryDepositConfiguration;
public class ZenodoConfig {
private enum DepositType {
SystemDeposit(0), UserDeposit(1), BothWaysDeposit(2);
private final int value;
DepositType(int value) {
this.value = value;
}
public int getValue() {
return value;
}
public static DepositType fromInteger(int value) {
switch (value) {
case 0:
return SystemDeposit;
case 1:
return UserDeposit;
case 2:
return BothWaysDeposit;
default:
throw new RuntimeException("Unsupported Deposit Type");
}
}
}
@JsonProperty("depositType")
private int depositType;
@JsonProperty("repositoryId")
private String repositoryId;
@JsonProperty("accessToken")
private String accessToken;
@JsonProperty("repositoryUrl")
private String repositoryUrl;
@JsonProperty("repositoryAuthorizationUrl")
private String repositoryAuthorizationUrl;
@JsonProperty("repositoryRecordUrl")
private String repositoryRecordUrl;
@JsonProperty("repositoryAccessTokenUrl")
private String repositoryAccessTokenUrl;
@JsonProperty("repositoryClientId")
private String repositoryClientId;
@JsonProperty("repositoryClientSecret")
private String repositoryClientSecret;
@JsonProperty("redirectUri")
private String redirectUri;
public int getDepositType() {
return depositType;
}
public void setDepositType(int depositType) {
this.depositType = depositType;
}
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 getRepositoryAuthorizationUrl() {
return repositoryAuthorizationUrl;
}
public void setRepositoryAuthorizationUrl(String repositoryAuthorizationUrl) {
this.repositoryAuthorizationUrl = repositoryAuthorizationUrl;
}
public String getRepositoryRecordUrl() {
return repositoryRecordUrl;
}
public void setRepositoryRecordUrl(String repositoryRecordUrl) {
this.repositoryRecordUrl = repositoryRecordUrl;
}
public String getRepositoryAccessTokenUrl() {
return repositoryAccessTokenUrl;
}
public void setRepositoryAccessTokenUrl(String repositoryAccessTokenUrl) {
this.repositoryAccessTokenUrl = repositoryAccessTokenUrl;
}
public String getRepositoryClientId() {
return repositoryClientId;
}
public void setRepositoryClientId(String repositoryClientId) {
this.repositoryClientId = repositoryClientId;
}
public String getRepositoryClientSecret() {
return repositoryClientSecret;
}
public void setRepositoryClientSecret(String repositoryClientSecret) {
this.repositoryClientSecret = repositoryClientSecret;
}
public String getRedirectUri() {
return redirectUri;
}
public void setRedirectUri(String redirectUri) {
this.redirectUri = redirectUri;
}
public RepositoryDepositConfiguration toRepoConfig() {
RepositoryDepositConfiguration config = new RepositoryDepositConfiguration();
config.setDepositType(this.depositType);
config.setRepositoryId(this.repositoryId);
config.setAccessToken(this.accessToken);
config.setRepositoryUrl(this.repositoryUrl);
config.setRepositoryAuthorizationUrl(this.repositoryAuthorizationUrl);
config.setRepositoryRecordUrl(this.repositoryRecordUrl);
config.setRepositoryAccessTokenUrl(this.repositoryAccessTokenUrl);
config.setRepositoryClientId(this.repositoryClientId);
config.setRepositoryClientSecret(this.repositoryClientSecret);
config.setRedirectUri(this.redirectUri);
return config;
}
}

View File

@ -1,248 +0,0 @@
package eu.eudat.depositinterface.zenodorepository.interfaces;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.depositinterface.models.DMPDepositModel;
import eu.eudat.depositinterface.repository.RepositoryDeposit;
import eu.eudat.depositinterface.repository.RepositoryDepositConfiguration;
import eu.eudat.depositinterface.zenodorepository.config.ConfigLoader;
import eu.eudat.depositinterface.zenodorepository.config.ZenodoConfig;
import eu.eudat.depositinterface.zenodorepository.mapper.DMPToZenodoMapper;
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.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.HttpServerErrorException;
import org.springframework.web.client.RestTemplate;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.util.*;
@Component
public class ZenodoDeposit implements RepositoryDeposit {
private static final Logger logger = LoggerFactory.getLogger(ZenodoDeposit.class);
private static final ObjectMapper objectMapper = new ObjectMapper();
private ConfigLoader configLoader;
private Environment environment;
@Autowired
public ZenodoDeposit(ConfigLoader configLoader, Environment environment){
this.configLoader = configLoader;
this.environment = environment;
}
@Override
public String deposit(DMPDepositModel dmpDepositModel, String zenodoToken) throws Exception {
RepositoryDepositConfiguration conf = this.getConfiguration();
if(zenodoToken == null){
zenodoToken = conf.getAccessToken();
}
String zenodoUrl = conf.getRepositoryUrl();
// 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);
eu.eudat.depositinterface.zenodorepository.models.ZenodoDeposit deposit = DMPToZenodoMapper.fromDMP(dmpDepositModel, "argos", "ARGOS", "https://argos.openaire.eu/", this.configLoader.getDOIFunders());
HttpEntity<eu.eudat.depositinterface.zenodorepository.models.ZenodoDeposit> request = new HttpEntity<>(deposit, headers);
Map createResponse;
LinkedHashMap<String, String> links;
String previousDOI = dmpDepositModel.getPreviousDOI();
String unpublishedUrl = null;
String publishUrl;
String finalDoi;
try {
if (previousDOI == null) {
String createUrl = zenodoUrl + "deposit/depositions" + "?access_token=" + zenodoToken;
createResponse = restTemplate.postForEntity(createUrl, request, Map.class).getBody();
links = (LinkedHashMap<String, String>) createResponse.get("links");
}
else {
unpublishedUrl = this.getUnpublishedDOI(zenodoUrl, previousDOI, zenodoToken, dmpDepositModel.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 = zenodoUrl + "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");
//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 = zenodoUrl + "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.
File pdfFile = dmpDepositModel.getPdfFile();
String fileName = dmpDepositModel.getPdfFileName();
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);
ResponseEntity<byte[]> jsonFile = dmpDepositModel.getRdaJson();
UUID jsonFileUUID = UUID.randomUUID();
File tempJsonFile = new File(this.environment.getProperty("storage.temp") + jsonFileUUID + ".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());
if(dmpDepositModel.getSupportingFilesZip() != null) {
File supportinFilesZip = dmpDepositModel.getSupportingFilesZip();
String supportinFilesZipName = dmpDepositModel.getSupportingFilesZip().getName();
fileSystemResource = new FileSystemResource(supportinFilesZip);
addFileMapRequest = new HttpEntity<>(fileSystemResource, null);
addFileUrl = links.get("bucket") + "/" + supportinFilesZipName + "?access_token=" + zenodoToken;
restTemplate.put(addFileUrl, addFileMapRequest);
}
// 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;
}
return this.publish(publishUrl);
} catch (HttpClientErrorException | HttpServerErrorException ex) {
Map<String, String> parsedException = objectMapper.readValue(ex.getResponseBodyAsString(), HashMap.class);
throw new IOException(parsedException.get("message"), ex);
}
}
private String publish(String publishUrl){
RestTemplate restTemplate = new RestTemplate();
Map<String, Object> publishResponce = restTemplate.postForObject(publishUrl, "", Map.class);
return (String) publishResponce.get("conceptdoi");
}
@Override
public RepositoryDepositConfiguration getConfiguration() {
ZenodoConfig zenodoConfig = this.configLoader.getZenodoConfig();
return zenodoConfig.toRepoConfig();
}
@Override
public String authenticate(String code){
RepositoryDepositConfiguration conf = this.getConfiguration();
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
map.add("client_id", conf.getRepositoryClientId());
map.add("client_secret", conf.getRepositoryClientSecret());
map.add("grant_type", "authorization_code");
map.add("code", code);
map.add("redirect_uri", conf.getRedirectUri());
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(map, headers);
try {
Map<String, Object> values = restTemplate.postForObject(conf.getRepositoryAccessTokenUrl(), request, Map.class);
//ZenodoResponseToken zenodoResponseToken = new ZenodoResponseToken();
Map<String, Object> user = (Map<String, Object>) values.get("user");
// zenodoResponseToken.setUserId((String) user.get("id"));
// zenodoResponseToken.setEmail((String) user.get("email"));
// zenodoResponseToken.setExpiresIn((Integer) values.get("expires_in"));
// zenodoResponseToken.setAccessToken((String) values.get("access_token"));
// zenodoResponseToken.setRefreshToken((String) values.get("refresh_token"));
//return zenodoResponseToken;
return (String) values.get("access_token");
} catch (HttpClientErrorException ex) {
logger.error(ex.getResponseBodyAsString(), ex);
}
return null;
}
private String getUnpublishedDOI(String zenodoUrl, String DOI, String token, Integer version) {
try {
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
headers.setContentType(MediaType.APPLICATION_JSON);
Map createResponse = null;
LinkedHashMap<String, String> links = null;
LinkedHashMap<String, String> metadata = null;
String listUrl = zenodoUrl + "deposit/depositions" + "?q=conceptdoi:\"" + DOI + "\"&access_token=" + token;
ResponseEntity<Map[]> listResponses = restTemplate.getForEntity(listUrl, Map[].class);
createResponse = listResponses.getBody()[0];
metadata = (LinkedHashMap<String, String>) createResponse.get("metadata");
links = (LinkedHashMap<String, String>) createResponse.get("links");
if (metadata.get("version").equals(version.toString())) {
return links.get("publish");
} else {
return null;
}
}catch (Exception e) {
logger.warn(e.getMessage(), e);
return null;
}
}
}

View File

@ -1,119 +0,0 @@
package eu.eudat.depositinterface.zenodorepository.mapper;
import eu.eudat.depositinterface.models.DMPDepositModel;
import eu.eudat.depositinterface.models.OrganisationDepositModel;
import eu.eudat.depositinterface.models.UserDMPDepositModel;
import eu.eudat.depositinterface.zenodorepository.config.DOIFunder;
import eu.eudat.depositinterface.zenodorepository.models.*;
import java.time.Instant;
import java.util.*;
import java.util.stream.Collectors;
public class DMPToZenodoMapper {
public static ZenodoDeposit fromDMP(DMPDepositModel dmp, String zenodoCommunity, String zenodoAffiliation, String domain, List<DOIFunder> doiFunders) {
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(String.valueOf(dmp.getVersion()));
if(zenodoCommunity != null && !zenodoAffiliation.isEmpty()) {
ZenodoComunity community = new ZenodoComunity();
community.setIdentifier(zenodoCommunity);
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(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(OrganisationDepositModel::getLabel).collect(Collectors.joining(", ")));
} else {
if(zenodoAffiliation != null && !zenodoAffiliation.isEmpty()) {
contributor.setAffiliation(zenodoAffiliation);
}
}
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 = doiFunders.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(UserDMPDepositModel.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser().getName());
if (dmp.getOrganisations() != null && !dmp.getOrganisations().isEmpty()) {
creator.setAffiliation(dmp.getOrganisations()
.stream().map(OrganisationDepositModel::getLabel).collect(Collectors.joining(", ")));
} else {
if(zenodoAffiliation != null && !zenodoAffiliation.isEmpty()) {
creator.setAffiliation(zenodoAffiliation);
}
}
deposit.getMetadata().setCreators(Collections.singletonList(creator));
return deposit;
}
}

View File

@ -1,18 +0,0 @@
package eu.eudat.depositinterface.zenodorepository.models;
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;
}
}

View File

@ -1,19 +0,0 @@
package eu.eudat.depositinterface.zenodorepository.models;
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;
}
}

View File

@ -1,45 +0,0 @@
package eu.eudat.depositinterface.zenodorepository.models;
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;
}
}

View File

@ -1,19 +0,0 @@
package eu.eudat.depositinterface.zenodorepository.models;
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;
}
}

View File

@ -1,158 +0,0 @@
package eu.eudat.depositinterface.zenodorepository.models;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
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;
}
}

View File

@ -1,18 +0,0 @@
package eu.eudat.depositinterface.zenodorepository.models;
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;
}
}

View File

@ -1,28 +0,0 @@
package eu.eudat.depositinterface.zenodorepository.models;
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;
}
}

View File

@ -1,70 +0,0 @@
[
{
"Funder": "Australian Research Council",
"DOI": "10.13039/501100000923"
},
{
"Funder": "Austrian Science Fund",
"DOI": "10.13039/501100002428"
},
{
"Funder": "European Commission",
"DOI": "10.13039/501100000780"
},
{
"Funder": "European Environment Agency",
"DOI": "10.13039/501100000806"
},
{
"Funder": "Academy of Finland",
"DOI": "10.13039/501100002341"
},
{
"Funder": "Hrvatska Zaklada za Znanost",
"DOI": "10.13039/501100004488"
},
{
"Funder": "Fundação para a Ciência e a Tecnologia",
"DOI": "10.13039/501100001871"
},
{
"Funder": "Ministarstvo Prosvete, Nauke i Tehnološkog Razvoja",
"DOI": "10.13039/501100004564"
},
{
"Funder": "Ministarstvo Znanosti, Obrazovanja i Sporta",
"DOI": "10.13039/501100006588"
},
{
"Funder": "National Health and Medical Research Council",
"DOI": "10.13039/501100000925"
},
{
"Funder": "National Institutes of Health",
"DOI": "10.13039/100000002"
},
{
"Funder": "National Science Foundation",
"DOI": "10.13039/100000001"
},
{
"Funder": "Nederlandse Organisatie voor Wetenschappelijk Onderzoek",
"DOI": "10.13039/501100003246"
},
{
"Funder": "Research Councils",
"DOI": "10.13039/501100000690"
},
{
"Funder": "Schweizerischer Nationalfonds zur Förderung der wissenschaftlichen Forschung",
"DOI": "10.13039/501100001711"
},
{
"Funder": "Science Foundation Ireland",
"DOI": "10.13039/501100001602"
},
{
"Funder": "Wellcome Trust",
"DOI": "10.13039/100004440"
}
]

View File

@ -1,3 +0,0 @@
configuration.doi_funder=DOI_Funder.json
storage.temp=${ZENODO_TMP}
configuration.zenodo=${ZENODO_CONF}

View File

@ -1,12 +0,0 @@
{
"depositType": 2,
"repositoryId": "Zenodo",
"accessToken": "",
"repositoryUrl": "https://sandbox.zenodo.org/api/",
"repositoryAuthorizationUrl": "https://sandbox.zenodo.org/oauth/authorize",
"repositoryRecordUrl": "https://sandbox.zenodo.org/record/",
"repositoryAccessTokenUrl": "https://sandbox.zenodo.org/oauth/token",
"repositoryClientId": "",
"repositoryClientSecret": "",
"redirectUri": "http://localhost:4200/login/external/zenodo"
}