protected void validateBooleanFields (String[] fieldNames, boolean areRequiredFields, Map<String, Object> conf) throws ComponentConfigException { for (String fieldName : fieldNames) { Object value = conf.get(fieldName); boolean isValid = true; if (areRequiredFields) { // validate no matter what for required fields if (!ConfigFieldValidation.isBoolean(value)) { isValid = false; } } else { // for optional fields validate only if user updated the // default value which means UI put it in json if ((value != null) && !ConfigFieldValidation.isBoolean(value)) { isValid = false; } } if (!isValid) { throw new ComponentConfigException(String.format(TopologyLayoutConstants.ERR_MSG_MISSING_INVALID_CONFIG, fieldName)); } } }
protected void validateFloatOrDoubleFields (String[] fieldNames, boolean areRequiredFields) throws ComponentConfigException { for (String fieldName : fieldNames) { Object value = conf.get(fieldName); boolean isValid = true; if (areRequiredFields) { // validate no matter what for required fields if (!ConfigFieldValidation.isFloatOrDouble(value)) { isValid = false; } } else { // for optional fields validate only if user updated the // default value which means UI put it in json if ((value != null) && !ConfigFieldValidation.isFloatOrDouble(value)) { isValid = false; } } if (!isValid) { throw new ComponentConfigException(String.format(TopologyLayoutConstants.ERR_MSG_MISSING_INVALID_CONFIG, fieldName)); } } }
protected void validateLongFields (String[] fieldNames, boolean areRequiredFields, Long[] mins, Long[] maxes) throws ComponentConfigException { if ((fieldNames == null) || (fieldNames.length != mins.length) || (fieldNames.length != maxes.length)) { return; } for (int i = 0; i < fieldNames.length; ++i) { String fieldName = fieldNames[i]; Object value = conf.get(fieldName); Long min = mins[i]; Long max = maxes[i]; boolean isValid = true; if (areRequiredFields) { // validate no matter what for required fields if (!ConfigFieldValidation.isLongAndInRange(value, min, max)) { isValid = false; } } else { // for optional fields validate only if user updated the // default value which means UI put it in json if ((value != null) && !ConfigFieldValidation.isLongAndInRange(value, min, max)) { isValid = false; } } if (!isValid) { throw new ComponentConfigException(String.format(TopologyLayoutConstants.ERR_MSG_MISSING_INVALID_CONFIG, fieldName)); } } }
protected void validateIntegerFields (String[] fieldNames, boolean areRequiredFields, Integer[] mins, Integer[] maxes, Map<String, Object> conf) throws ComponentConfigException { if ((fieldNames == null) || (fieldNames.length != mins.length) || (fieldNames.length != maxes.length)) { return; } for (int i = 0; i < fieldNames.length; ++i) { String fieldName = fieldNames[i]; Object value = conf.get(fieldName); Integer min = mins[i]; Integer max = maxes[i]; boolean isValid = true; if (areRequiredFields) { // validate no matter what for required fields if (!ConfigFieldValidation.isIntAndInRange(value, min, max)) { isValid = false; } } else { // for optional fields validate only if user updated the // default value which means UI put it in json if ((value != null) && !ConfigFieldValidation.isIntAndInRange(value, min, max)) { isValid = false; } } if (!isValid) { throw new ComponentConfigException(String.format(TopologyLayoutConstants.ERR_MSG_MISSING_INVALID_CONFIG, fieldName)); } } }
protected void validateShortFields (String[] fieldNames, boolean areRequiredFields, Short[] mins, Short[] maxes) throws ComponentConfigException { if ((fieldNames == null) || (fieldNames.length != mins.length) || (fieldNames.length != maxes.length)) { return; } for (int i = 0; i < fieldNames.length; ++i) { String fieldName = fieldNames[i]; Object value = conf.get(fieldName); Short min = mins[i]; Short max = maxes[i]; boolean isValid = true; if (areRequiredFields) { // validate no matter what for required fields if (!ConfigFieldValidation.isShortAndInRange(value, min, max)) { isValid = false; } } else { // for optional fields validate only if user updated the // default value which means UI put it in json if ((value != null) && !ConfigFieldValidation.isShortAndInRange(value, min, max)) { isValid = false; } } if (!isValid) { throw new ComponentConfigException(String.format(TopologyLayoutConstants.ERR_MSG_MISSING_INVALID_CONFIG, fieldName)); } } }
protected void validateByteFields (String[] fieldNames, boolean areRequiredFields, Byte[] mins, Byte[] maxes) throws ComponentConfigException { if ((fieldNames == null) || (fieldNames.length != mins.length) || (fieldNames.length != maxes.length)) { return; } for (int i = 0; i < fieldNames.length; ++i) { String fieldName = fieldNames[i]; Object value = conf.get(fieldName); Byte min = mins[i]; Byte max = maxes[i]; boolean isValid = true; if (areRequiredFields) { // validate no matter what for required fields if (!ConfigFieldValidation.isByteAndInRange(value, min, max)) { isValid = false; } } else { // for optional fields validate only if user updated the // default value which means UI put it in json if ((value != null) && !ConfigFieldValidation.isByteAndInRange(value, min, max)) { isValid = false; } } if (!isValid) { throw new ComponentConfigException(String.format(TopologyLayoutConstants.ERR_MSG_MISSING_INVALID_CONFIG, fieldName)); } } }