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.be.model;
23 import java.util.ArrayList;
24 import java.util.List;
26 import org.openecomp.sdc.be.model.category.CategoryDefinition;
27 import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
28 import org.openecomp.sdc.common.api.UploadArtifactInfo;
30 public class UploadResourceInfo {
32 private String payloadData;
33 private String payloadName;
34 private String description;
35 private List<String> tags;
36 private List<CategoryDefinition> categories;
38 private List<UploadArtifactInfo> artifactList;
39 private String contactId, name, resourceIconPath, icon, vendorName, vendorRelease, resourceVendorModelNumber;
41 private String resourceType = "VFC";
43 public UploadResourceInfo(String payload, String payloadName, String description, String category,
44 List<String> tags, List<UploadArtifactInfo> artifactsList) {
46 this.payloadData = payload;
47 this.payloadName = payloadName;
48 this.description = description;
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);
65 public UploadResourceInfo() {
69 public String getPayloadData() {
73 public void setPayloadData(String payload) {
74 this.payloadData = payload;
77 public String getPayloadName() {
81 public void setPayloadName(String payloadName) {
82 this.payloadName = payloadName;
85 public String getDescription() {
89 public void setDescription(String description) {
90 this.description = description;
93 public List<String> getTags() {
97 public void setTags(List<String> tags) {
101 public List<UploadArtifactInfo> getArtifactList() {
105 public void setArtifactList(List<UploadArtifactInfo> artifactsList) {
106 this.artifactList = artifactsList;
110 public int hashCode() {
111 final int prime = 31;
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());
129 public boolean equals(Object obj) {
136 if (getClass() != obj.getClass()) {
139 UploadResourceInfo other = (UploadResourceInfo) obj;
140 if (artifactList == null) {
141 if (other.artifactList != null) {
144 } else if (!artifactList.equals(other.artifactList)) {
147 if (contactId == null) {
148 if (other.contactId != null) {
151 } else if (!contactId.equals(other.contactId)) {
154 if (description == null) {
155 if (other.description != null) {
158 } else if (!description.equals(other.description)) {
162 if (other.icon != null) {
165 } else if (!icon.equals(other.icon)) {
168 if (payloadData == null) {
169 if (other.payloadData != null) {
172 } else if (!payloadData.equals(other.payloadData)) {
175 if (payloadName == null) {
176 if (other.payloadName != null) {
179 } else if (!payloadName.equals(other.payloadName)) {
182 if (resourceIconPath == null) {
183 if (other.resourceIconPath != null) {
186 } else if (!resourceIconPath.equals(other.resourceIconPath)) {
190 if (other.name != null) {
193 } else if (!name.equals(other.name)) {
197 if (other.tags != null) {
200 } else if (!tags.equals(other.tags)) {
203 if (vendorName == null) {
204 if (other.vendorName != null) {
207 } else if (!vendorName.equals(other.vendorName)) {
210 if (resourceVendorModelNumber == null) {
211 if (other.resourceVendorModelNumber != null) {
214 } else if (!resourceVendorModelNumber.equals(other.resourceVendorModelNumber)) {
217 if (vendorRelease == null) {
218 if (other.vendorRelease != null) {
221 } else if (!vendorRelease.equals(other.vendorRelease)) {
227 public String getContactId() {
231 public void setContactId(String userId) {
232 this.contactId = userId;
235 public String getName() {
239 public void setName(String resourceName) {
240 this.name = resourceName;
243 // Icon when using UI import otherwise resourceIconPath
244 public String getResourceIconPath() {
245 return (resourceIconPath != null) ? resourceIconPath : icon;
248 public void setResourceIconPath(String resourceIconPath) {
249 this.resourceIconPath = resourceIconPath;
252 public String getVendorName() {
256 public void setVendorName(String vendorName) {
257 this.vendorName = vendorName;
260 public String getVendorRelease() {
261 return vendorRelease;
264 public void setVendorRelease(String vendorRelease) {
265 this.vendorRelease = vendorRelease;
268 public String getResourceVendorModelNumber() {
269 return resourceVendorModelNumber;
272 public void setResourceVendorModelNumber(String resourceVendorModelNumber) {
273 this.resourceVendorModelNumber = resourceVendorModelNumber;
276 public void setIcon(String icon) {
280 public String getResourceType() {
284 public void setResourceType(String resourceType) {
285 this.resourceType = resourceType;
288 public List<CategoryDefinition> getCategories() {
292 public void setCategories(List<CategoryDefinition> categories) {
293 this.categories = categories;
296 public void addSubCategory(String category, String subCategory) {
297 if (category != null || subCategory != null) {
298 if (categories == null) {
299 categories = new ArrayList<>();
301 CategoryDefinition selectedCategory = null;
302 for (CategoryDefinition categoryDef : categories) {
303 if (categoryDef.getName().equals(category)) {
304 selectedCategory = categoryDef;
307 if (selectedCategory == null) {
308 selectedCategory = new CategoryDefinition();
309 selectedCategory.setName(category);
310 categories.add(selectedCategory);
312 List<SubCategoryDefinition> subcategories = selectedCategory.getSubcategories();
313 if (subcategories == null) {
314 subcategories = new ArrayList<>();
315 selectedCategory.setSubcategories(subcategories);
317 SubCategoryDefinition selectedSubcategory = null;
318 for (SubCategoryDefinition subcategory : subcategories) {
319 if (subcategory.getName().equals(subCategory)) {
320 selectedSubcategory = subcategory;
323 if (selectedSubcategory == null) {
324 selectedSubcategory = new SubCategoryDefinition();
325 selectedSubcategory.setName(subCategory);
326 subcategories.add(selectedSubcategory);