From 62d681d022b91282730d21f45ccea38ef6c945c8 Mon Sep 17 00:00:00 2001 From: gkolokythas Date: Tue, 14 May 2019 16:08:49 +0300 Subject: [PATCH] Project filter on "Public DMPs" now exposes only the ones associated with public DMPs (Ticket #79) --- .../eu/eudat/data/dao/criteria/ProjectCriteria.java | 12 ++++++++---- .../java/eu/eudat/data/dao/entities/DMPDaoImpl.java | 2 +- .../eu/eudat/data/dao/entities/ProjectDaoImpl.java | 4 ++++ .../java/eu/eudat/logic/managers/ProjectManager.java | 1 + 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/dao/criteria/ProjectCriteria.java b/dmp-backend/data/src/main/java/eu/eudat/data/dao/criteria/ProjectCriteria.java index d8a71b7ab..5aa7159f5 100644 --- a/dmp-backend/data/src/main/java/eu/eudat/data/dao/criteria/ProjectCriteria.java +++ b/dmp-backend/data/src/main/java/eu/eudat/data/dao/criteria/ProjectCriteria.java @@ -10,11 +10,11 @@ public class ProjectCriteria extends Criteria { private Date periodEnd; private String reference; private Integer projectStateType; + private boolean isPublic; public Date getPeriodStart() { return periodStart; } - public void setPeriodStart(Date periodStart) { this.periodStart = periodStart; } @@ -22,7 +22,6 @@ public class ProjectCriteria extends Criteria { public Date getPeriodEnd() { return periodEnd; } - public void setPeriodEnd(Date periodEnd) { this.periodEnd = periodEnd; } @@ -30,7 +29,6 @@ public class ProjectCriteria extends Criteria { public String getReference() { return reference; } - public void setReference(String reference) { this.reference = reference; } @@ -38,8 +36,14 @@ public class ProjectCriteria extends Criteria { public Integer getProjectStateType() { return projectStateType; } - public void setProjectStateType(Integer projectStateType) { this.projectStateType = projectStateType; } + + public boolean isPublic() { + return isPublic; + } + public void setPublic(boolean aPublic) { + isPublic = aPublic; + } } diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DMPDaoImpl.java b/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DMPDaoImpl.java index bff7a0d3b..625299c18 100644 --- a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DMPDaoImpl.java +++ b/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DMPDaoImpl.java @@ -69,7 +69,7 @@ public class DMPDaoImpl extends DatabaseAccess implements DMPDao { } public QueryableList getAuthenticated(QueryableList query, UUID principal) { - query.where((builder, root) -> builder.or(builder.equal(root.get("creator").get("id"), principal), builder.equal(root.join("users", JoinType.LEFT).get("id"), principal))); + query.where((builder, root) -> builder.equal(root.join("users", JoinType.LEFT).join("user").get("id"), principal)); return query; } diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/ProjectDaoImpl.java b/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/ProjectDaoImpl.java index 2a401bcff..1a1140153 100644 --- a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/ProjectDaoImpl.java +++ b/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/ProjectDaoImpl.java @@ -3,6 +3,7 @@ package eu.eudat.data.dao.entities; import eu.eudat.data.dao.DatabaseAccess; import eu.eudat.data.dao.criteria.ProjectCriteria; import eu.eudat.data.dao.databaselayer.service.DatabaseService; +import eu.eudat.data.entities.DMP; import eu.eudat.data.entities.Project; import eu.eudat.data.entities.UserInfo; import eu.eudat.queryable.QueryableList; @@ -45,6 +46,9 @@ public class ProjectDaoImpl extends DatabaseAccess implements ProjectDa builder.or(builder.greaterThan(root.get("enddate"), new Date()) , builder.isNull(root.get("enddate")))); } + if (criteria.isPublic()) { + query.where((builder, root) -> builder.equal(root.join("dmps").get("status"), DMP.DMPStatus.FINALISED.getValue())).distinct(); + } query.where((builder, root) -> builder.notEqual(root.get("status"), Project.Status.DELETED.getValue())); return query; } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/ProjectManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/ProjectManager.java index e950e744a..eacf3df35 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/ProjectManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/ProjectManager.java @@ -90,6 +90,7 @@ public class ProjectManager { public DataTableData getPublicPaged(ProjectTableRequest projectTableRequest) throws Exception { ProjectDao projectRepository = databaseRepository.getProjectDao(); + projectTableRequest.getCriteria().setPublic(true); QueryableList items = projectRepository.getWithCriteria(projectTableRequest.getCriteria()); QueryableList pagedItems = PaginationManager.applyPaging(items, projectTableRequest); DataTableData dataTable = new DataTableData<>();