String fieldId = (String) getProperty("fieldId");
String mandatory = (String) getProperty("mandatory");
String regex = (String) getProperty("regex");
String errorMsg = (String) getProperty("errorMsg");
PluginManager pm = (PluginManager) AppUtil.getApplicationContext().getBean("pluginManager");
//Check is empty or not
if (isEmptyValues(values)) {
if ("true".equals(mandatory)) {
result = false;
data.addFormError(id, pm.getMessage("form.duplicatevaluevalidator.e.missingValue", this.getClassName(), null));
}
} else {
//check value format with regex
if (!isFormatCorrect(regex, values)) {
result = false;
if (errorMsg != null && errorMsg.trim().length() == 0) {
errorMsg = pm.getMessage("form.duplicatevaluevalidator.e.formatInvalid", this.getClassName(), null);
}
data.addFormError(id, errorMsg);
} else {
//check for duplicate value
AppDefinition appDef = AppUtil.getCurrentAppDefinition();
String tableName = null;
AppService appService = (AppService) AppUtil.getApplicationContext().getBean("appService");
if (formDefId != null) {
tableName = appService.getFormTableName(appDef, formDefId);
}
if (isDuplicate(formDefId, tableName, element, data, fieldId, values)) {
result = false;
data.addFormError(id, pm.getMessage("form.duplicatevaluevalidator.e.valueAlreadyExist", this.getClassName(), null));
}
}
}
return result;