sync with new models
This commit is contained in:
parent
36892093bd
commit
c5570d15b7
|
@ -1,5 +1,6 @@
|
||||||
package eu.eudat.depositinterface.zenodorepository.configuration.zenodo;
|
package eu.eudat.depositinterface.zenodorepository.configuration.zenodo;
|
||||||
|
|
||||||
|
import eu.eudat.depositinterface.enums.DepositType;
|
||||||
import eu.eudat.depositinterface.repository.RepositoryDepositConfiguration;
|
import eu.eudat.depositinterface.repository.RepositoryDepositConfiguration;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.boot.context.properties.ConstructorBinding;
|
import org.springframework.boot.context.properties.ConstructorBinding;
|
||||||
|
@ -29,7 +30,7 @@ public class ZenodoProperties {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ZenodoConfig extends RepositoryDepositConfiguration {
|
public static class ZenodoConfig extends RepositoryDepositConfiguration {
|
||||||
private final int depositType;
|
private final DepositType depositType;
|
||||||
private final String repositoryId;
|
private final String repositoryId;
|
||||||
private final String accessToken;
|
private final String accessToken;
|
||||||
private final String repositoryUrl;
|
private final String repositoryUrl;
|
||||||
|
@ -47,7 +48,7 @@ public class ZenodoProperties {
|
||||||
private final String domain;
|
private final String domain;
|
||||||
|
|
||||||
@ConstructorBinding
|
@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) {
|
public ZenodoConfig(DepositType 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.depositType = depositType;
|
||||||
this.repositoryId = repositoryId;
|
this.repositoryId = repositoryId;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
|
@ -66,7 +67,7 @@ public class ZenodoProperties {
|
||||||
this.domain = domain;
|
this.domain = domain;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDepositType() {
|
public DepositType getDepositType() {
|
||||||
return depositType;
|
return depositType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
package eu.eudat.depositinterface.zenodorepository.enums;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
|
import eu.eudat.depositinterface.enums.EnumUtils;
|
||||||
|
import eu.eudat.depositinterface.enums.EnumValueProvider;
|
||||||
|
import eu.eudat.depositinterface.enums.FieldType;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public enum ZenodoAccessRight implements EnumValueProvider<String> {
|
||||||
|
RESTRICTED(Names.Restricted), EMBARGOED(Names.Embargoed), OPEN(Names.Open);
|
||||||
|
|
||||||
|
private final String value;
|
||||||
|
|
||||||
|
public static class Names {
|
||||||
|
public static final String Restricted = "restricted";
|
||||||
|
public static final String Embargoed = "embargoed";
|
||||||
|
public static final String Open = "open";
|
||||||
|
}
|
||||||
|
|
||||||
|
ZenodoAccessRight(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@JsonValue
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Map<String, ZenodoAccessRight> map = EnumUtils.getEnumValueMap(ZenodoAccessRight.class);
|
||||||
|
|
||||||
|
public static ZenodoAccessRight of(String i) {
|
||||||
|
return map.get(i);
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,18 +2,21 @@ package eu.eudat.depositinterface.zenodorepository.mapper;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import eu.eudat.depositinterface.enums.FieldType;
|
import eu.eudat.depositinterface.enums.DmpAccessType;
|
||||||
|
import eu.eudat.depositinterface.enums.DmpUserRole;
|
||||||
|
import eu.eudat.depositinterface.enums.ReferenceType;
|
||||||
import eu.eudat.depositinterface.models.*;
|
import eu.eudat.depositinterface.models.*;
|
||||||
|
import eu.eudat.depositinterface.models.reference.FieldDepositModel;
|
||||||
import eu.eudat.depositinterface.zenodorepository.configuration.funder.FunderProperties;
|
import eu.eudat.depositinterface.zenodorepository.configuration.funder.FunderProperties;
|
||||||
import eu.eudat.depositinterface.zenodorepository.configuration.identifier.IdentifierProperties;
|
import eu.eudat.depositinterface.zenodorepository.configuration.identifier.IdentifierProperties;
|
||||||
import eu.eudat.depositinterface.zenodorepository.configuration.pid.PidProperties;
|
import eu.eudat.depositinterface.zenodorepository.configuration.pid.PidProperties;
|
||||||
import eu.eudat.depositinterface.zenodorepository.configuration.zenodo.ZenodoProperties;
|
import eu.eudat.depositinterface.zenodorepository.configuration.zenodo.ZenodoProperties;
|
||||||
import eu.eudat.depositinterface.zenodorepository.models.*;
|
import eu.eudat.depositinterface.zenodorepository.enums.ZenodoAccessRight;
|
||||||
import org.slf4j.Logger;
|
import eu.eudat.depositinterface.zenodorepository.model.*;
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||||
|
import org.springframework.context.annotation.Scope;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
@ -21,32 +24,58 @@ import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class DMPToZenodoMapper {
|
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||||
|
public class ZenodoBuilderMapper {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(DMPToZenodoMapper.class);
|
|
||||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
|
||||||
|
|
||||||
private final PidProperties pidProperties;
|
private final PidProperties pidProperties;
|
||||||
private final IdentifierProperties identifierProperties;
|
private final IdentifierProperties identifierProperties;
|
||||||
private final FunderProperties funderProperties;
|
private final FunderProperties funderProperties;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public DMPToZenodoMapper(PidProperties pidProperties, IdentifierProperties identifierProperties, FunderProperties funderProperties){
|
public ZenodoBuilderMapper(PidProperties pidProperties, IdentifierProperties identifierProperties, FunderProperties funderProperties){
|
||||||
this.pidProperties = pidProperties;
|
this.pidProperties = pidProperties;
|
||||||
this.identifierProperties = identifierProperties;
|
this.identifierProperties = identifierProperties;
|
||||||
this.funderProperties = funderProperties;
|
this.funderProperties = funderProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ZenodoDeposit build(DmpDepositModel dmp, ZenodoProperties.ZenodoConfig zenodoConfig) throws JsonProcessingException {
|
||||||
|
ZenodoDeposit deposit = new ZenodoDeposit();
|
||||||
|
this.applyZenodoRelator(dmp, deposit);
|
||||||
|
deposit.getMetadata().setTitle(dmp.getLabel());
|
||||||
|
deposit.getMetadata().setUploadType("publication");
|
||||||
|
deposit.getMetadata().setPublicationType("datamanagementplan");
|
||||||
|
deposit.getMetadata().setDescription((dmp.getDescription() != null && !dmp.getDescription().isEmpty() ? dmp.getDescription() : "<p></p>"));
|
||||||
|
deposit.getMetadata().setVersion(String.valueOf(dmp.getVersion()));
|
||||||
|
String zenodoCommunity = zenodoConfig.getCommunity();
|
||||||
|
if(zenodoCommunity != null && !zenodoCommunity.isEmpty()) {
|
||||||
|
ZenodoComunity community = new ZenodoComunity();
|
||||||
|
community.setIdentifier(zenodoCommunity);
|
||||||
|
deposit.getMetadata().getCommunities().add(community);
|
||||||
|
}
|
||||||
|
this.applyAccessRight(dmp, deposit);
|
||||||
|
this.applyIsIdenticalTo(dmp, deposit, zenodoConfig);
|
||||||
|
this.applyLicenses(dmp, deposit);
|
||||||
|
this.applyResearchers(dmp, deposit);
|
||||||
|
this.applyGrants(dmp, deposit);
|
||||||
|
this.applyContributors(dmp, deposit, zenodoConfig);
|
||||||
|
this.applyCreators(dmp, deposit, zenodoConfig);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return deposit;
|
||||||
|
}
|
||||||
|
|
||||||
private 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());
|
return fields.stream().filter(f -> f.getSchematics().contains(relatedId)).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set<String> extractSchemanticValues(List<DatasetFieldsDepositModel> fields, List<String> acceptedPidTypes) throws JsonProcessingException{
|
private Set<String> extractSchematicValues(List<DatasetFieldsDepositModel> fields, List<String> acceptedPidTypes) throws JsonProcessingException{
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
Set<String> values = new HashSet<>();
|
Set<String> values = new HashSet<>();
|
||||||
for(DatasetFieldsDepositModel field: fields){
|
for(DatasetFieldsDepositModel field: fields){
|
||||||
String value = (String) field.getValue();
|
String value = (String) field.getValue();
|
||||||
if(value != null && !value.isEmpty()) {
|
if(value != null && !value.isEmpty()) {
|
||||||
switch (FieldType.fromName(field.getRenderStyleType())) {
|
switch (field.getFieldType()) {
|
||||||
case FREE_TEXT:
|
case FREE_TEXT:
|
||||||
case TEXT_AREA:
|
case TEXT_AREA:
|
||||||
case RICH_TEXT_AREA:
|
case RICH_TEXT_AREA:
|
||||||
|
@ -54,7 +83,8 @@ public class DMPToZenodoMapper {
|
||||||
case DATE_PICKER:
|
case DATE_PICKER:
|
||||||
values.add(value);
|
values.add(value);
|
||||||
break;
|
break;
|
||||||
case COMBO_BOX:
|
case AUTO_COMPLETE:
|
||||||
|
case WORD_LIST:
|
||||||
if (field.isMultiple()) {
|
if (field.isMultiple()) {
|
||||||
List<String> selected = objectMapper.readValue(value, new TypeReference<List<String>>() {});
|
List<String> selected = objectMapper.readValue(value, new TypeReference<List<String>>() {});
|
||||||
values.addAll(selected);
|
values.addAll(selected);
|
||||||
|
@ -63,7 +93,6 @@ public class DMPToZenodoMapper {
|
||||||
values.add(value);
|
values.add(value);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case REGISTRIES:
|
|
||||||
case SERVICES:
|
case SERVICES:
|
||||||
case EXTERNAL_DATASETS:
|
case EXTERNAL_DATASETS:
|
||||||
case DATA_REPOSITORIES:
|
case DATA_REPOSITORIES:
|
||||||
|
@ -121,154 +150,184 @@ public class DMPToZenodoMapper {
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ZenodoDeposit fromDMP(DMPDepositModel dmp, ZenodoProperties.ZenodoConfig zenodoConfig) throws JsonProcessingException {
|
private List<ReferenceDepositModel> getReferenceDepositModelOfType(DmpDepositModel dmp, ReferenceType referenceType){
|
||||||
Map<String, Object> extraProperties = dmp.getExtraProperties() != null ? new org.json.JSONObject(dmp.getExtraProperties()).toMap() : new HashMap<>();
|
if (dmp.getReferences() == null) return new ArrayList<>();
|
||||||
ZenodoDeposit deposit = new ZenodoDeposit();
|
return dmp.getReferences().stream().filter(x -> x.getType().equals(referenceType)).toList();
|
||||||
|
}
|
||||||
|
|
||||||
Map<String, Object> schematicsMap = new HashMap<>();
|
private void applyZenodoRelator(DmpDepositModel dmp, ZenodoDeposit deposit) throws JsonProcessingException {
|
||||||
|
if (deposit.getMetadata() == null) deposit.setMetadata(new ZenodoDepositMetadata());
|
||||||
List<ZenodoRelator> relatedIdentifiers = new ArrayList<>();
|
|
||||||
List<ZenodoComunity> communities = new ArrayList<>();
|
|
||||||
List<ZenodoContributor> contributors = new ArrayList<>();
|
|
||||||
List<ZenodoCreator> creators = new ArrayList<>();
|
|
||||||
List<ZenodoGrant> grants = new ArrayList<>();
|
|
||||||
List<String> keywords = new ArrayList<>();
|
|
||||||
List<String> references = new ArrayList<>();
|
|
||||||
|
|
||||||
List<String> acceptedPidTypes = this.pidProperties.getAcceptedTypes();
|
List<String> acceptedPidTypes = this.pidProperties.getAcceptedTypes();
|
||||||
|
List<ZenodoRelator> relatedIdentifiers = new ArrayList<>();
|
||||||
for(DatasetDepositModel dataset: dmp.getDatasets()){
|
for(DescriptionDepositModel descriptionDepositModel: dmp.getDescriptions()){
|
||||||
|
|
||||||
for(String relatedId: this.identifierProperties.getRelated()){
|
for(String relatedId: this.identifierProperties.getRelated()){
|
||||||
|
List<DatasetFieldsDepositModel> fields = findSchemanticValues(relatedId, descriptionDepositModel.getFields());
|
||||||
List<DatasetFieldsDepositModel> fields = findSchemanticValues(relatedId, dataset.getFields());
|
Set<String> values = extractSchematicValues(fields, acceptedPidTypes);
|
||||||
Set<String> values = extractSchemanticValues(fields, acceptedPidTypes);
|
|
||||||
for(String value: values){
|
for(String value: values){
|
||||||
ZenodoRelator relator = new ZenodoRelator();
|
ZenodoRelator relator = new ZenodoRelator();
|
||||||
relator.setRelation(relatedId.substring(relatedId.lastIndexOf(".") + 1));
|
relator.setRelation(relatedId.substring(relatedId.lastIndexOf(".") + 1));
|
||||||
relator.setIdentifier(value);
|
relator.setIdentifier(value);
|
||||||
relatedIdentifiers.add(relator);
|
relatedIdentifiers.add(relator);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
schematicsMap.put("related_identifiers", relatedIdentifiers);
|
deposit.getMetadata().setRelatedIdentifiers(relatedIdentifiers);
|
||||||
schematicsMap.put("communities", communities);
|
|
||||||
schematicsMap.put("contributors", contributors);
|
|
||||||
schematicsMap.put("creators", creators);
|
|
||||||
schematicsMap.put("grants", grants);
|
|
||||||
schematicsMap.put("keywords", keywords);
|
|
||||||
schematicsMap.put("references", references);
|
|
||||||
|
|
||||||
String schematicsString = objectMapper.writeValueAsString(schematicsMap);
|
|
||||||
objectMapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
|
|
||||||
ZenodoDepositMetadata metadata = objectMapper.readValue(schematicsString, new TypeReference<ZenodoDepositMetadata>(){});
|
|
||||||
|
|
||||||
deposit.setMetadata(metadata);
|
|
||||||
deposit.getMetadata().setTitle(dmp.getLabel());
|
|
||||||
deposit.getMetadata().setUploadType("publication");
|
|
||||||
deposit.getMetadata().setPublicationType("datamanagementplan");
|
|
||||||
deposit.getMetadata().setDescription((dmp.getDescription() != null && !dmp.getDescription().isEmpty() ? dmp.getDescription() : "<p></p>"));
|
|
||||||
deposit.getMetadata().setVersion(String.valueOf(dmp.getVersion()));
|
|
||||||
String zenodoCommunity = zenodoConfig.getCommunity();
|
|
||||||
if(zenodoCommunity != null && !zenodoCommunity.isEmpty()) {
|
|
||||||
ZenodoComunity community = new ZenodoComunity();
|
|
||||||
community.setIdentifier(zenodoCommunity);
|
|
||||||
deposit.getMetadata().getCommunities().add(community);
|
|
||||||
}
|
}
|
||||||
if (extraProperties.get("visible") == null) {
|
|
||||||
|
private void applyAccessRight(DmpDepositModel dmp, ZenodoDeposit deposit){
|
||||||
|
if (deposit.getMetadata() == null) deposit.setMetadata(new ZenodoDepositMetadata());
|
||||||
|
|
||||||
|
if (dmp.getAccessType() == null) {
|
||||||
deposit.getMetadata().setAccessRight(ZenodoAccessRight.RESTRICTED);
|
deposit.getMetadata().setAccessRight(ZenodoAccessRight.RESTRICTED);
|
||||||
deposit.getMetadata().setAccessConditions("");
|
deposit.getMetadata().setAccessConditions("");
|
||||||
} else {
|
} else {
|
||||||
if (((Boolean) extraProperties.get("visible"))) {
|
if (dmp.getAccessType().equals(DmpAccessType.Public)) {
|
||||||
Instant publicationDate = Instant.parse(extraProperties.get("publicDate").toString());
|
Instant publicationDate = dmp.getFinalizedAt();
|
||||||
|
if (publicationDate == null) publicationDate = Instant.now().minusSeconds(1);
|
||||||
|
|
||||||
if (publicationDate.isBefore(Instant.now())) {
|
if (publicationDate.isBefore(Instant.now())) {
|
||||||
deposit.getMetadata().setAccessRight(ZenodoAccessRight.OPEN);
|
deposit.getMetadata().setAccessRight(ZenodoAccessRight.OPEN);
|
||||||
} else {
|
} else {
|
||||||
deposit.getMetadata().setAccessRight(ZenodoAccessRight.EMBARGOED);
|
deposit.getMetadata().setAccessRight(ZenodoAccessRight.EMBARGOED);
|
||||||
deposit.getMetadata().setEmbargoDate(publicationDate.toString());
|
deposit.getMetadata().setEmbargoDate(publicationDate.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (extraProperties.get("license") != null) {
|
|
||||||
deposit.getMetadata().setLicense(((Map<?, ?>) extraProperties.get("license")).get("pid").toString());
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
deposit.getMetadata().setAccessRight(ZenodoAccessRight.RESTRICTED);
|
deposit.getMetadata().setAccessRight(ZenodoAccessRight.RESTRICTED);
|
||||||
deposit.getMetadata().setAccessConditions("");
|
deposit.getMetadata().setAccessConditions("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (dmp.isPublic()) {
|
}
|
||||||
|
|
||||||
|
private void applyIsIdenticalTo(DmpDepositModel dmp, ZenodoDeposit deposit, ZenodoProperties.ZenodoConfig zenodoConfig){
|
||||||
|
if (deposit.getMetadata() == null) deposit.setMetadata(new ZenodoDepositMetadata());
|
||||||
|
|
||||||
|
if (dmp.getAccessType().equals(DmpAccessType.Public)) {
|
||||||
ZenodoRelator relator = new ZenodoRelator();
|
ZenodoRelator relator = new ZenodoRelator();
|
||||||
relator.setIdentifier(zenodoConfig.getDomain() + "/external/zenodo/" + dmp.getId().toString());
|
relator.setIdentifier(zenodoConfig.getDomain() + "/external/zenodo/" + dmp.getId().toString());
|
||||||
relator.setRelation("isIdenticalTo");
|
relator.setRelation("isIdenticalTo");
|
||||||
|
if (deposit.getMetadata().getRelatedIdentifiers() == null)deposit.getMetadata().setRelatedIdentifiers(new ArrayList<>());
|
||||||
deposit.getMetadata().getRelatedIdentifiers().add(relator);
|
deposit.getMetadata().getRelatedIdentifiers().add(relator);
|
||||||
}
|
}
|
||||||
String zenodoAffiliation = zenodoConfig.getAffiliation();
|
|
||||||
List<ZenodoContributor> contributors1 = dmp.getUsers().stream().map(userDMP -> {
|
|
||||||
ZenodoContributor contributor = new ZenodoContributor();
|
|
||||||
contributor.setName(userDMP.getUser().getName());
|
|
||||||
contributor.setType("ProjectMember");
|
|
||||||
if (dmp.getOrganisations() != null && !dmp.getOrganisations().isEmpty()) {
|
|
||||||
contributor.setAffiliation(dmp.getOrganisations()
|
|
||||||
.stream().map(OrganisationDepositModel::getLabel).collect(Collectors.joining(", ")));
|
|
||||||
} else {
|
|
||||||
if(zenodoAffiliation != null && !zenodoAffiliation.isEmpty()) {
|
|
||||||
contributor.setAffiliation(zenodoAffiliation);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return contributor;
|
|
||||||
}).collect(Collectors.toList());
|
|
||||||
|
|
||||||
List<ZenodoContributor> researchers = dmp.getResearchers().stream().map(researcher -> {
|
private void applyLicenses(DmpDepositModel dmp, ZenodoDeposit deposit){
|
||||||
|
if (deposit.getMetadata() == null) deposit.setMetadata(new ZenodoDepositMetadata());
|
||||||
|
|
||||||
|
List<ReferenceDepositModel> dmpLicenses = this.getReferenceDepositModelOfType(dmp, ReferenceType.Licenses);
|
||||||
|
if (dmpLicenses != null && !dmpLicenses.isEmpty()) {
|
||||||
|
for (ReferenceDepositModel dmpLicense : dmpLicenses) {
|
||||||
|
String pid = dmpLicense.getDefinition().getFields().stream().filter(x-> "pid".equalsIgnoreCase(x.getCode())).map(FieldDepositModel::getValue).findFirst().orElse(null);
|
||||||
|
if (pid != null && !pid.isBlank()) {
|
||||||
|
deposit.getMetadata().setLicense(pid);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applyResearchers(DmpDepositModel dmp, ZenodoDeposit deposit){
|
||||||
|
if (deposit.getMetadata() == null) deposit.setMetadata(new ZenodoDepositMetadata());
|
||||||
|
|
||||||
|
List<ZenodoContributor> researchers = new ArrayList<>();
|
||||||
|
List<ReferenceDepositModel> dmpResearchers = this.getReferenceDepositModelOfType(dmp, ReferenceType.Researcher);
|
||||||
|
if (dmpResearchers != null && !dmpResearchers.isEmpty()) {
|
||||||
|
for (ReferenceDepositModel researcher : dmpResearchers) {
|
||||||
ZenodoContributor contributor = new ZenodoContributor();
|
ZenodoContributor contributor = new ZenodoContributor();
|
||||||
contributor.setName(researcher.getLabel());
|
contributor.setName(researcher.getLabel());
|
||||||
contributor.setType("Researcher");
|
contributor.setType("Researcher");
|
||||||
String referenceHead = researcher.getReference().split(":")[0];
|
contributor.setAffiliation(researcher.getSource());
|
||||||
String referenceTail = researcher.getReference().replace(referenceHead + ":", "");
|
if (researcher.getSource().equalsIgnoreCase("ORCID")) {
|
||||||
contributor.setAffiliation(referenceHead);
|
contributor.setOrcid(researcher.getReference());
|
||||||
if (referenceHead.equalsIgnoreCase("ORCID")) {
|
}
|
||||||
contributor.setOrcid(referenceTail);
|
researchers.add(contributor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return contributor;
|
|
||||||
}).collect(Collectors.toList());
|
|
||||||
|
|
||||||
deposit.getMetadata().getContributors().addAll(contributors1);
|
if (deposit.getMetadata().getContributors() == null)deposit.getMetadata().setContributors(new ArrayList<>());
|
||||||
|
|
||||||
deposit.getMetadata().getContributors().addAll(researchers);
|
deposit.getMetadata().getContributors().addAll(researchers);
|
||||||
|
|
||||||
if (dmp.getGrant() != null) {
|
|
||||||
if (dmp.getGrant().getReference() == null) {
|
|
||||||
dmp.getGrant().setReference("dmp:" + dmp.getGrant().getId());
|
|
||||||
}
|
}
|
||||||
String grantReferenceHead = dmp.getGrant().getReference().split(":")[0];
|
|
||||||
if (grantReferenceHead.equals("openaire")) {
|
private void applyGrants(DmpDepositModel dmp, ZenodoDeposit deposit){
|
||||||
String grantReferenceTail = dmp.getGrant().getReference().split(":")[3];
|
if (deposit.getMetadata() == null) deposit.setMetadata(new ZenodoDepositMetadata());
|
||||||
|
List<ReferenceDepositModel> dmpGrants = this.getReferenceDepositModelOfType(dmp, ReferenceType.Grants);
|
||||||
|
List<ReferenceDepositModel> dmpFunders = this.getReferenceDepositModelOfType(dmp, ReferenceType.Funder);
|
||||||
|
|
||||||
|
|
||||||
|
if (dmpGrants != null && !dmpGrants.isEmpty()) {
|
||||||
|
ReferenceDepositModel depositGrant = dmpGrants.stream().filter(x-> x.getSource().equals("openaire")).findFirst().orElse(null);
|
||||||
|
|
||||||
|
if (depositGrant != null) {
|
||||||
|
String grantReferenceTail = depositGrant.getReference().split(":")[2];
|
||||||
List<FunderProperties.DOIFunder> doiFunders = this.funderProperties.getAvailable();
|
List<FunderProperties.DOIFunder> doiFunders = this.funderProperties.getAvailable();
|
||||||
if (dmp.getGrant().getFunder() != null && dmp.getGrant().getFunder().getLabel() != null) {
|
if (dmpFunders != null && !dmpFunders.isEmpty()) {
|
||||||
|
ReferenceDepositModel depositFunder = dmpFunders.get(0);
|
||||||
FunderProperties.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()))
|
.filter(doiFunder1 -> depositFunder.getLabel().contains(doiFunder1.getFunder()) || doiFunder1.getFunder().contains(depositFunder.getLabel()))
|
||||||
.findFirst().orElse(null);
|
.findFirst().orElse(null);
|
||||||
if (doiFunder != null) {
|
if (doiFunder != null) {
|
||||||
String finalId = doiFunder.getDoi() + "::" + grantReferenceTail;
|
String finalId = doiFunder.getDoi() + "::" + grantReferenceTail;
|
||||||
ZenodoGrant grant = new ZenodoGrant();
|
ZenodoGrant grant = new ZenodoGrant();
|
||||||
grant.setId(finalId);
|
grant.setId(finalId);
|
||||||
|
if (deposit.getMetadata().getGrants() == null)deposit.getMetadata().setGrants(new ArrayList<>());
|
||||||
deposit.getMetadata().getGrants().add(grant);
|
deposit.getMetadata().getGrants().add(grant);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applyContributors(DmpDepositModel dmp, ZenodoDeposit deposit, ZenodoProperties.ZenodoConfig zenodoConfig){
|
||||||
|
if (dmp.getUsers() == null) return;
|
||||||
|
|
||||||
|
if (deposit.getMetadata() == null) deposit.setMetadata(new ZenodoDepositMetadata());
|
||||||
|
|
||||||
|
List<ReferenceDepositModel> dmpOrganizations = this.getReferenceDepositModelOfType(dmp, ReferenceType.Organizations);
|
||||||
|
String zenodoAffiliation = zenodoConfig.getAffiliation();
|
||||||
|
|
||||||
|
List<ZenodoContributor> contributors = new ArrayList<>();
|
||||||
|
for (UserDmpDepositModel userDMP: dmp.getUsers()) {
|
||||||
|
ZenodoContributor contributor = new ZenodoContributor();
|
||||||
|
contributor.setName(userDMP.getUser().getName());
|
||||||
|
contributor.setType("ProjectMember");
|
||||||
|
if (dmpOrganizations != null && !dmpOrganizations.isEmpty()) {
|
||||||
|
contributor.setAffiliation(dmpOrganizations.stream().map(ReferenceDepositModel::getLabel).collect(Collectors.joining(", ")));
|
||||||
|
} else {
|
||||||
|
if(zenodoAffiliation != null && !zenodoAffiliation.isEmpty()) {
|
||||||
|
contributor.setAffiliation(zenodoAffiliation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
contributors.add(contributor);
|
||||||
|
}
|
||||||
|
if (deposit.getMetadata().getContributors() == null)deposit.getMetadata().setContributors(new ArrayList<>());
|
||||||
|
|
||||||
|
deposit.getMetadata().getContributors().addAll(contributors);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applyCreators(DmpDepositModel dmp, ZenodoDeposit deposit, ZenodoProperties.ZenodoConfig zenodoConfig){
|
||||||
|
if (dmp.getUsers() == null) return;
|
||||||
|
|
||||||
|
if (deposit.getMetadata() == null) deposit.setMetadata(new ZenodoDepositMetadata());
|
||||||
|
|
||||||
|
List<ReferenceDepositModel> dmpOrganizations = this.getReferenceDepositModelOfType(dmp, ReferenceType.Organizations);
|
||||||
|
String zenodoAffiliation = zenodoConfig.getAffiliation();
|
||||||
|
|
||||||
ZenodoCreator creator = new ZenodoCreator();
|
ZenodoCreator creator = new ZenodoCreator();
|
||||||
creator.setName(dmp.getUsers().stream().filter(userDMP -> userDMP.getRole().equals(UserDMPDepositModel.UserDMPRoles.OWNER.getValue())).findFirst().get().getUser().getName());
|
UserDmpDepositModel dmpDepositModel = dmp.getUsers().stream().filter(userDMP -> userDMP.getRole().equals(DmpUserRole.Owner)).findFirst().orElse(null);
|
||||||
if (dmp.getOrganisations() != null && !dmp.getOrganisations().isEmpty()) {
|
if (dmpDepositModel == null || dmpDepositModel.getUser() == null) return;
|
||||||
creator.setAffiliation(dmp.getOrganisations()
|
|
||||||
.stream().map(OrganisationDepositModel::getLabel).collect(Collectors.joining(", ")));
|
creator.setName(dmpDepositModel.getUser().getName());
|
||||||
|
if (dmpOrganizations != null && !dmpOrganizations.isEmpty()) {
|
||||||
|
creator.setAffiliation(dmpOrganizations.stream().map(ReferenceDepositModel::getLabel).collect(Collectors.joining(", ")));
|
||||||
} else {
|
} else {
|
||||||
if(zenodoAffiliation != null && !zenodoAffiliation.isEmpty()) {
|
if(zenodoAffiliation != null && !zenodoAffiliation.isEmpty()) {
|
||||||
creator.setAffiliation(zenodoAffiliation);
|
creator.setAffiliation(zenodoAffiliation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (deposit.getMetadata().getCreators() == null)deposit.getMetadata().setCreators(new ArrayList<>());
|
||||||
deposit.getMetadata().getCreators().add(creator);
|
deposit.getMetadata().getCreators().add(creator);
|
||||||
|
|
||||||
return deposit;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package eu.eudat.depositinterface.zenodorepository.models;
|
package eu.eudat.depositinterface.zenodorepository.model;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
|
@ -1,4 +1,4 @@
|
||||||
package eu.eudat.depositinterface.zenodorepository.models;
|
package eu.eudat.depositinterface.zenodorepository.model;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
|
@ -1,4 +1,4 @@
|
||||||
package eu.eudat.depositinterface.zenodorepository.models;
|
package eu.eudat.depositinterface.zenodorepository.model;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
|
@ -1,4 +1,4 @@
|
||||||
package eu.eudat.depositinterface.zenodorepository.models;
|
package eu.eudat.depositinterface.zenodorepository.model;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
|
@ -1,8 +1,9 @@
|
||||||
package eu.eudat.depositinterface.zenodorepository.models;
|
package eu.eudat.depositinterface.zenodorepository.model;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import eu.eudat.depositinterface.zenodorepository.enums.ZenodoAccessRight;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package eu.eudat.depositinterface.zenodorepository.models;
|
package eu.eudat.depositinterface.zenodorepository.model;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
|
@ -1,4 +1,4 @@
|
||||||
package eu.eudat.depositinterface.zenodorepository.models;
|
package eu.eudat.depositinterface.zenodorepository.model;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
|
@ -1,18 +0,0 @@
|
||||||
package eu.eudat.depositinterface.zenodorepository.models;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonValue;
|
|
||||||
|
|
||||||
public enum ZenodoAccessRight {
|
|
||||||
RESTRICTED("restricted"), EMBARGOED("embargoed"), OPEN("open");
|
|
||||||
|
|
||||||
private final String value;
|
|
||||||
|
|
||||||
ZenodoAccessRight(String value) {
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@JsonValue
|
|
||||||
public String getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,12 +1,12 @@
|
||||||
package eu.eudat.depositinterface.zenodorepository.interfaces;
|
package eu.eudat.depositinterface.zenodorepository.service.zenodo;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import eu.eudat.depositinterface.models.DMPDepositModel;
|
import eu.eudat.depositinterface.models.DmpDepositModel;
|
||||||
import eu.eudat.depositinterface.models.FileEnvelope;
|
import eu.eudat.depositinterface.models.FileEnvelope;
|
||||||
import eu.eudat.depositinterface.repository.RepositoryDeposit;
|
import eu.eudat.depositinterface.repository.RepositoryDeposit;
|
||||||
import eu.eudat.depositinterface.repository.RepositoryDepositConfiguration;
|
import eu.eudat.depositinterface.repository.RepositoryDepositConfiguration;
|
||||||
import eu.eudat.depositinterface.zenodorepository.configuration.zenodo.ZenodoProperties;
|
import eu.eudat.depositinterface.zenodorepository.configuration.zenodo.ZenodoProperties;
|
||||||
import eu.eudat.depositinterface.zenodorepository.mapper.DMPToZenodoMapper;
|
import eu.eudat.depositinterface.zenodorepository.mapper.ZenodoBuilderMapper;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -23,36 +23,35 @@ import org.springframework.web.reactive.function.BodyInserters;
|
||||||
import org.springframework.web.reactive.function.client.WebClient;
|
import org.springframework.web.reactive.function.client.WebClient;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class ZenodoDeposit implements RepositoryDeposit {
|
public class ZenodoDepositService implements RepositoryDeposit {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(ZenodoDeposit.class);
|
private static final Logger logger = LoggerFactory.getLogger(ZenodoDepositService.class);
|
||||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
private final ZenodoProperties zenodoProperties;
|
private final ZenodoProperties zenodoProperties;
|
||||||
private final DMPToZenodoMapper mapper;
|
private final ZenodoBuilderMapper mapper;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public ZenodoDeposit(ZenodoProperties zenodoProperties, DMPToZenodoMapper mapper){
|
public ZenodoDepositService(ZenodoProperties zenodoProperties, ZenodoBuilderMapper mapper){
|
||||||
this.zenodoProperties = zenodoProperties;
|
this.zenodoProperties = zenodoProperties;
|
||||||
this.mapper = mapper;
|
this.mapper = mapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String deposit(String repositoryId, DMPDepositModel dmpDepositModel, String zenodoToken) throws Exception {
|
public String deposit(String repositoryId, DmpDepositModel dmpDepositModel, String zenodoToken) throws Exception {
|
||||||
|
|
||||||
RepositoryDepositConfiguration conf = this.getConfiguration().stream().filter(x -> x.getRepositoryId().equals(repositoryId)).findFirst().orElse(null);
|
RepositoryDepositConfiguration repositoryDepositConfiguration = this.getConfiguration().stream().filter(x -> x.getRepositoryId().equals(repositoryId)).findFirst().orElse(null);
|
||||||
|
|
||||||
if(conf != null) {
|
if(repositoryDepositConfiguration != null) {
|
||||||
|
|
||||||
if (zenodoToken == null || zenodoToken.isEmpty()) {
|
if (zenodoToken == null || zenodoToken.isEmpty()) {
|
||||||
zenodoToken = conf.getAccessToken();
|
zenodoToken = repositoryDepositConfiguration.getAccessToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
String zenodoUrl = conf.getRepositoryUrl();
|
String zenodoUrl = repositoryDepositConfiguration.getRepositoryUrl();
|
||||||
|
|
||||||
// First step, post call to Zenodo, to create the entry.
|
// First step, post call to Zenodo, to create the entry.
|
||||||
WebClient zenodoClient = WebClient.builder().build();
|
WebClient zenodoClient = WebClient.builder().build();
|
||||||
|
@ -61,7 +60,7 @@ public class ZenodoDeposit implements RepositoryDeposit {
|
||||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
|
||||||
ZenodoProperties.ZenodoConfig zenodoConfig = this.zenodoProperties.getConfiguration().stream().filter(x -> x.getRepositoryId().equals(repositoryId)).findFirst().orElse(null);
|
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);
|
eu.eudat.depositinterface.zenodorepository.model.ZenodoDeposit deposit = mapper.build(dmpDepositModel, zenodoConfig);
|
||||||
|
|
||||||
Map createResponse;
|
Map createResponse;
|
||||||
LinkedHashMap<String, String> links;
|
LinkedHashMap<String, String> links;
|
||||||
|
@ -143,20 +142,19 @@ public class ZenodoDeposit implements RepositoryDeposit {
|
||||||
String addFileUrl = links.get("bucket") + "/" + pdfEnvelope.getFilename() + "?access_token=" + zenodoToken;
|
String addFileUrl = links.get("bucket") + "/" + pdfEnvelope.getFilename() + "?access_token=" + zenodoToken;
|
||||||
zenodoClient.put().uri(addFileUrl)
|
zenodoClient.put().uri(addFileUrl)
|
||||||
.body(BodyInserters
|
.body(BodyInserters
|
||||||
.fromResource(new ByteArrayResource(Files.readAllBytes(pdfEnvelope.getFile().toPath()))))
|
.fromResource(new ByteArrayResource(pdfEnvelope.getFile())))
|
||||||
.retrieve().toEntity(Map.class).block();
|
.retrieve().toEntity(Map.class).block();
|
||||||
FileEnvelope rdaJsonEnvelope = dmpDepositModel.getRdaJsonFile();
|
FileEnvelope rdaJsonEnvelope = dmpDepositModel.getRdaJsonFile();
|
||||||
|
|
||||||
String jsonFileName = rdaJsonEnvelope.getFilename();
|
String jsonFileName = rdaJsonEnvelope.getFilename();
|
||||||
addFileUrl = links.get("bucket") + "/" + jsonFileName + "?access_token=" + zenodoToken;
|
addFileUrl = links.get("bucket") + "/" + jsonFileName + "?access_token=" + zenodoToken;
|
||||||
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();
|
zenodoClient.put().uri(addFileUrl).headers(httpHeaders -> httpHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM)).body(BodyInserters.fromResource(new ByteArrayResource(rdaJsonEnvelope.getFile()))).retrieve().toEntity(Map.class).block();
|
||||||
|
|
||||||
if (dmpDepositModel.getSupportingFilesZip() != null) {
|
if (dmpDepositModel.getSupportingFilesZip() != null) {
|
||||||
File supportinFilesZip = dmpDepositModel.getSupportingFilesZip();
|
String supportinFilesZipName = dmpDepositModel.getSupportingFilesZip().getFilename();
|
||||||
String supportinFilesZipName = dmpDepositModel.getSupportingFilesZip().getName();
|
|
||||||
|
|
||||||
addFileUrl = links.get("bucket") + "/" + supportinFilesZipName + "?access_token=" + zenodoToken;
|
addFileUrl = links.get("bucket") + "/" + supportinFilesZipName + "?access_token=" + zenodoToken;
|
||||||
zenodoClient.put().uri(addFileUrl).body(BodyInserters.fromResource(new ByteArrayResource(Files.readAllBytes(supportinFilesZip.toPath())))).retrieve().toEntity(Map.class).block();
|
zenodoClient.put().uri(addFileUrl).body(BodyInserters.fromResource(new ByteArrayResource(supportinFilesZipName.getBytes()))).retrieve().toEntity(Map.class).block();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Third post call to Zenodo to publish the entry and return the DOI.
|
// Third post call to Zenodo to publish the entry and return the DOI.
|
||||||
|
@ -179,7 +177,6 @@ public class ZenodoDeposit implements RepositoryDeposit {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String publish(String publishUrl){
|
private String publish(String publishUrl){
|
||||||
//RestTemplate restTemplate = new RestTemplate();
|
|
||||||
WebClient webClient = WebClient.builder().build();
|
WebClient webClient = WebClient.builder().build();
|
||||||
Map<String, Object> publishResponce = webClient.post().uri(publishUrl).bodyValue("").exchangeToMono(mono -> {
|
Map<String, Object> publishResponce = webClient.post().uri(publishUrl).bodyValue("").exchangeToMono(mono -> {
|
||||||
if (!mono.statusCode().is2xxSuccessful()) {
|
if (!mono.statusCode().is2xxSuccessful()) {
|
||||||
|
@ -202,30 +199,25 @@ public class ZenodoDeposit implements RepositoryDeposit {
|
||||||
@Override
|
@Override
|
||||||
public String authenticate(String repositoryId, String code){
|
public String authenticate(String repositoryId, String code){
|
||||||
|
|
||||||
RepositoryDepositConfiguration conf = this.getConfiguration().stream().filter(x -> x.getRepositoryId().equals(repositoryId)).findFirst().orElse(null);
|
RepositoryDepositConfiguration repositoryDepositConfiguration = this.getConfiguration().stream().filter(x -> x.getRepositoryId().equals(repositoryId)).findFirst().orElse(null);
|
||||||
|
|
||||||
if(conf != null) {
|
if(repositoryDepositConfiguration != null) {
|
||||||
|
|
||||||
WebClient client = WebClient.builder().defaultHeaders(httpHeaders -> {
|
WebClient client = WebClient.builder().defaultHeaders(httpHeaders -> {
|
||||||
httpHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
|
httpHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
|
||||||
httpHeaders.setContentType(MediaType.MULTIPART_FORM_DATA);
|
httpHeaders.setContentType(MediaType.MULTIPART_FORM_DATA);
|
||||||
}).build();
|
}).build();
|
||||||
HttpHeaders headers = new HttpHeaders();
|
|
||||||
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
|
|
||||||
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
|
|
||||||
|
|
||||||
MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
|
MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
|
||||||
map.add("client_id", conf.getRepositoryClientId());
|
map.add("client_id", repositoryDepositConfiguration.getRepositoryClientId());
|
||||||
map.add("client_secret", conf.getRepositoryClientSecret());
|
map.add("client_secret", repositoryDepositConfiguration.getRepositoryClientSecret());
|
||||||
map.add("grant_type", "authorization_code");
|
map.add("grant_type", "authorization_code");
|
||||||
map.add("code", code);
|
map.add("code", code);
|
||||||
map.add("redirect_uri", conf.getRedirectUri());
|
map.add("redirect_uri", repositoryDepositConfiguration.getRedirectUri());
|
||||||
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(map, headers);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Map<String, Object> values = client.post().uri(conf.getRepositoryAccessTokenUrl()).bodyValue(map).retrieve().bodyToMono(Map.class).block();
|
Map<String, Object> values = client.post().uri(repositoryDepositConfiguration.getRepositoryAccessTokenUrl()).bodyValue(map).retrieve().bodyToMono(Map.class).block();
|
||||||
Map<String, Object> user = (Map<String, Object>) values.get("user");
|
return values != null ? (String) values.get("access_token") : null;
|
||||||
return (String) values.get("access_token");
|
|
||||||
} catch (HttpClientErrorException ex) {
|
} catch (HttpClientErrorException ex) {
|
||||||
logger.error(ex.getResponseBodyAsString(), ex);
|
logger.error(ex.getResponseBodyAsString(), ex);
|
||||||
}
|
}
|
||||||
|
@ -244,9 +236,11 @@ public class ZenodoDeposit implements RepositoryDeposit {
|
||||||
if(conf.isHasLogo()){
|
if(conf.isHasLogo()){
|
||||||
byte[] logo;
|
byte[] logo;
|
||||||
try {
|
try {
|
||||||
File logoFile = ResourceUtils.getFile(conf.getLogo());
|
java.io.File logoFile = ResourceUtils.getFile(conf.getLogo());
|
||||||
InputStream logoStream = new FileInputStream(logoFile);
|
if (!logoFile.exists()) return null;
|
||||||
logo = logoStream.readAllBytes();
|
try(InputStream inputStream = new FileInputStream(logoFile)){
|
||||||
|
logo = inputStream.readAllBytes();
|
||||||
|
};
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
@ -256,16 +250,13 @@ public class ZenodoDeposit implements RepositoryDeposit {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getUnpublishedDOI(String zenodoUrl, String DOI, String token, Integer version) {
|
private String getUnpublishedDOI(String zenodoUrl, String doi, String token, Short version) {
|
||||||
try {
|
try {
|
||||||
WebClient client = WebClient.builder().build();
|
WebClient client = WebClient.builder().build();
|
||||||
HttpHeaders headers = new HttpHeaders();
|
|
||||||
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
|
|
||||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
|
||||||
Map createResponse = null;
|
Map createResponse = null;
|
||||||
LinkedHashMap<String, String> links;
|
LinkedHashMap<String, String> links;
|
||||||
LinkedHashMap<String, String> metadata;
|
LinkedHashMap<String, String> metadata;
|
||||||
String listUrl = zenodoUrl + "deposit/depositions" + "?q=conceptdoi:\"" + DOI + "\"&access_token=" + token;
|
String listUrl = zenodoUrl + "deposit/depositions" + "?q=conceptdoi:\"" + doi + "\"&access_token=" + token;
|
||||||
ResponseEntity<List<Map>> listResponses = client.get().uri(listUrl).retrieve().toEntityList(Map.class).block();
|
ResponseEntity<List<Map>> listResponses = client.get().uri(listUrl).retrieve().toEntityList(Map.class).block();
|
||||||
createResponse = listResponses.getBody().get(0);
|
createResponse = listResponses.getBody().get(0);
|
||||||
metadata = (LinkedHashMap<String, String>) createResponse.get("metadata");
|
metadata = (LinkedHashMap<String, String>) createResponse.get("metadata");
|
|
@ -1,6 +1,6 @@
|
||||||
package eu.eudat.deposit.controller;
|
package eu.eudat.deposit.controller;
|
||||||
|
|
||||||
import eu.eudat.depositinterface.models.DMPDepositModel;
|
import eu.eudat.depositinterface.models.DmpDepositModel;
|
||||||
import eu.eudat.depositinterface.repository.RepositoryDeposit;
|
import eu.eudat.depositinterface.repository.RepositoryDeposit;
|
||||||
import eu.eudat.depositinterface.repository.RepositoryDepositConfiguration;
|
import eu.eudat.depositinterface.repository.RepositoryDepositConfiguration;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -20,7 +20,7 @@ public class DepositController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/{id}")
|
@PostMapping("/{id}")
|
||||||
public String deposit(@PathVariable("id") String repositoryId, @RequestBody DMPDepositModel dmpDepositModel, @RequestParam("authToken")String authToken) throws Exception {
|
public String deposit(@PathVariable("id") String repositoryId, @RequestBody DmpDepositModel dmpDepositModel, @RequestParam("authToken")String authToken) throws Exception {
|
||||||
return repositoryDeposit.deposit(repositoryId, dmpDepositModel, authToken);
|
return repositoryDeposit.deposit(repositoryId, dmpDepositModel, authToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue