Skip to content

Commit

Permalink
🔧 chore(Shfrm contribution): Update deliverable delete model
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjitm committed Feb 22, 2024
1 parent 1e0791a commit c9d48a8
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public interface DeliverableShfrmPriorityActionDAO {

public List<DeliverableShfrmPriorityAction> findByDeliverableAndPhase(long deliverableId, long phaseId);

public List<DeliverableShfrmPriorityAction> findByDeliverablePriorityActionAndPhase(long deliverableId,
long priorityActionId, long phaseId);


/**
* This method saves the information of the given deliverableShfrmPriorityAction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ public List<DeliverableShfrmPriorityAction> findByDeliverableAndPhase(long deliv
return null;
}

@Override
public List<DeliverableShfrmPriorityAction> findByDeliverablePriorityActionAndPhase(long deliverableId,
long priorityActionId, long phaseId) {
String query = "from " + DeliverableShfrmPriorityAction.class.getName() + " where is_active=1 and deliverable_id="
+ deliverableId + " and shfrm_priority_action_id=" + priorityActionId + " and id_phase=" + phaseId;
List<DeliverableShfrmPriorityAction> list = super.findAll(query);
if (list.size() > 0) {
return list;
}
return null;
}

@Override
public DeliverableShfrmPriorityAction save(DeliverableShfrmPriorityAction deliverableShfrmPriorityAction) {
if (deliverableShfrmPriorityAction.getId() == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public interface DeliverableShfrmPriorityActionManager {

public List<DeliverableShfrmPriorityAction> findByDeliverableAndPhase(long deliverableId, long phaseId);

public List<DeliverableShfrmPriorityAction> findByDeliverablePriorityActionAndPhase(long deliverableId,
long priorityActionId, long phaseId);


/**
* This method gets a deliverableShfrmPriorityAction object by a given deliverableShfrmPriorityAction identifier.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ public List<DeliverableShfrmPriorityAction> findByDeliverableAndPhase(long deliv

}

@Override
public List<DeliverableShfrmPriorityAction> findByDeliverablePriorityActionAndPhase(long deliverableId,
long priorityActionId, long phaseId) {
return deliverableShfrmPriorityActionDAO.findByDeliverablePriorityActionAndPhase(deliverableId, priorityActionId,
phaseId);

}


@Override
public DeliverableShfrmPriorityAction getDeliverableShfrmPriorityActionById(long deliverableShfrmPriorityActionID) {

Expand All @@ -134,7 +143,7 @@ public DeliverableShfrmPriorityAction getDeliverableShfrmPriorityActionById(long
public void saveDeliverableShfrmPriorityActionPhase(Phase next, long deliverableId,
DeliverableShfrmPriorityAction deliverableShfrmPriorityAction) {
Phase phase = phaseDAO.find(next.getId());
DeliverableShfrmPriorityAction deliverableShfrmPriorityActionPhase = new DeliverableShfrmPriorityAction();
DeliverableShfrmPriorityAction deliverableShfrmPriorityActionPhase = null;
try {
deliverableShfrmPriorityActionPhase = deliverableShfrmPriorityActionDAO
.findByDeliverableAndPhase(deliverableId, phase.getId()).stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
package org.cgiar.ccafs.marlo.data.manager.impl;


import org.cgiar.ccafs.marlo.data.dao.DeliverableShfrmPriorityActionDAO;
import org.cgiar.ccafs.marlo.data.dao.DeliverableShfrmSubActionDAO;
import org.cgiar.ccafs.marlo.data.dao.PhaseDAO;
import org.cgiar.ccafs.marlo.data.manager.DeliverableShfrmSubActionManager;
import org.cgiar.ccafs.marlo.data.model.DeliverableShfrmPriorityAction;
import org.cgiar.ccafs.marlo.data.model.DeliverableShfrmSubAction;
import org.cgiar.ccafs.marlo.data.model.Phase;

Expand All @@ -39,12 +41,14 @@ public class DeliverableShfrmSubActionManagerImpl implements DeliverableShfrmSub

// Managers
private DeliverableShfrmSubActionDAO deliverableShfrmSubActionDAO;
private DeliverableShfrmPriorityActionDAO deliverableShfrmPriorityActionDAO;
private PhaseDAO phaseDAO;

@Inject
public DeliverableShfrmSubActionManagerImpl(DeliverableShfrmSubActionDAO deliverableShfrmSubActionDAO,
PhaseDAO phaseDAO) {
PhaseDAO phaseDAO, DeliverableShfrmPriorityActionDAO deliverableShfrmPriorityActionDAO) {
this.deliverableShfrmSubActionDAO = deliverableShfrmSubActionDAO;
this.deliverableShfrmPriorityActionDAO = deliverableShfrmPriorityActionDAO;
this.phaseDAO = phaseDAO;
}

Expand All @@ -65,12 +69,15 @@ public void deleteDeliverableShfrmSubAction(long deliverableShfrmSubActionId) {
public void deleteDeliverableShfrmSubActionPhase(Phase next, DeliverableShfrmSubAction deliverableShfrmSubAction) {
Phase phase = phaseDAO.find(next.getId());

DeliverableShfrmPriorityAction deliverablePriorityActionPhase =
this.findDeliverablePriorityActionByDeliverablePriorityActionAndPhase(deliverableShfrmSubAction, phase);
DeliverableShfrmSubAction deliverableShfrmSubActionDelete = new DeliverableShfrmSubAction();
deliverableShfrmSubActionDelete = deliverableShfrmSubActionDAO
.findByPriorityActionPhaseAndSubAction(deliverableShfrmSubAction.getDeliverableShfrmPriorityAction().getId(),
phase.getId(), deliverableShfrmSubAction.getShfrmSubAction().getId())
.get(0);

if (deliverablePriorityActionPhase != null && deliverablePriorityActionPhase.getId() != null) {
deliverableShfrmSubActionDelete =
deliverableShfrmSubActionDAO.findByPriorityActionPhaseAndSubAction(deliverablePriorityActionPhase.getId(),
phase.getId(), deliverableShfrmSubAction.getShfrmSubAction().getId()).get(0);
}
if (deliverableShfrmSubActionDelete != null) {
deliverableShfrmSubActionDAO.deleteDeliverableShfrmSubAction(deliverableShfrmSubActionDelete.getId());
}
Expand Down Expand Up @@ -106,6 +113,27 @@ public List<DeliverableShfrmSubAction> findByPriorityActionPhaseAndSubAction(lon
shfrmSubActionId);
}

public DeliverableShfrmPriorityAction findDeliverablePriorityActionByDeliverablePriorityActionAndPhase(
DeliverableShfrmSubAction deliverableShfrmSubAction, Phase phase) {
DeliverableShfrmPriorityAction deliverableshfrmPriorityActionPhase = null;
try {
if (phase != null && phase.getId() != null && deliverableShfrmSubAction != null
&& deliverableShfrmSubAction.getDeliverableShfrmPriorityAction() != null
&& deliverableShfrmSubAction.getDeliverableShfrmPriorityAction().getShfrmPriorityAction() != null
&& deliverableShfrmSubAction.getDeliverableShfrmPriorityAction().getShfrmPriorityAction().getId() != null
&& deliverableShfrmSubAction.getDeliverableShfrmPriorityAction().getDeliverable() != null
&& deliverableShfrmSubAction.getDeliverableShfrmPriorityAction().getDeliverable().getId() != null) {
deliverableshfrmPriorityActionPhase = deliverableShfrmPriorityActionDAO.findByDeliverablePriorityActionAndPhase(
deliverableShfrmSubAction.getDeliverableShfrmPriorityAction().getDeliverable().getId(),
deliverableShfrmSubAction.getDeliverableShfrmPriorityAction().getShfrmPriorityAction().getId(), phase.getId())
.get(0);
}
} catch (Exception e) {
logger.error("error getting deliverableShfrmPriorityActionPhase in subActionsavePhase: " + e);
}
return deliverableshfrmPriorityActionPhase;
}

@Override
public DeliverableShfrmSubAction getDeliverableShfrmSubActionById(long deliverableShfrmSubActionID) {

Expand All @@ -129,31 +157,43 @@ public DeliverableShfrmSubAction saveDeliverableShfrmSubAction(DeliverableShfrmS
public void saveDeliverableShfrmSubActionPhase(Phase next, DeliverableShfrmSubAction deliverableShfrmSubAction) {
Phase phase = phaseDAO.find(next.getId());
DeliverableShfrmSubAction deliverableShfrmSubActionPhase = new DeliverableShfrmSubAction();


// get priority action
DeliverableShfrmPriorityAction deliverableShfrmPriorityActionPhase = null;
try {
deliverableShfrmSubActionPhase = deliverableShfrmSubActionDAO
.findByPriorityActionPhaseAndSubAction(deliverableShfrmSubAction.getDeliverableShfrmPriorityAction().getId(),
phase.getId(), deliverableShfrmSubAction.getShfrmSubAction().getId())
.get(0);
deliverableShfrmPriorityActionPhase =
this.findDeliverablePriorityActionByDeliverablePriorityActionAndPhase(deliverableShfrmSubAction, phase);
} catch (Exception e) {
logger.error("error getting deliverableShfrmSubActionPhase: " + e);
logger.error("error getting deliverable priority action " + e);
}

if (deliverableShfrmSubActionPhase != null) {
DeliverableShfrmSubAction deliverableShfrmSubActionAdd = deliverableShfrmSubActionPhase;
deliverableShfrmSubActionAdd.setPhase(phase);
deliverableShfrmSubActionAdd.setShfrmSubAction(deliverableShfrmSubAction.getShfrmSubAction());
deliverableShfrmSubActionAdd
.setDeliverableShfrmPriorityAction(deliverableShfrmSubAction.getDeliverableShfrmPriorityAction());
deliverableShfrmSubActionDAO.save(deliverableShfrmSubActionAdd);
} else {
DeliverableShfrmSubAction deliverableShfrmSubActionAdd = new DeliverableShfrmSubAction();
deliverableShfrmSubActionAdd.setPhase(phase);
deliverableShfrmSubActionAdd.setShfrmSubAction(deliverableShfrmSubAction.getShfrmSubAction());
deliverableShfrmSubActionAdd
.setDeliverableShfrmPriorityAction(deliverableShfrmSubAction.getDeliverableShfrmPriorityAction());
deliverableShfrmSubActionDAO.save(deliverableShfrmSubActionAdd);
try {
if (deliverableShfrmPriorityActionPhase != null && deliverableShfrmPriorityActionPhase.getId() != null) {
deliverableShfrmSubActionPhase = deliverableShfrmSubActionDAO
.findByPriorityActionPhaseAndSubAction(deliverableShfrmPriorityActionPhase.getId(), phase.getId(),
deliverableShfrmSubAction.getShfrmSubAction().getId())
.get(0);
}
} catch (Exception e) {
logger.error("error getting deliverableShfrmSubActionPhase: " + e);
}

if (deliverableShfrmPriorityActionPhase != null) {
if (deliverableShfrmSubActionPhase != null) {
DeliverableShfrmSubAction deliverableShfrmSubActionAdd = deliverableShfrmSubActionPhase;
deliverableShfrmSubActionAdd.setPhase(phase);
deliverableShfrmSubActionAdd.setShfrmSubAction(deliverableShfrmSubAction.getShfrmSubAction());
deliverableShfrmSubActionAdd.setDeliverableShfrmPriorityAction(deliverableShfrmPriorityActionPhase);
deliverableShfrmSubActionDAO.save(deliverableShfrmSubActionAdd);
} else {
DeliverableShfrmSubAction deliverableShfrmSubActionAdd = new DeliverableShfrmSubAction();
deliverableShfrmSubActionAdd.setPhase(phase);
deliverableShfrmSubActionAdd.setShfrmSubAction(deliverableShfrmSubAction.getShfrmSubAction());
deliverableShfrmSubActionAdd.setDeliverableShfrmPriorityAction(deliverableShfrmPriorityActionPhase);
deliverableShfrmSubActionDAO.save(deliverableShfrmSubActionAdd);
}
}
if (phase.getNext() != null) {
this.saveDeliverableShfrmSubActionPhase(phase.getNext(), deliverableShfrmSubAction);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ public class DeliverableAction extends BaseAction {
private String handle;
private String disseminationURL;
private String soilIndicatorsText;
private String previousContributionNarrative;

private List<RepIndGenderYouthFocusLevel> focusLevels;
// HJ 08/01/2019 new fileds Deliverable Partnerships
Expand Down Expand Up @@ -687,23 +686,6 @@ public void fillClusterParticipantsList() {
}
}

public void fillPreviousContributionNarrative() {
try {
if (this.isReportingActive()) {
Phase previousPhase = phaseManager.findPreviousPhase(this.getActualPhase().getId());
if (previousPhase != null) {
if (deliverable.getDeliverableInfo(previousPhase) != null
&& deliverable.getDeliverableInfo(previousPhase).getShfrmContributionNarrative() != null) {
previousContributionNarrative =
deliverable.getDeliverableInfo(previousPhase).getShfrmContributionNarrative();
}
}
}
} catch (Exception e) {
Log.error("error getting previous contribution narrative " + e);
}
}

public void fillSoilIndicatorsText() {
try {
soilIndicatorsText = null;
Expand Down Expand Up @@ -1015,10 +997,6 @@ public long[] getPersonsIds(DeliverableUserPartnership deliverableUserPartnershi
return EMPTY_ARRAY;
}

public String getPreviousContributionNarrative() {
return previousContributionNarrative;
}

public List<CrpProgramOutcome> getProgramOutcomes() {
return programOutcomes;
}
Expand Down Expand Up @@ -1261,6 +1239,43 @@ public boolean isPPA(Institution institution) {
return false;
}

public boolean isSoilIndicatorSelected() {
boolean containsIndicator = false;

try {
if (deliverable.getCrpOutcomes() != null || !deliverable.getCrpOutcomes().isEmpty()) {
List<SoilIndicator> soilIndicators = new ArrayList<>();
soilIndicators = soilIndicatorManager.findAll();
for (DeliverableCrpOutcome indicator : deliverable.getCrpOutcomes()) {
if (soilIndicators != null && !soilIndicators.isEmpty()) {
for (SoilIndicator soilIndicator : soilIndicators) {
if (indicator != null && indicator.getCrpProgramOutcome() != null
&& indicator.getCrpProgramOutcome().getId() != null) {
try {
CrpProgramOutcome outcome =
crpProgramOutcomeManager.getCrpProgramOutcomeById(indicator.getCrpProgramOutcome().getId());
if (outcome != null && outcome.getAcronym() != null) {
indicator.getCrpProgramOutcome().setAcronym(outcome.getAcronym());
}
} catch (Exception e) {
Log.error("error getting crp program outcome " + e);
}
}
if (soilIndicator != null && soilIndicator.getIndicatorName() != null && indicator != null
&& indicator.getCrpProgramOutcome() != null && indicator.getCrpProgramOutcome().getAcronym() != null
&& indicator.getCrpProgramOutcome().getAcronym().contains(soilIndicator.getIndicatorName())) {
containsIndicator = true;
}
}
}
}
}
} catch (Exception e) {
Log.error("error validating soil indicator boolean " + e);
}
return containsIndicator;
}

@Override
public void prepare() throws Exception {
existCurrentCluster = false;
Expand Down Expand Up @@ -1638,7 +1653,6 @@ public void prepare() throws Exception {
}

this.fillSoilIndicatorsText();
this.fillPreviousContributionNarrative();
}

// Expected Study Geographic Regions List
Expand Down Expand Up @@ -4183,17 +4197,15 @@ public void saveSubActions() {
}
} else {
// Delete all in DB
/*
* if (subPrev != null && !subPrev.isEmpty()) {
* for (DeliverableShfrmSubAction subAction : subPrev) {
* if (subAction != null && subAction.getId() != null) {
* if (!existingIds.contains(subAction.getId())) {
* deliverableShfrmSubActionManager.deleteDeliverableShfrmSubAction(subAction.getId());
* }
* }
* }
* }
*/

if (subPrev != null && !subPrev.isEmpty()) {
for (DeliverableShfrmSubAction subAction : subPrev) {
if (subAction != null && subAction.getId() != null) {
deliverableShfrmSubActionManager.deleteDeliverableShfrmSubAction(subAction.getId());
}
}
}

}

/***************/
Expand Down Expand Up @@ -4222,6 +4234,9 @@ public void saveSubActions() {
// For new deliverable Priority Actions
if (deliverableSubAction.getId() == null || deliverableSubAction.getId() == -1) {
deliverableSubActionSave.setId(null);
if (deliverablePriorityAction.getDeliverable() == null) {
deliverablePriorityAction.setDeliverable(deliverable);
}
deliverableSubActionSave.setDeliverableShfrmPriorityAction(deliverablePriorityAction);
deliverableSubActionSave.setPhase(this.getActualPhase());
deliverableSubActionSave.setShfrmSubAction(subAction);
Expand All @@ -4233,6 +4248,9 @@ public void saveSubActions() {
deliverableSubActionSave =
deliverableShfrmSubActionManager.getDeliverableShfrmSubActionById(deliverableSubAction.getId());
if (deliverableSubActionSave != null) {
if (deliverablePriorityAction.getDeliverable() == null) {
deliverablePriorityAction.setDeliverable(deliverable);
}
deliverableSubActionSave.setDeliverableShfrmPriorityAction(deliverablePriorityAction);
deliverableSubActionSave.setPhase(this.getActualPhase());
deliverableSubActionSave.setShfrmSubAction(subAction);
Expand Down Expand Up @@ -4412,10 +4430,6 @@ public void setPartners(List<ProjectPartner> partners) {
this.partners = partners;
}

public void setPreviousContributionNarrative(String previousContributionNarrative) {
this.previousContributionNarrative = previousContributionNarrative;
}

public void setProgramOutcomes(List<CrpProgramOutcome> programOutcomes) {
this.programOutcomes = programOutcomes;
}
Expand Down
Loading

0 comments on commit c9d48a8

Please sign in to comment.