Skip to content

Commit

Permalink
Merge branch 'aiccra-shfrm-contribution-functionality' into aiccra-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjitm committed Feb 15, 2024
2 parents d693359 + 0e22b07 commit b2f04ef
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,37 @@ public String save() {

if (priorityActionsDB != null) {
try {
List<ShfrmSubAction> subActions = new ArrayList<>();

for (ShfrmPriorityAction actionDB : priorityActionsDB) {
if (this.priorityActions != null && !this.priorityActions.isEmpty()) {
Set<Long> actionIdsInFrontend = this.priorityActions.stream().filter(Objects::nonNull)
.map(ShfrmPriorityAction::getId).collect(Collectors.toSet());
if (!actionIdsInFrontend.contains(actionDB.getId())) {

// Validate previous sub actions in DB for each priority actions
if (actionDB.getShfrmSubActions() == null
|| (actionDB.getShfrmSubActions() != null && actionDB.getShfrmSubActions().isEmpty())) {
shfrmPriorityActionManager.deleteShfrmPriorityAction(actionDB.getId());

try {
subActions = shfrmSubActionManager.findAll().stream()
.filter(subActionDB -> subActionDB.getShfrmPriorityAction() != null
&& subActionDB.getShfrmPriorityAction().getId() != null
&& subActionDB.getShfrmPriorityAction().getId().equals(actionDB.getId()))
.collect(Collectors.toList());;


if (subActions != null && !subActions.isEmpty()) {

// delete sub actions
for (ShfrmSubAction subActionDelete : subActions) {
if (subActionDelete != null && subActionDelete.getId() != null) {
shfrmSubActionManager.deleteShfrmSubAction(subActionDelete.getId());
}
}
}
} catch (Exception e) {
logger.error("error deleting sub actions", e);
}
shfrmPriorityActionManager.deleteShfrmPriorityAction(actionDB.getId());


}
Expand Down Expand Up @@ -224,10 +244,30 @@ public String save() {
} else {
// Delete all priority actions DB
try {
List<ShfrmSubAction> subActions = new ArrayList<>();

if (priorityActionsDB != null && !priorityActionsDB.isEmpty()) {
priorityActionsDB.forEach(priorityAction -> {
shfrmPriorityActionManager.deleteShfrmPriorityAction(priorityAction.getId());
});
for (ShfrmPriorityAction priorityActionDB : priorityActionsDB) {

subActions = shfrmSubActionManager.findAll().stream()
.filter(subActionDB -> subActionDB.getShfrmPriorityAction() != null
&& subActionDB.getShfrmPriorityAction().getId() != null
&& subActionDB.getShfrmPriorityAction().getId().equals(priorityActionDB.getId()))
.collect(Collectors.toList());;


if (subActions != null && !subActions.isEmpty()) {

// delete sub actions
for (ShfrmSubAction subActionDelete : subActions) {
if (subActionDelete != null && subActionDelete.getId() != null) {
shfrmSubActionManager.deleteShfrmSubAction(subActionDelete.getId());
}
}
}

shfrmPriorityActionManager.deleteShfrmPriorityAction(priorityActionDB.getId());
}
}
} catch (Exception e) {
logger.error("error deleting priority actions: " + e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1580,7 +1580,7 @@
[#-- ${(shfrmPriorityActions[${priorityAction_index}].shfrmSubActions)![]} --]
[#if priorityAction.shfrmSubActions?has_content]
<div class="baseselect hideSelect">
[@customForm.select name="" label="" i18nkey="deliverable.shfrmContribution.subAction.help" listName="shfrmPriorityActions[${priorityAction_index}].shfrmSubActions" keyFieldName="id" displayFieldName="name" multiple=false required=true className=" deliverableList" disabled=!editable/]
[@customForm.select name="" label="" i18nkey="deliverable.shfrmContribution.subAction.help" listName="shfrmPriorityActions[${priorityAction_index}].shfrmSubActions" keyFieldName="id" displayFieldName="composedName" multiple=false required=true className=" deliverableList" disabled=!editable/]
</div>

[/#if]
Expand Down

0 comments on commit b2f04ef

Please sign in to comment.