update models

This commit is contained in:
Efstratios Giannopoulos 2024-03-01 17:55:17 +02:00
parent 060a4e41f6
commit 9f02c2ad92
6 changed files with 143 additions and 119 deletions

View File

@ -45,7 +45,7 @@
<dependency>
<groupId>gr.cite.opendmp</groupId>
<artifactId>repositorydepositbase</artifactId>
<version>2.0.0</version>
<version>2.0.1</version>
</dependency>
<dependency>

View File

@ -1,9 +1,8 @@
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 eu.eudat.commonmodels.enums.EnumUtils;
import eu.eudat.commonmodels.enums.EnumValueProvider;
import java.util.Map;

View File

@ -1,13 +1,15 @@
package eu.eudat.depositinterface.zenodorepository.model.builder;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
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.reference.FieldDepositModel;
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.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;
@ -20,6 +22,7 @@ import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
@ -32,12 +35,7 @@ public class ZenodoBuilder {
private static final String IS_IDENTICAL_TO = "isIdenticalTo";
private static final String CONTRIBUTOR_TYPE_RESEARCHER = "Researcher";
private static final String CONTRIBUTOR_TYPE_PROJECT_MANAGER = "ProjectMember";
private static final String SOURCE_OPENAIRE = "openaire";
private static final String SOURCE_ORCID = "ORCID";
private static final String PID = "pid";
private final PidProperties pidProperties;
private final IdentifierProperties identifierProperties;
private final FunderProperties funderProperties;
@ -49,9 +47,9 @@ public class ZenodoBuilder {
this.funderProperties = funderProperties;
}
public ZenodoDeposit build(DmpDepositModel dmp, ZenodoProperties zenodoConfig) throws JsonProcessingException {
public ZenodoDeposit build(DmpModel dmp, ZenodoProperties zenodoConfig) {
ZenodoDeposit deposit = new ZenodoDeposit();
this.applyZenodoRelator(dmp, deposit);
this.applyZenodoRelator(dmp, deposit, zenodoConfig);
deposit.getMetadata().setTitle(dmp.getLabel());
deposit.getMetadata().setUploadType(UPLOAD_TYPE);
deposit.getMetadata().setPublicationType(PUBLICATION_TYPE);
@ -65,91 +63,120 @@ public class ZenodoBuilder {
}
this.applyAccessRight(dmp, deposit);
this.applyIsIdenticalTo(dmp, deposit, zenodoConfig);
this.applyLicenses(dmp, deposit);
this.applyResearchers(dmp, deposit);
this.applyGrants(dmp, deposit);
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);
return deposit;
}
private List<DescriptionFieldDepositModel> findSchematicValues(String relatedId, List<DescriptionFieldDepositModel> fields){
return fields.stream().filter(f -> f.getSchematics().contains(relatedId)).collect(Collectors.toList());
private List<eu.eudat.commonmodels.models.descriptiotemplate.FieldModel> findSchematicValues(String relatedId, DefinitionModel definitionModel){
return definitionModel.getAllField().stream().filter(x-> x.getSchematics() != null && x.getSchematics().contains(relatedId)).toList();
}
private Set<String> extractSchematicValues(List<DescriptionFieldDepositModel> fields, List<String> acceptedPidTypes) throws JsonProcessingException{
ObjectMapper objectMapper = new ObjectMapper();
private List<FieldModel> findValueFieldsByIds(String fieldId, PropertyDefinitionModel definitionModel){
List<FieldModel> models = new ArrayList<>();
if (definitionModel == null || definitionModel.getFieldSets() == null || definitionModel.getFieldSets().isEmpty()) return models;
for (PropertyDefinitionFieldSetModel propertyDefinitionFieldSetModel : definitionModel.getFieldSets().values()){
if (propertyDefinitionFieldSetModel == null ||propertyDefinitionFieldSetModel.getItems() == null || propertyDefinitionFieldSetModel.getItems().isEmpty()) continue;
for (PropertyDefinitionFieldSetItemModel propertyDefinitionFieldSetItemModel : propertyDefinitionFieldSetModel.getItems()){
if (propertyDefinitionFieldSetItemModel == null ||propertyDefinitionFieldSetItemModel.getFields() == null || propertyDefinitionFieldSetItemModel.getFields().isEmpty()) continue;
for (Map.Entry<String, FieldModel> entry : propertyDefinitionFieldSetItemModel.getFields().entrySet()){
if (entry == null || entry.getValue() == null) continue;
if (entry.getKey().equalsIgnoreCase(fieldId)) models.add(entry.getValue());
}
}
}
return models;
}
private Set<String> extractSchematicValues(List<eu.eudat.commonmodels.models.descriptiotemplate.FieldModel> fields, PropertyDefinitionModel propertyDefinition, List<String> acceptedPidTypes, ZenodoProperties zenodoConfig) {
Set<String> values = new HashSet<>();
for(DescriptionFieldDepositModel field: fields){
//TODO: Check how to parse this values after update the logic of description persist from the main app
List<String> value =field.getValues() == null ? new ArrayList<>() : field.getValues().stream().map(x-> (String)x).filter(x-> x == null || x.isEmpty()).toList();
if(!value.isEmpty()) {
switch (field.getFieldType()) {
case FREE_TEXT:
case TEXT_AREA:
case RICH_TEXT_AREA:
case RADIO_BOX:
case DATE_PICKER:
case AUTO_COMPLETE:
case WORD_LIST:
values.addAll(value);
break;
case SERVICES:
case EXTERNAL_DATASETS:
case DATA_REPOSITORIES:
case PUB_REPOSITORIES:
case JOURNAL_REPOSITORIES:
case TAXONOMIES:
case PUBLICATIONS:
for (String s : value) {
Map<String, String> valueMap = objectMapper.readValue(s, new TypeReference<Map<String, String>>() {
});
String pid = valueMap.get(this.pidProperties.getFields().getPidName());
String pidType = valueMap.get(this.pidProperties.getFields().getPidTypeName());
if (acceptedPidTypes.contains(pidType)) {
values.add(pid);
for (eu.eudat.commonmodels.models.descriptiotemplate.FieldModel field : fields) {
if (field.getData() == null) continue;
List<FieldModel> valueFields = this.findValueFieldsByIds(field.getId(), propertyDefinition);
for (FieldModel valueField : valueFields) {
switch (field.getData().getFieldType()) {
case BOOLEAN_DECISION, FREE_TEXT, TEXT_AREA, RICH_TEXT_AREA, CHECK_BOX -> {
if (valueField.getTextValue() != null && !valueField.getTextValue().isBlank()) values.add(valueField.getTextValue());
}
case DATE_PICKER -> {
if (valueField.getDateValue() != null) values.add(DateTimeFormatter.ISO_DATE.format(valueField.getDateValue()));
}
case DATASET_IDENTIFIER, VALIDATION -> {
if (valueField.getExternalIdentifier() != null && valueField.getExternalIdentifier().getIdentifier() != null && !valueField.getExternalIdentifier().getIdentifier().isBlank()) {
values.add(valueField.getExternalIdentifier().getIdentifier());
}
}
case TAGS, CURRENCY -> {
if (valueField.getTextListValue() != null && !valueField.getTextListValue().isEmpty()) {
values.addAll(valueField.getTextListValue());
}
}
case SELECT -> {
if (valueField.getTextListValue() != null && !valueField.getTextListValue().isEmpty()) {
SelectDataModel selectDataModel = (SelectDataModel)field.getData();
if (selectDataModel != null && selectDataModel.getOptions() != null && !selectDataModel.getOptions().isEmpty()){
for (SelectDataModel.OptionModel option : selectDataModel.getOptions()){
if (valueField.getTextListValue().contains(option.getValue()) || valueField.getTextListValue().contains(option.getLabel())) values.add(option.getLabel());
}
}
}
break;
case ORGANIZATIONS:
case RESEARCHERS:
for (String s : value) {
Map<String, String> valueMap = objectMapper.readValue(s, new TypeReference<Map<String, String>>() {});
String pid = valueMap.get("reference");
if(pid != null) {
values.add(pid);
}
case RADIO_BOX -> {
if (valueField.getTextListValue() != null && !valueField.getTextListValue().isEmpty()) {
RadioBoxDataModel radioBoxModel = (RadioBoxDataModel)field.getData();
if (radioBoxModel != null && radioBoxModel.getOptions() != null && !radioBoxModel.getOptions().isEmpty()){
for (RadioBoxDataModel.RadioBoxOptionModel option : radioBoxModel.getOptions()){
if (valueField.getTextListValue().contains(option.getValue()) || valueField.getTextListValue().contains(option.getLabel())) values.add(option.getLabel());
}
}
}
break;
case DATASET_IDENTIFIER:
for (String s : value) {
Map<String, String> valueMap = objectMapper.readValue(s, new TypeReference<Map<String, String>>() {});
values.add(valueMap.get("identifier"));
}
case REFERENCE_TYPES -> {
if (valueField.getReferences() != null && !valueField.getReferences().isEmpty()) {
for (ReferenceModel referenceModel : valueField.getReferences()) {
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.getReference() != null && !referenceModel.getReference().isBlank()) {
values.add(referenceModel.getReference());
}
} else {
String pid = referenceModel.getDefinition().getFields().stream().filter(x -> x.getCode() != null && x.getCode().equals(this.pidProperties.getFields().getPidName())).map(ReferenceFieldModel::getValue).findFirst().orElse(null);
String pidType = referenceModel.getDefinition().getFields().stream().filter(x -> x.getCode() != null && x.getCode().equals(this.pidProperties.getFields().getPidTypeName())).map(ReferenceFieldModel::getValue).findFirst().orElse(null);
if (pid != null && !pid.isBlank() && pidType != null && !pidType.isBlank() && acceptedPidTypes.contains(pidType)) {
values.add(pid);
}
}
}
}
break;
}
case INTERNAL_ENTRIES_DESCRIPTIONS, INTERNAL_ENTRIES_DMPS, UPLOAD -> throw new RuntimeException("Invalid type " + field.getData().getFieldType());
default -> throw new RuntimeException("Invalid type " + field.getData().getFieldType());
}
}
}
return values;
}
private List<ReferenceDepositModel> getReferenceDepositModelOfType(DmpDepositModel dmp, ReferenceType referenceType){
private List<ReferenceModel> getReferenceModelOfType(DmpModel dmp, String code){
if (dmp.getReferences() == null) return new ArrayList<>();
return dmp.getReferences().stream().filter(x -> x.getType().equals(referenceType)).toList();
return dmp.getReferences().stream().filter(x -> x.getType() != null && x.getType().getCode().equals(code)).toList();
}
private void applyZenodoRelator(DmpDepositModel dmp, ZenodoDeposit deposit) throws JsonProcessingException {
private void applyZenodoRelator(DmpModel dmp, ZenodoDeposit deposit, ZenodoProperties zenodoConfig) {
if (deposit.getMetadata() == null) deposit.setMetadata(new ZenodoDepositMetadata());
List<String> acceptedPidTypes = this.pidProperties.getAcceptedTypes();
List<ZenodoRelator> relatedIdentifiers = new ArrayList<>();
for(DescriptionDepositModel descriptionDepositModel: dmp.getDescriptions()){
for(DescriptionModel descriptionModel: dmp.getDescriptions()){
for(String relatedId: this.identifierProperties.getRelated()){
List<DescriptionFieldDepositModel> fields = findSchematicValues(relatedId, descriptionDepositModel.getFields());
Set<String> values = extractSchematicValues(fields, acceptedPidTypes);
List<eu.eudat.commonmodels.models.descriptiotemplate.FieldModel> fields = this.findSchematicValues(relatedId, descriptionModel.getDescriptionTemplate().getDefinition());
Set<String> values = extractSchematicValues(fields, descriptionModel.getProperties(), acceptedPidTypes, zenodoConfig);
for(String value: values){
ZenodoRelator relator = new ZenodoRelator();
relator.setRelation(relatedId.substring(relatedId.lastIndexOf(".") + 1));
@ -161,7 +188,7 @@ public class ZenodoBuilder {
deposit.getMetadata().setRelatedIdentifiers(relatedIdentifiers);
}
private void applyAccessRight(DmpDepositModel dmp, ZenodoDeposit deposit){
private void applyAccessRight(DmpModel dmp, ZenodoDeposit deposit){
if (deposit.getMetadata() == null) deposit.setMetadata(new ZenodoDepositMetadata());
if (dmp.getAccessType() == null) {
@ -185,7 +212,7 @@ public class ZenodoBuilder {
}
}
private void applyIsIdenticalTo(DmpDepositModel dmp, ZenodoDeposit deposit, ZenodoProperties zenodoConfig){
private void applyIsIdenticalTo(DmpModel dmp, ZenodoDeposit deposit, ZenodoProperties zenodoConfig){
if (deposit.getMetadata() == null) deposit.setMetadata(new ZenodoDepositMetadata());
if (dmp.getAccessType().equals(DmpAccessType.Public)) {
@ -197,33 +224,32 @@ public class ZenodoBuilder {
}
}
private void applyLicenses(DmpDepositModel dmp, ZenodoDeposit deposit){
private void applyLicenses(DmpModel dmp, ZenodoDeposit deposit, ZenodoProperties zenodoConfig){
if (deposit.getMetadata() == null) deposit.setMetadata(new ZenodoDepositMetadata());
List<ReferenceDepositModel> dmpLicenses = this.getReferenceDepositModelOfType(dmp, ReferenceType.Licenses);
List<ReferenceModel> dmpLicenses = this.getReferenceModelOfType(dmp, zenodoConfig.getDepositConfiguration().getResearcherReferenceCode());
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);
for (ReferenceModel dmpLicense : dmpLicenses) {
if (dmpLicense != null && dmpLicense.getReference() != null && !dmpLicense.getReference().isBlank()) {
deposit.getMetadata().setLicense(dmpLicense.getReference());
break;
}
}
}
}
private void applyResearchers(DmpDepositModel dmp, ZenodoDeposit deposit){
private void applyResearchers(DmpModel dmp, ZenodoDeposit deposit, ZenodoProperties zenodoConfig){
if (deposit.getMetadata() == null) deposit.setMetadata(new ZenodoDepositMetadata());
List<ZenodoContributor> researchers = new ArrayList<>();
List<ReferenceDepositModel> dmpResearchers = this.getReferenceDepositModelOfType(dmp, ReferenceType.Researcher);
List<ReferenceModel> dmpResearchers = this.getReferenceModelOfType(dmp, zenodoConfig.getDepositConfiguration().getResearcherReferenceCode());
if (dmpResearchers != null && !dmpResearchers.isEmpty()) {
for (ReferenceDepositModel researcher : dmpResearchers) {
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(SOURCE_ORCID)) {
if (researcher.getSource().equalsIgnoreCase(zenodoConfig.getDepositConfiguration().getOrcidResearcherSourceCode())) {
contributor.setOrcid(researcher.getReference());
}
researchers.add(contributor);
@ -235,20 +261,19 @@ public class ZenodoBuilder {
deposit.getMetadata().getContributors().addAll(researchers);
}
private void applyGrants(DmpDepositModel dmp, ZenodoDeposit deposit){
private void applyGrants(DmpModel dmp, ZenodoDeposit deposit, ZenodoProperties zenodoConfig){
if (deposit.getMetadata() == null) deposit.setMetadata(new ZenodoDepositMetadata());
List<ReferenceDepositModel> dmpGrants = this.getReferenceDepositModelOfType(dmp, ReferenceType.Grants);
List<ReferenceDepositModel> dmpFunders = this.getReferenceDepositModelOfType(dmp, ReferenceType.Funder);
List<ReferenceModel> dmpGrants = this.getReferenceModelOfType(dmp, zenodoConfig.getDepositConfiguration().getGrantReferenceCode());
List<ReferenceModel> dmpFunders = this.getReferenceModelOfType(dmp, zenodoConfig.getDepositConfiguration().getFunderReferenceCode());
if (dmpGrants != null && !dmpGrants.isEmpty()) {
ReferenceDepositModel depositGrant = dmpGrants.stream().filter(x-> x.getSource().equals(SOURCE_OPENAIRE)).findFirst().orElse(null);
ReferenceModel depositGrant = dmpGrants.stream().filter(x-> x.getSource().equalsIgnoreCase(zenodoConfig.getDepositConfiguration().getOpenaireGrantSourceCode())).findFirst().orElse(null);
if (depositGrant != null) {
String grantReferenceTail = depositGrant.getReference().split(":")[2];
List<FunderProperties.DoiFunder> doiFunders = this.funderProperties.getAvailable();
if (dmpFunders != null && !dmpFunders.isEmpty()) {
ReferenceDepositModel depositFunder = dmpFunders.get(0);
ReferenceModel depositFunder = dmpFunders.get(0);
FunderProperties.DoiFunder doiFunder = doiFunders.stream()
.filter(doiFunder1 -> depositFunder.getLabel().contains(doiFunder1.getFunder()) || doiFunder1.getFunder().contains(depositFunder.getLabel()))
.findFirst().orElse(null);
@ -264,21 +289,21 @@ public class ZenodoBuilder {
}
}
private void applyContributors(DmpDepositModel dmp, ZenodoDeposit deposit, ZenodoProperties zenodoConfig){
private void applyContributors(DmpModel dmp, ZenodoDeposit deposit, ZenodoProperties zenodoConfig){
if (dmp.getUsers() == null) return;
if (deposit.getMetadata() == null) deposit.setMetadata(new ZenodoDepositMetadata());
List<ReferenceDepositModel> dmpOrganizations = this.getReferenceDepositModelOfType(dmp, ReferenceType.Organizations);
List<ReferenceModel> dmpOrganizations = this.getReferenceModelOfType(dmp, zenodoConfig.getDepositConfiguration().getOrganizationReferenceCode());
String zenodoAffiliation = zenodoConfig.getAffiliation();
List<ZenodoContributor> contributors = new ArrayList<>();
for (DmpUserDepositModel userDMP: dmp.getUsers()) {
for (DmpUserModel userDMP: dmp.getUsers()) {
ZenodoContributor contributor = new ZenodoContributor();
contributor.setName(userDMP.getUser().getName());
contributor.setType(CONTRIBUTOR_TYPE_PROJECT_MANAGER);
if (dmpOrganizations != null && !dmpOrganizations.isEmpty()) {
contributor.setAffiliation(dmpOrganizations.stream().map(ReferenceDepositModel::getLabel).collect(Collectors.joining(", ")));
contributor.setAffiliation(dmpOrganizations.stream().map(ReferenceModel::getLabel).collect(Collectors.joining(", ")));
} else {
if(zenodoAffiliation != null && !zenodoAffiliation.isEmpty()) {
contributor.setAffiliation(zenodoAffiliation);
@ -292,21 +317,21 @@ public class ZenodoBuilder {
}
private void applyCreators(DmpDepositModel dmp, ZenodoDeposit deposit, ZenodoProperties zenodoConfig){
private void applyCreators(DmpModel dmp, ZenodoDeposit deposit, ZenodoProperties zenodoConfig){
if (dmp.getUsers() == null) return;
if (deposit.getMetadata() == null) deposit.setMetadata(new ZenodoDepositMetadata());
List<ReferenceDepositModel> dmpOrganizations = this.getReferenceDepositModelOfType(dmp, ReferenceType.Organizations);
List<ReferenceModel> dmpOrganizations = this.getReferenceModelOfType(dmp, zenodoConfig.getDepositConfiguration().getOrganizationReferenceCode());
String zenodoAffiliation = zenodoConfig.getAffiliation();
ZenodoCreator creator = new ZenodoCreator();
DmpUserDepositModel dmpDepositModel = dmp.getUsers().stream().filter(userDMP -> userDMP.getRole().equals(DmpUserRole.Owner)).findFirst().orElse(null);
if (dmpDepositModel == null || dmpDepositModel.getUser() == null) return;
DmpUserModel dmpModel = dmp.getUsers().stream().filter(userDMP -> userDMP.getRole().equals(DmpUserRole.Owner)).findFirst().orElse(null);
if (dmpModel == null || dmpModel.getUser() == null) return;
creator.setName(dmpDepositModel.getUser().getName());
creator.setName(dmpModel.getUser().getName());
if (dmpOrganizations != null && !dmpOrganizations.isEmpty()) {
creator.setAffiliation(dmpOrganizations.stream().map(ReferenceDepositModel::getLabel).collect(Collectors.joining(", ")));
creator.setAffiliation(dmpOrganizations.stream().map(ReferenceModel::getLabel).collect(Collectors.joining(", ")));
} else {
if(zenodoAffiliation != null && !zenodoAffiliation.isEmpty()) {
creator.setAffiliation(zenodoAffiliation);

View File

@ -1,10 +1,10 @@
package eu.eudat.depositinterface.zenodorepository.service;
import eu.eudat.depositinterface.models.DmpDepositModel;
import eu.eudat.commonmodels.models.DmpModel;
import eu.eudat.depositinterface.repository.DepositConfiguration;
public interface ZenodoDepositService {
String deposit(DmpDepositModel dmpDepositModel, String zenodoToken) throws Exception;
String deposit(DmpModel dmpDepositModel, String zenodoToken) throws Exception;
DepositConfiguration getConfiguration();

View File

@ -1,8 +1,8 @@
package eu.eudat.depositinterface.zenodorepository.service;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.depositinterface.models.DmpDepositModel;
import eu.eudat.depositinterface.models.FileEnvelope;
import eu.eudat.commonmodels.models.DmpModel;
import eu.eudat.commonmodels.models.FileEnvelopeModel;
import eu.eudat.depositinterface.repository.DepositConfiguration;
import eu.eudat.depositinterface.zenodorepository.configuration.zenodo.ZenodoProperties;
import eu.eudat.depositinterface.zenodorepository.model.ZenodoDeposit;
@ -60,7 +60,7 @@ public class ZenodoDepositServiceImpl implements ZenodoDepositService {
}
@Override
public String deposit(DmpDepositModel dmpDepositModel, String zenodoToken) throws Exception {
public String deposit(DmpModel dmpModel, String zenodoToken) throws Exception {
DepositConfiguration depositConfiguration = this.getConfiguration();
@ -77,10 +77,10 @@ public class ZenodoDepositServiceImpl implements ZenodoDepositService {
DepositConfiguration zenodoConfig = this.zenodoProperties.getDepositConfiguration();
if (zenodoConfig == null) return null;
eu.eudat.depositinterface.zenodorepository.model.ZenodoDeposit deposit = mapper.build(dmpDepositModel, this.zenodoProperties);
eu.eudat.depositinterface.zenodorepository.model.ZenodoDeposit deposit = mapper.build(dmpModel, this.zenodoProperties);
LinkedHashMap<String, String> links;
String previousDOI = dmpDepositModel.getPreviousDOI();
String previousDOI = dmpModel.getPreviousDOI();
String unpublishedUrl = null;
String publishUrl;
try {
@ -88,7 +88,7 @@ public class ZenodoDepositServiceImpl implements ZenodoDepositService {
if (previousDOI == null) {
links = deposit(zenodoToken, zenodoUrl, zenodoClient, deposit);
} else {
unpublishedUrl = this.getUnpublishedDOI(zenodoUrl, previousDOI, zenodoToken, dmpDepositModel.getVersion());
unpublishedUrl = this.getUnpublishedDOI(zenodoUrl, previousDOI, zenodoToken, dmpModel.getVersion());
if (unpublishedUrl == null) {
//It requires more than one step to create a new version
//First, get the deposit related to the concept DOI
@ -100,7 +100,7 @@ public class ZenodoDepositServiceImpl implements ZenodoDepositService {
if (unpublishedUrl == null) {
// Second step, add the file to the entry.
FileEnvelope pdfEnvelope = dmpDepositModel.getPdfFile();
FileEnvelopeModel pdfEnvelope = dmpModel.getPdfFile();
if (links == null || !links.containsKey(ZENODO_LINKS_BUCKET)) throw new Exception("bucket not found");
@ -109,14 +109,14 @@ public class ZenodoDepositServiceImpl implements ZenodoDepositService {
.body(BodyInserters
.fromResource(new ByteArrayResource(pdfEnvelope.getFile())))
.retrieve().toEntity(Map.class).block();
FileEnvelope rdaJsonEnvelope = dmpDepositModel.getRdaJsonFile();
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();
if (dmpDepositModel.getSupportingFilesZip() != null) {
String supportingFilesZipName = dmpDepositModel.getSupportingFilesZip().getFilename();
if (dmpModel.getSupportingFilesZip() != null) {
String supportingFilesZipName = dmpModel.getSupportingFilesZip().getFilename();
addFileUrl = links.get(ZENODO_LINKS_BUCKET) + "/" + supportingFilesZipName + "?access_token=" + zenodoToken;
zenodoClient.put().uri(addFileUrl).body(BodyInserters.fromResource(new ByteArrayResource(supportingFilesZipName.getBytes()))).retrieve().toEntity(Map.class).block();

View File

@ -1,6 +1,6 @@
package eu.eudat.deposit.controller;
import eu.eudat.depositinterface.models.DmpDepositModel;
import eu.eudat.commonmodels.models.DmpModel;
import eu.eudat.depositinterface.repository.DepositConfiguration;
import eu.eudat.depositinterface.zenodorepository.service.ZenodoDepositService;
import org.springframework.beans.factory.annotation.Autowired;
@ -19,8 +19,8 @@ public class DepositController implements eu.eudat.depositinterface.repository.D
this.depositClient = depositClient;
}
public String deposit(@RequestBody DmpDepositModel dmpDepositModel, @RequestParam("authToken")String authToken) throws Exception {
return depositClient.deposit(dmpDepositModel, authToken);
public String deposit(@RequestBody DmpModel dmpModel, @RequestParam("authToken")String authToken) throws Exception {
return depositClient.deposit(dmpModel, authToken);
}
public String authenticate(@RequestParam("authToken") String code) {