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

multipleRepos
Bernaldo Mihasi 1 year ago
parent 8c95b16164
commit c6d37806c8

@ -87,7 +87,7 @@ public class DMPDaoImpl extends DatabaseAccess<DMP> implements DMPDao {
}
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()));
return query;

@ -80,7 +80,7 @@ public class DatasetDaoImpl extends DatabaseAccess<Dataset> implements DatasetDa
query.where((builder, root) -> root.get("profile").get("id").in(criteria.getDatasetTemplates()));
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.CANCELED.getValue()));

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

@ -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();
}
@Override
public EntityDoi findFromDoi(String doi) {
return this.getDatabaseService().getQueryable(EntityDoi.class).where((builder, root) -> builder.equal(root.get("doi"), doi)).getSingle();
}
@Override
public EntityDoi find(UUID id, String hint) {
return null;

@ -181,9 +181,6 @@ public class DMP implements DataEntity<DMP, UUID> {
@Convert(converter = DateToUTCConverter.class)
private Date publishedAt;
@Column(name = "\"DOI\"")
private String doi;
@OneToMany(mappedBy = "entityId", fetch = FetchType.LAZY)
private Set<EntityDoi> dois;
@ -342,13 +339,6 @@ public class DMP implements DataEntity<DMP, UUID> {
this.publishedAt = publishedAt;
}
public String getDoi() {
return doi;
}
public void setDoi(String doi) {
this.doi = doi;
}
public Set<EntityDoi> getDois() {
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.isPublic) this.setPublishedAt(new Date());
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.extraProperties = entity.getExtraProperties();
}

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

@ -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;
}
}

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

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

@ -41,7 +41,6 @@ public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
private List<DynamicFieldWithValue> dynamicFields;
private Map<String, Object> properties;
private List<UserInfoListingModel> users;
private String doi;
private List<Doi> dois;
private Project project;
private Funder funder;
@ -196,13 +195,6 @@ public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
this.users = users;
}
public String getDoi() {
return doi;
}
public void setDoi(String doi) {
this.doi = doi;
}
public List<Doi> getDois() {
return dois;
}
@ -289,7 +281,6 @@ public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
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.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<>();
if (entity.getProject() != null) {
@ -386,7 +377,6 @@ public class DataManagementPlan implements DataModel<DMP, DataManagementPlan> {
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.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.grant.fromDataModel(entity.getGrant());

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

@ -1,9 +1,6 @@
package eu.eudat.models.data.rda;
import eu.eudat.data.entities.DMP;
import eu.eudat.data.entities.Dataset;
import eu.eudat.data.entities.UserDMP;
import eu.eudat.data.entities.UserInfo;
import eu.eudat.data.entities.*;
import eu.eudat.logic.managers.DatasetManager;
import eu.eudat.models.data.security.Principal;
@ -146,8 +143,17 @@ public class DmpRDAExportModel {
dmpRda.dataset.add(new DatasetRDAExportModel().fromDataModel(dataset, datasetManager, principal));
}
dmpRda.description = entity.getDescription().replace("\n", " ");
if (entity.getDoi() != null) {
dmpRda.dmp_id = new IdRDAExportModel(entity.getDoi(), "zenodo");
if (entity.getDois() != null && !entity.getDois().isEmpty()) {
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 {
dmpRda.dmp_id = new IdRDAExportModel(entity.getId().toString(), "other");

@ -47,8 +47,12 @@ public class DmpRDAMapper {
}
}
Dmp rda = new Dmp();
if (dmp.getDoi() != null && !dmp.getDoi().isEmpty()) {
rda.setDmpId(DmpIdRDAMapper.toRDA(dmp.getDoi()));
if (dmp.getDois() != null && !dmp.getDois().isEmpty()) {
for(EntityDoi doi: dmp.getDois()){
if(doi.getRepositoryId().equals("Zenodo")){
rda.setDmpId(DmpIdRDAMapper.toRDA(doi.getDoi()));
}
}
} else {
rda.setDmpId(DmpIdRDAMapper.toRDA(dmp.getId()));
}
@ -105,7 +109,10 @@ public class DmpRDAMapper {
DMP entity = new DMP();
entity.setLabel(rda.getTitle());
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()) {
entity.setAssociatedDmps(((List<String>) rda.getAdditionalProperties().get("templates")).stream().map(this::getProfile).filter(Objects::nonNull).collect(Collectors.toSet()));

@ -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;
}
}

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

@ -4,7 +4,7 @@ BEGIN
PERFORM * FROM "DBVersion" WHERE version = this_version;
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');

Loading…
Cancel
Save