Example usage for java.sql Date setTime

List of usage examples for java.sql Date setTime

Introduction

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

Prototype

public void setTime(long date) 

Source Link

Document

Sets an existing Date object using the given milliseconds time value.

Usage

From source file:com.splicemachine.orc.OrcTester.java

private static Object preprocessWriteValueOld(TypeInfo typeInfo, Object value) throws IOException {
    if (value == null) {
        return null;
    }/*from w w  w.j a  va 2  s  .c  om*/
    switch (typeInfo.getCategory()) {
    case PRIMITIVE:
        PrimitiveObjectInspector.PrimitiveCategory primitiveCategory = ((PrimitiveTypeInfo) typeInfo)
                .getPrimitiveCategory();
        switch (primitiveCategory) {
        case BOOLEAN:
            return value;
        case BYTE:
            return ((Number) value).byteValue();
        case SHORT:
            return ((Number) value).shortValue();
        case INT:
            return ((Number) value).intValue();
        case LONG:
            return ((Number) value).longValue();
        case FLOAT:
            return ((Number) value).floatValue();
        case DOUBLE:
            return ((Number) value).doubleValue();
        case DECIMAL:
            return HiveDecimal.create(((Decimal) value).toBigDecimal().bigDecimal());
        case STRING:
            return value;
        case CHAR:
            return new HiveChar(value.toString(), ((CharTypeInfo) typeInfo).getLength());
        case DATE:
            LocalDate localDate = LocalDate.ofEpochDay((int) value);
            ZonedDateTime zonedDateTime = localDate.atStartOfDay(ZoneId.systemDefault());

            long millis = zonedDateTime.toEpochSecond() * 1000;
            Date date = new Date(0);
            // mills must be set separately to avoid masking
            date.setTime(millis);
            return date;
        case TIMESTAMP:
            long millisUtc = ((Long) value).intValue();
            return new Timestamp(millisUtc);
        case BINARY:
            return ((String) value).getBytes();
        //                        return (byte[])value;
        }
        break;
    case MAP:
        MapTypeInfo mapTypeInfo = (MapTypeInfo) typeInfo;
        TypeInfo keyTypeInfo = mapTypeInfo.getMapKeyTypeInfo();
        TypeInfo valueTypeInfo = mapTypeInfo.getMapValueTypeInfo();
        Map<Object, Object> newMap = new HashMap<>();
        for (Entry<?, ?> entry : ((Map<?, ?>) value).entrySet()) {
            newMap.put(preprocessWriteValueOld(keyTypeInfo, entry.getKey()),
                    preprocessWriteValueOld(valueTypeInfo, entry.getValue()));
        }
        return newMap;
    case LIST:
        ListTypeInfo listTypeInfo = (ListTypeInfo) typeInfo;
        TypeInfo elementTypeInfo = listTypeInfo.getListElementTypeInfo();
        List<Object> newList = new ArrayList<>(((Collection<?>) value).size());
        for (Object element : (Iterable<?>) value) {
            newList.add(preprocessWriteValueOld(elementTypeInfo, element));
        }
        return newList;
    case STRUCT:
        StructTypeInfo structTypeInfo = (StructTypeInfo) typeInfo;
        List<?> fieldValues = (List<?>) value;
        List<TypeInfo> fieldTypeInfos = structTypeInfo.getAllStructFieldTypeInfos();
        List<Object> newStruct = new ArrayList<>();
        for (int fieldId = 0; fieldId < fieldValues.size(); fieldId++) {
            newStruct.add(preprocessWriteValueOld(fieldTypeInfos.get(fieldId), fieldValues.get(fieldId)));
        }
        return newStruct;
    }
    throw new IOException(format("Unsupported Hive type: %s", typeInfo));
}

From source file:org.kuali.kfs.coa.document.validation.impl.AccountRule.java

/**
 * This method checks to see if the account expiration date is today's date or earlier
 *
 * @param newAccount//from  w w w .  j a  v  a2s  .  co m
 * @return fails if the expiration date is null or after today's date
 */
protected boolean checkAccountExpirationDateValidTodayOrEarlier(Account newAccount) {

    // get today's date, with no time component
    Date todaysDate = new Date(getDateTimeService().getCurrentDate().getTime());
    todaysDate.setTime(DateUtils.truncate(todaysDate, Calendar.DAY_OF_MONTH).getTime());
    // TODO: convert this to using Wes' Kuali KfsDateUtils once we're using Date's instead of Timestamp

    // get the expiration date, if any
    Date expirationDate = newAccount.getAccountExpirationDate();
    if (ObjectUtils.isNull(expirationDate)) {
        putFieldError("accountExpirationDate",
                KFSKeyConstants.ERROR_DOCUMENT_ACCMAINT_ACCT_CANNOT_BE_CLOSED_EXP_DATE_INVALID);
        return false;
    }

    // when closing an account, the account expiration date must be the current date or earlier
    expirationDate.setTime(DateUtils.truncate(expirationDate, Calendar.DAY_OF_MONTH).getTime());
    if (expirationDate.after(todaysDate)) {
        putFieldError("accountExpirationDate",
                KFSKeyConstants.ERROR_DOCUMENT_ACCMAINT_ACCT_CANNOT_BE_CLOSED_EXP_DATE_INVALID);
        return false;
    }

    return true;
}

From source file:org.kuali.kfs.coa.document.validation.impl.AccountRule.java

/**
 * This method checks to see if any expiration date field rules were violated
 *
 * @param maintenanceDocument//from  ww w .  java2 s .c  o m
 * @return false on rules violation
 */
protected boolean checkExpirationDate(MaintenanceDocument maintenanceDocument) {

    LOG.info("checkExpirationDate called");

    boolean success = true;

    Date oldExpDate = oldAccount.getAccountExpirationDate();
    Date newExpDate = newAccount.getAccountExpirationDate();
    Date today = new Date(getDateTimeService().getCurrentTimestamp().getTime());
    today.setTime(DateUtils.truncate(today, Calendar.DAY_OF_MONTH).getTime()); // remove any time components

    // When updating an account expiration date, the date must be today or later
    // Only run this test if this maintenance doc
    // is an edit doc

    if (isUpdatedExpirationDateInvalid(maintenanceDocument)) {
        Account newAccount = (Account) maintenanceDocument.getNewMaintainableObject().getBusinessObject();
        if (newAccount.isClosed()) {
            /*If the Account is being closed and the date is before today's date, the EXP date can only be today*/
            putFieldError("accountExpirationDate",
                    KFSKeyConstants.ERROR_DOCUMENT_ACCMAINT_ACCT_CANNOT_BE_CLOSED_EXP_DATE_INVALID);
        } else {
            /*If the Account is not being closed and the date is before today's date, the EXP date can only be today or at a later date*/
            putFieldError("accountExpirationDate",
                    KFSKeyConstants.ERROR_DOCUMENT_ACCMAINT_EXP_DATE_TODAY_LATER);
        }
        success &= false;
    }

    // a continuation account is required if the expiration date is completed.
    if (ObjectUtils.isNotNull(newExpDate)) {
        if (StringUtils.isBlank(newAccount.getContinuationAccountNumber())) {
            putFieldError("continuationAccountNumber",
                    KFSKeyConstants.ERROR_DOCUMENT_ACCMAINT_CONTINUATION_ACCT_REQD_IF_EXP_DATE_COMPLETED);
        }
        if (StringUtils.isBlank(newAccount.getContinuationFinChrtOfAcctCd())) {
            putFieldError("continuationFinChrtOfAcctCd",
                    KFSKeyConstants.ERROR_DOCUMENT_ACCMAINT_CONTINUATION_FINCODE_REQD_IF_EXP_DATE_COMPLETED);
            success &= false;
        }
    }

    // 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
    if (maintenanceDocument.isNew() && ObjectUtils.isNotNull(newExpDate)) {
        Collection<String> fundGroups = SpringContext.getBean(ParameterService.class)
                .getParameterValuesAsString(Account.class,
                        KFSConstants.ChartApcParms.EXPIRATION_DATE_BACKDATING_FUND_GROUPS);
        if (fundGroups == null || ObjectUtils.isNull(newAccount.getSubFundGroup())
                || !fundGroups.contains(newAccount.getSubFundGroup().getFundGroupCode())) {
            if (!newExpDate.after(today) && !newExpDate.equals(today)) {
                putFieldError("accountExpirationDate",
                        KFSKeyConstants.ERROR_DOCUMENT_ACCMAINT_EXP_DATE_TODAY_LATER);
                success &= false;
            }
        }
    }

    // acct_expiration_dt can not be before acct_effect_dt
    Date effectiveDate = newAccount.getAccountEffectiveDate();
    if (ObjectUtils.isNotNull(effectiveDate) && ObjectUtils.isNotNull(newExpDate)) {
        if (newExpDate.before(effectiveDate)) {
            putFieldError("accountExpirationDate",
                    KFSKeyConstants.ERROR_DOCUMENT_ACCMAINT_EXP_DATE_CANNOT_BE_BEFORE_EFFECTIVE_DATE);
            success &= false;
        }
    }

    return success;
}

From source file:org.kuali.kfs.coa.document.validation.impl.AccountRule.java

/**
 * This method checks to see if the new expiration date is different from the old expiration and if it has if it is invalid
 *
 * @param maintDoc/*from  w  w w .  j ava2s  . co m*/
 * @return true if expiration date has changed and is invalid
 */
protected boolean isUpdatedExpirationDateInvalid(MaintenanceDocument maintDoc) {

    // if this isn't an Edit document, we're not interested
    if (!maintDoc.isEdit()) {
        return false;
    }

    Date oldExpDate = oldAccount.getAccountExpirationDate();
    Date newExpDate = newAccount.getAccountExpirationDate();
    Date today = new Date(getDateTimeService().getCurrentDate().getTime());
    today.setTime(DateUtils.truncate(today, Calendar.DAY_OF_MONTH).getTime()); // remove any time components

    // if the date was valid upon submission, and this is an approval,
    // we're not interested unless the approver changed the value
    if (maintDoc.getDocumentHeader().getWorkflowDocument().isApprovalRequested()) {
        try {
            MaintenanceDocument oldMaintDoc = (MaintenanceDocument) SpringContext.getBean(DocumentService.class)
                    .getByDocumentHeaderId(maintDoc.getDocumentNumber());
            Account oldAccount = (Account) oldMaintDoc.getDocumentBusinessObject();

            if (ObjectUtils.isNotNull(oldAccount.getAccountExpirationDate())
                    && oldAccount.getAccountExpirationDate().equals(newExpDate)) {
                return false;
            }
        } catch (WorkflowException ex) {
            LOG.warn("Error retrieving maintenance doc for doc #" + maintDoc.getDocumentNumber()
                    + ". This shouldn't happen.", ex);
        }
    }

    // When updating an account expiration date, the date must be today or later
    // Only run this test if this maintenance 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 hasn't changed, we're not interested
    if (!expDateHasChanged) {
        return false;
    }

    // make a shortcut to the newAccount
    Account newAccount = (Account) maintDoc.getNewMaintainableObject().getBusinessObject();

    /* expirationDate must be today or later than today (cannot be before today).
     * This rule doesn't apply to certain fund groups (C&G perhaps) according to
     * the parameter.
     */
    Collection<String> fundGroups = SpringContext.getBean(ParameterService.class).getParameterValuesAsString(
            Account.class, KFSConstants.ChartApcParms.EXPIRATION_DATE_BACKDATING_FUND_GROUPS);
    if (fundGroups != null && ObjectUtils.isNotNull(newAccount.getSubFundGroup())
            && fundGroups.contains(newAccount.getSubFundGroup().getFundGroupCode())) {
        return false;
    }
    return newExpDate.before(today);
}

From source file:org.kuali.kfs.coa.document.validation.impl.AccountRuleTest.java

public void testGuidelinesConditionallyRequired_TodaysDate() {

    boolean result;
    Account account = new Account();
    MaintenanceDocument maintDoc = newMaintDoc(account);
    AccountRule rule = (AccountRule) setupMaintDocRule(maintDoc, AccountRule.class);

    // setup a var with today's date
    Date today = new Date(SpringContext.getBean(DateTimeService.class).getCurrentDate().getTime());
    today.setTime(DateUtils.truncate(today, Calendar.DAY_OF_MONTH).getTime());
    account.setAccountExpirationDate(today);
    result = rule.areGuidelinesRequired(account);
    assertEquals("Guidelines should be required for Account expiring today.", true, result);

}

From source file:org.kuali.kfs.fp.document.web.struts.AuxiliaryVoucherForm.java

/**
 * Gets today's date and then sets the day of the month as 15th, irrespective of the current day of the month
 * @return the modified reversal date//from w ww.  j av  a 2 s .  co m
 */
protected Date getAvReversalDate() {
    Date documentReveralDate = getAuxiliaryVoucherDocument().getReversalDate();
    if (ObjectUtils.isNotNull(documentReveralDate)) {
        return documentReveralDate;
    }

    java.sql.Date avReversalDate = SpringContext.getBean(DateTimeService.class).getCurrentSqlDateMidnight();

    Calendar cal = Calendar.getInstance();
    cal.setTime(avReversalDate);

    int thisMonth;

    if (getAuxiliaryVoucherDocument().getAccountingPeriod().getUniversityFiscalPeriodCode()
            .equals(KFSConstants.MONTH13)) {
        thisMonth = cal.JULY;
    } else {
        thisMonth = getAuxiliaryVoucherDocument().getAccountingPeriod().getMonth();
    }

    cal.set(Calendar.MONTH, (thisMonth));

    //if today's day > 15 then set the month to next month.
    //   if (cal.get(Calendar.DAY_OF_MONTH) > KFSConstants.AuxiliaryVoucher.ACCRUAL_DOC_DAY_OF_MONTH) {
    //      cal.add(Calendar.MONTH, 1);
    //  }

    int reversalDateDefaultDayOfMonth = this.getReversalDateDefaultDayOfMonth();

    cal.set(Calendar.DAY_OF_MONTH, reversalDateDefaultDayOfMonth);

    long timeInMillis = cal.getTimeInMillis();
    avReversalDate.setTime(timeInMillis);

    return avReversalDate;
}

From source file:org.kuali.ole.coa.document.validation.impl.AccountRule.java

/**
 * This method checks to see if the account expiration date is today's date or earlier
 *
 * @param newAccount//from w ww  . j a  v  a 2s . c  o m
 * @return fails if the expiration date is null or after today's date
 */
protected boolean checkAccountExpirationDateValidTodayOrEarlier(Account newAccount) {

    // get today's date, with no time component
    Date todaysDate = new Date(getDateTimeService().getCurrentDate().getTime());
    todaysDate.setTime(DateUtils.truncate(todaysDate, Calendar.DAY_OF_MONTH).getTime());
    // TODO: convert this to using Wes' Kuali KfsDateUtils once we're using Date's instead of Timestamp

    // get the expiration date, if any
    Date expirationDate = newAccount.getAccountExpirationDate();
    if (ObjectUtils.isNull(expirationDate)) {
        putFieldError("accountExpirationDate",
                OLEKeyConstants.ERROR_DOCUMENT_ACCMAINT_ACCT_CANNOT_BE_CLOSED_EXP_DATE_INVALID);
        return false;
    }

    // when closing an account, the account expiration date must be the current date or earlier
    expirationDate.setTime(DateUtils.truncate(expirationDate, Calendar.DAY_OF_MONTH).getTime());
    if (expirationDate.after(todaysDate)) {
        putFieldError("accountExpirationDate",
                OLEKeyConstants.ERROR_DOCUMENT_ACCMAINT_ACCT_CANNOT_BE_CLOSED_EXP_DATE_INVALID);
        return false;
    }

    return true;
}

From source file:org.kuali.ole.coa.document.validation.impl.AccountRule.java

/**
 * This method checks to see if any expiration date field rules were violated
 *
 * @param maintenanceDocument//from   w  w w.  j av a 2  s . c om
 * @return false on rules violation
 */
protected boolean checkExpirationDate(MaintenanceDocument maintenanceDocument) {

    LOG.debug("checkExpirationDate called");

    boolean success = true;

    Date oldExpDate = oldAccount.getAccountExpirationDate();
    Date newExpDate = newAccount.getAccountExpirationDate();
    Date today = new Date(getDateTimeService().getCurrentTimestamp().getTime());
    today.setTime(DateUtils.truncate(today, Calendar.DAY_OF_MONTH).getTime()); // remove any time components

    // When updating an account expiration date, the date must be today or later
    // Only run this test if this maintenance doc
    // is an edit doc

    //MSU Contribution OLEMI-8567 DTT-565 OLECNTRB-972
    if (isUpdatedExpirationDateInvalid(maintenanceDocument)) {
        Account newAccount = (Account) maintenanceDocument.getNewMaintainableObject().getBusinessObject();
        if (newAccount.isClosed()) {
            /*If the Account is being closed and the date is before today's date, the EXP date can only be today*/
            putFieldError("accountExpirationDate",
                    OLEKeyConstants.ERROR_DOCUMENT_ACCMAINT_ACCT_CANNOT_BE_CLOSED_EXP_DATE_INVALID);
        } else {
            /*If the Account is not being closed and the date is before today's date, the EXP date can only be today or at a later date*/
            putFieldError("accountExpirationDate",
                    OLEKeyConstants.ERROR_DOCUMENT_ACCMAINT_EXP_DATE_TODAY_LATER);
        }
        success &= false;
    }

    // a continuation account is required if the expiration date is completed.
    if (ObjectUtils.isNotNull(newExpDate)) {
        if (StringUtils.isBlank(newAccount.getContinuationAccountNumber())) {
            putFieldError("continuationAccountNumber",
                    OLEKeyConstants.ERROR_DOCUMENT_ACCMAINT_CONTINUATION_ACCT_REQD_IF_EXP_DATE_COMPLETED);
        }
        if (StringUtils.isBlank(newAccount.getContinuationFinChrtOfAcctCd())) {
            putFieldError("continuationFinChrtOfAcctCd",
                    OLEKeyConstants.ERROR_DOCUMENT_ACCMAINT_CONTINUATION_FINCODE_REQD_IF_EXP_DATE_COMPLETED);
            // putGlobalError(OLEKeyConstants.ERROR_DOCUMENT_ACCMAINT_CONTINUATION_ACCT_REQD_IF_EXP_DATE_COMPLETED);
            success &= false;
        }
    }

    // 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
    if (maintenanceDocument.isNew() && ObjectUtils.isNotNull(newExpDate)) {
        if (!newExpDate.after(today) && !newExpDate.equals(today)) {
            putFieldError("accountExpirationDate",
                    OLEKeyConstants.ERROR_DOCUMENT_ACCMAINT_EXP_DATE_TODAY_LATER);
            // putGlobalError(OLEKeyConstants.ERROR_DOCUMENT_ACCMAINT_EXP_DATE_TODAY_LATER);
            success &= false;
        }
    }

    // acct_expiration_dt can not be before acct_effect_dt
    Date effectiveDate = newAccount.getAccountEffectiveDate();
    if (ObjectUtils.isNotNull(effectiveDate) && ObjectUtils.isNotNull(newExpDate)) {
        if (newExpDate.before(effectiveDate)) {
            putFieldError("accountExpirationDate",
                    OLEKeyConstants.ERROR_DOCUMENT_ACCMAINT_EXP_DATE_CANNOT_BE_BEFORE_EFFECTIVE_DATE);
            // putGlobalError(OLEKeyConstants.ERROR_DOCUMENT_ACCMAINT_EXP_DATE_CANNOT_BE_BEFORE_EFFECTIVE_DATE);
            success &= false;
        }
    }

    return success;
}

From source file:org.kuali.ole.coa.document.validation.impl.AccountRule.java

/**
 * This method checks to see if the new expiration date is different from the old expiration and if it has if it is invalid
 *
 * @param maintDoc//  w  w  w  .j  a  v  a  2  s . c  o  m
 * @return true if expiration date has changed and is invalid
 */
protected boolean isUpdatedExpirationDateInvalid(MaintenanceDocument maintDoc) {

    // if this isn't an Edit document, we're not interested
    if (!maintDoc.isEdit()) {
        return false;
    }

    Date oldExpDate = oldAccount.getAccountExpirationDate();
    Date newExpDate = newAccount.getAccountExpirationDate();
    Date today = new Date(getDateTimeService().getCurrentDate().getTime());
    today.setTime(DateUtils.truncate(today, Calendar.DAY_OF_MONTH).getTime()); // remove any time components

    // When updating an account expiration date, the date must be today or later
    // Only run this test if this maintenance 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 hasn't changed, we're not interested
    if (!expDateHasChanged) {
        return false;
    }

    // make a shortcut to the newAccount
    Account newAccount = (Account) maintDoc.getNewMaintainableObject().getBusinessObject();

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

From source file:org.kuali.ole.coa.document.validation.impl.AccountRuleTest.java

@Test
public void testGuidelinesConditionallyRequired_TodaysDate() {

    boolean result;
    Account account = new Account();
    MaintenanceDocument maintDoc = newMaintDoc(account);
    AccountRule rule = (AccountRule) setupMaintDocRule(maintDoc, AccountRule.class);

    // setup a var with today's date
    Date today = new Date(SpringContext.getBean(DateTimeService.class).getCurrentDate().getTime());
    today.setTime(DateUtils.truncate(today, Calendar.DAY_OF_MONTH).getTime());
    account.setAccountExpirationDate(today);
    result = rule.areGuidelinesRequired(account);
    assertEquals("Guidelines should be required for Account expiring today.", true, result);

}