Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aiccra feature a2 569 - partner process #2541

Merged
merged 4 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.cgiar.ccafs.marlo.data.dao;

import org.cgiar.ccafs.marlo.data.model.Deliverable;
import org.cgiar.ccafs.marlo.data.model.DeliverableDTO;
import org.cgiar.ccafs.marlo.data.model.DeliverableHomeDTO;
import org.cgiar.ccafs.marlo.data.model.Phase;

Expand Down Expand Up @@ -120,6 +121,20 @@ List<Deliverable> getDeliverablesByPhaseAndUrlAndDoiAndHandel(long phase, String
*/
List<Deliverable> getDeliverablesLeadByUserAndProject(long userId, long phaseId, long projectId);

List<Deliverable> getDeliverablesLeadByUserAndProjectWithConditions(long userId, long phaseId, long projectId);

/**
* get deliverables list by user, phase and project
*
* @author IBD
* @param phaseId phase id
* @param projectId project id
* @param userId user id
* @return deliverables (DTO) list
*/
List<DeliverableDTO> getDeliverablesLeadByUserAndProjectWithSimpleConditions(long userId, long phaseId,
long projectId);

List<String> getDuplicatesDeliverablesByPhase(long phase);

public List<Deliverable> getPublicationsByPhase(long phase);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public List<Activity> findAll() {
@Override
public List<Activity> getActivitiesByProject(long projectId, long phaseId) {
String query = "from " + Activity.class.getName() + " where project_id=" + projectId + " and id_phase=" + phaseId
+ " and is_active=1";
+ " and is_active=1 and activityStatus=2";
List<Activity> list = super.findAll(query);
if (!list.isEmpty()) {
return list;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.cgiar.ccafs.marlo.data.dao.DeliverableDAO;
import org.cgiar.ccafs.marlo.data.model.Deliverable;
import org.cgiar.ccafs.marlo.data.model.DeliverableDTO;
import org.cgiar.ccafs.marlo.data.model.DeliverableHomeDTO;
import org.cgiar.ccafs.marlo.data.model.Phase;
import org.cgiar.ccafs.marlo.data.model.ProjectStatusEnum;
Expand Down Expand Up @@ -361,6 +362,7 @@ public List<Deliverable> getDeliverablesLeadByInstitutionAndProject(long institu
query.append("dup.is_active = 1 AND ");
query.append("dupp.is_active = 1 AND ");
query.append("dup.institution_id =" + institutionId + " AND ");
query.append("dup.id_phase = d.id_phase and ");
query.append("dup.id_phase = " + phaseId);
query.append(" and d.is_active =1 ");
query.append(" and d.project_id = " + projectId);
Expand Down Expand Up @@ -438,6 +440,126 @@ public List<Deliverable> getDeliverablesLeadByUserAndProject(long userId, long p
return deliverables;
}


@Override
public List<Deliverable> getDeliverablesLeadByUserAndProjectWithConditions(long userId, long phaseId,
long projectId) {
StringBuilder query = new StringBuilder();
query.append("SELECT DISTINCT ");
query.append("dup.deliverable_id as id ");
query.append("FROM ");
query.append("deliverable_user_partnerships AS dup ");
query.append("INNER JOIN deliverable_user_partnership_persons AS dupp ON dupp.user_partnership_id = dup.id ");
query.append(" inner join deliverables as d on dup.deliverable_id = d.id ");
query.append(" inner join deliverables_info di on di.deliverable_id = d.id ");
query.append(" inner join phases p on p.id = d.id_phase ");
query.append("WHERE ");
query.append("dupp.user_id =" + userId + " AND ");
query.append("dup.is_active = 1 AND ");
query.append("dupp.is_active = 1 AND ");
query.append(" dup.id_phase = d.id_phase AND ");
query.append("d.id_phase = di.id_phase AND ");
query.append("dup.id_phase =" + phaseId);
query.append(" and d.project_id =" + projectId);
query.append(" and di.status in (2,4) ");
query.append(" and d.is_active =1 ");
query.append(" and di.year >= p.year ");
query.append(" union ");
query.append("SELECT DISTINCT ");
query.append("dup.deliverable_id as id ");
query.append("FROM ");
query.append("deliverable_user_partnerships AS dup ");
query.append("INNER JOIN deliverable_user_partnership_persons AS dupp ON dupp.user_partnership_id = dup.id ");
query.append(" inner join deliverables as d on dup.deliverable_id = d.id ");
query.append(" inner join deliverables_info di on di.deliverable_id = d.id ");
query.append(" inner join phases p on p.id = d.id_phase ");
query.append("WHERE ");
query.append("dupp.user_id =" + userId + " AND ");
query.append("dup.is_active = 1 AND ");
query.append("dupp.is_active = 1 AND ");
query.append(" dup.id_phase = d.id_phase AND ");
query.append("d.id_phase = di.id_phase AND ");
query.append("dup.id_phase =" + phaseId);
query.append(" and d.project_id =" + projectId);
query.append(" and di.status in (4) ");
query.append(" and d.is_active =1 ");
query.append(" and di.new_expected_year >= p.year ");

List<Map<String, Object>> rList = super.findCustomQuery(query.toString());
List<Deliverable> deliverables = new ArrayList<>();

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

return deliverables;
}


@Override
public List<DeliverableDTO> getDeliverablesLeadByUserAndProjectWithSimpleConditions(long userId, long phaseId,
long projectId) {
StringBuilder query = new StringBuilder();
query.append("SELECT DISTINCT ");
query.append("dup.deliverable_id as id ");
query.append(",di.title as tittle ");
query.append("FROM ");
query.append("deliverable_user_partnerships AS dup ");
query.append("INNER JOIN deliverable_user_partnership_persons AS dupp ON dupp.user_partnership_id = dup.id ");
query.append(" inner join deliverables as d on dup.deliverable_id = d.id ");
query.append(" inner join deliverables_info di on di.deliverable_id = d.id ");
query.append(" inner join phases p on p.id = d.id_phase ");
query.append("WHERE ");
query.append("dupp.user_id =" + userId + " AND ");
query.append("dup.is_active = 1 AND ");
query.append("dupp.is_active = 1 AND ");
query.append(" dup.id_phase = d.id_phase AND ");
query.append("d.id_phase = di.id_phase AND ");
query.append("dup.id_phase =" + phaseId);
query.append(" and d.project_id =" + projectId);
query.append(" and di.status in (2,4) ");
query.append(" and d.is_active =1 ");
query.append(" and di.year >= p.year ");
query.append(" union ");
query.append("SELECT DISTINCT ");
query.append("dup.deliverable_id as id ");
query.append(",di.title as tittle ");
query.append("FROM ");
query.append("deliverable_user_partnerships AS dup ");
query.append("INNER JOIN deliverable_user_partnership_persons AS dupp ON dupp.user_partnership_id = dup.id ");
query.append(" inner join deliverables as d on dup.deliverable_id = d.id ");
query.append(" inner join deliverables_info di on di.deliverable_id = d.id ");
query.append(" inner join phases p on p.id = d.id_phase ");
query.append("WHERE ");
query.append("dupp.user_id =" + userId + " AND ");
query.append("dup.is_active = 1 AND ");
query.append("dupp.is_active = 1 AND ");
query.append(" dup.id_phase = d.id_phase AND ");
query.append("d.id_phase = di.id_phase AND ");
query.append("dup.id_phase =" + phaseId);
query.append(" and d.project_id =" + projectId);
query.append(" and di.status in (4) ");
query.append(" and d.is_active =1 ");
query.append(" and di.new_expected_year >= p.year ");

List<Map<String, Object>> rList = super.findCustomQuery(query.toString());
List<DeliverableDTO> deliverables = new ArrayList<>();

if (rList != null) {
for (Map<String, Object> map : rList) {
DeliverableDTO deliverable = new DeliverableDTO();
deliverable.setId(Long.parseLong(map.get("id").toString()));
deliverable.setTitle(map.get("tittle").toString());
deliverables.add(deliverable);
}
}

return deliverables;
}

/**
* Get listing to validate duplicate information (dissemination_URL,DIO, handle)
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.cgiar.ccafs.marlo.data.manager;

import org.cgiar.ccafs.marlo.data.model.Deliverable;
import org.cgiar.ccafs.marlo.data.model.DeliverableDTO;
import org.cgiar.ccafs.marlo.data.model.DeliverableHomeDTO;
import org.cgiar.ccafs.marlo.data.model.LiaisonInstitution;
import org.cgiar.ccafs.marlo.data.model.Phase;
Expand Down Expand Up @@ -130,6 +131,12 @@ List<Deliverable> getDeliverablesByPhaseAndUrlAndDoiAndHandel(long phase, String
List<Deliverable> getDeliverablesLeadByUserAndProject(long userId, long phaseId, long projectId);


List<Deliverable> getDeliverablesLeadByUserAndProjectWithConditions(long userId, long phaseId, long projectId);

List<DeliverableDTO> getDeliverablesLeadByUserAndProjectWithSimpleConditions(long userId, long phaseId,
long projectId);


/**
* This method gets a list of deliverables that are active for an specific liaisonInstitution
* Flagship: Get the list of projects that have project_focus equal to the liaisonInstitution
Expand All @@ -146,6 +153,7 @@ List<Deliverable> getDeliverablesByPhaseAndUrlAndDoiAndHandel(long phase, String

public List<Deliverable> getNotPublicationsList(LiaisonInstitution liaisonInstitution, Phase phase);


/**
* This method gets a list of publications that are active by a given phase
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.cgiar.ccafs.marlo.data.model.CrpClusterKeyOutput;
import org.cgiar.ccafs.marlo.data.model.CrpClusterOfActivity;
import org.cgiar.ccafs.marlo.data.model.Deliverable;
import org.cgiar.ccafs.marlo.data.model.DeliverableDTO;
import org.cgiar.ccafs.marlo.data.model.DeliverableHomeDTO;
import org.cgiar.ccafs.marlo.data.model.DeliverableInfo;
import org.cgiar.ccafs.marlo.data.model.DeliverableProgram;
Expand Down Expand Up @@ -214,6 +215,28 @@ public List<Deliverable> getDeliverablesLeadByUserAndProject(long userId, long p
return deliverableDAO.getDeliverablesLeadByUserAndProject(userId, phaseId, projectId);
}

@Override
public List<Deliverable> getDeliverablesLeadByUserAndProjectWithConditions(long userId, long phaseId,
long projectId) {
return deliverableDAO.getDeliverablesLeadByUserAndProjectWithConditions(userId, phaseId, projectId);
}

/**
* get deliverables list by user, phase and project
*
* @author IBD
* @param phaseId phase id
* @param projectId project id
* @param userId user id
* @return deliverables (DTO) list
*/
@Override
public List<DeliverableDTO> getDeliverablesLeadByUserAndProjectWithSimpleConditions(long userId, long phaseId,
long projectId) {
return deliverableDAO.getDeliverablesLeadByUserAndProjectWithSimpleConditions(userId, phaseId, projectId);
}


@Override
public List<Deliverable> getDeliverablesList(LiaisonInstitution liaisonInstitution, Phase phase) {
Phase phaseDB = phaseManager.getPhaseById(phase.getId());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*****************************************************************
* This file is part of Managing Agricultural Research for Learning &
* Outcomes Platform (MARLO).
* MARLO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
* MARLO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with MARLO. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************/

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


public class DeliverableDTO {

Long id;

private String title;


public Long getId() {
return id;
}


public String getTitle() {
return title;
}


public void setId(Long id) {
this.id = id;
}


public void setTitle(String title) {
this.title = title;
}


@Override
public String toString() {
return "DeliverableDTO [id=" + id + ", title=" + title + "]";
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.cgiar.ccafs.marlo.data.model.CrpProgramLeader;
import org.cgiar.ccafs.marlo.data.model.CrpUser;
import org.cgiar.ccafs.marlo.data.model.Deliverable;
import org.cgiar.ccafs.marlo.data.model.DeliverableDTO;
import org.cgiar.ccafs.marlo.data.model.GlobalUnit;
import org.cgiar.ccafs.marlo.data.model.GlobalUnitProject;
import org.cgiar.ccafs.marlo.data.model.Institution;
Expand Down Expand Up @@ -465,14 +466,14 @@ public List<Deliverable> getDeliverablesLedByPartner(Long projectPartnerID) {
List<Deliverable> deliverablesLeads = new ArrayList<>();
if (projectPartnerID != null && projectPartnerID != 0) {
ProjectPartner projectPartner = projectPartnerManager.getProjectPartnerById(projectPartnerID);

if (projectPartner != null) {
/// cgamboa 17/05/2024 getDeliverablesLeadByInstitution was changed by
/// getDeliverablesLeadByInstitutionAndProject
List<Deliverable> deliverables = deliverableManager
// .getDeliverablesLeadByInstitution(projectPartner.getInstitution().getId(), this.getActualPhase().getId());
.getDeliverablesLeadByInstitutionAndProject(projectPartner.getInstitution().getId(),
this.getActualPhase().getId(), projectID);

for (Deliverable deliverable : deliverables) {
if (deliverable.getProject() != null && deliverable.getProject().getId().equals(projectID)) {
deliverable.setDeliverableInfo(deliverable.getDeliverableInfo(this.getActualPhase()));
Expand Down Expand Up @@ -504,8 +505,29 @@ public List<Deliverable> getDeliverablesLedByPartner(Long projectPartnerID) {
return deliverablesLeads;
}

/**
* get deliverables list by user
*
* @author IBD
* @param userId user id
* @return deliverables (DTO) list
*/
public List<DeliverableDTO> getDeliverablesLedByUser(long userID) {
List<DeliverableDTO> deliverablesLeadsTmp = new ArrayList<>();
try {

deliverablesLeadsTmp = deliverableManager.getDeliverablesLeadByUserAndProjectWithSimpleConditions(userID,
this.getActualPhase().getId(), projectID);

public List<Deliverable> getDeliverablesLedByUser(long userID) {
} catch (Exception e) {
LOG.error(" unable to get deliverables - getDeliverablesLedByUser function ");
}
return deliverablesLeadsTmp;

}


public List<Deliverable> getDeliverablesLedByUserOld(long userID) {
List<Deliverable> deliverablesLeads = new ArrayList<>();
List<Deliverable> deliverables =
// cgamboa 16/05/2024 getDeliverablesLeadByUser was changed by getDeliverablesLeadByUser
Expand Down Expand Up @@ -1808,7 +1830,6 @@ public String save() {
} else {
this.addActionMessage("message:" + this.getText("saving.saved"));
}

return SUCCESS;
} else {
this.addActionMessage("");
Expand Down
Loading
Loading