Skip to content

Commit

Permalink
🔧 chore(innovation): Modify query to get deliverables related to the…
Browse files Browse the repository at this point in the history
… shared clusters
  • Loading branch information
Cristian45 committed Feb 10, 2025
1 parent 22618d7 commit cbc8bb8
Show file tree
Hide file tree
Showing 6 changed files with 711 additions and 612 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* along with MARLO. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************/


package org.cgiar.ccafs.marlo.data.dao;

import org.cgiar.ccafs.marlo.data.model.DeliverableInfo;
Expand All @@ -29,20 +28,23 @@ public interface DeliverableInfoDAO {
* This method removes a specific deliverableInfo value from the database.
*
* @param deliverableInfoId is the deliverableInfo identifier.
* @return true if the deliverableInfo was successfully deleted, false otherwise.
* @return true if the deliverableInfo was successfully deleted, false
* otherwise.
*/
public void deleteDeliverableInfo(long deliverableInfoId);

/**
* This method validate if the deliverableInfo identify with the given id exists in the system.
* This method validate if the deliverableInfo identify with the given id exists
* in the system.
*
* @param deliverableInfoID is a deliverableInfo identifier.
* @return true if the deliverableInfo exists, false otherwise.
*/
public boolean existDeliverableInfo(long deliverableInfoID);

/**
* This method gets a deliverableInfo object by a given deliverableInfo identifier.
* This method gets a deliverableInfo object by a given deliverableInfo
* identifier.
*
* @param deliverableInfoID is the deliverableInfo identifier.
* @return a DeliverableInfo object.
Expand All @@ -56,35 +58,40 @@ public interface DeliverableInfoDAO {
*/
public List<DeliverableInfo> findAll();


List<DeliverableInfo> getDeliverablesInfoByDeliverableId(long deliverableId);

public List<DeliverableInfo> getDeliverablesInfoByPhase(Phase phase);


/**
* This method gets a list of DeliverableInfo that are active by a given phase, project and status
* This method gets a list of DeliverableInfo that are active by a given phase,
* project and status
*
* @return a list from DeliverableInfo null if no exist records
*/
public List<DeliverableInfo> getDeliverablesInfoByPhaseProjectAndStatus(Phase phase, long projectId, long statusId);

public List<DeliverableInfo> getDeliverablesInfoByPhaseInnovationAndStatus(Phase phase, long innovationId,
long statusId);

/**
* This method gets a list of DeliverableInfo that are active by a given phase and project
* This method gets a list of DeliverableInfo that are active by a given phase
* and project
*
* @return a list from DeliverableInfo null if no exist records
*/
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)
* 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
* 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
*/
Expand All @@ -95,8 +102,10 @@ public interface DeliverableInfoDAO {
/**
* This method saves the information of the given deliverableInfo
*
* @param deliverableInfo - is the deliverableInfo object with the new information to be added/updated.
* @return a number greater than 0 representing the new ID assigned by the database, 0 if the deliverableInfo was
* @param deliverableInfo - is the deliverableInfo object with the new
* information to be added/updated.
* @return a number greater than 0 representing the new ID assigned by the
* database, 0 if the deliverableInfo was
* updated
* or -1 is some error occurred.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* along with MARLO. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************/


package org.cgiar.ccafs.marlo.data.dao.mysql;

import org.cgiar.ccafs.marlo.data.dao.DeliverableInfoDAO;
Expand All @@ -35,7 +34,6 @@
@Named
public class DeliverableInfoMySQLDAO extends AbstractMarloDAO<DeliverableInfo, Long> implements DeliverableInfoDAO {


@Inject
public DeliverableInfoMySQLDAO(SessionFactory sessionFactory) {
super(sessionFactory);
Expand Down Expand Up @@ -155,6 +153,38 @@ public List<DeliverableInfo> getDeliverablesInfoByPhaseProjectAndStatus(Phase ph
return deliverableInfos;
}

@Override
public List<DeliverableInfo> getDeliverablesInfoByPhaseInnovationAndStatus(Phase phase, long innovationId,
long statusId) {

StringBuilder query = new StringBuilder();
query.append("SELECT DISTINCT ");
query.append("di.id as id ");
query.append("FROM ");
query.append("deliverables_info AS di ");
query.append("INNER JOIN deliverables AS d ON d.id = di.deliverable_id ");
query.append("INNER JOIN project_innovation_shared pis ON pis.project_id = d.project_id ");
query.append("WHERE d.is_active = 1 AND ");
query.append("d.project_id IS NOT NULL AND ");
query.append("di.is_active = 1 AND ");
query.append("di.`id_phase` =" + phase.getId());
query.append(" AND pis.project_innovation_id =" + innovationId);
query.append(" AND pis.`id_phase` =" + phase.getId());
query.append(" AND pis.is_active =1");
query.append(" AND di.status !=" + statusId);

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> getDeliverablesInfoByProjectAndPhase(Phase phase, Project project) {
Expand Down Expand Up @@ -183,18 +213,17 @@ 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(
" 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 di.is_active = d.is_active ");
query.append(" AND (d.id IS NOT NULL OR pds.id IS NOT NULL)");
Expand Down Expand Up @@ -226,9 +255,9 @@ public List<DeliverableInfo> getDeliverablesInfoByType(Phase phase, DeliverableT
query.append("di.`id_phase` =" + phase.getId() + " AND ");
query.append("di.`status` !=" + ProjectStatusEnum.Cancelled.getStatusId() + " AND ");
query.append("(( di.status = " + ProjectStatusEnum.Extended.getStatusId() + " AND di.`new_expected_year` ="
+ phase.getYear() + " ) OR ");
+ phase.getYear() + " ) OR ");
query.append(
"( di.status != " + ProjectStatusEnum.Extended.getStatusId() + " AND di.`year` =" + phase.getYear() + " ))");
"( di.status != " + ProjectStatusEnum.Extended.getStatusId() + " AND di.`year` =" + phase.getYear() + " ))");

List<Map<String, Object>> rList = super.findCustomQuery(query.toString());
List<DeliverableInfo> deliverableInfos = new ArrayList<>();
Expand Down Expand Up @@ -273,9 +302,7 @@ public DeliverableInfo save(DeliverableInfo deliverableInfo) {
deliverableInfo = super.update(deliverableInfo);
}


return deliverableInfo;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,34 @@

public interface DeliverableInfoManager {


/**
* This method removes a specific deliverableInfo value from the database.
*
* @param deliverableInfoId is the deliverableInfo identifier.
* @return true if the deliverableInfo was successfully deleted, false otherwise.
* @return true if the deliverableInfo was successfully deleted, false
* otherwise.
*/
public void deleteDeliverableInfo(long deliverableInfoId);


/**
* This method validate if the deliverableInfo identify with the given id exists in the system.
* This method validate if the deliverableInfo identify with the given id exists
* in the system.
*
* @param deliverableInfoID is a deliverableInfo identifier.
* @return true if the deliverableInfo exists, false otherwise.
*/
public boolean existDeliverableInfo(long deliverableInfoID);


/**
* This method gets a list of deliverableInfo that are active
*
* @return a list from DeliverableInfo null if no exist records
*/
public List<DeliverableInfo> findAll();


/**
* This method gets a deliverableInfo object by a given deliverableInfo identifier.
* This method gets a deliverableInfo object by a given deliverableInfo
* identifier.
*
* @param deliverableInfoID is the deliverableInfo identifier.
* @return a DeliverableInfo object.
Expand All @@ -67,42 +66,49 @@ public interface DeliverableInfoManager {
public List<DeliverableInfo> getDeliverablesInfoByPhase(Phase phase);

/**
* This method gets a list of DeliverableInfo that are active by a given phase, project and status
* This method gets a list of DeliverableInfo that are active by a given phase,
* project and status
*
* @return a list from DeliverableInfo null if no exist records
*/
public List<DeliverableInfo> getDeliverablesInfoByPhaseProjectAndStatus(Phase phase, long projectId, long statusId);

public List<DeliverableInfo> getDeliverablesInfoByPhaseInnovationAndStatus(Phase phase, long innovationId,
long statusId);

/**
* This method gets a list of DeliverableInfo that are active by a given phase and type
* 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> getDeliverablesInfoByProjectAndPhase(Phase phase, Project project);

/**
* This method gets a list of DeliverableInfo that are active by a given phase and project (including shared projects)
* 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
* 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);


/**
* This method saves the information of the given deliverableInfo
*
* @param deliverableInfo - is the deliverableInfo object with the new information to be added/updated.
* @return a number greater than 0 representing the new ID assigned by the database, 0 if the deliverableInfo was
* @param deliverableInfo - is the deliverableInfo object with the new
* information to be added/updated.
* @return a number greater than 0 representing the new ID assigned by the
* database, 0 if the deliverableInfo was
* updated
* or -1 is some error occurred.
*/
Expand Down
Loading

0 comments on commit cbc8bb8

Please sign in to comment.