make doi_funder, community, affiliation, domain as config properties
This commit is contained in:
parent
1968334fdb
commit
ace8cf6189
|
@ -1,9 +1,10 @@
|
|||
package eu.eudat.depositinterface.zenodorepository.config;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
public interface ConfigLoader {
|
||||
List<DOIFunder> getDOIFunders();
|
||||
InputStream getStreamFromPath(String filePath);
|
||||
List<String> getRelatedIdentifiers();
|
||||
List<String> getAcceptedPidTypes();
|
||||
PidFieldNames getPidFieldNames();
|
||||
|
|
|
@ -19,7 +19,6 @@ 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 List<String> relatedIdentifiers = new ArrayList<>();
|
||||
private List<String> acceptedPidTypes = new ArrayList<>();
|
||||
private PidFieldNames pidFieldNames = new PidFieldNames();
|
||||
|
@ -32,19 +31,6 @@ public class ConfigLoaderImpl implements ConfigLoader{
|
|||
this.environment = environment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DOIFunder> getDOIFunders() {
|
||||
if (doiFunders == null || doiFunders.isEmpty()) {
|
||||
try {
|
||||
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());
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getLocalizedMessage(), e);
|
||||
}
|
||||
}
|
||||
return doiFunders;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getRelatedIdentifiers() {
|
||||
if (relatedIdentifiers == null || relatedIdentifiers.isEmpty()) {
|
||||
|
@ -112,7 +98,8 @@ public class ConfigLoaderImpl implements ConfigLoader{
|
|||
return null;
|
||||
}
|
||||
|
||||
private InputStream getStreamFromPath(String filePath) {
|
||||
@Override
|
||||
public InputStream getStreamFromPath(String filePath) {
|
||||
try {
|
||||
return new FileInputStream(filePath);
|
||||
} catch (FileNotFoundException e) {
|
||||
|
|
|
@ -56,6 +56,14 @@ public class ZenodoConfig {
|
|||
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;
|
||||
|
@ -141,6 +149,34 @@ public class ZenodoConfig {
|
|||
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);
|
||||
|
|
|
@ -58,7 +58,9 @@ public class ZenodoDeposit implements RepositoryDeposit {
|
|||
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);
|
||||
|
||||
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);
|
||||
|
||||
HttpEntity<eu.eudat.depositinterface.zenodorepository.models.ZenodoDeposit> request = new HttpEntity<>(deposit, headers);
|
||||
Map createResponse;
|
||||
|
|
|
@ -9,13 +9,14 @@ 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.models.*;
|
||||
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.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -27,15 +28,12 @@ public class DMPToZenodoMapper {
|
|||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
private static ConfigLoader configLoader;
|
||||
private static Environment environment;
|
||||
|
||||
private static PidFieldNames pidFieldNames;
|
||||
|
||||
@Autowired
|
||||
public DMPToZenodoMapper(ConfigLoader configL, Environment env){
|
||||
public DMPToZenodoMapper(ConfigLoader configL){
|
||||
configLoader = configL;
|
||||
pidFieldNames = configLoader.getPidFieldNames();
|
||||
environment = env;
|
||||
}
|
||||
|
||||
private static List<DatasetFieldsDepositModel> findSchemanticValues(String relatedId, List<DatasetFieldsDepositModel> fields){
|
||||
|
@ -122,7 +120,7 @@ public class DMPToZenodoMapper {
|
|||
return values;
|
||||
}
|
||||
|
||||
public static ZenodoDeposit fromDMP(DMPDepositModel dmp) throws JsonProcessingException {
|
||||
public static ZenodoDeposit fromDMP(DMPDepositModel dmp, ZenodoConfig zenodoConfig) throws JsonProcessingException {
|
||||
Map<String, Object> extraProperties = dmp.getExtraProperties() != null ? new org.json.JSONObject(dmp.getExtraProperties()).toMap() : new HashMap<>();
|
||||
ZenodoDeposit deposit = new ZenodoDeposit();
|
||||
|
||||
|
@ -171,7 +169,7 @@ public class DMPToZenodoMapper {
|
|||
deposit.getMetadata().setPublicationType("datamanagementplan");
|
||||
deposit.getMetadata().setDescription((dmp.getDescription() != null && !dmp.getDescription().isEmpty() ? dmp.getDescription() : "<p></p>"));
|
||||
deposit.getMetadata().setVersion(String.valueOf(dmp.getVersion()));
|
||||
String zenodoCommunity = environment.getProperty("zenodo_plugin.zenodo.community");
|
||||
String zenodoCommunity = zenodoConfig.getCommunity();
|
||||
if(zenodoCommunity != null && !zenodoCommunity.isEmpty()) {
|
||||
ZenodoComunity community = new ZenodoComunity();
|
||||
community.setIdentifier(zenodoCommunity);
|
||||
|
@ -200,11 +198,11 @@ public class DMPToZenodoMapper {
|
|||
}
|
||||
if (dmp.isPublic()) {
|
||||
ZenodoRelator relator = new ZenodoRelator();
|
||||
relator.setIdentifier(environment.getProperty("zenodo_plugin.zenodo.domain") + "/external/zenodo/" + dmp.getId().toString());
|
||||
relator.setIdentifier(zenodoConfig.getDomain() + "/external/zenodo/" + dmp.getId().toString());
|
||||
relator.setRelation("isIdenticalTo");
|
||||
deposit.getMetadata().getRelatedIdentifiers().add(relator);
|
||||
}
|
||||
String zenodoAffiliation = environment.getProperty("zenodo_plugin.zenodo.affiliation");
|
||||
String zenodoAffiliation = zenodoConfig.getAffiliation();
|
||||
List<ZenodoContributor> contributors1 = dmp.getUsers().stream().map(userDMP -> {
|
||||
ZenodoContributor contributor = new ZenodoContributor();
|
||||
contributor.setName(userDMP.getUser().getName());
|
||||
|
@ -242,7 +240,14 @@ public class DMPToZenodoMapper {
|
|||
String grantReferenceHead = dmp.getGrant().getReference().split(":")[0];
|
||||
if (grantReferenceHead.equals("openaire")) {
|
||||
String grantReferenceTail = dmp.getGrant().getReference().split(":")[3];
|
||||
DOIFunder doiFunder = configLoader.getDOIFunders().stream()
|
||||
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);
|
||||
}
|
||||
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) {
|
||||
|
|
|
@ -1,6 +1,2 @@
|
|||
zenodo_plugin.configuration.doi_funder=${ZENODO_DOI_DUNDER}
|
||||
zenodo_plugin.storage.temp=${STORAGE_TMP_ZENODO}
|
||||
zenodo_plugin.configuration.zenodo=${CONFIGURATION_ZENODO}
|
||||
zenodo_plugin.zenodo.community=${ZENODO_COMMUNITY}
|
||||
zenodo_plugin.zenodo.affiliation=${ZENODO_AFFILIATION}
|
||||
zenodo_plugin.zenodo.domain=${ZENODO_OPENDMP_DOMAIN}
|
||||
zenodo_plugin.configuration.zenodo=${CONFIGURATION_ZENODO}
|
Loading…
Reference in New Issue