List of usage examples for java.sql Date after
public boolean after(Date when)
From source file:org.kuali.kfs.module.ar.document.service.impl.InvoiceRecurrenceDocumentServiceImpl.java
/** * @see org.kuali.kfs.module.ar.document.service.InvoiceRecurrenceService#isValidEndDateAndTotalRecurrenceNumber(Date,Date,int,String) *//* w ww. j a v a 2 s . c o m*/ @Override public boolean isValidEndDateAndTotalRecurrenceNumber(Date recurrenceBeginDate, Date recurrenceEndDate, Integer totalRecurrenceNumber, String recurrenceIntervalCode) { if (ObjectUtils.isNull(recurrenceBeginDate) || ObjectUtils.isNull(recurrenceIntervalCode) || ObjectUtils.isNull(recurrenceEndDate) || ObjectUtils.isNull(totalRecurrenceNumber)) { return true; } Calendar beginCalendar = Calendar.getInstance(); beginCalendar.setTime(recurrenceBeginDate); Date beginDate = recurrenceBeginDate; Calendar endCalendar = Calendar.getInstance(); endCalendar.setTime(recurrenceEndDate); Date endDate = recurrenceEndDate; Calendar nextCalendar = Calendar.getInstance(); Date nextDate = beginDate; int totalRecurrences = 0; int addCounter = 0; String intervalCode = recurrenceIntervalCode; if (intervalCode.equals("M")) { addCounter = 1; } if (intervalCode.equals("Q")) { addCounter = 3; } /* perform this loop while begin_date is less than or equal to end_date */ while (!(beginDate.after(endDate))) { beginCalendar.setTime(beginDate); beginCalendar.add(Calendar.MONTH, addCounter); beginDate = KfsDateUtils.convertToSqlDate(beginCalendar.getTime()); totalRecurrences++; nextDate = beginDate; nextCalendar.setTime(nextDate); nextCalendar.add(Calendar.MONTH, addCounter); nextDate = KfsDateUtils.convertToSqlDate(nextCalendar.getTime()); if (endDate.after(beginDate) && endDate.before(nextDate)) { totalRecurrences++; break; } } if (totalRecurrences != totalRecurrenceNumber.intValue()) { return false; } return true; }
From source file:org.kuali.kfs.module.ar.document.validation.impl.CustomerRule.java
/** * This method checks if customer end date is valid: 1. if a new address is being added, customer end date must be a future date * 2. if inactivating an address, customer end date must be current or future date * * @param endDate// w w w. j av a2 s .c o m * @param canBeTodaysDateFlag * @return True if endDate is valid. */ public boolean checkEndDateIsValid(Date endDate, boolean canBeTodaysDateFlag) { boolean isValid = true; if (ObjectUtils.isNull(endDate)) { return isValid; } Timestamp today = dateTimeService.getCurrentTimestamp(); today.setTime(DateUtils.truncate(today, Calendar.DAY_OF_MONTH).getTime()); // end date must be todays date or future date if (canBeTodaysDateFlag) { if (endDate.before(today)) { isValid = false; } } // end date must be a future date else { if (!endDate.after(today)) { isValid = false; } } return isValid; }
From source file:org.kuali.kfs.module.ar.document.validation.impl.InvoiceRecurrenceRule.java
/** * This method checks that End Date and Total Recurrence Number are valid when both are entered. * * @param document the maintenance document * @return/* ww w . j a v a 2s. co m*/ */ protected boolean validateIfBothEndDateAndTotalRecurrenceNumberAreEntered(Date recurrenceBeginDate, Date recurrenceEndDate, Integer totalRecurrenceNumber, String recurrenceIntervalCode) { if (ObjectUtils.isNull(recurrenceBeginDate) || ObjectUtils.isNull(recurrenceIntervalCode) || ObjectUtils.isNull(recurrenceEndDate) || ObjectUtils.isNull(totalRecurrenceNumber)) { return true; } Calendar beginCalendar = Calendar.getInstance(); beginCalendar.setTime(recurrenceBeginDate); Date beginDate = recurrenceBeginDate; Calendar endCalendar = Calendar.getInstance(); endCalendar.setTime(recurrenceEndDate); Date endDate = recurrenceEndDate; Calendar nextCalendar = Calendar.getInstance(); Date nextDate = beginDate; int totalRecurrences = 0; int addCounter = 0; String intervalCode = recurrenceIntervalCode; if (intervalCode.equals("M")) { addCounter = 1; } if (intervalCode.equals("Q")) { addCounter = 3; } /* perform this loop while begin_date is less than or equal to end_date */ while (!(beginDate.after(endDate))) { beginCalendar.setTime(beginDate); beginCalendar.add(Calendar.MONTH, addCounter); beginDate = KfsDateUtils.convertToSqlDate(beginCalendar.getTime()); totalRecurrences++; nextDate = beginDate; nextCalendar.setTime(nextDate); nextCalendar.add(Calendar.MONTH, addCounter); nextDate = KfsDateUtils.convertToSqlDate(nextCalendar.getTime()); if (endDate.after(beginDate) && endDate.before(nextDate)) { totalRecurrences++; break; } } if (totalRecurrences != totalRecurrenceNumber.intValue()) { putFieldError(ArPropertyConstants.InvoiceRecurrenceFields.INVOICE_RECURRENCE_END_DATE, ArKeyConstants.ERROR_END_DATE_AND_TOTAL_NUMBER_OF_RECURRENCES_NOT_VALID); return false; } return true; }
From source file:org.kuali.kfs.module.cam.document.validation.impl.EquipmentLoanOrReturnDocumentRule.java
/** * Implementation of the rule that if a document has a valid expect loan date and loan return date, the both dates should come * before the 2 years limit.//from w w w. j a va2 s .c o m * * @param equipmentLoanOrReturnDocument the equipmentLoanOrReturn document to be validated * @return boolean false if the expect loan date or loan return date is not before the 2 years limit. */ protected boolean validateLoanDate(EquipmentLoanOrReturnDocument equipmentLoanOrReturnDocument) { boolean valid = true; Date loanDate = KfsDateUtils.clearTimeFields(equipmentLoanOrReturnDocument.getLoanDate()); Calendar cal = GregorianCalendar.getInstance(); cal.setTime(loanDate); cal.add(Calendar.YEAR, 2); Date maxDate = new Date(cal.getTime().getTime()); // Loan can not be before today Date loanReturnDate = equipmentLoanOrReturnDocument.getLoanReturnDate(); if (equipmentLoanOrReturnDocument.isNewLoan() && loanDate.before(KfsDateUtils.clearTimeFields(new java.util.Date()))) { GlobalVariables.getMessageMap().putError( KFSConstants.DOCUMENT_PROPERTY_NAME + "." + CamsPropertyConstants.EquipmentLoanOrReturnDocument.LOAN_DATE, CamsKeyConstants.EquipmentLoanOrReturn.ERROR_INVALID_LOAN_DATE); } // expect return date must be >= loan date and within 2 years limit Date expectReturnDate = equipmentLoanOrReturnDocument.getExpectedReturnDate(); if (expectReturnDate != null) { KfsDateUtils.clearTimeFields(expectReturnDate); if (expectReturnDate.before(loanDate)) { valid &= false; GlobalVariables.getMessageMap().putError( KFSConstants.DOCUMENT_PROPERTY_NAME + "." + CamsPropertyConstants.EquipmentLoanOrReturnDocument.EXPECTED_RETURN_DATE, CamsKeyConstants.EquipmentLoanOrReturn.ERROR_INVALID_EXPECTED_RETURN_DATE); } if (maxDate.before(expectReturnDate)) { valid &= false; GlobalVariables.getMessageMap().putError( KFSConstants.DOCUMENT_PROPERTY_NAME + "." + CamsPropertyConstants.EquipmentLoanOrReturnDocument.EXPECTED_RETURN_DATE, CamsKeyConstants.EquipmentLoanOrReturn.ERROR_INVALID_EXPECTED_MAX_DATE); } } // loan return date must be >= loan date and within 2 years limit if (loanReturnDate != null) { KfsDateUtils.clearTimeFields(loanReturnDate); if (loanDate.after(loanReturnDate) || maxDate.before(loanReturnDate)) { valid &= false; GlobalVariables.getMessageMap().putError( KFSConstants.DOCUMENT_PROPERTY_NAME + "." + CamsPropertyConstants.EquipmentLoanOrReturnDocument.LOAN_RETURN_DATE, CamsKeyConstants.EquipmentLoanOrReturn.ERROR_INVALID_LOAN_RETURN_DATE); } } return valid; }
From source file:org.kuali.kfs.module.cg.document.validation.impl.CGMaintenanceDocumentRuleBase.java
/** * Checks to see if the end date is after the begin date * * @param begin// ww w . j ava2s . c om * @param end * @param propertyName * @return true if end is after begin, false otherwise */ protected boolean checkEndAfterBegin(Date begin, Date end, String propertyName) { boolean success = true; if (ObjectUtils.isNotNull(begin) && ObjectUtils.isNotNull(end) && !end.after(begin)) { putFieldError(propertyName, KFSKeyConstants.ERROR_ENDING_DATE_NOT_AFTER_BEGIN); success = false; } return success; }
From source file:org.kuali.kfs.module.endow.document.validation.impl.KEMIDRule.java
/** * Checks that the pay income to kemid exists. * // w ww . j a v a 2 s . com * @param payoutInstruction the payout instruction to be validated * @param index -1 if cehcking the add payout instruction, the index of the payout instruction in the list of added payout * instruction otherwise * @return true if it exists, false otherwise */ private boolean checkPayoutInstruction(KemidPayoutInstruction payoutInstruction, int index) { boolean success = true; int originalErrorCount = GlobalVariables.getMessageMap().getErrorCount(); // check that the pay income to kemid exists if (StringUtils.isNotBlank(payoutInstruction.getPayIncomeToKemid()) && !payoutInstruction.getPayIncomeToKemid().equalsIgnoreCase(newKemid.getKemid())) { payoutInstruction.refreshReferenceObject(EndowPropertyConstants.KEMID_PAY_INC_TO_KEMID_OBJ_REF); if (ObjectUtils.isNull(payoutInstruction.getPayIncomeToKemidObjRef())) { String label = this.getDataDictionaryService().getAttributeLabel(KemidPayoutInstruction.class, EndowPropertyConstants.KEMID_PAY_INC_TO_KEMID); String message = label + "(" + payoutInstruction.getPayIncomeToKemid() + ")"; if (index == -1) { putFieldError( KFSConstants.MAINTENANCE_ADD_PREFIX + EndowPropertyConstants.KEMID_PAY_INSTRUCTIONS_TAB + "." + EndowPropertyConstants.KEMID_PAY_INC_TO_KEMID, KFSKeyConstants.ERROR_EXISTENCE, message); } else { putFieldError( EndowPropertyConstants.KEMID_PAY_INSTRUCTIONS_TAB + "[" + index + "]" + "." + EndowPropertyConstants.KEMID_PAY_INC_TO_KEMID, KFSKeyConstants.ERROR_EXISTENCE, message); } } } // check that start date is prior to end date Date startDate = payoutInstruction.getStartDate(); Date endDate = payoutInstruction.getEndDate(); if (startDate != null && endDate != null) { if (startDate.after(endDate)) { if (index == -1) { putFieldError( KFSConstants.MAINTENANCE_ADD_PREFIX + EndowPropertyConstants.KEMID_PAY_INSTRUCTIONS_TAB + "." + EndowPropertyConstants.KEMID_PAY_INC_START_DATE, EndowKeyConstants.KEMIDConstants.ERROR_KEMID_PAYOUT_INSTRUCTION_START_DATE_SHOULD_BE_PRIOR_TO_END_DATE); } else { putFieldError( EndowPropertyConstants.KEMID_PAY_INSTRUCTIONS_TAB + "[" + index + "]" + "." + EndowPropertyConstants.KEMID_PAY_INC_START_DATE, EndowKeyConstants.KEMIDConstants.ERROR_KEMID_PAYOUT_INSTRUCTION_START_DATE_SHOULD_BE_PRIOR_TO_END_DATE); } } } success &= GlobalVariables.getMessageMap().getErrorCount() == originalErrorCount; return success; }
From source file:org.kuali.kfs.module.tem.document.service.impl.MileageRateServiceImpl.java
@Override public MileageRate findMileageRateByExpenseTypeCodeAndDate(String expenseTypeCode, Date effectiveDate) { for (MileageRate mileageRate : cachingMileageRateService.findAllMileageRates()) { if ((KfsDateUtils.isSameDay(effectiveDate, mileageRate.getActiveFromDate()) || effectiveDate.after(mileageRate.getActiveFromDate())) && (KfsDateUtils.isSameDay(effectiveDate, mileageRate.getActiveToDate()) || effectiveDate.before(mileageRate.getActiveToDate())) && mileageRate.getExpenseTypeCode().equals(expenseTypeCode)) { return mileageRate; }/*from w w w . j ava 2 s . c o m*/ } return null; }
From source file:org.kuali.kra.award.timeandmoney.AwardDirectFandADistributionRuleImpl.java
/** * This is a helper method for doExistingFandADistributionDatesOverlap. *///from w w w .jav a 2 s . c o m boolean targetOverlapsWithExistingPeriods(AwardDirectFandADistribution thisAwardDirectFandADistribution, List<AwardDirectFandADistribution> thisAwardDirectFandADistributions, int currentIndex) { boolean invalid = false; Date testStartDate; Date testEndDate; Date startDate = thisAwardDirectFandADistribution.getStartDate(); Date endDate = thisAwardDirectFandADistribution.getEndDate(); int newCurrentIndex = 0; for (AwardDirectFandADistribution testAwardDirectFandADistribution : thisAwardDirectFandADistributions) { testStartDate = testAwardDirectFandADistribution.getStartDate(); testEndDate = testAwardDirectFandADistribution.getEndDate(); if (newCurrentIndex != currentIndex) { if (startDate.before(testEndDate) && startDate.after(testStartDate) || endDate.after(testStartDate) && endDate.before(testEndDate) || startDate.equals(testEndDate) || endDate.equals(testStartDate)) { invalid = true; break; } } newCurrentIndex++; } return invalid; }
From source file:org.kuali.kra.award.timeandmoney.AwardDirectFandADistributionRuleImpl.java
/** * This is a helper method for doTargetDatesFallWithinOpenPeriod. *//* ww w . ja v a 2 s . co m*/ 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 start date falls after project start date. */// www . ja v a2s.c om boolean isTargetStartAfterProjectStartDate( AwardDirectFandADistributionRuleEvent awardDirectFandADistributionRuleEvent) { Date targetStartDate = awardDirectFandADistribution.getStartDate(); Date projectStartDate = awardDirectFandADistributionRuleEvent.getTimeAndMoneyDocument().getAward() .getAwardEffectiveDate(); boolean valid = true; if (!(projectStartDate == null)) { if (projectStartDate.after(targetStartDate)) { valid = false; reportError(NEW_AWARD_DIRECT_FNA_DISTRIBUTION + INVALID_TARGET_START_DATE, KeyConstants.ERROR_TARGET_START_DATE); } } return valid; }