use of org.apache.isis.applib.annotation.ParameterLayout in project estatio by estatio.
the class Budget_Remove method removeBudget.
@Action(semantics = SemanticsOf.NON_IDEMPOTENT_ARE_YOU_SURE)
@ActionLayout(contributed = Contributed.AS_ACTION)
public void removeBudget(@ParameterLayout(named = "This will delete the budget and all associated data including keytables, calculations, runs, results and lease terms. (You may consider downloading the budget and the keytables beforehand.) Are you sure?") final boolean areYouSure) {
// delete results and runs
for (BudgetCalculationRun run : budgetCalculationRunRepository.allBudgetCalculationRuns().stream().filter(x -> x.getBudget().equals(budget)).collect(Collectors.toList())) {
for (BudgetCalculationResult result : run.getBudgetCalculationResults()) {
// delete links and lease terms
for (BudgetCalculationResultLink link : budgetCalculationResultLinkRepository.findByCalculationResult(result)) {
LeaseTermForServiceCharge leaseTermToRemove = null;
if (link.getLeaseTermForServiceCharge() != null) {
leaseTermToRemove = link.getLeaseTermForServiceCharge();
}
link.remove();
if (leaseTermToRemove != null) {
leaseTermToRemove.remove();
}
}
}
run.remove();
}
// delete overrides and values
for (Lease lease : leaseRepository.findByAssetAndActiveOnDate(budget.getProperty(), budget.getStartDate())) {
for (BudgetOverride override : budgetOverrideRepository.findByLease(lease)) {
override.remove();
}
}
// delete partition items
for (BudgetItem budgetItem : budget.getItems()) {
for (PartitionItem item : partitionItemRepository.findByBudgetItem(budgetItem)) {
item.remove();
}
}
budget.remove();
}
Aggregations