Skip to content

Commit

Permalink
Merge pull request #2548 from CCAFS/aiccra-feature-A2-614
Browse files Browse the repository at this point in the history
Aiccra feature a2 614
  • Loading branch information
Cristian45 authored Jun 19, 2024
2 parents 999115d + 2ad3c13 commit 682cb74
Show file tree
Hide file tree
Showing 18 changed files with 795 additions and 406 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ public interface ActivityDAO {
*/
public List<Activity> 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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ public interface DeliverableInfoDAO {
*/
public List<DeliverableInfo> 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<DeliverableInfo> getDeliverablesInfoByProjectAndPhaseWithSharedProjects(Phase phase, Project project);

/**
* This method gets a list of DeliverableInfo that are active by a given phase and type
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,29 @@ public List<Activity> 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<Map<String, Object>> rList = super.findCustomQuery(query.toString());
int activity = 0;

if (rList != null) {
for (Map<String, Object> map : rList) {
activity = Integer.parseInt(map.get("count").toString());
}
}

return activity;

}

@Override
public List<Activity> getActivitiesByProject(long projectId, long phaseId) {
String query = "from " + Activity.class.getName() + " where project_id=" + projectId + " and id_phase=" + phaseId
Expand All @@ -83,6 +106,7 @@ public List<Activity> getActivitiesByProject(long projectId, long phaseId) {

}


@Override
public int getActivitiesByProjectAndUserQuantity(long projectId, long phaseId, long projectPersonId) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,34 @@ public List<DeliverableInfo> getDeliverablesInfoByProjectAndPhase(Phase phase, P
return deliverableInfos;
}


@Override
public List<DeliverableInfo> 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<Map<String, Object>> rList = super.findCustomQuery(query.toString());
List<DeliverableInfo> deliverableInfos = new ArrayList<>();

if (rList != null) {
for (Map<String, Object> map : rList) {
DeliverableInfo deliverableInfo = this.find(Long.parseLong(map.get("id").toString()));
deliverableInfos.add(deliverableInfo);
}
}

return deliverableInfos;
}

@Override
public List<DeliverableInfo> getDeliverablesInfoByType(Phase phase, DeliverableType deliverableType) {
StringBuilder query = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ public interface ActivityManager {
*/
public List<Activity> 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.
*
Expand All @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,21 @@ public interface DeliverableInfoManager {
*/
public List<DeliverableInfo> 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<DeliverableInfo> getDeliverablesInfoByProjectAndPhaseWithSharedProjects(Phase phase, Project project);

/**
* This method gets a list of DeliverableInfo that are active by a given phase and type
*
* @return a list from DeliverableInfo null if no exist records
*/
public List<DeliverableInfo> getDeliverablesInfoByType(Phase phase, DeliverableType deliverableType);


public boolean isDeliverableSubcategoryIncludedWebsite(long deliverableID, Phase phase);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,23 @@ public List<Activity> findAll() {
}


@Override
public int getActivitiesByDeliverableAndPhaseQuantity(long deliverableId, long phaseId) {
return activityDAO.getActivitiesByDeliverableAndPhaseQuantity(deliverableId, phaseId);
}


@Override
public List<Activity> 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) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ public List<DeliverableInfo> getDeliverablesInfoByProjectAndPhase(Phase phase, P
return deliverableInfoDAO.getDeliverablesInfoByProjectAndPhase(phase, project);
}


@Override
public List<DeliverableInfo> getDeliverablesInfoByProjectAndPhaseWithSharedProjects(Phase phase, Project project) {
return deliverableInfoDAO.getDeliverablesInfoByProjectAndPhaseWithSharedProjects(phase, project);
}


@Override
public List<DeliverableInfo> getDeliverablesInfoByType(Phase phase, DeliverableType deliverableType) {
return deliverableInfoDAO.getDeliverablesInfoByType(phase, deliverableType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

/**
Expand Down Expand Up @@ -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(),
Expand All @@ -8857,6 +8883,7 @@ public boolean validatePolicy(long policyID) {
return true;
}


//
public boolean validURL(String URL) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -93,14 +96,14 @@ public class ValidateProjectSectionAction extends BaseAction {
private final ProjectSectionValidator<ValidateProjectSectionAction> projectSectionValidator;
private final GlobalUnitProjectManager globalUnitProjectManager;
private final DeliverableInfoManager deliverableInfoManager;

private ExpectedStudyProjectManager expectedStudyProjectManager;

@Inject
public ValidateProjectSectionAction(APConfig config, GlobalUnitManager crpManager, ProjectManager projectManager,
SectionStatusManager sectionStatusManager,
ProjectSectionValidator<ValidateProjectSectionAction> projectSectionValidator,
LocalizedTextProvider localizedTextProvider, GlobalUnitProjectManager globalUnitProjectManager,
DeliverableInfoManager deliverableInfoManager) {
DeliverableInfoManager deliverableInfoManager, ExpectedStudyProjectManager expectedStudyProjectManager) {
super(config);
this.sectionStatusManager = sectionStatusManager;
this.projectManager = projectManager;
Expand All @@ -109,6 +112,7 @@ public ValidateProjectSectionAction(APConfig config, GlobalUnitManager crpManage
this.localizedTextProvider = localizedTextProvider;
this.globalUnitProjectManager = globalUnitProjectManager;
this.deliverableInfoManager = deliverableInfoManager;
this.expectedStudyProjectManager = expectedStudyProjectManager;
}


Expand Down Expand Up @@ -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("");
}

}
}

Expand All @@ -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("");
}
}

}
Expand Down Expand Up @@ -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> 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());
}
Expand Down
Loading

0 comments on commit 682cb74

Please sign in to comment.