Reformat catalog-model
[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 org.openecomp.sdc.be.model.category.CategoryDefinition;
25 import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
26 import org.openecomp.sdc.common.api.UploadArtifactInfo;
27
28 public class UploadResourceInfo {
29
30     private String payloadData;
31     private String payloadName;
32     private String description;
33     private List<String> tags;
34     private List<CategoryDefinition> categories;
35     private List<UploadArtifactInfo> artifactList;
36     private String contactId, name, resourceIconPath, icon, vendorName, vendorRelease, resourceVendorModelNumber;
37     private String resourceType = "VFC";
38
39     public UploadResourceInfo(String payload, String payloadName, String description, String category, List<String> tags,
40                               List<UploadArtifactInfo> artifactsList) {
41         super();
42         this.payloadData = payload;
43         this.payloadName = payloadName;
44         this.description = description;
45         this.tags = tags;
46         this.artifactList = artifactsList;
47         if (category != null) {
48             String[] arr = category.split("/");
49             if (arr.length >= 2) {
50                 categories = new ArrayList<>();
51                 CategoryDefinition catDef = new CategoryDefinition();
52                 catDef.setName(arr[0]);
53                 SubCategoryDefinition subCat = new SubCategoryDefinition();
54                 subCat.setName(arr[1]);
55                 catDef.addSubCategory(subCat);
56                 categories.add(catDef);
57             }
58         }
59     }
60
61     public UploadResourceInfo() {
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     @Override
105     public int hashCode() {
106         final int prime = 31;
107         int result = 1;
108         result = prime * result + ((artifactList == null) ? 0 : artifactList.hashCode());
109         result = prime * result + ((contactId == null) ? 0 : contactId.hashCode());
110         result = prime * result + ((description == null) ? 0 : description.hashCode());
111         result = prime * result + ((icon == null) ? 0 : icon.hashCode());
112         result = prime * result + ((payloadData == null) ? 0 : payloadData.hashCode());
113         result = prime * result + ((payloadName == null) ? 0 : payloadName.hashCode());
114         result = prime * result + ((resourceIconPath == null) ? 0 : resourceIconPath.hashCode());
115         result = prime * result + ((name == null) ? 0 : name.hashCode());
116         result = prime * result + ((tags == null) ? 0 : tags.hashCode());
117         result = prime * result + ((vendorName == null) ? 0 : vendorName.hashCode());
118         result = prime * result + ((vendorRelease == null) ? 0 : vendorRelease.hashCode());
119         result = prime * result + ((resourceVendorModelNumber == null) ? 0 : resourceVendorModelNumber.hashCode());
120         return result;
121     }
122
123     @Override
124     public boolean equals(Object obj) {
125         if (this == obj) {
126             return true;
127         }
128         if (obj == null) {
129             return false;
130         }
131         if (getClass() != obj.getClass()) {
132             return false;
133         }
134         UploadResourceInfo other = (UploadResourceInfo) obj;
135         if (artifactList == null) {
136             if (other.artifactList != null) {
137                 return false;
138             }
139         } else if (!artifactList.equals(other.artifactList)) {
140             return false;
141         }
142         if (contactId == null) {
143             if (other.contactId != null) {
144                 return false;
145             }
146         } else if (!contactId.equals(other.contactId)) {
147             return false;
148         }
149         if (description == null) {
150             if (other.description != null) {
151                 return false;
152             }
153         } else if (!description.equals(other.description)) {
154             return false;
155         }
156         if (icon == null) {
157             if (other.icon != null) {
158                 return false;
159             }
160         } else if (!icon.equals(other.icon)) {
161             return false;
162         }
163         if (payloadData == null) {
164             if (other.payloadData != null) {
165                 return false;
166             }
167         } else if (!payloadData.equals(other.payloadData)) {
168             return false;
169         }
170         if (payloadName == null) {
171             if (other.payloadName != null) {
172                 return false;
173             }
174         } else if (!payloadName.equals(other.payloadName)) {
175             return false;
176         }
177         if (resourceIconPath == null) {
178             if (other.resourceIconPath != null) {
179                 return false;
180             }
181         } else if (!resourceIconPath.equals(other.resourceIconPath)) {
182             return false;
183         }
184         if (name == null) {
185             if (other.name != null) {
186                 return false;
187             }
188         } else if (!name.equals(other.name)) {
189             return false;
190         }
191         if (tags == null) {
192             if (other.tags != null) {
193                 return false;
194             }
195         } else if (!tags.equals(other.tags)) {
196             return false;
197         }
198         if (vendorName == null) {
199             if (other.vendorName != null) {
200                 return false;
201             }
202         } else if (!vendorName.equals(other.vendorName)) {
203             return false;
204         }
205         if (resourceVendorModelNumber == null) {
206             if (other.resourceVendorModelNumber != null) {
207                 return false;
208             }
209         } else if (!resourceVendorModelNumber.equals(other.resourceVendorModelNumber)) {
210             return false;
211         }
212         if (vendorRelease == null) {
213             if (other.vendorRelease != null) {
214                 return false;
215             }
216         } else if (!vendorRelease.equals(other.vendorRelease)) {
217             return false;
218         }
219         return true;
220     }
221
222     public String getContactId() {
223         return contactId;
224     }
225
226     public void setContactId(String userId) {
227         this.contactId = userId;
228     }
229
230     public String getName() {
231         return name;
232     }
233
234     public void setName(String resourceName) {
235         this.name = resourceName;
236     }
237
238     // Icon when using UI import otherwise resourceIconPath
239     public String getResourceIconPath() {
240         return (resourceIconPath != null) ? resourceIconPath : icon;
241     }
242
243     public void setResourceIconPath(String resourceIconPath) {
244         this.resourceIconPath = resourceIconPath;
245     }
246
247     public String getVendorName() {
248         return vendorName;
249     }
250
251     public void setVendorName(String vendorName) {
252         this.vendorName = vendorName;
253     }
254
255     public String getVendorRelease() {
256         return vendorRelease;
257     }
258
259     public void setVendorRelease(String vendorRelease) {
260         this.vendorRelease = vendorRelease;
261     }
262
263     public String getResourceVendorModelNumber() {
264         return resourceVendorModelNumber;
265     }
266
267     public void setResourceVendorModelNumber(String resourceVendorModelNumber) {
268         this.resourceVendorModelNumber = resourceVendorModelNumber;
269     }
270
271     public void setIcon(String icon) {
272         this.icon = icon;
273     }
274
275     public String getResourceType() {
276         return resourceType;
277     }
278
279     public void setResourceType(String resourceType) {
280         this.resourceType = resourceType;
281     }
282
283     public List<CategoryDefinition> getCategories() {
284         return categories;
285     }
286
287     public void setCategories(List<CategoryDefinition> categories) {
288         this.categories = categories;
289     }
290
291     public void addSubCategory(String category, String subCategory) {
292         if (category != null || subCategory != null) {
293             if (categories == null) {
294                 categories = new ArrayList<>();
295             }
296             CategoryDefinition selectedCategory = null;
297             for (CategoryDefinition categoryDef : categories) {
298                 if (categoryDef.getName().equals(category)) {
299                     selectedCategory = categoryDef;
300                 }
301             }
302             if (selectedCategory == null) {
303                 selectedCategory = new CategoryDefinition();
304                 selectedCategory.setName(category);
305                 categories.add(selectedCategory);
306             }
307             List<SubCategoryDefinition> subcategories = selectedCategory.getSubcategories();
308             if (subcategories == null) {
309                 subcategories = new ArrayList<>();
310                 selectedCategory.setSubcategories(subcategories);
311             }
312             SubCategoryDefinition selectedSubcategory = null;
313             for (SubCategoryDefinition subcategory : subcategories) {
314                 if (subcategory.getName().equals(subCategory)) {
315                     selectedSubcategory = subcategory;
316                 }
317             }
318             if (selectedSubcategory == null) {
319                 selectedSubcategory = new SubCategoryDefinition();
320                 selectedSubcategory.setName(subCategory);
321                 subcategories.add(selectedSubcategory);
322             }
323         }
324     }
325 }