⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rundatabo.java

📁 A Java web application, based on Struts and Hibernate, that serves as an online running log. Users m
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

        value = getPace();
        valueObject.setValue(RunData.FIELD_PACE, value);

        value = getRoute();
        valueObject.setValue(RunData.FIELD_ROUTE, value);

        value = getRunType();
        valueObject.setValue(RunData.FIELD_RUN_TYPE, value);

        value = getShoes();
        valueObject.setValue(RunData.FIELD_SHOES, value);

        value = getComments();
        valueObject.setValue(RunData.FIELD_COMMENTS, value);

        if (LOG.isDebugEnabled()) {
            LOG.debug("getValuesInternal: Contents of the value object (after) "
                      + valueObject);
        }

        return valueObject;
    }

    /**
     * Update the BO's fields with the values provided in a data transfer
     * object.  This is a template method that is called from the final
     * <code>setValue</code> method in <code>BaseBO</code>.
     *
     * @param valueObject The data transfer object containing values to be
     *                    used in updating this BO
     * @throws ConversionException If a conversion error occurrs while setting
     *                             the fields
     * @see BaseBO#setValues(DTO)
     */
    protected void setValuesInternal(DTO valueObject)
                                                    throws ConversionException {
        if (LOG.isDebugEnabled()) {
            LOG.debug("setValuesInternal: Contents of the value object "
                      + valueObject);
        }

        super.setValuesInternal(valueObject);
        String value = null;

        value = valueObject.getValue(RunData.FIELD_DATE);
        setDate(Conversions.stringToDate(value));

        value = valueObject.getValue(RunData.FIELD_DISTANCE);
        setDistance(Conversions.stringToDecimal(value));

        value = valueObject.getValue(RunData.FIELD_UNITS);
        setUnits(value);

        value = valueObject.getValue(RunData.FIELD_TIME);
        setTime(Conversions.stringToTime(value));

        value = valueObject.getValue(RunData.FIELD_ROUTE);
        setRoute(value);

        value = valueObject.getValue(RunData.FIELD_RUN_TYPE);
        setRunType(value);

        value = valueObject.getValue(RunData.FIELD_SHOES);
        setShoes(value);

        value = valueObject.getValue(RunData.FIELD_COMMENTS);
        setComments(value);
    }

    /**
     * Validate the values contained in a data transfer object.  This method
     * is reponsible for perofrming all validations on the transfer object, and
     * should be called before updating the BO's fields to avoid
     * bad data and/or errors.
     *
     * @param valueObject The data transfer object whose fields are to be
     *                    validated
     * @return A list consisting of any errors found while validating the
     *         transfer object
     * @to.do v1.x Implement FK constraint checks for 3 reference values
     */
    protected List validateValues(DTO valueObject) {
        List errors = super.validateValues(valueObject);

        if (LOG.isDebugEnabled()) {
            LOG.debug("validateValues: Before validations, error list contains"
                      + errors.size() + " error(s)");
        }

        validateDateValue(valueObject, errors);
        validateDistanceValue(valueObject, errors);
        validateUnitsValue(valueObject, errors);
        validateTimeValue(valueObject, errors);

        // Need FK checks for these values
        validateRouteValue(valueObject, errors);
        validateRunTypeValue(valueObject, errors);
        validateShoesValue(valueObject, errors);

        validateCommentsValue(valueObject, errors);

        if (LOG.isDebugEnabled()) {
            LOG.debug("validateValues: After validations, error list contains"
                      + errors.size() + " error(s)");
        }

        return errors;
    }

    /**
     * Validate the <code>date</code> field value on a data transfer
     * object.
     *
     * @param valueObject The data transfer object containing the value(s) to
     *                    be validated
     * @param errors An error list, which this method may add to if there are
     *               any validation errors
     */
    private void validateDateValue(DTO valueObject, List errors) {
        String fieldName = RunData.FIELD_DATE;

        ValidationUtilities.executeRequiredFieldValidation(valueObject,
                                                           fieldName,
                                                           errors);

        ValidationUtilities.executeDateValidation(valueObject,
                                                  fieldName,
                                                  errors);
    }

    /**
     * Validate the <code>distance</code> field value on a data transfer
     * object.
     *
     * @param valueObject The data transfer object containing the value(s) to
     *                    be validated
     * @param errors An error list, which this method may add to if there are
     *               any validation errors
     */
    private void validateDistanceValue(DTO valueObject, List errors) {
        String fieldName = RunData.FIELD_DISTANCE;

        String units = valueObject.getValue(RunData.FIELD_UNITS);
        String unitsLabel = CanonicalUtilities.getLabel(RunData.CANONICAL_ID,
                                                        RunData.FIELD_UNITS);
        String distance = valueObject.getValue(RunData.FIELD_DISTANCE);
        String distLabel = CanonicalUtilities.getLabel(RunData.CANONICAL_ID,
                                                       RunData.FIELD_DISTANCE);

        boolean validNumber =
                       ValidationUtilities.executeDecimalValidation(valueObject,
                                                                    fieldName,
                                                                    errors);

        // Units cannot be entered unless distance is entered
        if (Utilities.isBlank(distance) && !Utilities.isBlank(units)) {
            String errorNumber =
                        ValidationUtilities.ERROR_FORBIDDEN_DEPENDENT_FIELD;
            String [] inserts = new String[] {unitsLabel, distLabel};
            errors.add(new ValidationError(errorNumber, inserts));
        }

        // Units must not be blank when distance is entered
        if (!Utilities.isBlank(distance) && Utilities.isBlank(units)) {
            String errorNumber =
                         ValidationUtilities.ERROR_REQUIRED_DEPENDENT_FIELD;
            String [] inserts = new String [] {unitsLabel, distLabel};
            errors.add(new ValidationError(errorNumber, inserts));
        }

        if (!Utilities.isBlank(distance) && validNumber) {
                ValidationUtilities.executeMinValueValidation(valueObject,
                                                              fieldName,
                                                              errors);

                ValidationUtilities.executeMaxValueValidation(valueObject,
                                                              fieldName,
                                                              errors);
        }
    }

    /**
     * Validate the <code>units</code> field value on a data transfer
     * object.
     *
     * @param valueObject The data transfer object containing the value(s) to
     *                    be validated
     * @param errors An error list, which this method may add to if there are
     *               any validation errors
     */
    private void validateUnitsValue(DTO valueObject, List errors) {
        String fieldName = RunData.FIELD_UNITS;

        ValidationUtilities.executeValidValuesValidation(valueObject,
                                                         fieldName,
                                                         errors);
    }

    /**
     * Validate the <code>time</code> field value on a data transfer
     * object.
     *
     * @param valueObject The data transfer object containing the value(s) to
     *                    be validated
     * @param errors An error list, which this method may add to if there are
     *               any validation errors
     */
    private void validateTimeValue(DTO valueObject, List errors) {
        String fieldName = RunData.FIELD_TIME;

        ValidationUtilities.executeTimeValidation(valueObject,
                                                  fieldName,
                                                  errors);
    }

    /**
     * Validate the <code>route</code> field value on a data transfer
     * object.
     *
     * @param valueObject The data transfer object containing the value(s) to
     *                    be validated
     * @param errors An error list, which this method may add to if there are
     *               any validation errors
     */
    private void validateRouteValue(DTO valueObject, List errors) {
        String fieldName = RunData.FIELD_ROUTE;

        ValidationUtilities.executeMaxLengthValidation(valueObject,
                                                       fieldName,
                                                       errors);
    }

    /**
     * Validate the <code>run type</code> field value on a data transfer
     * object.
     *
     * @param valueObject The data transfer object containing the value(s) to
     *                    be validated
     * @param errors An error list, which this method may add to if there are
     *               any validation errors
     */
    private void validateRunTypeValue(DTO valueObject, List errors) {
        String fieldName = RunData.FIELD_RUN_TYPE;

        ValidationUtilities.executeMaxLengthValidation(valueObject,
                                                       fieldName,
                                                       errors);
    }

    /**
     * Validate the <code>shoes</code> field value on a data transfer
     * object.
     *
     * @param valueObject The data transfer object containing the value(s) to
     *                    be validated
     * @param errors An error list, which this method may add to if there are
     *               any validation errors
     */
    private void validateShoesValue(DTO valueObject, List errors) {
        String fieldName = RunData.FIELD_SHOES;

        ValidationUtilities.executeMaxLengthValidation(valueObject,
                                                       fieldName,
                                                       errors);
    }

    /**
     * Validate the <code>comments</code> field value on a data transfer
     * object.
     *
     * @param valueObject The data transfer object containing the value(s) to
     *                    be validated
     * @param errors An error list, which this method may add to if there are
     *               any validation errors
     */
    private void validateCommentsValue(DTO valueObject, List errors) {
        String fieldName = RunData.FIELD_COMMENTS;

        ValidationUtilities.executeMaxLengthValidation(valueObject,
                                                       fieldName,
                                                       errors);
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -