Replace old configuration loader with standard Spring boot configuration yml
This commit is contained in:
parent
a8f4d8a297
commit
369b24c673
|
@ -1,13 +0,0 @@
|
|||
package eu.eudat.depositinterface.zenodorepository.config;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
public interface ConfigLoader {
|
||||
InputStream getStreamFromPath(String filePath);
|
||||
List<String> getRelatedIdentifiers();
|
||||
List<String> getAcceptedPidTypes();
|
||||
PidFieldNames getPidFieldNames();
|
||||
byte[] getLogo(String repositoryId);
|
||||
List<ZenodoConfig> getZenodoConfig();
|
||||
}
|
|
@ -1,110 +0,0 @@
|
|||
package eu.eudat.depositinterface.zenodorepository.config;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
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<String> relatedIdentifiers = new ArrayList<>();
|
||||
private List<String> acceptedPidTypes = new ArrayList<>();
|
||||
private PidFieldNames pidFieldNames = new PidFieldNames();
|
||||
private List<ZenodoConfig> zenodoConfig = new ArrayList<>();
|
||||
|
||||
private final Environment environment;
|
||||
|
||||
@Autowired
|
||||
public ConfigLoaderImpl(Environment environment){
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getRelatedIdentifiers() {
|
||||
if (relatedIdentifiers == null || relatedIdentifiers.isEmpty()) {
|
||||
BufferedReader ids = new BufferedReader(new InputStreamReader(getStreamFromPath("relatedIdentifiers.txt")));
|
||||
relatedIdentifiers = ids.lines().collect(Collectors.toList());
|
||||
}
|
||||
return relatedIdentifiers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAcceptedPidTypes() {
|
||||
if (acceptedPidTypes == null || acceptedPidTypes.isEmpty()) {
|
||||
BufferedReader ids = new BufferedReader(new InputStreamReader(getStreamFromPath("acceptedPidTypes.txt")));
|
||||
acceptedPidTypes = ids.lines().collect(Collectors.toList());
|
||||
}
|
||||
return acceptedPidTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PidFieldNames getPidFieldNames() {
|
||||
try {
|
||||
pidFieldNames = mapper.readValue(getStreamFromPath("datasetFieldsPid.json"), PidFieldNames.class);
|
||||
}
|
||||
catch (IOException e){
|
||||
logger.error(e.getLocalizedMessage(), e);
|
||||
}
|
||||
return pidFieldNames;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ZenodoConfig> getZenodoConfig() {
|
||||
if (zenodoConfig == null || zenodoConfig.isEmpty()) {
|
||||
try {
|
||||
zenodoConfig = mapper.readValue(getStreamFromPath(environment.getProperty("zenodo_plugin.configuration.zenodo")), new TypeReference<List<ZenodoConfig>>() {});
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getLocalizedMessage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return zenodoConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getLogo(String repositoryId) {
|
||||
if (!zenodoConfig.isEmpty()) {
|
||||
ZenodoConfig zenodoConfig = getZenodoConfig().stream().filter(x -> x.getRepositoryId().equals(repositoryId)).findFirst().orElse(null);
|
||||
if (zenodoConfig != null) {
|
||||
String logo = zenodoConfig.getLogo();
|
||||
InputStream logoStream;
|
||||
if (logo != null && !logo.isEmpty()) {
|
||||
logoStream = getStreamFromPath(logo);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getStreamFromPath(String filePath) {
|
||||
try {
|
||||
return new FileInputStream(filePath);
|
||||
} catch (FileNotFoundException e) {
|
||||
logger.info("loading from classpath");
|
||||
return getClass().getClassLoader().getResourceAsStream(filePath);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
package eu.eudat.depositinterface.zenodorepository.config;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class PidFieldNames {
|
||||
@JsonProperty("pidName")
|
||||
private String pidName;
|
||||
@JsonProperty("pidTypeName")
|
||||
private String pidTypeName;
|
||||
|
||||
public PidFieldNames() {}
|
||||
|
||||
public PidFieldNames(String pidName, String pidTypeName) {
|
||||
this.pidName = pidName;
|
||||
this.pidTypeName = pidTypeName;
|
||||
}
|
||||
|
||||
public String getPidName() {
|
||||
return pidName;
|
||||
}
|
||||
public void setPidName(String pidName) {
|
||||
this.pidName = pidName;
|
||||
}
|
||||
|
||||
public String getPidTypeName() {
|
||||
return pidTypeName;
|
||||
}
|
||||
public void setPidTypeName(String pidTypeName) {
|
||||
this.pidTypeName = pidTypeName;
|
||||
}
|
||||
}
|
|
@ -1,195 +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;
|
||||
@JsonProperty("hasLogo")
|
||||
private boolean hasLogo;
|
||||
@JsonProperty("logo")
|
||||
private String logo;
|
||||
@JsonProperty("doiFunder")
|
||||
private String doiFunder;
|
||||
@JsonProperty("community")
|
||||
private String community;
|
||||
@JsonProperty("affiliation")
|
||||
private String affiliation;
|
||||
@JsonProperty("domain")
|
||||
private String domain;
|
||||
|
||||
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 boolean isHasLogo() {
|
||||
return hasLogo;
|
||||
}
|
||||
public void setHasLogo(boolean hasLogo) {
|
||||
this.hasLogo = hasLogo;
|
||||
}
|
||||
|
||||
public String getLogo() {
|
||||
return logo;
|
||||
}
|
||||
public void setLogo(String logo) {
|
||||
this.logo = logo;
|
||||
}
|
||||
|
||||
public String getDoiFunder() {
|
||||
return doiFunder;
|
||||
}
|
||||
public void setDoiFunder(String doiFunder) {
|
||||
this.doiFunder = doiFunder;
|
||||
}
|
||||
|
||||
public String getCommunity() {
|
||||
return community;
|
||||
}
|
||||
public void setCommunity(String community) {
|
||||
this.community = community;
|
||||
}
|
||||
|
||||
public String getAffiliation() {
|
||||
return affiliation;
|
||||
}
|
||||
public void setAffiliation(String affiliation) {
|
||||
this.affiliation = affiliation;
|
||||
}
|
||||
|
||||
public String getDomain() {
|
||||
return domain;
|
||||
}
|
||||
public void setDomain(String domain) {
|
||||
this.domain = domain;
|
||||
}
|
||||
|
||||
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);
|
||||
config.setHasLogo(this.hasLogo);
|
||||
return config;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package eu.eudat.depositinterface.zenodorepository.configuration;
|
||||
|
||||
import eu.eudat.depositinterface.zenodorepository.configuration.funder.FunderProperties;
|
||||
import eu.eudat.depositinterface.zenodorepository.configuration.identifier.IdentifierProperties;
|
||||
import eu.eudat.depositinterface.zenodorepository.configuration.pid.PidProperties;
|
||||
import eu.eudat.depositinterface.zenodorepository.configuration.zenodo.ZenodoProperties;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties({ZenodoProperties.class, PidProperties.class, FunderProperties.class, IdentifierProperties.class})
|
||||
public class GenericConfiguration {
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package eu.eudat.depositinterface.zenodorepository.configuration.funder;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.ConstructorBinding;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ConfigurationProperties(prefix = "funder")
|
||||
public class FunderProperties {
|
||||
|
||||
private final List<DOIFunder> available;
|
||||
|
||||
@ConstructorBinding
|
||||
public FunderProperties(List<DOIFunder> available) {
|
||||
this.available = available;
|
||||
}
|
||||
|
||||
public List<DOIFunder> getAvailable() {
|
||||
return available;
|
||||
}
|
||||
|
||||
public static class DOIFunder {
|
||||
private final String funder;
|
||||
private final String doi;
|
||||
|
||||
@ConstructorBinding
|
||||
public DOIFunder(String funder, String doi) {
|
||||
this.funder = funder;
|
||||
this.doi = doi;
|
||||
}
|
||||
|
||||
public String getFunder() {
|
||||
return funder;
|
||||
}
|
||||
|
||||
public String getDoi() {
|
||||
return doi;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package eu.eudat.depositinterface.zenodorepository.configuration.identifier;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.ConstructorBinding;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ConfigurationProperties(prefix = "identifiers")
|
||||
public class IdentifierProperties {
|
||||
private final List<String> related;
|
||||
|
||||
@ConstructorBinding
|
||||
public IdentifierProperties(List<String> related) {
|
||||
this.related = related;
|
||||
}
|
||||
|
||||
public List<String> getRelated() {
|
||||
return related;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package eu.eudat.depositinterface.zenodorepository.configuration.pid;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.ConstructorBinding;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ConfigurationProperties(prefix = "pid")
|
||||
public class PidProperties {
|
||||
|
||||
private final List<String> acceptedTypes;
|
||||
private final PidFieldNames fields;
|
||||
|
||||
@ConstructorBinding
|
||||
public PidProperties(List<String> acceptedTypes, PidFieldNames fields) {
|
||||
this.acceptedTypes = acceptedTypes;
|
||||
this.fields = fields;
|
||||
}
|
||||
|
||||
public List<String> getAcceptedTypes() {
|
||||
return acceptedTypes;
|
||||
}
|
||||
|
||||
public PidFieldNames getFields() {
|
||||
return fields;
|
||||
}
|
||||
|
||||
public static class PidFieldNames {
|
||||
private final String pidName;
|
||||
private final String pidTypeName;
|
||||
|
||||
@ConstructorBinding
|
||||
public PidFieldNames(String pidName, String pidTypeName) {
|
||||
this.pidName = pidName;
|
||||
this.pidTypeName = pidTypeName;
|
||||
}
|
||||
|
||||
public String getPidName() {
|
||||
return pidName;
|
||||
}
|
||||
|
||||
public String getPidTypeName() {
|
||||
return pidTypeName;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,150 @@
|
|||
package eu.eudat.depositinterface.zenodorepository.configuration.zenodo;
|
||||
|
||||
import eu.eudat.depositinterface.repository.RepositoryDepositConfiguration;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.ConstructorBinding;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ConfigurationProperties(prefix = "zenodo")
|
||||
public class ZenodoProperties {
|
||||
|
||||
private final String tempStorage;
|
||||
|
||||
private final List<ZenodoConfig> configuration;
|
||||
|
||||
@ConstructorBinding
|
||||
public ZenodoProperties(Map<String, String> storage, List<ZenodoConfig> configuration) {
|
||||
this.tempStorage = storage.get("temp");
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
public String getTempStorage() {
|
||||
return tempStorage;
|
||||
}
|
||||
|
||||
public List<ZenodoConfig> getConfiguration() {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
public static class ZenodoConfig extends RepositoryDepositConfiguration {
|
||||
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;
|
||||
private boolean hasLogo;
|
||||
private String logo;
|
||||
private String doiFunder;
|
||||
private String community;
|
||||
private String affiliation;
|
||||
private String domain;
|
||||
|
||||
@ConstructorBinding
|
||||
public ZenodoConfig(int depositType, String repositoryId, String accessToken, String repositoryUrl, String repositoryAuthorizationUrl, String repositoryRecordUrl, String repositoryAccessTokenUrl, String repositoryClientId, String repositoryClientSecret, String redirectUri, boolean hasLogo, String logo, String doiFunder, String community, String affiliation, String domain) {
|
||||
this.depositType = depositType;
|
||||
this.repositoryId = repositoryId;
|
||||
this.accessToken = accessToken;
|
||||
this.repositoryUrl = repositoryUrl;
|
||||
this.repositoryAuthorizationUrl = repositoryAuthorizationUrl;
|
||||
this.repositoryRecordUrl = repositoryRecordUrl;
|
||||
this.repositoryAccessTokenUrl = repositoryAccessTokenUrl;
|
||||
this.repositoryClientId = repositoryClientId;
|
||||
this.repositoryClientSecret = repositoryClientSecret;
|
||||
this.redirectUri = redirectUri;
|
||||
this.hasLogo = hasLogo;
|
||||
this.logo = logo;
|
||||
this.doiFunder = doiFunder;
|
||||
this.community = community;
|
||||
this.affiliation = affiliation;
|
||||
this.domain = domain;
|
||||
}
|
||||
|
||||
public int getDepositType() {
|
||||
return depositType;
|
||||
}
|
||||
|
||||
public String getRepositoryId() {
|
||||
return repositoryId;
|
||||
}
|
||||
|
||||
public String getAccessToken() {
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
public String getRepositoryUrl() {
|
||||
return repositoryUrl;
|
||||
}
|
||||
|
||||
public String getRepositoryAuthorizationUrl() {
|
||||
return repositoryAuthorizationUrl;
|
||||
}
|
||||
|
||||
public String getRepositoryRecordUrl() {
|
||||
return repositoryRecordUrl;
|
||||
}
|
||||
|
||||
public String getRepositoryAccessTokenUrl() {
|
||||
return repositoryAccessTokenUrl;
|
||||
}
|
||||
|
||||
public String getRepositoryClientId() {
|
||||
return repositoryClientId;
|
||||
}
|
||||
|
||||
public String getRepositoryClientSecret() {
|
||||
return repositoryClientSecret;
|
||||
}
|
||||
|
||||
public String getRedirectUri() {
|
||||
return redirectUri;
|
||||
}
|
||||
|
||||
public boolean isHasLogo() {
|
||||
return hasLogo;
|
||||
}
|
||||
|
||||
public String getLogo() {
|
||||
return logo;
|
||||
}
|
||||
|
||||
public String getDoiFunder() {
|
||||
return doiFunder;
|
||||
}
|
||||
|
||||
public String getCommunity() {
|
||||
return community;
|
||||
}
|
||||
|
||||
public String getAffiliation() {
|
||||
return affiliation;
|
||||
}
|
||||
|
||||
public String getDomain() {
|
||||
return domain;
|
||||
}
|
||||
|
||||
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);
|
||||
config.setHasLogo(this.hasLogo);
|
||||
return config;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,22 +5,21 @@ import eu.eudat.depositinterface.models.DMPDepositModel;
|
|||
import eu.eudat.depositinterface.models.FileEnvelope;
|
||||
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.configuration.zenodo.ZenodoProperties;
|
||||
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.ParameterizedTypeReference;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
import org.springframework.web.client.HttpServerErrorException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.reactive.function.BodyInserters;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
import java.io.*;
|
||||
|
@ -33,13 +32,13 @@ public class ZenodoDeposit implements RepositoryDeposit {
|
|||
private static final Logger logger = LoggerFactory.getLogger(ZenodoDeposit.class);
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
private final ConfigLoader configLoader;
|
||||
private final Environment environment;
|
||||
private final ZenodoProperties zenodoProperties;
|
||||
private final DMPToZenodoMapper mapper;
|
||||
|
||||
@Autowired
|
||||
public ZenodoDeposit(ConfigLoader configLoader, Environment environment){
|
||||
this.configLoader = configLoader;
|
||||
this.environment = environment;
|
||||
public ZenodoDeposit(ZenodoProperties zenodoProperties, DMPToZenodoMapper mapper){
|
||||
this.zenodoProperties = zenodoProperties;
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -52,27 +51,23 @@ public class ZenodoDeposit implements RepositoryDeposit {
|
|||
if (zenodoToken == null || zenodoToken.isEmpty()) {
|
||||
zenodoToken = conf.getAccessToken();
|
||||
}
|
||||
String finalToken = zenodoToken;
|
||||
|
||||
String zenodoUrl = conf.getRepositoryUrl();
|
||||
|
||||
// First step, post call to Zenodo, to create the entry.
|
||||
WebClient zenodoClient = WebClient.builder().build();
|
||||
//RestTemplate restTemplate = new RestTemplate();
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
|
||||
ZenodoConfig zenodoConfig = this.configLoader.getZenodoConfig().stream().filter(x -> x.getRepositoryId().equals(repositoryId)).findFirst().orElse(null);
|
||||
eu.eudat.depositinterface.zenodorepository.models.ZenodoDeposit deposit = DMPToZenodoMapper.fromDMP(dmpDepositModel, zenodoConfig);
|
||||
ZenodoProperties.ZenodoConfig zenodoConfig = this.zenodoProperties.getConfiguration().stream().filter(x -> x.getRepositoryId().equals(repositoryId)).findFirst().orElse(null);
|
||||
eu.eudat.depositinterface.zenodorepository.models.ZenodoDeposit deposit = mapper.fromDMP(dmpDepositModel, zenodoConfig);
|
||||
|
||||
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) {
|
||||
|
@ -81,7 +76,7 @@ public class ZenodoDeposit implements RepositoryDeposit {
|
|||
httpHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
|
||||
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
|
||||
})
|
||||
.bodyValue(deposit).exchangeToMono(mono -> mono.bodyToMono(new ParameterizedTypeReference<Map<String, Object>>() {})).block(); //restTemplate.postForEntity(createUrl, request, Map.class).getBody();
|
||||
.bodyValue(deposit).exchangeToMono(mono -> mono.bodyToMono(new ParameterizedTypeReference<Map<String, Object>>() {})).block();
|
||||
links = (LinkedHashMap<String, String>) createResponse.get("links");
|
||||
} else {
|
||||
unpublishedUrl = this.getUnpublishedDOI(zenodoUrl, previousDOI, zenodoToken, dmpDepositModel.getVersion());
|
||||
|
@ -90,7 +85,7 @@ public class ZenodoDeposit implements RepositoryDeposit {
|
|||
//First, get the deposit related to the concept DOI
|
||||
String listUrl = zenodoUrl + "deposit/depositions" + "?q=conceptdoi:\"" + previousDOI + "\"&access_token=" + zenodoToken;
|
||||
logger.debug("listUrl = " + listUrl);
|
||||
ResponseEntity<List<Map>> listResponses = zenodoClient.get().uri(listUrl).retrieve().toEntityList(Map.class).block();//restTemplate.getForEntity(listUrl, Map[].class);
|
||||
ResponseEntity<List<Map>> listResponses = zenodoClient.get().uri(listUrl).retrieve().toEntityList(Map.class).block();
|
||||
createResponse = listResponses.getBody().get(0);
|
||||
logger.debug("createResponse-previousDoi:");
|
||||
logger.debug(objectMapper.writeValueAsString(createResponse));
|
||||
|
@ -99,14 +94,14 @@ public class ZenodoDeposit implements RepositoryDeposit {
|
|||
String newVersionUrl = links.get("self") + "/actions/newversion" + "?access_token=" + zenodoToken;
|
||||
logger.debug("new version url: " + newVersionUrl);
|
||||
createResponse = zenodoClient.post().uri(newVersionUrl)
|
||||
.bodyValue(null).exchangeToMono(mono -> mono.bodyToMono(Map.class)).block();//restTemplate.postForObject(newVersionUrl, null, Map.class);
|
||||
.bodyValue(null).exchangeToMono(mono -> mono.bodyToMono(Map.class)).block();
|
||||
logger.debug("createResponse-newVersion:");
|
||||
logger.debug(objectMapper.writeValueAsString(createResponse));
|
||||
links = (LinkedHashMap<String, String>) createResponse.get("links");
|
||||
//Third, get the new deposit
|
||||
String latestDraftUrl = links.get("latest_draft") + "?access_token=" + zenodoToken;
|
||||
createResponse = zenodoClient.get().uri(latestDraftUrl)
|
||||
.exchangeToMono(mono -> mono.bodyToMono(Map.class)).block();//restTemplate.getForObject(latestDraftUrl, Map.class);
|
||||
.exchangeToMono(mono -> mono.bodyToMono(Map.class)).block();
|
||||
logger.debug("createResponse-latestDraft:");
|
||||
logger.debug(objectMapper.writeValueAsString(createResponse));
|
||||
links = (LinkedHashMap<String, String>) createResponse.get("links");
|
||||
|
@ -119,13 +114,12 @@ public class ZenodoDeposit implements RepositoryDeposit {
|
|||
httpHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
|
||||
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
|
||||
})
|
||||
.bodyValue(deposit).retrieve().toEntity(Map.class).block();//restTemplate.put(updateUrl, request);
|
||||
.bodyValue(deposit).retrieve().toEntity(Map.class).block();
|
||||
//And finally remove pre-existing files from it
|
||||
String fileListUrl = links.get("self") + "/files" + "?access_token=" + zenodoToken;
|
||||
ResponseEntity<List<Map>> fileListResponse = zenodoClient.get().uri(fileListUrl).retrieve().toEntityList(Map.class).block();//restTemplate.getForEntity(fileListUrl, Map[].class);
|
||||
ResponseEntity<List<Map>> fileListResponse = zenodoClient.get().uri(fileListUrl).retrieve().toEntityList(Map.class).block();
|
||||
for (Map file : fileListResponse.getBody()) {
|
||||
String fileDeleteUrl = links.get("self") + "/files/" + file.get("id") + "?access_token=" + zenodoToken;
|
||||
//restTemplate.delete(fileDeleteUrl);
|
||||
zenodoClient.delete().uri(fileDeleteUrl).retrieve().toEntity(Map.class).block();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
@ -145,50 +139,24 @@ public class ZenodoDeposit implements RepositoryDeposit {
|
|||
if (unpublishedUrl == null) {
|
||||
// Second step, add the file to the entry.
|
||||
FileEnvelope pdfEnvelope = dmpDepositModel.getPdfFile();
|
||||
FileSystemResource fileSystemResource = new FileSystemResource(pdfEnvelope.getFile());
|
||||
HttpEntity<FileSystemResource> addFileMapRequest = new HttpEntity<>(fileSystemResource, null);
|
||||
|
||||
String addFileUrl = links.get("bucket") + "/" + pdfEnvelope.getFilename() + "?access_token=" + zenodoToken;
|
||||
//restTemplate.put(addFileUrl, addFileMapRequest);
|
||||
zenodoClient.put().uri(addFileUrl).headers(httpHeaders -> httpHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM)).bodyValue(fileSystemResource).retrieve().toEntity(Map.class).block();
|
||||
|
||||
zenodoClient.put().uri(addFileUrl)
|
||||
.body(BodyInserters
|
||||
.fromResource(new ByteArrayResource(Files.readAllBytes(pdfEnvelope.getFile().toPath()))))
|
||||
.retrieve().toEntity(Map.class).block();
|
||||
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);
|
||||
String jsonFileName = rdaJsonEnvelope.getFilename();
|
||||
addFileUrl = links.get("bucket") + "/" + jsonFileName + "?access_token=" + zenodoToken;
|
||||
//restTemplate.put(addFileUrl, addFileMapRequest);
|
||||
zenodoClient.put().uri(addFileUrl).headers(httpHeaders -> httpHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM)).bodyValue(fileSystemResource).retrieve().toEntity(Map.class).block();
|
||||
Files.deleteIfExists(tempJsonFile.toPath());
|
||||
zenodoClient.put().uri(addFileUrl).headers(httpHeaders -> httpHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM)).body(BodyInserters.fromResource(new ByteArrayResource(Files.readAllBytes(rdaJsonEnvelope.getFile().toPath())))).retrieve().toEntity(Map.class).block();
|
||||
|
||||
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);
|
||||
zenodoClient.put().uri(addFileUrl).bodyValue(fileSystemResource).retrieve().toEntity(Map.class).block();
|
||||
zenodoClient.put().uri(addFileUrl).body(BodyInserters.fromResource(new ByteArrayResource(Files.readAllBytes(supportinFilesZip.toPath())))).retrieve().toEntity(Map.class).block();
|
||||
}
|
||||
|
||||
// Third post call to Zenodo to publish the entry and return the DOI.
|
||||
|
@ -213,15 +181,22 @@ public class ZenodoDeposit implements RepositoryDeposit {
|
|||
private String publish(String publishUrl){
|
||||
//RestTemplate restTemplate = new RestTemplate();
|
||||
WebClient webClient = WebClient.builder().build();
|
||||
Map<String, Object> publishResponce = webClient.post().uri(publishUrl).bodyValue("").retrieve().bodyToMono(Map.class).block();//restTemplate.postForObject(publishUrl, "", Map.class);
|
||||
Map<String, Object> publishResponce = webClient.post().uri(publishUrl).bodyValue("").exchangeToMono(mono -> {
|
||||
if (!mono.statusCode().is2xxSuccessful()) {
|
||||
mono.createException();
|
||||
throw new UnsupportedOperationException("Failed to publish to Zenodo");
|
||||
}
|
||||
return mono.bodyToMono(new ParameterizedTypeReference<Map<String, Object>>() {
|
||||
});
|
||||
}).block();
|
||||
return (String) publishResponce.get("conceptdoi");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<RepositoryDepositConfiguration> getConfiguration() {
|
||||
List<ZenodoConfig> zenodoConfigs = this.configLoader.getZenodoConfig();
|
||||
return (zenodoConfigs != null) ? zenodoConfigs.stream().map(ZenodoConfig::toRepoConfig).collect(Collectors.toList()) : null;
|
||||
List<ZenodoProperties.ZenodoConfig> zenodoConfigs = this.zenodoProperties.getConfiguration();
|
||||
return (zenodoConfigs != null) ? zenodoConfigs.stream().map(ZenodoProperties.ZenodoConfig::toRepoConfig).collect(Collectors.toList()) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -231,7 +206,6 @@ public class ZenodoDeposit implements RepositoryDeposit {
|
|||
|
||||
if(conf != null) {
|
||||
|
||||
//RestTemplate restTemplate = new RestTemplate();
|
||||
WebClient client = WebClient.builder().defaultHeaders(httpHeaders -> {
|
||||
httpHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
|
||||
httpHeaders.setContentType(MediaType.MULTIPART_FORM_DATA);
|
||||
|
@ -249,16 +223,8 @@ public class ZenodoDeposit implements RepositoryDeposit {
|
|||
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(map, headers);
|
||||
|
||||
try {
|
||||
Map<String, Object> values = client.post().uri(conf.getRepositoryAccessTokenUrl()).bodyValue(map).retrieve().bodyToMono(Map.class).block();//restTemplate.postForObject(conf.getRepositoryAccessTokenUrl(), request, Map.class);
|
||||
//ZenodoResponseToken zenodoResponseToken = new ZenodoResponseToken();
|
||||
Map<String, Object> values = client.post().uri(conf.getRepositoryAccessTokenUrl()).bodyValue(map).retrieve().bodyToMono(Map.class).block();
|
||||
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);
|
||||
|
@ -273,10 +239,17 @@ public class ZenodoDeposit implements RepositoryDeposit {
|
|||
|
||||
@Override
|
||||
public String getLogo(String repositoryId) {
|
||||
RepositoryDepositConfiguration conf = this.getConfiguration().stream().filter(x -> x.getRepositoryId().equals(repositoryId)).findFirst().orElse(null);
|
||||
ZenodoProperties.ZenodoConfig conf = this.zenodoProperties.getConfiguration().stream().filter(x -> x.getRepositoryId().equals(repositoryId)).findFirst().orElse(null);
|
||||
if(conf != null) {
|
||||
if(conf.isHasLogo()){
|
||||
byte[] logo = this.configLoader.getLogo(repositoryId);
|
||||
byte[] logo;
|
||||
try {
|
||||
File logoFile = ResourceUtils.getFile(conf.getLogo());
|
||||
InputStream logoStream = new FileInputStream(logoFile);
|
||||
logo = logoStream.readAllBytes();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return (logo != null && logo.length != 0) ? Base64.getEncoder().encodeToString(logo) : null;
|
||||
}
|
||||
}
|
||||
|
@ -285,16 +258,15 @@ public class ZenodoDeposit implements RepositoryDeposit {
|
|||
|
||||
private String getUnpublishedDOI(String zenodoUrl, String DOI, String token, Integer version) {
|
||||
try {
|
||||
//RestTemplate restTemplate = new RestTemplate();
|
||||
WebClient client = WebClient.builder().build();
|
||||
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;
|
||||
LinkedHashMap<String, String> links;
|
||||
LinkedHashMap<String, String> metadata;
|
||||
String listUrl = zenodoUrl + "deposit/depositions" + "?q=conceptdoi:\"" + DOI + "\"&access_token=" + token;
|
||||
ResponseEntity<List<Map>> listResponses = client.get().uri(listUrl).retrieve().toEntityList(Map.class).block();//restTemplate.getForEntity(listUrl, Map[].class);
|
||||
ResponseEntity<List<Map>> listResponses = client.get().uri(listUrl).retrieve().toEntityList(Map.class).block();
|
||||
createResponse = listResponses.getBody().get(0);
|
||||
metadata = (LinkedHashMap<String, String>) createResponse.get("metadata");
|
||||
links = (LinkedHashMap<String, String>) createResponse.get("links");
|
||||
|
|
|
@ -6,17 +6,16 @@ import com.fasterxml.jackson.databind.DeserializationFeature;
|
|||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import eu.eudat.depositinterface.enums.FieldType;
|
||||
import eu.eudat.depositinterface.models.*;
|
||||
import eu.eudat.depositinterface.zenodorepository.config.ConfigLoader;
|
||||
import eu.eudat.depositinterface.zenodorepository.config.DOIFunder;
|
||||
import eu.eudat.depositinterface.zenodorepository.config.PidFieldNames;
|
||||
import eu.eudat.depositinterface.zenodorepository.config.ZenodoConfig;
|
||||
import eu.eudat.depositinterface.zenodorepository.configuration.funder.FunderProperties;
|
||||
import eu.eudat.depositinterface.zenodorepository.configuration.identifier.IdentifierProperties;
|
||||
import eu.eudat.depositinterface.zenodorepository.configuration.pid.PidProperties;
|
||||
import eu.eudat.depositinterface.zenodorepository.configuration.zenodo.ZenodoProperties;
|
||||
import eu.eudat.depositinterface.zenodorepository.models.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -27,20 +26,22 @@ public class DMPToZenodoMapper {
|
|||
private static final Logger logger = LoggerFactory.getLogger(DMPToZenodoMapper.class);
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
private static ConfigLoader configLoader;
|
||||
private static PidFieldNames pidFieldNames;
|
||||
private final PidProperties pidProperties;
|
||||
private final IdentifierProperties identifierProperties;
|
||||
private final FunderProperties funderProperties;
|
||||
|
||||
@Autowired
|
||||
public DMPToZenodoMapper(ConfigLoader configL){
|
||||
configLoader = configL;
|
||||
pidFieldNames = configLoader.getPidFieldNames();
|
||||
public DMPToZenodoMapper(PidProperties pidProperties, IdentifierProperties identifierProperties, FunderProperties funderProperties){
|
||||
this.pidProperties = pidProperties;
|
||||
this.identifierProperties = identifierProperties;
|
||||
this.funderProperties = funderProperties;
|
||||
}
|
||||
|
||||
private static List<DatasetFieldsDepositModel> findSchemanticValues(String relatedId, List<DatasetFieldsDepositModel> fields){
|
||||
private List<DatasetFieldsDepositModel> findSchemanticValues(String relatedId, List<DatasetFieldsDepositModel> fields){
|
||||
return fields.stream().filter(f -> f.getSchematics().contains(relatedId)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private static Set<String> extractSchemanticValues(List<DatasetFieldsDepositModel> fields, List<String> acceptedPidTypes) throws JsonProcessingException{
|
||||
private Set<String> extractSchemanticValues(List<DatasetFieldsDepositModel> fields, List<String> acceptedPidTypes) throws JsonProcessingException{
|
||||
Set<String> values = new HashSet<>();
|
||||
for(DatasetFieldsDepositModel field: fields){
|
||||
String value = (String) field.getValue();
|
||||
|
@ -74,8 +75,8 @@ public class DMPToZenodoMapper {
|
|||
List<String> selected = objectMapper.readValue(value, new TypeReference<List<String>>() {});
|
||||
for (String s : selected) {
|
||||
Map<String, String> valueMap = objectMapper.readValue(s, new TypeReference<Map<String, String>>() {});
|
||||
String pid = valueMap.get(pidFieldNames.getPidName());
|
||||
String pidType = valueMap.get(pidFieldNames.getPidTypeName());
|
||||
String pid = valueMap.get(this.pidProperties.getFields().getPidName());
|
||||
String pidType = valueMap.get(this.pidProperties.getFields().getPidTypeName());
|
||||
if (acceptedPidTypes.contains(pidType)) {
|
||||
values.add(pid);
|
||||
}
|
||||
|
@ -83,8 +84,8 @@ public class DMPToZenodoMapper {
|
|||
}
|
||||
else {
|
||||
Map<String, String> valueMap = objectMapper.readValue(value, new TypeReference<Map<String, String>>() {});
|
||||
String pid = valueMap.get(pidFieldNames.getPidName());
|
||||
String pidType = valueMap.get(pidFieldNames.getPidTypeName());
|
||||
String pid = valueMap.get(this.pidProperties.getFields().getPidName());
|
||||
String pidType = valueMap.get(this.pidProperties.getFields().getPidTypeName());
|
||||
if (acceptedPidTypes.contains(pidType)) {
|
||||
values.add(pid);
|
||||
}
|
||||
|
@ -120,7 +121,7 @@ public class DMPToZenodoMapper {
|
|||
return values;
|
||||
}
|
||||
|
||||
public static ZenodoDeposit fromDMP(DMPDepositModel dmp, ZenodoConfig zenodoConfig) throws JsonProcessingException {
|
||||
public ZenodoDeposit fromDMP(DMPDepositModel dmp, ZenodoProperties.ZenodoConfig zenodoConfig) throws JsonProcessingException {
|
||||
Map<String, Object> extraProperties = dmp.getExtraProperties() != null ? new org.json.JSONObject(dmp.getExtraProperties()).toMap() : new HashMap<>();
|
||||
ZenodoDeposit deposit = new ZenodoDeposit();
|
||||
|
||||
|
@ -134,11 +135,11 @@ public class DMPToZenodoMapper {
|
|||
List<String> keywords = new ArrayList<>();
|
||||
List<String> references = new ArrayList<>();
|
||||
|
||||
List<String> acceptedPidTypes = configLoader.getAcceptedPidTypes();
|
||||
List<String> acceptedPidTypes = this.pidProperties.getAcceptedTypes();
|
||||
|
||||
for(DatasetDepositModel dataset: dmp.getDatasets()){
|
||||
|
||||
for(String relatedId: configLoader.getRelatedIdentifiers()){
|
||||
for(String relatedId: this.identifierProperties.getRelated()){
|
||||
|
||||
List<DatasetFieldsDepositModel> fields = findSchemanticValues(relatedId, dataset.getFields());
|
||||
Set<String> values = extractSchemanticValues(fields, acceptedPidTypes);
|
||||
|
@ -241,19 +242,13 @@ public class DMPToZenodoMapper {
|
|||
String grantReferenceHead = dmp.getGrant().getReference().split(":")[0];
|
||||
if (grantReferenceHead.equals("openaire")) {
|
||||
String grantReferenceTail = dmp.getGrant().getReference().split(":")[3];
|
||||
List<DOIFunder> doiFunders = new ArrayList<>();
|
||||
try {
|
||||
List<Map<String, Object>> tempdoiFunders = objectMapper.readValue(configLoader.getStreamFromPath(zenodoConfig.getDoiFunder()), List.class);
|
||||
doiFunders = tempdoiFunders.stream().map(map -> objectMapper.convertValue(map, DOIFunder.class)).collect(Collectors.toList());
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getLocalizedMessage(), e);
|
||||
}
|
||||
List<FunderProperties.DOIFunder> doiFunders = this.funderProperties.getAvailable();
|
||||
if (dmp.getGrant().getFunder() != null && dmp.getGrant().getFunder().getLabel() != null) {
|
||||
DOIFunder doiFunder = doiFunders.stream()
|
||||
FunderProperties.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;
|
||||
String finalId = doiFunder.getDoi() + "::" + grantReferenceTail;
|
||||
ZenodoGrant grant = new ZenodoGrant();
|
||||
grant.setId(finalId);
|
||||
deposit.getMetadata().getGrants().add(grant);
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
]
|
|
@ -1,43 +0,0 @@
|
|||
actrn
|
||||
ark
|
||||
bibcode
|
||||
nct
|
||||
drks
|
||||
doi
|
||||
euctr
|
||||
data.europa.eu
|
||||
epo_id
|
||||
GRID
|
||||
gsk
|
||||
GeoPass
|
||||
GBIF
|
||||
hal
|
||||
handle
|
||||
isrctn
|
||||
ichushi
|
||||
ISNI
|
||||
jprn
|
||||
mag_id
|
||||
NAID
|
||||
NCID
|
||||
oai
|
||||
orcid_pending
|
||||
orcid
|
||||
OrgPeg
|
||||
PANGAEA
|
||||
PIC
|
||||
epo_nr_epodoc
|
||||
pdb
|
||||
pmc
|
||||
pmid
|
||||
RNSR
|
||||
ROR
|
||||
RRID
|
||||
UNKNOWN
|
||||
VIAF
|
||||
who
|
||||
arXiv
|
||||
info:eu-repo/dai
|
||||
orcidworkid
|
||||
urn
|
||||
w3id
|
|
@ -1,2 +0,0 @@
|
|||
zenodo_plugin.storage.temp=${STORAGE_TMP_ZENODO}
|
||||
zenodo_plugin.configuration.zenodo=${CONFIGURATION_ZENODO}
|
|
@ -0,0 +1,10 @@
|
|||
spring:
|
||||
jackson:
|
||||
default-property-inclusion: non_null
|
||||
config:
|
||||
import: optional:classpath:config/app.env[.properties], optional:file:../config/app.env[.properties],
|
||||
optional:classpath:config/server.yml[.yml], optional:classpath:config/server-${spring.profiles.active}.yml[.yml], optional:file:../config/server-${spring.profiles.active}.yml[.yml],
|
||||
optional:classpath:config/zenodo.yml[.yml], optional:classpath:config/zenodo-${spring.profiles.active}.yml[.yml], optional:file:../config/zenodo-${spring.profiles.active}.yml[.yml],
|
||||
optional:classpath:config/pid.yml[.yml], optional:classpath:config/pid-${spring.profiles.active}.yml[.yml], optional:file:../config/pid-${spring.profiles.active}.yml[.yml],
|
||||
optional:classpath:config/funder.yml[.yml], optional:classpath:config/funder-${spring.profiles.active}.yml[.yml], optional:file:../config/funder-${spring.profiles.active}.yml[.yml],
|
||||
optional:classpath:config/identifiers.yml[.yml], optional:classpath:config/identifiers-${spring.profiles.active}.yml[.yml], optional:file:../config/identifiers-${spring.profiles.active}.yml[.yml]
|
|
@ -0,0 +1,34 @@
|
|||
funder:
|
||||
available:
|
||||
- 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"
|
|
@ -0,0 +1,34 @@
|
|||
identifiers:
|
||||
related:
|
||||
- zenodo.related_identifiers.isCitedBy
|
||||
- zenodo.related_identifiers.cites
|
||||
- zenodo.related_identifiers.isSupplementTo
|
||||
- zenodo.related_identifiers.isSupplementedBy
|
||||
- zenodo.related_identifiers.isContinuedBy
|
||||
- zenodo.related_identifiers.continues
|
||||
- zenodo.related_identifiers.isDescribedBy
|
||||
- zenodo.related_identifiers.describes
|
||||
- zenodo.related_identifiers.hasMetadata
|
||||
- zenodo.related_identifiers.isMetadataFor
|
||||
- zenodo.related_identifiers.isNewVersionOf
|
||||
- zenodo.related_identifiers.isPreviousVersionOf
|
||||
- zenodo.related_identifiers.isPartOf
|
||||
- zenodo.related_identifiers.hasPart
|
||||
- zenodo.related_identifiers.isReferencedBy
|
||||
- zenodo.related_identifiers.references
|
||||
- zenodo.related_identifiers.isDocumentedBy
|
||||
- zenodo.related_identifiers.documents
|
||||
- zenodo.related_identifiers.isCompiledBy
|
||||
- zenodo.related_identifiers.compiles
|
||||
- zenodo.related_identifiers.isVariantFormOf
|
||||
- zenodo.related_identifiers.isOriginalFormof
|
||||
- zenodo.related_identifiers.isIdenticalTo
|
||||
- zenodo.related_identifiers.isAlternateIdentifier
|
||||
- zenodo.related_identifiers.isReviewedBy
|
||||
- zenodo.related_identifiers.reviews
|
||||
- zenodo.related_identifiers.isDerivedFrom
|
||||
- zenodo.related_identifiers.isSourceOf
|
||||
- zenodo.related_identifiers.requires
|
||||
- zenodo.related_identifiers.isRequiredBy
|
||||
- zenodo.related_identifiers.isObsoletedBy
|
||||
- zenodo.related_identifiers.obsoletes
|
|
@ -0,0 +1,48 @@
|
|||
pid:
|
||||
fields:
|
||||
pid-name: pid
|
||||
pid-type-name: pidTypeField
|
||||
accepted-types:
|
||||
- actrn
|
||||
- ark
|
||||
- bibcode
|
||||
- nct
|
||||
- drks
|
||||
- doi
|
||||
- euctr
|
||||
- data.europa.eu
|
||||
- epo_id
|
||||
- GRID
|
||||
- gsk
|
||||
- GeoPass
|
||||
- GBIF
|
||||
- hal
|
||||
- handle
|
||||
- isrctn
|
||||
- ichushi
|
||||
- ISNI
|
||||
- jprn
|
||||
- mag_id
|
||||
- NAID
|
||||
- NCID
|
||||
- oai
|
||||
- orcid_pending
|
||||
- orcid
|
||||
- OrgPeg
|
||||
- PANGAEA
|
||||
- PIC
|
||||
- epo_nr_epodoc
|
||||
- pdb
|
||||
- pmc
|
||||
- pmid
|
||||
- RNSR
|
||||
- ROR
|
||||
- RRID
|
||||
- UNKNOWN
|
||||
- VIAF
|
||||
- who
|
||||
- arXiv
|
||||
- info:eu-repo/dai
|
||||
- orcidworkid
|
||||
- urn
|
||||
- w3id
|
|
@ -0,0 +1,12 @@
|
|||
server:
|
||||
port: 8082
|
||||
tomcat:
|
||||
threads:
|
||||
max: 20
|
||||
max-connections: 10000
|
||||
|
||||
spring:
|
||||
servlet:
|
||||
multipart:
|
||||
max-file-size: 10MB
|
||||
max-request-size: 10MB
|
|
@ -0,0 +1,18 @@
|
|||
zenodo:
|
||||
configuration:
|
||||
- deposit-type: 2
|
||||
repository-id: Zenodo
|
||||
access-token: ${ZENODO_ACCESS_TOKEN}
|
||||
repository-url: https://sandbox.zenodo.org/api/
|
||||
repository-authorization-url: https://sandbox.zenodo.org/oauth/authorize
|
||||
repository-record-url: https://sandbox.zenodo.org/record/
|
||||
repository-access-token-url: https://sandbox.zenodo.org/oauth/token
|
||||
repository-client-id:
|
||||
repository-client-secret:
|
||||
redirect-uri: http://localhost:4200/login/external/zenodo
|
||||
has-logo: true
|
||||
logo: classpath:zenodo.jpg
|
||||
doi-funder:
|
||||
community: argos
|
||||
affiliation: ARGOS
|
||||
domain: https://argos.openaire.eu/
|
|
@ -0,0 +1,3 @@
|
|||
zenodo:
|
||||
storage:
|
||||
temp: ${STORAGE_TMP_ZENODO}
|
|
@ -1,4 +0,0 @@
|
|||
{
|
||||
"pidName": "pid",
|
||||
"pidTypeName": "pidTypeField"
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
zenodo.related_identifiers.isCitedBy
|
||||
zenodo.related_identifiers.cites
|
||||
zenodo.related_identifiers.isSupplementTo
|
||||
zenodo.related_identifiers.isSupplementedBy
|
||||
zenodo.related_identifiers.isContinuedBy
|
||||
zenodo.related_identifiers.continues
|
||||
zenodo.related_identifiers.isDescribedBy
|
||||
zenodo.related_identifiers.describes
|
||||
zenodo.related_identifiers.hasMetadata
|
||||
zenodo.related_identifiers.isMetadataFor
|
||||
zenodo.related_identifiers.isNewVersionOf
|
||||
zenodo.related_identifiers.isPreviousVersionOf
|
||||
zenodo.related_identifiers.isPartOf
|
||||
zenodo.related_identifiers.hasPart
|
||||
zenodo.related_identifiers.isReferencedBy
|
||||
zenodo.related_identifiers.references
|
||||
zenodo.related_identifiers.isDocumentedBy
|
||||
zenodo.related_identifiers.documents
|
||||
zenodo.related_identifiers.isCompiledBy
|
||||
zenodo.related_identifiers.compiles
|
||||
zenodo.related_identifiers.isVariantFormOf
|
||||
zenodo.related_identifiers.isOriginalFormof
|
||||
zenodo.related_identifiers.isIdenticalTo
|
||||
zenodo.related_identifiers.isAlternateIdentifier
|
||||
zenodo.related_identifiers.isReviewedBy
|
||||
zenodo.related_identifiers.reviews
|
||||
zenodo.related_identifiers.isDerivedFrom
|
||||
zenodo.related_identifiers.isSourceOf
|
||||
zenodo.related_identifiers.requires
|
||||
zenodo.related_identifiers.isRequiredBy
|
||||
zenodo.related_identifiers.isObsoletedBy
|
||||
zenodo.related_identifiers.obsoletes
|
Loading…
Reference in New Issue