aboutsummaryrefslogtreecommitdiffstats
path: root/jtosca/src/main/java/org/openecomp/sdc/toscaparser/elements/constraints/ValidValues.java
diff options
context:
space:
mode:
authorPavel Aharoni <pa0916@att.com>2017-04-25 08:02:08 +0300
committerPavel Aharoni <pa0916@att.com>2017-04-25 08:02:33 +0300
commitecd529b4057f8619c9ef0d1c46d1bec5571f5b29 (patch)
tree7133ba1350516a03db982ea30228437ebf843536 /jtosca/src/main/java/org/openecomp/sdc/toscaparser/elements/constraints/ValidValues.java
parent9cb83cb1b15e93c95b1462fc2e3315b35dbc6c4d (diff)
[SDC-13] JTosca delivery - 1.1.8-SNAPSHOT DC
Change-Id: Ib6af5d9393473c3db3f1e21da570c71ea0944eca Signed-off-by: Pavel Aharoni <pa0916@att.com>
Diffstat (limited to 'jtosca/src/main/java/org/openecomp/sdc/toscaparser/elements/constraints/ValidValues.java')
-rw-r--r--jtosca/src/main/java/org/openecomp/sdc/toscaparser/elements/constraints/ValidValues.java84
1 files changed, 84 insertions, 0 deletions
diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/elements/constraints/ValidValues.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/elements/constraints/ValidValues.java
new file mode 100644
index 0000000..61e9cc2
--- /dev/null
+++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/elements/constraints/ValidValues.java
@@ -0,0 +1,84 @@
+package org.openecomp.sdc.toscaparser.elements.constraints;
+
+import java.util.ArrayList;
+
+public class ValidValues extends Constraint {
+
+
+ protected void _setValues() {
+
+ constraintKey = VALID_VALUES;
+
+ for(String s: Schema.PROPERTY_TYPES) {
+ validPropTypes.add(s);
+ }
+
+ }
+
+
+ public ValidValues(String name,String type,Object c) {
+ super(name,type,c);
+
+ }
+
+ @SuppressWarnings("unchecked")
+ protected boolean _isValid(Object val) {
+ if(!(constraintValue instanceof ArrayList)) {
+ return false;
+ }
+ if(val instanceof ArrayList) {
+ boolean bAll = true;
+ for(Object v: (ArrayList<Object>)val) {
+ if(!((ArrayList<Object>)constraintValue).contains(v)) {
+ bAll = false;
+ break;
+ };
+ }
+ return bAll;
+ }
+ return ((ArrayList<Object>)constraintValue).contains(val);
+ }
+
+ protected String _errMsg(Object value) {
+ return String.format("The value \"%s\" of property \"%s\" is not valid. Expected a value from \"%s\"",
+ value.toString(),propertyName,constraintValue.toString());
+ }
+
+}
+
+/*python
+
+class ValidValues(Constraint):
+"""Constraint class for "valid_values"
+
+Constrains a property or parameter to a value that is in the list of
+declared values.
+"""
+constraint_key = Constraint.VALID_VALUES
+
+valid_prop_types = Schema.PROPERTY_TYPES
+
+def __init__(self, property_name, property_type, constraint):
+ super(ValidValues, self).__init__(property_name, property_type,
+ constraint)
+ if not isinstance(self.constraint_value, collections.Sequence):
+ ExceptionCollector.appendException(
+ InvalidSchemaError(message=_('The property "valid_values" '
+ 'expects a list.')))
+
+def _is_valid(self, value):
+ print '*** payton parser validating ',value,' in ',self.constraint_value#GGG
+ if isinstance(value, list):
+ return all(v in self.constraint_value for v in value)
+ return value in self.constraint_value
+
+def _err_msg(self, value):
+ allowed = '[%s]' % ', '.join(str(a) for a in self.constraint_value)
+ return (_('The value "%(pvalue)s" of property "%(pname)s" is not '
+ 'valid. Expected a value from "%(cvalue)s".') %
+ dict(pname=self.property_name,
+ pvalue=value,
+ cvalue=allowed))
+
+
+*/ \ No newline at end of file