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;
23 import java.util.ArrayList;
24 import java.util.List;
26 import java.util.TreeSet;
28 import lombok.AccessLevel;
32 import org.openecomp.sdc.datatypes.error.ErrorMessage;
33 import org.openecomp.sdc.heat.datatypes.manifest.FileData;
36 public class HeatStructureTree implements Comparable<HeatStructureTree> {
38 private String fileName;
39 private FileData.Type type;
41 @Getter(AccessLevel.NONE)
42 @Setter(AccessLevel.NONE)
43 private Boolean isBase;
45 private HeatStructureTree env;
46 private List<ErrorMessage> errors;
47 private Set<HeatStructureTree> heat;
48 private Set<HeatStructureTree> volume;
49 private Set<HeatStructureTree> network;
50 private Set<HeatStructureTree> nested;
51 private Set<HeatStructureTree> other;
52 private Set<Artifact> artifacts;
53 private Set<HeatStructureTree> helm;
55 public HeatStructureTree() {
58 public HeatStructureTree(String fileName, boolean isBase) {
60 this.fileName = fileName;
63 public Boolean getBase() {
67 public void setBase(Boolean isBase) {
72 * Gets heat structure tree by name.
74 * @param filesSet the files set
75 * @param filename the filename
76 * @return the heat structure tree by name
78 public static HeatStructureTree getHeatStructureTreeByName(Set<HeatStructureTree> filesSet,
80 for (HeatStructureTree heatStructureTree : filesSet) {
81 if (heatStructureTree.getFileName().equals(filename)) {
82 return heatStructureTree;
90 * Add heat structure tree to nested heat list.
92 * @param heatStructureTree the heat structure tree
94 public void addHeatStructureTreeToNestedHeatList(HeatStructureTree heatStructureTree) {
95 if (this.nested == null) {
96 this.nested = new TreeSet<>();
98 if (!findItemInSetByName(this.nested, heatStructureTree)) {
99 this.nested.add(heatStructureTree);
104 * Add artifact to artifact list.
106 * @param artifact the artifact
108 public void addArtifactToArtifactList(Artifact artifact) {
109 if (this.artifacts == null || this.artifacts.isEmpty()) {
110 this.artifacts = new TreeSet<>();
112 this.artifacts.add(artifact);
116 * Add network to network list.
118 * @param heatStructureTree the heat structure tree
120 public void addNetworkToNetworkList(HeatStructureTree heatStructureTree) {
121 if (this.network == null) {
122 this.network = new TreeSet<>();
124 if (!findItemInSetByName(this.network, heatStructureTree)) {
125 this.network.add(heatStructureTree);
130 * Add volume file to volume list.
132 * @param heatStructureTree the heat structure tree
134 public void addVolumeFileToVolumeList(HeatStructureTree heatStructureTree) {
135 if (this.volume == null) {
136 this.volume = new TreeSet<>();
138 if (!findItemInSetByName(this.volume, heatStructureTree)) {
139 this.volume.add(heatStructureTree);
144 * Add heat to heat list.
146 * @param heat the heat
148 public void addHeatToHeatList(HeatStructureTree heat) {
149 if (this.heat == null) {
150 this.heat = new TreeSet<>();
157 * Add other to other list.
159 * @param other the other
161 public void addOtherToOtherList(HeatStructureTree other) {
162 if (this.other == null) {
163 this.other = new TreeSet<>();
166 this.other.add(other);
169 public void addToHelmList(HeatStructureTree helm){
170 if (this.helm == null) {
171 this.helm = new TreeSet<>();
178 * Find item in set by name boolean.
180 * @param searchSet the search set
181 * @param toFind the to find
182 * @return the boolean
184 public boolean findItemInSetByName(Set<HeatStructureTree> searchSet, HeatStructureTree toFind) {
185 for (HeatStructureTree heatStructureTree : searchSet) {
186 if (heatStructureTree.getFileName().equals(toFind.getFileName())) {
194 * Remove from volume or network.
196 * @param fileNameToRemove the file name to remove
197 * @param type the type
199 public void removeFromVolumeOrNetwork(String fileNameToRemove, FileData.Type type) {
200 Set<HeatStructureTree> volumeOrNetworkSet =
201 type.equals(FileData.Type.HEAT_VOL) ? this.volume : this.network;
202 HeatStructureTree toRemove = getHeatStructureTreeByName(volumeOrNetworkSet, fileNameToRemove);
204 volumeOrNetworkSet.remove(toRemove);
208 public int hashCode() {
209 int result1 = fileName != null ? fileName.hashCode() : 0;
210 result1 = 31 * result1 + (env != null ? env.hashCode() : 0);
211 result1 = 31 * result1 + (heat != null ? heat.hashCode() : 0);
212 result1 = 31 * result1 + (volume != null ? volume.hashCode() : 0);
213 result1 = 31 * result1 + (network != null ? network.hashCode() : 0);
214 result1 = 31 * result1 + (artifacts != null ? artifacts.hashCode() : 0);
215 result1 = 31 * result1 + (nested != null ? nested.hashCode() : 0);
216 result1 = 31 * result1 + (errors != null ? errors.hashCode() : 0);
223 public boolean equals(Object other) {
227 if (other == null || getClass() != other.getClass()) {
231 HeatStructureTree heatStructureTree = (HeatStructureTree) other;
233 if (fileName != null ? !fileName.equals(heatStructureTree.fileName)
234 : heatStructureTree.fileName != null) {
237 if (env != null ? !env.equals(heatStructureTree.env) : heatStructureTree.env != null) {
240 if (heat != null ? !heat.equals(heatStructureTree.heat) : heatStructureTree.heat != null) {
243 if (volume != null ? !volume.equals(heatStructureTree.volume)
244 : heatStructureTree.volume != null) {
247 if (network != null ? !network.equals(heatStructureTree.network)
248 : heatStructureTree.network != null) {
251 if (artifacts != null ? !artifacts.equals(heatStructureTree.artifacts)
252 : heatStructureTree.artifacts != null) {
255 if (nested != null ? !nested.equals(heatStructureTree.nested)
256 : heatStructureTree.nested != null) {
260 return errors != null ? errors.equals(heatStructureTree.errors) : heatStructureTree.errors == null;
264 * Add error to errors list.
266 * @param error the error
268 public void addErrorToErrorsList(ErrorMessage error) {
269 if (this.errors == null || this.errors.isEmpty()) {
270 this.errors = new ArrayList<>();
272 if (!this.errors.contains(error)) {
273 this.errors.add(error);
278 public int compareTo(HeatStructureTree obj) {
279 return obj.getFileName().compareTo(this.getFileName());