2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (C) 2021 Nokia
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.openecomp.sdc.heat.datatypes.structure;
25 import java.util.ArrayList;
26 import java.util.List;
28 import java.util.TreeSet;
29 import lombok.AccessLevel;
33 import org.openecomp.sdc.datatypes.error.ErrorMessage;
34 import org.openecomp.sdc.heat.datatypes.manifest.FileData;
37 public class HeatStructureTree implements Comparable<HeatStructureTree> {
39 private String fileName;
40 private FileData.Type type;
42 @Getter(AccessLevel.NONE)
43 @Setter(AccessLevel.NONE)
44 private Boolean isBase;
46 private HeatStructureTree env;
47 private List<ErrorMessage> errors;
48 private Set<HeatStructureTree> heat;
49 private Set<HeatStructureTree> volume;
50 private Set<HeatStructureTree> network;
51 private Set<HeatStructureTree> nested;
52 private Set<HeatStructureTree> other;
53 private Set<Artifact> artifacts;
54 private Set<HeatStructureTree> helm;
56 public HeatStructureTree() {
57 heat = new TreeSet<>();
60 public HeatStructureTree(String fileName, boolean isBase) {
63 this.fileName = fileName;
66 public Boolean getBase() {
70 public void setBase(Boolean isBase) {
75 * Gets heat structure tree by name.
77 * @param filesSet the files set
78 * @param filename the filename
79 * @return the heat structure tree by name
81 public static HeatStructureTree getHeatStructureTreeByName(Set<HeatStructureTree> filesSet,
83 for (HeatStructureTree heatStructureTree : filesSet) {
84 if (heatStructureTree.getFileName().equals(filename)) {
85 return heatStructureTree;
93 * Add heat structure tree to nested heat list.
95 * @param heatStructureTree the heat structure tree
97 public void addHeatStructureTreeToNestedHeatList(HeatStructureTree heatStructureTree) {
98 if (this.nested == null) {
99 this.nested = new TreeSet<>();
101 if (!findItemInSetByName(this.nested, heatStructureTree)) {
102 this.nested.add(heatStructureTree);
107 * Add artifact to artifact list.
109 * @param artifact the artifact
111 public void addArtifactToArtifactList(Artifact artifact) {
112 if (this.artifacts == null || this.artifacts.isEmpty()) {
113 this.artifacts = new TreeSet<>();
115 this.artifacts.add(artifact);
119 * Add network to network list.
121 * @param heatStructureTree the heat structure tree
123 public void addNetworkToNetworkList(HeatStructureTree heatStructureTree) {
124 if (this.network == null) {
125 this.network = new TreeSet<>();
127 if (!findItemInSetByName(this.network, heatStructureTree)) {
128 this.network.add(heatStructureTree);
133 * Add volume file to volume list.
135 * @param heatStructureTree the heat structure tree
137 public void addVolumeFileToVolumeList(HeatStructureTree heatStructureTree) {
138 if (this.volume == null) {
139 this.volume = new TreeSet<>();
141 if (!findItemInSetByName(this.volume, heatStructureTree)) {
142 this.volume.add(heatStructureTree);
147 * Add heat to heat list.
149 * @param heat the heat
151 public void addHeatToHeatList(HeatStructureTree heat) {
152 if (this.heat == null) {
153 this.heat = new TreeSet<>();
160 * Add other to other list.
162 * @param other the other
164 public void addOtherToOtherList(HeatStructureTree other) {
165 if (this.other == null) {
166 this.other = new TreeSet<>();
169 this.other.add(other);
172 public void addToHelmList(HeatStructureTree helm) {
173 if (this.helm == null) {
174 this.helm = new TreeSet<>();
181 * Find item in set by name boolean.
183 * @param searchSet the search set
184 * @param toFind the to find
185 * @return the boolean
187 public boolean findItemInSetByName(Set<HeatStructureTree> searchSet, HeatStructureTree toFind) {
188 for (HeatStructureTree heatStructureTree : searchSet) {
189 if (heatStructureTree.getFileName().equals(toFind.getFileName())) {
197 * Remove from volume or network.
199 * @param fileNameToRemove the file name to remove
200 * @param type the type
202 public void removeFromVolumeOrNetwork(String fileNameToRemove, FileData.Type type) {
203 Set<HeatStructureTree> volumeOrNetworkSet =
204 type.equals(FileData.Type.HEAT_VOL) ? this.volume : this.network;
205 HeatStructureTree toRemove = getHeatStructureTreeByName(volumeOrNetworkSet, fileNameToRemove);
207 volumeOrNetworkSet.remove(toRemove);
211 public int hashCode() {
212 int result1 = fileName != null ? fileName.hashCode() : 0;
213 result1 = 31 * result1 + (env != null ? env.hashCode() : 0);
214 result1 = 31 * result1 + (heat != null ? heat.hashCode() : 0);
215 result1 = 31 * result1 + (volume != null ? volume.hashCode() : 0);
216 result1 = 31 * result1 + (network != null ? network.hashCode() : 0);
217 result1 = 31 * result1 + (artifacts != null ? artifacts.hashCode() : 0);
218 result1 = 31 * result1 + (nested != null ? nested.hashCode() : 0);
219 result1 = 31 * result1 + (errors != null ? errors.hashCode() : 0);
225 public boolean equals(Object other) {
229 if (other == null || getClass() != other.getClass()) {
233 HeatStructureTree heatStructureTree = (HeatStructureTree) other;
235 if (fileName != null ? !fileName.equals(heatStructureTree.fileName)
236 : heatStructureTree.fileName != null) {
239 if (env != null ? !env.equals(heatStructureTree.env) : heatStructureTree.env != null) {
242 if (heat != null ? !heat.equals(heatStructureTree.heat) : heatStructureTree.heat != null) {
245 if (volume != null ? !volume.equals(heatStructureTree.volume)
246 : heatStructureTree.volume != null) {
249 if (network != null ? !network.equals(heatStructureTree.network)
250 : heatStructureTree.network != null) {
253 if (artifacts != null ? !artifacts.equals(heatStructureTree.artifacts)
254 : heatStructureTree.artifacts != null) {
257 if (nested != null ? !nested.equals(heatStructureTree.nested)
258 : heatStructureTree.nested != null) {
262 return errors != null ? errors.equals(heatStructureTree.errors) : heatStructureTree.errors == null;
266 * Add error to errors list.
268 * @param error the error
270 public void addErrorToErrorsList(ErrorMessage error) {
271 if (this.errors == null || this.errors.isEmpty()) {
272 this.errors = new ArrayList<>();
274 if (!this.errors.contains(error)) {
275 this.errors.add(error);
280 public int compareTo(HeatStructureTree obj) {
281 return obj.getFileName().compareTo(this.getFileName());