drop column doi from dmp and refactor code(replace single doi with list of dois)

This commit is contained in:
Bernaldo Mihasi 2022-12-08 13:12:54 +02:00
parent 8c95b16164
commit c6d37806c8
16 changed files with 186 additions and 61 deletions

View File

@ -87,7 +87,7 @@ public class DMPDaoImpl extends DatabaseAccess<DMP> implements DMPDao {
} }
if (criteria.hasDoi()) { if (criteria.hasDoi()) {
query.where((builder, root) -> builder.not(builder.isNull(root.get("doi")))); query.where((builder, root) -> builder.not(builder.isNull(root.join("dois").get("id"))));
} }
query.where((builder, root) -> builder.notEqual(root.get("status"), DMP.DMPStatus.DELETED.getValue())); query.where((builder, root) -> builder.notEqual(root.get("status"), DMP.DMPStatus.DELETED.getValue()));
return query; return query;

View File

@ -80,7 +80,7 @@ public class DatasetDaoImpl extends DatabaseAccess<Dataset> implements DatasetDa
query.where((builder, root) -> root.get("profile").get("id").in(criteria.getDatasetTemplates())); query.where((builder, root) -> root.get("profile").get("id").in(criteria.getDatasetTemplates()));
if (criteria.hasDoi()) { if (criteria.hasDoi()) {
query.where((builder, root) -> builder.not(builder.isNull(root.get("dmp").get("doi")))); query.where((builder, root) -> builder.not(builder.isNull(root.join("dmp").join("dois").get("id"))));
} }
query.where((builder, root) -> builder.notEqual(root.get("status"), Dataset.Status.DELETED.getValue())); query.where((builder, root) -> builder.notEqual(root.get("status"), Dataset.Status.DELETED.getValue()));
query.where((builder, root) -> builder.notEqual(root.get("status"), Dataset.Status.CANCELED.getValue())); query.where((builder, root) -> builder.notEqual(root.get("status"), Dataset.Status.CANCELED.getValue()));

View File

@ -6,4 +6,5 @@ import eu.eudat.data.entities.EntityDoi;
import java.util.UUID; import java.util.UUID;
public interface EntityDoiDao extends DatabaseAccessLayer<EntityDoi, UUID> { public interface EntityDoiDao extends DatabaseAccessLayer<EntityDoi, UUID> {
EntityDoi findFromDoi(String doi);
} }

View File

@ -34,6 +34,11 @@ public class EntityDoiDaoImpl extends DatabaseAccess<EntityDoi> implements Entit
return this.getDatabaseService().getQueryable(EntityDoi.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle(); return this.getDatabaseService().getQueryable(EntityDoi.class).where((builder, root) -> builder.equal(root.get("id"), id)).getSingle();
} }
@Override
public EntityDoi findFromDoi(String doi) {
return this.getDatabaseService().getQueryable(EntityDoi.class).where((builder, root) -> builder.equal(root.get("doi"), doi)).getSingle();
}
@Override @Override
public EntityDoi find(UUID id, String hint) { public EntityDoi find(UUID id, String hint) {
return null; return null;

View File

@ -181,9 +181,6 @@ public class DMP implements DataEntity<DMP, UUID> {
@Convert(converter = DateToUTCConverter.class) @Convert(converter = DateToUTCConverter.class)
private Date publishedAt; private Date publishedAt;
@Column(name = "\"DOI\"")
private String doi;
@OneToMany(mappedBy = "entityId", fetch = FetchType.LAZY) @OneToMany(mappedBy = "entityId", fetch = FetchType.LAZY)
private Set<EntityDoi> dois; private Set<EntityDoi> dois;
@ -342,13 +339,6 @@ public class DMP implements DataEntity<DMP, UUID> {
this.publishedAt = publishedAt; this.publishedAt = publishedAt;
} }
public String getDoi() {
return doi;
}
public void setDoi(String doi) {
this.doi = doi;
}
public Set<EntityDoi> getDois() { public Set<EntityDoi> getDois() {
return dois; return dois;
} }
@ -390,7 +380,6 @@ public class DMP implements DataEntity<DMP, UUID> {
if (entity.getStatus().equals(DMPStatus.FINALISED.getValue())) this.setFinalizedAt(new Date()); if (entity.getStatus().equals(DMPStatus.FINALISED.getValue())) this.setFinalizedAt(new Date());
if (entity.isPublic) this.setPublishedAt(new Date()); if (entity.isPublic) this.setPublishedAt(new Date());
if (entity.getUsers() != null) this.users = entity.getUsers(); if (entity.getUsers() != null) this.users = entity.getUsers();
if (entity.getDoi() != null && entity.getDoi().trim().isEmpty()) this.doi = entity.doi;
this.dois = entity.getDois(); this.dois = entity.getDois();
this.extraProperties = entity.getExtraProperties(); this.extraProperties = entity.getExtraProperties();
} }

View File

@ -57,7 +57,7 @@ public class Dmp implements ElasticEntity<Dmp> {
private Date modified; private Date modified;
private Date finalizedAt; private Date finalizedAt;
private Date publishedAt; private Date publishedAt;
private String doi; private List<Doi> dois;
public UUID getId() { public UUID getId() {
return id; return id;
@ -203,12 +203,12 @@ public class Dmp implements ElasticEntity<Dmp> {
this.publishedAt = publishedAt; this.publishedAt = publishedAt;
} }
public String getDoi() { public List<Doi> getDois() {
return doi; return dois;
} }
public void setDoi(String doi) { public void setDois(List<Doi> dois) {
this.doi = doi; this.dois = dois;
} }
@Override @Override
@ -280,7 +280,17 @@ public class Dmp implements ElasticEntity<Dmp> {
builder.field(MapKey.MODIFIED.getName(), this.modified); builder.field(MapKey.MODIFIED.getName(), this.modified);
builder.field(MapKey.FINALIZEDAT.getName(), this.finalizedAt); builder.field(MapKey.FINALIZEDAT.getName(), this.finalizedAt);
builder.field(MapKey.PUBLISHEDAT.getName(), this.publishedAt); builder.field(MapKey.PUBLISHEDAT.getName(), this.publishedAt);
builder.field(MapKey.DOI.getName(), this.doi); if (this.dois != null && !this.dois.isEmpty()) {
builder.startArray(MapKey.DOIS.getName());
this.dois.forEach(doi -> {
try {
doi.toElasticEntity(builder);
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
});
builder.endArray();
}
builder.endObject(); builder.endObject();
return builder; return builder;
} }
@ -329,8 +339,8 @@ public class Dmp implements ElasticEntity<Dmp> {
if (fields.get(MapKey.PUBLISHEDAT.getName()) != null) { if (fields.get(MapKey.PUBLISHEDAT.getName()) != null) {
this.publishedAt = Date.from(Instant.parse(fields.get(MapKey.PUBLISHEDAT.getName()).toString())); this.publishedAt = Date.from(Instant.parse(fields.get(MapKey.PUBLISHEDAT.getName()).toString()));
} }
if (fields.get(MapKey.DOI.getName()) != null) { if (fields.get(MapKey.DOIS.getName()) != null) {
this.doi = fields.get(MapKey.DOI.getName()).toString(); this.dois = ((List<HashMap<String, Object>>) fields.get(MapKey.DOIS.getName())).stream().map(map -> new Doi().fromElasticEntity(map)).collect(Collectors.toList());
} }
} }
return this; return this;
@ -355,7 +365,7 @@ public class Dmp implements ElasticEntity<Dmp> {
MODIFIED ("modified"), MODIFIED ("modified"),
FINALIZEDAT ("finalizedAt"), FINALIZEDAT ("finalizedAt"),
PUBLISHEDAT ("publishedAt"), PUBLISHEDAT ("publishedAt"),
DOI ("doi"); DOIS ("dois");
private final String name; private final String name;

View File

@ -0,0 +1,65 @@
package eu.eudat.elastic.entities;
import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException;
import java.util.Map;
import java.util.UUID;
public class Doi implements ElasticEntity<Doi>{
private UUID id;
private String repositoryId;
private String doi;
private UUID dmp;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getRepositoryId() {
return repositoryId;
}
public void setRepositoryId(String repositoryId) {
this.repositoryId = repositoryId;
}
public String getDoi() {
return doi;
}
public void setDoi(String doi) {
this.doi = doi;
}
public UUID getDmp() {
return dmp;
}
public void setDmp(UUID dmp) {
this.dmp = dmp;
}
@Override
public XContentBuilder toElasticEntity(XContentBuilder builder) throws IOException {
builder.startObject();
builder.field("id", this.id.toString());
builder.field("repositoryId", this.repositoryId);
builder.field("doi", this.doi);
builder.field("dmp", this.dmp.toString());
builder.endObject();
return builder;
}
@Override
public Doi fromElasticEntity(Map<String, Object> fields) {
if (fields == null || fields.isEmpty()) {
return null;
}
this.id = UUID.fromString((String) fields.get("id"));
this.repositoryId = (String) fields.get("repositoryId");
this.doi = (String) fields.get("doi");
this.dmp = UUID.fromString((String) fields.get("dmp"));
return this;
}
}

View File

@ -756,7 +756,7 @@ public class DataManagementPlanManager {
metricsManager.decreaseValue(MetricNames.DMP, 1, MetricNames.DRAFT); metricsManager.decreaseValue(MetricNames.DMP, 1, MetricNames.DRAFT);
break; break;
case 1: case 1:
if (oldDmp.getDoi() != null) { if (oldDmp.getDois() != null && !oldDmp.getDois().isEmpty()) {
metricsManager.decreaseValue(MetricNames.DMP, 1, MetricNames.DOIED); metricsManager.decreaseValue(MetricNames.DMP, 1, MetricNames.DOIED);
} }
if (oldDmp.isPublic()) { if (oldDmp.isPublic()) {

View File

@ -796,9 +796,8 @@ public class WordBuilder {
r.setText(text, 0); r.setText(text, 0);
} }
if(text.contains("{ARGOS.DMP.DOI}")){ if(text.contains("{ARGOS.DMP.DOI}")){
String doi = dmpEntity.getDoi(); if(dmpEntity.getDois() != null && !dmpEntity.getDois().isEmpty())
if(doi != null) text = text.replace("{ARGOS.DMP.DOI}", dmpEntity.getDois().iterator().next().getDoi());
text = text.replace("{ARGOS.DMP.DOI}", doi);
else else
text = text.replace("{ARGOS.DMP.DOI}", "-"); text = text.replace("{ARGOS.DMP.DOI}", "-");
r.setText(text, 0); r.setText(text, 0);

View File

@ -41,7 +41,6 @@ public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
private List<DynamicFieldWithValue> dynamicFields; private List<DynamicFieldWithValue> dynamicFields;
private Map<String, Object> properties; private Map<String, Object> properties;
private List<UserInfoListingModel> users; private List<UserInfoListingModel> users;
private String doi;
private List<Doi> dois; private List<Doi> dois;
private Project project; private Project project;
private Funder funder; private Funder funder;
@ -196,13 +195,6 @@ public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
this.users = users; this.users = users;
} }
public String getDoi() {
return doi;
}
public void setDoi(String doi) {
this.doi = doi;
}
public List<Doi> getDois() { public List<Doi> getDois() {
return dois; return dois;
} }
@ -289,7 +281,6 @@ public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
this.status = entity.getStatus(); this.status = entity.getStatus();
this.associatedUsers = entity.getUsers() != null ? entity.getUsers().stream().map(item -> new UserListingModel().fromDataModel(item.getUser())).collect(Collectors.toList()) : new ArrayList<>(); this.associatedUsers = entity.getUsers() != null ? entity.getUsers().stream().map(item -> new UserListingModel().fromDataModel(item.getUser())).collect(Collectors.toList()) : new ArrayList<>();
this.users = entity.getUsers() != null ? entity.getUsers().stream().map(item -> new UserInfoListingModel().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>(); this.users = entity.getUsers() != null ? entity.getUsers().stream().map(item -> new UserInfoListingModel().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>();
this.doi = entity.getDoi();
this.dois = entity.getDois() != null ? entity.getDois().stream().map(item -> new Doi().fromDataModel(item)).collect(Collectors.toList()): new ArrayList<>(); this.dois = entity.getDois() != null ? entity.getDois().stream().map(item -> new Doi().fromDataModel(item)).collect(Collectors.toList()): new ArrayList<>();
if (entity.getProject() != null) { if (entity.getProject() != null) {
@ -386,7 +377,6 @@ public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
this.status = entity.getStatus(); this.status = entity.getStatus();
this.associatedUsers = entity.getUsers() != null ? entity.getUsers().stream().map(item -> new UserListingModel().fromDataModel(item.getUser())).collect(Collectors.toList()) : new ArrayList<>(); this.associatedUsers = entity.getUsers() != null ? entity.getUsers().stream().map(item -> new UserListingModel().fromDataModel(item.getUser())).collect(Collectors.toList()) : new ArrayList<>();
this.users = entity.getUsers() != null ? entity.getUsers().stream().map(item -> new UserInfoListingModel().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>(); this.users = entity.getUsers() != null ? entity.getUsers().stream().map(item -> new UserInfoListingModel().fromDataModel(item)).collect(Collectors.toList()) : new ArrayList<>();
this.doi = entity.getDoi();
this.dois = entity.getDois() != null ? entity.getDois().stream().map(item -> new Doi().fromDataModel(item)).collect(Collectors.toList()): new ArrayList<>(); this.dois = entity.getDois() != null ? entity.getDois().stream().map(item -> new Doi().fromDataModel(item)).collect(Collectors.toList()): new ArrayList<>();
this.grant.fromDataModel(entity.getGrant()); this.grant.fromDataModel(entity.getGrant());

View File

@ -36,7 +36,6 @@ public class DataManagementPlanOverviewModel implements DataModel<DMP, DataManag
private String description; private String description;
private boolean isPublic; private boolean isPublic;
private Date publishedAt; private Date publishedAt;
private String doi;
private List<Doi> dois; private List<Doi> dois;
@ -166,13 +165,6 @@ public class DataManagementPlanOverviewModel implements DataModel<DMP, DataManag
this.publishedAt = publishedAt; this.publishedAt = publishedAt;
} }
public String getDoi() {
return doi;
}
public void setDoi(String doi) {
this.doi = doi;
}
public List<Doi> getDois() { public List<Doi> getDois() {
return dois; return dois;
} }
@ -220,7 +212,6 @@ public class DataManagementPlanOverviewModel implements DataModel<DMP, DataManag
} }
this.isPublic = entity.isPublic(); this.isPublic = entity.isPublic();
this.publishedAt = entity.getPublishedAt(); this.publishedAt = entity.getPublishedAt();
this.doi = entity.getDoi();
this.dois = entity.getDois().stream().map(item -> new Doi().fromDataModel(item)).collect(Collectors.toList()); this.dois = entity.getDois().stream().map(item -> new Doi().fromDataModel(item)).collect(Collectors.toList());
return this; return this;

View File

@ -1,9 +1,6 @@
package eu.eudat.models.data.rda; package eu.eudat.models.data.rda;
import eu.eudat.data.entities.DMP; import eu.eudat.data.entities.*;
import eu.eudat.data.entities.Dataset;
import eu.eudat.data.entities.UserDMP;
import eu.eudat.data.entities.UserInfo;
import eu.eudat.logic.managers.DatasetManager; import eu.eudat.logic.managers.DatasetManager;
import eu.eudat.models.data.security.Principal; import eu.eudat.models.data.security.Principal;
@ -146,8 +143,17 @@ public class DmpRDAExportModel {
dmpRda.dataset.add(new DatasetRDAExportModel().fromDataModel(dataset, datasetManager, principal)); dmpRda.dataset.add(new DatasetRDAExportModel().fromDataModel(dataset, datasetManager, principal));
} }
dmpRda.description = entity.getDescription().replace("\n", " "); dmpRda.description = entity.getDescription().replace("\n", " ");
if (entity.getDoi() != null) { if (entity.getDois() != null && !entity.getDois().isEmpty()) {
dmpRda.dmp_id = new IdRDAExportModel(entity.getDoi(), "zenodo"); boolean zenodoDoi = false;
for(EntityDoi doi: entity.getDois()){
if(doi.getRepositoryId().equals("Zenodo")){
dmpRda.dmp_id = new IdRDAExportModel(doi.getDoi(), "zenodo");
zenodoDoi = true;
}
}
if(!zenodoDoi){
dmpRda.dmp_id = new IdRDAExportModel(entity.getId().toString(), "other");
}
} }
else { else {
dmpRda.dmp_id = new IdRDAExportModel(entity.getId().toString(), "other"); dmpRda.dmp_id = new IdRDAExportModel(entity.getId().toString(), "other");

View File

@ -47,8 +47,12 @@ public class DmpRDAMapper {
} }
} }
Dmp rda = new Dmp(); Dmp rda = new Dmp();
if (dmp.getDoi() != null && !dmp.getDoi().isEmpty()) { if (dmp.getDois() != null && !dmp.getDois().isEmpty()) {
rda.setDmpId(DmpIdRDAMapper.toRDA(dmp.getDoi())); for(EntityDoi doi: dmp.getDois()){
if(doi.getRepositoryId().equals("Zenodo")){
rda.setDmpId(DmpIdRDAMapper.toRDA(doi.getDoi()));
}
}
} else { } else {
rda.setDmpId(DmpIdRDAMapper.toRDA(dmp.getId())); rda.setDmpId(DmpIdRDAMapper.toRDA(dmp.getId()));
} }
@ -105,7 +109,10 @@ public class DmpRDAMapper {
DMP entity = new DMP(); DMP entity = new DMP();
entity.setLabel(rda.getTitle()); entity.setLabel(rda.getTitle());
if (rda.getDmpId().getType() == DmpId.Type.DOI) { if (rda.getDmpId().getType() == DmpId.Type.DOI) {
entity.setDoi(rda.getDmpId().getIdentifier()); EntityDoi doi = apiContext.getOperationsContext().getDatabaseRepository().getEntityDoiDao().findFromDoi(rda.getDmpId().getIdentifier());
Set<EntityDoi> dois = new HashSet<>();
dois.add(doi);
entity.setDois(dois);
} }
if (((List<String>) rda.getAdditionalProperties().get("templates")) != null && !((List<String>) rda.getAdditionalProperties().get("templates")).isEmpty()) { if (((List<String>) rda.getAdditionalProperties().get("templates")) != null && !((List<String>) rda.getAdditionalProperties().get("templates")).isEmpty()) {
entity.setAssociatedDmps(((List<String>) rda.getAdditionalProperties().get("templates")).stream().map(this::getProfile).filter(Objects::nonNull).collect(Collectors.toSet())); entity.setAssociatedDmps(((List<String>) rda.getAdditionalProperties().get("templates")).stream().map(this::getProfile).filter(Objects::nonNull).collect(Collectors.toSet()));

View File

@ -0,0 +1,61 @@
package eu.eudat.publicapi.models.doi;
import eu.eudat.data.entities.EntityDoi;
import eu.eudat.logic.utilities.helpers.LabelGenerator;
import eu.eudat.models.DataModel;
import java.util.UUID;
public class DoiPublicModel implements DataModel<EntityDoi, DoiPublicModel>, LabelGenerator {
private UUID id;
private String repositoryId;
private String doi;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getRepositoryId() {
return repositoryId;
}
public void setRepositoryId(String repositoryId) {
this.repositoryId = repositoryId;
}
public String getDoi() {
return doi;
}
public void setDoi(String doi) {
this.doi = doi;
}
@Override
public DoiPublicModel fromDataModel(EntityDoi entity) {
this.id = entity.getId();
this.repositoryId = entity.getRepositoryId();
this.doi = entity.getDoi();
return this;
}
@Override
public EntityDoi toDataModel() throws Exception {
EntityDoi entity = new EntityDoi();
entity.setId(this.getId());
entity.setRepositoryId(this.getRepositoryId());
entity.setDoi(this.getDoi());
return entity;
}
@Override
public String generateLabel() {
return this.getDoi();
}
@Override
public String getHint() {
return null;
}
}

View File

@ -7,6 +7,7 @@ import eu.eudat.logic.utilities.builders.XmlBuilder;
import eu.eudat.models.DataModel; import eu.eudat.models.DataModel;
import eu.eudat.models.data.user.composite.PagedDatasetProfile; import eu.eudat.models.data.user.composite.PagedDatasetProfile;
import eu.eudat.publicapi.models.associatedprofile.AssociatedProfilePublicModel; import eu.eudat.publicapi.models.associatedprofile.AssociatedProfilePublicModel;
import eu.eudat.publicapi.models.doi.DoiPublicModel;
import eu.eudat.publicapi.models.grant.GrantPublicOverviewModel; import eu.eudat.publicapi.models.grant.GrantPublicOverviewModel;
import eu.eudat.publicapi.models.organisation.OrganizationPublicModel; import eu.eudat.publicapi.models.organisation.OrganizationPublicModel;
import eu.eudat.publicapi.models.researcher.ResearcherPublicModel; import eu.eudat.publicapi.models.researcher.ResearcherPublicModel;
@ -35,7 +36,7 @@ public class DataManagementPlanPublicModel implements DataModel<DMP, DataManagem
private List<UserInfoPublicModel> users; private List<UserInfoPublicModel> users;
private String description; private String description;
private Date publishedAt; private Date publishedAt;
private String doi; private List<DoiPublicModel> dois;
public String getId() { public String getId() {
@ -150,11 +151,11 @@ public class DataManagementPlanPublicModel implements DataModel<DMP, DataManagem
this.publishedAt = publishedAt; this.publishedAt = publishedAt;
} }
public String getDoi() { public List<DoiPublicModel> getDois() {
return doi; return dois;
} }
public void setDoi(String doi) { public void setDois(List<DoiPublicModel> dois) {
this.doi = doi; this.dois = dois;
} }
@Override @Override
@ -198,7 +199,7 @@ public class DataManagementPlanPublicModel implements DataModel<DMP, DataManagem
} }
} }
this.publishedAt = entity.getPublishedAt(); this.publishedAt = entity.getPublishedAt();
this.doi = entity.getDoi(); this.dois = entity.getDois().stream().map(item -> new DoiPublicModel().fromDataModel(item)).collect(Collectors.toList());
return this; return this;
} }

View File

@ -4,7 +4,7 @@ BEGIN
PERFORM * FROM "DBVersion" WHERE version = this_version; PERFORM * FROM "DBVersion" WHERE version = this_version;
IF FOUND THEN RETURN; END IF; IF FOUND THEN RETURN; END IF;
ALTER TABLE public."DMP" DROP COLUMN 'DOI'; ALTER TABLE public."DMP" DROP COLUMN "DOI";
INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.00.012', '2022-10-27 10:50:00.000000+02', now(), 'Delete doi column from dmp table'); INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.00.012', '2022-10-27 10:50:00.000000+02', now(), 'Delete doi column from dmp table');