dcb01169c6decf97fa7f377243a72b060026a3e2
[sdc.git] / catalog-model / src / main / java / org / openecomp / sdc / be / model / UploadResourceInfo.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20 package org.openecomp.sdc.be.model;
21
22 import java.util.ArrayList;
23 import java.util.List;
24 import lombok.NoArgsConstructor;
25 import org.openecomp.sdc.be.model.category.CategoryDefinition;
26 import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
27 import org.openecomp.sdc.common.api.UploadArtifactInfo;
28
29 @NoArgsConstructor
30 public class UploadResourceInfo {
31
32     private String payloadData;
33     private String payloadName;
34     private String description;
35     private List<String> tags;
36     private List<CategoryDefinition> categories;
37     private List<UploadArtifactInfo> artifactList;
38     private String contactId, name, resourceIconPath, icon, vendorName, vendorRelease, resourceVendorModelNumber;
39     private String resourceType = "VFC";
40     private String model;
41
42     public UploadResourceInfo(String payload, String payloadName, String description, String category, List<String> tags,
43                               List<UploadArtifactInfo> artifactsList, String modelName) {
44         this.payloadData = payload;
45         this.payloadName = payloadName;
46         this.description = description;
47         this.tags = tags;
48         this.artifactList = artifactsList;
49         this.model = modelName;
50         if (category != null) {
51             String[] arr = category.split("/");
52             if (arr.length >= 2) {
53                 categories = new ArrayList<>();
54                 CategoryDefinition catDef = new CategoryDefinition();
55                 catDef.setName(arr[0]);
56                 SubCategoryDefinition subCat = new SubCategoryDefinition();
57                 subCat.setName(arr[1]);
58                 catDef.addSubCategory(subCat);
59                 categories.add(catDef);
60             }
61         }
62     }
63
64     public String getPayloadData() {
65         return payloadData;
66     }
67
68     public void setPayloadData(String payload) {
69         this.payloadData = payload;
70     }
71
72     public String getPayloadName() {
73         return payloadName;
74     }
75
76     public void setPayloadName(String payloadName) {
77         this.payloadName = payloadName;
78     }
79
80     public String getDescription() {
81         return description;
82     }
83
84     public void setDescription(String description) {
85         this.description = description;
86     }
87
88     public List<String> getTags() {
89         return tags;
90     }
91
92     public void setTags(List<String> tags) {
93         this.tags = tags;
94     }
95
96     public List<UploadArtifactInfo> getArtifactList() {
97         return artifactList;
98     }
99
100     public void setArtifactList(List<UploadArtifactInfo> artifactsList) {
101         this.artifactList = artifactsList;
102     }
103
104     public String getModel() {
105         return model;
106     }
107
108     public void setModel(final String model) {
109         this.model = model;
110     }
111
112     @Override
113     public int hashCode() {
114         final int prime = 31;
115         int result = 1;
116         result = prime * result + ((artifactList == null) ? 0 : artifactList.hashCode());
117         result = prime * result + ((contactId == null) ? 0 : contactId.hashCode());
118         result = prime * result + ((description == null) ? 0 : description.hashCode());
119         result = prime * result + ((icon == null) ? 0 : icon.hashCode());
120         result = prime * result + ((payloadData == null) ? 0 : payloadData.hashCode());
121         result = prime * result + ((payloadName == null) ? 0 : payloadName.hashCode());
122         result = prime * result + ((resourceIconPath == null) ? 0 : resourceIconPath.hashCode());
123         result = prime * result + ((name == null) ? 0 : name.hashCode());
124         result = prime * result + ((tags == null) ? 0 : tags.hashCode());
125         result = prime * result + ((vendorName == null) ? 0 : vendorName.hashCode());
126         result = prime * result + ((vendorRelease == null) ? 0 : vendorRelease.hashCode());
127         result = prime * result + ((model == null) ? 0 : model.hashCode());
128         result = prime * result + ((resourceVendorModelNumber == null) ? 0 : resourceVendorModelNumber.hashCode());
129         return result;
130     }
131
132     @Override
133     public boolean equals(Object obj) {
134         if (this == obj) {
135             return true;
136         }
137         if (obj == null) {
138             return false;
139         }
140         if (getClass() != obj.getClass()) {
141             return false;
142         }
143         UploadResourceInfo other = (UploadResourceInfo) obj;
144         if (artifactList == null) {
145             if (other.artifactList != null) {
146                 return false;
147             }
148         } else if (!artifactList.equals(other.artifactList)) {
149             return false;
150         }
151         if (contactId == null) {
152             if (other.contactId != null) {
153                 return false;
154             }
155         } else if (!contactId.equals(other.contactId)) {
156             return false;
157         }
158         if (description == null) {
159             if (other.description != null) {
160                 return false;
161             }
162         } else if (!description.equals(other.description)) {
163             return false;
164         }
165         if (icon == null) {
166             if (other.icon != null) {
167                 return false;
168             }
169         } else if (!icon.equals(other.icon)) {
170             return false;
171         }
172         if (payloadData == null) {
173             if (other.payloadData != null) {
174                 return false;
175             }
176         } else if (!payloadData.equals(other.payloadData)) {
177             return false;
178         }
179         if (payloadName == null) {
180             if (other.payloadName != null) {
181                 return false;
182             }
183         } else if (!payloadName.equals(other.payloadName)) {
184             return false;
185         }
186         if (resourceIconPath == null) {
187             if (other.resourceIconPath != null) {
188                 return false;
189             }
190         } else if (!resourceIconPath.equals(other.resourceIconPath)) {
191             return false;
192         }
193         if (name == null) {
194             if (other.name != null) {
195                 return false;
196             }
197         } else if (!name.equals(other.name)) {
198             return false;
199         }
200         if (tags == null) {
201             if (other.tags != null) {
202                 return false;
203             }
204         } else if (!tags.equals(other.tags)) {
205             return false;
206         }
207         if (model == null) {
208             if (other.model != null) {
209                 return false;
210             }
211         } else if (!model.equals(other.model)) {
212             return false;
213         }
214         if (vendorName == null) {
215             if (other.vendorName != null) {
216                 return false;
217             }
218         } else if (!vendorName.equals(other.vendorName)) {
219             return false;
220         }
221         if (resourceVendorModelNumber == null) {
222             if (other.resourceVendorModelNumber != null) {
223                 return false;
224             }
225         } else if (!resourceVendorModelNumber.equals(other.resourceVendorModelNumber)) {
226             return false;
227         }
228         if (vendorRelease == null) {
229             if (other.vendorRelease != null) {
230                 return false;
231             }
232         } else if (!vendorRelease.equals(other.vendorRelease)) {
233             return false;
234         }
235         return true;
236     }
237
238     public String getContactId() {
239         return contactId;
240     }
241
242     public void setContactId(String userId) {
243         this.contactId = userId;
244     }
245
246     public String getName() {
247         return name;
248     }
249
250     public void setName(String resourceName) {
251         this.name = resourceName;
252     }
253
254     // Icon when using UI import otherwise resourceIconPath
255     public String getResourceIconPath() {
256         return (resourceIconPath != null) ? resourceIconPath : icon;
257     }
258
259     public void setResourceIconPath(String resourceIconPath) {
260         this.resourceIconPath = resourceIconPath;
261     }
262
263     public String getVendorName() {
264         return vendorName;
265     }
266
267     public void setVendorName(String vendorName) {
268         this.vendorName = vendorName;
269     }
270
271     public String getVendorRelease() {
272         return vendorRelease;
273     }
274
275     public void setVendorRelease(String vendorRelease) {
276         this.vendorRelease = vendorRelease;
277     }
278
279     public String getResourceVendorModelNumber() {
280         return resourceVendorModelNumber;
281     }
282
283     public void setResourceVendorModelNumber(String resourceVendorModelNumber) {
284         this.resourceVendorModelNumber = resourceVendorModelNumber;
285     }
286
287     public void setIcon(String icon) {
288         this.icon = icon;
289     }
290
291     public String getResourceType() {
292         return resourceType;
293     }
294
295     public void setResourceType(String resourceType) {
296         this.resourceType = resourceType;
297     }
298
299     public List<CategoryDefinition> getCategories() {
300         return categories;
301     }
302
303     public void setCategories(List<CategoryDefinition> categories) {
304         this.categories = categories;
305     }
306
307     public void addSubCategory(String category, String subCategory) {
308         if (category != null || subCategory != null) {
309             if (categories == null) {
310                 categories = new ArrayList<>();
311             }
312             CategoryDefinition selectedCategory = null;
313             for (CategoryDefinition categoryDef : categories) {
314                 if (categoryDef.getName().equals(category)) {
315                     selectedCategory = categoryDef;
316                 }
317             }
318             if (selectedCategory == null) {
319                 selectedCategory = new CategoryDefinition();
320                 selectedCategory.setName(category);
321                 categories.add(selectedCategory);
322             }
323             List<SubCategoryDefinition> subcategories = selectedCategory.getSubcategories();
324             if (subcategories == null) {
325                 subcategories = new ArrayList<>();
326                 selectedCategory.setSubcategories(subcategories);
327             }
328             SubCategoryDefinition selectedSubcategory = null;
329             for (SubCategoryDefinition subcategory : subcategories) {
330                 if (subcategory.getName().equals(subCategory)) {
331                     selectedSubcategory = subcategory;
332                 }
333             }
334             if (selectedSubcategory == null) {
335                 selectedSubcategory = new SubCategoryDefinition();
336                 selectedSubcategory.setName(subCategory);
337                 subcategories.add(selectedSubcategory);
338             }
339         }
340     }
341 }