Example usage for java.util Date compareTo

List of usage examples for java.util Date compareTo

Introduction

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

Prototype

public int compareTo(Date anotherDate) 

Source Link

Document

Compares two Dates for ordering.

Usage

From source file:org.openadaptor.auxil.expression.BinaryOp.java

protected Object dateOp(Date d1, Date d2) throws ExpressionException {
    Object result;//from   ww  w . j a  v a  2 s.  c  o m
    switch (op) {

    case ExpressionToken.OP_PLUS:
        result = new Long(d1.getTime() + d2.getTime());
        break;
    case ExpressionToken.OP_MINUS:
        result = new Long(d1.getTime() - d2.getTime());
        break;

    case ExpressionToken.OP_EQ:
        result = new Boolean(d1.equals(d2));
        break;
    case ExpressionToken.OP_NE:
        result = new Boolean(!(d1.equals(d2)));
        break;

    case ExpressionToken.OP_GT:
        result = new Boolean(d1.compareTo(d2) > 0);
        break;

    case ExpressionToken.OP_LT:
        result = new Boolean(d1.compareTo(d2) < 0);
        break;

    case ExpressionToken.OP_LE:
        result = new Boolean(d1.compareTo(d2) <= 0);
        break;

    case ExpressionToken.OP_GE:
        result = new Boolean(d1.compareTo(d2) >= 0);
        break;
    default:
        throw new ExpressionException("Attempted unrecognised expression operation: " + op);
        // break;
    }
    return result;
}

From source file:org.apache.oozie.command.coord.CoordChangeXCommand.java

/**
 * Delete coordinator action//from  www . j  a v  a  2s .  c  om
 *
 * @param actionNum coordinator action number
 */
private Date deleteAction(int actionNum, Date afterDate) throws CommandException {
    try {
        if (actionNum <= 0) {
            return null;
        }

        String actionId = jobId + "@" + actionNum;
        CoordinatorActionBean bean = CoordActionQueryExecutor.getInstance()
                .getIfExist(CoordActionQueryExecutor.CoordActionQuery.GET_COORD_ACTION, actionId);
        if (bean == null) {
            return null;
        }
        if (afterDate.compareTo(bean.getNominalTime()) <= 0) {
            if (bean.getStatus() == CoordinatorAction.Status.WAITING
                    || bean.getStatus() == CoordinatorAction.Status.READY) {
                // delete SLA registration entry (if any) for action
                if (SLAService.isEnabled()) {
                    Services.get().get(SLAService.class).removeRegistration(actionId);
                }
                SLARegistrationBean slaReg = SLARegistrationQueryExecutor.getInstance()
                        .get(SLARegQuery.GET_SLA_REG_ALL, actionId);
                if (slaReg != null) {
                    LOG.debug("Deleting registration bean corresponding to action " + slaReg.getId());
                    deleteList.add(slaReg);
                }
                SLASummaryBean slaSummaryBean = SLASummaryQueryExecutor.getInstance()
                        .get(SLASummaryQuery.GET_SLA_SUMMARY, actionId);
                if (slaSummaryBean != null) {
                    LOG.debug("Deleting summary bean corresponding to action " + slaSummaryBean.getId());
                    deleteList.add(slaSummaryBean);
                }
                deleteList.add(bean);
            } else {
                throw new CommandException(ErrorCode.E1022, bean.getId());
            }
            return bean.getNominalTime();
        } else {
            return null;
        }

    } catch (JPAExecutorException e) {
        throw new CommandException(e);
    }
}

From source file:com.marcohc.robotocalendar.RobotoCalendarView.java

public boolean selectDay(Date currentDate, int modeSelect) {
    boolean isSelect = false;
    if (startDay == null) {
        selectStartDay(currentDate);//from  w w w  . ja  va  2s . co m
        isSelect = true;
    } else {
        if (startDay != null && endDay != null) {
            if (currentDate.compareTo(startDay) >= 0) {
                endDay = null;
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(currentDate);
                initializeCalendar(calendar);
                selectEndDay(currentDate);
                isSelect = true;
            } else {
                //do nothing
            }
        } else {
            if (modeSelect == MODE_START_DATE) {
                clearDayOfTheMonthStyle(currentDate);
                selectStartDay(currentDate);
                isSelect = true;
            } else {
                if (currentDate.compareTo(startDay) >= 0) {
                    selectEndDay(currentDate);
                    isSelect = true;
                } else {
                    //do nothing
                }
            }

        }
    }
    lastSelectedDay = currentDate;
    return isSelect;
}

From source file:co.adun.mvnejb3jpa.web.validation.IdentifyingNumberValidator.java

@Override
public void validate(Object target, Errors errors) {

    List<IdentifyingNumberModel> inList = (List<IdentifyingNumberModel>) target;

    /*/*from w w w  .  ja va  2 s  .co  m*/
     * Field names:
     * ltLeadsModel[0].identifyingNumberModel["+i+"].numberType.abbreviation
     * ltLeadsModel[0].identifyingNumberModel["+i+"].number
     * ltLeadsModel[0].identifyingNumberModel["+i+"].otherType
     * ltLeadsModel[0].identifyingNumberModel["+i+"].statusCode.abbreviation
     * ltLeadsModel
     * [0].identifyingNumberModel["+i+"].countryCode.abbreviation
     * ltLeadsModel
     * [0].identifyingNumberModel["+i+"].sourceCodes[0].abbreviation
     * ltLeadsModel[0].identifyingNumberModel["+i+"].comments
     * ltLeadsModel[0].identifyingNumberModel["+i+"].issueDate
     * ltLeadsModel[0].identifyingNumberModel["+i+"].expirationDate
     * ltLeadsModel[0].identifyingNumberModel["+i+"].eventDate
     * ltLeadsModel[0].identifyingNumberModel["+i+"].creationDate
     * ltLeadsModel[0].identifyingNumberModel["+i+"].updateDate
     * ltLeadsModel[0].identifyingNumberModel["+i+"].incidentDate
     * ltLeadsModel[0].identifyingNumberModel["+i+"].naturalizationDate
     */

    // retrieve DOB from lead model
    // Date dob = model.getBirthDateModel().getAsDate();

    String errorCode = "";
    int i = 0;

    for (IdentifyingNumberModel in : inList) {
        LtIdentifyingNumber ltIdentifyingNumber = in.getLtIdentifierNumber();
        if (ltIdentifyingNumber == null)
            continue;

        DateValueModel dateValueModel = in.getBirthDateModel();
        Date dob = dateValueModel.getAsDate();

        String numberType = in.getLtIdentifierNumber().getNumberTypeCode().getAbbreviation();

        // **************Global checks***************
        // - Number Type should not be default
        // - Check comment length (4000)
        // - Check source for not empty
        // Note: All dates are NOT required, but
        // an earlier-than-DOB check (if DOB is not null) must be done.

        if (numberType == "Select...") {
            errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].numberType.abbreviation",
                    errorCode, "Please select a Number Type.");
        }
        if (!StringUtils.isEmpty(ltIdentifyingNumber.getIdentifyingNumberComment())
                && ltIdentifyingNumber.getIdentifyingNumberComment().length() > 4000) {
            errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].comments", errorCode,
                    "Comments must be 4000 characters or less.");
        }
        if (in.getSourceCodes().isEmpty()) {
            errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].sourceCodes[0].abbreviation",
                    errorCode, "Each IN must have at least one source.");
        }

        // *************Number-specific checks*************

        String pattern = "";

        // Alien Registration #
        if (numberType == "AR") {
            // number [9 numerics, not null]
            pattern = "^(\\d{9})$";
            if (!StringUtils.isEmpty(ltIdentifyingNumber.getIdentifyingNumber())
                    && !ltIdentifyingNumber.getIdentifyingNumber().matches(pattern)) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].number", errorCode,
                        "Incorrect format [Alien Reg. #: 9 numerics]");
            }
        }
        // FIN
        else if (numberType == "FI") {
            // number [10 numerics, not null]
            pattern = "^(\\d{10})$";
            if (!StringUtils.isEmpty(ltIdentifyingNumber.getIdentifyingNumber())
                    && !ltIdentifyingNumber.getIdentifyingNumber().matches(pattern)) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].number", errorCode,
                        "Incorrect format [FIN: 10 numerics]");
            }
        }
        // SSN
        else if (numberType == "SS") {
            // number [9 numerics input type ###-##-####, not null]
            pattern = "^(\\d{3}-\\d{2}-\\d{4})$";
            if (!StringUtils.isEmpty(ltIdentifyingNumber.getIdentifyingNumber())
                    && !ltIdentifyingNumber.getIdentifyingNumber().matches(pattern)) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].number", errorCode,
                        "Incorrect format [SSN: ###-##-####]");
            }
        }
        // ADIS PID
        else if (numberType == "AD") {
            // number [9 numerics, not null]
            pattern = "^(\\d{9})$";
            if (!StringUtils.isEmpty(ltIdentifyingNumber.getIdentifyingNumber())
                    && !ltIdentifyingNumber.getIdentifyingNumber().matches(pattern)) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].number", errorCode,
                        "Incorrect format [ADIS PID: 9 numerics]");
            }
        }
        // Credit Card
        else if (numberType == "CC") {
            // number [100 chars, not null]
            if (ltIdentifyingNumber.getIdentifyingNumber() == null) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].number", errorCode,
                        "Number field cannot be null.");
            }
            if (!StringUtils.isEmpty(ltIdentifyingNumber.getIdentifyingNumber())
                    && ltIdentifyingNumber.getIdentifyingNumber().length() > 100) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].number", errorCode,
                        "Number must be 100 characters or less.");
            }
        }
        // ENFORCE Event
        else if (numberType == "EE") {
            // number [13 alphanumerics, not null]
            pattern = "^(\\w{9})$";
            if (!StringUtils.isEmpty(ltIdentifyingNumber.getIdentifyingNumber())
                    && !ltIdentifyingNumber.getIdentifyingNumber().matches(pattern)) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].number", errorCode,
                        "Incorrect format [ENFORCE Event: 9 alphanumerics]");
            }
        }
        // LSID
        else if (numberType == "LS") {
            // number [100 chars, not null]
            if (ltIdentifyingNumber.getIdentifyingNumber() == null) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].number", errorCode,
                        "Number field cannot be null.");
            }
            if (!StringUtils.isEmpty(ltIdentifyingNumber.getIdentifyingNumber())
                    && ltIdentifyingNumber.getIdentifyingNumber().length() > 100) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].number", errorCode,
                        "Number must be 100 characters or less.");
            }
        }
        // NUIN
        else if (numberType == "NU") {
            // number [100 chars, not null]
            if (ltIdentifyingNumber.getIdentifyingNumber() == null) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].number", errorCode,
                        "Number field cannot be null.");
            }
            if (!StringUtils.isEmpty(ltIdentifyingNumber.getIdentifyingNumber())
                    && ltIdentifyingNumber.getIdentifyingNumber().length() > 100) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].number", errorCode,
                        "Number must be 100 characters or less.");
            }
        }
        // Other
        else if (numberType == "OT") {
            // other type [100 chars, not null]
            // number [100 chars, not null]
            if (ltIdentifyingNumber.getIdentifyingNumber() == null) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].number", errorCode,
                        "Number field cannot be null.");
            }
            if (!StringUtils.isEmpty(ltIdentifyingNumber.getIdentifyingNumber())
                    && ltIdentifyingNumber.getIdentifyingNumber().length() > 100) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].number", errorCode,
                        "Number must be 100 characters or less.");
            }
        }
        // TSC
        else if (numberType == "TS") {
            // number [100 chars, not null]
            if (ltIdentifyingNumber.getIdentifyingNumber() == null) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].number", errorCode,
                        "Number field cannot be null.");
            }
            if (!StringUtils.isEmpty(ltIdentifyingNumber.getIdentifyingNumber())
                    && ltIdentifyingNumber.getIdentifyingNumber().length() > 100) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].number", errorCode,
                        "Number must be 100 characters or less.");
            }
        }
        // TECS Case
        else if (numberType == "TC") {
            // number [14 alphanumerics, not null]
            // status [DD]
            pattern = "^(\\w{14})$";
            if (!StringUtils.isEmpty(ltIdentifyingNumber.getIdentifyingNumber())
                    && !ltIdentifyingNumber.getIdentifyingNumber().matches(pattern)) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].number", errorCode,
                        "Incorrect format [TECS Case: 14 alphanumerics]");
            }
            if (ltIdentifyingNumber.getStatusCodeByTecsCaseStatusCodeId().getAbbreviation() != null
                    && ltIdentifyingNumber.getStatusCodeByTecsCaseStatusCodeId()
                            .getAbbreviation() == "Select...") {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].statusCode.abbreviation",
                        errorCode, "Status is required.");
            }
        }
        // Naturalization
        else if (numberType == "NA") {
            // number [100 chars, not null]
            // naturalization date [date]
            if (ltIdentifyingNumber.getIdentifyingNumber() == null) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].number", errorCode,
                        "Number field cannot be null.");
            }
            if (!StringUtils.isEmpty(ltIdentifyingNumber.getIdentifyingNumber())
                    && ltIdentifyingNumber.getIdentifyingNumber().length() > 100) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].number", errorCode,
                        "Number must be 100 characters or less.");
            }
            DateValueModel naturalizationDateModel = in.getNaturalizationDate();
            ValidationUtils.invokeValidator(dateModelValidator, naturalizationDateModel, errors);
            Date naturalizationDate = naturalizationDateModel.getAsDate();
            if (dob != null && naturalizationDate != null && naturalizationDate.compareTo(dob) <= 0) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].naturalizationDate",
                        errorCode, "Naturalization Date should be later than lead's DOB.");
            }
        }
        // TECS ILOG
        else if (numberType == "TI") {
            // number [100 chars, not null]
            // incident date [date]
            if (ltIdentifyingNumber.getIdentifyingNumber() == null) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].number", errorCode,
                        "Number field cannot be null.");
            }
            if (!StringUtils.isEmpty(ltIdentifyingNumber.getIdentifyingNumber())
                    && ltIdentifyingNumber.getIdentifyingNumber().length() > 100) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].number", errorCode,
                        "Number must be 100 characters or less.");
            }
            DateValueModel incidentDateModel = in.getIncidentDate();
            ValidationUtils.invokeValidator(dateModelValidator, incidentDateModel, errors);
            Date incidentDate = incidentDateModel.getAsDate();
            if (dob != null && incidentDate != null && incidentDate.compareTo(dob) <= 0) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].incidentDate", errorCode,
                        "Incident Date should be later than lead's DOB.");
            }
        }
        // TECS Subject Record
        else if (numberType == "TR") {
            // number [14 alphanumerics, not null]
            // status [DD]
            // creation date [date]
            // update date [date]
            pattern = "^(\\w{14})$";
            if (!StringUtils.isEmpty(ltIdentifyingNumber.getIdentifyingNumber())
                    && !ltIdentifyingNumber.getIdentifyingNumber().matches(pattern)) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].number", errorCode,
                        "Incorrect format [TECS Subject Record: 14 alphanumerics]");
            }
            DateValueModel creationDateModel = in.getCreationDate();
            ValidationUtils.invokeValidator(dateModelValidator, creationDateModel, errors);
            Date creationDate = creationDateModel.getAsDate();
            if (dob != null && creationDate != null && creationDate.compareTo(dob) <= 0) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].creationDate", errorCode,
                        "Creation Date should be later than lead's DOB.");
            }
            DateValueModel updateDateModel = in.getUpdateDate();
            ValidationUtils.invokeValidator(dateModelValidator, updateDateModel, errors);
            Date updateDate = updateDateModel.getAsDate();
            if (dob != null && updateDate != null && updateDate.compareTo(dob) <= 0) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].updateDate", errorCode,
                        "Update Date should be later than lead's DOB.");
            }
        }
        // Passport
        else if (numberType == "PA") {
            // number [100 chars, not null]
            // country [DD]
            // issue date [date]
            // expiration date [date]
            if (ltIdentifyingNumber.getIdentifyingNumber() == null) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].number", errorCode,
                        "Number field cannot be null.");
            }
            if (!StringUtils.isEmpty(ltIdentifyingNumber.getIdentifyingNumber())
                    && ltIdentifyingNumber.getIdentifyingNumber().length() > 100) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].number", errorCode,
                        "Number must be 100 characters or less.");
            }
            DateValueModel issueDateModel = in.getIssueDate();
            ValidationUtils.invokeValidator(dateModelValidator, issueDateModel, errors);
            Date issueDate = issueDateModel.getAsDate();
            if (dob != null && issueDate != null && issueDate.compareTo(dob) <= 0) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].issueDate", errorCode,
                        "Issue Date should be later than lead's DOB.");
            }
            DateValueModel expirationDateModel = in.getExpirationDate();
            ValidationUtils.invokeValidator(dateModelValidator, expirationDateModel, errors);
            Date expirationDate = expirationDateModel.getAsDate();
            if (dob != null && expirationDate != null && expirationDate.compareTo(dob) <= 0) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].expirationDate",
                        errorCode, "Expiration Date should be later than lead's DOB.");
            }
        }
        // Visa
        else if (numberType == "VI") {
            // number [8 alphanumerics, not null]
            // issue date [date]
            // expiration date [date]
            pattern = "^(\\w{8})$";
            if (!StringUtils.isEmpty(ltIdentifyingNumber.getIdentifyingNumber())
                    && !ltIdentifyingNumber.getIdentifyingNumber().matches(pattern)) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].number", errorCode,
                        "Incorrect format [Visa: 8 alphanumerics]");
            }
            DateValueModel issueDateModel = in.getIssueDate();
            ValidationUtils.invokeValidator(dateModelValidator, issueDateModel, errors);
            Date issueDate = issueDateModel.getAsDate();
            if (dob != null && issueDate != null && issueDate.compareTo(dob) <= 0) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].issueDate", errorCode,
                        "Issue Date should be later than lead's DOB.");
            }
            DateValueModel expirationDateModel = in.getExpirationDate();
            ValidationUtils.invokeValidator(dateModelValidator, expirationDateModel, errors);
            Date expirationDate = expirationDateModel.getAsDate();
            if (dob != null && expirationDate != null && expirationDate.compareTo(dob) <= 0) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].expirationDate",
                        errorCode, "Expiration Date should be later than lead's DOB.");
            }
        }
        // Driver's License
        else if (numberType == "DL") {
            // number [100 chars, not null]
            // country [DD]
            // issue date [date]
            // expiration date [date]
            if (ltIdentifyingNumber.getIdentifyingNumber() == null) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].number", errorCode,
                        "Number field cannot be null.");
            }
            if (!StringUtils.isEmpty(ltIdentifyingNumber.getIdentifyingNumber())
                    && ltIdentifyingNumber.getIdentifyingNumber().length() > 100) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].number", errorCode,
                        "Number must be 100 characters or less.");
            }
            DateValueModel issueDateModel = in.getIssueDate();
            ValidationUtils.invokeValidator(dateModelValidator, issueDateModel, errors);
            Date issueDate = issueDateModel.getAsDate();
            if (dob != null && issueDate != null && issueDate.compareTo(dob) <= 0) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].issueDate", errorCode,
                        "Issue Date should be later than lead's DOB.");
            }
            DateValueModel expirationDateModel = in.getExpirationDate();
            ValidationUtils.invokeValidator(dateModelValidator, expirationDateModel, errors);
            Date expirationDate = expirationDateModel.getAsDate();
            if (dob != null && expirationDate != null && expirationDate.compareTo(dob) <= 0) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].expirationDate",
                        errorCode, "Expiration Date should be later than lead's DOB.");
            }
        }
        // State ID Card
        else if (numberType == "SI") {
            // number [100 chars, not null]
            // country [DD]
            // issue date [date]
            // expiration date [date]
            if (ltIdentifyingNumber.getIdentifyingNumber() == null) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].number", errorCode,
                        "Number field cannot be null.");
            }
            if (!StringUtils.isEmpty(ltIdentifyingNumber.getIdentifyingNumber())
                    && ltIdentifyingNumber.getIdentifyingNumber().length() > 100) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].number", errorCode,
                        "Number must be 100 characters or less.");
            }
            DateValueModel issueDateModel = in.getIssueDate();
            ValidationUtils.invokeValidator(dateModelValidator, issueDateModel, errors);
            Date issueDate = issueDateModel.getAsDate();
            if (dob != null && issueDate != null && issueDate.compareTo(dob) <= 0) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].issueDate", errorCode,
                        "Issue Date should be later than lead's DOB.");
            }
            DateValueModel expirationDateModel = in.getExpirationDate();
            ValidationUtils.invokeValidator(dateModelValidator, expirationDateModel, errors);
            Date expirationDate = expirationDateModel.getAsDate();
            if (dob != null && expirationDate != null && expirationDate.compareTo(dob) <= 0) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].expirationDate",
                        errorCode, "Expiration Date should be later than lead's DOB.");
            }
        }
        // FAA License
        else if (numberType == "FA") {
            // number [100 chars, not null]
            // issue date [date]
            // expiration date [date]
            if (ltIdentifyingNumber.getIdentifyingNumber() == null) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].number", errorCode,
                        "Number field cannot be null.");
            }
            if (!StringUtils.isEmpty(ltIdentifyingNumber.getIdentifyingNumber())
                    && ltIdentifyingNumber.getIdentifyingNumber().length() > 100) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].number", errorCode,
                        "Number must be 100 characters or less.");
            }
            DateValueModel issueDateModel = in.getIssueDate();
            ValidationUtils.invokeValidator(dateModelValidator, issueDateModel, errors);
            Date issueDate = issueDateModel.getAsDate();
            if (dob != null && issueDate != null && issueDate.compareTo(dob) <= 0) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].issueDate", errorCode,
                        "Issue Date should be later than lead's DOB.");
            }
            DateValueModel expirationDateModel = in.getExpirationDate();
            ValidationUtils.invokeValidator(dateModelValidator, expirationDateModel, errors);
            Date expirationDate = expirationDateModel.getAsDate();
            if (dob != null && expirationDate != null && expirationDate.compareTo(dob) <= 0) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].expirationDate",
                        errorCode, "Expiration Date should be later than lead's DOB.");
            }
        }
        // Visa Control
        else if (numberType == "VC") {
            // number [100 chars, not null]
            // event date [date]
            if (ltIdentifyingNumber.getIdentifyingNumber() == null) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].number", errorCode,
                        "Number field cannot be null.");
            }
            if (!StringUtils.isEmpty(ltIdentifyingNumber.getIdentifyingNumber())
                    && ltIdentifyingNumber.getIdentifyingNumber().length() > 100) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].number", errorCode,
                        "Number must be 100 characters or less.");
            }
            DateValueModel eventDateModel = in.getEventDate();
            ValidationUtils.invokeValidator(dateModelValidator, eventDateModel, errors);
            Date eventDate = eventDateModel.getAsDate();
            if (dob != null && eventDate != null && eventDate.compareTo(dob) <= 0) {
                errors.rejectValue("ltLeadsModel[0].identifyingNumberModel[" + i + "].eventDate", errorCode,
                        "Event Date should be later than lead's DOB.");
            }
        }
        i++;
    }
}

From source file:com.aurel.track.linkType.MsProjectLinkTypeBL.java

/**
 * This method checks if the parameters work item's new start/end date dependencies are valid with his preds.
 * @param originalMovedWorkItemBean/*from   w  w w .  j  av  a 2s. c  o m*/
 * @param workItemParam
 * @param startdateParam
 * @param endDateParam
 * @param workItemLinkDao
 * @return
 * @throws ItemLoaderException
 */
public static boolean checkWorkItemAndPredsDependencyViolation(TWorkItemBean originalMovedWorkItemBean,
        TWorkItemBean workItemParam, Date startdateParam, Date endDateParam, Integer personID,
        Map<Integer, WorkItemWithNewCascadedDates> itemCascadeMap, List<Integer> msProjectLinkTypeIDs,
        Date startDate, Date endDate) throws ItemLoaderException {
    boolean violates = false;
    List<TWorkItemLinkBean> links = workItemLinkDao.loadByWorkItemSucc(workItemParam.getObjectID());
    List<Integer> workItemIDsList = new ArrayList<Integer>();
    for (TWorkItemLinkBean workItemLinkBean : links) {
        if (msProjectLinkTypeIDs.contains(workItemLinkBean.getLinkType())) {
            workItemIDsList.add(workItemLinkBean.getLinkPred());
        }
    }
    int[] workItemIDs = org.apache.commons.lang.ArrayUtils
            .toPrimitive(workItemIDsList.toArray(new Integer[workItemIDsList.size()]));
    List<TWorkItemBean> predList = LoadItemIDListItems.getWorkItemBeansByWorkItemIDs(workItemIDs, personID,
            false, false, false);
    Map<Integer, TWorkItemBean> predMap = new HashMap<Integer, TWorkItemBean>();
    for (int i = 0; i < predList.size(); i++) {
        predMap.put(predList.get(i).getObjectID(), predList.get(i));
    }
    for (int i = 0; i < links.size(); i++) {
        TWorkItemLinkBean actualLinkBean = links.get(i);
        if (msProjectLinkTypeIDs.contains(actualLinkBean.getLinkType())) {
            int dependencyType = actualLinkBean.getIntegerValue1();
            int predWorkItemId = actualLinkBean.getLinkPred();
            TWorkItemBean predWorkItemBean = predMap.get(predWorkItemId);
            Date predWorkItemStartDate = getStartDate(predWorkItemBean);
            Date predWorkItemEndDate = getEndDate(predWorkItemBean);
            if (originalMovedWorkItemBean.getObjectID().equals(predWorkItemBean.getObjectID())) {
                predWorkItemStartDate = startDate;
                predWorkItemEndDate = endDate;
            }
            if (itemCascadeMap.get(predWorkItemId) == null
                    && predWorkItemId != originalMovedWorkItemBean.getObjectID()) {
                switch (dependencyType) {
                case PREDECESSOR_ELEMENT_TYPE.FS:
                    if (predWorkItemEndDate != null && predWorkItemEndDate.compareTo(startdateParam) >= 0) {
                        violates = true;
                    }
                    break;
                case PREDECESSOR_ELEMENT_TYPE.FF:
                    if (predWorkItemEndDate != null && predWorkItemEndDate.compareTo(endDateParam) >= 0) {
                        violates = true;
                    }
                    break;
                case PREDECESSOR_ELEMENT_TYPE.SF:
                    if (predWorkItemStartDate != null && predWorkItemStartDate.compareTo(endDateParam) > 0) {
                        violates = true;
                    }
                    break;
                case PREDECESSOR_ELEMENT_TYPE.SS:
                    if (predWorkItemStartDate != null && predWorkItemStartDate.compareTo(startdateParam) > 0) {
                        violates = true;
                    }
                    break;
                }
            }
        }
    }
    return violates;
}

From source file:org.infoglue.calendar.actions.ViewEventListAction.java

public int compare(final Object aObj, final Object bObj) {
    final Date aDate = ((SyndEntry) aObj).getPublishedDate();
    final Date bDate = ((SyndEntry) bObj).getPublishedDate();
    return (aDate == null) ? 1 : (bDate == null) ? -1 : bDate.compareTo(aDate);
}

From source file:com.aurel.track.linkType.MsProjectLinkTypeBL.java

/**
 * This method returns true if actualWorkItem new start/end dates require cascading childWorkItem.
 * This method returns false if actualWorkItem new start/end dates not violating dependency with childWorkItem => childWorkItem doesn't needs cascading.
 * @param actualWorkItem//from w w  w. j a v  a2s . com
 * @param childWorkItem
 * @param link
 * @return
 */
public static boolean checkWhichChildWorkItemNeedCascadingRight(TWorkItemBean actualWorkItem,
        TWorkItemBean childWorkItem, TWorkItemLinkBean link, Date startDate, Date endDate) {
    boolean cascadeNeed = false;
    if (getStartDate(childWorkItem) == null && getEndDate(childWorkItem) == null) {
        return cascadeNeed;
    }
    int dependencyType = link.getIntegerValue1();
    Date newStartDate = startDate;
    Date newEndDate = endDate;
    if (actualWorkItem.isMilestone()) {
        newEndDate = newStartDate;
    }
    if (link.getLinkLag() != 0 && checkLinkLagAvaibilityForCascade(link.getLinkLagFormat())) {

        int linkLagInDays = getLinkLagInDays(link, actualWorkItem.getObjectID());

        if (linkLagInDays > 0) {
            newEndDate = stepForward(newEndDate, linkLagInDays, true);
            newStartDate = stepBack(newStartDate, linkLagInDays, true);
        }
    }
    switch (dependencyType) {
    case PREDECESSOR_ELEMENT_TYPE.FS:
        if (newEndDate.compareTo(getStartDate(childWorkItem)) >= 0) {
            cascadeNeed = true;
        }
        break;
    case PREDECESSOR_ELEMENT_TYPE.FF:
        if (newEndDate.compareTo(getEndDate(childWorkItem)) >= 0) {
            cascadeNeed = true;
        }
        break;
    case PREDECESSOR_ELEMENT_TYPE.SF:
        if (newStartDate.compareTo(getEndDate(childWorkItem)) > 0) {
            cascadeNeed = true;
        }
        break;
    case PREDECESSOR_ELEMENT_TYPE.SS:
        if (newStartDate.compareTo(getStartDate(childWorkItem)) > 0) {
            cascadeNeed = true;
        }
        break;
    }
    return cascadeNeed;
}

From source file:org.libreplan.web.orders.OrderModel.java

@Override
public boolean alreadyExistsRepeatedEndDate(Date value) {
    if (getOrder() != null) {
        Order order = getOrder();/*from  w ww .j a v a  2  s . c  o m*/
        if (order.getEndDateCommunicationToCustomer().isEmpty()) {
            return false;
        }

        EndDateCommunication endDateCommunicationToCustomer = order.getEndDateCommunicationToCustomer().first();
        Date currentEndDate = endDateCommunicationToCustomer.getEndDate();
        return (currentEndDate.compareTo(value) == 0);
    }

    return false;
}

From source file:org.apache.oozie.service.ShareLibService.java

/**
 * Gets the Latest lib path.//from www  .jav a2  s . c o m
 *
 * @param rootDir the root dir
 * @param prefix the prefix
 * @return latest lib path
 * @throws IOException Signals that an I/O exception has occurred.
 */
public Path getLatestLibPath(Path rootDir, final String prefix) throws IOException {
    Date max = new Date(0L);
    Path path = null;
    PathFilter directoryFilter = new PathFilter() {
        @Override
        public boolean accept(Path path) {
            return path.getName().startsWith(prefix);
        }
    };

    FileStatus[] files = fs.listStatus(rootDir, directoryFilter);
    for (FileStatus file : files) {
        String name = file.getPath().getName().toString();
        String time = name.substring(prefix.length());
        Date d = null;
        try {
            d = dateFormat.parse(time);
        } catch (ParseException e) {
            continue;
        }
        if (d.compareTo(max) > 0) {
            path = file.getPath();
            max = d;
        }
    }
    // If there are no timestamped directories, fall back to root directory
    if (path == null) {
        path = rootDir;
    }
    return path;
}

From source file:com.streamreduce.util.GitHubClient.java

/**
 * Retrieves the activity for the given connection based on the last poll date stored in the connection.
 *
 * Note: This list is already sorted in the proper order, contains no duplicates and contains only entries that
 *       are pertinent:/*from   w  w w  .j a  v  a  2 s . com*/
 *
 *         * Entries will correspond with a project in the projectKeys set unless that set is empty/null and then
 *           entries can be for any project
 *         * Entries will after the last activity date in the connection
 *
 * @param projectKeys the project keys we're interested in or null for all
 * @param maxActivities the maximum number of results to return
 *
 * @return list of JSONObjects representing activity entries
 *
 * @throws InvalidCredentialsException if the connection associated with this client has invalid credentials
 * @throws IOException if anything goes wrong making the actual request
 */
public List<JSONObject> getActivity(Set<String> projectKeys, int maxActivities)
        throws InvalidCredentialsException, IOException {
    // The way we gather activity for a GitHub connection is by making a few events feeds calls, merging them
    // together and then returning the results.  The end result should be a list of pertinent events that have no
    // duplicates and includes all necessary events after the last poll period.
    //
    // The GitHub API request logic looks like this:
    //
    //   * /users/<user_id>/received_events: This is the list of events that the user has "received" by watching
    //                                       repositories/users.
    //   * /users/<user_id>/events: This is a list of events that the user itself has created.
    //   * /users/<user_id>/events/orgs/<org_id>: This is a list of events that have been performed within the
    //                                            the organization.  (This will also require a call prior to this
    //                                            to get the user's organizations, if any.)

    debugLog(LOGGER, "Getting activity");

    // Establish some defaults for fields that can be null
    projectKeys = (projectKeys != null ? projectKeys : new HashSet<String>());
    maxActivities = (maxActivities >= 1 ? maxActivities : 100);

    List<JSONObject> allActivityItems = new ArrayList<>();
    Set<Integer> processedActivityHashes = new HashSet<>();
    Date lastActivity = getLastActivityPollDate();
    Set<String> eventsUrls = new HashSet<>();
    String username = getConnectionCredentials().getIdentity();

    // Generate the list of events URLs to process
    eventsUrls.add(GITHUB_API_BASE + "users/" + username + "/received_events"); // User's received events
    eventsUrls.add(GITHUB_API_BASE + "users/" + username + "/events"); // User's events

    //        // To generate the list of organization URLs to process, we need to walk through the user's organizations list
    //        List<JSONObject> organizations = getOrganizations();
    //
    //        for (JSONObject organization : organizations) {
    //            eventsUrls.add(GITHUB_API_BASE + "users/" + username + "/events/orgs/" + organization.getString("login"));
    //        }

    for (String eventUrl : eventsUrls) {
        List<JSONObject> rawActivity = makeRequest(eventUrl, maxActivities, false);

        for (JSONObject activity : rawActivity) {
            String eventType = activity.getString("type");
            String repoName = activity.getJSONObject("repo").getString("name");
            Date activityDate = getCreatedDate(activity);

            // If we do not support the event type or its for a repository we don't monitor, move on
            if (!SUPPORTED_EVENT_TYPES.contains(eventType) || !projectKeys.contains(repoName)) {
                continue;
            }

            if (activityDate.before(lastActivity)) {
                break;
            }

            int activityHash = activity.hashCode();

            if (!processedActivityHashes.contains(activityHash) && allActivityItems.size() < maxActivities) {
                allActivityItems.add(activity);
                processedActivityHashes.add(activityHash);
            }
        }
    }

    // Sort the activities
    Collections.sort(allActivityItems, new Comparator<JSONObject>() {
        /**
         * {@inheritDoc}
         */
        @Override
        public int compare(JSONObject jo0, JSONObject jo1) {
            Date jod0 = getCreatedDate(jo0);
            Date jod1 = getCreatedDate(jo1);

            return jod0.compareTo(jod1);
        }
    });

    // Return only the maximum number of results if the list of activities is greater than the maximum requested
    if (allActivityItems.size() > maxActivities) {
        allActivityItems = allActivityItems.subList(0, maxActivities);
    }

    debugLog(LOGGER, "  Activities found: " + allActivityItems.size());

    return allActivityItems;
}