2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.openecomp.sdc.heat.datatypes.structure;
24 import org.codehaus.jackson.annotate.JsonProperty;
25 import org.openecomp.sdc.datatypes.error.ErrorMessage;
26 import org.openecomp.sdc.heat.datatypes.manifest.FileData;
28 import java.util.ArrayList;
29 import java.util.List;
31 import java.util.TreeSet;
33 public class HeatStructureTree implements Comparable<HeatStructureTree> {
35 private String fileName;
36 private FileData.Type type;
37 private Boolean isBase;
38 private HeatStructureTree env;
39 private List<ErrorMessage> errors;
40 private Set<HeatStructureTree> heat;
41 private Set<HeatStructureTree> volume;
42 private Set<HeatStructureTree> network;
43 private Set<HeatStructureTree> nested;
44 private Set<HeatStructureTree> other;
45 private Set<Artifact> artifacts;
47 public HeatStructureTree() {
52 public HeatStructureTree(String fileName, boolean isBase) {
54 setFileName(fileName);
58 * Gets heat structure tree by name.
60 * @param filesSet the files set
61 * @param filename the filename
62 * @return the heat structure tree by name
64 public static HeatStructureTree getHeatStructureTreeByName(Set<HeatStructureTree> filesSet,
66 for (HeatStructureTree heatStructureTree : filesSet) {
67 if (heatStructureTree.getFileName().equals(filename)) {
68 return heatStructureTree;
75 public void setType(FileData.Type type) {
79 public Boolean getBase() {
83 public void setBase(Boolean base) {
87 public String getFileName() {
91 public void setFileName(String file) {
95 @JsonProperty(value = "heat")
96 public Set<HeatStructureTree> getHeat() {
100 public void setHeat(Set<HeatStructureTree> heat) {
104 public Set<HeatStructureTree> getNested() {
108 public void setNested(Set<HeatStructureTree> nested) {
109 this.nested = nested;
112 public Set<Artifact> getArtifacts() {
116 public void setArtifacts(Set<Artifact> artifacts) {
117 this.artifacts = artifacts;
121 * Add heat structure tree to nested heat list.
123 * @param heatStructureTree the heat structure tree
125 public void addHeatStructureTreeToNestedHeatList(HeatStructureTree heatStructureTree) {
126 if (this.nested == null) {
127 this.nested = new TreeSet<>();
129 if (!findItemInSetByName(this.nested, heatStructureTree)) {
130 this.nested.add(heatStructureTree);
135 * Add artifact to artifact list.
137 * @param artifact the artifact
139 public void addArtifactToArtifactList(Artifact artifact) {
140 if (this.artifacts == null || this.artifacts.isEmpty()) {
141 this.artifacts = new TreeSet<>();
143 this.artifacts.add(artifact);
146 public HeatStructureTree getEnv() {
150 public void setEnv(HeatStructureTree env) {
154 public Set<HeatStructureTree> getVolume() {
158 public void setVolume(Set<HeatStructureTree> volume) {
159 this.volume = volume;
162 public Set<HeatStructureTree> getNetwork() {
166 public void setNetwork(Set<HeatStructureTree> network) {
167 this.network = network;
171 * Add network to network list.
173 * @param heatStructureTree the heat structure tree
175 public void addNetworkToNetworkList(HeatStructureTree heatStructureTree) {
176 if (this.network == null) {
177 this.network = new TreeSet<>();
179 if (!findItemInSetByName(this.network, heatStructureTree)) {
180 this.network.add(heatStructureTree);
185 * Add volume file to volume list.
187 * @param heatStructureTree the heat structure tree
189 public void addVolumeFileToVolumeList(HeatStructureTree heatStructureTree) {
190 if (this.volume == null) {
191 this.volume = new TreeSet<>();
193 if (!findItemInSetByName(this.volume, heatStructureTree)) {
194 this.volume.add(heatStructureTree);
199 * Add heat to heat list.
201 * @param heat the heat
203 public void addHeatToHeatList(HeatStructureTree heat) {
204 if (this.heat == null) {
205 this.heat = new TreeSet<>();
212 * Add other to other list.
214 * @param other the other
216 public void addOtherToOtherList(HeatStructureTree other) {
217 if (this.other == null) {
218 this.other = new TreeSet<>();
221 this.other.add(other);
225 * Find item in set by name boolean.
227 * @param searchSet the search set
228 * @param toFind the to find
229 * @return the boolean
231 public boolean findItemInSetByName(Set<HeatStructureTree> searchSet, HeatStructureTree toFind) {
232 for (HeatStructureTree heatStructureTree : searchSet) {
233 if (heatStructureTree.getFileName().equals(toFind.getFileName())) {
243 * Remove from volume or network.
245 * @param fileNameToRemove the file name to remove
246 * @param type the type
248 public void removeFromVolumeOrNetwork(String fileNameToRemove, FileData.Type type) {
249 Set<HeatStructureTree> volumeOrNetworkSet =
250 type.equals(FileData.Type.HEAT_VOL) ? this.volume : this.network;
251 HeatStructureTree toRemove = getHeatStructureTreeByName(volumeOrNetworkSet, fileNameToRemove);
253 volumeOrNetworkSet.remove(toRemove);
257 public int hashCode() {
258 int result1 = fileName != null ? fileName.hashCode() : 0;
259 result1 = 31 * result1 + (env != null ? env.hashCode() : 0);
260 result1 = 31 * result1 + (heat != null ? heat.hashCode() : 0);
261 result1 = 31 * result1 + (volume != null ? volume.hashCode() : 0);
262 result1 = 31 * result1 + (network != null ? network.hashCode() : 0);
263 result1 = 31 * result1 + (artifacts != null ? artifacts.hashCode() : 0);
264 result1 = 31 * result1 + (nested != null ? nested.hashCode() : 0);
265 result1 = 31 * result1 + (errors != null ? errors.hashCode() : 0);
272 public boolean equals(Object other) {
276 if (other == null || getClass() != other.getClass()) {
280 HeatStructureTree heatStructureTree = (HeatStructureTree) other;
282 if (fileName != null ? !fileName.equals(heatStructureTree.fileName)
283 : heatStructureTree.fileName != null) {
286 if (env != null ? !env.equals(heatStructureTree.env) : heatStructureTree.env != null) {
289 if (heat != null ? !heat.equals(heatStructureTree.heat) : heatStructureTree.heat != null) {
292 if (volume != null ? !volume.equals(heatStructureTree.volume)
293 : heatStructureTree.volume != null) {
296 if (network != null ? !network.equals(heatStructureTree.network)
297 : heatStructureTree.network != null) {
300 if (artifacts != null ? !artifacts.equals(heatStructureTree.artifacts)
301 : heatStructureTree.artifacts != null) {
304 if (nested != null ? !nested.equals(heatStructureTree.nested)
305 : heatStructureTree.nested != null) {
308 if (errors != null ? !errors.equals(heatStructureTree.errors)
309 : heatStructureTree.errors != null) {
316 public List<ErrorMessage> getErrors() {
320 public void setErrors(List<ErrorMessage> errors) {
321 this.errors = errors;
325 * Add error to errors list.
327 * @param error the error
329 public void addErrorToErrorsList(ErrorMessage error) {
330 if (this.errors == null || this.errors.isEmpty()) {
331 this.errors = new ArrayList<>();
333 if (!this.errors.contains(error)) {
334 this.errors.add(error);
338 public Set<HeatStructureTree> getOther() {
342 public void setOther(Set<HeatStructureTree> other) {
347 public int compareTo(HeatStructureTree obj) {
348 return obj.getFileName().compareTo(this.getFileName());