rename dmp to plan
This commit is contained in:
parent
4c34f1f606
commit
5f9e1850a3
|
@ -11,15 +11,15 @@ After creating the jar from the project, environment variables should be set sin
|
||||||
### JSON configuration file
|
### JSON configuration file
|
||||||
|
|
||||||
The following fields should be set:<br>
|
The following fields should be set:<br>
|
||||||
**depositType** - an integer representing how the dmp user can deposit in the repository,<br>
|
**depositType** - an integer representing how the plan user can deposit in the repository,<br>
|
||||||
a. **0** stands for system deposition meaning the dmp is deposited using argos credentials to the repository,<br>
|
a. **0** stands for system deposition meaning the plan is deposited using argos credentials to the repository,<br>
|
||||||
b. **1** stands for user deposition in which the argos user specifies his/her own credentials to the repository,<br>
|
b. **1** stands for user deposition in which the argos user specifies his/her own credentials to the repository,<br>
|
||||||
c. **2** stands for both ways deposition if the repository allows the deposits of dmps to be made from both argos and users accounts<br>
|
c. **2** stands for both ways deposition if the repository allows the deposits of plans to be made from both argos and users accounts<br>
|
||||||
**repositoryId** - unique identifier for the repository<br>
|
**repositoryId** - unique identifier for the repository<br>
|
||||||
**accessToken** - access token provided for the system type deposits<br>
|
**accessToken** - access token provided for the system type deposits<br>
|
||||||
**repositoryUrl** - repository's api url e.g "https://sandbox.zenodo.org/api/" <br>
|
**repositoryUrl** - repository's api url e.g "https://sandbox.zenodo.org/api/" <br>
|
||||||
**repositoryAuthorizationUrl** - repository's authorization url e.g. "https://sandbox.zenodo.org/oauth/authorize" <br>
|
**repositoryAuthorizationUrl** - repository's authorization url e.g. "https://sandbox.zenodo.org/oauth/authorize" <br>
|
||||||
**repositoryRecordUrl** - repository's record url, this url is used to index dmps that are created e.g. "https://sandbox.zenodo.org/record/" <br>
|
**repositoryRecordUrl** - repository's record url, this url is used to index plans that are created e.g. "https://sandbox.zenodo.org/record/" <br>
|
||||||
**repositoryAccessTokenUrl** - repository's access token url e.g. "https://sandbox.zenodo.org/oauth/token" <br>
|
**repositoryAccessTokenUrl** - repository's access token url e.g. "https://sandbox.zenodo.org/oauth/token" <br>
|
||||||
**repositoryClientId** - repository's client id<br>
|
**repositoryClientId** - repository's client id<br>
|
||||||
**repositoryClientSecret** - repository's client secret<br>
|
**repositoryClientSecret** - repository's client secret<br>
|
||||||
|
|
|
@ -2,17 +2,17 @@ package org.opencdmp.deposit.zenodorepository.model.builder;
|
||||||
|
|
||||||
import gr.cite.tools.exception.MyApplicationException;
|
import gr.cite.tools.exception.MyApplicationException;
|
||||||
import gr.cite.tools.logging.LoggerService;
|
import gr.cite.tools.logging.LoggerService;
|
||||||
import org.opencdmp.commonmodels.enums.DmpAccessType;
|
import org.opencdmp.commonmodels.enums.PlanAccessType;
|
||||||
import org.opencdmp.commonmodels.enums.DmpUserRole;
|
import org.opencdmp.commonmodels.enums.PlanUserRole;
|
||||||
import org.opencdmp.commonmodels.models.DmpUserModel;
|
import org.opencdmp.commonmodels.models.PlanUserModel;
|
||||||
import org.opencdmp.commonmodels.models.description.*;
|
import org.opencdmp.commonmodels.models.description.*;
|
||||||
import org.opencdmp.commonmodels.models.descriptiotemplate.DefinitionModel;
|
import org.opencdmp.commonmodels.models.descriptiotemplate.DefinitionModel;
|
||||||
import org.opencdmp.commonmodels.models.descriptiotemplate.fielddata.RadioBoxDataModel;
|
import org.opencdmp.commonmodels.models.descriptiotemplate.fielddata.RadioBoxDataModel;
|
||||||
import org.opencdmp.commonmodels.models.descriptiotemplate.fielddata.SelectDataModel;
|
import org.opencdmp.commonmodels.models.descriptiotemplate.fielddata.SelectDataModel;
|
||||||
import org.opencdmp.commonmodels.models.dmp.DmpBlueprintValueModel;
|
import org.opencdmp.commonmodels.models.plan.PlanBlueprintValueModel;
|
||||||
import org.opencdmp.commonmodels.models.dmp.DmpModel;
|
import org.opencdmp.commonmodels.models.plan.PlanModel;
|
||||||
import org.opencdmp.commonmodels.models.dmpblueprint.SectionModel;
|
import org.opencdmp.commonmodels.models.planblueprint.SectionModel;
|
||||||
import org.opencdmp.commonmodels.models.dmpreference.DmpReferenceModel;
|
import org.opencdmp.commonmodels.models.planreference.PlanReferenceModel;
|
||||||
import org.opencdmp.commonmodels.models.reference.ReferenceFieldModel;
|
import org.opencdmp.commonmodels.models.reference.ReferenceFieldModel;
|
||||||
import org.opencdmp.commonmodels.models.reference.ReferenceModel;
|
import org.opencdmp.commonmodels.models.reference.ReferenceModel;
|
||||||
import org.opencdmp.deposit.zenodorepository.configuration.funder.FunderProperties;
|
import org.opencdmp.deposit.zenodorepository.configuration.funder.FunderProperties;
|
||||||
|
@ -29,9 +29,7 @@ import org.springframework.context.annotation.Scope;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.ZoneOffset;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
@ -61,14 +59,14 @@ public class ZenodoBuilder {
|
||||||
this.zenodoServiceProperties = zenodoServiceProperties;
|
this.zenodoServiceProperties = zenodoServiceProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ZenodoDeposit build(DmpModel dmp) {
|
public ZenodoDeposit build(PlanModel plan) {
|
||||||
ZenodoDeposit deposit = new ZenodoDeposit();
|
ZenodoDeposit deposit = new ZenodoDeposit();
|
||||||
this.applyZenodoRelator(dmp, deposit);
|
this.applyZenodoRelator(plan, deposit);
|
||||||
deposit.getMetadata().setTitle(dmp.getLabel());
|
deposit.getMetadata().setTitle(plan.getLabel());
|
||||||
deposit.getMetadata().setUploadType(UPLOAD_TYPE);
|
deposit.getMetadata().setUploadType(UPLOAD_TYPE);
|
||||||
deposit.getMetadata().setPublicationType(PUBLICATION_TYPE);
|
deposit.getMetadata().setPublicationType(PUBLICATION_TYPE);
|
||||||
deposit.getMetadata().setDescription((dmp.getDescription() != null && !dmp.getDescription().isEmpty() ? dmp.getDescription() : "<p></p>"));
|
deposit.getMetadata().setDescription((plan.getDescription() != null && !plan.getDescription().isEmpty() ? plan.getDescription() : "<p></p>"));
|
||||||
deposit.getMetadata().setVersion(String.valueOf(dmp.getVersion()));
|
deposit.getMetadata().setVersion(String.valueOf(plan.getVersion()));
|
||||||
String zenodoCommunity = zenodoServiceProperties.getCommunity();
|
String zenodoCommunity = zenodoServiceProperties.getCommunity();
|
||||||
if(zenodoCommunity != null && !zenodoCommunity.isEmpty()) {
|
if(zenodoCommunity != null && !zenodoCommunity.isEmpty()) {
|
||||||
if (deposit.getMetadata().getCommunities() == null) deposit.getMetadata().setCommunities(new ArrayList<>());
|
if (deposit.getMetadata().getCommunities() == null) deposit.getMetadata().setCommunities(new ArrayList<>());
|
||||||
|
@ -77,41 +75,41 @@ public class ZenodoBuilder {
|
||||||
deposit.getMetadata().getCommunities().add(community);
|
deposit.getMetadata().getCommunities().add(community);
|
||||||
}
|
}
|
||||||
|
|
||||||
org.opencdmp.commonmodels.models.dmpblueprint.FieldModel fieldOfSemantic = this.getFieldOfSemantic(dmp, SEMANTIC_PUBLICATION_DATE);
|
org.opencdmp.commonmodels.models.planblueprint.FieldModel fieldOfSemantic = this.getFieldOfSemantic(plan, SEMANTIC_PUBLICATION_DATE);
|
||||||
if (fieldOfSemantic != null){
|
if (fieldOfSemantic != null){
|
||||||
DmpBlueprintValueModel dmpBlueprintValueModel = this.getDmpBlueprintValue(dmp, fieldOfSemantic.getId());
|
PlanBlueprintValueModel planBlueprintValueModel = this.getPlanBlueprintValue(plan, fieldOfSemantic.getId());
|
||||||
if (dmpBlueprintValueModel != null && dmpBlueprintValueModel.getDateValue() != null) {
|
if (planBlueprintValueModel != null && planBlueprintValueModel.getDateValue() != null) {
|
||||||
deposit.getMetadata().setPublicationDate(DateTimeFormatter.ofPattern("yyyy-MM-dd").withZone(ZoneId.systemDefault()).format(dmpBlueprintValueModel.getDateValue()));
|
deposit.getMetadata().setPublicationDate(DateTimeFormatter.ofPattern("yyyy-MM-dd").withZone(ZoneId.systemDefault()).format(planBlueprintValueModel.getDateValue()));
|
||||||
} else if (dmpBlueprintValueModel != null && dmpBlueprintValueModel.getValue() != null && !dmpBlueprintValueModel.getValue().isBlank()){
|
} else if (planBlueprintValueModel != null && planBlueprintValueModel.getValue() != null && !planBlueprintValueModel.getValue().isBlank()){
|
||||||
try {
|
try {
|
||||||
Instant instant = Instant.parse(dmpBlueprintValueModel.getValue());
|
Instant instant = Instant.parse(planBlueprintValueModel.getValue());
|
||||||
deposit.getMetadata().setPublicationDate(DateTimeFormatter.ofPattern("yyyy-MM-dd").withZone(ZoneId.systemDefault()).format(instant));
|
deposit.getMetadata().setPublicationDate(DateTimeFormatter.ofPattern("yyyy-MM-dd").withZone(ZoneId.systemDefault()).format(instant));
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
logger.error(e.getMessage(), e);
|
logger.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.applyAccessRight(dmp, deposit);
|
this.applyAccessRight(plan, deposit);
|
||||||
this.applyIsIdenticalTo(dmp, deposit);
|
this.applyIsIdenticalTo(plan, deposit);
|
||||||
this.applyLicenses(dmp, deposit);
|
this.applyLicenses(plan, deposit);
|
||||||
this.applyResearchers(dmp, deposit);
|
this.applyResearchers(plan, deposit);
|
||||||
this.applyGrants(dmp, deposit);
|
this.applyGrants(plan, deposit);
|
||||||
this.applyContributors(dmp, deposit);
|
this.applyContributors(plan, deposit);
|
||||||
this.applyCreators(dmp, deposit);
|
this.applyCreators(plan, deposit);
|
||||||
|
|
||||||
return deposit;
|
return deposit;
|
||||||
}
|
}
|
||||||
|
|
||||||
private DmpBlueprintValueModel getDmpBlueprintValue(DmpModel dmp, UUID id){
|
private PlanBlueprintValueModel getPlanBlueprintValue(PlanModel plan, UUID id){
|
||||||
if (dmp == null || dmp.getProperties() == null || dmp.getProperties().getDmpBlueprintValues() == null) return null;
|
if (plan == null || plan.getProperties() == null || plan.getProperties().getPlanBlueprintValues() == null) return null;
|
||||||
return dmp.getProperties().getDmpBlueprintValues().stream().filter(x-> x.getFieldId().equals(id)).findFirst().orElse(null);
|
return plan.getProperties().getPlanBlueprintValues().stream().filter(x-> x.getFieldId().equals(id)).findFirst().orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private org.opencdmp.commonmodels.models.dmpblueprint.FieldModel getFieldOfSemantic(DmpModel dmp, String semanticKey){
|
private org.opencdmp.commonmodels.models.planblueprint.FieldModel getFieldOfSemantic(PlanModel plan, String semanticKey){
|
||||||
if (dmp == null || dmp.getDmpBlueprint() == null || dmp.getDmpBlueprint().getDefinition() == null || dmp.getDmpBlueprint().getDefinition().getSections() == null) return null;
|
if (plan == null || plan.getPlanBlueprint() == null || plan.getPlanBlueprint().getDefinition() == null || plan.getPlanBlueprint().getDefinition().getSections() == null) return null;
|
||||||
for (SectionModel sectionModel : dmp.getDmpBlueprint().getDefinition().getSections()){
|
for (SectionModel sectionModel : plan.getPlanBlueprint().getDefinition().getSections()){
|
||||||
if (sectionModel.getFields() != null){
|
if (sectionModel.getFields() != null){
|
||||||
org.opencdmp.commonmodels.models.dmpblueprint.FieldModel fieldModel = sectionModel.getFields().stream().filter(x-> x.getSemantics() != null && x.getSemantics().contains(semanticKey)).findFirst().orElse(null);
|
org.opencdmp.commonmodels.models.planblueprint.FieldModel fieldModel = sectionModel.getFields().stream().filter(x-> x.getSemantics() != null && x.getSemantics().contains(semanticKey)).findFirst().orElse(null);
|
||||||
if (fieldModel != null) return fieldModel;
|
if (fieldModel != null) return fieldModel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -204,7 +202,7 @@ public class ZenodoBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case INTERNAL_ENTRIES_DESCRIPTIONS, INTERNAL_ENTRIES_DMPS, UPLOAD -> throw new MyApplicationException("Invalid type " + field.getData().getFieldType());
|
case INTERNAL_ENTRIES_DESCRIPTIONS, INTERNAL_ENTRIES_PlANS, UPLOAD -> throw new MyApplicationException("Invalid type " + field.getData().getFieldType());
|
||||||
default -> throw new MyApplicationException("Invalid type " + field.getData().getFieldType());
|
default -> throw new MyApplicationException("Invalid type " + field.getData().getFieldType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -212,23 +210,23 @@ public class ZenodoBuilder {
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ReferenceModel> getReferenceModelOfType(DmpModel dmp, String code){
|
private List<ReferenceModel> getReferenceModelOfType(PlanModel plan, String code){
|
||||||
List<ReferenceModel> response = new ArrayList<>();
|
List<ReferenceModel> response = new ArrayList<>();
|
||||||
if (dmp.getReferences() == null) return response;
|
if (plan.getReferences() == null) return response;
|
||||||
for (DmpReferenceModel dmpReferenceModel : dmp.getReferences()){
|
for (PlanReferenceModel planReferenceModel : plan.getReferences()){
|
||||||
if (dmpReferenceModel.getReference() != null && dmpReferenceModel.getReference().getType() != null && dmpReferenceModel.getReference().getType().getCode() != null && dmpReferenceModel.getReference().getType().getCode().equals(code)){
|
if (planReferenceModel.getReference() != null && planReferenceModel.getReference().getType() != null && planReferenceModel.getReference().getType().getCode() != null && planReferenceModel.getReference().getType().getCode().equals(code)){
|
||||||
response.add(dmpReferenceModel.getReference());
|
response.add(planReferenceModel.getReference());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyZenodoRelator(DmpModel dmp, ZenodoDeposit deposit) {
|
private void applyZenodoRelator(PlanModel plan, ZenodoDeposit deposit) {
|
||||||
if (deposit.getMetadata() == null) deposit.setMetadata(new ZenodoDepositMetadata());
|
if (deposit.getMetadata() == null) deposit.setMetadata(new ZenodoDepositMetadata());
|
||||||
|
|
||||||
List<String> acceptedPidTypes = this.pidProperties.getAcceptedTypes();
|
List<String> acceptedPidTypes = this.pidProperties.getAcceptedTypes();
|
||||||
List<ZenodoRelator> relatedIdentifiers = new ArrayList<>();
|
List<ZenodoRelator> relatedIdentifiers = new ArrayList<>();
|
||||||
for(DescriptionModel descriptionModel: dmp.getDescriptions()){
|
for(DescriptionModel descriptionModel: plan.getDescriptions()){
|
||||||
for(String relatedId: this.identifierProperties.getRelated()){
|
for(String relatedId: this.identifierProperties.getRelated()){
|
||||||
List<org.opencdmp.commonmodels.models.descriptiotemplate.FieldModel> fields = this.findSchematicValues(relatedId, descriptionModel.getDescriptionTemplate().getDefinition());
|
List<org.opencdmp.commonmodels.models.descriptiotemplate.FieldModel> fields = this.findSchematicValues(relatedId, descriptionModel.getDescriptionTemplate().getDefinition());
|
||||||
Set<String> values = extractSchematicValues(fields, descriptionModel.getProperties(), acceptedPidTypes);
|
Set<String> values = extractSchematicValues(fields, descriptionModel.getProperties(), acceptedPidTypes);
|
||||||
|
@ -243,15 +241,15 @@ public class ZenodoBuilder {
|
||||||
deposit.getMetadata().setRelatedIdentifiers(relatedIdentifiers);
|
deposit.getMetadata().setRelatedIdentifiers(relatedIdentifiers);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyAccessRight(DmpModel dmp, ZenodoDeposit deposit){
|
private void applyAccessRight(PlanModel plan, ZenodoDeposit deposit){
|
||||||
if (deposit.getMetadata() == null) deposit.setMetadata(new ZenodoDepositMetadata());
|
if (deposit.getMetadata() == null) deposit.setMetadata(new ZenodoDepositMetadata());
|
||||||
|
|
||||||
if (dmp.getAccessType() == null) {
|
if (plan.getAccessType() == null) {
|
||||||
deposit.getMetadata().setAccessRight(ZenodoAccessRight.RESTRICTED);
|
deposit.getMetadata().setAccessRight(ZenodoAccessRight.RESTRICTED);
|
||||||
deposit.getMetadata().setAccessConditions("");
|
deposit.getMetadata().setAccessConditions("");
|
||||||
} else {
|
} else {
|
||||||
if (dmp.getAccessType().equals(DmpAccessType.Public)) {
|
if (plan.getAccessType().equals(PlanAccessType.Public)) {
|
||||||
Instant publicationDate = dmp.getFinalizedAt();
|
Instant publicationDate = plan.getFinalizedAt();
|
||||||
if (publicationDate == null) publicationDate = Instant.now().minusSeconds(1);
|
if (publicationDate == null) publicationDate = Instant.now().minusSeconds(1);
|
||||||
|
|
||||||
if (publicationDate.isBefore(Instant.now())) {
|
if (publicationDate.isBefore(Instant.now())) {
|
||||||
|
@ -267,39 +265,39 @@ public class ZenodoBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyIsIdenticalTo(DmpModel dmp, ZenodoDeposit deposit){
|
private void applyIsIdenticalTo(PlanModel plan, ZenodoDeposit deposit){
|
||||||
if (deposit.getMetadata() == null) deposit.setMetadata(new ZenodoDepositMetadata());
|
if (deposit.getMetadata() == null) deposit.setMetadata(new ZenodoDepositMetadata());
|
||||||
|
|
||||||
if (dmp.getAccessType().equals(DmpAccessType.Public)) {
|
if (plan.getAccessType().equals(PlanAccessType.Public)) {
|
||||||
ZenodoRelator relator = new ZenodoRelator();
|
ZenodoRelator relator = new ZenodoRelator();
|
||||||
relator.setIdentifier(zenodoServiceProperties.getDomain() + "/external/zenodo/" + dmp.getId().toString());
|
relator.setIdentifier(zenodoServiceProperties.getDomain() + "/external/zenodo/" + plan.getId().toString());
|
||||||
relator.setRelation(IS_IDENTICAL_TO);
|
relator.setRelation(IS_IDENTICAL_TO);
|
||||||
if (deposit.getMetadata().getRelatedIdentifiers() == null)deposit.getMetadata().setRelatedIdentifiers(new ArrayList<>());
|
if (deposit.getMetadata().getRelatedIdentifiers() == null)deposit.getMetadata().setRelatedIdentifiers(new ArrayList<>());
|
||||||
deposit.getMetadata().getRelatedIdentifiers().add(relator);
|
deposit.getMetadata().getRelatedIdentifiers().add(relator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyLicenses(DmpModel dmp, ZenodoDeposit deposit){
|
private void applyLicenses(PlanModel plan, ZenodoDeposit deposit){
|
||||||
if (deposit.getMetadata() == null) deposit.setMetadata(new ZenodoDepositMetadata());
|
if (deposit.getMetadata() == null) deposit.setMetadata(new ZenodoDepositMetadata());
|
||||||
|
|
||||||
List<ReferenceModel> dmpLicenses = this.getReferenceModelOfType(dmp, zenodoServiceProperties.getLicensesReferenceCode());
|
List<ReferenceModel> planLicenses = this.getReferenceModelOfType(plan, zenodoServiceProperties.getLicensesReferenceCode());
|
||||||
if (!dmpLicenses.isEmpty()) {
|
if (!planLicenses.isEmpty()) {
|
||||||
for (ReferenceModel dmpLicense : dmpLicenses) {
|
for (ReferenceModel planLicense : planLicenses) {
|
||||||
if (dmpLicense != null && dmpLicense.getReference() != null && !dmpLicense.getReference().isBlank()) {
|
if (planLicense != null && planLicense.getReference() != null && !planLicense.getReference().isBlank()) {
|
||||||
deposit.getMetadata().setLicense(dmpLicense.getReference());
|
deposit.getMetadata().setLicense(planLicense.getReference());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyResearchers(DmpModel dmp, ZenodoDeposit deposit){
|
private void applyResearchers(PlanModel plan, ZenodoDeposit deposit){
|
||||||
if (deposit.getMetadata() == null) deposit.setMetadata(new ZenodoDepositMetadata());
|
if (deposit.getMetadata() == null) deposit.setMetadata(new ZenodoDepositMetadata());
|
||||||
|
|
||||||
List<ZenodoContributor> researchers = new ArrayList<>();
|
List<ZenodoContributor> researchers = new ArrayList<>();
|
||||||
List<ReferenceModel> dmpResearchers = this.getReferenceModelOfType(dmp, zenodoServiceProperties.getResearcherReferenceCode());
|
List<ReferenceModel> planResearchers = this.getReferenceModelOfType(plan, zenodoServiceProperties.getResearcherReferenceCode());
|
||||||
if (dmpResearchers != null && !dmpResearchers.isEmpty()) {
|
if (planResearchers != null && !planResearchers.isEmpty()) {
|
||||||
for (ReferenceModel researcher : dmpResearchers) {
|
for (ReferenceModel researcher : planResearchers) {
|
||||||
ZenodoContributor contributor = new ZenodoContributor();
|
ZenodoContributor contributor = new ZenodoContributor();
|
||||||
contributor.setName(researcher.getLabel());
|
contributor.setName(researcher.getLabel());
|
||||||
contributor.setType(CONTRIBUTOR_TYPE_RESEARCHER);
|
contributor.setType(CONTRIBUTOR_TYPE_RESEARCHER);
|
||||||
|
@ -316,19 +314,19 @@ public class ZenodoBuilder {
|
||||||
deposit.getMetadata().getContributors().addAll(researchers);
|
deposit.getMetadata().getContributors().addAll(researchers);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyGrants(DmpModel dmp, ZenodoDeposit deposit){
|
private void applyGrants(PlanModel plan, ZenodoDeposit deposit){
|
||||||
if (deposit.getMetadata() == null) deposit.setMetadata(new ZenodoDepositMetadata());
|
if (deposit.getMetadata() == null) deposit.setMetadata(new ZenodoDepositMetadata());
|
||||||
List<ReferenceModel> dmpGrants = this.getReferenceModelOfType(dmp, zenodoServiceProperties.getGrantReferenceCode());
|
List<ReferenceModel> planGrants = this.getReferenceModelOfType(plan, zenodoServiceProperties.getGrantReferenceCode());
|
||||||
List<ReferenceModel> dmpFunders = this.getReferenceModelOfType(dmp, zenodoServiceProperties.getFunderReferenceCode());
|
List<ReferenceModel> planFunders = this.getReferenceModelOfType(plan, zenodoServiceProperties.getFunderReferenceCode());
|
||||||
|
|
||||||
if (!dmpGrants.isEmpty()) {
|
if (!planGrants.isEmpty()) {
|
||||||
ReferenceModel depositGrant = dmpGrants.stream().filter(x-> x.getSource().equalsIgnoreCase(zenodoServiceProperties.getOpenaireGrantSourceCode())).findFirst().orElse(null);
|
ReferenceModel depositGrant = planGrants.stream().filter(x-> x.getSource().equalsIgnoreCase(zenodoServiceProperties.getOpenaireGrantSourceCode())).findFirst().orElse(null);
|
||||||
|
|
||||||
if (depositGrant != null) {
|
if (depositGrant != null) {
|
||||||
String grantReferenceTail = depositGrant.getReference().split(":")[2];
|
String grantReferenceTail = depositGrant.getReference().split(":")[2];
|
||||||
List<FunderProperties.DoiFunder> doiFunders = this.funderProperties.getAvailable();
|
List<FunderProperties.DoiFunder> doiFunders = this.funderProperties.getAvailable();
|
||||||
if (!dmpFunders.isEmpty()) {
|
if (!planFunders.isEmpty()) {
|
||||||
ReferenceModel depositFunder = dmpFunders.getFirst();
|
ReferenceModel depositFunder = planFunders.getFirst();
|
||||||
FunderProperties.DoiFunder doiFunder = doiFunders.stream()
|
FunderProperties.DoiFunder doiFunder = doiFunders.stream()
|
||||||
.filter(doiFunder1 -> depositFunder.getLabel().contains(doiFunder1.getFunder()) || doiFunder1.getFunder().contains(depositFunder.getLabel()))
|
.filter(doiFunder1 -> depositFunder.getLabel().contains(doiFunder1.getFunder()) || doiFunder1.getFunder().contains(depositFunder.getLabel()))
|
||||||
.findFirst().orElse(null);
|
.findFirst().orElse(null);
|
||||||
|
@ -344,21 +342,21 @@ public class ZenodoBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyContributors(DmpModel dmp, ZenodoDeposit deposit){
|
private void applyContributors(PlanModel plan, ZenodoDeposit deposit){
|
||||||
if (dmp.getUsers() == null) return;
|
if (plan.getUsers() == null) return;
|
||||||
|
|
||||||
if (deposit.getMetadata() == null) deposit.setMetadata(new ZenodoDepositMetadata());
|
if (deposit.getMetadata() == null) deposit.setMetadata(new ZenodoDepositMetadata());
|
||||||
|
|
||||||
List<ReferenceModel> dmpOrganizations = this.getReferenceModelOfType(dmp, zenodoServiceProperties.getOrganizationReferenceCode());
|
List<ReferenceModel> planOrganizations = this.getReferenceModelOfType(plan, zenodoServiceProperties.getOrganizationReferenceCode());
|
||||||
String zenodoAffiliation = zenodoServiceProperties.getAffiliation();
|
String zenodoAffiliation = zenodoServiceProperties.getAffiliation();
|
||||||
|
|
||||||
List<ZenodoContributor> contributors = new ArrayList<>();
|
List<ZenodoContributor> contributors = new ArrayList<>();
|
||||||
for (DmpUserModel userDMP: dmp.getUsers()) {
|
for (PlanUserModel planUser: plan.getUsers()) {
|
||||||
ZenodoContributor contributor = new ZenodoContributor();
|
ZenodoContributor contributor = new ZenodoContributor();
|
||||||
contributor.setName(userDMP.getUser().getName());
|
contributor.setName(planUser.getUser().getName());
|
||||||
contributor.setType(CONTRIBUTOR_TYPE_PROJECT_MANAGER);
|
contributor.setType(CONTRIBUTOR_TYPE_PROJECT_MANAGER);
|
||||||
if (dmpOrganizations != null && !dmpOrganizations.isEmpty()) {
|
if (planOrganizations != null && !planOrganizations.isEmpty()) {
|
||||||
contributor.setAffiliation(dmpOrganizations.stream().map(ReferenceModel::getLabel).collect(Collectors.joining(", ")));
|
contributor.setAffiliation(planOrganizations.stream().map(ReferenceModel::getLabel).collect(Collectors.joining(", ")));
|
||||||
} else {
|
} else {
|
||||||
if(zenodoAffiliation != null && !zenodoAffiliation.isEmpty()) {
|
if(zenodoAffiliation != null && !zenodoAffiliation.isEmpty()) {
|
||||||
contributor.setAffiliation(zenodoAffiliation);
|
contributor.setAffiliation(zenodoAffiliation);
|
||||||
|
@ -372,21 +370,21 @@ public class ZenodoBuilder {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void applyCreators(DmpModel dmp, ZenodoDeposit deposit){
|
private void applyCreators(PlanModel plan, ZenodoDeposit deposit){
|
||||||
if (dmp.getUsers() == null) return;
|
if (plan.getUsers() == null) return;
|
||||||
|
|
||||||
if (deposit.getMetadata() == null) deposit.setMetadata(new ZenodoDepositMetadata());
|
if (deposit.getMetadata() == null) deposit.setMetadata(new ZenodoDepositMetadata());
|
||||||
|
|
||||||
List<ReferenceModel> dmpOrganizations = this.getReferenceModelOfType(dmp, zenodoServiceProperties.getOrganizationReferenceCode());
|
List<ReferenceModel> planOrganizations = this.getReferenceModelOfType(plan, zenodoServiceProperties.getOrganizationReferenceCode());
|
||||||
String zenodoAffiliation = zenodoServiceProperties.getAffiliation();
|
String zenodoAffiliation = zenodoServiceProperties.getAffiliation();
|
||||||
|
|
||||||
ZenodoCreator creator = new ZenodoCreator();
|
ZenodoCreator creator = new ZenodoCreator();
|
||||||
DmpUserModel dmpModel = dmp.getUsers().stream().filter(userDMP -> userDMP.getRole().equals(DmpUserRole.Owner)).findFirst().orElse(null);
|
PlanUserModel planModel = plan.getUsers().stream().filter(planUser -> planUser.getRole().equals(PlanUserRole.Owner)).findFirst().orElse(null);
|
||||||
if (dmpModel == null || dmpModel.getUser() == null) return;
|
if (planModel == null || planModel.getUser() == null) return;
|
||||||
|
|
||||||
creator.setName(dmpModel.getUser().getName());
|
creator.setName(planModel.getUser().getName());
|
||||||
if (dmpOrganizations != null && !dmpOrganizations.isEmpty()) {
|
if (planOrganizations != null && !planOrganizations.isEmpty()) {
|
||||||
creator.setAffiliation(dmpOrganizations.stream().map(ReferenceModel::getLabel).collect(Collectors.joining(", ")));
|
creator.setAffiliation(planOrganizations.stream().map(ReferenceModel::getLabel).collect(Collectors.joining(", ")));
|
||||||
} else {
|
} else {
|
||||||
if(zenodoAffiliation != null && !zenodoAffiliation.isEmpty()) {
|
if(zenodoAffiliation != null && !zenodoAffiliation.isEmpty()) {
|
||||||
creator.setAffiliation(zenodoAffiliation);
|
creator.setAffiliation(zenodoAffiliation);
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package org.opencdmp.deposit.zenodorepository.service.zenodo;
|
package org.opencdmp.deposit.zenodorepository.service.zenodo;
|
||||||
|
|
||||||
import org.opencdmp.commonmodels.models.dmp.DmpModel;
|
import org.opencdmp.commonmodels.models.plan.PlanModel;
|
||||||
import org.opencdmp.depositbase.repository.DepositConfiguration;
|
import org.opencdmp.depositbase.repository.DepositConfiguration;
|
||||||
|
|
||||||
public interface ZenodoDepositService {
|
public interface ZenodoDepositService {
|
||||||
String deposit(DmpModel dmpDepositModel, String zenodoToken) throws Exception;
|
String deposit(PlanModel planDepositModel, String zenodoToken) throws Exception;
|
||||||
|
|
||||||
DepositConfiguration getConfiguration();
|
DepositConfiguration getConfiguration();
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import gr.cite.tools.exception.MyApplicationException;
|
||||||
import gr.cite.tools.logging.LoggerService;
|
import gr.cite.tools.logging.LoggerService;
|
||||||
import gr.cite.tools.logging.MapLogEntry;
|
import gr.cite.tools.logging.MapLogEntry;
|
||||||
import org.opencdmp.commonmodels.models.FileEnvelopeModel;
|
import org.opencdmp.commonmodels.models.FileEnvelopeModel;
|
||||||
import org.opencdmp.commonmodels.models.dmp.DmpModel;
|
import org.opencdmp.commonmodels.models.plan.PlanModel;
|
||||||
import org.opencdmp.deposit.zenodorepository.model.ZenodoDeposit;
|
import org.opencdmp.deposit.zenodorepository.model.ZenodoDeposit;
|
||||||
import org.opencdmp.deposit.zenodorepository.model.builder.ZenodoBuilder;
|
import org.opencdmp.deposit.zenodorepository.model.builder.ZenodoBuilder;
|
||||||
import org.opencdmp.deposit.zenodorepository.service.storage.FileStorageService;
|
import org.opencdmp.deposit.zenodorepository.service.storage.FileStorageService;
|
||||||
|
@ -69,7 +69,7 @@ public class ZenodoDepositServiceImpl implements ZenodoDepositService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String deposit(DmpModel dmpModel, String zenodoToken) throws Exception {
|
public String deposit(PlanModel planModel, String zenodoToken) throws Exception {
|
||||||
|
|
||||||
DepositConfiguration depositConfiguration = this.getConfiguration();
|
DepositConfiguration depositConfiguration = this.getConfiguration();
|
||||||
|
|
||||||
|
@ -86,10 +86,10 @@ public class ZenodoDepositServiceImpl implements ZenodoDepositService {
|
||||||
|
|
||||||
DepositConfiguration zenodoConfig = this.zenodoServiceProperties.getDepositConfiguration();
|
DepositConfiguration zenodoConfig = this.zenodoServiceProperties.getDepositConfiguration();
|
||||||
if (zenodoConfig == null) return null;
|
if (zenodoConfig == null) return null;
|
||||||
ZenodoDeposit deposit = zenodoBuilder.build(dmpModel);
|
ZenodoDeposit deposit = zenodoBuilder.build(planModel);
|
||||||
|
|
||||||
LinkedHashMap<String, String> links;
|
LinkedHashMap<String, String> links;
|
||||||
String previousDOI = dmpModel.getPreviousDOI();
|
String previousDOI = planModel.getPreviousDOI();
|
||||||
String unpublishedUrl = null;
|
String unpublishedUrl = null;
|
||||||
String publishUrl;
|
String publishUrl;
|
||||||
try {
|
try {
|
||||||
|
@ -97,7 +97,7 @@ public class ZenodoDepositServiceImpl implements ZenodoDepositService {
|
||||||
if (previousDOI == null) {
|
if (previousDOI == null) {
|
||||||
links = deposit(zenodoToken, zenodoUrl, zenodoClient, deposit);
|
links = deposit(zenodoToken, zenodoUrl, zenodoClient, deposit);
|
||||||
} else {
|
} else {
|
||||||
unpublishedUrl = this.getUnpublishedDOI(zenodoClient, zenodoUrl, previousDOI, zenodoToken, dmpModel.getVersion());
|
unpublishedUrl = this.getUnpublishedDOI(zenodoClient, zenodoUrl, previousDOI, zenodoToken, planModel.getVersion());
|
||||||
if (unpublishedUrl == null) {
|
if (unpublishedUrl == null) {
|
||||||
//It requires more than one step to create a new version
|
//It requires more than one step to create a new version
|
||||||
//First, get the deposit related to the concept DOI
|
//First, get the deposit related to the concept DOI
|
||||||
|
@ -109,7 +109,7 @@ public class ZenodoDepositServiceImpl implements ZenodoDepositService {
|
||||||
|
|
||||||
if (unpublishedUrl == null) {
|
if (unpublishedUrl == null) {
|
||||||
// Second step, add the file to the entry.
|
// Second step, add the file to the entry.
|
||||||
FileEnvelopeModel pdfEnvelope = dmpModel.getPdfFile();
|
FileEnvelopeModel pdfEnvelope = planModel.getPdfFile();
|
||||||
|
|
||||||
if (links == null || !links.containsKey(ZENODO_LINKS_BUCKET)) throw new MyApplicationException("bucket not found");
|
if (links == null || !links.containsKey(ZENODO_LINKS_BUCKET)) throw new MyApplicationException("bucket not found");
|
||||||
String addFileUrl = links.get(ZENODO_LINKS_BUCKET) + "/" + cleanFileName(pdfEnvelope.getFilename()) + "?access_token=" + zenodoToken;
|
String addFileUrl = links.get(ZENODO_LINKS_BUCKET) + "/" + cleanFileName(pdfEnvelope.getFilename()) + "?access_token=" + zenodoToken;
|
||||||
|
@ -125,7 +125,7 @@ public class ZenodoDepositServiceImpl implements ZenodoDepositService {
|
||||||
.body(BodyInserters
|
.body(BodyInserters
|
||||||
.fromResource(new ByteArrayResource(pdfFileBytes)))
|
.fromResource(new ByteArrayResource(pdfFileBytes)))
|
||||||
.retrieve().toEntity(Map.class).block();
|
.retrieve().toEntity(Map.class).block();
|
||||||
FileEnvelopeModel rdaJsonEnvelope = dmpModel.getRdaJsonFile();
|
FileEnvelopeModel rdaJsonEnvelope = planModel.getRdaJsonFile();
|
||||||
|
|
||||||
String jsonFileName = cleanFileName(rdaJsonEnvelope.getFilename());
|
String jsonFileName = cleanFileName(rdaJsonEnvelope.getFilename());
|
||||||
addFileUrl = links.get(ZENODO_LINKS_BUCKET) + "/" + jsonFileName + "?access_token=" + zenodoToken;
|
addFileUrl = links.get(ZENODO_LINKS_BUCKET) + "/" + jsonFileName + "?access_token=" + zenodoToken;
|
||||||
|
@ -139,8 +139,8 @@ public class ZenodoDepositServiceImpl implements ZenodoDepositService {
|
||||||
}
|
}
|
||||||
zenodoClient.put().uri(addFileUrl).headers(httpHeaders -> httpHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM)).body(BodyInserters.fromResource(new ByteArrayResource(rdaJsonBytes))).retrieve().toEntity(Map.class).block();
|
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) {
|
if (planModel.getSupportingFilesZip() != null) {
|
||||||
String supportingFilesZipName = cleanFileName(dmpModel.getSupportingFilesZip().getFilename());
|
String supportingFilesZipName = cleanFileName(planModel.getSupportingFilesZip().getFilename());
|
||||||
|
|
||||||
addFileUrl = links.get(ZENODO_LINKS_BUCKET) + "/" + supportingFilesZipName + "?access_token=" + zenodoToken;
|
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();
|
zenodoClient.put().uri(addFileUrl).body(BodyInserters.fromResource(new ByteArrayResource(supportingFilesZipName.getBytes()))).retrieve().toEntity(Map.class).block();
|
||||||
|
|
2
pom.xml
2
pom.xml
|
@ -31,7 +31,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.opencdmp</groupId>
|
<groupId>org.opencdmp</groupId>
|
||||||
<artifactId>repositorydepositbase</artifactId>
|
<artifactId>repositorydepositbase</artifactId>
|
||||||
<version>2.0.15</version>
|
<version>2.0.16</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>gr.cite</groupId>
|
<groupId>gr.cite</groupId>
|
||||||
|
|
|
@ -3,7 +3,7 @@ package org.opencdmp.deposit.controller;
|
||||||
import gr.cite.tools.auditing.AuditService;
|
import gr.cite.tools.auditing.AuditService;
|
||||||
import gr.cite.tools.logging.LoggerService;
|
import gr.cite.tools.logging.LoggerService;
|
||||||
import gr.cite.tools.logging.MapLogEntry;
|
import gr.cite.tools.logging.MapLogEntry;
|
||||||
import org.opencdmp.commonmodels.models.dmp.DmpModel;
|
import org.opencdmp.commonmodels.models.plan.PlanModel;
|
||||||
import org.opencdmp.deposit.zenodorepository.audit.AuditableAction;
|
import org.opencdmp.deposit.zenodorepository.audit.AuditableAction;
|
||||||
import org.opencdmp.depositbase.repository.DepositConfiguration;
|
import org.opencdmp.depositbase.repository.DepositConfiguration;
|
||||||
import org.opencdmp.deposit.zenodorepository.service.zenodo.ZenodoDepositService;
|
import org.opencdmp.deposit.zenodorepository.service.zenodo.ZenodoDepositService;
|
||||||
|
@ -29,19 +29,19 @@ public class DepositController implements org.opencdmp.depositbase.repository.De
|
||||||
this.auditService = auditService;
|
this.auditService = auditService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String deposit(@RequestBody DmpModel dmpModel, @RequestParam("authToken")String authToken) throws Exception {
|
public String deposit(@RequestBody PlanModel planModel, @RequestParam("authToken")String authToken) throws Exception {
|
||||||
logger.debug(new MapLogEntry("deposit " + DmpModel.class.getSimpleName()).And("dmpModel", dmpModel));
|
logger.debug(new MapLogEntry("deposit " + PlanModel.class.getSimpleName()).And("planModel", planModel));
|
||||||
|
|
||||||
String doiId = depositClient.deposit(dmpModel, authToken);
|
String doiId = depositClient.deposit(planModel, authToken);
|
||||||
|
|
||||||
this.auditService.track(AuditableAction.Deposit_Deposit, Map.ofEntries(
|
this.auditService.track(AuditableAction.Deposit_Deposit, Map.ofEntries(
|
||||||
new AbstractMap.SimpleEntry<String, Object>("dmpModel", dmpModel)
|
new AbstractMap.SimpleEntry<String, Object>("planModel", planModel)
|
||||||
));
|
));
|
||||||
return doiId;
|
return doiId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String authenticate(@RequestParam("authToken") String code) {
|
public String authenticate(@RequestParam("authToken") String code) {
|
||||||
logger.debug(new MapLogEntry("authenticate " + DmpModel.class.getSimpleName()));
|
logger.debug(new MapLogEntry("authenticate " + PlanModel.class.getSimpleName()));
|
||||||
|
|
||||||
String token = depositClient.authenticate(code);
|
String token = depositClient.authenticate(code);
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ public class DepositController implements org.opencdmp.depositbase.repository.De
|
||||||
}
|
}
|
||||||
|
|
||||||
public DepositConfiguration getConfiguration() {
|
public DepositConfiguration getConfiguration() {
|
||||||
logger.debug(new MapLogEntry("getConfiguration " + DmpModel.class.getSimpleName()));
|
logger.debug(new MapLogEntry("getConfiguration " + PlanModel.class.getSimpleName()));
|
||||||
|
|
||||||
DepositConfiguration configuration = depositClient.getConfiguration();
|
DepositConfiguration configuration = depositClient.getConfiguration();
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ public class DepositController implements org.opencdmp.depositbase.repository.De
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLogo() {
|
public String getLogo() {
|
||||||
logger.debug(new MapLogEntry("getLogo " + DmpModel.class.getSimpleName()));
|
logger.debug(new MapLogEntry("getLogo " + PlanModel.class.getSimpleName()));
|
||||||
|
|
||||||
String logo = depositClient.getLogo();
|
String logo = depositClient.getLogo();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue