List of usage examples for java.sql Date after
public boolean after(Date when)
From source file:org.kuali.kra.budget.calculator.AbstractBudgetCalculator.java
/** * Use the combined & sorted Prop & LA rates to create Boundary objects. Each Boundary will contain start date & end date. Check * whether any rate changes, and break at this point to create a new boundary. * // w w w .java 2 s . c o m * @return List of boundary objects */ public List<Boundary> createBreakupBoundaries(QueryList<AbstractBudgetRate> qlCombinedRates, Date liStartDate, Date liEndDate) { List<Boundary> boundaries = new ArrayList<Boundary>(); if (qlCombinedRates != null && qlCombinedRates.size() > 0) { Date tempStartDate = liStartDate; Date tempEndDate = liEndDate; Date rateChangeDate; GreaterThan greaterThan = new GreaterThan("startDate", liStartDate); qlCombinedRates = qlCombinedRates.filter(greaterThan); qlCombinedRates.sort("startDate", true); for (AbstractBudgetRate laRate : qlCombinedRates) { rateChangeDate = laRate.getStartDate(); if (rateChangeDate.after(tempStartDate)) { Calendar temEndCal = dateTimeService.getCalendar(rateChangeDate); temEndCal.add(Calendar.DAY_OF_MONTH, -1); try { tempEndDate = dateTimeService.convertToSqlDate(temEndCal.get(Calendar.YEAR) + "-" + (temEndCal.get(Calendar.MONTH) + 1) + "-" + temEndCal.get(Calendar.DAY_OF_MONTH)); } catch (ParseException e) { tempEndDate = new Date(rateChangeDate.getTime() - 86400000); } Boundary boundary = new Boundary(tempStartDate, tempEndDate); boundaries.add(boundary); tempStartDate = rateChangeDate; } } /** * add one more boundary if no rate change on endDate and atleast one boundary is present */ if (boundaries.size() > 0) { Boundary boundary = new Boundary(tempStartDate, liEndDate); boundaries.add(boundary); } /** * if no rate changes during the period create one boundary with startDate & endDate same as that for line item */ if (boundaries.size() == 0) { Boundary boundary = new Boundary(liStartDate, liEndDate); boundaries.add(boundary); } } return boundaries; }
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;/* w ww . j a v a 2 s.com*/ 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 w w w.java 2 s . c o m return returnErrorValue; }
From source file:org.kuali.kra.budget.personnel.BudgetPersonnelBudgetServiceImpl.java
public void calculateBudgetPersonnelBudget(Budget budget, BudgetLineItem selectedBudgetLineItem, BudgetPersonnelDetails budgetPersonnelDetails, int lineNumber) { copyLineItemToPersonnelDetails(selectedBudgetLineItem, budgetPersonnelDetails); budgetCalculationService.calculateBudgetLineItem(budget, budgetPersonnelDetails); // error message if effective data is out of range if (budgetPersonnelDetails.getSalaryRequested().equals(BudgetDecimal.ZERO)) { int budgetPeriodNumber = budgetPersonnelDetails.getBudgetPeriod() - 1; BudgetPeriod budgetPeriod = budget.getBudgetPeriod(budgetPeriodNumber); Date personEffectiveDate = budgetPersonnelDetails.getBudgetPerson().getEffectiveDate(); if (personEffectiveDate.after(budgetPeriod.getEndDate())) { ErrorMap errorMap = GlobalVariables.getErrorMap(); // salaryrequested is hidden field, so use person errorMap.putError(//from w w w. j av a2 s . com "document.budgetPeriod[" + budgetPeriodNumber + "].budgetLineItems[" + budgetPeriodNumber + "].budgetPersonnelDetailsList[" + lineNumber + "].personSequenceNumber", KeyConstants.ERROR_EFFECTIVE_DATE_OUT_OF_RANGE, new String[] { budgetPersonnelDetails.getBudgetPerson().getPersonName() }); } } }
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 www . j av a2 s. c o 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// ww w. j av a2 s. co 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//from w ww . j a v a2 s .c om * * @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.summary.BudgetSummaryServiceImpl.java
/** * /*from w w w. j a va2s. c o 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;/* ww w. jav a2 s . c om*/ boolean endDateAdjusted = false; if (gap == 0) { newEndDate = add(startDate, duration); ; } 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; }
From source file:org.kuali.kra.committee.bo.Committee.java
private boolean isChairPerson(CommitteeMembership committeeMembership) { boolean isChairRoleFound = false; Date currentDate = DateUtils.clearTimeFields(new Date(System.currentTimeMillis())); for (CommitteeMembershipRole committeeMembershipRole : committeeMembership.getMembershipRoles()) { if (committeeMembershipRole.getMembershipRoleCode().equals(CHAIR_MEMBERSHIP_ROLE_CODE) && !currentDate.before(committeeMembershipRole.getStartDate()) && !currentDate.after(committeeMembershipRole.getEndDate())) { isChairRoleFound = true;//from w w w . j a v a 2 s .c o m break; } } return isChairRoleFound; }