2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.sdc.toscaparser.api.parameters;
23 import org.onap.sdc.toscaparser.api.common.JToscaValidationIssue;
24 import org.onap.sdc.toscaparser.api.utils.ThreadLocalsHolder;
26 import java.util.LinkedHashMap;
30 private static final String DESCRIPTION = "description";
31 public static final String VALUE = "value";
32 private static final String[] OUTPUT_FIELD = {DESCRIPTION, VALUE};
35 private LinkedHashMap<String, Object> attributes;
37 public Output(String name, LinkedHashMap<String, Object> attributes) {
39 this.attributes = attributes;
42 public String getDescription() {
43 return (String) attributes.get(DESCRIPTION);
46 public Object getValue() {
47 return attributes.get(VALUE);
50 public void validate() {
54 private void validateField() {
55 if (attributes == null) {
56 //TODO wrong error message...
57 ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE216", String.format(
58 "ValidationError: Output \"%s\" has wrong type. Expecting a dict",
62 if (getValue() == null) {
63 ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE217", String.format(
64 "MissingRequiredFieldError: Output \"%s\" is missing required \"%s\"",
67 for (String key : attributes.keySet()) {
68 boolean bFound = false;
69 for (String of : OUTPUT_FIELD) {
76 ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE218", String.format(
77 "UnknownFieldError: Output \"%s\" contains unknown field \"%s\"",
85 public String getName() {
89 public void setAttr(String name, Object value) {
90 attributes.put(name, value);
98 OUTPUT_FIELD = (DESCRIPTION, VALUE) = ('description', 'value')
100 def __init__(self, name, attributes):
102 self.attributes = attributes
105 def description(self):
106 return self.attributes.get(self.DESCRIPTION)
110 return self.attributes.get(self.VALUE)
113 self._validate_field()
115 def _validate_field(self):
116 if not isinstance(self.attributes, dict):
117 ValidationIssueCollector.appendException(
118 MissingRequiredFieldError(what='Output "%s"' % self.name,
119 required=self.VALUE))
120 if self.value is None:
121 ValidationIssueCollector.appendException(
122 MissingRequiredFieldError(what='Output "%s"' % self.name,
123 required=self.VALUE))
124 for name in self.attributes:
125 if name not in self.OUTPUT_FIELD:
126 ValidationIssueCollector.appendException(
127 UnknownFieldError(what='Output "%s"' % self.name,