aboutsummaryrefslogtreecommitdiffstats
path: root/sdc-distribution-client/src/main/java/org/onap/sdc/utils/heat/HeatParameter.java
blob: 3638bcfc2afd88afa856171523cbf5b7479d8c7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*-
 * ============LICENSE_START=======================================================
 * sdc-distribution-client
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.onap.sdc.utils.heat;

import java.util.ArrayList;
import java.util.List;

public class HeatParameter{

	String type;
	String label;
	String description;
	//This is in order to workaround "default" field in HeatParameterEntry, since default is Java keyword
	//YAML constructor will lowercase it during parsing	
	String Default;
	String hidden = "false";//Default value according to OpenStack spec
	List<HeatParameterConstraint> constraints;



	public String getHidden() {
		return hidden;
	}
	public void setHidden(String hidden) {
		this.hidden = hidden;
	}

	public List<HeatParameterConstraint> getConstraints() {
		return constraints;
	}
	public void setConstraints(List<HeatParameterConstraint> constraints) {
		this.constraints = constraints;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public String getLabel() {
		return label;
	}
	public void setLabel(String label) {
		this.label = label;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public String getDefault() {
		return Default;
	}
	public void setDefault(String default1) {
		Default = default1;
	}
	
	

	// Getting specific constraints
	/**
	 * Get the first "length" constraint from HEAT parameter.
	 * No additional "length" constraint is searched for.
	 * 
	 * @return first "length" constraint found for this parameter,
	 * or null if no such constraint exists. 
	 */
	public HeatParameterConstraint getLengthConstraint(){
		HeatParameterConstraint res = null;
		if (constraints != null){
			for (HeatParameterConstraint entry : constraints){
				if (entry.getLength() != null){
					res = entry;
					break;
				}
			}
		}
		return res;
	}


	/**
	 * Get the first "range" constraint from HEAT parameter.
	 * No additional "range" constraint is searched for.
	 * 
	 * @return first "range" constraint found for this parameter,
	 * or null if no such constraint exists. 
	 */
	public HeatParameterConstraint getRangeConstraint(){
		HeatParameterConstraint res = null;
		if (constraints != null){
			for (HeatParameterConstraint entry : constraints){
				if (entry.getRange() != null){
					res = entry;
					break;
				}
			}
		}
		return res;
	}

	/**
	 * Get the first "allowed_values" constraint from HEAT parameter.
	 * No additional "allowed_values" constraint is searched for.
	 * 
	 * @return first "allowed_values" constraint found for this parameter,
	 * or null if no such constraint exists. 
	 */
	public HeatParameterConstraint getAllowedValuesConstraint(){
		HeatParameterConstraint res = null;
		if (constraints != null){
			for (HeatParameterConstraint entry : constraints){
				if (entry.getAllowed_values() != null){
					res = entry;
					break;
				}
			}
		}
		return res;
	}

	/**
	 * Get the "allowed_pattern" constraint list from HEAT parameter.
	 * 
	 * @return "allowed_pattern" constraint list found for this parameter,
	 * or null if no such constraint exists. 
	 */
	public List<HeatParameterConstraint> getAllowedPatternConstraint(){
		List<HeatParameterConstraint> res = null;
		if (constraints != null){
			for (HeatParameterConstraint entry : constraints){
				if (entry.getAllowed_pattern() != null){
					if (res == null){
						res = new ArrayList<>();
					}
					res.add(entry);
				}
			}
		}
		return res;
	}

	/**
	 * Get the "custom_constraint" constraint list from HEAT parameter.
	 * 
	 * @return "custom_constraint" constraint list found for this parameter,
	 * or null if no such constraint exists. 
	 */
	public List<HeatParameterConstraint> getCustomConstraintConstraint(){
		List<HeatParameterConstraint> res = null;
		if (constraints != null){
			for (HeatParameterConstraint entry : constraints){
				if (entry.getCustom_constraint() != null){
					if (res == null){
						res = new ArrayList<>();
					}
					res.add(entry);
				}
			}
		}
		return res;
	}
	
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		if (type != null){
			sb.append("type:"+type+", ");
		} 
		if (label != null){
			sb.append("label:"+label+", ");
		}
		if (Default != null){
			sb.append("default:"+Default+", ");
		}
		if (hidden != null){
			sb.append("hidden:"+hidden+", ");
		}
		if (constraints != null){
			sb.append("constraints:"+constraints+", ");
		}
		if (description != null){
			sb.append("description:"+description);
		}
		return sb.toString();
	}

}