本文整理汇总了Java中org.kuali.rice.krad.datadictionary.validation.constraint.WhenConstraint类的典型用法代码示例。如果您正苦于以下问题:Java WhenConstraint类的具体用法?Java WhenConstraint怎么用?Java WhenConstraint使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WhenConstraint类属于org.kuali.rice.krad.datadictionary.validation.constraint包,在下文中一共展示了WhenConstraint类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processCaseConstraint
import org.kuali.rice.krad.datadictionary.validation.constraint.WhenConstraint; //导入依赖的package包/类
/**
* This method processes a single CaseConstraint. Internally it makes calls to
* processWhenConstraint for each WhenConstraint that exists in this constraint. It adds a
* "dependsOn" css class to this field for the field which the CaseConstraint references.
*
* @param field input field
* @param view active view
* @param constraint case constraint providing the field reference
* @param andedCase the boolean logic to be anded when determining if this case is satisfied
* (used for nested CaseConstraints)
* @param validationState validation state
* @param stateMapping state mapping
*/
public static void processCaseConstraint(InputField field, View view, CaseConstraint constraint, String andedCase,
String validationState, StateMapping stateMapping) {
if (constraint.getOperator() == null) {
constraint.setOperator("equals");
}
String operator = "==";
if (constraint.getOperator().equalsIgnoreCase("not_equals") || constraint.getOperator().equalsIgnoreCase(
"not_equal")) {
operator = "!=";
} else if (constraint.getOperator().equalsIgnoreCase("greater_than_equal")) {
operator = ">=";
} else if (constraint.getOperator().equalsIgnoreCase("less_than_equal")) {
operator = "<=";
} else if (constraint.getOperator().equalsIgnoreCase("greater_than")) {
operator = ">";
} else if (constraint.getOperator().equalsIgnoreCase("less_than")) {
operator = "<";
} else if (constraint.getOperator().equalsIgnoreCase("has_value")) {
operator = "";
}
// add more operator types here if more are supported later
field.getControl().addStyleClass("dependsOn-" + ScriptUtils.escapeName(constraint.getPropertyName()));
if (constraint.getWhenConstraint() != null && !constraint.getWhenConstraint().isEmpty()) {
//String fieldPath = field.getBindingInfo().getBindingObjectPath() + "." + constraint.getPropertyName();
String fieldPath = constraint.getPropertyName();
for (WhenConstraint wc : constraint.getWhenConstraint()) {
wc = ConstraintStateUtils.getApplicableConstraint(wc, validationState, stateMapping);
if (wc != null) {
processWhenConstraint(field, view, constraint, wc, ScriptUtils.escapeName(fieldPath), operator,
andedCase, validationState, stateMapping);
}
}
}
}
示例2: processCaseConstraint
import org.kuali.rice.krad.datadictionary.validation.constraint.WhenConstraint; //导入依赖的package包/类
/**
* This method processes a single CaseConstraint. Internally it makes calls
* to processWhenConstraint for each WhenConstraint that exists in this
* constraint. It adds a "dependsOn" css class to this field for the field
* which the CaseConstraint references.
*
* @param view
* @param andedCase the boolean logic to be anded when determining if this case is
* satisfied (used for nested CaseConstraints)
*/
public static void processCaseConstraint(InputField field, View view, CaseConstraint constraint, String andedCase,
String validationState, StateMapping stateMapping) {
if (constraint.getOperator() == null) {
constraint.setOperator("equals");
}
String operator = "==";
if (constraint.getOperator().equalsIgnoreCase("not_equals") || constraint.getOperator().equalsIgnoreCase(
"not_equal")) {
operator = "!=";
} else if (constraint.getOperator().equalsIgnoreCase("greater_than_equal")) {
operator = ">=";
} else if (constraint.getOperator().equalsIgnoreCase("less_than_equal")) {
operator = "<=";
} else if (constraint.getOperator().equalsIgnoreCase("greater_than")) {
operator = ">";
} else if (constraint.getOperator().equalsIgnoreCase("less_than")) {
operator = "<";
} else if (constraint.getOperator().equalsIgnoreCase("has_value")) {
operator = "";
}
// add more operator types here if more are supported later
field.getControl().addStyleClass("dependsOn-" + ScriptUtils.escapeName(constraint.getPropertyName()));
if (constraint.getWhenConstraint() != null && !constraint.getWhenConstraint().isEmpty()) {
//String fieldPath = field.getBindingInfo().getBindingObjectPath() + "." + constraint.getPropertyName();
String fieldPath = constraint.getPropertyName();
for (WhenConstraint wc : constraint.getWhenConstraint()) {
wc = ConstraintStateUtils.getApplicableConstraint(wc, validationState, stateMapping);
if (wc != null) {
processWhenConstraint(field, view, constraint, wc, ScriptUtils.escapeName(fieldPath), operator,
andedCase, validationState, stateMapping);
}
}
}
}
示例3: processWhenConstraint
import org.kuali.rice.krad.datadictionary.validation.constraint.WhenConstraint; //导入依赖的package包/类
/**
* This method processes the WhenConstraint passed in. The when constraint is used to create a
* boolean statement to determine if the constraint will be applied. The necessary rules/methods
* for applying this constraint are created in the createRule call. Note the use of the use of
* coerceValue js function call.
*
* @param view
* @param wc
* @param fieldPath
* @param operator
* @param andedCase
*/
private static void processWhenConstraint(InputField field, View view, CaseConstraint caseConstraint,
WhenConstraint wc, String fieldPath, String operator, String andedCase, String validationState,
StateMapping stateMapping) {
String ruleString = "";
// prerequisite constraint
String booleanStatement = "";
if (wc.getValues() != null) {
String caseStr = "";
if (!caseConstraint.isCaseSensitive()) {
caseStr = ".toUpperCase()";
}
for (int i = 0; i < wc.getValues().size(); i++) {
if (operator.isEmpty()) {
// has_value case
if (wc.getValues().get(i) instanceof String && ((String) wc.getValues().get(i)).equalsIgnoreCase(
"false")) {
booleanStatement = booleanStatement + "(coerceValue('" + fieldPath + "') == '')";
} else {
booleanStatement = booleanStatement + "(coerceValue('" + fieldPath + "') != '')";
}
} else {
// everything else
booleanStatement = booleanStatement
+ "(coerceValue('"
+ fieldPath
+ "')"
+ caseStr
+ " "
+ operator
+ " \""
+ wc.getValues().get(i)
+ "\""
+ caseStr
+ ")";
}
if ((i + 1) != wc.getValues().size()) {
booleanStatement = booleanStatement + " || ";
}
}
}
if (andedCase != null) {
booleanStatement = "(" + booleanStatement + ") && (" + andedCase + ")";
}
if (wc.getConstraint() != null && StringUtils.isNotEmpty(booleanStatement)) {
Constraint constraint = ConstraintStateUtils.getApplicableConstraint(wc.getConstraint(), validationState,
stateMapping);
if (constraint != null) {
ruleString = createRule(field, constraint, booleanStatement, view, validationState, stateMapping);
}
}
if (StringUtils.isNotEmpty(ruleString)) {
addScriptToPage(view, field, ruleString);
}
}
示例4: process
import org.kuali.rice.krad.datadictionary.validation.constraint.WhenConstraint; //导入依赖的package包/类
/**
* @see org.kuali.rice.krad.datadictionary.validation.processor.ConstraintProcessor#process(org.kuali.rice.krad.datadictionary.validation.result.DictionaryValidationResult,
* Object, org.kuali.rice.krad.datadictionary.validation.constraint.Constraint,
* org.kuali.rice.krad.datadictionary.validation.AttributeValueReader)
*/
@Override
public ProcessorResult process(DictionaryValidationResult result, Object value, CaseConstraint caseConstraint,
AttributeValueReader attributeValueReader) throws AttributeValidationException {
// Don't process this constraint if it's null
if (null == caseConstraint) {
return new ProcessorResult(result.addNoConstraint(attributeValueReader, CONSTRAINT_NAME));
}
AttributeValueReader constraintAttributeReader = attributeValueReader.clone();
String operator = (ValidationUtils.hasText(caseConstraint.getOperator())) ? caseConstraint.getOperator() :
"EQUALS";
AttributeValueReader fieldPathReader = (ValidationUtils.hasText(caseConstraint.getPropertyName())) ?
getChildAttributeValueReader(caseConstraint.getPropertyName(), attributeValueReader) :
attributeValueReader;
Constrainable caseField = (null != fieldPathReader) ? fieldPathReader.getDefinition(
fieldPathReader.getAttributeName()) : null;
Object fieldValue = (null != fieldPathReader) ? fieldPathReader.getValue(fieldPathReader.getAttributeName()) :
value;
DataType fieldDataType = (null != caseField && caseField instanceof DataTypeConstraint) ?
((DataTypeConstraint) caseField).getDataType() : null;
// Default to a string comparison
if (fieldDataType == null) {
fieldDataType = DataType.STRING;
}
// If fieldValue is null then skip Case check
if (null == fieldValue) {
// FIXME: not sure if the definition and attribute value reader should change under this case
return new ProcessorResult(result.addSkipped(attributeValueReader, CONSTRAINT_NAME), caseField,
fieldPathReader);
}
List<Constraint> constraints = new ArrayList<Constraint>();
// Extract value for field Key
for (WhenConstraint wc : caseConstraint.getWhenConstraint()) {
evaluateWhenConstraint(fieldValue, fieldDataType, operator, caseConstraint, wc, attributeValueReader,
constraints);
}
if (!constraints.isEmpty()) {
return new ProcessorResult(result.addSuccess(attributeValueReader, CONSTRAINT_NAME), null,
constraintAttributeReader, constraints);
}
// Assuming that not finding any case constraints is equivalent to 'skipping' the constraint
return new ProcessorResult(result.addSkipped(attributeValueReader, CONSTRAINT_NAME));
}
示例5: processWhenConstraint
import org.kuali.rice.krad.datadictionary.validation.constraint.WhenConstraint; //导入依赖的package包/类
/**
* This method processes the WhenConstraint passed in. The when constraint
* is used to create a boolean statement to determine if the constraint will
* be applied. The necessary rules/methods for applying this constraint are
* created in the createRule call. Note the use of the use of coerceValue js
* function call.
*
* @param view
* @param wc
* @param fieldPath
* @param operator
* @param andedCase
*/
private static void processWhenConstraint(InputField field, View view, CaseConstraint caseConstraint,
WhenConstraint wc, String fieldPath, String operator, String andedCase, String validationState,
StateMapping stateMapping) {
String ruleString = "";
// prerequisite constraint
String booleanStatement = "";
if (wc.getValues() != null) {
String caseStr = "";
if (!caseConstraint.isCaseSensitive()) {
caseStr = ".toUpperCase()";
}
for (int i = 0; i < wc.getValues().size(); i++) {
if (operator.isEmpty()) {
// has_value case
if (wc.getValues().get(i) instanceof String && ((String) wc.getValues().get(i)).equalsIgnoreCase(
"false")) {
booleanStatement = booleanStatement + "(coerceValue('" + fieldPath + "') == '')";
} else {
booleanStatement = booleanStatement + "(coerceValue('" + fieldPath + "') != '')";
}
} else {
// everything else
booleanStatement = booleanStatement
+ "(coerceValue('"
+ fieldPath
+ "')"
+ caseStr
+ " "
+ operator
+ " \""
+ wc.getValues().get(i)
+ "\""
+ caseStr
+ ")";
}
if ((i + 1) != wc.getValues().size()) {
booleanStatement = booleanStatement + " || ";
}
}
}
if (andedCase != null) {
booleanStatement = "(" + booleanStatement + ") && (" + andedCase + ")";
}
if (wc.getConstraint() != null && StringUtils.isNotEmpty(booleanStatement)) {
Constraint constraint = ConstraintStateUtils.getApplicableConstraint(wc.getConstraint(), validationState,
stateMapping);
if (constraint != null) {
ruleString = createRule(field, constraint, booleanStatement, view, validationState, stateMapping);
}
}
if (StringUtils.isNotEmpty(ruleString)) {
addScriptToPage(view, field, ruleString);
}
}