List of usage examples for java.sql Date before
public boolean before(Date when)
From source file:org.kuali.kra.award.timeandmoney.AwardDirectFandADistributionRuleImpl.java
/** * This is a helper method for doTargetDatesFallWithinOpenPeriod. */// ww w .jav a 2s .com boolean doDateRangesOverlap(AwardDirectFandADistribution testAwardDirectFandADistribution, AwardDirectFandADistribution thisAwardDirectFandADistribution) { Date testStartDate = testAwardDirectFandADistribution.getStartDate(); Date testEndDate = testAwardDirectFandADistribution.getEndDate(); Date startDate = thisAwardDirectFandADistribution.getStartDate(); Date endDate = thisAwardDirectFandADistribution.getEndDate(); return startDate.before(testEndDate) && startDate.after(testStartDate) || endDate.after(testStartDate) && endDate.before(testEndDate); }
From source file:org.kuali.kra.award.timeandmoney.AwardDirectFandADistributionRuleImpl.java
/** * This method tests if target end date falls before project end date. *///from w w w . j ava2 s . c o m boolean isTargetEndDatePriorToProjectEndDate( AwardDirectFandADistributionRuleEvent awardDirectFandADistributionRuleEvent) { Date targetEndDate = awardDirectFandADistribution.getEndDate(); //Date projectEndDate = awardDirectFandADistributionRuleEvent.getTimeAndMoneyDocument().getAward().getProjectEndDate(); Date projectEndDate = getAwardAmountInfoService().fetchAwardAmountInfoWithHighestTransactionId( awardDirectFandADistributionRuleEvent.getTimeAndMoneyDocument().getAward().getAwardAmountInfos()) .getFinalExpirationDate(); boolean valid = true; if (projectEndDate.before(targetEndDate)) { valid = false; reportError(NEW_AWARD_DIRECT_FNA_DISTRIBUTION + INVALID_TARGET_END_DATE, KeyConstants.ERROR_TARGET_END_DATE); } return valid; }
From source file:org.kuali.kra.budget.parameters.BudgetPeriodRule.java
private boolean isValidNewBudgetPeriod(Budget budget, BudgetPeriod newBudgetPeriod) { ErrorMap errorMap = GlobalVariables.getErrorMap(); boolean validNewBudgetPeriod = true; List<BudgetPeriod> budgetPeriods = budget.getBudgetPeriods(); Date previousPeriodStartDate = null; Date previousPeriodEndDate = null; Date periodStartDate = null;// ww w . ja va 2s . c o m Date periodEndDate = null; Date newPeriodStartDate = null; Date newPeriodEndDate = null; int index = 0; /* check new budget period */ newPeriodStartDate = newBudgetPeriod.getStartDate(); newPeriodEndDate = newBudgetPeriod.getEndDate(); errorMap.addToErrorPath(NEW_BUDGET_PERIOD); if (newPeriodStartDate == null) { saveErrors("ERROR_PERIOD_START_REQUIRED", errorMap); validNewBudgetPeriod = false; } if (newPeriodEndDate == null) { saveErrors("ERROR_PERIOD_END_REQUIRED", errorMap); validNewBudgetPeriod = false; } errorMap.removeFromErrorPath(NEW_BUDGET_PERIOD); /* if dates are valid, check further where we can insert this new date */ if (validNewBudgetPeriod) { int totalBudgetPeriods = budgetPeriods.size() - 1; errorMap.addToErrorPath(NEW_BUDGET_PERIOD); for (BudgetPeriod budgetPeriod : budgetPeriods) { Date validDateBefore; periodStartDate = budgetPeriod.getStartDate(); periodEndDate = budgetPeriod.getEndDate(); String dateCompareValue = null; /* check first record */ if (previousPeriodStartDate == null) { validDateBefore = projectStartDate; } else { validDateBefore = previousPeriodEndDate; } /* check if entered new period already exists in budget periods list */ int periodNum = index; String[] newPeriodDateParams = { periodNum + "", periodNum + 1 + "" }; String invalidErrorMessage = null; setErrorParameter(newPeriodDateParams); if (index == 0 || index == totalBudgetPeriods) { invalidErrorMessage = "ERROR_NEW_PERIOD_INVALID"; } else { invalidErrorMessage = "ERROR_NEW_PERIOD_VALID"; } if ((newPeriodStartDate.compareTo(periodStartDate) == 0) || (newPeriodEndDate.compareTo(periodEndDate) == 0)) { saveErrors(invalidErrorMessage, errorMap); validNewBudgetPeriod = false; break; } else if (newPeriodStartDate.before(periodStartDate) || (index == totalBudgetPeriods && newPeriodStartDate.after(periodEndDate))) { /* check if new period start date is before current period start date */ boolean lastRecord = false; if (index == totalBudgetPeriods) { lastRecord = true; if (newPeriodStartDate.after(periodEndDate)) { periodNum = index + 1; } } /* check new budget period */ if (newPeriodStartDate.before(getProjectStartDate())) { dateCompareValue = "ERROR_PERIOD_START_BEFORE_PROJECT_START"; } else if (newPeriodStartDate.after(getProjectEndDate())) { dateCompareValue = "ERROR_NEW_PERIOD_START_AFTER_PROJECT_END"; } else if (newPeriodEndDate.after(getProjectEndDate())) { dateCompareValue = "ERROR_NEW_PERIOD_END_DATE"; } else if (newPeriodStartDate.before(validDateBefore)) { dateCompareValue = invalidErrorMessage; } else if ((index < totalBudgetPeriods) && newPeriodEndDate.after(periodStartDate)) { if (!lastRecord) { dateCompareValue = invalidErrorMessage; } else { dateCompareValue = "ERROR_NEW_PERIOD_PROJECT_END"; } } if (dateCompareValue != null) { saveErrors(dateCompareValue, errorMap); validNewBudgetPeriod = false; } else { newBudgetPeriod.setBudgetPeriod(periodNum + 1); } break; } previousPeriodStartDate = budgetPeriod.getStartDate(); previousPeriodEndDate = budgetPeriod.getEndDate(); index++; } errorMap.removeFromErrorPath(NEW_BUDGET_PERIOD); } return validNewBudgetPeriod; }
From source file:org.kuali.kra.budget.parameters.BudgetPeriodRule.java
private String compareDate(Date periodStartDate, Date periodEndDate, Date previousPeriodEndDate) { String returnErrorValue = null; LOG.info("prd st dt " + periodStartDate.getTime() + periodEndDate.getTime() + getProjectStartDate().getTime() + getProjectEndDate().getTime()); if (periodStartDate.after(getProjectEndDate())) { LOG.info("ERROR_PERIOD_START_AFTER_PROJECT_END" + periodStartDate + getProjectEndDate()); returnErrorValue = "ERROR_PERIOD_START_AFTER_PROJECT_END"; } else if (periodStartDate.before(getProjectStartDate())) { LOG.info("ERROR_PERIOD_START_BEFORE_PROJECT_START" + periodStartDate + getProjectStartDate()); returnErrorValue = "ERROR_PERIOD_START_BEFORE_PROJECT_START"; } else if (periodEndDate.before(getProjectStartDate())) { LOG.info("ERROR_PERIOD_END_BEFORE_PROJECT_START" + periodEndDate + getProjectStartDate()); returnErrorValue = "ERROR_PERIOD_END_BEFORE_PROJECT_START"; } else if (periodEndDate.after(getProjectEndDate())) { LOG.info("ERROR_PERIOD_END_AFTER_PROJECT_END" + periodEndDate + getProjectEndDate()); returnErrorValue = "ERROR_PERIOD_END_AFTER_PROJECT_END"; } else if (periodStartDate.after(periodEndDate)) { LOG.info("ERROR_PERIOD_START_AFTER_PERIOD_END" + periodStartDate + periodEndDate); returnErrorValue = "ERROR_PERIOD_START_AFTER_PERIOD_END"; } else if (previousPeriodEndDate != null && !periodStartDate.after(previousPeriodEndDate)) { LOG.info("ERROR_PERIOD_START_BEFORE_PREVIOUS_END" + previousPeriodEndDate + periodStartDate); returnErrorValue = "ERROR_PERIOD_START_BEFORE_PREVIOUS_END"; } else if (previousPeriodEndDate != null && !periodEndDate.after(previousPeriodEndDate)) { LOG.info("ERROR_PERIOD_END_BEFORE_PREVIOUS_END" + previousPeriodEndDate + periodEndDate); returnErrorValue = "ERROR_PERIOD_END_BEFORE_PREVIOUS_END"; }/*from ww w . j av a2 s. c o m*/ return returnErrorValue; }
From source file:org.kuali.kra.budget.printing.xmlstream.BudgetBaseStream.java
/** * This method sets reportType to ReportTypeList for BudgetLASalary and get * sum of fringe, calculatedCost, calculatedCostSharing and salary by * grouping reportType based on budgetLASalaryKey * /*from w ww . j a v a 2s .co m*/ * @param reportTypeList * @param reportTypeVOList */ protected void setReportTypeBudgetLASalary(List<ReportType> reportTypeList, List<ReportTypeVO> reportTypeVOList) { Map<String, ReportTypeVO> reportTypeMap = new HashMap<String, ReportTypeVO>(); for (ReportTypeVO reportTypeVO : reportTypeVOList) { String budgetLASalaryKey = reportTypeVO.getCostElementDesc(); if (reportTypeMap.containsKey(budgetLASalaryKey)) { continue; } Date startDate = reportTypeVO.getStartDate(); Date endDate = reportTypeVO.getEndDate(); BudgetDecimal fringe = BudgetDecimal.ZERO; BudgetDecimal calculatedCost = BudgetDecimal.ZERO; BudgetDecimal calculatedCostSharing = BudgetDecimal.ZERO; BudgetDecimal salary = BudgetDecimal.ZERO; for (ReportTypeVO tempReportTypeVO : reportTypeVOList) { String budgetLASalaryTempKey = tempReportTypeVO.getCostElementDesc(); if (budgetLASalaryTempKey.equals(budgetLASalaryKey)) { if (startDate.after(tempReportTypeVO.getStartDate())) { startDate = tempReportTypeVO.getStartDate(); } if (endDate.before(tempReportTypeVO.getEndDate())) { endDate = tempReportTypeVO.getEndDate(); } fringe = fringe.add(tempReportTypeVO.getFringe()); calculatedCost = calculatedCost.add(tempReportTypeVO.getCalculatedCost()); calculatedCostSharing = calculatedCostSharing.add(tempReportTypeVO.getCostSharingAmount()); salary = salary.add(tempReportTypeVO.getSalaryRequested()); } } ReportType reportType = getReportTypeForLASalary(fringe, salary, calculatedCost, calculatedCostSharing, reportTypeVO, startDate, endDate); reportTypeList.add(reportType); reportTypeMap.put(budgetLASalaryKey, reportTypeVO); } }
From source file:org.kuali.kra.budget.printing.xmlstream.BudgetBaseStream.java
/** * This method set reportTypeMap from reportTypeVOList by grouping based on * reportTypeKey and get sum of salaryRequested, calculatedCost, first * startDate, last endDate//from ww w .j a v a2 s.c o m * * @param tempReportTypeVOList * @param reportTypeMap */ protected void setReportTypeMapFromReportTypeVOList(List<ReportTypeVO> tempReportTypeVOList, Map<String, ReportType> reportTypeMap) { for (ReportTypeVO reportTypeVO : tempReportTypeVOList) { String reportTypeKey = getKeyForRateBase(reportTypeVO); if (reportTypeMap.containsKey(reportTypeKey)) { continue; } Date startDate = reportTypeVO.getStartDate(); Date endDate = reportTypeVO.getEndDate(); BudgetDecimal calculatedCost = BudgetDecimal.ZERO; BudgetDecimal salaryRequested = BudgetDecimal.ZERO; for (ReportTypeVO tempReportTypeVO : tempReportTypeVOList) { String reportTypeTempKey = getKeyForRateBase(tempReportTypeVO); if (reportTypeTempKey.equals(reportTypeKey)) { salaryRequested = salaryRequested.add(tempReportTypeVO.getSalaryRequested()); calculatedCost = calculatedCost.add(tempReportTypeVO.getCalculatedCost()); if (startDate.after(tempReportTypeVO.getStartDate())) { startDate = tempReportTypeVO.getStartDate(); } if (endDate.before(tempReportTypeVO.getEndDate())) { endDate = tempReportTypeVO.getEndDate(); } } } ReportType reportType = getReportTypeForRateAndBase(startDate, endDate, calculatedCost, salaryRequested, reportTypeVO); reportTypeMap.put(reportTypeKey, reportType); } }
From source file:org.kuali.kra.budget.printing.xmlstream.BudgetBaseStream.java
/** * This method set reportTypeMap for BudgetOHRateAndBase by grouping based * on budgetOHRateBaseKey and get sum of salaryRequested, calculatedCost, * first startDate, last endDate/* w w w . jav a 2 s .co m*/ * * @param tempReportTypeVOList * @param reportTypeMap */ protected void setReportTypeMapForBudgetOHRateAndBase(List<ReportTypeVO> tempReportTypeVOList, Map<String, ReportType> reportTypeMap) { for (ReportTypeVO reportTypeVO : tempReportTypeVOList) { String budgetOHRateBaseKey = getKeyForBudgetOHRateBase(reportTypeVO); if (reportTypeMap.containsKey(budgetOHRateBaseKey)) { continue; } Date startDate = reportTypeVO.getStartDate(); Date endDate = reportTypeVO.getEndDate(); BudgetDecimal calculatedCost = BudgetDecimal.ZERO; BudgetDecimal salaryRequested = BudgetDecimal.ZERO; for (ReportTypeVO tempReportTypeVO : tempReportTypeVOList) { String budgetOHRateBaseTempKey = getKeyForBudgetOHRateBase(tempReportTypeVO); if (budgetOHRateBaseTempKey.equals(budgetOHRateBaseKey)) { salaryRequested = salaryRequested .add(tempReportTypeVO.getSalaryRequested() == null ? BudgetDecimal.ZERO : tempReportTypeVO.getSalaryRequested()); calculatedCost = calculatedCost.add(tempReportTypeVO.getCalculatedCost()); if (startDate.after(tempReportTypeVO.getStartDate())) { startDate = tempReportTypeVO.getStartDate(); } if (endDate.before(tempReportTypeVO.getEndDate())) { endDate = tempReportTypeVO.getEndDate(); } } } ReportType reportType = getReportTypeForBudgetOHRateAndBase(startDate, endDate, calculatedCost, salaryRequested, reportTypeVO); reportTypeMap.put(budgetOHRateBaseKey, reportType); } }
From source file:org.kuali.kra.budget.rates.BudgetRatesServiceImpl.java
@SuppressWarnings("unchecked") protected void getApplicableRates(Budget budget, Collection allRates, Collection filteredRates, Date personSalaryEffectiveDate) { List<AbstractInstituteRate> allAbstractInstituteRates = (List<AbstractInstituteRate>) allRates; Map<String, AbstractInstituteRate> instRates = new HashMap<String, AbstractInstituteRate>(); for (AbstractInstituteRate instituteRate : allAbstractInstituteRates) { Date rateStartDate = instituteRate.getStartDate(); Date rateEffectiveDate = getRateEffectiveStartDate(budget, instituteRate, personSalaryEffectiveDate); if (rateStartDate.before(rateEffectiveDate)) { String hKey = generateThreePartKey(instituteRate); AbstractInstituteRate instRate = instRates.get(hKey); if ((instRate != null) && (instRate.getStartDate().compareTo(rateStartDate) <= 0)) { Date currentStartDate = instRate.getStartDate(); if (currentStartDate.compareTo(rateStartDate) <= 0) { instRates.remove(hKey); }//from w ww . ja va2s . com } if (!instRates.keySet().contains(hKey)) { instRates.put(hKey, instituteRate); } } } filteredRates.addAll(instRates.values()); }
From source file:org.kuali.kra.budget.summary.BudgetSummaryServiceImpl.java
/** * /*from w w w .ja v a2s. co m*/ * This method is to be shared by adjusting dates for budgetperiod->lineitem and lineitem->personnellineitem * refer to jira-1376 for rules * @param parentStartDate * @param oldStartDate * @param parentEndDate * @param startEndDates * @return */ protected List<Date> getNewStartEndDates(Date parentStartDate, Date oldStartDate, Date parentEndDate, Date oldEndDate, List<Date> startEndDates) { Date startDate = startEndDates.get(0); Date endDate = startEndDates.get(1); Date newStartDate = startDate; Date newEndDate = endDate; if (startDate.compareTo(oldStartDate) == 0 && endDate.compareTo(oldEndDate) == 0) { // if initiall, both are matching, then keep matching. newStartDate = parentStartDate; newEndDate = parentEndDate; } else { // duration has priority over child start date relative to parent start date if (parentStartDate.compareTo(oldStartDate) != 0) { // keep the gap between child start date and parent start date newStartDate = add(newStartDate, KraServiceLocator.getService(DateTimeService.class) .dateDiff(oldStartDate, parentStartDate, false)); if (newStartDate.after(parentEndDate)) { newStartDate = parentStartDate; } else { if (newStartDate.after(parentStartDate)) { // keep the duration, but the item start date relative to period start date is not maintained. int parentDuration = KraServiceLocator.getService(DateTimeService.class) .dateDiff(parentStartDate, parentEndDate, false); int duration = KraServiceLocator.getService(DateTimeService.class).dateDiff(startDate, endDate, false); int daysTOEndDate = KraServiceLocator.getService(DateTimeService.class) .dateDiff(newStartDate, parentEndDate, false); if (daysTOEndDate < duration) { if (parentDuration > duration) { newEndDate = parentEndDate; newStartDate = add(newEndDate, duration * (-1)); } else { // can't keep duration because parent duration is smaller than child initial duration newStartDate = parentStartDate; } } } } newEndDate = add(newStartDate, KraServiceLocator.getService(DateTimeService.class).dateDiff(startDate, endDate, false)); if (newEndDate.after(parentEndDate)) { newEndDate = parentEndDate; } } else { // end date changed if (parentEndDate.compareTo(oldStartDate) != 0 && parentEndDate.before(endDate)) { if (parentEndDate.after(startDate) && parentEndDate.before(endDate)) { newEndDate = parentEndDate; // try to keep duration newStartDate = add(newEndDate, KraServiceLocator.getService(DateTimeService.class) .dateDiff(endDate, startDate, false)); if (newStartDate.before(parentStartDate)) { newStartDate = parentStartDate; } } else { if (parentEndDate.before(startDate)) { newStartDate = parentStartDate; newEndDate = add(newStartDate, KraServiceLocator.getService(DateTimeService.class) .dateDiff(startDate, endDate, false)); if (newEndDate.after(parentEndDate)) { newEndDate = parentEndDate; } } } } } } startEndDates.clear(); startEndDates.add(0, newStartDate); startEndDates.add(1, newEndDate); return startEndDates; }
From source file:org.kuali.kra.budget.summary.BudgetSummaryServiceImpl.java
public List<Date> getNewStartEndDates(List<Date> startEndDates, int gap, int duration, Date prevDate, boolean leapDayInPeriod, boolean leapDayInGap) { // duration is < (enddate - start date) Date startDate = startEndDates.get(0); Date endDate = startEndDates.get(1); Date newStartDate = startDate; Date newEndDate = endDate; boolean endDateAdjusted = false; if (gap == 0) { newEndDate = add(startDate, duration); ;//from ww w . j a va 2 s .c o m } else { // keep the gap between child start date and parent start date newStartDate = add(startDate, gap); newEndDate = add(newStartDate, duration); ; if (newStartDate.after(endDate)) { newStartDate = startDate; newEndDate = add(startDate, duration); } else if (newEndDate.after(endDate)) { endDateAdjusted = true; newEndDate = endDate; newStartDate = add(endDate, duration * (-1)); } } boolean isLeapDayInNewGap = isLeapDaysInPeriod(startDate, newStartDate); startEndDates.clear(); if (leapDayInGap && !endDateAdjusted) { if (newStartDate.after(startDate)) { // shift non-leap year date newStartDate = add(newStartDate, -1); newEndDate = add(newEndDate, -1); } } else if (isLeapDayInNewGap) { if (newEndDate.before(endDate)) { // shift leap year date newStartDate = add(newStartDate, 1); newEndDate = add(newEndDate, 1); } } boolean isLeapDayInNewPeriod = isLeapDaysInPeriod(newStartDate, newEndDate); if (leapDayInPeriod && !isLeapDayInNewPeriod) { newEndDate = add(newEndDate, -1); } else if (!leapDayInPeriod && isLeapDayInNewPeriod) { if (endDate.after(newEndDate)) { newEndDate = add(newEndDate, 1); } else if (startDate.before(newStartDate)) { newStartDate = add(newStartDate, 1); } } startEndDates.add(0, newStartDate); startEndDates.add(1, newEndDate); return startEndDates; }