diff options
author | Pavel Aharoni <pa0916@att.com> | 2017-04-27 17:52:06 +0300 |
---|---|---|
committer | Pavel Aharoni <pa0916@att.com> | 2017-04-27 17:53:52 +0300 |
commit | 04e7fa443307328986942c66fbcb01693c8f9ccb (patch) | |
tree | 7aca450c4cd4ae7a1c2fa7ecb83abcb513d3cfe9 /jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/parameters/Output.java | |
parent | 305a8611558f0e91d05ad3f5d954137cc8606d63 (diff) |
[SDC-13] fixing JTosca package declarations
Change-Id: I0741c743e50e9784c50cb59529d2188ce984d830
Signed-off-by: Pavel Aharoni <pa0916@att.com>
Diffstat (limited to 'jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/parameters/Output.java')
-rw-r--r-- | jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/parameters/Output.java | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/parameters/Output.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/parameters/Output.java new file mode 100644 index 0000000..e987996 --- /dev/null +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/parameters/Output.java @@ -0,0 +1,108 @@ +package org.openecomp.sdc.toscaparser.api.parameters; + +import java.util.LinkedHashMap; + +import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; + +public class Output { + + private static final String DESCRIPTION = "description"; + public static final String VALUE = "value"; + private static final String OUTPUTFIELD[] = {DESCRIPTION, VALUE}; + + private String name; + private LinkedHashMap<String,Object> attrs;//TYPE??? + + public Output(String oname,LinkedHashMap<String,Object> oattrs) { + name = oname; + attrs = oattrs; + } + + public String getDescription() { + return (String)attrs.get(DESCRIPTION); + } + + public Object getValue() { + return attrs.get(VALUE); + } + + public void validate() { + _validateField(); + } + + private void _validateField() { + if(!(attrs instanceof LinkedHashMap)) { + //TODO wrong error message... + ExceptionCollector.appendException(String.format( + "ValidationError: Output \"%s\" has wrong type. Expecting a dict", + name)); + } + + if(getValue() == null) { + ExceptionCollector.appendException(String.format( + "MissingRequiredFieldError: Output \"%s\" is missing required \"%s\"", + name,VALUE)); + } + for(String key: attrs.keySet()) { + boolean bFound = false; + for(String of: OUTPUTFIELD) { + if(key.equals(of)) { + bFound = true; + break; + } + } + if(!bFound) { + ExceptionCollector.appendException(String.format( + "UnknownFieldError: Output \"%s\" contains unknown field \"%s\"", + name,key)); + } + } + } + + // getter/setter + + public String getName() { + return name; + } + + public void setAttr(String name,Object value) { + attrs.put(name, value); + } +} + +/*python + +class Output(object): + + OUTPUTFIELD = (DESCRIPTION, VALUE) = ('description', 'value') + + def __init__(self, name, attrs): + self.name = name + self.attrs = attrs + + @property + def description(self): + return self.attrs.get(self.DESCRIPTION) + + @property + def value(self): + return self.attrs.get(self.VALUE) + + def validate(self): + self._validate_field() + + def _validate_field(self): + if not isinstance(self.attrs, dict): + ExceptionCollector.appendException( + MissingRequiredFieldError(what='Output "%s"' % self.name, + required=self.VALUE)) + if self.value is None: + ExceptionCollector.appendException( + MissingRequiredFieldError(what='Output "%s"' % self.name, + required=self.VALUE)) + for name in self.attrs: + if name not in self.OUTPUTFIELD: + ExceptionCollector.appendException( + UnknownFieldError(what='Output "%s"' % self.name, + field=name)) +*/ |