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;
34 * The type Heat structure tree.
36 public class HeatStructureTree implements Comparable<HeatStructureTree> {
38 private String fileName;
39 private FileData.Type type;
40 private Boolean isBase;
41 private HeatStructureTree env;
42 private List<ErrorMessage> errors;
43 private Set<HeatStructureTree> HEAT;
44 private Set<HeatStructureTree> volume;
45 private Set<HeatStructureTree> network;
46 private Set<HeatStructureTree> nested;
47 private Set<HeatStructureTree> other;
48 private Set<Artifact> artifacts;
51 * Instantiates a new Heat structure tree.
53 public HeatStructureTree() {
59 * Instantiates a new Heat structure tree.
61 * @param fileName the file name
62 * @param isBase the is base
64 public HeatStructureTree(String fileName, boolean isBase) {
66 setFileName(fileName);
70 * Gets heat structure tree by name.
72 * @param filesSet the files set
73 * @param filename the filename
74 * @return the heat structure tree by name
76 public static HeatStructureTree getHeatStructureTreeByName(Set<HeatStructureTree> filesSet,
78 for (HeatStructureTree heatStructureTree : filesSet) {
79 if (heatStructureTree.getFileName().equals(filename)) {
80 return heatStructureTree;
90 * @param type the type
92 public void setType(FileData.Type type) {
101 public Boolean getBase() {
108 * @param base the base
110 public void setBase(Boolean base) {
117 * @return the file name
119 public String getFileName() {
126 * @param file the file
128 public void setFileName(String file) {
129 this.fileName = file;
137 @JsonProperty(value = "HEAT")
138 public Set<HeatStructureTree> getHEAT() {
145 * @param heat the heat
147 public void setHEAT(Set<HeatStructureTree> heat) {
156 public Set<HeatStructureTree> getNested() {
163 * @param nested the nested
165 public void setNested(Set<HeatStructureTree> nested) {
166 this.nested = nested;
172 * @return the artifacts
174 public Set<Artifact> getArtifacts() {
181 * @param artifacts the artifacts
183 public void setArtifacts(Set<Artifact> artifacts) {
184 this.artifacts = artifacts;
188 * Add heat structure tree to nested heat list.
190 * @param heatStructureTree the heat structure tree
192 public void addHeatStructureTreeToNestedHeatList(HeatStructureTree heatStructureTree) {
193 if (this.nested == null) {
194 this.nested = new TreeSet<>();
196 if (!findItemInSetByName(this.nested, heatStructureTree)) {
197 this.nested.add(heatStructureTree);
202 * Add artifact to artifact list.
204 * @param artifact the artifact
206 public void addArtifactToArtifactList(Artifact artifact) {
207 if (this.artifacts == null || this.artifacts.isEmpty()) {
208 this.artifacts = new TreeSet<>();
210 this.artifacts.add(artifact);
218 public HeatStructureTree getEnv() {
227 public void setEnv(HeatStructureTree env) {
236 public Set<HeatStructureTree> getVolume() {
243 * @param volume the volume
245 public void setVolume(Set<HeatStructureTree> volume) {
246 this.volume = volume;
252 * @return the network
254 public Set<HeatStructureTree> getNetwork() {
261 * @param network the network
263 public void setNetwork(Set<HeatStructureTree> network) {
264 this.network = network;
268 * Add network to network list.
270 * @param heatStructureTree the heat structure tree
272 public void addNetworkToNetworkList(HeatStructureTree heatStructureTree) {
273 if (this.network == null) {
274 this.network = new TreeSet<>();
276 if (!findItemInSetByName(this.network, heatStructureTree)) {
277 this.network.add(heatStructureTree);
282 * Add volume file to volume list.
284 * @param heatStructureTree the heat structure tree
286 public void addVolumeFileToVolumeList(HeatStructureTree heatStructureTree) {
287 if (this.volume == null) {
288 this.volume = new TreeSet<>();
290 if (!findItemInSetByName(this.volume, heatStructureTree)) {
291 this.volume.add(heatStructureTree);
296 * Add heat to heat list.
298 * @param heat the heat
300 public void addHeatToHEATList(HeatStructureTree heat) {
301 if (this.HEAT == null) {
302 this.HEAT = new TreeSet<>();
309 * Add other to other list.
311 * @param other the other
313 public void addOtherToOtherList(HeatStructureTree other) {
314 if (this.other == null) {
315 this.other = new TreeSet<>();
318 this.other.add(other);
322 * Find item in set by name boolean.
324 * @param searchSet the search set
325 * @param toFind the to find
326 * @return the boolean
328 public boolean findItemInSetByName(Set<HeatStructureTree> searchSet, HeatStructureTree toFind) {
329 for (HeatStructureTree heatStructureTree : searchSet) {
330 if (heatStructureTree.getFileName().equals(toFind.getFileName())) {
340 * Remove from volume or network.
342 * @param fileNameToRemove the file name to remove
343 * @param type the type
345 public void removeFromVolumeOrNetwork(String fileNameToRemove, FileData.Type type) {
346 Set<HeatStructureTree> volumeOrNetworkSet =
347 type.equals(FileData.Type.HEAT_VOL) ? this.volume : this.network;
348 HeatStructureTree toRemove = getHeatStructureTreeByName(volumeOrNetworkSet, fileNameToRemove);
350 volumeOrNetworkSet.remove(toRemove);
354 public boolean equals(Object other) {
358 if (other == null || getClass() != other.getClass()) {
362 HeatStructureTree heatStructureTree = (HeatStructureTree) other;
364 if (fileName != null ? !fileName.equals(heatStructureTree.fileName)
365 : heatStructureTree.fileName != null) {
368 if (env != null ? !env.equals(heatStructureTree.env) : heatStructureTree.env != null) {
371 if (HEAT != null ? !HEAT.equals(heatStructureTree.HEAT) : heatStructureTree.HEAT != null) {
374 if (volume != null ? !volume.equals(heatStructureTree.volume)
375 : heatStructureTree.volume != null) {
378 if (network != null ? !network.equals(heatStructureTree.network)
379 : heatStructureTree.network != null) {
382 if (artifacts != null ? !artifacts.equals(heatStructureTree.artifacts)
383 : heatStructureTree.artifacts != null) {
386 if (nested != null ? !nested.equals(heatStructureTree.nested)
387 : heatStructureTree.nested != null) {
390 if (errors != null ? !errors.equals(heatStructureTree.errors)
391 : heatStructureTree.errors != null) {
399 public int hashCode() {
400 int result1 = fileName != null ? fileName.hashCode() : 0;
401 result1 = 31 * result1 + (env != null ? env.hashCode() : 0);
402 result1 = 31 * result1 + (HEAT != null ? HEAT.hashCode() : 0);
403 result1 = 31 * result1 + (volume != null ? volume.hashCode() : 0);
404 result1 = 31 * result1 + (network != null ? network.hashCode() : 0);
405 result1 = 31 * result1 + (artifacts != null ? artifacts.hashCode() : 0);
406 result1 = 31 * result1 + (nested != null ? nested.hashCode() : 0);
407 result1 = 31 * result1 + (errors != null ? errors.hashCode() : 0);
418 public List<ErrorMessage> getErrors() {
425 * @param errors the errors
427 public void setErrors(List<ErrorMessage> errors) {
428 this.errors = errors;
432 * Add error to errors list.
434 * @param error the error
436 public void addErrorToErrorsList(ErrorMessage error) {
437 if (this.errors == null || this.errors.isEmpty()) {
438 this.errors = new ArrayList<>();
440 if (!this.errors.contains(error)) {
441 this.errors.add(error);
450 public Set<HeatStructureTree> getOther() {
457 * @param other the other
459 public void setOther(Set<HeatStructureTree> other) {
464 public int compareTo(HeatStructureTree heatStructureTree) {
465 return heatStructureTree.getFileName().compareTo(this.getFileName());