diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/DeliverableDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/DeliverableDAO.java index 0d8165d887..e147d84680 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/DeliverableDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/DeliverableDAO.java @@ -17,6 +17,7 @@ package org.cgiar.ccafs.marlo.data.dao; import org.cgiar.ccafs.marlo.data.model.Deliverable; +import org.cgiar.ccafs.marlo.data.model.DeliverableDTO; import org.cgiar.ccafs.marlo.data.model.DeliverableHomeDTO; import org.cgiar.ccafs.marlo.data.model.Phase; @@ -120,6 +121,20 @@ List getDeliverablesByPhaseAndUrlAndDoiAndHandel(long phase, String */ List getDeliverablesLeadByUserAndProject(long userId, long phaseId, long projectId); + List getDeliverablesLeadByUserAndProjectWithConditions(long userId, long phaseId, long projectId); + + /** + * get deliverables list by user, phase and project + * + * @author IBD + * @param phaseId phase id + * @param projectId project id + * @param userId user id + * @return deliverables (DTO) list + */ + List getDeliverablesLeadByUserAndProjectWithSimpleConditions(long userId, long phaseId, + long projectId); + List getDuplicatesDeliverablesByPhase(long phase); public List getPublicationsByPhase(long phase); diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ActivityMySQLDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ActivityMySQLDAO.java index 3855740fc1..01f1580e0b 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ActivityMySQLDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ActivityMySQLDAO.java @@ -74,7 +74,7 @@ public List findAll() { @Override public List getActivitiesByProject(long projectId, long phaseId) { String query = "from " + Activity.class.getName() + " where project_id=" + projectId + " and id_phase=" + phaseId - + " and is_active=1"; + + " and is_active=1 and activityStatus=2"; List list = super.findAll(query); if (!list.isEmpty()) { return list; diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableMySQLDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableMySQLDAO.java index a1d49d4db6..6665b2c4e5 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableMySQLDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableMySQLDAO.java @@ -18,6 +18,7 @@ import org.cgiar.ccafs.marlo.data.dao.DeliverableDAO; import org.cgiar.ccafs.marlo.data.model.Deliverable; +import org.cgiar.ccafs.marlo.data.model.DeliverableDTO; import org.cgiar.ccafs.marlo.data.model.DeliverableHomeDTO; import org.cgiar.ccafs.marlo.data.model.Phase; import org.cgiar.ccafs.marlo.data.model.ProjectStatusEnum; @@ -361,6 +362,7 @@ public List getDeliverablesLeadByInstitutionAndProject(long institu query.append("dup.is_active = 1 AND "); query.append("dupp.is_active = 1 AND "); query.append("dup.institution_id =" + institutionId + " AND "); + query.append("dup.id_phase = d.id_phase and "); query.append("dup.id_phase = " + phaseId); query.append(" and d.is_active =1 "); query.append(" and d.project_id = " + projectId); @@ -438,6 +440,126 @@ public List getDeliverablesLeadByUserAndProject(long userId, long p return deliverables; } + + @Override + public List getDeliverablesLeadByUserAndProjectWithConditions(long userId, long phaseId, + long projectId) { + StringBuilder query = new StringBuilder(); + query.append("SELECT DISTINCT "); + query.append("dup.deliverable_id as id "); + query.append("FROM "); + query.append("deliverable_user_partnerships AS dup "); + query.append("INNER JOIN deliverable_user_partnership_persons AS dupp ON dupp.user_partnership_id = dup.id "); + query.append(" inner join deliverables as d on dup.deliverable_id = d.id "); + query.append(" inner join deliverables_info di on di.deliverable_id = d.id "); + query.append(" inner join phases p on p.id = d.id_phase "); + query.append("WHERE "); + query.append("dupp.user_id =" + userId + " AND "); + query.append("dup.is_active = 1 AND "); + query.append("dupp.is_active = 1 AND "); + query.append(" dup.id_phase = d.id_phase AND "); + query.append("d.id_phase = di.id_phase AND "); + query.append("dup.id_phase =" + phaseId); + query.append(" and d.project_id =" + projectId); + query.append(" and di.status in (2,4) "); + query.append(" and d.is_active =1 "); + query.append(" and di.year >= p.year "); + query.append(" union "); + query.append("SELECT DISTINCT "); + query.append("dup.deliverable_id as id "); + query.append("FROM "); + query.append("deliverable_user_partnerships AS dup "); + query.append("INNER JOIN deliverable_user_partnership_persons AS dupp ON dupp.user_partnership_id = dup.id "); + query.append(" inner join deliverables as d on dup.deliverable_id = d.id "); + query.append(" inner join deliverables_info di on di.deliverable_id = d.id "); + query.append(" inner join phases p on p.id = d.id_phase "); + query.append("WHERE "); + query.append("dupp.user_id =" + userId + " AND "); + query.append("dup.is_active = 1 AND "); + query.append("dupp.is_active = 1 AND "); + query.append(" dup.id_phase = d.id_phase AND "); + query.append("d.id_phase = di.id_phase AND "); + query.append("dup.id_phase =" + phaseId); + query.append(" and d.project_id =" + projectId); + query.append(" and di.status in (4) "); + query.append(" and d.is_active =1 "); + query.append(" and di.new_expected_year >= p.year "); + + List> rList = super.findCustomQuery(query.toString()); + List deliverables = new ArrayList<>(); + + if (rList != null) { + for (Map map : rList) { + Deliverable deliverable = this.find(Long.parseLong(map.get("id").toString())); + deliverables.add(deliverable); + } + } + + return deliverables; + } + + + @Override + public List getDeliverablesLeadByUserAndProjectWithSimpleConditions(long userId, long phaseId, + long projectId) { + StringBuilder query = new StringBuilder(); + query.append("SELECT DISTINCT "); + query.append("dup.deliverable_id as id "); + query.append(",di.title as tittle "); + query.append("FROM "); + query.append("deliverable_user_partnerships AS dup "); + query.append("INNER JOIN deliverable_user_partnership_persons AS dupp ON dupp.user_partnership_id = dup.id "); + query.append(" inner join deliverables as d on dup.deliverable_id = d.id "); + query.append(" inner join deliverables_info di on di.deliverable_id = d.id "); + query.append(" inner join phases p on p.id = d.id_phase "); + query.append("WHERE "); + query.append("dupp.user_id =" + userId + " AND "); + query.append("dup.is_active = 1 AND "); + query.append("dupp.is_active = 1 AND "); + query.append(" dup.id_phase = d.id_phase AND "); + query.append("d.id_phase = di.id_phase AND "); + query.append("dup.id_phase =" + phaseId); + query.append(" and d.project_id =" + projectId); + query.append(" and di.status in (2,4) "); + query.append(" and d.is_active =1 "); + query.append(" and di.year >= p.year "); + query.append(" union "); + query.append("SELECT DISTINCT "); + query.append("dup.deliverable_id as id "); + query.append(",di.title as tittle "); + query.append("FROM "); + query.append("deliverable_user_partnerships AS dup "); + query.append("INNER JOIN deliverable_user_partnership_persons AS dupp ON dupp.user_partnership_id = dup.id "); + query.append(" inner join deliverables as d on dup.deliverable_id = d.id "); + query.append(" inner join deliverables_info di on di.deliverable_id = d.id "); + query.append(" inner join phases p on p.id = d.id_phase "); + query.append("WHERE "); + query.append("dupp.user_id =" + userId + " AND "); + query.append("dup.is_active = 1 AND "); + query.append("dupp.is_active = 1 AND "); + query.append(" dup.id_phase = d.id_phase AND "); + query.append("d.id_phase = di.id_phase AND "); + query.append("dup.id_phase =" + phaseId); + query.append(" and d.project_id =" + projectId); + query.append(" and di.status in (4) "); + query.append(" and d.is_active =1 "); + query.append(" and di.new_expected_year >= p.year "); + + List> rList = super.findCustomQuery(query.toString()); + List deliverables = new ArrayList<>(); + + if (rList != null) { + for (Map map : rList) { + DeliverableDTO deliverable = new DeliverableDTO(); + deliverable.setId(Long.parseLong(map.get("id").toString())); + deliverable.setTitle(map.get("tittle").toString()); + deliverables.add(deliverable); + } + } + + return deliverables; + } + /** * Get listing to validate duplicate information (dissemination_URL,DIO, handle) * diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/InstitutionMySQLDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/InstitutionMySQLDAO.java index cc8cee436d..7ddf5eecc2 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/InstitutionMySQLDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/InstitutionMySQLDAO.java @@ -64,7 +64,7 @@ public Institution find(long id) { @Override public List findAll() { - String query = "from " + Institution.class.getName(); + String query = "from " + Institution.class.getName() + " where is_active=1"; List list = super.findAll(query); if (list.size() > 0) { return list; diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/DeliverableManager.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/DeliverableManager.java index d86745abd1..14a37630f2 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/DeliverableManager.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/DeliverableManager.java @@ -15,6 +15,7 @@ package org.cgiar.ccafs.marlo.data.manager; import org.cgiar.ccafs.marlo.data.model.Deliverable; +import org.cgiar.ccafs.marlo.data.model.DeliverableDTO; import org.cgiar.ccafs.marlo.data.model.DeliverableHomeDTO; import org.cgiar.ccafs.marlo.data.model.LiaisonInstitution; import org.cgiar.ccafs.marlo.data.model.Phase; @@ -130,6 +131,12 @@ List getDeliverablesByPhaseAndUrlAndDoiAndHandel(long phase, String List getDeliverablesLeadByUserAndProject(long userId, long phaseId, long projectId); + List getDeliverablesLeadByUserAndProjectWithConditions(long userId, long phaseId, long projectId); + + List getDeliverablesLeadByUserAndProjectWithSimpleConditions(long userId, long phaseId, + long projectId); + + /** * This method gets a list of deliverables that are active for an specific liaisonInstitution * Flagship: Get the list of projects that have project_focus equal to the liaisonInstitution @@ -146,6 +153,7 @@ List getDeliverablesByPhaseAndUrlAndDoiAndHandel(long phase, String public List getNotPublicationsList(LiaisonInstitution liaisonInstitution, Phase phase); + /** * This method gets a list of publications that are active by a given phase * diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/impl/DeliverableManagerImpl.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/impl/DeliverableManagerImpl.java index a4eb33c7ed..41b8b6159a 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/impl/DeliverableManagerImpl.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/impl/DeliverableManagerImpl.java @@ -29,6 +29,7 @@ import org.cgiar.ccafs.marlo.data.model.CrpClusterKeyOutput; import org.cgiar.ccafs.marlo.data.model.CrpClusterOfActivity; import org.cgiar.ccafs.marlo.data.model.Deliverable; +import org.cgiar.ccafs.marlo.data.model.DeliverableDTO; import org.cgiar.ccafs.marlo.data.model.DeliverableHomeDTO; import org.cgiar.ccafs.marlo.data.model.DeliverableInfo; import org.cgiar.ccafs.marlo.data.model.DeliverableProgram; @@ -214,6 +215,28 @@ public List getDeliverablesLeadByUserAndProject(long userId, long p return deliverableDAO.getDeliverablesLeadByUserAndProject(userId, phaseId, projectId); } + @Override + public List getDeliverablesLeadByUserAndProjectWithConditions(long userId, long phaseId, + long projectId) { + return deliverableDAO.getDeliverablesLeadByUserAndProjectWithConditions(userId, phaseId, projectId); + } + + /** + * get deliverables list by user, phase and project + * + * @author IBD + * @param phaseId phase id + * @param projectId project id + * @param userId user id + * @return deliverables (DTO) list + */ + @Override + public List getDeliverablesLeadByUserAndProjectWithSimpleConditions(long userId, long phaseId, + long projectId) { + return deliverableDAO.getDeliverablesLeadByUserAndProjectWithSimpleConditions(userId, phaseId, projectId); + } + + @Override public List getDeliverablesList(LiaisonInstitution liaisonInstitution, Phase phase) { Phase phaseDB = phaseManager.getPhaseById(phase.getId()); diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/model/DeliverableDTO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/model/DeliverableDTO.java new file mode 100644 index 0000000000..3c7649c1e4 --- /dev/null +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/model/DeliverableDTO.java @@ -0,0 +1,52 @@ +/***************************************************************** + * This file is part of Managing Agricultural Research for Learning & + * Outcomes Platform (MARLO). + * MARLO is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * MARLO is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with MARLO. If not, see . + *****************************************************************/ + +package org.cgiar.ccafs.marlo.data.model; + + +public class DeliverableDTO { + + Long id; + + private String title; + + + public Long getId() { + return id; + } + + + public String getTitle() { + return title; + } + + + public void setId(Long id) { + this.id = id; + } + + + public void setTitle(String title) { + this.title = title; + } + + + @Override + public String toString() { + return "DeliverableDTO [id=" + id + ", title=" + title + "]"; + } + + +} diff --git a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/projects/ProjectPartnerAction.java b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/projects/ProjectPartnerAction.java index a72c4323c6..5b12d20bb1 100644 --- a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/projects/ProjectPartnerAction.java +++ b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/projects/ProjectPartnerAction.java @@ -58,6 +58,7 @@ import org.cgiar.ccafs.marlo.data.model.CrpProgramLeader; import org.cgiar.ccafs.marlo.data.model.CrpUser; import org.cgiar.ccafs.marlo.data.model.Deliverable; +import org.cgiar.ccafs.marlo.data.model.DeliverableDTO; import org.cgiar.ccafs.marlo.data.model.GlobalUnit; import org.cgiar.ccafs.marlo.data.model.GlobalUnitProject; import org.cgiar.ccafs.marlo.data.model.Institution; @@ -465,6 +466,7 @@ public List getDeliverablesLedByPartner(Long projectPartnerID) { List deliverablesLeads = new ArrayList<>(); if (projectPartnerID != null && projectPartnerID != 0) { ProjectPartner projectPartner = projectPartnerManager.getProjectPartnerById(projectPartnerID); + if (projectPartner != null) { /// cgamboa 17/05/2024 getDeliverablesLeadByInstitution was changed by /// getDeliverablesLeadByInstitutionAndProject @@ -472,7 +474,6 @@ public List getDeliverablesLedByPartner(Long projectPartnerID) { // .getDeliverablesLeadByInstitution(projectPartner.getInstitution().getId(), this.getActualPhase().getId()); .getDeliverablesLeadByInstitutionAndProject(projectPartner.getInstitution().getId(), this.getActualPhase().getId(), projectID); - for (Deliverable deliverable : deliverables) { if (deliverable.getProject() != null && deliverable.getProject().getId().equals(projectID)) { deliverable.setDeliverableInfo(deliverable.getDeliverableInfo(this.getActualPhase())); @@ -504,8 +505,29 @@ public List getDeliverablesLedByPartner(Long projectPartnerID) { return deliverablesLeads; } + /** + * get deliverables list by user + * + * @author IBD + * @param userId user id + * @return deliverables (DTO) list + */ + public List getDeliverablesLedByUser(long userID) { + List deliverablesLeadsTmp = new ArrayList<>(); + try { + + deliverablesLeadsTmp = deliverableManager.getDeliverablesLeadByUserAndProjectWithSimpleConditions(userID, + this.getActualPhase().getId(), projectID); - public List getDeliverablesLedByUser(long userID) { + } catch (Exception e) { + LOG.error(" unable to get deliverables - getDeliverablesLedByUser function "); + } + return deliverablesLeadsTmp; + + } + + + public List getDeliverablesLedByUserOld(long userID) { List deliverablesLeads = new ArrayList<>(); List deliverables = // cgamboa 16/05/2024 getDeliverablesLeadByUser was changed by getDeliverablesLeadByUser @@ -1808,7 +1830,6 @@ public String save() { } else { this.addActionMessage("message:" + this.getText("saving.saved")); } - return SUCCESS; } else { this.addActionMessage(""); diff --git a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/summaries/ReportingSummaryAction.java b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/summaries/ReportingSummaryAction.java index 31c438a7b8..b51f43a040 100644 --- a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/summaries/ReportingSummaryAction.java +++ b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/summaries/ReportingSummaryAction.java @@ -7668,7 +7668,8 @@ public void prepare() { } catch (Exception e) { LOG.error("Failed to get project. Exception: " + e.getMessage()); } - if (this.getSelectedPhase() != null && project.getProjecInfoPhase(this.getSelectedPhase()) != null) { + if (this.getSelectedPhase() != null && project != null + && project.getProjecInfoPhase(this.getSelectedPhase()) != null) { this.setProjectInfo(project.getProjecInfoPhase(this.getSelectedPhase())); } } diff --git a/marlo-web/src/main/webapp/WEB-INF/crp/views/projects/projectPartners.ftl b/marlo-web/src/main/webapp/WEB-INF/crp/views/projects/projectPartners.ftl index 294f0f2558..788c937f32 100644 --- a/marlo-web/src/main/webapp/WEB-INF/crp/views/projects/projectPartners.ftl +++ b/marlo-web/src/main/webapp/WEB-INF/crp/views/projects/projectPartners.ftl @@ -418,7 +418,9 @@ [/#if] - + + [#assign permissionLeader = action.hasPermission("leader")] + [#assign permissionCoordinator = action.hasPermission("coordinator")] [#-- Contacts person(s) --]
[@s.text name="projectPartners.projectPartnerContacts" /] [@customForm.req required=isPPA /]
@@ -462,16 +464,16 @@
- [#local canEditLeader=(editable && action.hasPermission("leader"))!false /] - [#local canEditCoordinator=(editable && action.hasPermission("coordinator"))!false /] + [#local canEditLeader=(editable && permissionLeader)!false /] + [#local canEditCoordinator=(editable && permissionCoordinator)!false /] [#local isPPA = (action.isPPA(element.projectPartner.institution))!false /] [#if (element.contactType == "PL")!false] - [#local canEditContactType = (editable && action.hasPermission("leader"))!false /] + [#local canEditContactType = (editable && permissionLeader)!false /] [#elseif (element.contactType == "PC")!false] - [#local canEditContactType = (editable && action.hasPermission("coordinator"))!false /] + [#local canEditContactType = (editable && permissionCoordinator)!false /] [#else] [#local canEditContactType = editable || isTemplate /] [/#if] @@ -547,7 +549,7 @@

Deliverables

    [#list deliverablesLedByUserList as deliverable] -
  • ${deliverable.deliverableInfo.title}
  • +
  • ${deliverable.title}
  • [/#list]