use of com.qlangtech.tis.plugin.annotation.Validator in project tis by qlangtech.
the class PropertyType method isInputRequired.
public boolean isInputRequired() {
if (inputRequired == null) {
inputRequired = false;
Validator[] validators = this.formField.validate();
for (Validator v : validators) {
if (v == Validator.require) {
return inputRequired = true;
}
}
}
return inputRequired;
}
use of com.qlangtech.tis.plugin.annotation.Validator in project tis by qlangtech.
the class Descriptor method isValid.
private boolean isValid(IControlMsgHandler msgHandler, Context context, boolean bizValidate, Optional<IPropertyType.SubFormFilter> subFormFilter, PluginFormProperties propertyTypes, PostFormVals postFormVals) {
Objects.requireNonNull(postFormVals, "postFormVals can not be null");
Map<String, JSONObject> formData = postFormVals.rawFormData;
boolean valid = true;
String attr;
PropertyType attrDesc;
JSONObject valJ;
String impl;
String attrVal;
for (Map.Entry<String, PropertyType> entry : propertyTypes.getKVTuples()) {
attr = entry.getKey();
attrDesc = entry.getValue();
valJ = formData.get(attr);
if (valJ == null && attrDesc.isInputRequired()) {
addFieldRequiredError(msgHandler, context, attr);
valid = false;
continue;
}
if (valJ == null) {
valJ = new JSONObject();
}
if (attrDesc.isDescribable()) {
JSONObject descVal = valJ.getJSONObject("descVal");
impl = descVal.getString("impl");
if (StringUtils.isBlank(impl)) {
addFieldRequiredError(msgHandler, context, attr);
valid = false;
continue;
}
AttrValMap attrValMap = AttrValMap.parseDescribableMap(msgHandler, subFormFilter, descVal);
pushFieldStack(context, attr, 0);
try {
if (!attrValMap.validate(context, bizValidate).isValid()) {
valid = false;
continue;
}
} finally {
popFieldStack(context);
}
} else {
if (attrDesc.typeIdentity() == FormFieldType.MULTI_SELECTABLE.getIdentity()) {
List<FormFieldType.SelectedItem> selectedItems = getSelectedMultiItems(valJ);
// }
if (selectedItems.size() < 1) {
// 没有选中
Validator[] validators = attrDesc.getValidator();
for (Validator v : validators) {
if (v == Validator.require) {
v.validate(msgHandler, context, attr, StringUtils.EMPTY);
}
}
} else if (this instanceof FormFieldType.IMultiSelectValidator) {
FormFieldType.IMultiSelectValidator multiSelectValidator = (FormFieldType.IMultiSelectValidator) this;
if (!multiSelectValidator.validate(msgHandler, subFormFilter, context, attr, selectedItems)) {
valid = false;
break;
}
}
} else {
// single value
boolean containVal = valJ.containsKey(KEY_primaryVal);
if (!containVal && attrDesc.isInputRequired()) {
addFieldRequiredError(msgHandler, context, attr);
valid = false;
continue;
}
if (containVal) {
attrVal = valJ.getString(KEY_primaryVal);
postFormVals.fieldVals.put(attr, attrVal);
Validator[] validators = attrDesc.getValidator();
for (Validator v : validators) {
if (!v.validate(msgHandler, context, attr, attrVal)) {
valid = false;
break;
}
}
try {
Method validateMethod = this.validateMethodMap.get(attr);
if (validateMethod != null && StringUtils.isNotEmpty(attrVal)) {
if (!(boolean) validateMethod.invoke(this, msgHandler, context, attr, attrVal)) {
valid = false;
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
}
}
// end for
return valid;
}
Aggregations