Example usage for java.sql Date compareTo

List of usage examples for java.sql Date compareTo

Introduction

In this page you can find the example usage for java.sql Date compareTo.

Prototype

public int compareTo(Date anotherDate) 

Source Link

Document

Compares two Dates for ordering.

Usage

From source file:org.kuali.kfs.module.endow.document.KEMIDMaintainableImpl.java

/**
 * Prepares the fees tab.//w w w. java  2 s  .  c  om
 * 
 * @param document
 * @param section
 * @param field
 */
private void prepareFeesTab(MaintenanceDocument document, Section section) {
    KEMService kemService = SpringContext.getBean(KEMService.class);
    DateTimeService dateTimeService = SpringContext.getBean(DateTimeService.class);

    // fees tab
    for (Row row : section.getRows()) {
        for (Field field : row.getFields()) {

            if (field.getCONTAINER().equalsIgnoreCase(field.getFieldType())) {

                for (Row containerRow : field.getContainerRows()) {
                    for (Field containerRowfield : containerRow.getFields()) {
                        if (KRADConstants.MAINTENANCE_NEW_ACTION
                                .equals(document.getNewMaintainableObject().getMaintenanceAction())
                                || KRADConstants.MAINTENANCE_COPY_ACTION
                                        .equals(document.getNewMaintainableObject().getMaintenanceAction())) {
                            String totalAccruedFeespropertyName = KFSConstants.ADD_PREFIX + "."
                                    + EndowPropertyConstants.KEMID_FEES_TAB + "."
                                    + EndowPropertyConstants.KEMID_FEE_TOTAL_ACCRUED_FEES;
                            String indexedTotalAccruedFeesPropertyName = EndowPropertyConstants.KEMID_FEES_TAB
                                    + "\\[\\d+\\]\\" + "."
                                    + EndowPropertyConstants.KEMID_FEE_TOTAL_ACCRUED_FEES;
                            if (totalAccruedFeespropertyName
                                    .equalsIgnoreCase(containerRowfield.getPropertyName())
                                    || containerRowfield.getPropertyName()
                                            .matches(indexedTotalAccruedFeesPropertyName)) {
                                containerRowfield.setReadOnly(true);
                            }
                        }
                        if (KRADConstants.MAINTENANCE_EDIT_ACTION
                                .equals(document.getNewMaintainableObject().getMaintenanceAction())) {

                            String indexedFeeStartDatePropertyName = EndowPropertyConstants.KEMID_FEES_TAB
                                    + "\\[\\d+\\]\\" + "." + EndowPropertyConstants.KEMID_FEE_START_DATE;
                            if (containerRowfield.getPropertyName().matches(indexedFeeStartDatePropertyName)) {
                                containerRowfield.setReadOnly(true);
                            }
                        }

                        String feeEndDateField = KFSConstants.ADD_PREFIX + "."
                                + EndowPropertyConstants.KEMID_FEES_TAB + "."
                                + EndowPropertyConstants.KEMID_FEE_END_DATE;
                        if (feeEndDateField.equalsIgnoreCase(feeEndDateField)) {
                            String feeEndDateString = containerRowfield.getPropertyValue();
                            if (feeEndDateString != null
                                    && !KFSConstants.EMPTY_STRING.equalsIgnoreCase(feeEndDateString)) {

                                String currentProcessDateString = kemService.getCurrentSystemProcessDate();

                                try {
                                    Date currentProcessDate = dateTimeService
                                            .convertToSqlDate(currentProcessDateString);
                                    Date specialInstructionEndDate = dateTimeService
                                            .convertToSqlDate(feeEndDateString);

                                    if (specialInstructionEndDate.compareTo(currentProcessDate) < 0) {
                                        for (Field rowfield : row.getFields()) {
                                            rowfield.setReadOnly(true);

                                        }
                                    }
                                } catch (ParseException ex) {
                                    // do nothing
                                }
                            }
                        }
                    }
                }

            }
        }
    }
}

From source file:org.kuali.kfs.module.endow.document.KEMIDMaintainableImpl.java

/**
 * Prepares the Report Groups tab.// www  .j  a va 2  s .c  o m
 * 
 * @param document
 * @param section
 * @param field
 */
private void prepareReportGroupsTab(MaintenanceDocument document, Section section) {
    KEMService kemService = SpringContext.getBean(KEMService.class);
    DateTimeService dateTimeService = SpringContext.getBean(DateTimeService.class);

    for (Row row : section.getRows()) {
        for (Field field : row.getFields()) {

            if (field.getCONTAINER().equalsIgnoreCase(field.getFieldType())) {

                for (Row containerRow : field.getContainerRows()) {
                    for (Field containerRowfield : containerRow.getFields()) {

                        // a record is no longer editable if the instruction end date is less than the current process or system
                        // date

                        String indexedDonorStatementTermDateField = EndowPropertyConstants.KEMID_REPORT_GROUP_TAB
                                + "\\[\\d+\\]\\" + "."
                                + EndowPropertyConstants.KEMID_REPORT_GRP_DATE_TERMINATED;
                        if (containerRowfield.getPropertyName().matches(indexedDonorStatementTermDateField)) {
                            String reportTerminatedDateString = containerRowfield.getPropertyValue();
                            if (reportTerminatedDateString != null && !KFSConstants.EMPTY_STRING
                                    .equalsIgnoreCase(reportTerminatedDateString)) {

                                String currentProcessDateString = kemService.getCurrentSystemProcessDate();

                                try {
                                    Date currentProcessDate = dateTimeService
                                            .convertToSqlDate(currentProcessDateString);
                                    Date reportTerminatedDate = dateTimeService
                                            .convertToSqlDate(reportTerminatedDateString);

                                    if (reportTerminatedDate.compareTo(currentProcessDate) < 0) {

                                        for (Field rowfield : row.getFields()) {
                                            if (rowfield.getCONTAINER()
                                                    .equalsIgnoreCase(rowfield.getFieldType())) {

                                                for (Row fieldContainerRow : rowfield.getContainerRows()) {
                                                    for (Field fieldContainerRowField : fieldContainerRow
                                                            .getFields()) {
                                                        fieldContainerRowField.setReadOnly(true);
                                                    }
                                                }
                                            }

                                        }
                                    }
                                } catch (ParseException ex) {
                                    // do nothing
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

From source file:org.kuali.kfs.module.endow.document.KEMIDMaintainableImpl.java

/**
 * Prepares the Donor Statements tab./*  w w  w. j  a v a2  s.com*/
 * 
 * @param document
 * @param section
 * @param row
 * @param field
 */
private void prepareDonorStatementsTab(MaintenanceDocument document, Section section) {
    KEMService kemService = SpringContext.getBean(KEMService.class);
    DateTimeService dateTimeService = SpringContext.getBean(DateTimeService.class);
    for (Row row : section.getRows()) {
        for (Field field : row.getFields()) {
            if (field.getCONTAINER().equalsIgnoreCase(field.getFieldType())) {

                for (Row containerRow : field.getContainerRows()) {
                    for (Field containerRowfield : containerRow.getFields()) {

                        // a record is no longer editable if the donor statement termination date is less than the current
                        // process or system date

                        String indexedDonorStatementTermDateField = EndowPropertyConstants.KEMID_DONOR_STATEMENTS_TAB
                                + "\\[\\d+\\]\\" + "."
                                + EndowPropertyConstants.KEMID_DONOR_STATEMENT_TERMINATION_DATE;

                        if (containerRowfield.getPropertyName().matches(indexedDonorStatementTermDateField)) {
                            String donorStatementTermDateString = containerRowfield.getPropertyValue();
                            if (donorStatementTermDateString != null && !KFSConstants.EMPTY_STRING
                                    .equalsIgnoreCase(donorStatementTermDateString)) {

                                String currentProcessDateString = kemService.getCurrentSystemProcessDate();

                                try {
                                    Date currentProcessDate = dateTimeService
                                            .convertToSqlDate(currentProcessDateString);
                                    Date donorStatementTermDate = dateTimeService
                                            .convertToSqlDate(donorStatementTermDateString);

                                    if (donorStatementTermDate.compareTo(currentProcessDate) < 0) {
                                        for (Field rowfield : row.getFields()) {
                                            if (rowfield.getCONTAINER()
                                                    .equalsIgnoreCase(rowfield.getFieldType())) {

                                                for (Row fieldContainerRow : rowfield.getContainerRows()) {
                                                    for (Field fieldContainerRowField : fieldContainerRow
                                                            .getFields()) {
                                                        fieldContainerRowField.setReadOnly(true);
                                                    }
                                                }
                                            }

                                        }
                                    }
                                } catch (ParseException ex) {
                                    // do nothing
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

From source file:org.kuali.kfs.module.endow.document.KEMIDMaintainableImpl.java

/**
 * Prepares the Combine Donor statements tab.
 * /*  www . j av  a  2 s  .  com*/
 * @param document
 * @param section
 * @param row
 * @param field
 */
private void prepareCombineDonorStatementsTab(MaintenanceDocument document, Section section) {
    KEMService kemService = SpringContext.getBean(KEMService.class);
    DateTimeService dateTimeService = SpringContext.getBean(DateTimeService.class);

    for (Row row : section.getRows()) {
        for (Field field : row.getFields()) {
            if (field.getCONTAINER().equalsIgnoreCase(field.getFieldType())) {

                for (Row containerRow : field.getContainerRows()) {
                    for (Field containerRowfield : containerRow.getFields()) {

                        // a record is no longer editable if the combine donor statement termination date is less than the
                        // current
                        // process or system date

                        String indexedCombineDonorStatementTermDateField = EndowPropertyConstants.KEMID_COMBINE_DONOR_STATEMENTS_TAB
                                + "\\[\\d+\\]\\" + "."
                                + EndowPropertyConstants.KEMID_COMBINE_DONOR_STATEMENT_TERMINATION_DATE;

                        if (containerRowfield.getPropertyName()
                                .matches(indexedCombineDonorStatementTermDateField)) {
                            String combineDonorStatementTermDateString = containerRowfield.getPropertyValue();
                            if (combineDonorStatementTermDateString != null && !KFSConstants.EMPTY_STRING
                                    .equalsIgnoreCase(combineDonorStatementTermDateString)) {

                                String currentProcessDateString = kemService.getCurrentSystemProcessDate();

                                try {
                                    Date currentProcessDate = dateTimeService
                                            .convertToSqlDate(currentProcessDateString);
                                    Date combineDonorStatementTermDate = dateTimeService
                                            .convertToSqlDate(combineDonorStatementTermDateString);

                                    if (combineDonorStatementTermDate.compareTo(currentProcessDate) < 0) {
                                        for (Field rowfield : row.getFields()) {
                                            if (rowfield.getCONTAINER()
                                                    .equalsIgnoreCase(rowfield.getFieldType())) {

                                                for (Row fieldContainerRow : rowfield.getContainerRows()) {
                                                    for (Field fieldContainerRowField : fieldContainerRow
                                                            .getFields()) {
                                                        fieldContainerRowField.setReadOnly(true);
                                                    }
                                                }
                                            }

                                        }
                                    }
                                } catch (ParseException ex) {
                                    // do nothing
                                }
                            }
                        }
                    }
                }
            }
        }
    }

}

From source file:org.kuali.kfs.module.endow.document.service.impl.FrequencyDatesServiceImpl.java

/**
 * Method to calculate the next processing semi-monthly date based on the frequency type
 * Sets the day of the month and then returns the processing date
 * @param dayOfSemiMonthly/*from www  . j a va  2s.co m*/
 * @return next processing date
 */
protected Calendar calculateNextSemiMonthlyDate(String dayOfSemiMonthly, Date currentDate) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(currentDate);

    int dayOfMonthToSet = Integer.parseInt(dayOfSemiMonthly);
    int dayOfMonthNextToSet = 15;

    // start from the target day
    calendar.set(Calendar.DAY_OF_MONTH, dayOfMonthToSet);

    // it must be greater than the current date
    if (currentDate.compareTo(new java.sql.Date(calendar.getTimeInMillis())) > -1) {
        calendar.add(Calendar.DAY_OF_MONTH, dayOfMonthNextToSet);
    }
    // if it is not still greater, it should be in the next month
    if (currentDate.compareTo(new java.sql.Date(calendar.getTimeInMillis())) > -1) {
        calendar.set(Calendar.DAY_OF_MONTH, dayOfMonthToSet);
        calendar.add(Calendar.MONTH, 1);
    }

    return calendar;
}

From source file:org.kuali.kfs.module.endow.document.service.impl.HoldingHistoryServiceImpl.java

/**
 * @see org.kuali.kfs.module.endow.document.service.HoldingHistoryService#getHoldingHistoryTotalHoldingUnits(org.kuali.kfs.module.endow.businessobject.FeeMethod,
 *      java.lang.String, java.lang.String)
 *///  ww w  .  ja v  a  2 s.  c  o  m
public BigDecimal getHoldingHistoryTotalHoldingUnits(FeeMethod feeMethod,
        String feeMethodCodeForSecurityClassCodes, String feeMethodCodeForSecurityIds) {
    BigDecimal totalHoldingUnits = BigDecimal.ZERO;

    Date lastProcessDate = feeMethod.getFeeLastProcessDate();
    Date mostRecentDate = monthEndDateService.getMostRecentDate();

    String feeBalanceTypeCode = feeMethod.getFeeBalanceTypeCode();

    Collection<HoldingHistory> holdingHistoryRecords = holdingHistoryDao.getHoldingHistoryForBlance(feeMethod,
            feeMethodCodeForSecurityClassCodes, feeMethodCodeForSecurityIds);
    for (HoldingHistory holdingHistory : holdingHistoryRecords) {
        Date monthEndDate = monthEndDateService.getByPrimaryKey(holdingHistory.getMonthEndDateId());

        if (feeBalanceTypeCode.equals(EndowConstants.FeeBalanceTypes.FEE_BALANCE_TYPE_VALUE_FOR_AVERAGE_UNITS)
                && (monthEndDate.compareTo(lastProcessDate) > 0)) {
            totalHoldingUnits = totalHoldingUnits.add(holdingHistory.getUnits());
        }
        if (feeBalanceTypeCode.equals(EndowConstants.FeeBalanceTypes.FEE_BALANCE_TYPE_VALUE_FOR_MONTH_END_UNITS)
                && (mostRecentDate.compareTo(lastProcessDate) > 0)) {
            totalHoldingUnits = totalHoldingUnits.add(holdingHistory.getUnits());
        }
    }

    if (feeBalanceTypeCode.equals(EndowConstants.FeeBalanceTypes.FEE_BALANCE_TYPE_VALUE_FOR_AVERAGE_UNITS)) {
        totalHoldingUnits = KEMCalculationRoundingHelper.divide(totalHoldingUnits,
                BigDecimal.valueOf(holdingHistoryRecords.size()), EndowConstants.Scale.SECURITY_UNIT_VALUE);
    }

    return totalHoldingUnits;
}

From source file:org.kuali.kfs.module.endow.document.service.impl.HoldingHistoryServiceImpl.java

/**
 * @see org.kuali.kfs.module.endow.document.service.HoldingHistoryService#getHoldingHistoryTotalHoldingMarketValue(org.kuali.kfs.module.endow.businessobject.FeeMethod,
 *      java.lang.String, java.lang.String)
 *///from w  w  w .j a  v  a  2 s .c  o  m
public BigDecimal getHoldingHistoryTotalHoldingMarketValue(FeeMethod feeMethod,
        String feeMethodCodeForSecurityClassCodes, String feeMethodCodeForSecurityIds) {
    BigDecimal totalHoldingMarkteValue = BigDecimal.ZERO;

    Date lastProcessDate = feeMethod.getFeeLastProcessDate();
    Date mostRecentDate = monthEndDateService.getMostRecentDate();

    String feeBalanceTypeCode = feeMethod.getFeeBalanceTypeCode();

    Collection<HoldingHistory> holdingHistoryRecords = holdingHistoryDao.getHoldingHistoryForBlance(feeMethod,
            feeMethodCodeForSecurityClassCodes, feeMethodCodeForSecurityIds);
    for (HoldingHistory holdingHistory : holdingHistoryRecords) {
        Date monthEndDate = monthEndDateService.getByPrimaryKey(holdingHistory.getMonthEndDateId());
        if (feeBalanceTypeCode
                .equals(EndowConstants.FeeBalanceTypes.FEE_BALANCE_TYPE_VALUE_FOR_AVERAGE_MARKET_VALUE)
                && (monthEndDate.compareTo(lastProcessDate) > 0)) {
            totalHoldingMarkteValue = totalHoldingMarkteValue.add(holdingHistory.getMarketValue());
        }
        if (feeBalanceTypeCode
                .equals(EndowConstants.FeeBalanceTypes.FEE_BALANCE_TYPE_VALUE_FOR_MONTH_END_MARKET_VALUE)
                && (monthEndDate.compareTo(mostRecentDate) > 0)) {
            totalHoldingMarkteValue = totalHoldingMarkteValue.add(holdingHistory.getMarketValue());
        }
    }

    if (feeBalanceTypeCode
            .equals(EndowConstants.FeeBalanceTypes.FEE_BALANCE_TYPE_VALUE_FOR_AVERAGE_MARKET_VALUE)) {
        totalHoldingMarkteValue = KEMCalculationRoundingHelper.divide(totalHoldingMarkteValue,
                BigDecimal.valueOf(holdingHistoryRecords.size()), EndowConstants.Scale.SECURITY_UNIT_VALUE);
    }

    return totalHoldingMarkteValue;
}

From source file:org.kuali.kfs.module.purap.document.validation.impl.PurchasingProcessVendorValidation.java

@Override
public boolean validate(AttributedDocumentEvent event) {
    boolean valid = true;
    PurchasingDocument purDocument = (PurchasingDocument) event.getDocument();
    MessageMap errorMap = GlobalVariables.getMessageMap();
    errorMap.clearErrorPath();//w w w . j  av a  2s. c  o m
    errorMap.addToErrorPath(PurapConstants.VENDOR_ERRORS);

    valid &= super.validate(event);

    if (!purDocument.getRequisitionSourceCode().equals(PurapConstants.RequisitionSources.B2B)) {

        //If there is a vendor and the transmission method is FAX and the fax number is blank, display
        //error that the fax number is required.
        if (purDocument.getVendorHeaderGeneratedIdentifier() != null
                && purDocument.getPurchaseOrderTransmissionMethodCode()
                        .equals(PurapConstants.POTransmissionMethods.FAX)
                && StringUtils.isBlank(purDocument.getVendorFaxNumber())) {
            valid &= false;
            String attributeLabel = SpringContext.getBean(DataDictionaryService.class).getDataDictionary()
                    .getBusinessObjectEntry(VendorAddress.class.getName())
                    .getAttributeDefinition(VendorPropertyConstants.VENDOR_FAX_NUMBER).getLabel();
            errorMap.putError(VendorPropertyConstants.VENDOR_FAX_NUMBER, KFSKeyConstants.ERROR_REQUIRED,
                    attributeLabel);
        }
    }

    VendorDetail vendorDetail = vendorService.getVendorDetail(purDocument.getVendorHeaderGeneratedIdentifier(),
            purDocument.getVendorDetailAssignedIdentifier());
    if (ObjectUtils.isNull(vendorDetail)) {
        return valid;
    }
    VendorHeader vendorHeader = vendorDetail.getVendorHeader();

    // make sure that the vendor is not debarred
    if (vendorDetail.isVendorDebarred()) {
        if (parameterService.getParameterValueAsBoolean(
                KFSConstants.OptionalModuleNamespaces.PURCHASING_ACCOUNTS_PAYABLE, "Requisition",
                PurapParameterConstants.SHOW_DEBARRED_VENDOR_WARNING_IND)) {
            if (StringUtils.isEmpty(((PurchasingDocumentBase) purDocument).getJustification())) {
                errorMap.putWarning(VendorPropertyConstants.VENDOR_NAME,
                        PurapKeyConstants.WARNING_DEBARRED_VENDOR, vendorDetail.getVendorName());
                valid &= false;
            }
        } else {
            errorMap.putError(VendorPropertyConstants.VENDOR_NAME, PurapKeyConstants.ERROR_DEBARRED_VENDOR);
            valid &= false;
        }
    }

    // make sure that the vendor is of allowed type
    List<String> allowedVendorTypes = new ArrayList<String>(
            parameterService.getParameterValuesAsString(KfsParameterConstants.PURCHASING_DOCUMENT.class,
                    PurapRuleConstants.PURAP_VENDOR_TYPE_ALLOWED_ON_REQ_AND_PO));
    if (allowedVendorTypes != null && !allowedVendorTypes.isEmpty()) {
        if (ObjectUtils.isNotNull(vendorHeader) && ObjectUtils.isNotNull(vendorHeader.getVendorTypeCode())
                && !allowedVendorTypes.contains(vendorHeader.getVendorTypeCode())) {
            valid &= false;
            errorMap.putError(VendorPropertyConstants.VENDOR_NAME, PurapKeyConstants.ERROR_INVALID_VENDOR_TYPE);
        }
    }

    // make sure that the vendor is active
    if (!vendorDetail.isActiveIndicator()) {
        valid &= false;
        errorMap.putError(VendorPropertyConstants.VENDOR_NAME, PurapKeyConstants.ERROR_INACTIVE_VENDOR);
    }

    //make sure that the vendor contract is active and not expired.
    if (ObjectUtils.isNotNull(purDocument.getVendorContractGeneratedIdentifier())) {
        VendorContract vendorContract = SpringContext.getBean(BusinessObjectService.class)
                .findBySinglePrimaryKey(VendorContract.class,
                        purDocument.getVendorContractGeneratedIdentifier());
        Date currentDate = SpringContext.getBean(DateTimeService.class).getCurrentSqlDate();

        if (currentDate.compareTo(vendorContract.getVendorContractEndDate()) > 0
                || !vendorContract.isActive()) {
            valid &= false;
            errorMap.putError(VendorPropertyConstants.VENDOR_CONTRACT_NAME,
                    PurapKeyConstants.ERROR_INACTIVE_OR_EXPIRED_VENDOR_CONTRACT);
        }
    }
    // validate vendor address
    postalCodeValidationService.validateAddress(purDocument.getVendorCountryCode(),
            purDocument.getVendorStateCode(), purDocument.getVendorPostalCode(),
            PurapPropertyConstants.VENDOR_STATE_CODE, PurapPropertyConstants.VENDOR_POSTAL_CODE);

    errorMap.clearErrorPath();
    return valid;

}

From source file:org.kuali.kfs.module.tem.document.service.impl.TravelAuthorizationServiceImpl.java

public boolean doesDatesOverlap(Date tripBeginBufferDate, Date tripEndBufferDate, Date tripBeginDate,
        Date tripEndDate) {/* w  w  w  .  j av  a 2  s. c  om*/
    if ((tripBeginDate.compareTo(tripBeginBufferDate) >= 0 && tripBeginDate.compareTo(tripEndBufferDate) <= 0)
            || (tripEndDate.compareTo(tripBeginBufferDate) >= 0
                    && tripEndDate.compareTo(tripEndBufferDate) <= 0)) {
        return true;
    }
    return false;
}

From source file:org.kuali.kfs.module.tem.document.TravelReimbursementDocument.java

@Override
protected String generateDescription() {
    DateTimeService dateTimeService = SpringContext.getBean(DateTimeService.class);
    String description = super.generateDescription();

    if (getTripEnd() != null && getTripBegin() != null) {
        boolean preTripReimbursement = false;
        try {/*from  www .jav a 2s.  c  om*/
            Date tripEnd = dateTimeService.convertToSqlDate(getTripEnd());
            Date tripBegin = dateTimeService.convertToSqlDate(getTripBegin());
            Date currentDate = dateTimeService.getCurrentSqlDate();
            preTripReimbursement = tripBegin.compareTo(currentDate) >= 0 && tripEnd.compareTo(currentDate) >= 0
                    ? true
                    : false;
        } catch (ParseException pe) {
            LOG.error("Error while parsing dates ", pe);
        }

        final boolean preTrip = getParameterService().getParameterValueAsBoolean(
                TravelReimbursementDocument.class,
                TemConstants.TravelReimbursementParameters.PRETRIP_REIMBURSEMENT_IND, false);

        if (preTrip && preTripReimbursement) {
            return postpendPreTripToDescription(description);
        }
    }

    return description;
}