model changes
This commit is contained in:
parent
9f02c2ad92
commit
64181d941e
|
@ -45,7 +45,7 @@
|
|||
<dependency>
|
||||
<groupId>gr.cite.opendmp</groupId>
|
||||
<artifactId>repositorydepositbase</artifactId>
|
||||
<version>2.0.1</version>
|
||||
<version>2.0.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
|
|
@ -3,11 +3,10 @@ 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})
|
||||
@EnableConfigurationProperties({PidProperties.class, FunderProperties.class, IdentifierProperties.class})
|
||||
public class GenericConfiguration {
|
||||
}
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
package eu.eudat.depositinterface.zenodorepository.configuration.zenodo;
|
||||
|
||||
import eu.eudat.depositinterface.repository.DepositConfiguration;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
@ConfigurationProperties(prefix = "zenodo")
|
||||
public class ZenodoProperties {
|
||||
private String logo;
|
||||
|
||||
private String community;
|
||||
|
||||
private String domain;
|
||||
|
||||
private String affiliation;
|
||||
|
||||
private DepositConfiguration depositConfiguration;
|
||||
|
||||
public void setLogo(String logo) {
|
||||
this.logo = logo;
|
||||
}
|
||||
|
||||
public String getLogo() {
|
||||
return logo;
|
||||
}
|
||||
|
||||
public String getCommunity() {
|
||||
return community;
|
||||
}
|
||||
|
||||
public void setCommunity(String community) {
|
||||
this.community = community;
|
||||
}
|
||||
|
||||
public String getDomain() {
|
||||
return domain;
|
||||
}
|
||||
|
||||
public void setDomain(String domain) {
|
||||
this.domain = domain;
|
||||
}
|
||||
|
||||
public String getAffiliation() {
|
||||
return affiliation;
|
||||
}
|
||||
|
||||
public void setAffiliation(String affiliation) {
|
||||
this.affiliation = affiliation;
|
||||
}
|
||||
|
||||
public DepositConfiguration getDepositConfiguration() {
|
||||
return depositConfiguration;
|
||||
}
|
||||
|
||||
public void setDepositConfiguration(DepositConfiguration depositConfiguration) {
|
||||
this.depositConfiguration = depositConfiguration;
|
||||
}
|
||||
}
|
|
@ -2,20 +2,21 @@ package eu.eudat.depositinterface.zenodorepository.model.builder;
|
|||
|
||||
import eu.eudat.commonmodels.enums.DmpAccessType;
|
||||
import eu.eudat.commonmodels.enums.DmpUserRole;
|
||||
import eu.eudat.commonmodels.models.DmpModel;
|
||||
import eu.eudat.commonmodels.models.DmpUserModel;
|
||||
import eu.eudat.commonmodels.models.description.*;
|
||||
import eu.eudat.commonmodels.models.descriptiotemplate.DefinitionModel;
|
||||
import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.RadioBoxDataModel;
|
||||
import eu.eudat.commonmodels.models.descriptiotemplate.fielddata.SelectDataModel;
|
||||
import eu.eudat.commonmodels.models.dmp.DmpModel;
|
||||
import eu.eudat.commonmodels.models.dmpreference.DmpReferenceModel;
|
||||
import eu.eudat.commonmodels.models.reference.ReferenceFieldModel;
|
||||
import eu.eudat.commonmodels.models.reference.ReferenceModel;
|
||||
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.enums.ZenodoAccessRight;
|
||||
import eu.eudat.depositinterface.zenodorepository.model.*;
|
||||
import eu.eudat.depositinterface.zenodorepository.service.zenodo.ZenodoServiceProperties;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
|
@ -39,35 +40,37 @@ public class ZenodoBuilder {
|
|||
private final PidProperties pidProperties;
|
||||
private final IdentifierProperties identifierProperties;
|
||||
private final FunderProperties funderProperties;
|
||||
private final ZenodoServiceProperties zenodoServiceProperties;
|
||||
|
||||
@Autowired
|
||||
public ZenodoBuilder(PidProperties pidProperties, IdentifierProperties identifierProperties, FunderProperties funderProperties){
|
||||
public ZenodoBuilder(PidProperties pidProperties, IdentifierProperties identifierProperties, FunderProperties funderProperties, ZenodoServiceProperties zenodoServiceProperties){
|
||||
this.pidProperties = pidProperties;
|
||||
this.identifierProperties = identifierProperties;
|
||||
this.funderProperties = funderProperties;
|
||||
this.zenodoServiceProperties = zenodoServiceProperties;
|
||||
}
|
||||
|
||||
public ZenodoDeposit build(DmpModel dmp, ZenodoProperties zenodoConfig) {
|
||||
public ZenodoDeposit build(DmpModel dmp) {
|
||||
ZenodoDeposit deposit = new ZenodoDeposit();
|
||||
this.applyZenodoRelator(dmp, deposit, zenodoConfig);
|
||||
this.applyZenodoRelator(dmp, deposit);
|
||||
deposit.getMetadata().setTitle(dmp.getLabel());
|
||||
deposit.getMetadata().setUploadType(UPLOAD_TYPE);
|
||||
deposit.getMetadata().setPublicationType(PUBLICATION_TYPE);
|
||||
deposit.getMetadata().setDescription((dmp.getDescription() != null && !dmp.getDescription().isEmpty() ? dmp.getDescription() : "<p></p>"));
|
||||
deposit.getMetadata().setVersion(String.valueOf(dmp.getVersion()));
|
||||
String zenodoCommunity = zenodoConfig.getCommunity();
|
||||
String zenodoCommunity = zenodoServiceProperties.getCommunity();
|
||||
if(zenodoCommunity != null && !zenodoCommunity.isEmpty()) {
|
||||
ZenodoCommunity community = new ZenodoCommunity();
|
||||
community.setIdentifier(zenodoCommunity);
|
||||
deposit.getMetadata().getCommunities().add(community);
|
||||
}
|
||||
this.applyAccessRight(dmp, deposit);
|
||||
this.applyIsIdenticalTo(dmp, deposit, zenodoConfig);
|
||||
this.applyLicenses(dmp, deposit, zenodoConfig);
|
||||
this.applyResearchers(dmp, deposit, zenodoConfig);
|
||||
this.applyGrants(dmp, deposit, zenodoConfig);
|
||||
this.applyContributors(dmp, deposit, zenodoConfig);
|
||||
this.applyCreators(dmp, deposit, zenodoConfig);
|
||||
this.applyIsIdenticalTo(dmp, deposit);
|
||||
this.applyLicenses(dmp, deposit);
|
||||
this.applyResearchers(dmp, deposit);
|
||||
this.applyGrants(dmp, deposit);
|
||||
this.applyContributors(dmp, deposit);
|
||||
this.applyCreators(dmp, deposit);
|
||||
|
||||
return deposit;
|
||||
}
|
||||
|
@ -92,7 +95,7 @@ public class ZenodoBuilder {
|
|||
return models;
|
||||
}
|
||||
|
||||
private Set<String> extractSchematicValues(List<eu.eudat.commonmodels.models.descriptiotemplate.FieldModel> fields, PropertyDefinitionModel propertyDefinition, List<String> acceptedPidTypes, ZenodoProperties zenodoConfig) {
|
||||
private Set<String> extractSchematicValues(List<eu.eudat.commonmodels.models.descriptiotemplate.FieldModel> fields, PropertyDefinitionModel propertyDefinition, List<String> acceptedPidTypes) {
|
||||
Set<String> values = new HashSet<>();
|
||||
for (eu.eudat.commonmodels.models.descriptiotemplate.FieldModel field : fields) {
|
||||
if (field.getData() == null) continue;
|
||||
|
@ -141,7 +144,7 @@ public class ZenodoBuilder {
|
|||
if (referenceModel == null
|
||||
|| referenceModel.getType() == null || referenceModel.getType().getCode() == null || referenceModel.getType().getCode().isBlank()
|
||||
|| referenceModel.getDefinition() == null || referenceModel.getDefinition().getFields() == null || referenceModel.getDefinition().getFields().isEmpty()) continue;
|
||||
if (referenceModel.getType().getCode().equals(zenodoConfig.getDepositConfiguration().getOrganizationReferenceCode()) || referenceModel.getType().getCode().equals(zenodoConfig.getDepositConfiguration().getResearcherReferenceCode())) {
|
||||
if (referenceModel.getType().getCode().equals(zenodoServiceProperties.getOrganizationReferenceCode()) || referenceModel.getType().getCode().equals(zenodoServiceProperties.getResearcherReferenceCode())) {
|
||||
if (referenceModel.getReference() != null && !referenceModel.getReference().isBlank()) {
|
||||
values.add(referenceModel.getReference());
|
||||
}
|
||||
|
@ -164,11 +167,17 @@ public class ZenodoBuilder {
|
|||
}
|
||||
|
||||
private List<ReferenceModel> getReferenceModelOfType(DmpModel dmp, String code){
|
||||
if (dmp.getReferences() == null) return new ArrayList<>();
|
||||
return dmp.getReferences().stream().filter(x -> x.getType() != null && x.getType().getCode().equals(code)).toList();
|
||||
List<ReferenceModel> response = new ArrayList<>();
|
||||
if (dmp.getReferences() == null) return response;
|
||||
for (DmpReferenceModel dmpReferenceModel : dmp.getReferences()){
|
||||
if (dmpReferenceModel.getReference() != null && dmpReferenceModel.getReference().getType() != null && dmpReferenceModel.getReference().getType().getCode() != null && dmpReferenceModel.getReference().getType().getCode().equals(code)){
|
||||
response.add(dmpReferenceModel.getReference());
|
||||
}
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
private void applyZenodoRelator(DmpModel dmp, ZenodoDeposit deposit, ZenodoProperties zenodoConfig) {
|
||||
private void applyZenodoRelator(DmpModel dmp, ZenodoDeposit deposit) {
|
||||
if (deposit.getMetadata() == null) deposit.setMetadata(new ZenodoDepositMetadata());
|
||||
|
||||
List<String> acceptedPidTypes = this.pidProperties.getAcceptedTypes();
|
||||
|
@ -176,7 +185,7 @@ public class ZenodoBuilder {
|
|||
for(DescriptionModel descriptionModel: dmp.getDescriptions()){
|
||||
for(String relatedId: this.identifierProperties.getRelated()){
|
||||
List<eu.eudat.commonmodels.models.descriptiotemplate.FieldModel> fields = this.findSchematicValues(relatedId, descriptionModel.getDescriptionTemplate().getDefinition());
|
||||
Set<String> values = extractSchematicValues(fields, descriptionModel.getProperties(), acceptedPidTypes, zenodoConfig);
|
||||
Set<String> values = extractSchematicValues(fields, descriptionModel.getProperties(), acceptedPidTypes);
|
||||
for(String value: values){
|
||||
ZenodoRelator relator = new ZenodoRelator();
|
||||
relator.setRelation(relatedId.substring(relatedId.lastIndexOf(".") + 1));
|
||||
|
@ -212,22 +221,22 @@ public class ZenodoBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
private void applyIsIdenticalTo(DmpModel dmp, ZenodoDeposit deposit, ZenodoProperties zenodoConfig){
|
||||
private void applyIsIdenticalTo(DmpModel dmp, ZenodoDeposit deposit){
|
||||
if (deposit.getMetadata() == null) deposit.setMetadata(new ZenodoDepositMetadata());
|
||||
|
||||
if (dmp.getAccessType().equals(DmpAccessType.Public)) {
|
||||
ZenodoRelator relator = new ZenodoRelator();
|
||||
relator.setIdentifier(zenodoConfig.getDomain() + "/external/zenodo/" + dmp.getId().toString());
|
||||
relator.setIdentifier(zenodoServiceProperties.getDomain() + "/external/zenodo/" + dmp.getId().toString());
|
||||
relator.setRelation(IS_IDENTICAL_TO);
|
||||
if (deposit.getMetadata().getRelatedIdentifiers() == null)deposit.getMetadata().setRelatedIdentifiers(new ArrayList<>());
|
||||
deposit.getMetadata().getRelatedIdentifiers().add(relator);
|
||||
}
|
||||
}
|
||||
|
||||
private void applyLicenses(DmpModel dmp, ZenodoDeposit deposit, ZenodoProperties zenodoConfig){
|
||||
private void applyLicenses(DmpModel dmp, ZenodoDeposit deposit){
|
||||
if (deposit.getMetadata() == null) deposit.setMetadata(new ZenodoDepositMetadata());
|
||||
|
||||
List<ReferenceModel> dmpLicenses = this.getReferenceModelOfType(dmp, zenodoConfig.getDepositConfiguration().getResearcherReferenceCode());
|
||||
List<ReferenceModel> dmpLicenses = this.getReferenceModelOfType(dmp, zenodoServiceProperties.getResearcherReferenceCode());
|
||||
if (dmpLicenses != null && !dmpLicenses.isEmpty()) {
|
||||
for (ReferenceModel dmpLicense : dmpLicenses) {
|
||||
if (dmpLicense != null && dmpLicense.getReference() != null && !dmpLicense.getReference().isBlank()) {
|
||||
|
@ -238,18 +247,18 @@ public class ZenodoBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
private void applyResearchers(DmpModel dmp, ZenodoDeposit deposit, ZenodoProperties zenodoConfig){
|
||||
private void applyResearchers(DmpModel dmp, ZenodoDeposit deposit){
|
||||
if (deposit.getMetadata() == null) deposit.setMetadata(new ZenodoDepositMetadata());
|
||||
|
||||
List<ZenodoContributor> researchers = new ArrayList<>();
|
||||
List<ReferenceModel> dmpResearchers = this.getReferenceModelOfType(dmp, zenodoConfig.getDepositConfiguration().getResearcherReferenceCode());
|
||||
List<ReferenceModel> dmpResearchers = this.getReferenceModelOfType(dmp, zenodoServiceProperties.getResearcherReferenceCode());
|
||||
if (dmpResearchers != null && !dmpResearchers.isEmpty()) {
|
||||
for (ReferenceModel researcher : dmpResearchers) {
|
||||
ZenodoContributor contributor = new ZenodoContributor();
|
||||
contributor.setName(researcher.getLabel());
|
||||
contributor.setType(CONTRIBUTOR_TYPE_RESEARCHER);
|
||||
contributor.setAffiliation(researcher.getSource());
|
||||
if (researcher.getSource().equalsIgnoreCase(zenodoConfig.getDepositConfiguration().getOrcidResearcherSourceCode())) {
|
||||
if (researcher.getSource().equalsIgnoreCase(zenodoServiceProperties.getOrcidResearcherSourceCode())) {
|
||||
contributor.setOrcid(researcher.getReference());
|
||||
}
|
||||
researchers.add(contributor);
|
||||
|
@ -261,13 +270,13 @@ public class ZenodoBuilder {
|
|||
deposit.getMetadata().getContributors().addAll(researchers);
|
||||
}
|
||||
|
||||
private void applyGrants(DmpModel dmp, ZenodoDeposit deposit, ZenodoProperties zenodoConfig){
|
||||
private void applyGrants(DmpModel dmp, ZenodoDeposit deposit){
|
||||
if (deposit.getMetadata() == null) deposit.setMetadata(new ZenodoDepositMetadata());
|
||||
List<ReferenceModel> dmpGrants = this.getReferenceModelOfType(dmp, zenodoConfig.getDepositConfiguration().getGrantReferenceCode());
|
||||
List<ReferenceModel> dmpFunders = this.getReferenceModelOfType(dmp, zenodoConfig.getDepositConfiguration().getFunderReferenceCode());
|
||||
List<ReferenceModel> dmpGrants = this.getReferenceModelOfType(dmp, zenodoServiceProperties.getGrantReferenceCode());
|
||||
List<ReferenceModel> dmpFunders = this.getReferenceModelOfType(dmp, zenodoServiceProperties.getFunderReferenceCode());
|
||||
|
||||
if (dmpGrants != null && !dmpGrants.isEmpty()) {
|
||||
ReferenceModel depositGrant = dmpGrants.stream().filter(x-> x.getSource().equalsIgnoreCase(zenodoConfig.getDepositConfiguration().getOpenaireGrantSourceCode())).findFirst().orElse(null);
|
||||
ReferenceModel depositGrant = dmpGrants.stream().filter(x-> x.getSource().equalsIgnoreCase(zenodoServiceProperties.getOpenaireGrantSourceCode())).findFirst().orElse(null);
|
||||
|
||||
if (depositGrant != null) {
|
||||
String grantReferenceTail = depositGrant.getReference().split(":")[2];
|
||||
|
@ -289,13 +298,13 @@ public class ZenodoBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
private void applyContributors(DmpModel dmp, ZenodoDeposit deposit, ZenodoProperties zenodoConfig){
|
||||
private void applyContributors(DmpModel dmp, ZenodoDeposit deposit){
|
||||
if (dmp.getUsers() == null) return;
|
||||
|
||||
if (deposit.getMetadata() == null) deposit.setMetadata(new ZenodoDepositMetadata());
|
||||
|
||||
List<ReferenceModel> dmpOrganizations = this.getReferenceModelOfType(dmp, zenodoConfig.getDepositConfiguration().getOrganizationReferenceCode());
|
||||
String zenodoAffiliation = zenodoConfig.getAffiliation();
|
||||
List<ReferenceModel> dmpOrganizations = this.getReferenceModelOfType(dmp, zenodoServiceProperties.getOrganizationReferenceCode());
|
||||
String zenodoAffiliation = zenodoServiceProperties.getAffiliation();
|
||||
|
||||
List<ZenodoContributor> contributors = new ArrayList<>();
|
||||
for (DmpUserModel userDMP: dmp.getUsers()) {
|
||||
|
@ -317,13 +326,13 @@ public class ZenodoBuilder {
|
|||
|
||||
}
|
||||
|
||||
private void applyCreators(DmpModel dmp, ZenodoDeposit deposit, ZenodoProperties zenodoConfig){
|
||||
private void applyCreators(DmpModel dmp, ZenodoDeposit deposit){
|
||||
if (dmp.getUsers() == null) return;
|
||||
|
||||
if (deposit.getMetadata() == null) deposit.setMetadata(new ZenodoDepositMetadata());
|
||||
|
||||
List<ReferenceModel> dmpOrganizations = this.getReferenceModelOfType(dmp, zenodoConfig.getDepositConfiguration().getOrganizationReferenceCode());
|
||||
String zenodoAffiliation = zenodoConfig.getAffiliation();
|
||||
List<ReferenceModel> dmpOrganizations = this.getReferenceModelOfType(dmp, zenodoServiceProperties.getOrganizationReferenceCode());
|
||||
String zenodoAffiliation = zenodoServiceProperties.getAffiliation();
|
||||
|
||||
ZenodoCreator creator = new ZenodoCreator();
|
||||
DmpUserModel dmpModel = dmp.getUsers().stream().filter(userDMP -> userDMP.getRole().equals(DmpUserRole.Owner)).findFirst().orElse(null);
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package eu.eudat.depositinterface.zenodorepository.service.storage;
|
||||
|
||||
public interface FileStorageService {
|
||||
String storeFile(byte[] data);
|
||||
|
||||
byte[] readFile(String fileRef);
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package eu.eudat.depositinterface.zenodorepository.service.storage;
|
||||
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties({FileStorageServiceProperties.class})
|
||||
public class FileStorageServiceConfiguration {
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package eu.eudat.depositinterface.zenodorepository.service.storage;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
|
||||
@Service
|
||||
public class FileStorageServiceImpl implements FileStorageService {
|
||||
private final static Logger logger = LoggerFactory.getLogger(FileStorageServiceImpl.class);
|
||||
|
||||
private final FileStorageServiceProperties properties;
|
||||
|
||||
@Autowired
|
||||
public FileStorageServiceImpl(FileStorageServiceProperties properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String storeFile(byte[] data) {
|
||||
try {
|
||||
String fileName = UUID.randomUUID().toString().replace("-", "").toLowerCase(Locale.ROOT);
|
||||
Path storagePath = Paths.get(properties.getTransientPath() + "/" + fileName);
|
||||
Files.write(storagePath, data, StandardOpenOption.CREATE_NEW);
|
||||
return fileName;
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] readFile(String fileRef) {
|
||||
try (FileInputStream inputStream = new FileInputStream(properties.getTransientPath() + "/" + fileRef)) {
|
||||
return inputStream.readAllBytes();
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return new byte[0];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package eu.eudat.depositinterface.zenodorepository.service.storage;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.bind.ConstructorBinding;
|
||||
|
||||
@ConfigurationProperties(prefix = "file.storage")
|
||||
public class FileStorageServiceProperties {
|
||||
private final String temp;
|
||||
private final String transientPath;
|
||||
|
||||
@ConstructorBinding
|
||||
public FileStorageServiceProperties(String temp, String transientPath) {
|
||||
this.temp = temp;
|
||||
this.transientPath = transientPath;
|
||||
}
|
||||
|
||||
public String getTemp() {
|
||||
return temp;
|
||||
}
|
||||
|
||||
public String getTransientPath() {
|
||||
return transientPath;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package eu.eudat.depositinterface.zenodorepository.service;
|
||||
package eu.eudat.depositinterface.zenodorepository.service.zenodo;
|
||||
|
||||
import eu.eudat.commonmodels.models.DmpModel;
|
||||
import eu.eudat.commonmodels.models.dmp.DmpModel;
|
||||
import eu.eudat.depositinterface.repository.DepositConfiguration;
|
||||
|
||||
public interface ZenodoDepositService {
|
|
@ -1,18 +1,19 @@
|
|||
package eu.eudat.depositinterface.zenodorepository.service;
|
||||
package eu.eudat.depositinterface.zenodorepository.service.zenodo;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import eu.eudat.commonmodels.models.DmpModel;
|
||||
import eu.eudat.commonmodels.models.FileEnvelopeModel;
|
||||
import eu.eudat.commonmodels.models.dmp.DmpModel;
|
||||
import eu.eudat.depositinterface.repository.DepositConfiguration;
|
||||
import eu.eudat.depositinterface.zenodorepository.configuration.zenodo.ZenodoProperties;
|
||||
import eu.eudat.depositinterface.zenodorepository.model.ZenodoDeposit;
|
||||
import eu.eudat.depositinterface.zenodorepository.model.builder.ZenodoBuilder;
|
||||
import eu.eudat.depositinterface.zenodorepository.service.storage.FileStorageService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
@ -22,7 +23,9 @@ import org.springframework.web.client.HttpServerErrorException;
|
|||
import org.springframework.web.reactive.function.BodyInserters;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
|
||||
@Component
|
||||
|
@ -47,16 +50,18 @@ public class ZenodoDepositServiceImpl implements ZenodoDepositService {
|
|||
private static final Logger logger = LoggerFactory.getLogger(ZenodoDepositServiceImpl.class);
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
private final ZenodoProperties zenodoProperties;
|
||||
private final ZenodoBuilder mapper;
|
||||
private final ZenodoServiceProperties zenodoServiceProperties;
|
||||
private final ZenodoBuilder zenodoBuilder;
|
||||
private final FileStorageService storageService;
|
||||
|
||||
private byte[] logo;
|
||||
|
||||
@Autowired
|
||||
public ZenodoDepositServiceImpl(ZenodoProperties zenodoProperties, ZenodoBuilder mapper){
|
||||
this.zenodoProperties = zenodoProperties;
|
||||
this.mapper = mapper;
|
||||
this.logo = null;
|
||||
public ZenodoDepositServiceImpl(ZenodoServiceProperties zenodoServiceProperties, ZenodoBuilder mapper, FileStorageService storageService){
|
||||
this.zenodoServiceProperties = zenodoServiceProperties;
|
||||
this.zenodoBuilder = mapper;
|
||||
this.storageService = storageService;
|
||||
this.logo = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -75,9 +80,9 @@ public class ZenodoDepositServiceImpl implements ZenodoDepositService {
|
|||
// First step, post call to Zenodo, to create the entry.
|
||||
WebClient zenodoClient = WebClient.builder().build();
|
||||
|
||||
DepositConfiguration zenodoConfig = this.zenodoProperties.getDepositConfiguration();
|
||||
DepositConfiguration zenodoConfig = this.zenodoServiceProperties.getDepositConfiguration();
|
||||
if (zenodoConfig == null) return null;
|
||||
eu.eudat.depositinterface.zenodorepository.model.ZenodoDeposit deposit = mapper.build(dmpModel, this.zenodoProperties);
|
||||
eu.eudat.depositinterface.zenodorepository.model.ZenodoDeposit deposit = zenodoBuilder.build(dmpModel);
|
||||
|
||||
LinkedHashMap<String, String> links;
|
||||
String previousDOI = dmpModel.getPreviousDOI();
|
||||
|
@ -105,15 +110,31 @@ public class ZenodoDepositServiceImpl implements ZenodoDepositService {
|
|||
if (links == null || !links.containsKey(ZENODO_LINKS_BUCKET)) throw new Exception("bucket not found");
|
||||
|
||||
String addFileUrl = links.get(ZENODO_LINKS_BUCKET) + "/" + pdfEnvelope.getFilename() + "?access_token=" + zenodoToken;
|
||||
|
||||
byte[] pdfFileBytes = null;
|
||||
if (this.getConfiguration().isUseSharedStorage() && pdfEnvelope.getFileRef() != null && !pdfEnvelope.getFileRef().isBlank()) {
|
||||
pdfFileBytes = this.storageService.readFile(pdfEnvelope.getFileRef());
|
||||
}
|
||||
if (pdfFileBytes == null || pdfFileBytes.length == 0){
|
||||
pdfFileBytes = pdfEnvelope.getFile();
|
||||
}
|
||||
zenodoClient.put().uri(addFileUrl)
|
||||
.body(BodyInserters
|
||||
.fromResource(new ByteArrayResource(pdfEnvelope.getFile())))
|
||||
.fromResource(new ByteArrayResource(pdfFileBytes)))
|
||||
.retrieve().toEntity(Map.class).block();
|
||||
FileEnvelopeModel rdaJsonEnvelope = dmpModel.getRdaJsonFile();
|
||||
|
||||
String jsonFileName = rdaJsonEnvelope.getFilename();
|
||||
addFileUrl = links.get(ZENODO_LINKS_BUCKET) + "/" + jsonFileName + "?access_token=" + zenodoToken;
|
||||
zenodoClient.put().uri(addFileUrl).headers(httpHeaders -> httpHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM)).body(BodyInserters.fromResource(new ByteArrayResource(rdaJsonEnvelope.getFile()))).retrieve().toEntity(Map.class).block();
|
||||
|
||||
byte[] rdaJsonBytes = null;
|
||||
if (this.getConfiguration().isUseSharedStorage() && rdaJsonEnvelope.getFileRef() != null && !rdaJsonEnvelope.getFileRef().isBlank()) {
|
||||
rdaJsonBytes = this.storageService.readFile(rdaJsonEnvelope.getFileRef());
|
||||
}
|
||||
if (rdaJsonBytes == null || rdaJsonBytes.length == 0){
|
||||
rdaJsonBytes = rdaJsonEnvelope.getFile();
|
||||
}
|
||||
zenodoClient.put().uri(addFileUrl).headers(httpHeaders -> httpHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM)).body(BodyInserters.fromResource(new ByteArrayResource(rdaJsonBytes))).retrieve().toEntity(Map.class).block();
|
||||
|
||||
if (dmpModel.getSupportingFilesZip() != null) {
|
||||
String supportingFilesZipName = dmpModel.getSupportingFilesZip().getFilename();
|
||||
|
@ -237,7 +258,7 @@ public class ZenodoDepositServiceImpl implements ZenodoDepositService {
|
|||
|
||||
@Override
|
||||
public DepositConfiguration getConfiguration() {
|
||||
return this.zenodoProperties.getDepositConfiguration();
|
||||
return this.zenodoServiceProperties.getDepositConfiguration();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -281,11 +302,11 @@ public class ZenodoDepositServiceImpl implements ZenodoDepositService {
|
|||
|
||||
@Override
|
||||
public String getLogo() {
|
||||
DepositConfiguration zenodoConfig = this.zenodoProperties.getDepositConfiguration();
|
||||
if(zenodoConfig != null && zenodoConfig.isHasLogo() && this.zenodoProperties.getLogo() != null && !this.zenodoProperties.getLogo().isBlank()) {
|
||||
DepositConfiguration zenodoConfig = this.zenodoServiceProperties.getDepositConfiguration();
|
||||
if(zenodoConfig != null && zenodoConfig.isHasLogo() && this.zenodoServiceProperties.getLogo() != null && !this.zenodoServiceProperties.getLogo().isBlank()) {
|
||||
if (this.logo == null) {
|
||||
try {
|
||||
java.io.File logoFile = ResourceUtils.getFile(this.zenodoProperties.getLogo());
|
||||
java.io.File logoFile = ResourceUtils.getFile(this.zenodoServiceProperties.getLogo());
|
||||
if (!logoFile.exists()) return null;
|
||||
try(InputStream inputStream = new FileInputStream(logoFile)){
|
||||
this.logo = inputStream.readAllBytes();
|
|
@ -0,0 +1,9 @@
|
|||
package eu.eudat.depositinterface.zenodorepository.service.zenodo;
|
||||
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties({ZenodoServiceProperties.class})
|
||||
public class ZenodoServiceConfiguration {
|
||||
}
|
|
@ -0,0 +1,122 @@
|
|||
package eu.eudat.depositinterface.zenodorepository.service.zenodo;
|
||||
|
||||
import eu.eudat.depositinterface.repository.DepositConfiguration;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.bind.ConstructorBinding;
|
||||
|
||||
@ConfigurationProperties(prefix = "zenodo")
|
||||
public class ZenodoServiceProperties {
|
||||
private String logo;
|
||||
|
||||
private String community;
|
||||
|
||||
private String domain;
|
||||
|
||||
private String affiliation;
|
||||
|
||||
private DepositConfiguration depositConfiguration;
|
||||
|
||||
private String organizationReferenceCode;
|
||||
private String grantReferenceCode;
|
||||
private String funderReferenceCode;
|
||||
private String researcherReferenceCode;
|
||||
private String licensesReferenceCode;
|
||||
private String openaireGrantSourceCode;
|
||||
private String orcidResearcherSourceCode;
|
||||
|
||||
public String getLogo() {
|
||||
return logo;
|
||||
}
|
||||
|
||||
public void setLogo(String logo) {
|
||||
this.logo = logo;
|
||||
}
|
||||
|
||||
public String getCommunity() {
|
||||
return community;
|
||||
}
|
||||
|
||||
public void setCommunity(String community) {
|
||||
this.community = community;
|
||||
}
|
||||
|
||||
public String getDomain() {
|
||||
return domain;
|
||||
}
|
||||
|
||||
public void setDomain(String domain) {
|
||||
this.domain = domain;
|
||||
}
|
||||
|
||||
public String getAffiliation() {
|
||||
return affiliation;
|
||||
}
|
||||
|
||||
public void setAffiliation(String affiliation) {
|
||||
this.affiliation = affiliation;
|
||||
}
|
||||
|
||||
public DepositConfiguration getDepositConfiguration() {
|
||||
return depositConfiguration;
|
||||
}
|
||||
|
||||
public void setDepositConfiguration(DepositConfiguration depositConfiguration) {
|
||||
this.depositConfiguration = depositConfiguration;
|
||||
}
|
||||
|
||||
public String getOrganizationReferenceCode() {
|
||||
return organizationReferenceCode;
|
||||
}
|
||||
|
||||
public void setOrganizationReferenceCode(String organizationReferenceCode) {
|
||||
this.organizationReferenceCode = organizationReferenceCode;
|
||||
}
|
||||
|
||||
public String getGrantReferenceCode() {
|
||||
return grantReferenceCode;
|
||||
}
|
||||
|
||||
public void setGrantReferenceCode(String grantReferenceCode) {
|
||||
this.grantReferenceCode = grantReferenceCode;
|
||||
}
|
||||
|
||||
public String getFunderReferenceCode() {
|
||||
return funderReferenceCode;
|
||||
}
|
||||
|
||||
public void setFunderReferenceCode(String funderReferenceCode) {
|
||||
this.funderReferenceCode = funderReferenceCode;
|
||||
}
|
||||
|
||||
public String getResearcherReferenceCode() {
|
||||
return researcherReferenceCode;
|
||||
}
|
||||
|
||||
public void setResearcherReferenceCode(String researcherReferenceCode) {
|
||||
this.researcherReferenceCode = researcherReferenceCode;
|
||||
}
|
||||
|
||||
public String getLicensesReferenceCode() {
|
||||
return licensesReferenceCode;
|
||||
}
|
||||
|
||||
public void setLicensesReferenceCode(String licensesReferenceCode) {
|
||||
this.licensesReferenceCode = licensesReferenceCode;
|
||||
}
|
||||
|
||||
public String getOpenaireGrantSourceCode() {
|
||||
return openaireGrantSourceCode;
|
||||
}
|
||||
|
||||
public void setOpenaireGrantSourceCode(String openaireGrantSourceCode) {
|
||||
this.openaireGrantSourceCode = openaireGrantSourceCode;
|
||||
}
|
||||
|
||||
public String getOrcidResearcherSourceCode() {
|
||||
return orcidResearcherSourceCode;
|
||||
}
|
||||
|
||||
public void setOrcidResearcherSourceCode(String orcidResearcherSourceCode) {
|
||||
this.orcidResearcherSourceCode = orcidResearcherSourceCode;
|
||||
}
|
||||
}
|
|
@ -1,13 +1,11 @@
|
|||
package eu.eudat.deposit.controller;
|
||||
|
||||
import eu.eudat.commonmodels.models.DmpModel;
|
||||
import eu.eudat.commonmodels.models.dmp.DmpModel;
|
||||
import eu.eudat.depositinterface.repository.DepositConfiguration;
|
||||
import eu.eudat.depositinterface.zenodorepository.service.ZenodoDepositService;
|
||||
import eu.eudat.depositinterface.zenodorepository.service.zenodo.ZenodoDepositService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/deposit")
|
||||
public class DepositController implements eu.eudat.depositinterface.repository.DepositController {
|
||||
|
|
|
@ -3,6 +3,16 @@ zenodo:
|
|||
affiliation: ARGOS
|
||||
domain: https://argos.openaire.eu/
|
||||
logo: classpath:zenodo.jpg
|
||||
organizationReferenceCode: "organisations"
|
||||
grantReferenceCode: "grants"
|
||||
funderReferenceCode: "funders"
|
||||
researcherReferenceCode: "researchers"
|
||||
licenceReferenceCode: "licenses"
|
||||
projectReferenceCode: "projects"
|
||||
datasetReferenceCode: "datasets"
|
||||
publicationReferenceCode: "publications"
|
||||
openaireGrantSourceCode: "openaire"
|
||||
orcidResearcherSourceCode: "ORCID"
|
||||
depositConfiguration:
|
||||
deposit-type: 2
|
||||
repository-id: Zenodo
|
||||
|
@ -15,3 +25,4 @@ zenodo:
|
|||
repository-client-secret:
|
||||
redirect-uri: http://localhost:4200/login/external/zenodo
|
||||
has-logo: true
|
||||
useSharedStorage: true
|
||||
|
|
Loading…
Reference in New Issue