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