Example usage for java.sql Timestamp setTime

List of usage examples for java.sql Timestamp setTime

Introduction

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

Prototype

public void setTime(long time) 

Source Link

Document

Sets this Timestamp object to represent a point in time that is time milliseconds after January 1, 1970 00:00:00 GMT.

Usage

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

/**
 * This method determines whether the guidelines are required, based on business rules.
 *
 * @param account - the populated Account bo to be evaluated
 * @return true if guidelines are required, false otherwise
 *///from   www .  j  a v a  2  s  .  c  om
protected boolean areGuidelinesRequired(Account account) {

    boolean result = true;

    if (account.getAccountExpirationDate() != null) {
        Timestamp today = getDateTimeService().getCurrentTimestamp();
        today.setTime(DateUtils.truncate(today, Calendar.DAY_OF_MONTH).getTime());
        if (account.getAccountExpirationDate().before(today)) {
            result = false;
        }
    }
    return result;
}

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

/**
 * This checks the following conditions:
 * <ul>// w  ww  . ja  va 2  s  .c om
 * <li>begin date must be greater than or equal to end date</li>
 * <li>start date must be greater than or equal to today if new Document</li>
 * <li>Reports To Chart/Org should not be same as this Chart/Org</li>
 * </ul>
 *
 * @param document
 * @return true if it passes all the rules, false otherwise
 */
protected boolean checkSimpleRules(MaintenanceDocument document) {

    boolean success = true;
    String lastReportsToChartOfAccountsCode;
    String lastReportsToOrganizationCode;
    boolean continueSearch;
    Organization tempOrg;
    Integer loopCount;
    Integer maxLoopCount = 40;

    // begin date must be greater than or equal to end date
    if ((ObjectUtils.isNotNull(newOrg.getOrganizationBeginDate())
            && (ObjectUtils.isNotNull(newOrg.getOrganizationEndDate())))) {

        Date beginDate = newOrg.getOrganizationBeginDate();
        Date endDate = newOrg.getOrganizationEndDate();

        if (endDate.before(beginDate)) {
            putFieldError("organizationEndDate",
                    KFSKeyConstants.ERROR_DOCUMENT_ORGMAINT_END_DATE_GREATER_THAN_BEGIN_DATE);
            success &= false;
        }
    }

    // start date must be greater than or equal to today if new Document
    if ((ObjectUtils.isNotNull(newOrg.getOrganizationBeginDate()) && (document.isNew()))) {
        Timestamp today = getDateTimeService().getCurrentTimestamp();
        today.setTime(DateUtils.truncate(today, Calendar.DAY_OF_MONTH).getTime());
        if (newOrg.getOrganizationBeginDate().before(today)) {
            putFieldError("organizationBeginDate", KFSKeyConstants.ERROR_DOCUMENT_ORGMAINT_STARTDATE_IN_PAST);
            success &= false;
        }
    }

    // Reports To Chart/Org should not be same as this Chart/Org
    // However, allow special case where organization type is listed in the business rules
    if (ObjectUtils.isNotNull(newOrg.getReportsToChartOfAccountsCode())
            && ObjectUtils.isNotNull(newOrg.getReportsToOrganizationCode())
            && ObjectUtils.isNotNull(newOrg.getChartOfAccountsCode())
            && ObjectUtils.isNotNull(newOrg.getOrganizationCode())) {
        if (!getOrgMustReportToSelf(newOrg)) {

            if ((newOrg.getReportsToChartOfAccountsCode().equals(newOrg.getChartOfAccountsCode()))
                    && (newOrg.getReportsToOrganizationCode().equals(newOrg.getOrganizationCode()))) {
                putFieldError("reportsToOrganizationCode",
                        KFSKeyConstants.ERROR_DOCUMENT_ORGMAINT_REPORTING_ORG_CANNOT_BE_SAME_ORG);
                success = false;
            } else {
                // Don't allow a circular reference on Reports to Chart/Org
                // terminate the search when a top-level org is found
                lastReportsToChartOfAccountsCode = newOrg.getReportsToChartOfAccountsCode();
                lastReportsToOrganizationCode = newOrg.getReportsToOrganizationCode();
                continueSearch = true;
                loopCount = 0;
                do {
                    tempOrg = orgService.getByPrimaryId(lastReportsToChartOfAccountsCode,
                            lastReportsToOrganizationCode);
                    loopCount++;
                    ;
                    if (ObjectUtils.isNull(tempOrg)) {
                        continueSearch = false;
                        // if a null is returned on the first iteration, then the reports-to org does not exist
                        // fail the validation
                        if (loopCount == 1) {
                            putFieldError("reportsToOrganizationCode",
                                    KFSKeyConstants.ERROR_DOCUMENT_ORGMAINT_REPORTING_ORG_MUST_EXIST);
                            success = false;
                        }
                    } else {
                        // on the first iteration, check whether the reports-to organization is active
                        if (loopCount == 1 && !tempOrg.isActive()) {
                            putFieldError("reportsToOrganizationCode",
                                    KFSKeyConstants.ERROR_DOCUMENT_ORGMAINT_REPORTING_ORG_MUST_EXIST);
                            success = false;
                            continueSearch = false;
                        } else {
                            // LOG.info("Found Org = " + lastReportsToChartOfAccountsCode + "/" +
                            // lastReportsToOrganizationCode);
                            lastReportsToChartOfAccountsCode = tempOrg.getReportsToChartOfAccountsCode();
                            lastReportsToOrganizationCode = tempOrg.getReportsToOrganizationCode();

                            if ((tempOrg.getReportsToChartOfAccountsCode()
                                    .equals(newOrg.getChartOfAccountsCode()))
                                    && (tempOrg.getReportsToOrganizationCode()
                                            .equals(newOrg.getOrganizationCode()))) {
                                putFieldError("reportsToOrganizationCode",
                                        KFSKeyConstants.ERROR_DOCUMENT_ORGMAINT_REPORTING_ORG_CANNOT_BE_CIRCULAR_REF_TO_SAME_ORG);
                                success = false;
                                continueSearch = false;
                            }
                        }
                    }
                    if (loopCount > maxLoopCount) {
                        continueSearch = false;
                    }
                    // stop the search if we reach an org that must report to itself
                    if (continueSearch && /*REFACTORME*/SpringContext.getBean(ParameterEvaluatorService.class)
                            .getParameterEvaluator(Organization.class,
                                    KFSConstants.ChartApcParms.ORG_MUST_REPORT_TO_SELF_ORG_TYPES,
                                    tempOrg.getOrganizationTypeCode())
                            .evaluationSucceeds()) {
                        continueSearch = false;
                    }

                } while (continueSearch == true);
            } // end else (checking for circular ref)
        } else { // org must report to self (university level organization)
            if (!(newOrg.getReportsToChartOfAccountsCode().equals(newOrg.getChartOfAccountsCode())
                    && newOrg.getReportsToOrganizationCode().equals(newOrg.getOrganizationCode()))) {
                putFieldError("reportsToOrganizationCode",
                        KFSKeyConstants.ERROR_DOCUMENT_ORGMAINT_REPORTING_ORG_MUST_BE_SAME_ORG);
                success = false;
            }
            // org must be the only one of that type
            String topLevelOrgTypeCode = SpringContext.getBean(ParameterService.class)
                    .getParameterValueAsString(Organization.class,
                            KFSConstants.ChartApcParms.ORG_MUST_REPORT_TO_SELF_ORG_TYPES);
            List<Organization> topLevelOrgs = orgService.getActiveOrgsByType(topLevelOrgTypeCode);
            if (!topLevelOrgs.isEmpty()) {
                // is the new org in the topLevelOrgs list? If not, then there's an error; if so, we're editing the top level
                // org
                if (!topLevelOrgs.contains(newOrg)) {
                    putFieldError("organizationTypeCode",
                            KFSKeyConstants.ERROR_DOCUMENT_ORGMAINT_ONLY_ONE_TOP_LEVEL_ORG,
                            topLevelOrgs.get(0).getChartOfAccountsCode() + "-"
                                    + topLevelOrgs.get(0).getOrganizationCode());
                    success = false;
                }
            }
        }
    }

    return success;
}

From source file:org.kuali.kfs.module.ar.document.validation.impl.CustomerRule.java

/**
 * This method checks if customer end date is valid: 1. if a new address is being added, customer end date must be a future date
 * 2. if inactivating an address, customer end date must be current or future date
 *
 * @param endDate/*from  w w  w  . j  a  va  2  s  . c  o m*/
 * @param canBeTodaysDateFlag
 * @return True if endDate is valid.
 */
public boolean checkEndDateIsValid(Date endDate, boolean canBeTodaysDateFlag) {
    boolean isValid = true;

    if (ObjectUtils.isNull(endDate)) {
        return isValid;
    }

    Timestamp today = dateTimeService.getCurrentTimestamp();
    today.setTime(DateUtils.truncate(today, Calendar.DAY_OF_MONTH).getTime());

    // end date must be todays date or future date
    if (canBeTodaysDateFlag) {
        if (endDate.before(today)) {
            isValid = false;
        }
    } // end date must be a future date
    else {
        if (!endDate.after(today)) {
            isValid = false;
        }
    }

    return isValid;
}

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

private boolean checkStartDate(AccountDelegateModelDetail delegateModel) {
    boolean success = true;
    if (ObjectUtils.isNotNull(delegateModel.getAccountDelegateStartDate())) {
        Timestamp today = getDateTimeService().getCurrentTimestamp();
        today.setTime(DateUtils.truncate(today, Calendar.DAY_OF_MONTH).getTime());
        if (delegateModel.getAccountDelegateStartDate().before(today)) {
            success = false;/*from  w w w. j a v a  2s . c  o  m*/
            GlobalVariables.getMessageMap().putError("accountDelegateStartDate",
                    OLEKeyConstants.ERROR_DOCUMENT_ACCTDELEGATEMAINT_STARTDATE_IN_PAST, new String[0]);
        }
    }
    return success;
}

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

private boolean checkStartDate(AccountDelegateGlobalDetail delegateGlobalDetail, int lineNum) {
    boolean success = true;
    if (ObjectUtils.isNotNull(delegateGlobalDetail.getAccountDelegateStartDate())) {
        Timestamp today = getDateTimeService().getCurrentTimestamp();
        today.setTime(DateUtils.truncate(today, Calendar.DAY_OF_MONTH).getTime());
        if (delegateGlobalDetail.getAccountDelegateStartDate().before(today)) {
            success = false;/* ww w .j  a va  2  s .  c  om*/
            String errorPath = DELEGATE_GLOBALS_PREFIX + "[" + lineNum + "]." + "accountDelegateStartDate";
            putFieldError(errorPath, OLEKeyConstants.ERROR_DOCUMENT_ACCTDELEGATEMAINT_STARTDATE_IN_PAST,
                    new String[0]);
        }
    }
    return success;
}

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

/**
 * This checks to see if//from  w  ww . j  ava  2 s.com
 * <ul>
 * <li>the delegate start date is valid and they are active</li>
 * <li>from amount is >= 0</li>
 * <li>to amount cannot be empty when from amount is filled out</li>
 * <li>to amount is >= from amount</li>
 * <li>account cannot be closed</li>
 * </ul>
 * 
 * @return
 */
protected boolean checkSimpleRules() {
    boolean success = true;

    Map<String, String> fieldValues = new HashMap<String, String>();
    fieldValues.put(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, newDelegate.getChartOfAccountsCode());
    fieldValues.put(OLEPropertyConstants.ACCOUNT_NUMBER, newDelegate.getAccountNumber());

    int accountExist = getBoService().countMatching(Account.class, fieldValues);
    if (accountExist <= 0) {
        putFieldError(OLEPropertyConstants.ACCOUNT_NUMBER, OLEKeyConstants.ERROR_EXISTENCE,
                newDelegate.getAccountNumber());
        success &= false;
    }

    // start date must be greater than or equal to today if active
    boolean newActive = newDelegate.isActive();
    if ((ObjectUtils.isNotNull(newDelegate.getAccountDelegateStartDate())) && newActive) {
        Timestamp today = getDateTimeService().getCurrentTimestamp();
        today.setTime(DateUtils.truncate(today, Calendar.DAY_OF_MONTH).getTime());
        if (newDelegate.getAccountDelegateStartDate().before(today)) {
            putFieldError(OLEPropertyConstants.ACCOUNT_DELEGATE_START_DATE,
                    OLEKeyConstants.ERROR_DOCUMENT_ACCTDELEGATEMAINT_STARTDATE_IN_PAST);
            success &= false;
        }
    }

    // FROM amount must be >= 0 (may not be negative)
    KualiDecimal fromAmount = newDelegate.getFinDocApprovalFromThisAmt();
    if (ObjectUtils.isNotNull(fromAmount)) {
        if (fromAmount.isLessThan(KualiDecimal.ZERO)) {
            putFieldError(OLEPropertyConstants.FIN_DOC_APPROVAL_FROM_THIS_AMT,
                    OLEKeyConstants.ERROR_DOCUMENT_ACCTDELEGATEMAINT_FROM_AMOUNT_NONNEGATIVE);
            success &= false;
        }
    }

    // TO amount must be >= FROM amount or Zero
    KualiDecimal toAmount = newDelegate.getFinDocApprovalToThisAmount();
    if (ObjectUtils.isNotNull(toAmount) && !toAmount.equals(KualiDecimal.ZERO)) {
        // case if FROM amount is non-null and positive, disallow TO amount being less
        if (fromAmount != null && toAmount.isLessThan(fromAmount)) {
            putFieldError(OLEPropertyConstants.FIN_DOC_APPROVAL_TO_THIS_AMOUNT,
                    OLEKeyConstants.ERROR_DOCUMENT_ACCTDELEGATEMAINT_TO_AMOUNT_MORE_THAN_FROM_OR_ZERO);
            success &= false;
        } else if (toAmount.isLessThan(KualiDecimal.ZERO)) {
            putFieldError(OLEPropertyConstants.FIN_DOC_APPROVAL_TO_THIS_AMOUNT,
                    OLEKeyConstants.ERROR_DOCUMENT_ACCTDELEGATEMAINT_TO_AMOUNT_MORE_THAN_FROM_OR_ZERO);
            success &= false;
        }
    }

    // do we have a good document type?
    final FinancialSystemDocumentTypeService documentService = SpringContext
            .getBean(FinancialSystemDocumentTypeService.class);
    if (!documentService.isFinancialSystemDocumentType(newDelegate.getFinancialDocumentTypeCode())) {
        putFieldError(OLEPropertyConstants.FINANCIAL_DOCUMENT_TYPE_CODE,
                OLEKeyConstants.ERROR_DOCUMENT_ACCTDELEGATEMAINT_INVALID_DOC_TYPE,
                new String[] { newDelegate.getFinancialDocumentTypeCode(), OLEConstants.ROOT_DOCUMENT_TYPE });
        success = false;
    }

    return success;
}

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

/**
 * This checks the following conditions:
 * <ul>/*from  w  w w . j  ava  2  s .  c o m*/
 * <li>begin date must be greater than or equal to end date</li>
 * <li>start date must be greater than or equal to today if new Document</li>
 * <li>Reports To Chart/Org should not be same as this Chart/Org</li>
 * </ul>
 *
 * @param document
 * @return true if it passes all the rules, false otherwise
 */
protected boolean checkSimpleRules(MaintenanceDocument document) {

    boolean success = true;
    String lastReportsToChartOfAccountsCode;
    String lastReportsToOrganizationCode;
    boolean continueSearch;
    Organization tempOrg;
    Integer loopCount;
    Integer maxLoopCount = 40;

    // begin date must be greater than or equal to end date
    if ((ObjectUtils.isNotNull(newOrg.getOrganizationBeginDate())
            && (ObjectUtils.isNotNull(newOrg.getOrganizationEndDate())))) {

        Date beginDate = newOrg.getOrganizationBeginDate();
        Date endDate = newOrg.getOrganizationEndDate();

        if (endDate.before(beginDate)) {
            putFieldError("organizationEndDate",
                    OLEKeyConstants.ERROR_DOCUMENT_ORGMAINT_END_DATE_GREATER_THAN_BEGIN_DATE);
            success &= false;
        }
    }

    // start date must be greater than or equal to today if new Document
    if ((ObjectUtils.isNotNull(newOrg.getOrganizationBeginDate()) && (document.isNew()))) {
        Timestamp today = getDateTimeService().getCurrentTimestamp();
        today.setTime(DateUtils.truncate(today, Calendar.DAY_OF_MONTH).getTime());
        if (newOrg.getOrganizationBeginDate().before(today)) {
            putFieldError("organizationBeginDate", OLEKeyConstants.ERROR_DOCUMENT_ORGMAINT_STARTDATE_IN_PAST);
            success &= false;
        }
    }

    // Reports To Chart/Org should not be same as this Chart/Org
    // However, allow special case where organization type is listed in the business rules
    if (ObjectUtils.isNotNull(newOrg.getReportsToChartOfAccountsCode())
            && ObjectUtils.isNotNull(newOrg.getReportsToOrganizationCode())
            && ObjectUtils.isNotNull(newOrg.getChartOfAccountsCode())
            && ObjectUtils.isNotNull(newOrg.getOrganizationCode())) {
        if (!getOrgMustReportToSelf(newOrg)) {

            if ((newOrg.getReportsToChartOfAccountsCode().equals(newOrg.getChartOfAccountsCode()))
                    && (newOrg.getReportsToOrganizationCode().equals(newOrg.getOrganizationCode()))) {
                putFieldError("reportsToOrganizationCode",
                        OLEKeyConstants.ERROR_DOCUMENT_ORGMAINT_REPORTING_ORG_CANNOT_BE_SAME_ORG);
                success = false;
            } else {
                // Don't allow a circular reference on Reports to Chart/Org
                // terminate the search when a top-level org is found
                lastReportsToChartOfAccountsCode = newOrg.getReportsToChartOfAccountsCode();
                lastReportsToOrganizationCode = newOrg.getReportsToOrganizationCode();
                continueSearch = true;
                loopCount = 0;
                do {
                    tempOrg = orgService.getByPrimaryId(lastReportsToChartOfAccountsCode,
                            lastReportsToOrganizationCode);
                    loopCount++;
                    ;
                    if (ObjectUtils.isNull(tempOrg)) {
                        continueSearch = false;
                        // if a null is returned on the first iteration, then the reports-to org does not exist
                        // fail the validation
                        if (loopCount == 1) {
                            putFieldError("reportsToOrganizationCode",
                                    OLEKeyConstants.ERROR_DOCUMENT_ORGMAINT_REPORTING_ORG_MUST_EXIST);
                            success = false;
                        }
                    } else {
                        // on the first iteration, check whether the reports-to organization is active
                        if (loopCount == 1 && !tempOrg.isActive()) {
                            putFieldError("reportsToOrganizationCode",
                                    OLEKeyConstants.ERROR_DOCUMENT_ORGMAINT_REPORTING_ORG_MUST_EXIST);
                            success = false;
                            continueSearch = false;
                        } else {
                            // LOG.info("Found Org = " + lastReportsToChartOfAccountsCode + "/" +
                            // lastReportsToOrganizationCode);
                            lastReportsToChartOfAccountsCode = tempOrg.getReportsToChartOfAccountsCode();
                            lastReportsToOrganizationCode = tempOrg.getReportsToOrganizationCode();

                            if ((tempOrg.getReportsToChartOfAccountsCode()
                                    .equals(newOrg.getChartOfAccountsCode()))
                                    && (tempOrg.getReportsToOrganizationCode()
                                            .equals(newOrg.getOrganizationCode()))) {
                                putFieldError("reportsToOrganizationCode",
                                        OLEKeyConstants.ERROR_DOCUMENT_ORGMAINT_REPORTING_ORG_CANNOT_BE_CIRCULAR_REF_TO_SAME_ORG);
                                success = false;
                                continueSearch = false;
                            }
                        }
                    }
                    if (loopCount > maxLoopCount) {
                        continueSearch = false;
                    }
                    // stop the search if we reach an org that must report to itself
                    if (continueSearch && /*REFACTORME*/SpringContext.getBean(ParameterEvaluatorService.class)
                            .getParameterEvaluator(Organization.class,
                                    OLEConstants.ChartApcParms.ORG_MUST_REPORT_TO_SELF_ORG_TYPES,
                                    tempOrg.getOrganizationTypeCode())
                            .evaluationSucceeds()) {
                        continueSearch = false;
                    }

                } while (continueSearch == true);
            } // end else (checking for circular ref)
        } else { // org must report to self (university level organization)
            if (!(newOrg.getReportsToChartOfAccountsCode().equals(newOrg.getChartOfAccountsCode())
                    && newOrg.getReportsToOrganizationCode().equals(newOrg.getOrganizationCode()))) {
                putFieldError("reportsToOrganizationCode",
                        OLEKeyConstants.ERROR_DOCUMENT_ORGMAINT_REPORTING_ORG_MUST_BE_SAME_ORG);
                success = false;
            }
            // org must be the only one of that type
            String topLevelOrgTypeCode = SpringContext.getBean(ParameterService.class)
                    .getParameterValueAsString(Organization.class,
                            OLEConstants.ChartApcParms.ORG_MUST_REPORT_TO_SELF_ORG_TYPES);
            List<Organization> topLevelOrgs = orgService.getActiveOrgsByType(topLevelOrgTypeCode);
            if (!topLevelOrgs.isEmpty()) {
                // is the new org in the topLevelOrgs list? If not, then there's an error; if so, we're editing the top level
                // org
                if (!topLevelOrgs.contains(newOrg)) {
                    putFieldError("organizationTypeCode",
                            OLEKeyConstants.ERROR_DOCUMENT_ORGMAINT_ONLY_ONE_TOP_LEVEL_ORG,
                            topLevelOrgs.get(0).getChartOfAccountsCode() + "-"
                                    + topLevelOrgs.get(0).getOrganizationCode());
                    success = false;
                }
            }
        }
    }

    return success;
}

From source file:org.openiam.idm.srvc.synch.srcadapter.RDBMSAdapter.java

private Timestamp proccess(SynchConfig config, SynchReviewEntity review, ProvisionService provService,
        List<LineObject> part, final ValidationScript validationScript,
        final List<TransformScript> transformScripts, MatchObjectRule matchRule, SynchReviewEntity resultReview,
        int ctr) throws ClassNotFoundException {
    Timestamp mostRecentRecord = null;
    for (LineObject rowObj : part) {
        log.debug("-RDBMS ADAPTER: SYNCHRONIZING  RECORD # ---" + ctr++);
        log.debug(" - Record update time=" + rowObj.getLastUpdate());

        if (mostRecentRecord == null) {
            mostRecentRecord = rowObj.getLastUpdate();

        } else {/*from   www. j a  va  2 s  .  com*/
            // if current record is newer than what we saved, then update the most recent record value
            if (mostRecentRecord.before(rowObj.getLastUpdate())) {
                log.debug("- MostRecentRecord value updated to=" + rowObj.getLastUpdate());
                mostRecentRecord.setTime(rowObj.getLastUpdate().getTime());
            }
        }

        processLineObject(rowObj, config, resultReview, validationScript, transformScripts, matchRule);

    }
    return mostRecentRecord;
}