diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/ActivityTitleDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/ActivityTitleDAO.java index 8d4f897066..bca3dbdaf0 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/ActivityTitleDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/ActivityTitleDAO.java @@ -54,6 +54,14 @@ public interface ActivityTitleDAO { */ public List findAll(); + /** + * This method gets a list of activityTitle that are active + * + * @param year is a int object. + * @return a list from ActivityTitle null if no exist records + */ + public List findByCurrentYear(int year); + /** * This method saves the information of the given activityTitle diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ActivityTitleMySQLDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ActivityTitleMySQLDAO.java index 0c62c6912d..f4f0165752 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ActivityTitleMySQLDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/ActivityTitleMySQLDAO.java @@ -24,6 +24,7 @@ import javax.inject.Inject; import javax.inject.Named; +import org.hibernate.Query; import org.hibernate.SessionFactory; @Named @@ -68,6 +69,18 @@ public List findAll() { } + @Override + public List findByCurrentYear(int year) { + String query = "select pat from ActivityTitle pat where pat.endYear >= :year and pat.startYear < :year"; + Query createQuery = this.getSessionFactory().getCurrentSession().createQuery(query); + createQuery.setParameter("year", year); + List list = super.findAll(createQuery); + if (!list.isEmpty()) { + return list; + } + return null; + } + @Override public ActivityTitle save(ActivityTitle activityTitle) { if (activityTitle.getId() == null) { diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/ActivityTitleManager.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/ActivityTitleManager.java index c0cf6c4f98..bcf5b322b2 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/ActivityTitleManager.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/ActivityTitleManager.java @@ -51,6 +51,14 @@ public interface ActivityTitleManager { */ public List findAll(); + /** + * This method gets a list of activityTitle that are active + * + * @param year is a int object. + * @return a list from ActivityTitle null if no exist records + */ + public List findByCurrentYear(int year); + /** * This method gets a activityTitle object by a given activityTitle identifier. diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/impl/ActivityTitleManagerImpl.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/impl/ActivityTitleManagerImpl.java index 1e9f1105fe..430927a70a 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/impl/ActivityTitleManagerImpl.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/impl/ActivityTitleManagerImpl.java @@ -61,6 +61,11 @@ public List findAll() { } + @Override + public List findByCurrentYear(int year) { + return activityTitleDAO.findByCurrentYear(year); + } + @Override public ActivityTitle getActivityTitleById(long activityTitleID) { diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/model/ActivityTitle.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/model/ActivityTitle.java index 3ebb10f6c1..355f8d2c8a 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/model/ActivityTitle.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/model/ActivityTitle.java @@ -31,7 +31,10 @@ public class ActivityTitle extends MarloBaseEntity implements java.io.Serializab private String title; private Set activities = new HashSet(0); - + @Expose + private int startYear; + @Expose + private int endYear; @Override public boolean equals(Object obj) { @@ -58,6 +61,10 @@ public Set getActivities() { return activities; } + public int getEndYear() { + return endYear; + } + @Override public String getLogDeatil() { @@ -80,12 +87,14 @@ public User getModifiedBy() { return null; } + public int getStartYear() { + return startYear; + } public String getTitle() { return title; } - @Override public int hashCode() { final int prime = 31; @@ -104,11 +113,19 @@ public void setActivities(Set activities) { this.activities = activities; } + public void setEndYear(int endYear) { + this.endYear = endYear; + } + @Override public void setModifiedBy(User modifiedBy) { // TODO Auto-generated method stub } + public void setStartYear(int startYear) { + this.startYear = startYear; + } + public void setTitle(String title) { this.title = title; } diff --git a/marlo-data/src/main/resources/xmls/ActivitiesTitles.hbm.xml b/marlo-data/src/main/resources/xmls/ActivitiesTitles.hbm.xml index 0cc5710995..d54df7eced 100644 --- a/marlo-data/src/main/resources/xmls/ActivitiesTitles.hbm.xml +++ b/marlo-data/src/main/resources/xmls/ActivitiesTitles.hbm.xml @@ -11,6 +11,12 @@ + + + + + + diff --git a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/BaseAction.java b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/BaseAction.java index 34c8b20848..1b35898519 100644 --- a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/BaseAction.java +++ b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/BaseAction.java @@ -934,21 +934,24 @@ public boolean canBeDeleted(long id, String className) { if (clazz == ProjectOutcome.class) { if (this.isAiccra()) { boolean canDelete = true; - ProjectOutcome projectOutcome = this.projectOutcomeManager.getProjectOutcomeById(id); + ProjectOutcome projectOutcome = null; + try { + projectOutcome = this.projectOutcomeManager.getProjectOutcomeById(id); - for (Deliverable deliverable : projectOutcome.getProject().getCurrentDeliverables(this.getActualPhase())) { - if (deliverable.getDeliverableProjectOutcomes() != null) { - deliverable.setProjectOutcomes(new ArrayList<>(deliverable.getDeliverableProjectOutcomes().stream() - .filter(o -> o.getPhase().getId().equals(this.getActualPhase().getId())).collect(Collectors.toList()))); - } - if (deliverable != null && deliverable.getProjectOutcomes() != null - && !deliverable.getProjectOutcomes().isEmpty()) { - if (deliverable != null && deliverable.getProjectOutcomes() != null - && !deliverable.getProjectOutcomes().isEmpty()) { - for (DeliverableProjectOutcome deliverableProjectOutcome : deliverable.getProjectOutcomes()) { - if (deliverableProjectOutcome != null && deliverableProjectOutcome.getProjectOutcome() != null - && deliverableProjectOutcome.getProjectOutcome().getId() != null - && deliverableProjectOutcome.getProjectOutcome().getId().compareTo(projectOutcome.getId()) == 0) { + for (Deliverable deliverable : projectOutcome.getProject().getCurrentDeliverables(this.getActualPhase())) { + if (deliverable.getDeliverableCrpOutcomes() != null) { + deliverable.setCrpOutcomes(new ArrayList<>(deliverable.getDeliverableCrpOutcomes().stream() + .filter(o -> o.getPhase().getId().equals(this.getActualPhase().getId())) + .collect(Collectors.toList()))); + } + + if (deliverable != null && deliverable.getCrpOutcomes() != null + && !deliverable.getCrpOutcomes().isEmpty()) { + + for (DeliverableCrpOutcome deliverableCrpOutcome : deliverable.getCrpOutcomes()) { + if (deliverableCrpOutcome != null && deliverableCrpOutcome.getCrpProgramOutcome() != null + && deliverableCrpOutcome.getCrpProgramOutcome().getId() != null && deliverableCrpOutcome + .getCrpProgramOutcome().getId().compareTo(projectOutcome.getCrpProgramOutcome().getId()) == 0) { canDelete = false; break; @@ -956,26 +959,27 @@ public boolean canBeDeleted(long id, String className) { } } } + } catch (Exception e) { + e.printStackTrace(); } - try { for (ProjectExpectedStudy expectedStudy : projectOutcome.getProject().getProjectExpectedStudies().stream() .filter(ps -> ps.isActive() && ps.getProjectExpectedStudyInfo(this.getActualPhase()) != null && ps.getProjectExpectedStudyInfo(this.getActualPhase()).isActive()) .collect(Collectors.toList())) { - if (expectedStudy.getProjectExpectedStudyProjectOutcomes() != null) { - expectedStudy.setProjectOutcomes(new ArrayList<>(expectedStudy.getProjectExpectedStudyProjectOutcomes() - .stream().filter(o -> o.getPhase().getId().equals(this.getActualPhase().getId())) + if (expectedStudy.getProjectExpectedStudyCrpOutcomes() != null) { + expectedStudy.setCrpOutcomes(new ArrayList<>(expectedStudy.getProjectExpectedStudyCrpOutcomes().stream() + .filter(o -> o.getPhase().getId().equals(this.getActualPhase().getId())) .collect(Collectors.toList()))); } - if (expectedStudy != null && expectedStudy.getProjectOutcomes() != null - && !expectedStudy.getProjectOutcomes().isEmpty()) { - for (ProjectExpectedStudyProjectOutcome expectedStudyProjectOutcome : expectedStudy - .getProjectOutcomes()) { - if (expectedStudyProjectOutcome != null && expectedStudyProjectOutcome.getProjectOutcome() != null - && expectedStudyProjectOutcome.getProjectOutcome().getId() != null - && expectedStudyProjectOutcome.getProjectOutcome().getId().compareTo(projectOutcome.getId()) == 0) { + if (expectedStudy != null && expectedStudy.getCrpOutcomes() != null + && !expectedStudy.getCrpOutcomes().isEmpty()) { + for (ProjectExpectedStudyCrpOutcome expectedStudyCrpOutcome : expectedStudy.getCrpOutcomes()) { + if (expectedStudyCrpOutcome != null && expectedStudyCrpOutcome.getCrpOutcome() != null + && expectedStudyCrpOutcome.getCrpOutcome().getId() != null && projectOutcome != null + && projectOutcome.getCrpProgramOutcome() != null && expectedStudyCrpOutcome.getCrpOutcome().getId() + .compareTo(projectOutcome.getCrpProgramOutcome().getId()) == 0) { canDelete = false; break; } @@ -991,18 +995,16 @@ public boolean canBeDeleted(long id, String className) { .filter(ps -> ps.isActive() && ps.getProjectInnovationInfo(this.getActualPhase()) != null && ps.getProjectInnovationInfo(this.getActualPhase()).isActive()) .collect(Collectors.toList())) { - if (innovation.getProjectInnovationProjectOutcomes() != null) { - innovation.setProjectOutcomes(new ArrayList<>(innovation.getProjectInnovationProjectOutcomes().stream() + if (innovation.getProjectInnovationCrpOutcomes() != null) { + innovation.setCrpOutcomes(new ArrayList<>(innovation.getProjectInnovationCrpOutcomes().stream() .filter(o -> o.getPhase().getId().equals(this.getActualPhase().getId())) .collect(Collectors.toList()))); } - if (innovation != null && innovation.getProjectOutcomes() != null - && !innovation.getProjectOutcomes().isEmpty()) { - for (ProjectInnovationProjectOutcome innovationStudyProjectOutcome : innovation.getProjectOutcomes()) { - if (innovationStudyProjectOutcome != null && innovationStudyProjectOutcome.getProjectOutcome() != null - && innovationStudyProjectOutcome.getProjectOutcome().getId() != null - && innovationStudyProjectOutcome.getProjectOutcome().getId() - .compareTo(projectOutcome.getId()) == 0) { + if (innovation != null && innovation.getCrpOutcomes() != null && !innovation.getCrpOutcomes().isEmpty()) { + for (ProjectInnovationCrpOutcome innovationStudyCrpOutcome : innovation.getCrpOutcomes()) { + if (innovationStudyCrpOutcome != null && innovationStudyCrpOutcome.getCrpOutcome() != null + && innovationStudyCrpOutcome.getCrpOutcome().getId() != null && innovationStudyCrpOutcome + .getCrpOutcome().getId().compareTo(projectOutcome.getCrpProgramOutcome().getId()) == 0) { canDelete = false; break; } diff --git a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/projects/ProjectActivitiesAction.java b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/projects/ProjectActivitiesAction.java index 04042ca7ae..0c5859600e 100644 --- a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/projects/ProjectActivitiesAction.java +++ b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/projects/ProjectActivitiesAction.java @@ -451,7 +451,33 @@ public void prepare() throws Exception { if (this.isAiccra()) { if (activityTitleManager.findAll() != null && !activityTitleManager.findAll().isEmpty()) { - activityTitles = activityTitleManager.findAll(); + + + try { + activityTitles = activityTitleManager.findByCurrentYear(this.getActualPhase().getYear()); + } catch (Exception e) { + logger.error("unable to get activity title by date", e); + } + + if (activityTitles == null || (activityTitles != null && activityTitles.isEmpty())) { + activityTitles = activityTitleManager.findAll(); + } + /* + * List tempActivityTitles = new ArrayList<>(); + * for (ActivityTitle activityTitle : activityTitles) { + * if (activityTitle != null && activityTitle.getStartDate() != null && activityTitle.getEndDate() != null) { + * if (activityTitle.getStartDate().before(this.getActualPhase().getStartDate()) + * && activityTitle.getEndDate().after(this.getActualPhase().getEndDate())) { + * tempActivityTitles.add(activityTitle); + * } + * } + * } + */ + /* + * if (activityTitles != null && !activityTitles.isEmpty()) { + * activityTitles = tempActivityTitles; + * } + */ if (activityTitles != null && activityTitles.isEmpty()) { activityTitles.sort((a1, a2) -> a1.getTitle().compareTo(a2.getTitle())); } diff --git a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/summaries/ProgressReportProcessPOISummaryAction.java b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/summaries/ProgressReportProcessPOISummaryAction.java index 920e8d9f69..682e750881 100644 --- a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/summaries/ProgressReportProcessPOISummaryAction.java +++ b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/summaries/ProgressReportProcessPOISummaryAction.java @@ -802,6 +802,7 @@ public String execute() throws Exception { indicatorsList.add("IPI 2.2"); indicatorsList.add("IPI 2.3"); indicatorsList.add("IPI 2.4"); + indicatorsList.add("IPI 2.5"); indicatorsList.add("IPI 3.1"); indicatorsList.add("IPI 3.2"); indicatorsList.add("IPI 3.3"); @@ -920,6 +921,15 @@ public String execute() throws Exception { .collect(Collectors.toList())); } catch (Exception e) { } + // IPI 2.5 + try { + projectOutcomes.addAll(project.getProjectOutcomes().stream() + .filter(c -> c.isActive() && c.getPhase().equals(this.getSelectedPhase()) + && c.getCrpProgramOutcome() != null && c.getCrpProgramOutcome().getComposedName() != null + && c.getCrpProgramOutcome().getComposedName().contains("IPI 2.5")) + .collect(Collectors.toList())); + } catch (Exception e) { + } // IPI 3.1 diff --git a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/validation/projects/ProjectOutcomeValidator.java b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/validation/projects/ProjectOutcomeValidator.java index 9a6cf32cd6..64b3e01972 100644 --- a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/validation/projects/ProjectOutcomeValidator.java +++ b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/validation/projects/ProjectOutcomeValidator.java @@ -302,6 +302,7 @@ public void validateAiccraProjectOutcomeIndicator(BaseAction action, ProjectOutc // IPI 2.1, 2.3, IPI 3.1, IPI 3.2, IPI 3.4, IPI 3.5 if (programOutcome.contains("IPI 2.1") || programOutcome.contains("IPI 2.3") || programOutcome.contains("IPI 3.1") || programOutcome.contains("IPI 3.2") || programOutcome.contains("IPI 3.4") + || programOutcome.contains("IPI 2.4") || programOutcome.contains("IPI 2.5") || programOutcome.contains("IPI 3.5")) { List params = new ArrayList<>(); params.add(String.valueOf(i + 1)); diff --git a/marlo-web/src/main/resources/database/migrations/V2_6_0_20230808_0823__AddFieldsColumnActivityTitle.sql b/marlo-web/src/main/resources/database/migrations/V2_6_0_20230808_0823__AddFieldsColumnActivityTitle.sql new file mode 100644 index 0000000000..64fdf2f002 --- /dev/null +++ b/marlo-web/src/main/resources/database/migrations/V2_6_0_20230808_0823__AddFieldsColumnActivityTitle.sql @@ -0,0 +1,2 @@ +ALTER TABLE activities_titles ADD start_year int(4) NULL; +ALTER TABLE activities_titles ADD end_year int(4) NULL; \ No newline at end of file diff --git a/marlo-web/src/main/resources/global.properties b/marlo-web/src/main/resources/global.properties index 50a5738cd2..77b6daa131 100644 --- a/marlo-web/src/main/resources/global.properties +++ b/marlo-web/src/main/resources/global.properties @@ -2552,6 +2552,7 @@ project.deliverable.notDuplicated=Not duplicated project.deliverable.isDuplicated=Duplicated project.deliverable.duplicated.legend=Deliverables identified as duplicates project.deliverable.responsible.person=Responsible person +project.deliverable.activities.readText=Activities # Deliverable MODEL deliverable.crossCuttingDimensions=Does this deliverable have a cross-cutting dimension(s)? deliverable.crossCuttingDimensions.readText=Deliverable cross-cutting dimension(s) diff --git a/marlo-web/src/main/webapp/WEB-INF/crp/views/projects/deliverableInfo.ftl b/marlo-web/src/main/webapp/WEB-INF/crp/views/projects/deliverableInfo.ftl index eac99b6359..c080090a78 100644 --- a/marlo-web/src/main/webapp/WEB-INF/crp/views/projects/deliverableInfo.ftl +++ b/marlo-web/src/main/webapp/WEB-INF/crp/views/projects/deliverableInfo.ftl @@ -1,6 +1,6 @@ [#ftl] - +
[#-- Title input --]