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

The following examples show how to use java.sql.Date#compareTo() . 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: DateType.java    From tddl5 with Apache License 2.0 6 votes vote down vote up
@Override
public int compare(Object o1, Object o2) {
    if (o1 == o2) {
        return 0;
    }
    if (o1 == null) {
        return -1;
    }

    if (o2 == null) {
        return 1;
    }

    Date d1 = convertFrom(o1);
    Date d2 = convertFrom(o2);

    return d1.compareTo(d2);
}
 
Example 2
Source File: DateType.java    From tddl with Apache License 2.0 6 votes vote down vote up
@Override
public int compare(Object o1, Object o2) {
    if (o1 == o2) {
        return 0;
    }
    if (o1 == null) {
        return -1;
    }

    if (o2 == null) {
        return 1;
    }

    Date d1 = convertFrom(o1);
    Date d2 = convertFrom(o2);

    return d1.compareTo(d2);
}
 
Example 3
Source File: SortTransaction.java    From kfs with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public int compare(CustomerStatementDetailReportDataHolder c1, CustomerStatementDetailReportDataHolder c2) {
    Date c1Date = c1.getDocumentFinalDate();
    Date c2Date = c2.getDocumentFinalDate();
    int result = 0;
    if (c1Date == null) {
        result = (c2Date == null)? 0 : -1;
    } else {
        result = (c2Date == null) ? 1 : c1Date.compareTo(c2Date);
    }

    if (result == 0) {
        result = c1.getDocType().compareTo(c2.getDocType());
    }
    return result;
}
 
Example 4
Source File: TravelReimbursementDocument.java    From kfs with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected String generateDescription() {
    DateTimeService dateTimeService = SpringContext.getBean(DateTimeService.class);
    String description = super.generateDescription();

    if (getTripEnd() != null && getTripBegin() != null) {
        boolean preTripReimbursement = false;
        try {
        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;
}
 
Example 5
Source File: VendorServiceImpl.java    From kfs with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * @see org.kuali.kfs.vnd.document.service.VendorService#isVendorContractExpired(org.kuali.rice.krad.document.Document, java.lang.Integer, org.kuali.kfs.vnd.businessobject.VendorDetail)
 */
@Override
public boolean isVendorContractExpired(Document document, Integer vendorContractGeneratedIdentifier, VendorDetail vendorDetail) {
    boolean isExpired = false;

    if (ObjectUtils.isNotNull(vendorContractGeneratedIdentifier)) {
        VendorContract vendorContract = SpringContext.getBean(BusinessObjectService.class).findBySinglePrimaryKey(VendorContract.class, vendorContractGeneratedIdentifier);
        Date currentDate = SpringContext.getBean(DateTimeService.class).getCurrentSqlDate();
        List<Note> notes = document.getNotes();

        if ((currentDate.compareTo(vendorContract.getVendorContractEndDate()) > 0 && (vendorContract.getVendorContractExtensionDate() == null || currentDate.compareTo(vendorContract.getVendorContractExtensionDate()) > 0)) || !vendorContract.isActive()) {
            Note newNote = new Note();
            newNote.setNoteText("Vendor Contract: " + vendorContract.getVendorContractName() + " contract has expired contract end date.");
            newNote.setNotePostedTimestampToCurrent();
            newNote.setNoteTypeCode(KFSConstants.NoteTypeEnum.BUSINESS_OBJECT_NOTE_TYPE.getCode());
            Note note = noteService.createNote(newNote, vendorDetail, GlobalVariables.getUserSession().getPrincipalId());
            notes.add(note);
            isExpired = true;
        }
    }

    return isExpired;
}
 
Example 6
Source File: TravelAuthorizationServiceImpl.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
public boolean doesDatesOverlap(Date tripBeginBufferDate, Date tripEndBufferDate, Date tripBeginDate, Date tripEndDate) {
    if ((tripBeginDate.compareTo(tripBeginBufferDate) >= 0 && tripBeginDate.compareTo(tripEndBufferDate) <= 0) ||
        (tripEndDate.compareTo(tripBeginBufferDate) >= 0 && tripEndDate.compareTo(tripEndBufferDate) <=0 )) {
                  return true;
                }
    return false;
}
 
Example 7
Source File: AccountingPeriodServiceImpl.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * @see org.kuali.kfs.coa.service.AccountingPeriodService#compareAccountingPeriodsByDate(org.kuali.kfs.coa.businessobject.AccountingPeriod,
 *      org.kuali.kfs.coa.businessobject.AccountingPeriod)
 */
@Override
public int compareAccountingPeriodsByDate(AccountingPeriod tweedleDee, AccountingPeriod tweedleDum) {
    // note the lack of defensive programming here. If you send a null accounting
    // period...then chances are, you deserve the NPE that you receive
    Date tweedleDeeClose = tweedleDee.getUniversityFiscalPeriodEndDate();
    Date tweedleDumClose = tweedleDum.getUniversityFiscalPeriodEndDate();

    return tweedleDeeClose.compareTo(tweedleDumClose);
}
 
Example 8
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 9
Source File: PurchasingProcessVendorValidation.java    From kfs with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public boolean validate(AttributedDocumentEvent event) {
    boolean valid = true;
    PurchasingDocument purDocument = (PurchasingDocument) event.getDocument();
    MessageMap errorMap = GlobalVariables.getMessageMap();
    errorMap.clearErrorPath();
    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;

}