Exemple #1
0
 public ActionForward delete(
     ActionMapping mapping,
     ActionForm form,
     HttpServletRequest request,
     HttpServletResponse response)
     throws Exception {
   BudgetForm budgetForm = (BudgetForm) form;
   AwardBudgetDocument awardBudgetDocument = budgetForm.getBudgetDocument();
   int selectedLineNumber = getSelectedLine(request);
   BudgetSubAwards subAward =
       awardBudgetDocument.getBudget().getBudgetSubAwards().get(selectedLineNumber);
   for (BudgetPeriod period : awardBudgetDocument.getBudget().getBudgetPeriods()) {
     Iterator<BudgetLineItem> iter = period.getBudgetLineItems().iterator();
     while (iter.hasNext()) {
       BudgetLineItem item = iter.next();
       if (org.apache.commons.lang3.ObjectUtils.equals(
           subAward.getSubAwardNumber(), item.getSubAwardNumber())) {
         iter.remove();
       }
     }
   }
   awardBudgetDocument.getBudget().getBudgetSubAwards().remove(selectedLineNumber);
   Collections.sort(awardBudgetDocument.getBudget().getBudgetSubAwards());
   return mapping.findForward(Constants.MAPPING_BASIC);
 }
 protected List<BudgetLineItem> findLineItemsByCostElement(
     List<BudgetLineItem> lineItems, String costElement) {
   List<BudgetLineItem> lineItemsFound = new ArrayList<>();
   for (BudgetLineItem lineItem : lineItems) {
     if (StringUtils.equals(lineItem.getCostElement(), costElement)
         && ObjectUtils.equals(lineItem.getSubAwardNumber(), subAward.getSubAwardNumber())) {
       lineItemsFound.add(lineItem);
     }
   }
   return lineItemsFound;
 }
 protected void assertExpectedResults(List<Map<String, ScaleTwoDecimal>> results) {
   int index = 0;
   for (BudgetPeriod period : budget.getBudgetPeriods()) {
     for (BudgetLineItem lineItem : period.getBudgetLineItems()) {
       Assert.assertEquals(subAward.getSubAwardNumber(), lineItem.getSubAwardNumber());
       Assert.assertEquals(
           results.get(index).get(lineItem.getCostElement()), lineItem.getLineItemCost());
     }
     for (Map.Entry<String, ScaleTwoDecimal> entry : results.get(index).entrySet()) {
       final List<BudgetLineItem> lineItemsByCostElement =
           findLineItemsByCostElement(period.getBudgetLineItems(), entry.getKey());
       if (entry.getValue().isZero()) {
         Assert.assertTrue(lineItemsByCostElement.size() == 0);
       } else {
         Assert.assertEquals(entry.getValue(), lineItemsByCostElement.get(0).getLineItemCost());
       }
     }
     index++;
   }
 }