Example usage for org.apache.commons.collections4 CollectionUtils isNotEmpty

List of usage examples for org.apache.commons.collections4 CollectionUtils isNotEmpty

Introduction

In this page you can find the example usage for org.apache.commons.collections4 CollectionUtils isNotEmpty.

Prototype

public static boolean isNotEmpty(final Collection<?> coll) 

Source Link

Document

Null-safe check if the specified collection is not empty.

Usage

From source file:org.kuali.coeus.common.budget.impl.calculator.AbstractBudgetCalculator.java

/**
 * //from   ww w .  j  a  v a  2 s .  co m
 * This method is for populating the calculated amounts by looking at the rate class and rate type for each line item gets applied to.
 */
@SuppressWarnings("unchecked")
protected void updateBudgetLineItemCalculatedAmounts() {

    List<AbstractBudgetCalculatedAmount> lineItemCalcAmts = budgetLineItem.getBudgetCalculatedAmounts();
    List<BreakUpInterval> cvLIBreakupIntervals = getBreakupIntervals();
    if (lineItemCalcAmts != null && lineItemCalcAmts.size() > 0 && cvLIBreakupIntervals != null
            && cvLIBreakupIntervals.size() > 0) {
        /*
         * Sum up all the calculated costs for each breakup interval and then update the line item cal amts.
         */
        String rateClassCode = "0";
        String rateTypeCode = "0";
        ScaleTwoDecimal totalCalculatedCost = ScaleTwoDecimal.ZERO;
        ScaleTwoDecimal totalCalculatedCostSharing = ScaleTwoDecimal.ZERO;
        ScaleTwoDecimal totalUnderRecovery = ScaleTwoDecimal.ZERO;
        ScaleTwoDecimal directCost = ScaleTwoDecimal.ZERO;
        ScaleTwoDecimal indirectCost = ScaleTwoDecimal.ZERO;
        Equals equalsRC;
        Equals equalsRT;
        And RCandRT = null;
        QueryList<RateAndCost> cvCombinedAmtDetails = new QueryList<RateAndCost>();
        for (BreakUpInterval brkUpInterval : cvLIBreakupIntervals) {
            cvCombinedAmtDetails.addAll(brkUpInterval.getRateAndCosts());
        }
        for (AbstractBudgetCalculatedAmount calculatedAmount : lineItemCalcAmts) {
            rateClassCode = calculatedAmount.getRateClassCode();
            rateTypeCode = calculatedAmount.getRateTypeCode();
            equalsRC = new Equals(RATE_CLASS_CODE, rateClassCode);
            equalsRT = new Equals(RATE_TYPE_CODE, rateTypeCode);
            RCandRT = new And(equalsRC, equalsRT);
            totalCalculatedCost = cvCombinedAmtDetails.sumObjects("calculatedCost", RCandRT);

            calculatedAmount.setCalculatedCost(totalCalculatedCost);

            totalCalculatedCostSharing = cvCombinedAmtDetails.sumObjects("calculatedCostSharing", RCandRT);
            calculatedAmount.setCalculatedCostSharing(totalCalculatedCostSharing);
        }

        /*
         * Sum up all the underRecovery costs for each breakup interval and then update the line item details.
         */
        totalUnderRecovery = new QueryList<BreakUpInterval>(cvLIBreakupIntervals).sumObjects("underRecovery");
        budgetLineItem.setUnderrecoveryAmount(totalUnderRecovery);

        /*
         * Sum up all direct costs ie, rates for RateClassType <> 'O', for each breakup interval plus the line item cost, and
         * then update the line item details.
         */
        NotEquals notEqualsOH = new NotEquals("rateClassType", RateClassType.OVERHEAD.getRateClassType());
        boolean directCostRolledUp = false;
        boolean resetTotalUnderRecovery = false;
        ScaleTwoDecimal newTotalUrAmount = ScaleTwoDecimal.ZERO;
        ScaleTwoDecimal newTotalCostSharing = ScaleTwoDecimal.ZERO;
        if (budgetLineItem instanceof BudgetLineItem && CollectionUtils
                .isNotEmpty(((BudgetLineItem) budgetLineItem).getBudgetPersonnelDetailsList())) {
            for (BudgetPersonnelDetails budgetPersonnelDetail : ((BudgetLineItem) budgetLineItem)
                    .getBudgetPersonnelDetailsList()) {
                List<BudgetPersonnelCalculatedAmount> personnelCalAmts = budgetPersonnelDetail
                        .getBudgetCalculatedAmounts();
                newTotalUrAmount = newTotalUrAmount.add(budgetPersonnelDetail.getUnderrecoveryAmount());
                resetTotalUnderRecovery = true;
                if (CollectionUtils.isNotEmpty(personnelCalAmts)) {
                    for (BudgetPersonnelCalculatedAmount personnelCalAmt : personnelCalAmts) {
                        if (personnelCalAmt.getRateClass() == null) {
                            personnelCalAmt.refreshReferenceObject("rateClass");
                        }
                        if (!personnelCalAmt.getRateClass().getRateClassTypeCode().equals("O")) {
                            directCost = directCost.add(personnelCalAmt.getCalculatedCost());
                        } else {
                            indirectCost = indirectCost.add(personnelCalAmt.getCalculatedCost());

                        }
                        newTotalCostSharing = newTotalCostSharing
                                .add(personnelCalAmt.getCalculatedCostSharing());
                        directCostRolledUp = true;

                    }
                }
            }
        }
        if (resetTotalUnderRecovery) {
            budgetLineItem.setUnderrecoveryAmount(newTotalUrAmount);
        }
        if (!directCostRolledUp) {
            directCost = cvCombinedAmtDetails.sumObjects("calculatedCost", notEqualsOH);
        }
        budgetLineItem.setDirectCost(directCost.add(budgetLineItem.getLineItemCost()));
        /*
         * Sum up all Indirect costs ie, rates for RateClassType = 'O', for each breakup interval and then update the line item
         * details.
         */
        Equals equalsOH = new Equals("rateClassType", RateClassType.OVERHEAD.getRateClassType());
        if (!directCostRolledUp) {
            indirectCost = cvCombinedAmtDetails.sumObjects("calculatedCost", equalsOH);
        }
        budgetLineItem.setIndirectCost(indirectCost);

        /*
         * Sum up all Cost Sharing amounts ie, rates for RateClassType <> 'O' and set in the calculatedCostSharing field of line
         * item details
         */
        if (!directCostRolledUp) {
            totalCalculatedCostSharing = cvCombinedAmtDetails.sumObjects("calculatedCostSharing");
        } else {
            totalCalculatedCostSharing = newTotalCostSharing;
        }

        budgetLineItem.setTotalCostSharingAmount(
                budgetLineItem.getCostSharingAmount() == null ? totalCalculatedCostSharing
                        : budgetLineItem.getCostSharingAmount().add(totalCalculatedCostSharing));

    } else if (lineItemCalcAmts != null && lineItemCalcAmts.size() > 0
            && (budgetLineItem.getLineItemCost().equals(ScaleTwoDecimal.ZERO)
                    || CollectionUtils.isEmpty(cvLIBreakupIntervals))) {
        for (AbstractBudgetCalculatedAmount calculatedAmount : lineItemCalcAmts) {
            calculatedAmount.setCalculatedCost(ScaleTwoDecimal.ZERO);
            calculatedAmount.setCalculatedCostSharing(ScaleTwoDecimal.ZERO);
        }
    }
}

From source file:org.kuali.coeus.common.budget.impl.calculator.AbstractBudgetCalculator.java

private void setLabAllocationSalariesCalculatedAmounts(BudgetLineItemBase lineItem) {
    QueryEngine queryEngine = new QueryEngine();
    queryEngine.addDataCollection(ValidCalcType.class, getValidCalcTypes());

    QueryList<ValidCeRateType> qValidCeRateTypes = createQueryList(
            budgetLineItem.getCostElementBO().getValidCeRateTypes());
    QueryList<ValidCeRateType> qLabAllocSalRates = qValidCeRateTypes
            .filter(equalsLabAllocationSalariesRateClassType());

    if (CollectionUtils.isNotEmpty(qLabAllocSalRates)) {
        List<ValidCalcType> validCalCTypes = queryEngine.executeQuery(ValidCalcType.class,
                equalsEmployeeBenefitsRateClassType());
        if (CollectionUtils.isNotEmpty(validCalCTypes)) {
            ValidCalcType validCalcType = validCalCTypes.get(0);
            if (validCalcType.getDependentRateClassType()
                    .equals(RateClassType.LA_SALARIES.getRateClassType())) {
                addBudgetLineItemCalculatedAmount(validCalcType.getRateClassCode(), validCalcType.getRateType(),
                        validCalcType.getRateClassType());
            }//  w  ww  . j  a va2s.  c  o  m
        }
        validCalCTypes = queryEngine.executeQuery(ValidCalcType.class, equalsVacationRateClassType());
        if (!validCalCTypes.isEmpty()) {
            ValidCalcType validCalcType = (ValidCalcType) validCalCTypes.get(0);
            if (validCalcType.getDependentRateClassType()
                    .equals(RateClassType.LA_SALARIES.getRateClassType())) {
                addBudgetLineItemCalculatedAmount(validCalcType.getRateClassCode(), validCalcType.getRateType(),
                        validCalcType.getRateClassType());
            }
        }
    }
}

From source file:org.kuali.coeus.common.budget.impl.calculator.BudgetCalculationServiceImpl.java

@Override
public void calculateBudgetLineItem(Budget budget, BudgetLineItem budgetLineItem) {
    BudgetLineItem budgetLineItemToCalc = budgetLineItem;
    List<BudgetPersonnelDetails> budgetPersonnelDetList = budgetLineItemToCalc.getBudgetPersonnelDetailsList();
    if (budgetLineItemToCalc.isBudgetPersonnelLineItemDeleted()
            || (budgetPersonnelDetList != null && !budgetPersonnelDetList.isEmpty())) {
        updatePersonnelBudgetRate(budgetLineItemToCalc);
        ScaleTwoDecimal personnelLineItemTotal = ScaleTwoDecimal.ZERO;
        ScaleTwoDecimal personnelTotalCostSharing = ScaleTwoDecimal.ZERO;
        Map<String, ScaleTwoDecimal> totalCalculatedCost = new HashMap<>();
        Map<String, ScaleTwoDecimal> totalCalculatedCostSharing = new HashMap<>();
        ScaleTwoDecimal newTotalUrAmount = ScaleTwoDecimal.ZERO;
        budgetLineItem.getBudgetRateAndBaseList().clear();
        int rateNumber = 0;
        boolean resetTotalUnderRecovery = false;
        ScaleTwoDecimal calcDirectCost = ScaleTwoDecimal.ZERO;
        ScaleTwoDecimal calcIndirectCost = ScaleTwoDecimal.ZERO;
        ScaleTwoDecimal calcTotalCostSharing = ScaleTwoDecimal.ZERO;
        for (BudgetPersonnelDetails budgetPersonnelDetails : budgetPersonnelDetList) {
            copyLineItemToPersonnelDetails(budgetLineItemToCalc, budgetPersonnelDetails);
            new PersonnelLineItemCalculator(budget, budgetPersonnelDetails).calculate();
            personnelLineItemTotal = personnelLineItemTotal.add(budgetPersonnelDetails.getLineItemCost());
            personnelTotalCostSharing = personnelTotalCostSharing
                    .add(budgetPersonnelDetails.getCostSharingAmount());
            newTotalUrAmount = newTotalUrAmount.add(budgetPersonnelDetails.getUnderrecoveryAmount());
            resetTotalUnderRecovery = true;
            List<BudgetPersonnelCalculatedAmount> calAmts = budgetPersonnelDetails.getBudgetCalculatedAmounts();
            if (CollectionUtils.isNotEmpty(calAmts)) {
                String rateKey;/*from  w w w .  j  a v  a  2 s . com*/
                for (BudgetPersonnelCalculatedAmount personnelCalAmt : calAmts) {
                    rateKey = personnelCalAmt.getRateClassCode() + ":" + personnelCalAmt.getRateTypeCode();
                    if (!totalCalculatedCost.containsKey(rateKey)) {
                        totalCalculatedCost.put(rateKey, personnelCalAmt.getCalculatedCost());
                        totalCalculatedCostSharing.put(rateKey, personnelCalAmt.getCalculatedCostSharing());
                    } else {
                        ScaleTwoDecimal value = totalCalculatedCost.get(rateKey);
                        value = value.add(personnelCalAmt.getCalculatedCost());
                        totalCalculatedCost.put(rateKey, value);

                        value = totalCalculatedCostSharing.get(rateKey);
                        value = value.add(personnelCalAmt.getCalculatedCostSharing());
                        totalCalculatedCostSharing.put(rateKey, value);

                    }

                    if (personnelCalAmt.getRateClass() == null) {
                        personnelCalAmt.refreshReferenceObject("rateClass");
                    }
                    if (!personnelCalAmt.getRateClass().getRateClassTypeCode()
                            .equals(RateClassType.OVERHEAD.getRateClassType())) {
                        calcDirectCost = calcDirectCost.add(personnelCalAmt.getCalculatedCost());
                    } else {
                        calcIndirectCost = calcIndirectCost.add(personnelCalAmt.getCalculatedCost());

                    }
                    calcTotalCostSharing = calcTotalCostSharing.add(personnelCalAmt.getCalculatedCostSharing());

                }
            }
            populateRateAndBase(budgetLineItem, budgetPersonnelDetails, rateNumber);
        }
        if (resetTotalUnderRecovery) {
            budgetLineItem.setUnderrecoveryAmount(newTotalUrAmount);
        }
        budgetLineItem.setLineItemCost(personnelLineItemTotal);
        budgetLineItem.setCostSharingAmount(personnelTotalCostSharing);
        budgetLineItem.setDirectCost(calcDirectCost.add(personnelLineItemTotal));
        budgetLineItem.setTotalCostSharingAmount(calcTotalCostSharing.add(personnelTotalCostSharing));
        budgetLineItem.setIndirectCost(calcIndirectCost);

        boolean lineItemCalcAmntsOutOfDate = false;
        if (budgetLineItem.getBudgetCalculatedAmounts().size() == totalCalculatedCost.size()) {
            for (BudgetLineItemCalculatedAmount lineItemCalAmt : budgetLineItem
                    .getBudgetLineItemCalculatedAmounts()) {
                String rateKey = lineItemCalAmt.getRateClassCode() + ":" + lineItemCalAmt.getRateTypeCode();
                if (!totalCalculatedCost.containsKey(rateKey)) {
                    lineItemCalcAmntsOutOfDate = true;
                    break;
                }
            }
        } else {
            lineItemCalcAmntsOutOfDate = true;
        }
        if (lineItemCalcAmntsOutOfDate) {
            rePopulateCalculatedAmount(budget, budgetLineItemToCalc);
        }

        List<BudgetLineItemCalculatedAmount> budgetLineItemCalculatedAmounts = budgetLineItem
                .getBudgetLineItemCalculatedAmounts();
        if (CollectionUtils.isNotEmpty(budgetLineItemCalculatedAmounts)) {
            String rateKey;
            for (BudgetLineItemCalculatedAmount lineItemCalAmt : budgetLineItemCalculatedAmounts) {
                rateKey = lineItemCalAmt.getRateClassCode() + ":" + lineItemCalAmt.getRateTypeCode();
                if (totalCalculatedCost.containsKey(rateKey)) {
                    lineItemCalAmt.setCalculatedCost(totalCalculatedCost.get(rateKey));
                    lineItemCalAmt.setCalculatedCostSharing(totalCalculatedCostSharing.get(rateKey));
                }
            }
        }
    } else {
        new LineItemCalculator(budget, budgetLineItem).calculate();
    }
}

From source file:org.kuali.coeus.common.budget.impl.calculator.BudgetCalculationServiceImpl.java

@Deprecated
@Override//from w  ww .  ja v a  2s . c  o  m
public void calculateBudgetSummaryTotals(Budget budget) {
    calculateBudgetTotals(budget);

    //Categorize all Object Codes per their Category Type
    SortedMap<BudgetCategoryType, List<CostElement>> objectCodeListByBudgetCategoryType = categorizeObjectCodesByCategory(
            budget);

    SortedMap<CostElement, List<BudgetPersonnelDetails>> objectCodeUniquePersonnelList = new TreeMap<>();

    SortedMap<String, List<ScaleTwoDecimal>> objectCodePersonnelSalaryTotals = new TreeMap<>();
    SortedMap<String, List<ScaleTwoDecimal>> objectCodePersonnelFringeTotals = new TreeMap<>();

    //Temp collections for maintaining Sub Section Totals
    SortedSet<String> objectCodePersonnelSalaryTotalsByPeriod = new TreeSet<>();
    SortedSet<String> objectCodePersonnelFringeTotalsByPeriod = new TreeSet<>();

    SortedMap<RateType, List<ScaleTwoDecimal>> personnelCalculatedExpenseTotals = new TreeMap<>();
    SortedMap<RateType, List<ScaleTwoDecimal>> nonPersonnelCalculatedExpenseTotals = new TreeMap<>();

    List<ScaleTwoDecimal> periodSummarySalaryTotals = new ArrayList<>();
    for (int i = 0; i < budget.getBudgetPeriods().size(); i++) {
        periodSummarySalaryTotals.add(i, ScaleTwoDecimal.ZERO);
    }
    List<ScaleTwoDecimal> periodSummaryFringeTotals = new ArrayList<>();
    for (int i = 0; i < budget.getBudgetPeriods().size(); i++) {
        periodSummaryFringeTotals.add(i, ScaleTwoDecimal.ZERO);
    }
    SortedMap<String, List<ScaleTwoDecimal>> subTotalsBySubSection = new TreeMap<>();
    subTotalsBySubSection.put("personnelSalaryTotals", periodSummarySalaryTotals);
    subTotalsBySubSection.put("personnelFringeTotals", periodSummaryFringeTotals);

    //Loop thru the Personnel Object Codes - to calculate Salary, Fringe Totals etc.. per person
    BudgetCategoryType personnelCategory = getPersonnelCategoryType();
    List<CostElement> personnelObjectCodes = objectCodeListByBudgetCategoryType.get(personnelCategory);

    if (CollectionUtils.isNotEmpty(personnelObjectCodes)) {
        for (CostElement personnelCostElement : personnelObjectCodes) {
            if (!objectCodeUniquePersonnelList.containsKey(personnelCostElement)) {
                objectCodeUniquePersonnelList.put(personnelCostElement,
                        new ArrayList<BudgetPersonnelDetails>());
            }

            for (BudgetPeriod budgetPeriod : budget.getBudgetPeriods()) {
                budgetPeriod.setBudget(budget);
                QueryList<BudgetLineItem> lineItemQueryList = new QueryList<>();
                lineItemQueryList.addAll(budgetPeriod.getBudgetLineItems());
                Equals objectCodeEquals = new Equals("costElement", personnelCostElement.getCostElement());
                QueryList<BudgetLineItem> filteredLineItems = lineItemQueryList.filter(objectCodeEquals);
                QueryList<BudgetPersonnelDetails> personnelQueryList = new QueryList<>();

                //Loop thru the matching Line Items to gather personnel info
                for (BudgetLineItem matchingLineItem : filteredLineItems) {
                    personnelQueryList.addAll(matchingLineItem.getBudgetPersonnelDetailsList());
                }

                for (BudgetLineItem matchingLineItem : filteredLineItems) {
                    for (BudgetPersonnelDetails budgetPersonnelDetails : matchingLineItem
                            .getBudgetPersonnelDetailsList()) {
                        Equals personIdEquals = new Equals("personId", budgetPersonnelDetails.getPersonId());
                        QueryList personOccurrencesForSameObjectCode = personnelQueryList
                                .filter(personIdEquals);

                        //Calculate the Salary Totals for each Person
                        ScaleTwoDecimal personSalaryTotalsForCurrentPeriod = personOccurrencesForSameObjectCode
                                .sumObjects("salaryRequested");

                        if (!objectCodePersonnelSalaryTotals.containsKey(matchingLineItem.getCostElement() + ","
                                + budgetPersonnelDetails.getPersonId())) {
                            objectCodeUniquePersonnelList.get(matchingLineItem.getCostElementBO())
                                    .add(budgetPersonnelDetails);
                            // set up for all periods and put into map
                            List<ScaleTwoDecimal> periodTotals = new ArrayList<>();
                            for (int i = 0; i < budget.getBudgetPeriods().size(); i++) {
                                periodTotals.add(i, ScaleTwoDecimal.ZERO);
                            }
                            objectCodePersonnelSalaryTotals.put(matchingLineItem.getCostElement() + ","
                                    + budgetPersonnelDetails.getPersonId(), periodTotals);
                        }
                        //Setting the total lines here - so that they'll be set just once for a unique person within an Object Code
                        objectCodePersonnelSalaryTotals
                                .get(matchingLineItem.getCostElement() + ","
                                        + budgetPersonnelDetails.getPersonId())
                                .set(budgetPeriod.getBudgetPeriod() - 1, personSalaryTotalsForCurrentPeriod);
                        if (objectCodePersonnelSalaryTotalsByPeriod
                                .add(budgetPeriod.getBudgetPeriod().toString() + ","
                                        + matchingLineItem.getCostElement() + ","
                                        + budgetPersonnelDetails.getPersonId())) {
                            subTotalsBySubSection.get("personnelSalaryTotals").set(
                                    budgetPeriod.getBudgetPeriod() - 1,
                                    ((subTotalsBySubSection.get("personnelSalaryTotals")
                                            .get(budgetPeriod.getBudgetPeriod() - 1)))
                                                    .add(personSalaryTotalsForCurrentPeriod));
                        }

                        //Calculate the Fringe Totals for each Person
                        if (!objectCodePersonnelFringeTotals.containsKey(matchingLineItem.getCostElement() + ","
                                + budgetPersonnelDetails.getPersonId())) {
                            // set up for all periods and put into map
                            List<ScaleTwoDecimal> periodFringeTotals = new ArrayList<>();
                            for (int i = 0; i < budget.getBudgetPeriods().size(); i++) {
                                periodFringeTotals.add(i, ScaleTwoDecimal.ZERO);
                            }
                            objectCodePersonnelFringeTotals.put(matchingLineItem.getCostElement() + ","
                                    + budgetPersonnelDetails.getPersonId(), periodFringeTotals);
                        }
                        ScaleTwoDecimal personFringeTotalsForCurrentPeriod = ScaleTwoDecimal.ZERO;
                        //Calculate the Fringe Totals for that Person (cumulative fringe for all occurrences of the person)
                        for (Object person : personOccurrencesForSameObjectCode) {
                            BudgetPersonnelDetails personOccurrence = (BudgetPersonnelDetails) person;
                            for (BudgetPersonnelCalculatedAmount calcExpenseAmount : personOccurrence
                                    .getBudgetPersonnelCalculatedAmounts()) {
                                calcExpenseAmount.refreshReferenceObject("rateClass");
                                //Check for Employee Benefits RateClassType
                                if (calcExpenseAmount.getRateClass().getRateClassTypeCode()
                                        .equalsIgnoreCase("E")) {
                                    personFringeTotalsForCurrentPeriod = personFringeTotalsForCurrentPeriod
                                            .add(calcExpenseAmount.getCalculatedCost());
                                }
                            }
                        }
                        objectCodePersonnelFringeTotals
                                .get(matchingLineItem.getCostElement() + ","
                                        + budgetPersonnelDetails.getPersonId())
                                .set(budgetPeriod.getBudgetPeriod() - 1, personFringeTotalsForCurrentPeriod);

                        if (objectCodePersonnelFringeTotalsByPeriod
                                .add(budgetPeriod.getBudgetPeriod().toString() + ","
                                        + matchingLineItem.getCostElement() + ","
                                        + budgetPersonnelDetails.getPersonId())) {
                            subTotalsBySubSection.get("personnelFringeTotals").set(
                                    budgetPeriod.getBudgetPeriod() - 1,
                                    ((subTotalsBySubSection.get("personnelFringeTotals")
                                            .get(budgetPeriod.getBudgetPeriod() - 1)))
                                                    .add(personFringeTotalsForCurrentPeriod));
                        }
                    }

                    //Need to handle the Summary Items - if any
                    if (CollectionUtils.isEmpty(matchingLineItem.getBudgetPersonnelDetailsList())) {
                        //Include Summary Item Salary (Line Item Cost)
                        if (!objectCodePersonnelSalaryTotals.containsKey(matchingLineItem.getCostElement())) {
                            // set up for all periods and put into map
                            List<ScaleTwoDecimal> periodTotals = new ArrayList<>();
                            for (int i = 0; i < budget.getBudgetPeriods().size(); i++) {
                                periodTotals.add(i, ScaleTwoDecimal.ZERO);
                            }
                            objectCodePersonnelSalaryTotals.put(matchingLineItem.getCostElement(),
                                    periodTotals);
                        }
                        objectCodePersonnelSalaryTotals.get(matchingLineItem.getCostElement()).set(
                                budgetPeriod.getBudgetPeriod() - 1,
                                (objectCodePersonnelSalaryTotals.get(matchingLineItem.getCostElement())
                                        .get(budgetPeriod.getBudgetPeriod() - 1))
                                                .add(matchingLineItem.getLineItemCost()));

                        //Include Summary Item Fringe Amt
                        ScaleTwoDecimal summaryFringeTotalsForCurrentPeriod = ScaleTwoDecimal.ZERO;
                        if (!objectCodePersonnelFringeTotals.containsKey(matchingLineItem.getCostElement())) {
                            // set up for all periods and put into map
                            List<ScaleTwoDecimal> periodFringeTotals = new ArrayList<>();
                            for (int i = 0; i < budget.getBudgetPeriods().size(); i++) {
                                periodFringeTotals.add(i, ScaleTwoDecimal.ZERO);
                            }
                            objectCodePersonnelFringeTotals.put(matchingLineItem.getCostElement(),
                                    periodFringeTotals);
                        }

                        for (BudgetLineItemCalculatedAmount lineItemCalculatedAmount : matchingLineItem
                                .getBudgetLineItemCalculatedAmounts()) {
                            lineItemCalculatedAmount.refreshReferenceObject("rateClass");
                            //Check for Employee Benefits RateClassType
                            if (lineItemCalculatedAmount.getRateClass().getRateClassTypeCode()
                                    .equalsIgnoreCase("E")) {
                                summaryFringeTotalsForCurrentPeriod = summaryFringeTotalsForCurrentPeriod
                                        .add(lineItemCalculatedAmount.getCalculatedCost());
                            }
                        }
                        objectCodePersonnelFringeTotals.get(matchingLineItem.getCostElement()).set(
                                budgetPeriod.getBudgetPeriod() - 1,
                                (objectCodePersonnelFringeTotals.get(matchingLineItem.getCostElement())
                                        .get(budgetPeriod.getBudgetPeriod() - 1))
                                                .add(summaryFringeTotalsForCurrentPeriod));

                        subTotalsBySubSection.get("personnelSalaryTotals").set(
                                budgetPeriod.getBudgetPeriod() - 1,
                                ((subTotalsBySubSection.get("personnelSalaryTotals")
                                        .get(budgetPeriod.getBudgetPeriod() - 1)))
                                                .add((objectCodePersonnelSalaryTotals
                                                        .get(matchingLineItem.getCostElement())
                                                        .get(budgetPeriod.getBudgetPeriod() - 1))));
                        subTotalsBySubSection.get("personnelFringeTotals").set(
                                budgetPeriod.getBudgetPeriod() - 1,
                                ((subTotalsBySubSection.get("personnelFringeTotals")
                                        .get(budgetPeriod.getBudgetPeriod() - 1)))
                                                .add((objectCodePersonnelFringeTotals
                                                        .get(matchingLineItem.getCostElement())
                                                        .get(budgetPeriod.getBudgetPeriod() - 1))));
                    }
                }

            } //Budget Period Looping Ends here
        } //Personnel Object Code Looping Ends here
    }

    budget.setBudgetSummaryTotals(subTotalsBySubSection);
    personnelCalculatedExpenseTotals = calculateExpenseTotals(budget, true);
    nonPersonnelCalculatedExpenseTotals = calculateExpenseTotals(budget, false);

    budget.setObjectCodeListByBudgetCategoryType(objectCodeListByBudgetCategoryType);
    budget.setObjectCodePersonnelList(objectCodeUniquePersonnelList);
    budget.setObjectCodePersonnelSalaryTotals(objectCodePersonnelSalaryTotals);
    budget.setObjectCodePersonnelFringeTotals(objectCodePersonnelFringeTotals);
    budget.setPersonnelCalculatedExpenseTotals(personnelCalculatedExpenseTotals);
    budget.setNonPersonnelCalculatedExpenseTotals(nonPersonnelCalculatedExpenseTotals);
    calculateNonPersonnelSummaryTotals(budget);
    populateBudgetPeriodSummaryCalcAmounts(budget);
}

From source file:org.kuali.coeus.common.budget.impl.calculator.LineItemCalculator.java

private Map<String, Boolean> saveApplyRateFlagsForReset() {
    Map<String, Boolean> applyRateFlags = new HashMap<String, Boolean>();
    if (bli != null && CollectionUtils.isNotEmpty(bli.getBudgetLineItemCalculatedAmounts())) {
        for (BudgetLineItemCalculatedAmount budgetLineItemCalculatedAmount : bli
                .getBudgetLineItemCalculatedAmounts()) {
            applyRateFlags.put(/* w ww .j  a va 2  s.  c  o  m*/
                    budgetLineItemCalculatedAmount.getRateClassCode()
                            + budgetLineItemCalculatedAmount.getRateTypeCode(),
                    budgetLineItemCalculatedAmount.getApplyRateFlag());
        }
    }

    return applyRateFlags;
}

From source file:org.kuali.coeus.common.budget.impl.calculator.LineItemCalculator.java

public void populateCalculatedAmountLineItems() {
    if (bli.getBudgetLineItemCalculatedAmounts().size() <= 0) {
        setCalculatedAmounts(budget, bli);
    }/*w  w  w.j a va  2  s. com*/

    if (getBudgetRateService().performSyncFlag(budget)) {
        Long versionNumber = null;
        if (CollectionUtils.isNotEmpty(bli.getBudgetLineItemCalculatedAmounts())) {
            versionNumber = bli.getBudgetLineItemCalculatedAmounts().get(0).getVersionNumber();
        }
        //Save applyRateFlag to set it back on the new Calculated Amounts
        Map<String, Boolean> applyRateFlags = saveApplyRateFlagsForReset();

        bli.setBudgetLineItemCalculatedAmounts(new ArrayList<BudgetLineItemCalculatedAmount>());

        setCalculatedAmounts(budget, bli);

        for (BudgetLineItemCalculatedAmount budgetLineItemCalculatedAmount : bli
                .getBudgetLineItemCalculatedAmounts()) {
            if (versionNumber != null) {
                budgetLineItemCalculatedAmount.setVersionNumber(versionNumber);
            }

            if (applyRateFlags != null && applyRateFlags.get(budgetLineItemCalculatedAmount.getRateClassCode()
                    + budgetLineItemCalculatedAmount.getRateTypeCode()) != null) {
                budgetLineItemCalculatedAmount
                        .setApplyRateFlag(applyRateFlags.get(budgetLineItemCalculatedAmount.getRateClassCode()
                                + budgetLineItemCalculatedAmount.getRateTypeCode()));
            }
        }
    }

}

From source file:org.kuali.coeus.common.budget.impl.calculator.PersonnelLineItemCalculator.java

private Map<String, Boolean> saveApplyRateFlagsForReset() {
    Map<String, Boolean> applyRateFlags = new HashMap<String, Boolean>();
    if (budgetPersonnelLineItem != null
            && CollectionUtils.isNotEmpty(budgetPersonnelLineItem.getBudgetPersonnelCalculatedAmounts())) {
        for (BudgetPersonnelCalculatedAmount budgetPersonnelCalculatedAmount : budgetPersonnelLineItem
                .getBudgetPersonnelCalculatedAmounts()) {
            applyRateFlags.put(// ww w .  j a va2  s  . c  om
                    budgetPersonnelCalculatedAmount.getRateClassCode()
                            + budgetPersonnelCalculatedAmount.getRateTypeCode(),
                    budgetPersonnelCalculatedAmount.getApplyRateFlag());
        }
    }

    return applyRateFlags;
}

From source file:org.kuali.coeus.common.budget.impl.core.AbstractBudgetService.java

@Override
public String getActivityTypeForBudget(Budget budget) {
    BudgetParent budgetParent = budget.getBudgetParent().getDocument().getBudgetParent();
    Map<String, Object> qMap = new HashMap<String, Object>();
    qMap.put(BUDGET_ID, budget.getBudgetId());
    List<BudgetRate> allPropRates = (List<BudgetRate>) businessObjectService.findMatching(BudgetRate.class,
            qMap);//from  www.ja v a2 s . c o m
    if (CollectionUtils.isNotEmpty(allPropRates)) {
        qMap.put(ACTIVITY_TYPE_CODE, budgetParent.getActivityTypeCode());
        Collection<BudgetRate> matchActivityTypePropRates = businessObjectService.findMatching(BudgetRate.class,
                qMap);
        if (CollectionUtils.isNotEmpty(matchActivityTypePropRates)) {
            for (BudgetRate budgetRate : allPropRates) {
                if (!budgetRate.getActivityTypeCode().equals(budgetParent.getActivityTypeCode())) {
                    return budgetRate.getActivityTypeCode();
                }
            }
            return budgetParent.getActivityTypeCode();
        } else {
            return allPropRates.get(0).getActivityTypeCode();
        }
    }

    return "x";

}

From source file:org.kuali.coeus.common.budget.impl.nonpersonnel.BudgetExpenseRule.java

@KcEventMethod
public boolean processCheckExistBudgetPersonnelDetailsBusinessRules(DeleteBudgetLineItemEvent event) {
    boolean valid = true;

    MessageMap errorMap = getGlobalVariableService().getMessageMap();
    if (CollectionUtils.isNotEmpty(event.getBudgetLineItem().getBudgetPersonnelDetailsList())) {
        // just try to make sure key is on budget personnel tab
        errorMap.putError(event.getErrorPath() + COST_ELEMENT, KeyConstants.ERROR_DELETE_LINE_ITEM);
        valid = false;/*  w  w w .  j  a v a  2  s . c o m*/
    }

    return valid;
}

From source file:org.kuali.coeus.common.budget.impl.period.BudgetPeriodRule.java

private boolean isValidToInsert(Budget budget, BudgetPeriod newBudgetPeriod, String errorPathPrefix) {

    int expenseExistStatus = checkExpenseInBudget(budget);
    MessageMap errorMap = GlobalVariables.getMessageMap();
    if (CollectionUtils.isNotEmpty(budget.getBudgetPeriods())) {
        if (newBudgetPeriod.getEndDate().before(budget.getBudgetPeriod(0).getStartDate())) {
            // insert before 1st period
            if (expenseExistStatus >= 1) {
                errorMap.putError(errorPathPrefix, KeyConstants.ERROR_INSERT_BUDGET_PERIOD);
                return false;
            }/*w w  w  . j ava  2  s  . c o m*/
        } else if (newBudgetPeriod.getEndDate()
                .before(budget.getBudgetPeriod(budget.getBudgetPeriods().size() - 1).getStartDate())
                && expenseExistStatus > 1) {
            errorMap.putError(errorPathPrefix, KeyConstants.ERROR_INSERT_BUDGET_PERIOD);
            return false;
        }
    }
    return true;
}