diff --git a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/projects/DeliverableAction.java b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/projects/DeliverableAction.java index fab745cb95..768fd55605 100644 --- a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/projects/DeliverableAction.java +++ b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/projects/DeliverableAction.java @@ -529,6 +529,42 @@ public Boolean candEditYear(long deliverableID) { } + public void deleteAllActionsAndSubActions() { + try { + deliverable.getDeliverableInfo().setShfrmContributionNarrative(null); + List actionPrev = deliverableShfrmPriorityActionManager + .findByDeliverableAndPhase(deliverable.getId(), this.getActualPhase().getId()); + + List deliverableSubActions = new ArrayList<>(); + + if (actionPrev != null) { + for (DeliverableShfrmPriorityAction priorityAction : actionPrev) { + if (priorityAction != null && priorityAction.getId() != null) { + + deliverableSubActions = deliverableShfrmSubActionManager + .findByPriorityActionAndPhase(priorityAction.getId(), this.getActualPhase().getId()); + + if (deliverableSubActions != null && !deliverableSubActions.isEmpty()) { + + // delete sub actions + for (DeliverableShfrmSubAction deliverableSubActionDelete : deliverableSubActions) { + if (deliverableSubActionDelete != null && deliverableSubActionDelete.getId() != null) { + deliverableShfrmSubActionManager.deleteDeliverableShfrmSubAction(deliverableSubActionDelete.getId()); + } + } + } + + // delete actions + deliverableShfrmPriorityActionManager.deleteDeliverableShfrmPriorityAction(priorityAction.getId()); + } + } + } + + } catch (Exception e) { + logger.error("unable to delete priority action", e); + } + } + private void deleteDeliverableLocations(List locationsDB) { if (locationsDB != null) { for (DeliverableLocation deliverableLocation : locationsDB) { @@ -726,6 +762,7 @@ public List getActivities() { return activities; } + /** * Get the ID of the clusterParticipantObject for this cluster in actual phase * @@ -752,7 +789,6 @@ public List getAnswers() { return answers; } - public List getAnswersDataDic() { return answersDataDic; } @@ -894,6 +930,7 @@ public GlobalUnit getLoggedCrp() { return loggedCrp; } + public List getMyProjects() { return myProjects; } @@ -903,7 +940,6 @@ public List getPartnerInstitutions() { return partnerInstitutions; } - public List getPartnerPersons() { return partnerPersons; } @@ -2448,6 +2484,10 @@ public String save() { if (this.hasSpecificities(APConstants.SHFRM_CONTRIBUTION_ACTIVE)) { this.savePriorityActions(false); this.saveSubActions(); + if (deliverable.getDeliverableInfo() != null && (deliverable.getDeliverableInfo().getContributingShfrm() != null + && deliverable.getDeliverableInfo().getContributingShfrm() == false)) { + this.deleteAllActionsAndSubActions(); + } } /* diff --git a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/projects/ProjectExpectedStudiesAction.java b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/projects/ProjectExpectedStudiesAction.java index 5e89308010..b1fe05bc4e 100644 --- a/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/projects/ProjectExpectedStudiesAction.java +++ b/marlo-web/src/main/java/org/cgiar/ccafs/marlo/action/projects/ProjectExpectedStudiesAction.java @@ -2469,15 +2469,17 @@ private void saveReferences(ProjectExpectedStudy projectExpectedStudy, Phase pha // auditlog. this.expectedStudy.getProjectExpectedStudyReferences().add(studyReferenceSave); } else { - ProjectExpectedStudyReference studyReferenceSave = - this.projectExpectedStudyReferenceManager.getProjectExpectedStudyReferenceById(studyReference.getId()); - studyReferenceSave.setProjectExpectedStudy(projectExpectedStudy); - studyReferenceSave.setPhase(phase); - studyReferenceSave.setReference(studyReference.getReference()); - studyReferenceSave.setLink(studyReference.getLink()); - studyReferenceSave.setExternalAuthor(studyReference.getExternalAuthor()); - try { + ProjectExpectedStudyReference studyReferenceSave = + this.projectExpectedStudyReferenceManager.getProjectExpectedStudyReferenceById(studyReference.getId()); + if (studyReferenceSave != null && projectExpectedStudy != null) { + studyReferenceSave.setProjectExpectedStudy(projectExpectedStudy); + studyReferenceSave.setPhase(phase); + studyReferenceSave.setReference(studyReference.getReference()); + studyReferenceSave.setLink(studyReference.getLink()); + studyReferenceSave.setExternalAuthor(studyReference.getExternalAuthor()); + } + this.projectExpectedStudyReferenceManager.saveProjectExpectedStudyReference(studyReferenceSave); // This is to add studyReferenceSave to generate correct // auditlog.