Java Code Examples for java.sql.Date#equals()

The following examples show how to use java.sql.Date#equals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AuxiliaryVoucherDocument.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * This method checks if the given accounting period ends on the last day of the previous fiscal year
 *
 * @param acctPeriod accounting period to check
 * @return true if the accounting period ends with the fiscal year, false if otherwise
 */
public boolean isEndOfPreviousFiscalYear(AccountingPeriod acctPeriod) {
    final UniversityDateService universityDateService = SpringContext.getBean(UniversityDateService.class);
    final Date firstDayOfCurrFiscalYear = new Date(universityDateService.getFirstDateOfFiscalYear(universityDateService.getCurrentFiscalYear()).getTime());
    final Date periodClose = acctPeriod.getUniversityFiscalPeriodEndDate();
    java.util.Calendar cal = new java.util.GregorianCalendar();
    cal.setTime(periodClose);
    cal.add(java.util.Calendar.DATE, 1);
    return (firstDayOfCurrFiscalYear.equals(new Date(cal.getTimeInMillis())));
}
 
Example 2
Source File: HumanResourcesPayrollDaoJdbc.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * find positions with effective date before July 1 of fiscal year or on August 1 of fiscal year for academic tenure salary plan
 * 
 * @param universityFiscalYear
 * @param positionNumber
 * @return
 */
protected PositionData getPositionDataForFiscalYear(Integer universityFiscalYear, String positionNumber) {
    Collection<PositionData> positionData = getPositionData(positionNumber);
    
    if (positionData == null || positionData.isEmpty()) {
        return null;
    }

    // find positions with effective date before July 1 of fiscal year or on August 1 of fiscal year
    // for academic tenure salary plan
    Integer baseFiscalYear = universityFiscalYear - 1;

    GregorianCalendar calendarJuly1 = new GregorianCalendar(baseFiscalYear, Calendar.JULY, 1);
    GregorianCalendar calendarAugust1 = new GregorianCalendar(universityFiscalYear, Calendar.AUGUST, 1);
    Date julyFirst = new Date(calendarJuly1.getTimeInMillis());
    Date augustFirst = new Date(calendarAugust1.getTimeInMillis());

    String academicTenureTrackSalaryPlan = new String("AC1");

    PositionData positionDataMaxEffectiveDate = null;
    for (PositionData posData : positionData) {
        Date positionEffectiveDate = posData.getEffectiveDate();
        if ((positionEffectiveDate.compareTo(julyFirst) <= 0) || (academicTenureTrackSalaryPlan.equals(posData.getPositionSalaryPlanDefault()) && positionEffectiveDate.equals(augustFirst))) {
            // get position with max effective date for year
            if (positionDataMaxEffectiveDate == null || positionDataMaxEffectiveDate.getEffectiveDate().compareTo(positionEffectiveDate) < 0) {
                positionDataMaxEffectiveDate = posData;
            }
        }
    }

    return positionDataMaxEffectiveDate;
}
 
Example 3
Source File: TestAdvQueryImpl.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void setDate( String parameterName, Date value ) throws OdaException
{
    if( m_currentTestCase == 2 )
    {
        if( parameterName.endsWith( "2" ) ) //$NON-NLS-1$
            if( ! value.equals( Date.valueOf( "2005-11-13" ) )) //$NON-NLS-1$
                throw new OdaException( "Error in setDate by name" ); //$NON-NLS-1$
    }
}
 
Example 4
Source File: AccountGlobalRule.java    From kfs with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * This method checks to see if any expiration date field rules were violated Loops through each detail object and calls
 * {@link AccountGlobalRule#checkExpirationDate(MaintenanceDocument, AccountGlobalDetail)}
 *
 * @param maintenanceDocument
 * @return false on rules violation
 */
protected boolean checkExpirationDate(MaintenanceDocument maintenanceDocument) {
    LOG.info("checkExpirationDate called");

    boolean success = true;
    Date newExpDate = newAccountGlobal.getAccountExpirationDate();

    // If creating a new account if acct_expiration_dt is set then
    // the acct_expiration_dt must be changed to a date that is today or later
    // unless the date was valid upon submission, this is an approval action
    // and the approver hasn't changed the value
    if (maintenanceDocument.isNew() && ObjectUtils.isNotNull(newExpDate)) {
        Date oldExpDate = null;

        if (maintenanceDocument.getDocumentHeader().getWorkflowDocument().isApprovalRequested()) {
            try {
                MaintenanceDocument oldMaintDoc = (MaintenanceDocument) SpringContext.getBean(DocumentService.class).getByDocumentHeaderId(maintenanceDocument.getDocumentNumber());
                AccountGlobal oldAccountGlobal = (AccountGlobal)oldMaintDoc.getDocumentBusinessObject();
                if (ObjectUtils.isNotNull(oldAccountGlobal)) {
                    oldExpDate = oldAccountGlobal.getAccountExpirationDate();
                }
            }
            catch (WorkflowException ex) {
                LOG.warn( "Error retrieving maintenance doc for doc #" + maintenanceDocument.getDocumentNumber()+ ". This shouldn't happen.", ex );
            }
        }

        if (ObjectUtils.isNull(oldExpDate) || !oldExpDate.equals(newExpDate)) {
            if (!newExpDate.after(today) && !newExpDate.equals(today)) {
                putFieldError("accountExpirationDate", KFSKeyConstants.ERROR_DOCUMENT_ACCMAINT_EXP_DATE_TODAY_LATER);
                success &= false;
            }
        }
    }


    // a continuation account is required if the expiration date is completed.
    success &= checkContinuationAccount(maintenanceDocument, newExpDate);

    for (AccountGlobalDetail detail : newAccountGlobal.getAccountGlobalDetails()) {
        success &= checkExpirationDate(maintenanceDocument, detail);
    }
    return success;
}
 
Example 5
Source File: AccountGlobalRule.java    From kfs with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * This method checks to see if any expiration date field rules were violated in relation to the given detail record
 *
 * @param maintenanceDocument
 * @param detail - the account detail we are investigating
 * @return false on rules violation
 */
protected boolean checkExpirationDate(MaintenanceDocument maintenanceDocument, AccountGlobalDetail detail) {
    boolean success = true;
    Date newExpDate = newAccountGlobal.getAccountExpirationDate();

    Date prevExpDate = null;

    // get previous expiration date for possible check later
    if (maintenanceDocument.getDocumentHeader().getWorkflowDocument().isApprovalRequested()) {
        try {
            MaintenanceDocument oldMaintDoc = (MaintenanceDocument) SpringContext.getBean(DocumentService.class).getByDocumentHeaderId(maintenanceDocument.getDocumentNumber());
            AccountGlobal oldAccountGlobal = (AccountGlobal)oldMaintDoc.getDocumentBusinessObject();
            if (ObjectUtils.isNotNull(oldAccountGlobal)) {
                prevExpDate = oldAccountGlobal.getAccountExpirationDate();
            }
        }
        catch (WorkflowException ex) {
            LOG.warn( "Error retrieving maintenance doc for doc #" + maintenanceDocument.getDocumentNumber()+ ". This shouldn't happen.", ex );
        }
    }


    // load the object by keys
    Account account = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(Account.class, detail.getPrimaryKeys());
    if (ObjectUtils.isNotNull(account)) {
        Date oldExpDate = account.getAccountExpirationDate();

        // When updating an account expiration date, the date must be today or later
        // (except for C&G accounts). Only run this test if this maint doc
        // is an edit doc
        if (isUpdatedExpirationDateInvalid(account, newAccountGlobal)) {
            // if the date was valid upon submission, and this is an approval,
            // we're not interested unless the approver changed the value
            if (ObjectUtils.isNull(prevExpDate) || !prevExpDate.equals(newExpDate)) {
                putFieldError("accountExpirationDate", KFSKeyConstants.ERROR_DOCUMENT_ACCMAINT_EXP_DATE_TODAY_LATER);
                success &= false;
            }
        }

        // If creating a new account if acct_expiration_dt is set and the fund_group is not "CG" then
        // the acct_expiration_dt must be changed to a date that is today or later
        // unless the date was valid upon submission, this is an approval action
        // and the approver hasn't changed the value
        if (maintenanceDocument.isNew() && ObjectUtils.isNotNull(newExpDate)) {
            if (ObjectUtils.isNull(prevExpDate) || !prevExpDate.equals(newExpDate)) {
                if (ObjectUtils.isNotNull(newExpDate) && ObjectUtils.isNull(newAccountGlobal.getSubFundGroup())) {
                    if (ObjectUtils.isNotNull(account.getSubFundGroup())) {
                        if (!account.isForContractsAndGrants()) {
                            if (!newExpDate.after(today) && !newExpDate.equals(today)) {
                                putGlobalError(KFSKeyConstants.ERROR_DOCUMENT_ACCMAINT_EXP_DATE_TODAY_LATER);
                                success &= false;
                            }
                        }
                    }
                }
            }
        }

        // acct_expiration_dt can not be before acct_effect_dt
        Date effectiveDate = account.getAccountEffectiveDate();
        if (ObjectUtils.isNotNull(effectiveDate) && ObjectUtils.isNotNull(newExpDate)) {
            if (newExpDate.before(effectiveDate)) {
                putGlobalError(KFSKeyConstants.ERROR_DOCUMENT_ACCMAINT_EXP_DATE_CANNOT_BE_BEFORE_EFFECTIVE_DATE);
                success &= false;
            }
        }
    }

    return success;
}
 
Example 6
Source File: AccountGlobalRule.java    From kfs with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * This method checks to see if the updated expiration is not a valid one Only gets checked for specific {@link SubFundGroup}s
 *
 * @param oldAccount
 * @param newAccountGlobal
 * @return true if date has changed and is invalid
 */
protected boolean isUpdatedExpirationDateInvalid(Account oldAccount, AccountGlobal newAccountGlobal) {

    Date oldExpDate = oldAccount.getAccountExpirationDate();
    Date newExpDate = newAccountGlobal.getAccountExpirationDate();

    // When updating an account expiration date, the date must be today or later
    // (except for C&G accounts). Only run this test if this maint doc
    // is an edit doc
    boolean expDateHasChanged = false;

    // if the old version of the account had no expiration date, and the new
    // one has a date
    if (ObjectUtils.isNull(oldExpDate) && ObjectUtils.isNotNull(newExpDate)) {
        expDateHasChanged = true;
    }

    // if there was an old and a new expDate, but they're different
    else if (ObjectUtils.isNotNull(oldExpDate) && ObjectUtils.isNotNull(newExpDate)) {
        if (!oldExpDate.equals(newExpDate)) {
            expDateHasChanged = true;
        }
    }

    // if the expiration date hasnt changed, we're not interested
    if (!expDateHasChanged) {
        return false;
    }

    // if a subFundGroup isnt present, we cannot continue the testing
    SubFundGroup subFundGroup = newAccountGlobal.getSubFundGroup();
    if (ObjectUtils.isNull(subFundGroup)) {
        return false;
    }

    // get the fundGroup code
    String fundGroupCode = newAccountGlobal.getSubFundGroup().getFundGroupCode().trim();

    // if the account is part of the CG fund group, then this rule does not
    // apply, so we're done
    if (SpringContext.getBean(SubFundGroupService.class).isForContractsAndGrants(newAccountGlobal.getSubFundGroup())) {
        return false;
    }

    // at this point, we know its not a CG fund group, so we must apply the rule

    // expirationDate must be today or later than today (cannot be before today)
    if (newExpDate.equals(today) || newExpDate.after(today)) {
        return false;
    }
    else {
        return true;
    }
}