use of org.akaza.openclinica.bean.core.TermType in project OpenClinica by OpenClinica.
the class Validator method validate.
protected HashMap validate(String fieldName, Validation v) {
switch(v.getType()) {
case NO_BLANKS:
if (isBlank(fieldName)) {
addError(fieldName, v);
}
break;
case IS_A_NUMBER:
if (!isNumber(fieldName)) {
addError(fieldName, v);
}
break;
case IS_IN_RANGE:
float lowerBound = v.getFloat(0);
float upperBound = v.getFloat(1);
if (!isInRange(fieldName, lowerBound, upperBound)) {
addError(fieldName, v);
}
break;
case IS_A_DATE:
if (!isDate(fieldName)) {
addError(fieldName, v);
}
break;
case IS_DATE_TIME:
if (!isDateTime(fieldName)) {
addError(fieldName, v);
}
break;
case CHECK_SAME:
String compareField = v.getString(0);
if (!isSame(fieldName, compareField)) {
addError(fieldName, v);
}
break;
case IS_A_EMAIL:
if (!isEmail(fieldName)) {
addError(fieldName, v);
}
break;
case IS_A_PHONE_NUMBER:
if (!isPhoneNumber(fieldName)) {
addError(fieldName, v);
}
break;
case ENTITY_EXISTS:
EntityDAO edao = (EntityDAO) v.getArg(0);
if (!entityExists(fieldName, edao)) {
addError(fieldName, v);
}
break;
case ENTITY_EXISTS_IN_STUDY:
AuditableEntityDAO dao = (AuditableEntityDAO) v.getArg(0);
StudyBean study = (StudyBean) v.getArg(1);
if (!entityExistsInStudy(fieldName, dao, study)) {
addError(fieldName, v);
}
break;
case USERNAME_UNIQUE:
UserAccountDAO udao = (UserAccountDAO) v.getArg(0);
if (!usernameUnique(fieldName, udao)) {
addError(fieldName, v);
}
break;
case IS_AN_INTEGER:
if (!isInteger(fieldName)) {
addError(fieldName, v);
}
break;
// break;
case IS_IN_SET:
ArrayList set = (ArrayList) v.getArg(0);
if (!isInSet(fieldName, set)) {
addError(fieldName, v);
}
break;
case IS_A_PASSWORD:
if (!lengthComparesToStaticValue(fieldName, NumericComparisonOperator.GREATER_THAN_OR_EQUAL_TO, PASSWORD_MINIMUM_LENGTH)) {
addError(fieldName, v);
}
break;
case IS_A_USERNAME:
if (!isUsername(fieldName)) {
addError(fieldName, v);
}
break;
case IS_VALID_TERM:
TermType termType = (TermType) v.getArg(0);
if (!isValidTerm(fieldName, termType)) {
addError(fieldName, v);
}
break;
case COMPARES_TO_STATIC_VALUE:
NumericComparisonOperator operator = (NumericComparisonOperator) v.getArg(0);
float compareTo = v.getFloat(1);
if (!comparesToStaticValue(fieldName, operator, compareTo)) {
addError(fieldName, v);
}
break;
case LENGTH_NUMERIC_COMPARISON:
NumericComparisonOperator operator2 = (NumericComparisonOperator) v.getArg(0);
int compareTo2 = v.getInt(1);
if (!lengthComparesToStaticValue(fieldName, operator2, compareTo2)) {
addError(fieldName, v);
}
break;
case DATE_IS_AFTER_OR_EQUAL:
String earlierDateFieldName = v.getString(0);
if (!isDateAfterOrEqual(fieldName, earlierDateFieldName)) {
addError(fieldName, v);
}
break;
case NO_BLANKS_SET:
if (isSetBlank(fieldName)) {
addError(fieldName, v);
}
break;
case IN_RESPONSE_SET:
ResponseSetBean rsb = (ResponseSetBean) v.getArg(0);
if (!isInResponseSet(fieldName, rsb, true)) {
addError(fieldName, v);
}
break;
case IN_RESPONSE_SET_COMMA_SEPERATED:
ResponseSetBean rsbs = (ResponseSetBean) v.getArg(0);
if (!isInResponseSetCommaSeperated(fieldName, rsbs, true)) {
addError(fieldName, v);
}
break;
case IN_RESPONSE_SET_SINGLE_VALUE:
ResponseSetBean rsbSingle = (ResponseSetBean) v.getArg(0);
if (!isInResponseSet(fieldName, rsbSingle, false)) {
addError(fieldName, v);
}
break;
case MATCHES_INITIAL_DATA_ENTRY_VALUE:
String oldValue = v.getString(0);
boolean isMultiple = v.getBoolean(1);
if (!valueMatchesInitialValue(fieldName, oldValue, isMultiple)) {
addError(fieldName, v);
}
break;
case DIFFERENT_NUMBER_OF_GROUPS_IN_DDE:
addError(fieldName, v);
break;
case IS_REQUIRED:
if (isBlank(fieldName)) {
addError(fieldName, v);
}
break;
case DATE_IN_PAST:
if (!isDateInPast(fieldName)) {
addError(fieldName, v);
}
break;
case MATCHES_REGULAR_EXPRESSION:
if (!matchesRegex(fieldName, v.getString(0))) {
addError(fieldName, v);
}
break;
case CHECK_DIFFERENT:
String old = v.getString(0);
if (isSame(fieldName, old)) {
addError(fieldName, v);
}
break;
case IS_A_DATE_WITHOUT_REQUIRED_CHECK:
if (!isDateWithoutRequiredCheck(fieldName)) {
addError(fieldName, v);
}
break;
case CALCULATION_FAILED:
addError(fieldName, v);
break;
case IS_AN_RULE:
ArrayList<String> messages = (ArrayList<String>) v.getArg(0);
StringBuffer sb = new StringBuffer();
for (int i = 0; i < messages.size(); i++) {
sb.append(messages.get(i));
if (i != messages.size() - 1)
sb.append(" , ");
logger.debug(messages.get(i));
}
v.setErrorMessage(sb.toString());
addError(fieldName, v);
break;
case IS_PARTIAL_DATE:
boolean isPDate = Boolean.FALSE;
String fieldValue = getFieldValue(fieldName);
if (fieldValue != null) {
// resformat.getString("date_format_string"))) {
if (StringUtil.isFormatDate(fieldValue, resformat.getString("date_format_string")) || StringUtil.isPartialYear(fieldValue, "yyyy") || StringUtil.isPartialYearMonth(fieldValue, resformat.getString("date_format_year_month"))) {
isPDate = true;
}
}
if (!isPDate) {
addError(fieldName, v);
}
break;
case IS_VALID_WIDTH_DECIMAL:
ArrayList<String> params = (ArrayList<String>) v.getArg(0);
String dataType = params.get(0);
String widthDecimal = params.get(1);
StringBuffer error = this.validateFieldWidthDecimal(fieldName, dataType, widthDecimal);
if (error.length() > 0) {
addError(fieldName, error.toString());
}
break;
case BARCODE_EAN_13:
EanCheckDigit eanChk = new EanCheckDigit();
if (!eanChk.isValid(getFieldValue(fieldName))) {
addError(fieldName, v);
}
break;
case TO_HIDE_CONDITIONAL_DISPLAY:
addError(fieldName, v);
break;
}
return errors;
}
Aggregations