diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/ActivityDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/ActivityDAO.java index e28bf3ff2d..9e072c6644 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/ActivityDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/ActivityDAO.java @@ -54,6 +54,15 @@ public interface ActivityDAO { */ public List findAll(); + /** + * This method obtains the number of existing activities, by deliverable and phase + * + * @param deliverableId deliverable identifier. + * @param phaseId phase identifier. + * @return number of existing activities + */ + int getActivitiesByDeliverableAndPhaseQuantity(long deliverableId, long phaseId); + /** * This method validate if the activity identify with the given id exists in the system. * diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/DeliverableInfoDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/DeliverableInfoDAO.java index 17afb596ca..ededd96694 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/DeliverableInfoDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/DeliverableInfoDAO.java @@ -69,6 +69,13 @@ public interface DeliverableInfoDAO { */ public List getDeliverablesInfoByProjectAndPhase(Phase phase, Project project); + /** + * This method gets a list of DeliverableInfo that are active by a given phase and project (including shared projects) + * + * @return a list from DeliverableInfo null if no exist records + */ + List getDeliverablesInfoByProjectAndPhaseWithSharedProjects(Phase phase, Project project); + /** * This method gets a list of DeliverableInfo that are active by a given phase and type * 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 01f1580e0b..c66ddfab7e 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 @@ -71,6 +71,29 @@ public List findAll() { } + + @Override + public int getActivitiesByDeliverableAndPhaseQuantity(long deliverableId, long phaseId) { + + StringBuilder query = new StringBuilder(); + query.append("SELECT count(*) as count from deliverable_activities da "); + query.append(" where deliverable_id= " + deliverableId); + query.append(" and id_phase = " + phaseId); + query.append(" and is_active =1 "); + + List> rList = super.findCustomQuery(query.toString()); + int activity = 0; + + if (rList != null) { + for (Map map : rList) { + activity = Integer.parseInt(map.get("count").toString()); + } + } + + return activity; + + } + @Override public List getActivitiesByProject(long projectId, long phaseId) { String query = "from " + Activity.class.getName() + " where project_id=" + projectId + " and id_phase=" + phaseId @@ -83,6 +106,7 @@ public List getActivitiesByProject(long projectId, long phaseId) { } + @Override public int getActivitiesByProjectAndUserQuantity(long projectId, long phaseId, long projectPersonId) { diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableInfoMySQLDAO.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableInfoMySQLDAO.java index a84a29c6fe..4818a4fc94 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableInfoMySQLDAO.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/dao/mysql/DeliverableInfoMySQLDAO.java @@ -152,6 +152,34 @@ public List getDeliverablesInfoByProjectAndPhase(Phase phase, P return deliverableInfos; } + + @Override + public List getDeliverablesInfoByProjectAndPhaseWithSharedProjects(Phase phase, Project project) { + StringBuilder query = new StringBuilder(); + query.append("SELECT "); + query.append("DISTINCT di.id AS id "); + query.append("FROM deliverables_info AS di "); + query.append("LEFT JOIN deliverables AS d ON d.id = di.deliverable_id AND d.is_active = 1 AND d.project_id = " + + project.getId()); + query.append( + " LEFT JOIN project_deliverable_shared AS pds ON pds.deliverable_id = di.deliverable_id AND pds.is_active = 1 AND pds.project_id = " + + project.getId()); + query.append(" WHERE di.is_active = 1 AND di.id_phase = " + phase.getId()); + query.append(" AND (d.id IS NOT NULL OR pds.id IS NOT NULL)"); + + List> rList = super.findCustomQuery(query.toString()); + List deliverableInfos = new ArrayList<>(); + + if (rList != null) { + for (Map map : rList) { + DeliverableInfo deliverableInfo = this.find(Long.parseLong(map.get("id").toString())); + deliverableInfos.add(deliverableInfo); + } + } + + return deliverableInfos; + } + @Override public List getDeliverablesInfoByType(Phase phase, DeliverableType deliverableType) { StringBuilder query = new StringBuilder(); diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/ActivityManager.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/ActivityManager.java index 03b8dc52da..6446839628 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/ActivityManager.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/ActivityManager.java @@ -55,6 +55,15 @@ public interface ActivityManager { */ public List findAll(); + /** + * This method obtains the number of existing activities, by deliverable and phase + * + * @param deliverableId deliverable identifier. + * @param phaseId phase identifier. + * @return number of existing activities + */ + int getActivitiesByDeliverableAndPhaseQuantity(long deliverableId, long phaseId); + /** * This method gets a activity object by a given activity identifier. * @@ -75,6 +84,7 @@ public interface ActivityManager { int getActivitiesByProjectAndUserQuantity(long projectId, long phaseId, long projectPersonId); + /** * This method gets a activity object by a given activity identifier. * diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/DeliverableInfoManager.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/DeliverableInfoManager.java index d3c19e39a7..0073db0017 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/DeliverableInfoManager.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/DeliverableInfoManager.java @@ -73,6 +73,13 @@ public interface DeliverableInfoManager { */ public List getDeliverablesInfoByProjectAndPhase(Phase phase, Project project); + /** + * This method gets a list of DeliverableInfo that are active by a given phase and project (including shared projects) + * + * @return a list from DeliverableInfo null if no exist records + */ + List getDeliverablesInfoByProjectAndPhaseWithSharedProjects(Phase phase, Project project); + /** * This method gets a list of DeliverableInfo that are active by a given phase and type * @@ -80,6 +87,7 @@ public interface DeliverableInfoManager { */ public List getDeliverablesInfoByType(Phase phase, DeliverableType deliverableType); + public boolean isDeliverableSubcategoryIncludedWebsite(long deliverableID, Phase phase); diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/impl/ActivityManagerImpl.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/impl/ActivityManagerImpl.java index 10a04dc4ce..c028182264 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/impl/ActivityManagerImpl.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/impl/ActivityManagerImpl.java @@ -174,17 +174,23 @@ public List findAll() { } + @Override + public int getActivitiesByDeliverableAndPhaseQuantity(long deliverableId, long phaseId) { + return activityDAO.getActivitiesByDeliverableAndPhaseQuantity(deliverableId, phaseId); + } + + @Override public List getActivitiesByProject(long projectId, long phaseId) { return activityDAO.getActivitiesByProject(projectId, phaseId); } - @Override public int getActivitiesByProjectAndUserQuantity(long projectId, long phaseId, long projectPersonId) { return activityDAO.getActivitiesByProjectAndUserQuantity(projectId, phaseId, projectPersonId); } + @Override public Activity getActivityById(long activityID) { diff --git a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/impl/DeliverableInfoManagerImpl.java b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/impl/DeliverableInfoManagerImpl.java index 036cb5283b..5d53786d96 100644 --- a/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/impl/DeliverableInfoManagerImpl.java +++ b/marlo-data/src/main/java/org/cgiar/ccafs/marlo/data/manager/impl/DeliverableInfoManagerImpl.java @@ -104,6 +104,13 @@ public List getDeliverablesInfoByProjectAndPhase(Phase phase, P return deliverableInfoDAO.getDeliverablesInfoByProjectAndPhase(phase, project); } + + @Override + public List getDeliverablesInfoByProjectAndPhaseWithSharedProjects(Phase phase, Project project) { + return deliverableInfoDAO.getDeliverablesInfoByProjectAndPhaseWithSharedProjects(phase, project); + } + + @Override public List getDeliverablesInfoByType(Phase phase, DeliverableType deliverableType) { return deliverableInfoDAO.getDeliverablesInfoByType(phase, deliverableType); 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 b7bf661d39..19ed7c8299 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 @@ -7632,7 +7632,11 @@ public boolean isPPAOld(Institution institution) { } public boolean isProgressActive() { - return this.getActualPhase().getUpkeep(); + try { + return this.getActualPhase().getUpkeep(); + } catch (Exception e) { + return false; + } } /** @@ -8843,6 +8847,28 @@ public boolean validateEmailNotification() { return crpNotification; } + /** + * Validate if the current phase is progress, with status + * + * @param status entity status + * @return validation result + */ + + public boolean validateIsProgressWithStatus(int status) { + boolean result = true; + try { + + if (this.isProgressActive() && status != Integer.parseInt(ProjectStatusEnum.Complete.getStatusId())) { + result = false; + } + return result; + } catch (Exception e) { + LOG.error(" error in validateIsProgressAndNotStatus function [BaseAction]"); + return result; + } + } + + public boolean validatePolicy(long policyID) { SectionStatus sectionStatus = this.sectionStatusManager.getSectionStatusByProjectPolicy(policyID, this.getCurrentCycle(), @@ -8857,6 +8883,7 @@ public boolean validatePolicy(long policyID) { return true; } + // public boolean validURL(String URL) { try { diff --git a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/json/project/ValidateProjectSectionAction.java b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/json/project/ValidateProjectSectionAction.java index c1d3997dfc..c99acf3485 100644 --- a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/json/project/ValidateProjectSectionAction.java +++ b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/json/project/ValidateProjectSectionAction.java @@ -20,12 +20,14 @@ import org.cgiar.ccafs.marlo.config.APConstants; import org.cgiar.ccafs.marlo.config.MarloLocalizedTextProvider; import org.cgiar.ccafs.marlo.data.manager.DeliverableInfoManager; +import org.cgiar.ccafs.marlo.data.manager.ExpectedStudyProjectManager; import org.cgiar.ccafs.marlo.data.manager.GlobalUnitManager; import org.cgiar.ccafs.marlo.data.manager.GlobalUnitProjectManager; import org.cgiar.ccafs.marlo.data.manager.ProjectManager; import org.cgiar.ccafs.marlo.data.manager.SectionStatusManager; import org.cgiar.ccafs.marlo.data.model.Deliverable; import org.cgiar.ccafs.marlo.data.model.DeliverableInfo; +import org.cgiar.ccafs.marlo.data.model.ExpectedStudyProject; import org.cgiar.ccafs.marlo.data.model.GlobalUnit; import org.cgiar.ccafs.marlo.data.model.GlobalUnitProject; import org.cgiar.ccafs.marlo.data.model.Phase; @@ -45,6 +47,7 @@ import org.cgiar.ccafs.marlo.validation.projects.ProjectSectionValidator; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -93,14 +96,14 @@ public class ValidateProjectSectionAction extends BaseAction { private final ProjectSectionValidator projectSectionValidator; private final GlobalUnitProjectManager globalUnitProjectManager; private final DeliverableInfoManager deliverableInfoManager; - + private ExpectedStudyProjectManager expectedStudyProjectManager; @Inject public ValidateProjectSectionAction(APConfig config, GlobalUnitManager crpManager, ProjectManager projectManager, SectionStatusManager sectionStatusManager, ProjectSectionValidator projectSectionValidator, LocalizedTextProvider localizedTextProvider, GlobalUnitProjectManager globalUnitProjectManager, - DeliverableInfoManager deliverableInfoManager) { + DeliverableInfoManager deliverableInfoManager, ExpectedStudyProjectManager expectedStudyProjectManager) { super(config); this.sectionStatusManager = sectionStatusManager; this.projectManager = projectManager; @@ -109,6 +112,7 @@ public ValidateProjectSectionAction(APConfig config, GlobalUnitManager crpManage this.localizedTextProvider = localizedTextProvider; this.globalUnitProjectManager = globalUnitProjectManager; this.deliverableInfoManager = deliverableInfoManager; + this.expectedStudyProjectManager = expectedStudyProjectManager; } @@ -320,7 +324,13 @@ public String execute() throws Exception { if (deliverable.getDeliverableInfo(phase).getStatus() != null && deliverable.getDeliverableInfo(phase) .getStatus().intValue() == Integer.parseInt(ProjectStatusEnum.Ongoing.getStatusId())) { if (deliverable.getDeliverableInfo(phase).getYear() > this.getActualPhase().getYear()) { - sectionStatus.setMissingFields(""); + + // 2024/06/07 cgamboa Functionality is added to validate all deliverables regardless of the year, in + // progress phase + if (!deliverable.getDeliverableInfo().getPhase().getUpkeep()) { + sectionStatus.setMissingFields(""); + } + } } @@ -334,7 +344,11 @@ public String execute() throws Exception { if (deliverable.getDeliverableInfo(phase).getStatus() != null && deliverable.getDeliverableInfo(phase) .getStatus().intValue() == Integer.parseInt(ProjectStatusEnum.Cancelled.getStatusId())) { - sectionStatus.setMissingFields(""); + // 2024/06/07 cgamboa Functionality is added to validate all deliverables regardless of the year, in + // progress phase + if (!deliverable.getDeliverableInfo().getPhase().getUpkeep()) { + sectionStatus.setMissingFields(""); + } } } @@ -381,16 +395,40 @@ public String execute() throws Exception { && ps.getProjectExpectedStudyInfo().getStatus() != null && ps.getProjectExpectedStudyInfo().getYear() >= this.getCurrentCycleYear()) .collect(Collectors.toList()); + + // 2024/07/06 cgamboa add shared expetec studies + if (this.getActualPhase().getUpkeep()) { + List expectedStudyProject = this.expectedStudyProjectManager + .getByProjectAndPhase(project.getId(), this.getActualPhase().getId()) != null + ? this.expectedStudyProjectManager + .getByProjectAndPhase(project.getId(), this.getActualPhase().getId()).stream() + .filter(px -> px.isActive() && px.getProjectExpectedStudy().isActive() + && px.getProjectExpectedStudy().getProjectExpectedStudyInfo(this.getActualPhase()) != null) + .collect(Collectors.toList()) + : Collections.emptyList(); + if (expectedStudyProject != null && !expectedStudyProject.isEmpty()) { + for (ExpectedStudyProject expectedStudy : expectedStudyProject) { + if (!allProjectStudies.contains(expectedStudy.getProjectExpectedStudy())) { + projectStudies.add(expectedStudy.getProjectExpectedStudy()); + } + } + } + } + + } for (ProjectExpectedStudy projectExpectedStudy : projectStudies) { sectionStatus = sectionStatusManager.getSectionStatusByProjectExpectedStudy(projectExpectedStudy.getId(), cycle, this.getActualPhase().getYear(), this.getActualPhase().getUpkeep(), sectionName); + if (sectionStatus == null) { sectionStatus = new SectionStatus(); sectionStatus.setMissingFields("No section"); } + + if (sectionStatus.getMissingFields().length() > 0) { section.put("missingFields", section.get("missingFields") + "-" + sectionStatus.getMissingFields()); } diff --git a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/validation/projects/DeliverableValidator.java b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/validation/projects/DeliverableValidator.java index e731beb863..3eb86c5eb4 100644 --- a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/validation/projects/DeliverableValidator.java +++ b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/validation/projects/DeliverableValidator.java @@ -18,6 +18,7 @@ import org.cgiar.ccafs.marlo.action.BaseAction; import org.cgiar.ccafs.marlo.config.APConstants; +import org.cgiar.ccafs.marlo.data.manager.ActivityManager; import org.cgiar.ccafs.marlo.data.manager.CgiarCrossCuttingMarkerManager; import org.cgiar.ccafs.marlo.data.manager.CrpProgramOutcomeManager; import org.cgiar.ccafs.marlo.data.manager.DeliverableUserManager; @@ -25,6 +26,7 @@ import org.cgiar.ccafs.marlo.data.manager.ProjectManager; import org.cgiar.ccafs.marlo.data.manager.ProjectPartnerPersonManager; import org.cgiar.ccafs.marlo.data.manager.RepIndTypeActivityManager; +import org.cgiar.ccafs.marlo.data.manager.SectionStatusManager; import org.cgiar.ccafs.marlo.data.manager.SoilIndicatorManager; import org.cgiar.ccafs.marlo.data.model.CgiarCrossCuttingMarker; import org.cgiar.ccafs.marlo.data.model.CrpProgramOutcome; @@ -79,6 +81,8 @@ public class DeliverableValidator extends BaseValidator { private RepIndTypeActivityManager repIndTypeActivityManager; private SoilIndicatorManager soilIndicatorManager; private CrpProgramOutcomeManager crpProgramOutcomeManager; + private ActivityManager activityManager; + private SectionStatusManager sectionStatusManager; Boolean doesNotHaveDOI; @@ -87,7 +91,8 @@ public DeliverableValidator(GlobalUnitManager crpManager, ProjectManager project ProjectPartnerPersonManager projectPartnerPersonManager, CgiarCrossCuttingMarkerManager cgiarCrossCuttingMarkerManager, RepIndTypeActivityManager repIndTypeActivityManager, DeliverableUserManager deliverableUserManager, SoilIndicatorManager soilIndicatorManager, - CrpProgramOutcomeManager crpProgramOutcomeManager) { + CrpProgramOutcomeManager crpProgramOutcomeManager, ActivityManager activityManager, + SectionStatusManager sectionStatusManager) { this.crpManager = crpManager; this.projectManager = projectManager; this.projectPartnerPersonManager = projectPartnerPersonManager; @@ -96,6 +101,8 @@ public DeliverableValidator(GlobalUnitManager crpManager, ProjectManager project this.repIndTypeActivityManager = repIndTypeActivityManager; this.soilIndicatorManager = soilIndicatorManager; this.crpProgramOutcomeManager = crpProgramOutcomeManager; + this.activityManager = activityManager; + this.sectionStatusManager = sectionStatusManager; } private Path getAutoSaveFilePath(Deliverable deliverable, long crpID, BaseAction action) { @@ -109,6 +116,9 @@ private Path getAutoSaveFilePath(Deliverable deliverable, long crpID, BaseAction } public void validate(BaseAction action, Deliverable deliverable, boolean saving) { + + boolean resultProgessValidate = this.validateIsProgressAndNotCompleteStatus(action, deliverable); + action.setInvalidFields(new HashMap<>()); boolean validate = false; @@ -118,29 +128,31 @@ public void validate(BaseAction action, Deliverable deliverable, boolean saving) for (DeliverableMetadataElement deliverableMetadataElement : deliverable.getMetadataElements()) { if (deliverableMetadataElement != null) { if (deliverableMetadataElement.getMetadataElement().getId() != null) { - - // Validate metadata title - if (deliverableMetadataElement.getMetadataElement().getId() != null - && 1 == deliverableMetadataElement.getMetadataElement().getId()) { - if ((deliverableMetadataElement.getElementValue() != null - && deliverableMetadataElement.getElementValue().isEmpty()) - || deliverableMetadataElement.getElementValue() == null) { - action.addMessage(action.getText("project.deliverable.metadata.v.title")); - action.getInvalidFields().put("input-deliverable.metadataElements[0].elementValue", - InvalidFieldsMessages.EMPTYFIELD); + if (!resultProgessValidate) { + // Validate metadata title + if (deliverableMetadataElement.getMetadataElement().getId() != null + && 1 == deliverableMetadataElement.getMetadataElement().getId()) { + if ((deliverableMetadataElement.getElementValue() != null + && deliverableMetadataElement.getElementValue().isEmpty()) + || deliverableMetadataElement.getElementValue() == null) { + action.addMessage(action.getText("project.deliverable.metadata.v.title")); + action.getInvalidFields().put("input-deliverable.metadataElements[0].elementValue", + InvalidFieldsMessages.EMPTYFIELD); + } } - } - // Validate metadata publication date - if (deliverableMetadataElement.getMetadataElement().getId() != null - && 17 == deliverableMetadataElement.getMetadataElement().getId()) { - if ((deliverableMetadataElement.getElementValue() != null - && deliverableMetadataElement.getElementValue().isEmpty()) - || deliverableMetadataElement.getElementValue() == null) { - action.addMessage(action.getText("project.deliverable.metadata.v.publicationDate")); - action.getInvalidFields().put("input-deliverable.metadataElements[16].elementValue", - InvalidFieldsMessages.EMPTYFIELD); + // Validate metadata publication date + if (deliverableMetadataElement.getMetadataElement().getId() != null + && 17 == deliverableMetadataElement.getMetadataElement().getId()) { + if ((deliverableMetadataElement.getElementValue() != null + && deliverableMetadataElement.getElementValue().isEmpty()) + || deliverableMetadataElement.getElementValue() == null) { + action.addMessage(action.getText("project.deliverable.metadata.v.publicationDate")); + action.getInvalidFields().put("input-deliverable.metadataElements[16].elementValue", + InvalidFieldsMessages.EMPTYFIELD); + } } + } } } @@ -221,7 +233,8 @@ public void validate(BaseAction action, Deliverable deliverable, boolean saving) && deliverable.getDeliverableInfo(action.getActualPhase()).getStatus().intValue() == Integer .parseInt(ProjectStatusEnum.Cancelled.getStatusId()))) { - this.validateDeliverableInfo(deliverable.getDeliverableInfo(), deliverable, project, action); + this.validateDeliverableInfo(deliverable.getDeliverableInfo(), deliverable, project, action, + resultProgessValidate); Boolean isManagingPartnerPersonRequerid = action.hasSpecificities(APConstants.CRP_MANAGING_PARTNERS_CONTACT_PERSONS); @@ -350,10 +363,13 @@ public void validate(BaseAction action, Deliverable deliverable, boolean saving) InvalidFieldsMessages.EMPTYFIELD); } + if (deliverable.getActivities() == null || deliverable.getActivities().isEmpty()) { action.addMessage(action.getText("project.deliverable.activity")); action.getInvalidFields().put("list-deliverable.activities", action.getText(InvalidFieldsMessages.EMPTYLIST, new String[] {"activities"})); + + } } @@ -472,7 +488,7 @@ public void validate(BaseAction action, Deliverable deliverable, boolean saving) */ if (!action.isPOWB()) { if (deliverable.getDeliverableParticipant() != null && deliverable.getDeliverableParticipant() != null) { - this.validateDeliverableParticipant(deliverable.getDeliverableParticipant(), action); + this.validateDeliverableParticipant(deliverable.getDeliverableParticipant(), action, resultProgessValidate); } else { action.addMessage("hasParticipants"); action.getInvalidFields().put("input-deliverable.deliverableParticipant.hasParticipants", @@ -645,13 +661,29 @@ public void validate(BaseAction action, Deliverable deliverable, boolean saving) } } + // 2024/06/07 cgamboa functionality to validate activities, from the general check + try { + if (resultProgessValidate && !saving) { + int activitiesByDeliverableAndPhaseQuantity = activityManager + .getActivitiesByDeliverableAndPhaseQuantity(deliverable.getId(), action.getActualPhase().getId()); + if (activitiesByDeliverableAndPhaseQuantity == 0 + && !action.getMissingFields().toString().contains("project.deliverable.activity")) { + action.addMissingField("project.deliverable.activity"); + } + } + } catch (Exception e) { + LOG.error(" unable to getActivitiesByDeliverableAndPhaseQuantity in validate function [DeliverableValidator]"); + } + this.saveMissingFields(deliverable, action.getActualPhase().getDescription(), action.getActualPhase().getYear(), action.getActualPhase().getUpkeep(), ProjectSectionStatusEnum.DELIVERABLES.getStatus(), action); + + } private void validateDeliverableInfo(DeliverableInfo deliverableInfo, Deliverable deliverable, Project project, - BaseAction action) { + BaseAction action, boolean resultProgessValidate) { if (!(this.isValidString(deliverable.getDeliverableInfo(action.getActualPhase()).getTitle()) && this.wordCount(deliverable.getDeliverableInfo(action.getActualPhase()).getTitle()) <= 25)) { action.addMessage(action.getText("project.deliverable.generalInformation.title")); @@ -677,17 +709,39 @@ private void validateDeliverableInfo(DeliverableInfo deliverableInfo, Deliverabl action.getInvalidFields().put("input-deliverable.deliverableInfo.deliverableType.deliverableCategory.id", InvalidFieldsMessages.EMPTYFIELD); deliverable.getDeliverableInfo(action.getActualPhase()).setDeliverableType(null); + + // [start] cgamboa 12/06/2024 conditional is added to mark the category and the subcategory, in red + if (deliverable.getDeliverableInfo(action.getActualPhase()).getDeliverableType() == null) { + action.addMessage(action.getText("project.deliverable.generalInformation.subType")); + action.getInvalidFields().put("input-deliverable.deliverableInfo.deliverableType.id", + InvalidFieldsMessages.EMPTYFIELD); + } + // [end] } if (deliverable.getDeliverableInfo(action.getActualPhase()) != null && deliverable.getDeliverableInfo(action.getActualPhase()).getDeliverableType() != null && deliverable.getDeliverableInfo(action.getActualPhase()).getDeliverableType().getId() != null && deliverable.getDeliverableInfo(action.getActualPhase()).getDeliverableType().getId() == -1) { + + // [start] cgamboa 12/06/2024 conditional is added to mark the category and the subcategory, in red + action.addMessage(action.getText("project.deliverable.generalInformation.category")); + action.getInvalidFields().put("input-deliverable.deliverableInfo.deliverableType.deliverableCategory.id", + InvalidFieldsMessages.EMPTYFIELD); + // [end] + action.addMessage(action.getText("project.deliverable.generalInformation.subType")); action.getInvalidFields().put("input-deliverable.deliverableInfo.deliverableType.id", InvalidFieldsMessages.EMPTYFIELD); deliverable.getDeliverableInfo(action.getActualPhase()).setDeliverableType(null); + // [start] cgamboa 12/06/2024 conditional is added to mark the category and the subcategory, in red + action.addMessage(action.getText("project.deliverable.generalInformation.type")); + action.getInvalidFields().put("input-deliverable.deliverableInfo.deliverableType.deliverableType.id", + InvalidFieldsMessages.EMPTYFIELD); + // [end] + + } else { if (deliverable.getDeliverableInfo(action.getActualPhase()).getDeliverableType() != null && deliverable .getDeliverableInfo(action.getActualPhase()).getDeliverableType().getDeliverableCategory() != null) { @@ -700,6 +754,7 @@ private void validateDeliverableInfo(DeliverableInfo deliverableInfo, Deliverabl } } else { + action.addMessage(action.getText("project.deliverable.generalInformation.type")); action.getInvalidFields().put("input-deliverable.deliverableInfo.deliverableType.deliverableType.id", InvalidFieldsMessages.EMPTYFIELD); @@ -942,87 +997,93 @@ private void validateDeliverableInfo(DeliverableInfo deliverableInfo, Deliverabl } - private void validateDeliverableParticipant(DeliverableParticipant deliverableParticipant, BaseAction action) { - if (deliverableParticipant.getHasParticipants() != null && deliverableParticipant.getHasParticipants()) { - if (deliverableParticipant.getEventActivityName() != null - && !this.isValidString(deliverableParticipant.getEventActivityName())) { - action.addMessage(action.getText("involveParticipants.title")); - action.getInvalidFields().put("input-deliverable.deliverableParticipant.eventActivityName", - InvalidFieldsMessages.EMPTYFIELD); - } - if (deliverableParticipant.getRepIndTypeActivity() == null - || deliverableParticipant.getRepIndTypeActivity().getId() == -1) { - action.addMessage(action.getText("involveParticipants.typeActivity")); - action.getInvalidFields().put("input-deliverable.deliverableParticipant.repIndTypeActivity.id", - InvalidFieldsMessages.EMPTYFIELD); - deliverableParticipant.setRepIndTypeActivity(null); - } else { - RepIndTypeActivity repIndTypeActivity = - repIndTypeActivityManager.getRepIndTypeActivityById(deliverableParticipant.getRepIndTypeActivity().getId()); + private void validateDeliverableParticipant(DeliverableParticipant deliverableParticipant, BaseAction action, + boolean resultProgessValidate) { - if (repIndTypeActivity.getId().equals(action.getReportingIndTypeActivityAcademicDegree())) { - if (!this.isValidString(deliverableParticipant.getAcademicDegree())) { - action.addMessage(action.getText("involveParticipants.academicDegree")); - action.getInvalidFields().put("input-deliverable.deliverableParticipant.academicDegree", - InvalidFieldsMessages.EMPTYFIELD); + if (!resultProgessValidate) { + if (deliverableParticipant.getHasParticipants() != null && deliverableParticipant.getHasParticipants()) { + if (deliverableParticipant.getEventActivityName() != null + && !this.isValidString(deliverableParticipant.getEventActivityName())) { + action.addMessage(action.getText("involveParticipants.title")); + action.getInvalidFields().put("input-deliverable.deliverableParticipant.eventActivityName", + InvalidFieldsMessages.EMPTYFIELD); + } + if (deliverableParticipant.getRepIndTypeActivity() == null + || deliverableParticipant.getRepIndTypeActivity().getId() == -1) { + action.addMessage(action.getText("involveParticipants.typeActivity")); + action.getInvalidFields().put("input-deliverable.deliverableParticipant.repIndTypeActivity.id", + InvalidFieldsMessages.EMPTYFIELD); + deliverableParticipant.setRepIndTypeActivity(null); + } else { + RepIndTypeActivity repIndTypeActivity = + repIndTypeActivityManager.getRepIndTypeActivityById(deliverableParticipant.getRepIndTypeActivity().getId()); + + if (repIndTypeActivity.getId().equals(action.getReportingIndTypeActivityAcademicDegree())) { + if (!this.isValidString(deliverableParticipant.getAcademicDegree())) { + action.addMessage(action.getText("involveParticipants.academicDegree")); + action.getInvalidFields().put("input-deliverable.deliverableParticipant.academicDegree", + InvalidFieldsMessages.EMPTYFIELD); + } + } + if (repIndTypeActivity.getIsFormal()) { + if (deliverableParticipant.getRepIndTrainingTerm() == null + || deliverableParticipant.getRepIndTrainingTerm().getId() == -1) { + action.addMessage(action.getText("involveParticipants.trainingPeriod")); + action.getInvalidFields().put("input-deliverable.deliverableParticipant.repIndTrainingTerm.id", + InvalidFieldsMessages.EMPTYFIELD); + } } } - if (repIndTypeActivity.getIsFormal()) { - if (deliverableParticipant.getRepIndTrainingTerm() == null - || deliverableParticipant.getRepIndTrainingTerm().getId() == -1) { - action.addMessage(action.getText("involveParticipants.trainingPeriod")); - action.getInvalidFields().put("input-deliverable.deliverableParticipant.repIndTrainingTerm.id", + if (deliverableParticipant.getParticipants() == null + || !this.isValidNumber(deliverableParticipant.getParticipants().toString()) + || deliverableParticipant.getParticipants() < 0) { + action.addMessage(action.getText("involveParticipants.participants")); + action.getInvalidFields().put("input-deliverable.deliverableParticipant.participants", + InvalidFieldsMessages.EMPTYFIELD); + } + if (deliverableParticipant.getDontKnowFemale() == null || !deliverableParticipant.getDontKnowFemale()) { + if (deliverableParticipant.getFemales() == null + || !this.isValidNumber(deliverableParticipant.getFemales().toString()) + || deliverableParticipant.getFemales() < 0) { + action.addMessage(action.getText("involveParticipants.females")); + action.getInvalidFields().put("input-deliverable.deliverableParticipant.females", InvalidFieldsMessages.EMPTYFIELD); } } - } - if (deliverableParticipant.getParticipants() == null - || !this.isValidNumber(deliverableParticipant.getParticipants().toString()) - || deliverableParticipant.getParticipants() < 0) { - action.addMessage(action.getText("involveParticipants.participants")); - action.getInvalidFields().put("input-deliverable.deliverableParticipant.participants", - InvalidFieldsMessages.EMPTYFIELD); - } - if (deliverableParticipant.getDontKnowFemale() == null || !deliverableParticipant.getDontKnowFemale()) { - if (deliverableParticipant.getFemales() == null - || !this.isValidNumber(deliverableParticipant.getFemales().toString()) - || deliverableParticipant.getFemales() < 0) { - action.addMessage(action.getText("involveParticipants.females")); - action.getInvalidFields().put("input-deliverable.deliverableParticipant.females", + if (deliverableParticipant.getAfrican() == null + || !this.isValidNumber(deliverableParticipant.getAfrican().toString()) + || deliverableParticipant.getAfrican().intValue() < 0) { + action.addMessage(action.getText("involveParticipants.african")); + action.getInvalidFields().put("input-deliverable.deliverableParticipant.african", + InvalidFieldsMessages.EMPTYFIELD); + } + if (deliverableParticipant.getYouth() == null + || !this.isValidNumber(deliverableParticipant.getYouth().toString()) + || deliverableParticipant.getYouth().intValue() < 0) { + action.addMessage(action.getText("involveParticipants.youth")); + action.getInvalidFields().put("input-deliverable.deliverableParticipant.youth", InvalidFieldsMessages.EMPTYFIELD); } - } - if (deliverableParticipant.getAfrican() == null - || !this.isValidNumber(deliverableParticipant.getAfrican().toString()) - || deliverableParticipant.getAfrican().intValue() < 0) { - action.addMessage(action.getText("involveParticipants.african")); - action.getInvalidFields().put("input-deliverable.deliverableParticipant.african", - InvalidFieldsMessages.EMPTYFIELD); - } - if (deliverableParticipant.getYouth() == null || !this.isValidNumber(deliverableParticipant.getYouth().toString()) - || deliverableParticipant.getYouth().intValue() < 0) { - action.addMessage(action.getText("involveParticipants.youth")); - action.getInvalidFields().put("input-deliverable.deliverableParticipant.youth", - InvalidFieldsMessages.EMPTYFIELD); - } - if (!this.isValidString(deliverableParticipant.getFocus())) { - action.addMessage(action.getText("involveParticipants.focus")); - action.getInvalidFields().put("input-deliverable.deliverableParticipant.focus", - InvalidFieldsMessages.EMPTYFIELD); - } + if (!this.isValidString(deliverableParticipant.getFocus())) { + action.addMessage(action.getText("involveParticipants.focus")); + action.getInvalidFields().put("input-deliverable.deliverableParticipant.focus", + InvalidFieldsMessages.EMPTYFIELD); + } - if (!this.isValidString(deliverableParticipant.getLikelyOutcomes())) { - action.addMessage(action.getText("involveParticipants.likelyOutcomes")); - action.getInvalidFields().put("input-deliverable.deliverableParticipant.likelyOutcomes", - InvalidFieldsMessages.EMPTYFIELD); - } + if (!this.isValidString(deliverableParticipant.getLikelyOutcomes())) { + action.addMessage(action.getText("involveParticipants.likelyOutcomes")); + action.getInvalidFields().put("input-deliverable.deliverableParticipant.likelyOutcomes", + InvalidFieldsMessages.EMPTYFIELD); + } - if (deliverableParticipant.getRepIndTypeParticipant() == null - || deliverableParticipant.getRepIndTypeParticipant().getId() == -1) { - action.addMessage(action.getText("involveParticipants.participantsType")); - action.getInvalidFields().put("input-deliverable.deliverableParticipant.repIndTypeParticipant.id", - InvalidFieldsMessages.EMPTYFIELD); + + if (deliverableParticipant.getRepIndTypeParticipant() == null + || deliverableParticipant.getRepIndTypeParticipant().getId() == -1) { + action.addMessage(action.getText("involveParticipants.participantsType")); + action.getInvalidFields().put("input-deliverable.deliverableParticipant.repIndTypeParticipant.id", + InvalidFieldsMessages.EMPTYFIELD); + } } } } @@ -1126,6 +1187,29 @@ public void validateDissemination(DeliverableDissemination dissemination, boolea } } + /** + * Validate if the current phase is progress + * + * @param action base action + * @param deliverable An specific deliverable + * @return validation result + */ + + public boolean validateIsProgressAndNotCompleteStatus(BaseAction action, Deliverable deliverable) { + boolean result = false; + try { + + if (action.isProgressActive() + && deliverable.getDeliverableInfo().getStatus() != Integer.parseInt(ProjectStatusEnum.Complete.getStatusId())) { + result = true; + } + return result; + } catch (Exception e) { + LOG.error(" error in validateIsProgressAndNotStatus function [DeliverableValidator]"); + return result; + } + } + public void validateLicense(Deliverable deliverable, BaseAction action) { /* * if (deliverable.getDeliverableInfo(action.getActualPhase()).getAdoptedLicense().booleanValue()) { diff --git a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/validation/projects/ProjectExpectedStudiesValidator.java b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/validation/projects/ProjectExpectedStudiesValidator.java index 05a3189812..1694cd058c 100644 --- a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/validation/projects/ProjectExpectedStudiesValidator.java +++ b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/validation/projects/ProjectExpectedStudiesValidator.java @@ -25,6 +25,7 @@ import org.cgiar.ccafs.marlo.data.model.ProjectExpectedStudyReference; import org.cgiar.ccafs.marlo.data.model.ProjectExpectedStudySubIdo; import org.cgiar.ccafs.marlo.data.model.ProjectSectionStatusEnum; +import org.cgiar.ccafs.marlo.data.model.ProjectStatusEnum; import org.cgiar.ccafs.marlo.utils.InvalidFieldsMessages; import org.cgiar.ccafs.marlo.utils.Patterns; import org.cgiar.ccafs.marlo.validation.BaseValidator; @@ -36,12 +37,17 @@ import javax.inject.Inject; import javax.inject.Named; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * @author Christian Garcia - CIAT/CCAFS */ @Named public class ProjectExpectedStudiesValidator extends BaseValidator { + private static final Logger LOG = LoggerFactory.getLogger(ProjectExpectedStudiesValidator.class); + private final GlobalUnitManager crpManager; private BaseAction baseAction; @@ -60,6 +66,8 @@ private Path getAutoSaveFilePath(ProjectExpectedStudy expectedStudy, long crpID, } public void validate(BaseAction action, Project project, ProjectExpectedStudy projectExpectedStudy, boolean saving) { + + action.setInvalidFields(new HashMap<>()); baseAction = action; @@ -87,9 +95,33 @@ public void validate(BaseAction action, Project project, ProjectExpectedStudy pr } + /** + * Validate if the current phase is progress + * + * @param action base action + * @param projectExpectedStudy An specific projectExpectedStudy + * @return validation result + */ + public boolean validateIsProgressAndNotCompleteStatus(BaseAction action, ProjectExpectedStudy projectExpectedStudy) { + boolean result = false; + try { + if (action.isProgressActive() && projectExpectedStudy.getProjectExpectedStudyInfo().getStatus().getId() != Integer + .parseInt(ProjectStatusEnum.Complete.getStatusId())) { + result = true; + } + return result; + } catch (Exception e) { + LOG.error(" error in validateIsProgressAndNotStatus function [ProjectExpectedStudiesValidator]"); + return result; + } + } + public void validateProjectExpectedStudy(ProjectExpectedStudy projectExpectedStudy, BaseAction action) { + boolean resultProgessValidate = false; + resultProgessValidate = this.validateIsProgressAndNotCompleteStatus(action, projectExpectedStudy); + // Validate Study type if (projectExpectedStudy.getProjectExpectedStudyInfo(baseAction.getActualPhase()).getStudyType() != null) { if (projectExpectedStudy.getProjectExpectedStudyInfo(baseAction.getActualPhase()).getStudyType().getId() == null @@ -162,17 +194,20 @@ public void validateProjectExpectedStudy(ProjectExpectedStudy projectExpectedStu } } - // validate Milestones - if (projectExpectedStudy.getProjectExpectedStudyInfo(baseAction.getActualPhase()) != null - && baseAction.getActualPhase().getName() != null - && projectExpectedStudy.getProjectExpectedStudyInfo().getStudyType() != null - && projectExpectedStudy.getProjectExpectedStudyInfo().getStudyType().getId().intValue() == 1) { + + if (!resultProgessValidate) { + // validate Milestones if (projectExpectedStudy.getProjectExpectedStudyInfo(baseAction.getActualPhase()) != null - && projectExpectedStudy.getProjectExpectedStudyInfo().getHasMilestones() == null) { - action.addMessage(action.getText("hasMilestones")); - action.addMissingField("expectedStudy.projectExpectedStudyInfo.hasMilestones"); - action.getInvalidFields().put("input-expectedStudy.projectExpectedStudyInfo.hasMilestones", - InvalidFieldsMessages.EMPTYFIELD); + && baseAction.getActualPhase().getName() != null + && projectExpectedStudy.getProjectExpectedStudyInfo().getStudyType() != null + && projectExpectedStudy.getProjectExpectedStudyInfo().getStudyType().getId().intValue() == 1) { + if (projectExpectedStudy.getProjectExpectedStudyInfo(baseAction.getActualPhase()) != null + && projectExpectedStudy.getProjectExpectedStudyInfo().getHasMilestones() == null) { + action.addMessage(action.getText("hasMilestones")); + action.addMissingField("expectedStudy.projectExpectedStudyInfo.hasMilestones"); + action.getInvalidFields().put("input-expectedStudy.projectExpectedStudyInfo.hasMilestones", + InvalidFieldsMessages.EMPTYFIELD); + } } } /* @@ -193,32 +228,36 @@ public void validateProjectExpectedStudy(ProjectExpectedStudy projectExpectedStu * } * } */ - if (projectExpectedStudy.getProjectExpectedStudyInfo(baseAction.getActualPhase()) != null - && baseAction.getActualPhase().getName() != null - && projectExpectedStudy.getProjectExpectedStudyInfo().getStudyType() != null - && projectExpectedStudy.getProjectExpectedStudyInfo().getStudyType().getId().intValue() == 1) { + if (!resultProgessValidate) { if (projectExpectedStudy.getProjectExpectedStudyInfo(baseAction.getActualPhase()) != null - && (projectExpectedStudy.getProjectExpectedStudyInfo().getHasMilestones() != null - && projectExpectedStudy.getProjectExpectedStudyInfo().getHasMilestones() == true - && (projectExpectedStudy.getCrpOutcomes() == null || projectExpectedStudy.getCrpOutcomes().isEmpty())) - || projectExpectedStudy.getProjectExpectedStudyInfo().getHasMilestones() == null) { - - action.addMessage(action.getText("expectedStudy.crpOutcomes")); - action.addMissingField("expectedStudy.crpOutcomes"); - action.getInvalidFields().put("list-expectedStudy.crpOutcomes", - action.getText(InvalidFieldsMessages.EMPTYLIST, new String[] {"expectedStudy.crpOutcomes"})); + && baseAction.getActualPhase().getName() != null + && projectExpectedStudy.getProjectExpectedStudyInfo().getStudyType() != null + && projectExpectedStudy.getProjectExpectedStudyInfo().getStudyType().getId().intValue() == 1) { + if (projectExpectedStudy.getProjectExpectedStudyInfo(baseAction.getActualPhase()) != null + && (projectExpectedStudy.getProjectExpectedStudyInfo().getHasMilestones() != null + && projectExpectedStudy.getProjectExpectedStudyInfo().getHasMilestones() == true + && (projectExpectedStudy.getCrpOutcomes() == null || projectExpectedStudy.getCrpOutcomes().isEmpty())) + || projectExpectedStudy.getProjectExpectedStudyInfo().getHasMilestones() == null) { + + action.addMessage(action.getText("expectedStudy.crpOutcomes")); + action.addMissingField("expectedStudy.crpOutcomes"); + action.getInvalidFields().put("list-expectedStudy.crpOutcomes", + action.getText(InvalidFieldsMessages.EMPTYLIST, new String[] {"expectedStudy.crpOutcomes"})); + } } } - // Validate Centers - if (projectExpectedStudy.getProjectExpectedStudyInfo() != null - && projectExpectedStudy.getProjectExpectedStudyInfo().getStudyType() != null - && projectExpectedStudy.getProjectExpectedStudyInfo().getStudyType().getId() == 1 - && (projectExpectedStudy.getCenters() == null || projectExpectedStudy.getCenters().isEmpty())) { - action.addMessage(action.getText("expectedStudy.contributingCenters")); - action.addMissingField("expectedStudy.centers"); - action.getInvalidFields().put("list-expectedStudy.centers", - action.getText(InvalidFieldsMessages.EMPTYLIST, new String[] {"centers"})); + if (!resultProgessValidate) { + // Validate Centers + if (projectExpectedStudy.getProjectExpectedStudyInfo() != null + && projectExpectedStudy.getProjectExpectedStudyInfo().getStudyType() != null + && projectExpectedStudy.getProjectExpectedStudyInfo().getStudyType().getId() == 1 + && (projectExpectedStudy.getCenters() == null || projectExpectedStudy.getCenters().isEmpty())) { + action.addMessage(action.getText("expectedStudy.contributingCenters")); + action.addMissingField("expectedStudy.centers"); + action.getInvalidFields().put("list-expectedStudy.centers", + action.getText(InvalidFieldsMessages.EMPTYLIST, new String[] {"centers"})); + } } @@ -226,20 +265,23 @@ public void validateProjectExpectedStudy(ProjectExpectedStudy projectExpectedStu boolean haveRegions = false; boolean haveCountries = false; - if (projectExpectedStudy.getGeographicScopes() == null || projectExpectedStudy.getGeographicScopes().isEmpty()) { - action.addMessage(action.getText("geographicScopes")); - action.addMissingField("policy.geographicScope"); - action.getInvalidFields().put("list-expectedStudy.geographicScopes", - action.getText(InvalidFieldsMessages.EMPTYLIST, new String[] {"geographicScopes"})); - } else { - for (ProjectExpectedStudyGeographicScope projectPolicyGeographicScope : projectExpectedStudy - .getGeographicScopes()) { - if (projectPolicyGeographicScope.getRepIndGeographicScope().getId() == 2) { - haveRegions = true; - } - if (projectPolicyGeographicScope.getRepIndGeographicScope().getId() != 1 - && projectPolicyGeographicScope.getRepIndGeographicScope().getId() != 2) { - haveCountries = true; + if (!resultProgessValidate) { + if (projectExpectedStudy.getGeographicScopes() == null + || projectExpectedStudy.getGeographicScopes().isEmpty()) { + action.addMessage(action.getText("geographicScopes")); + action.addMissingField("policy.geographicScope"); + action.getInvalidFields().put("list-expectedStudy.geographicScopes", + action.getText(InvalidFieldsMessages.EMPTYLIST, new String[] {"geographicScopes"})); + } else { + for (ProjectExpectedStudyGeographicScope projectPolicyGeographicScope : projectExpectedStudy + .getGeographicScopes()) { + if (projectPolicyGeographicScope.getRepIndGeographicScope().getId() == 2) { + haveRegions = true; + } + if (projectPolicyGeographicScope.getRepIndGeographicScope().getId() != 1 + && projectPolicyGeographicScope.getRepIndGeographicScope().getId() != 2) { + haveCountries = true; + } } } } @@ -346,12 +388,14 @@ public void validateProjectExpectedStudy(ProjectExpectedStudy projectExpectedStu */ // Validate CGIAR Innovation - if (!this.isValidString( - projectExpectedStudy.getProjectExpectedStudyInfo(baseAction.getActualPhase()).getCgiarInnovation())) { - action.addMessage(action.getText("CGIAR innovation")); - action.addMissingField("study.cgiarInnovation"); - action.getInvalidFields().put("input-expectedStudy.projectExpectedStudyInfo.cgiarInnovation", - InvalidFieldsMessages.EMPTYFIELD); + if (!resultProgessValidate) { + if (!this.isValidString( + projectExpectedStudy.getProjectExpectedStudyInfo(baseAction.getActualPhase()).getCgiarInnovation())) { + action.addMessage(action.getText("CGIAR innovation")); + action.addMissingField("study.cgiarInnovation"); + action.getInvalidFields().put("input-expectedStudy.projectExpectedStudyInfo.cgiarInnovation", + InvalidFieldsMessages.EMPTYFIELD); + } } // Validate Is Contribution Radio Button (Yes/No) @@ -380,54 +424,62 @@ public void validateProjectExpectedStudy(ProjectExpectedStudy projectExpectedStu } } - // Validate Stage Study - if (projectExpectedStudy.getProjectExpectedStudyInfo(baseAction.getActualPhase()) - .getRepIndStageStudy() != null) { - if (projectExpectedStudy.getProjectExpectedStudyInfo(baseAction.getActualPhase()).getRepIndStageStudy() - .getId() == null - || projectExpectedStudy.getProjectExpectedStudyInfo(baseAction.getActualPhase()).getRepIndStageStudy() - .getId() == -1) { + if (!resultProgessValidate) { + // Validate Stage Study + if (projectExpectedStudy.getProjectExpectedStudyInfo(baseAction.getActualPhase()) + .getRepIndStageStudy() != null) { + if (projectExpectedStudy.getProjectExpectedStudyInfo(baseAction.getActualPhase()).getRepIndStageStudy() + .getId() == null + || projectExpectedStudy.getProjectExpectedStudyInfo(baseAction.getActualPhase()).getRepIndStageStudy() + .getId() == -1) { + action.addMessage(action.getText("Stage Study")); + action.addMissingField("study.reportingIndicatorThree.stage"); + action.getInvalidFields().put("input-expectedStudy.projectExpectedStudyInfo.repIndStageStudy.id", + InvalidFieldsMessages.EMPTYFIELD); + } + } else { action.addMessage(action.getText("Stage Study")); action.addMissingField("study.reportingIndicatorThree.stage"); action.getInvalidFields().put("input-expectedStudy.projectExpectedStudyInfo.repIndStageStudy.id", InvalidFieldsMessages.EMPTYFIELD); } - } else { - action.addMessage(action.getText("Stage Study")); - action.addMissingField("study.reportingIndicatorThree.stage"); - action.getInvalidFields().put("input-expectedStudy.projectExpectedStudyInfo.repIndStageStudy.id", - InvalidFieldsMessages.EMPTYFIELD); } - // Validate Srf Targets Selection - if (projectExpectedStudy.getProjectExpectedStudyInfo(baseAction.getActualPhase()).getIsSrfTarget() == null) { - action.addMessage(action.getText("targets")); - action.addMissingField("expectedStudy.projectExpectedStudyInfo.isSrfTarget"); - action.getInvalidFields().put("input-expectedStudy.projectExpectedStudyInfo.isSrfTarget", - InvalidFieldsMessages.EMPTYFIELD); - } else { - if (projectExpectedStudy.getProjectExpectedStudyInfo(baseAction.getActualPhase()).getIsSrfTarget() - .equals("targetsOptionYes")) { - // Validate Srf Targets - if (projectExpectedStudy.getSrfTargets() == null || projectExpectedStudy.getSrfTargets().isEmpty()) { - action.addMessage(action.getText("targets")); - action.addMissingField("study.stratgicResultsLink.srfTargets"); - action.getInvalidFields().put("list-expectedStudy.srfTargets", - action.getText(InvalidFieldsMessages.EMPTYLIST, new String[] {"targets"})); + if (!resultProgessValidate) { + + // Validate Srf Targets Selection + if (projectExpectedStudy.getProjectExpectedStudyInfo(baseAction.getActualPhase()) + .getIsSrfTarget() == null) { + action.addMessage(action.getText("targets")); + action.addMissingField("expectedStudy.projectExpectedStudyInfo.isSrfTarget"); + action.getInvalidFields().put("input-expectedStudy.projectExpectedStudyInfo.isSrfTarget", + InvalidFieldsMessages.EMPTYFIELD); + } else { + if (projectExpectedStudy.getProjectExpectedStudyInfo(baseAction.getActualPhase()).getIsSrfTarget() + .equals("targetsOptionYes")) { + // Validate Srf Targets + if (projectExpectedStudy.getSrfTargets() == null || projectExpectedStudy.getSrfTargets().isEmpty()) { + action.addMessage(action.getText("targets")); + action.addMissingField("study.stratgicResultsLink.srfTargets"); + action.getInvalidFields().put("list-expectedStudy.srfTargets", + action.getText(InvalidFieldsMessages.EMPTYLIST, new String[] {"targets"})); + } } } } - // Validate Elaboration Outcomes - if ((!this.isValidString(projectExpectedStudy.getProjectExpectedStudyInfo(baseAction.getActualPhase()) - .getElaborationOutcomeImpactStatement())) - || this.wordCount(projectExpectedStudy.getProjectExpectedStudyInfo(baseAction.getActualPhase()) - .getElaborationOutcomeImpactStatement()) > 400) { - action.addMessage(action.getText("Elaboration Outcome")); - action.addMissingField("study.elaborationStatement"); - action.getInvalidFields().put( - "input-expectedStudy.projectExpectedStudyInfo.elaborationOutcomeImpactStatement", - InvalidFieldsMessages.EMPTYFIELD); + if (!resultProgessValidate) { + // Validate Elaboration Outcomes + if ((!this.isValidString(projectExpectedStudy.getProjectExpectedStudyInfo(baseAction.getActualPhase()) + .getElaborationOutcomeImpactStatement())) + || this.wordCount(projectExpectedStudy.getProjectExpectedStudyInfo(baseAction.getActualPhase()) + .getElaborationOutcomeImpactStatement()) > 400) { + action.addMessage(action.getText("Elaboration Outcome")); + action.addMissingField("study.elaborationStatement"); + action.getInvalidFields().put( + "input-expectedStudy.projectExpectedStudyInfo.elaborationOutcomeImpactStatement", + InvalidFieldsMessages.EMPTYFIELD); + } } // Validate References Cited @@ -540,13 +592,15 @@ public void validateProjectExpectedStudy(ProjectExpectedStudy projectExpectedStu } } - // Validate Contacts - if (!this.isValidString( - projectExpectedStudy.getProjectExpectedStudyInfo(baseAction.getActualPhase()).getContacts())) { - action.addMessage(action.getText("Contacts")); - action.addMissingField("study.contacts"); - action.getInvalidFields().put("input-expectedStudy.projectExpectedStudyInfo.contacts", - InvalidFieldsMessages.EMPTYFIELD); + if (!resultProgessValidate) { + // Validate Contacts + if (!this.isValidString( + projectExpectedStudy.getProjectExpectedStudyInfo(baseAction.getActualPhase()).getContacts())) { + action.addMessage(action.getText("Contacts")); + action.addMissingField("study.contacts"); + action.getInvalidFields().put("input-expectedStudy.projectExpectedStudyInfo.contacts", + InvalidFieldsMessages.EMPTYFIELD); + } } diff --git a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/validation/projects/ProjectInnovationValidator.java b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/validation/projects/ProjectInnovationValidator.java index 49fd96fd29..6f7c982977 100644 --- a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/validation/projects/ProjectInnovationValidator.java +++ b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/validation/projects/ProjectInnovationValidator.java @@ -33,12 +33,17 @@ import javax.inject.Inject; import javax.inject.Named; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * @author Hermes Jiménez - CIAT/CCAFS */ @Named public class ProjectInnovationValidator extends BaseValidator { + private static final Logger LOG = LoggerFactory.getLogger(ProjectInnovationValidator.class); + private final GlobalUnitManager crpManager; private BaseAction baseAction; // private Boolean clearLead; @@ -58,8 +63,12 @@ private Path getAutoSaveFilePath(ProjectInnovation innovation, long crpID, BaseA return Paths.get(config.getAutoSaveFolder() + autoSaveFile); } + public void validate(BaseAction action, Project project, ProjectInnovation projectInnovation, Boolean clearLead, boolean saving, boolean struts, int year, boolean upkeep) { + + boolean resultProgessValidate = false; + resultProgessValidate = this.validateIsProgress(action); if (!action.isAWPBActive()) { // The validator is called by Struts @@ -116,45 +125,49 @@ public void validate(BaseAction action, Project project, ProjectInnovation proje * } */ // validate crp outcomes - if (projectInnovation.getProjectInnovationInfo(baseAction.getActualPhase()) != null - && (projectInnovation.getProjectInnovationInfo().getHasMilestones() != null - && projectInnovation.getProjectInnovationInfo().getHasMilestones() == true - && (projectInnovation.getCrpOutcomes() == null || projectInnovation.getCrpOutcomes().isEmpty())) - || projectInnovation.getProjectInnovationInfo().getHasMilestones() == null) { - action.addMessage(action.getText("crpOutcomes")); - action.addMissingField("innovation.crpOutcomes"); - action.getInvalidFields().put("list-innovation.crpOutcomes", - action.getText(InvalidFieldsMessages.EMPTYLIST, new String[] {"crpOutcomes"})); + if (!resultProgessValidate) { + if (projectInnovation.getProjectInnovationInfo(baseAction.getActualPhase()) != null + && (projectInnovation.getProjectInnovationInfo().getHasMilestones() != null + && projectInnovation.getProjectInnovationInfo().getHasMilestones() == true + && (projectInnovation.getCrpOutcomes() == null || projectInnovation.getCrpOutcomes().isEmpty())) + || projectInnovation.getProjectInnovationInfo().getHasMilestones() == null) { + action.addMessage(action.getText("crpOutcomes")); + action.addMissingField("innovation.crpOutcomes"); + action.getInvalidFields().put("list-innovation.crpOutcomes", + action.getText(InvalidFieldsMessages.EMPTYLIST, new String[] {"crpOutcomes"})); + } } - if (projectInnovation.getProjectInnovationInfo(baseAction.getActualPhase()) != null - && (projectInnovation.getProjectInnovationInfo().getHasMilestones() == null)) { - action.addMessage(action.getText("projectOutcomes")); - action.addMissingField("innovation.projectOutcomes"); - action.getInvalidFields().put("list-innovation.projectOutcomes", - action.getText(InvalidFieldsMessages.EMPTYLIST, new String[] {"projectOutcomes"})); - } else { + if (!resultProgessValidate) { + if (projectInnovation.getProjectInnovationInfo(baseAction.getActualPhase()) != null + && (projectInnovation.getProjectInnovationInfo().getHasMilestones() == null)) { + action.addMessage(action.getText("projectOutcomes")); + action.addMissingField("innovation.projectOutcomes"); + action.getInvalidFields().put("list-innovation.projectOutcomes", + action.getText(InvalidFieldsMessages.EMPTYLIST, new String[] {"projectOutcomes"})); + } else { - // Validate primary milestones - /* - * if (projectInnovation.getMilestones() != null - * && (projectInnovation.getProjectInnovationInfo().getHasMilestones() != null - * && projectInnovation.getProjectInnovationInfo().getHasMilestones() == true - * && !projectInnovation.getMilestones().isEmpty())) { - * int count = 0; - * for (ProjectInnovationMilestone innovationMilestone : projectInnovation.getMilestones()) { - * if (innovationMilestone.getPrimary() != null && innovationMilestone.getPrimary()) { - * count++; - * } - * } - * if (count == 0) { - * action.addMessage(action.getText("milestones")); - * action.addMissingField("innovation.milestones"); - * action.getInvalidFields().put("list-innovation.milestones", - * action.getText(InvalidFieldsMessages.EMPTYLIST, new String[] {"milestones"})); - * } - * } - */ + // Validate primary milestones + /* + * if (projectInnovation.getMilestones() != null + * && (projectInnovation.getProjectInnovationInfo().getHasMilestones() != null + * && projectInnovation.getProjectInnovationInfo().getHasMilestones() == true + * && !projectInnovation.getMilestones().isEmpty())) { + * int count = 0; + * for (ProjectInnovationMilestone innovationMilestone : projectInnovation.getMilestones()) { + * if (innovationMilestone.getPrimary() != null && innovationMilestone.getPrimary()) { + * count++; + * } + * } + * if (count == 0) { + * action.addMessage(action.getText("milestones")); + * action.addMissingField("innovation.milestones"); + * action.getInvalidFields().put("list-innovation.milestones", + * action.getText(InvalidFieldsMessages.EMPTYLIST, new String[] {"milestones"})); + * } + * } + */ + } } // Validate SubIdos @@ -181,66 +194,71 @@ public void validate(BaseAction action, Project project, ProjectInnovation proje } } - // Validate Stage of Innovation - if (projectInnovation.getProjectInnovationInfo(baseAction.getActualPhase()).getRepIndStageInnovation() != null) { - if (projectInnovation.getProjectInnovationInfo(baseAction.getActualPhase()).getRepIndStageInnovation() - .getId() == null - || projectInnovation.getProjectInnovationInfo(baseAction.getActualPhase()).getRepIndStageInnovation() - .getId() == -1) { - if (struts) { - action.addMessage(action.getText("projectInnovations.stage")); - action.addMissingField("projectInnovations.stage"); - action.getInvalidFields().put("input-innovation.projectInnovationInfo.repIndStageInnovation.id", - InvalidFieldsMessages.EMPTYFIELD); - } - } else { - // Validate if Stage is = 4 and review if the innovation has an Organization Types and Outcome Case Study + if (!resultProgessValidate) { + // Validate Stage of Innovation + if (projectInnovation.getProjectInnovationInfo(baseAction.getActualPhase()) + .getRepIndStageInnovation() != null) { if (projectInnovation.getProjectInnovationInfo(baseAction.getActualPhase()).getRepIndStageInnovation() - .getId() == 4) { - // Validate Organization Types - if (projectInnovation.getOrganizations() == null || projectInnovation.getOrganizations().isEmpty()) { + .getId() == null + || projectInnovation.getProjectInnovationInfo(baseAction.getActualPhase()).getRepIndStageInnovation() + .getId() == -1) { + if (!resultProgessValidate) { if (struts) { - action.addMessage(action.getText("projectInnovations.nextUserOrganizationalType")); - action.addMissingField("projectInnovations.nextUserOrganizationalType"); - action.getInvalidFields().put("list-innovation.organizations", - action.getText(InvalidFieldsMessages.EMPTYLIST, new String[] {"Organization Types"})); + action.addMessage(action.getText("projectInnovations.stage")); + action.addMissingField("projectInnovations.stage"); + action.getInvalidFields().put("input-innovation.projectInnovationInfo.repIndStageInnovation.id", + InvalidFieldsMessages.EMPTYFIELD); } } + } else { + // Validate if Stage is = 4 and review if the innovation has an Organization Types and Outcome Case Study + if (projectInnovation.getProjectInnovationInfo(baseAction.getActualPhase()).getRepIndStageInnovation() + .getId() == 4) { + // Validate Organization Types + if (projectInnovation.getOrganizations() == null || projectInnovation.getOrganizations().isEmpty()) { + if (struts) { + action.addMessage(action.getText("projectInnovations.nextUserOrganizationalType")); + action.addMissingField("projectInnovations.nextUserOrganizationalType"); + action.getInvalidFields().put("list-innovation.organizations", + action.getText(InvalidFieldsMessages.EMPTYLIST, new String[] {"Organization Types"})); + } + } - // Validate Outcome Case Study - if (projectInnovation.getProjectInnovationInfo(baseAction.getActualPhase()) - .getProjectExpectedStudy() != null) { - if (projectInnovation.getProjectInnovationInfo(baseAction.getActualPhase()).getProjectExpectedStudy() - .getId() == null - || projectInnovation.getProjectInnovationInfo(baseAction.getActualPhase()).getProjectExpectedStudy() - .getId() == -1) { + // Validate Outcome Case Study + if (projectInnovation.getProjectInnovationInfo(baseAction.getActualPhase()) + .getProjectExpectedStudy() != null) { + if (projectInnovation.getProjectInnovationInfo(baseAction.getActualPhase()).getProjectExpectedStudy() + .getId() == null + || projectInnovation.getProjectInnovationInfo(baseAction.getActualPhase()).getProjectExpectedStudy() + .getId() == -1) { + if (struts) { + action.addMessage(action.getText("projectInnovations.outcomeCaseStudy")); + action.addMissingField("projectInnovations.outcomeCaseStudy"); + action.getInvalidFields().put("input-innovation.projectInnovationInfo.projectExpectedStudy.id", + InvalidFieldsMessages.EMPTYFIELD); + } + } + } + } else { + // Validate Evidence Link (URL) + if (!this.isValidString( + projectInnovation.getProjectInnovationInfo(baseAction.getActualPhase()).getEvidenceLink())) { if (struts) { - action.addMessage(action.getText("projectInnovations.outcomeCaseStudy")); - action.addMissingField("projectInnovations.outcomeCaseStudy"); - action.getInvalidFields().put("input-innovation.projectInnovationInfo.projectExpectedStudy.id", + action.addMessage(action.getText("projectInnovations.evidenceLink")); + action.addMissingField("projectInnovations.evidenceLink"); + action.getInvalidFields().put("input-innovation.projectInnovationInfo.evidenceLink", InvalidFieldsMessages.EMPTYFIELD); } } } - } else { - // Validate Evidence Link (URL) - if (!this.isValidString( - projectInnovation.getProjectInnovationInfo(baseAction.getActualPhase()).getEvidenceLink())) { - if (struts) { - action.addMessage(action.getText("projectInnovations.evidenceLink")); - action.addMissingField("projectInnovations.evidenceLink"); - action.getInvalidFields().put("input-innovation.projectInnovationInfo.evidenceLink", - InvalidFieldsMessages.EMPTYFIELD); - } - } } - } - } else { - if (struts) { - action.addMessage(action.getText("projectInnovations.stage")); - action.addMissingField("projectInnovations.stage"); - action.getInvalidFields().put("input-innovation.projectInnovationInfo.repIndStageInnovation.id", - InvalidFieldsMessages.EMPTYFIELD); + } else { + if (struts) { + action.addMessage(action.getText("projectInnovations.stage")); + action.addMissingField("projectInnovations.stage"); + action.getInvalidFields().put("input-innovation.projectInnovationInfo.repIndStageInnovation.id", + InvalidFieldsMessages.EMPTYFIELD); + } } } @@ -250,11 +268,13 @@ public void validate(BaseAction action, Project project, ProjectInnovation proje boolean haveCountries = false; if (projectInnovation.getGeographicScopes() == null || projectInnovation.getGeographicScopes().isEmpty()) { - if (struts) { - action.addMessage(action.getText("projectInnovations.geographicScope")); - action.getInvalidFields().put("list-innovation.geographicScopes", - action.getText(InvalidFieldsMessages.EMPTYLIST, new String[] {"geographicScopes"})); - action.addMissingField("projectInnovations.geographicScope"); + if (!resultProgessValidate) { + if (struts) { + action.addMessage(action.getText("projectInnovations.geographicScope")); + action.getInvalidFields().put("list-innovation.geographicScopes", + action.getText(InvalidFieldsMessages.EMPTYLIST, new String[] {"geographicScopes"})); + action.addMissingField("projectInnovations.geographicScope"); + } } } else { @@ -295,12 +315,21 @@ public void validate(BaseAction action, Project project, ProjectInnovation proje } } - // Validate Innovation Type - if (projectInnovation.getProjectInnovationInfo(baseAction.getActualPhase()).getRepIndInnovationType() != null) { - if (projectInnovation.getProjectInnovationInfo(baseAction.getActualPhase()).getRepIndInnovationType() - .getId() == null - || projectInnovation.getProjectInnovationInfo(baseAction.getActualPhase()).getRepIndInnovationType() - .getId() == -1) { + if (!resultProgessValidate) { + // Validate Innovation Type + if (projectInnovation.getProjectInnovationInfo(baseAction.getActualPhase()).getRepIndInnovationType() != null) { + if (projectInnovation.getProjectInnovationInfo(baseAction.getActualPhase()).getRepIndInnovationType() + .getId() == null + || projectInnovation.getProjectInnovationInfo(baseAction.getActualPhase()).getRepIndInnovationType() + .getId() == -1) { + if (struts) { + action.addMessage(action.getText("projectInnovations.innovationType")); + action.addMissingField("projectInnovations.innovationType"); + action.getInvalidFields().put("input-innovation.projectInnovationInfo.repIndInnovationType.id", + InvalidFieldsMessages.EMPTYFIELD); + } + } + } else { if (struts) { action.addMessage(action.getText("projectInnovations.innovationType")); action.addMissingField("projectInnovations.innovationType"); @@ -308,13 +337,6 @@ public void validate(BaseAction action, Project project, ProjectInnovation proje InvalidFieldsMessages.EMPTYFIELD); } } - } else { - if (struts) { - action.addMessage(action.getText("projectInnovations.innovationType")); - action.addMissingField("projectInnovations.innovationType"); - action.getInvalidFields().put("input-innovation.projectInnovationInfo.repIndInnovationType.id", - InvalidFieldsMessages.EMPTYFIELD); - } } // Other Innovation Type Field @@ -336,15 +358,17 @@ public void validate(BaseAction action, Project project, ProjectInnovation proje } // Validate Description Stage - if (!(this - .isValidString(projectInnovation.getProjectInnovationInfo(baseAction.getActualPhase()).getDescriptionStage()) - && this.wordCount( - projectInnovation.getProjectInnovationInfo(action.getActualPhase()).getDescriptionStage()) <= 50)) { - if (struts) { - action.addMessage(action.getText("projectInnovations.stageDescription")); - action.addMissingField("projectInnovations.stageDescription"); - action.getInvalidFields().put("input-innovation.projectInnovationInfo.descriptionStage", - InvalidFieldsMessages.EMPTYFIELD); + if (!resultProgessValidate) { + if (!(this + .isValidString(projectInnovation.getProjectInnovationInfo(baseAction.getActualPhase()).getDescriptionStage()) + && this.wordCount( + projectInnovation.getProjectInnovationInfo(action.getActualPhase()).getDescriptionStage()) <= 50)) { + if (struts) { + action.addMessage(action.getText("projectInnovations.stageDescription")); + action.addMissingField("projectInnovations.stageDescription"); + action.getInvalidFields().put("input-innovation.projectInnovationInfo.descriptionStage", + InvalidFieldsMessages.EMPTYFIELD); + } } } @@ -354,11 +378,13 @@ public void validate(BaseAction action, Project project, ProjectInnovation proje if (projectInnovation.getProjectInnovationInfo(baseAction.getActualPhase()).getLeadOrganization() == null || projectInnovation.getProjectInnovationInfo(baseAction.getActualPhase()).getLeadOrganization() .getId() == -1) { - if (struts) { - action.addMessage(action.getText("projectInnovations.leadOrganization")); - action.addMissingField("projectInnovations.leadOrganization"); - action.getInvalidFields().put("input-innovation.projectInnovationInfo.leadOrganization.id", - InvalidFieldsMessages.EMPTYFIELD); + if (!resultProgessValidate) { + if (struts) { + action.addMessage(action.getText("projectInnovations.leadOrganization")); + action.addMissingField("projectInnovations.leadOrganization"); + action.getInvalidFields().put("input-innovation.projectInnovationInfo.leadOrganization.id", + InvalidFieldsMessages.EMPTYFIELD); + } } } } @@ -400,11 +426,13 @@ public void validate(BaseAction action, Project project, ProjectInnovation proje } // Validate Innovation Centers - if (projectInnovation.getCenters() == null || projectInnovation.getCenters().isEmpty()) { - action.addMessage(action.getText("projectInnovations.contributingCenters")); - action.addMissingField("innovation.centers"); - action.getInvalidFields().put("list-innovation.centers", - action.getText(InvalidFieldsMessages.EMPTYLIST, new String[] {"centers"})); + if (!resultProgessValidate) { + if (projectInnovation.getCenters() == null || projectInnovation.getCenters().isEmpty()) { + action.addMessage(action.getText("projectInnovations.contributingCenters")); + action.addMissingField("innovation.centers"); + action.getInvalidFields().put("list-innovation.centers", + action.getText(InvalidFieldsMessages.EMPTYLIST, new String[] {"centers"})); + } } @@ -433,6 +461,26 @@ public void validate(BaseAction action, Project project, ProjectInnovation proje } } + + /** + * Validate if the current phase is progress + * + * @param action base action + * @return validation result + */ + public boolean validateIsProgress(BaseAction action) { + boolean result = false; + try { + if (action.isProgressActive()) { + result = true; + } + return result; + } catch (Exception e) { + LOG.error(" error in validateIsProgress function [ProjectInnovationValidator]"); + return result; + } + } + /* * private void validateProjectInnovation(BaseAction action, ProjectInnovation projectInnovation, boolean struts) { * // Validate Title diff --git a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/validation/projects/ProjectSectionValidator.java b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/validation/projects/ProjectSectionValidator.java index 4c82c80f5e..6fea7107d6 100644 --- a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/validation/projects/ProjectSectionValidator.java +++ b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/validation/projects/ProjectSectionValidator.java @@ -24,6 +24,7 @@ import org.cgiar.ccafs.marlo.data.manager.DeliverableParticipantManager; import org.cgiar.ccafs.marlo.data.manager.DeliverableQualityCheckManager; import org.cgiar.ccafs.marlo.data.manager.DeliverableTypeManager; +import org.cgiar.ccafs.marlo.data.manager.ExpectedStudyProjectManager; import org.cgiar.ccafs.marlo.data.manager.FundingSourceManager; import org.cgiar.ccafs.marlo.data.manager.GlobalUnitManager; import org.cgiar.ccafs.marlo.data.manager.GlobalUnitProjectManager; @@ -59,6 +60,7 @@ import org.cgiar.ccafs.marlo.data.model.DeliverableQualityCheck; import org.cgiar.ccafs.marlo.data.model.DeliverableUserPartnership; import org.cgiar.ccafs.marlo.data.model.DeliverableUserPartnershipPerson; +import org.cgiar.ccafs.marlo.data.model.ExpectedStudyProject; import org.cgiar.ccafs.marlo.data.model.FundingSource; import org.cgiar.ccafs.marlo.data.model.FundingSourceLocation; import org.cgiar.ccafs.marlo.data.model.GlobalUnit; @@ -213,6 +215,7 @@ public class ProjectSectionValidator extends BaseValidator private final ProjectImpactsValidator projectImpactsValidator; private final Logger logger = LoggerFactory.getLogger(ProjectSectionValidator.class); + private ExpectedStudyProjectManager expectedStudyProjectManager; @Inject @@ -242,7 +245,7 @@ public ProjectSectionValidator(ProjectManager projectManager, ProjectLocationVal ProjectExpectedStudyRegionManager projectExpectedStudyRegionManager, ProjectInnovationRegionManager projectInnovationRegionManager, ProjectImpactsManager projectImpactsManager, ProjectImpactsValidator projectImpactsValidator, SafeguardValidator safeguardValidator, - FeedbackStatusValidator feedbackStatusValidator) { + FeedbackStatusValidator feedbackStatusValidator, ExpectedStudyProjectManager expectedStudyProjectManager) { this.projectManager = projectManager; this.locationValidator = locationValidator; this.projectBudgetsValidator = projectBudgetsValidator; @@ -289,6 +292,7 @@ public ProjectSectionValidator(ProjectManager projectManager, ProjectLocationVal this.safeguardValidator = safeguardValidator; this.safeguardsManager = safeguardsManager; this.feedbackStatusValidator = feedbackStatusValidator; + this.expectedStudyProjectManager = expectedStudyProjectManager; } @@ -1020,7 +1024,15 @@ public void validateProjectDeliverables(BaseAction action, Long projectID) { if (project.getDeliverables() != null) { - List infos = deliverableInfoManager.getDeliverablesInfoByProjectAndPhase(phase, project); + List infos = new ArrayList(); + + if (action.isProgressActive()) { + infos = deliverableInfoManager.getDeliverablesInfoByProjectAndPhaseWithSharedProjects(phase, project); + } else { + infos = deliverableInfoManager.getDeliverablesInfoByProjectAndPhase(phase, project); + } + + deliverables = new ArrayList<>(); if (infos != null && !infos.isEmpty()) { for (DeliverableInfo deliverableInfo : infos) { @@ -1357,6 +1369,25 @@ public void validateProjectExpectedStudies(BaseAction action, Long projectID) { && ps.getProjectExpectedStudyInfo().getStatus() != null && ps.getProjectExpectedStudyInfo().getYear() >= action.getCurrentCycleYear()) .collect(Collectors.toList()); + + // 2024/07/06 cgamboa add shared expetec studies + if (action.isProgressActive()) { + List expectedStudyProject = this.expectedStudyProjectManager + .getByProjectAndPhase(project.getId(), action.getActualPhase().getId()) != null + ? this.expectedStudyProjectManager.getByProjectAndPhase(project.getId(), action.getActualPhase().getId()) + .stream() + .filter(px -> px.isActive() && px.getProjectExpectedStudy().isActive() + && px.getProjectExpectedStudy().getProjectExpectedStudyInfo(action.getActualPhase()) != null) + .collect(Collectors.toList()) + : Collections.emptyList(); + if (expectedStudyProject != null && !expectedStudyProject.isEmpty()) { + for (ExpectedStudyProject expectedStudy : expectedStudyProject) { + if (!allProjectStudies.contains(expectedStudy.getProjectExpectedStudy())) { + projectStudies.add(expectedStudy.getProjectExpectedStudy()); + } + } + } + } } diff --git a/marlo-web/src/main/webapp/WEB-INF/crp/views/projects/projectDeliverable.ftl b/marlo-web/src/main/webapp/WEB-INF/crp/views/projects/projectDeliverable.ftl index 5d05c1b5b4..31ec30f099 100644 --- a/marlo-web/src/main/webapp/WEB-INF/crp/views/projects/projectDeliverable.ftl +++ b/marlo-web/src/main/webapp/WEB-INF/crp/views/projects/projectDeliverable.ftl @@ -246,6 +246,9 @@ [#-- Is deliverable new --] [#assign isDeliverableNew = action.isDeliverableNew(deliverable.id) /] + [#-- Is deliverable in progress phase and is not completed --] + [#assign validateIsProgressWithStatus = action.validateIsProgressWithStatus(deliverable.deliverableInfo.status)] +
[#-- Deliverable Menu --] @@ -265,6 +268,7 @@ [/#if] +
[#-- Deliverable Information --]
@@ -288,7 +292,7 @@ [#-- Metadata (included publications) --]

[@s.text name="project.deliverable.dissemination.metadataSubtitle" /]

- [@deliverableMacros.deliverableMetadataMacro /] + [@deliverableMacros.deliverableMetadataMacro validateIsProgressWithStatus=validateIsProgressWithStatus/]
[#-- Deliverable qualityCheck --] diff --git a/marlo-web/src/main/webapp/WEB-INF/crp/views/projects/projectInnovation.ftl b/marlo-web/src/main/webapp/WEB-INF/crp/views/projects/projectInnovation.ftl index 6606049eeb..1e4759086a 100644 --- a/marlo-web/src/main/webapp/WEB-INF/crp/views/projects/projectInnovation.ftl +++ b/marlo-web/src/main/webapp/WEB-INF/crp/views/projects/projectInnovation.ftl @@ -79,6 +79,7 @@ [@s.form action=actionName cssClass="pure-form" enctype="multipart/form-data" ] + [#assign isProgressActive = action.isProgressActive() /] [#-- Innovation Title --]

[@s.text name="projectInnovations" /]

@@ -109,7 +110,7 @@ [#-- Phase of research and Stage of innovation --]
- [@customForm.select name="innovation.projectInnovationInfo.repIndStageInnovation.id" label="" i18nkey="projectInnovations.stage" listName="stageInnovationList" keyFieldName="id" displayFieldName="name" required=true className="stageInnovationSelect" editable=editable/] + [@customForm.select name="innovation.projectInnovationInfo.repIndStageInnovation.id" label="" i18nkey="projectInnovations.stage" listName="stageInnovationList" keyFieldName="id" displayFieldName="name" required=!isProgressActive className="stageInnovationSelect" editable=editable/] [#assign isStageFour = (innovation.projectInnovationInfo.repIndStageInnovation.id == 4)!false]
@@ -119,7 +120,7 @@
- [@customForm.select name="innovation.projectInnovationInfo.repIndInnovationType.id" label="" i18nkey="projectInnovations.innovationType" listName="innovationTypeList" keyFieldName="id" displayFieldName="name" required=true className="innovationTypeSelect" editable=editable/] + [@customForm.select name="innovation.projectInnovationInfo.repIndInnovationType.id" label="" i18nkey="projectInnovations.innovationType" listName="innovationTypeList" keyFieldName="id" displayFieldName="name" required=!isProgressActive className="innovationTypeSelect" editable=editable/]
[#assign isGenetic = ((innovation.projectInnovationInfo.repIndInnovationType.id == 1))!false ]
@@ -137,7 +138,7 @@ [#assign isTypeSix = (innovation.projectInnovationInfo.repIndInnovationType.id == 6)!false]
- [@customForm.input name="innovation.projectInnovationInfo.otherInnovationType" type="text" i18nkey="projectInnovations.otherInnovation" helpIcon=false required=true editable=editable /] + [@customForm.input name="innovation.projectInnovationInfo.otherInnovationType" type="text" i18nkey="projectInnovations.otherInnovation" helpIcon=false required=!isProgressActive editable=editable /]
@@ -167,7 +168,7 @@
[#-- Geographic Scope --] - [@customForm.elementsListComponent name="innovation.geographicScopes" elementType="repIndGeographicScope" elementList=innovation.geographicScopes maxLimit=1 label="projectInnovations.geographicScope" listName="geographicScopeList" keyFieldName="id" displayFieldName="name" required=true /] + [@customForm.elementsListComponent name="innovation.geographicScopes" elementType="repIndGeographicScope" elementList=innovation.geographicScopes maxLimit=1 label="projectInnovations.geographicScope" listName="geographicScopeList" keyFieldName="id" displayFieldName="name" required=!isProgressActive /]
@@ -176,14 +177,14 @@
[#-- Multinational, National and Subnational scope --] - [@customForm.select name="innovation.countriesIds" label="" i18nkey="projectInnovations.countries" listName="countries" keyFieldName="isoAlpha2" displayFieldName="name" value="innovation.countriesIds" multiple=true required=true className="countriesSelect" disabled=!editable/] + [@customForm.select name="innovation.countriesIds" label="" i18nkey="projectInnovations.countries" listName="countries" keyFieldName="isoAlpha2" displayFieldName="name" value="innovation.countriesIds" multiple=true required=!isProgressActive className="countriesSelect" disabled=!editable/]
[#-- Description of Stage reached--]
- [@customForm.textArea name="innovation.projectInnovationInfo.descriptionStage" i18nkey="projectInnovations.stageDescription" help="projectInnovations.stageDescription.help" helpIcon=false placeholder="" className="limitWords-50" required=true editable=editable /] + [@customForm.textArea name="innovation.projectInnovationInfo.descriptionStage" i18nkey="projectInnovations.stageDescription" help="projectInnovations.stageDescription.help" helpIcon=false placeholder="" className="limitWords-50" required=!isProgressActive editable=editable /]
[#-- Is clear lead --] @@ -194,7 +195,7 @@
[#-- Lead Organization --]
- [@customForm.select name="innovation.projectInnovationInfo.leadOrganization.id" label="" i18nkey="projectInnovations.leadOrganization" listName="institutions" keyFieldName="id" displayFieldName="composedName" className="" editable=editable required=true /] + [@customForm.select name="innovation.projectInnovationInfo.leadOrganization.id" label="" i18nkey="projectInnovations.leadOrganization" listName="institutions" keyFieldName="id" displayFieldName="composedName" className="" editable=editable required=!isProgressActive /]
[#-- Top Five Contributing Organizations --] @@ -223,12 +224,12 @@ [#-- [@customForm.select name="innovation.projectInnovationInfo.projectExpectedStudy.id" label="" i18nkey="projectInnovations.outcomeCaseStudy" listName="expectedStudyList" keyFieldName="id" displayFieldName="composedNameAlternative" multiple=false required=true className="keyOutput" editable=editable/] --] - [@customForm.elementsListComponent name="innovation.studies" elementType="projectExpectedStudy" elementList=innovation.studies label="projectInnovations.outcomeCaseStudy" helpIcon=false listName="expectedStudyList" keyFieldName="id" displayFieldName="composedNameAlternative" required=isEvidenceRequired/] + [@customForm.elementsListComponent name="innovation.studies" elementType="projectExpectedStudy" elementList=innovation.studies label="projectInnovations.outcomeCaseStudy" helpIcon=false listName="expectedStudyList" keyFieldName="id" displayFieldName="composedNameAlternative" required=(isEvidenceRequired!false && !isProgressActive)/]
[#-- Evidence Link --]
- [@customForm.input name="innovation.projectInnovationInfo.evidenceLink" type="text" i18nkey="projectInnovations.evidenceLink" placeholder="marloRequestCreation.webSiteLink.placeholder" className="" required=true editable=editable /] + [@customForm.input name="innovation.projectInnovationInfo.evidenceLink" type="text" i18nkey="projectInnovations.evidenceLink" placeholder="marloRequestCreation.webSiteLink.placeholder" className="" required=!isProgressActive editable=editable /]
[#-- Or Deliverable ID (optional) --] @@ -238,7 +239,7 @@ [#-- Milestones Contribution --]
-