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;
54 public HeatStructureTree() {
57 public HeatStructureTree(String fileName, boolean isBase) {
59 this.fileName = fileName;
62 public Boolean getBase() {
66 public void setBase(Boolean isBase) {
71 * Gets heat structure tree by name.
73 * @param filesSet the files set
74 * @param filename the filename
75 * @return the heat structure tree by name
77 public static HeatStructureTree getHeatStructureTreeByName(Set<HeatStructureTree> filesSet,
79 for (HeatStructureTree heatStructureTree : filesSet) {
80 if (heatStructureTree.getFileName().equals(filename)) {
81 return heatStructureTree;
89 * Add heat structure tree to nested heat list.
91 * @param heatStructureTree the heat structure tree
93 public void addHeatStructureTreeToNestedHeatList(HeatStructureTree heatStructureTree) {
94 if (this.nested == null) {
95 this.nested = new TreeSet<>();
97 if (!findItemInSetByName(this.nested, heatStructureTree)) {
98 this.nested.add(heatStructureTree);
103 * Add artifact to artifact list.
105 * @param artifact the artifact
107 public void addArtifactToArtifactList(Artifact artifact) {
108 if (this.artifacts == null || this.artifacts.isEmpty()) {
109 this.artifacts = new TreeSet<>();
111 this.artifacts.add(artifact);
115 * Add network to network list.
117 * @param heatStructureTree the heat structure tree
119 public void addNetworkToNetworkList(HeatStructureTree heatStructureTree) {
120 if (this.network == null) {
121 this.network = new TreeSet<>();
123 if (!findItemInSetByName(this.network, heatStructureTree)) {
124 this.network.add(heatStructureTree);
129 * Add volume file to volume list.
131 * @param heatStructureTree the heat structure tree
133 public void addVolumeFileToVolumeList(HeatStructureTree heatStructureTree) {
134 if (this.volume == null) {
135 this.volume = new TreeSet<>();
137 if (!findItemInSetByName(this.volume, heatStructureTree)) {
138 this.volume.add(heatStructureTree);
143 * Add heat to heat list.
145 * @param heat the heat
147 public void addHeatToHeatList(HeatStructureTree heat) {
148 if (this.heat == null) {
149 this.heat = new TreeSet<>();
156 * Add other to other list.
158 * @param other the other
160 public void addOtherToOtherList(HeatStructureTree other) {
161 if (this.other == null) {
162 this.other = new TreeSet<>();
165 this.other.add(other);
169 * Find item in set by name boolean.
171 * @param searchSet the search set
172 * @param toFind the to find
173 * @return the boolean
175 public boolean findItemInSetByName(Set<HeatStructureTree> searchSet, HeatStructureTree toFind) {
176 for (HeatStructureTree heatStructureTree : searchSet) {
177 if (heatStructureTree.getFileName().equals(toFind.getFileName())) {
185 * Remove from volume or network.
187 * @param fileNameToRemove the file name to remove
188 * @param type the type
190 public void removeFromVolumeOrNetwork(String fileNameToRemove, FileData.Type type) {
191 Set<HeatStructureTree> volumeOrNetworkSet =
192 type.equals(FileData.Type.HEAT_VOL) ? this.volume : this.network;
193 HeatStructureTree toRemove = getHeatStructureTreeByName(volumeOrNetworkSet, fileNameToRemove);
195 volumeOrNetworkSet.remove(toRemove);
199 public int hashCode() {
200 int result1 = fileName != null ? fileName.hashCode() : 0;
201 result1 = 31 * result1 + (env != null ? env.hashCode() : 0);
202 result1 = 31 * result1 + (heat != null ? heat.hashCode() : 0);
203 result1 = 31 * result1 + (volume != null ? volume.hashCode() : 0);
204 result1 = 31 * result1 + (network != null ? network.hashCode() : 0);
205 result1 = 31 * result1 + (artifacts != null ? artifacts.hashCode() : 0);
206 result1 = 31 * result1 + (nested != null ? nested.hashCode() : 0);
207 result1 = 31 * result1 + (errors != null ? errors.hashCode() : 0);
214 public boolean equals(Object other) {
218 if (other == null || getClass() != other.getClass()) {
222 HeatStructureTree heatStructureTree = (HeatStructureTree) other;
224 if (fileName != null ? !fileName.equals(heatStructureTree.fileName)
225 : heatStructureTree.fileName != null) {
228 if (env != null ? !env.equals(heatStructureTree.env) : heatStructureTree.env != null) {
231 if (heat != null ? !heat.equals(heatStructureTree.heat) : heatStructureTree.heat != null) {
234 if (volume != null ? !volume.equals(heatStructureTree.volume)
235 : heatStructureTree.volume != null) {
238 if (network != null ? !network.equals(heatStructureTree.network)
239 : heatStructureTree.network != null) {
242 if (artifacts != null ? !artifacts.equals(heatStructureTree.artifacts)
243 : heatStructureTree.artifacts != null) {
246 if (nested != null ? !nested.equals(heatStructureTree.nested)
247 : heatStructureTree.nested != null) {
251 return errors != null ? errors.equals(heatStructureTree.errors) : heatStructureTree.errors == null;
255 * Add error to errors list.
257 * @param error the error
259 public void addErrorToErrorsList(ErrorMessage error) {
260 if (this.errors == null || this.errors.isEmpty()) {
261 this.errors = new ArrayList<>();
263 if (!this.errors.contains(error)) {
264 this.errors.add(error);
269 public int compareTo(HeatStructureTree obj) {
270 return obj.getFileName().compareTo(this.getFileName());