multiple configuration for repository

This commit is contained in:
Aldo Mihasi 2023-06-21 12:35:52 +03:00
parent 7510d27d9c
commit 1968334fdb
7 changed files with 220 additions and 190 deletions

View File

@ -51,7 +51,7 @@
<dependency> <dependency>
<groupId>gr.cite.opendmp</groupId> <groupId>gr.cite.opendmp</groupId>
<artifactId>repositorydepositbase</artifactId> <artifactId>repositorydepositbase</artifactId>
<version>1.0.3</version> <version>1.0.4</version>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -7,6 +7,6 @@ public interface ConfigLoader {
List<String> getRelatedIdentifiers(); List<String> getRelatedIdentifiers();
List<String> getAcceptedPidTypes(); List<String> getAcceptedPidTypes();
PidFieldNames getPidFieldNames(); PidFieldNames getPidFieldNames();
byte[] getLogo(); byte[] getLogo(String repositoryId);
ZenodoConfig getZenodoConfig(); List<ZenodoConfig> getZenodoConfig();
} }

View File

@ -1,5 +1,6 @@
package eu.eudat.depositinterface.zenodorepository.config; package eu.eudat.depositinterface.zenodorepository.config;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -22,9 +23,9 @@ public class ConfigLoaderImpl implements ConfigLoader{
private List<String> relatedIdentifiers = new ArrayList<>(); private List<String> relatedIdentifiers = new ArrayList<>();
private List<String> acceptedPidTypes = new ArrayList<>(); private List<String> acceptedPidTypes = new ArrayList<>();
private PidFieldNames pidFieldNames = new PidFieldNames(); private PidFieldNames pidFieldNames = new PidFieldNames();
private ZenodoConfig zenodoConfig; private List<ZenodoConfig> zenodoConfig = new ArrayList<>();
private Environment environment; private final Environment environment;
@Autowired @Autowired
public ConfigLoaderImpl(Environment environment){ public ConfigLoaderImpl(Environment environment){
@ -35,7 +36,7 @@ public class ConfigLoaderImpl implements ConfigLoader{
public List<DOIFunder> getDOIFunders() { public List<DOIFunder> getDOIFunders() {
if (doiFunders == null || doiFunders.isEmpty()) { if (doiFunders == null || doiFunders.isEmpty()) {
try { try {
List<Map<String, Object>> tempdoiFunders = mapper.readValue(getStreamFromPath(environment.getProperty("configuration.doi_funder")), List.class); List<Map<String, Object>> tempdoiFunders = mapper.readValue(getStreamFromPath(environment.getProperty("zenodo_plugin.configuration.doi_funder")), List.class);
doiFunders = tempdoiFunders.stream().map(map -> mapper.convertValue(map, DOIFunder.class) ).collect(Collectors.toList()); doiFunders = tempdoiFunders.stream().map(map -> mapper.convertValue(map, DOIFunder.class) ).collect(Collectors.toList());
} catch (IOException e) { } catch (IOException e) {
logger.error(e.getLocalizedMessage(), e); logger.error(e.getLocalizedMessage(), e);
@ -74,10 +75,10 @@ public class ConfigLoaderImpl implements ConfigLoader{
} }
@Override @Override
public ZenodoConfig getZenodoConfig() { public List<ZenodoConfig> getZenodoConfig() {
if (zenodoConfig == null) { if (zenodoConfig == null || zenodoConfig.isEmpty()) {
try { try {
zenodoConfig = mapper.readValue(getStreamFromPath(environment.getProperty("configuration.zenodo")), ZenodoConfig.class); zenodoConfig = mapper.readValue(getStreamFromPath(environment.getProperty("zenodo_plugin.configuration.zenodo")), new TypeReference<List<ZenodoConfig>>() {});
} catch (IOException e) { } catch (IOException e) {
logger.error(e.getLocalizedMessage(), e); logger.error(e.getLocalizedMessage(), e);
return null; return null;
@ -87,17 +88,26 @@ public class ConfigLoaderImpl implements ConfigLoader{
} }
@Override @Override
public byte[] getLogo() { public byte[] getLogo(String repositoryId) {
String logo = "zenodo.jpg"; if (!zenodoConfig.isEmpty()) {
if(logo != null && !logo.isEmpty()){ ZenodoConfig zenodoConfig = getZenodoConfig().stream().filter(x -> x.getRepositoryId().equals(repositoryId)).findFirst().orElse(null);
InputStream logoStream = getStreamFromPath(logo); if (zenodoConfig != null) {
try { String logo = zenodoConfig.getLogo();
return logoStream.readAllBytes(); InputStream logoStream;
} if (logo != null && !logo.isEmpty()) {
catch (IOException e){ logoStream = getStreamFromPath(logo);
logger.error(e.getMessage(), e); }
return null; else {
logoStream = getClass().getClassLoader().getResourceAsStream("zenodo.jpg");
}
try {
return (logoStream != null) ? logoStream.readAllBytes() : null;
}
catch (IOException e) {
logger.error(e.getMessage(), e);
}
} }
return null;
} }
return null; return null;
} }

View File

@ -54,6 +54,8 @@ public class ZenodoConfig {
private String redirectUri; private String redirectUri;
@JsonProperty("hasLogo") @JsonProperty("hasLogo")
private boolean hasLogo; private boolean hasLogo;
@JsonProperty("logo")
private String logo;
public int getDepositType() { public int getDepositType() {
return depositType; return depositType;
@ -132,6 +134,13 @@ public class ZenodoConfig {
this.hasLogo = hasLogo; this.hasLogo = hasLogo;
} }
public String getLogo() {
return logo;
}
public void setLogo(String logo) {
this.logo = logo;
}
public RepositoryDepositConfiguration toRepoConfig() { public RepositoryDepositConfiguration toRepoConfig() {
RepositoryDepositConfiguration config = new RepositoryDepositConfiguration(); RepositoryDepositConfiguration config = new RepositoryDepositConfiguration();
config.setDepositType(this.depositType); config.setDepositType(this.depositType);

View File

@ -24,14 +24,15 @@ import org.springframework.web.client.RestTemplate;
import java.io.*; import java.io.*;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
@Component @Component
public class ZenodoDeposit implements RepositoryDeposit { public class ZenodoDeposit implements RepositoryDeposit {
private static final Logger logger = LoggerFactory.getLogger(ZenodoDeposit.class); private static final Logger logger = LoggerFactory.getLogger(ZenodoDeposit.class);
private static final ObjectMapper objectMapper = new ObjectMapper(); private static final ObjectMapper objectMapper = new ObjectMapper();
private ConfigLoader configLoader; private final ConfigLoader configLoader;
private Environment environment; private final Environment environment;
@Autowired @Autowired
public ZenodoDeposit(ConfigLoader configLoader, Environment environment){ public ZenodoDeposit(ConfigLoader configLoader, Environment environment){
@ -40,148 +41,151 @@ public class ZenodoDeposit implements RepositoryDeposit {
} }
@Override @Override
public String deposit(DMPDepositModel dmpDepositModel, String zenodoToken) throws Exception { public String deposit(String repositoryId, DMPDepositModel dmpDepositModel, String zenodoToken) throws Exception {
RepositoryDepositConfiguration conf = this.getConfiguration(); RepositoryDepositConfiguration conf = this.getConfiguration().stream().filter(x -> x.getRepositoryId().equals(repositoryId)).findFirst().orElse(null);
if(zenodoToken == null){ if(conf != null) {
zenodoToken = conf.getAccessToken();
}
String zenodoUrl = conf.getRepositoryUrl(); if (zenodoToken == null) {
zenodoToken = conf.getAccessToken();
// 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);
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()); String zenodoUrl = conf.getRepositoryUrl();
if (unpublishedUrl == null) {
//It requires more than one step to create a new version // First step, post call to Zenodo, to create the entry.
//First, get the deposit related to the concept DOI RestTemplate restTemplate = new RestTemplate();
String listUrl = zenodoUrl + "deposit/depositions" + "?q=conceptdoi:\"" + previousDOI + "\"&access_token=" + zenodoToken; HttpHeaders headers = new HttpHeaders();
logger.debug("listUrl = " + listUrl); headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
ResponseEntity<Map[]> listResponses = restTemplate.getForEntity(listUrl, Map[].class); headers.setContentType(MediaType.APPLICATION_JSON);
createResponse = listResponses.getBody()[0]; eu.eudat.depositinterface.zenodorepository.models.ZenodoDeposit deposit = DMPToZenodoMapper.fromDMP(dmpDepositModel);
logger.debug("createResponse-previousDoi:");
logger.debug(objectMapper.writeValueAsString(createResponse)); 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"); links = (LinkedHashMap<String, String>) createResponse.get("links");
//Second, make the new version (not in the links?) } else {
String newVersionUrl = links.get("self") + "/actions/newversion" + "?access_token=" + zenodoToken; unpublishedUrl = this.getUnpublishedDOI(zenodoUrl, previousDOI, zenodoToken, dmpDepositModel.getVersion());
logger.debug("new version url: " + newVersionUrl); if (unpublishedUrl == null) {
createResponse = restTemplate.postForObject(newVersionUrl, null, Map.class); //It requires more than one step to create a new version
logger.debug("createResponse-newVersion:"); //First, get the deposit related to the concept DOI
logger.debug(objectMapper.writeValueAsString(createResponse)); String listUrl = zenodoUrl + "deposit/depositions" + "?q=conceptdoi:\"" + previousDOI + "\"&access_token=" + zenodoToken;
links = (LinkedHashMap<String, String>) createResponse.get("links"); logger.debug("listUrl = " + listUrl);
//Third, get the new deposit ResponseEntity<Map[]> listResponses = restTemplate.getForEntity(listUrl, Map[].class);
String latestDraftUrl = links.get("latest_draft") + "?access_token=" + zenodoToken; createResponse = listResponses.getBody()[0];
createResponse = restTemplate.getForObject(latestDraftUrl, Map.class); logger.debug("createResponse-previousDoi:");
logger.debug("createResponse-latestDraft:"); logger.debug(objectMapper.writeValueAsString(createResponse));
logger.debug(objectMapper.writeValueAsString(createResponse)); links = (LinkedHashMap<String, String>) createResponse.get("links");
links = (LinkedHashMap<String, String>) createResponse.get("links"); //Second, make the new version (not in the links?)
//At this point it might fail to perform the next requests so enclose them with try catch String newVersionUrl = links.get("self") + "/actions/newversion" + "?access_token=" + zenodoToken;
try { logger.debug("new version url: " + newVersionUrl);
//Forth, update the new deposit's metadata createResponse = restTemplate.postForObject(newVersionUrl, null, Map.class);
String updateUrl = links.get("self") + "?access_token=" + zenodoToken; logger.debug("createResponse-newVersion:");
restTemplate.put(updateUrl, request); logger.debug(objectMapper.writeValueAsString(createResponse));
//And finally remove pre-existing files from it links = (LinkedHashMap<String, String>) createResponse.get("links");
String fileListUrl = links.get("self") + "/files" + "?access_token=" + zenodoToken; //Third, get the new deposit
ResponseEntity<Map[]> fileListResponse = restTemplate.getForEntity(fileListUrl, Map[].class); String latestDraftUrl = links.get("latest_draft") + "?access_token=" + zenodoToken;
for (Map file : fileListResponse.getBody()) { createResponse = restTemplate.getForObject(latestDraftUrl, Map.class);
String fileDeleteUrl = links.get("self") + "/files/" + file.get("id") + "?access_token=" + zenodoToken; logger.debug("createResponse-latestDraft:");
restTemplate.delete(fileDeleteUrl); logger.debug(objectMapper.writeValueAsString(createResponse));
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;
} }
} catch (Exception e) { } else {
//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) String listUrl = zenodoUrl + "deposit/depositions" + "?q=conceptdoi:\"" + previousDOI + "\"&access_token=" + zenodoToken;
restTemplate.delete(latestDraftUrl); ResponseEntity<Map[]> listResponses = restTemplate.getForEntity(listUrl, Map[].class);
throw e; createResponse = listResponses.getBody()[0];
links = (LinkedHashMap<String, String>) createResponse.get("links");
} }
} }
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) { if (unpublishedUrl == null) {
// Second step, add the file to the entry. // Second step, add the file to the entry.
FileEnvelope pdfEnvelope = dmpDepositModel.getPdfFile(); FileEnvelope pdfEnvelope = dmpDepositModel.getPdfFile();
FileSystemResource fileSystemResource = new FileSystemResource(pdfEnvelope.getFile()); FileSystemResource fileSystemResource = new FileSystemResource(pdfEnvelope.getFile());
HttpEntity<FileSystemResource> addFileMapRequest = new HttpEntity<>(fileSystemResource, null); HttpEntity<FileSystemResource> addFileMapRequest = new HttpEntity<>(fileSystemResource, null);
String addFileUrl = links.get("bucket") + "/" + pdfEnvelope.getFilename() + "?access_token=" + zenodoToken; String addFileUrl = links.get("bucket") + "/" + pdfEnvelope.getFilename() + "?access_token=" + zenodoToken;
restTemplate.put(addFileUrl, addFileMapRequest);
FileEnvelope rdaJsonEnvelope = dmpDepositModel.getRdaJsonFile();
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentLength(rdaJsonEnvelope.getFile().length());
responseHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM);
responseHeaders.set("Content-Disposition", "attachment;filename=" + rdaJsonEnvelope.getFilename());
responseHeaders.set("Access-Control-Expose-Headers", "Content-Disposition");
responseHeaders.get("Access-Control-Expose-Headers").add("Content-Type");
byte[] content = Files.readAllBytes(rdaJsonEnvelope.getFile().toPath());
ResponseEntity<byte[]> jsonFile = new ResponseEntity<>(content, responseHeaders, HttpStatus.OK);
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); restTemplate.put(addFileUrl, addFileMapRequest);
FileEnvelope rdaJsonEnvelope = dmpDepositModel.getRdaJsonFile();
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentLength(rdaJsonEnvelope.getFile().length());
responseHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM);
responseHeaders.set("Content-Disposition", "attachment;filename=" + rdaJsonEnvelope.getFilename());
responseHeaders.set("Access-Control-Expose-Headers", "Content-Disposition");
responseHeaders.get("Access-Control-Expose-Headers").add("Content-Type");
byte[] content = Files.readAllBytes(rdaJsonEnvelope.getFile().toPath());
ResponseEntity<byte[]> jsonFile = new ResponseEntity<>(content, responseHeaders, HttpStatus.OK);
UUID jsonFileUUID = UUID.randomUUID();
File tempJsonFile = new File(this.environment.getProperty("zenodo_plugin.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;
} }
// Third post call to Zenodo to publish the entry and return the DOI. return this.publish(publishUrl);
publishUrl = links.get("publish") + "?access_token=" + zenodoToken;
} } catch (HttpClientErrorException | HttpServerErrorException ex) {
else { Map<String, String> parsedException = objectMapper.readValue(ex.getResponseBodyAsString(), HashMap.class);
publishUrl = unpublishedUrl + "?access_token=" + zenodoToken; throw new IOException(parsedException.get("message"), ex);
} }
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);
} }
return null;
} }
private String publish(String publishUrl){ private String publish(String publishUrl){
@ -192,54 +196,62 @@ public class ZenodoDeposit implements RepositoryDeposit {
@Override @Override
public RepositoryDepositConfiguration getConfiguration() { public List<RepositoryDepositConfiguration> getConfiguration() {
ZenodoConfig zenodoConfig = this.configLoader.getZenodoConfig(); List<ZenodoConfig> zenodoConfigs = this.configLoader.getZenodoConfig();
return (zenodoConfig != null) ? zenodoConfig.toRepoConfig() : null; return (zenodoConfigs != null) ? zenodoConfigs.stream().map(ZenodoConfig::toRepoConfig).collect(Collectors.toList()) : null;
} }
@Override @Override
public String authenticate(String code){ public String authenticate(String repositoryId, String code){
RepositoryDepositConfiguration conf = this.getConfiguration(); RepositoryDepositConfiguration conf = this.getConfiguration().stream().filter(x -> x.getRepositoryId().equals(repositoryId)).findFirst().orElse(null);
RestTemplate restTemplate = new RestTemplate(); if(conf != null) {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
MultiValueMap<String, String> map = new LinkedMultiValueMap<>(); RestTemplate restTemplate = new RestTemplate();
map.add("client_id", conf.getRepositoryClientId()); HttpHeaders headers = new HttpHeaders();
map.add("client_secret", conf.getRepositoryClientSecret()); headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
map.add("grant_type", "authorization_code"); headers.setContentType(MediaType.MULTIPART_FORM_DATA);
map.add("code", code);
map.add("redirect_uri", conf.getRedirectUri());
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(map, headers);
try { MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
Map<String, Object> values = restTemplate.postForObject(conf.getRepositoryAccessTokenUrl(), request, Map.class); map.add("client_id", conf.getRepositoryClientId());
//ZenodoResponseToken zenodoResponseToken = new ZenodoResponseToken(); map.add("client_secret", conf.getRepositoryClientSecret());
Map<String, Object> user = (Map<String, Object>) values.get("user"); map.add("grant_type", "authorization_code");
// zenodoResponseToken.setUserId((String) user.get("id")); map.add("code", code);
// zenodoResponseToken.setEmail((String) user.get("email")); map.add("redirect_uri", conf.getRedirectUri());
// zenodoResponseToken.setExpiresIn((Integer) values.get("expires_in")); HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(map, headers);
// zenodoResponseToken.setAccessToken((String) values.get("access_token"));
// zenodoResponseToken.setRefreshToken((String) values.get("refresh_token")); 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;
//return zenodoResponseToken;
return (String) values.get("access_token");
} catch (HttpClientErrorException ex) {
logger.error(ex.getResponseBodyAsString(), ex);
} }
return null; return null;
} }
@Override @Override
public String getLogo() { public String getLogo(String repositoryId) {
RepositoryDepositConfiguration conf = this.getConfiguration(); RepositoryDepositConfiguration conf = this.getConfiguration().stream().filter(x -> x.getRepositoryId().equals(repositoryId)).findFirst().orElse(null);
if(conf.isHasLogo()){ if(conf != null) {
byte[] logo = this.configLoader.getLogo(); if(conf.isHasLogo()){
return (logo != null && logo.length != 0) ? Base64.getEncoder().encodeToString(logo) : null; byte[] logo = this.configLoader.getLogo(repositoryId);
return (logo != null && logo.length != 0) ? Base64.getEncoder().encodeToString(logo) : null;
}
} }
return null; return null;
} }

View File

@ -171,7 +171,7 @@ public class DMPToZenodoMapper {
deposit.getMetadata().setPublicationType("datamanagementplan"); deposit.getMetadata().setPublicationType("datamanagementplan");
deposit.getMetadata().setDescription((dmp.getDescription() != null && !dmp.getDescription().isEmpty() ? dmp.getDescription() : "<p></p>")); deposit.getMetadata().setDescription((dmp.getDescription() != null && !dmp.getDescription().isEmpty() ? dmp.getDescription() : "<p></p>"));
deposit.getMetadata().setVersion(String.valueOf(dmp.getVersion())); deposit.getMetadata().setVersion(String.valueOf(dmp.getVersion()));
String zenodoCommunity = environment.getProperty("zenodo.community"); String zenodoCommunity = environment.getProperty("zenodo_plugin.zenodo.community");
if(zenodoCommunity != null && !zenodoCommunity.isEmpty()) { if(zenodoCommunity != null && !zenodoCommunity.isEmpty()) {
ZenodoComunity community = new ZenodoComunity(); ZenodoComunity community = new ZenodoComunity();
community.setIdentifier(zenodoCommunity); community.setIdentifier(zenodoCommunity);
@ -200,11 +200,11 @@ public class DMPToZenodoMapper {
} }
if (dmp.isPublic()) { if (dmp.isPublic()) {
ZenodoRelator relator = new ZenodoRelator(); ZenodoRelator relator = new ZenodoRelator();
relator.setIdentifier(environment.getProperty("zenodo.domain") + "/external/zenodo/" + dmp.getId().toString()); relator.setIdentifier(environment.getProperty("zenodo_plugin.zenodo.domain") + "/external/zenodo/" + dmp.getId().toString());
relator.setRelation("isIdenticalTo"); relator.setRelation("isIdenticalTo");
deposit.getMetadata().getRelatedIdentifiers().add(relator); deposit.getMetadata().getRelatedIdentifiers().add(relator);
} }
String zenodoAffiliation = environment.getProperty("zenodo.affiliation"); String zenodoAffiliation = environment.getProperty("zenodo_plugin.zenodo.affiliation");
List<ZenodoContributor> contributors1 = dmp.getUsers().stream().map(userDMP -> { List<ZenodoContributor> contributors1 = dmp.getUsers().stream().map(userDMP -> {
ZenodoContributor contributor = new ZenodoContributor(); ZenodoContributor contributor = new ZenodoContributor();
contributor.setName(userDMP.getUser().getName()); contributor.setName(userDMP.getUser().getName());

View File

@ -1,7 +1,6 @@
configuration.doi_funder=DOI_Funder.json zenodo_plugin.configuration.doi_funder=${ZENODO_DOI_DUNDER}
configuration.zenodo.logo=${CONFIGURATION_LOGO_ZENODO} zenodo_plugin.storage.temp=${STORAGE_TMP_ZENODO}
storage.temp=${STORAGE_TMP_ZENODO} zenodo_plugin.configuration.zenodo=${CONFIGURATION_ZENODO}
configuration.zenodo=${CONFIGURATION_ZENODO} zenodo_plugin.zenodo.community=${ZENODO_COMMUNITY}
zenodo.community=argos zenodo_plugin.zenodo.affiliation=${ZENODO_AFFILIATION}
zenodo.affiliation=ARGOS zenodo_plugin.zenodo.domain=${ZENODO_OPENDMP_DOMAIN}
zenodo.domain=https://argos.openaire.eu/