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=========================================================
20 package org.openecomp.sdc.be.model;
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;
28 public class UploadResourceInfo {
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";
39 public UploadResourceInfo(String payload, String payloadName, String description, String category, List<String> tags,
40 List<UploadArtifactInfo> artifactsList) {
42 this.payloadData = payload;
43 this.payloadName = payloadName;
44 this.description = description;
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);
61 public UploadResourceInfo() {
64 public String getPayloadData() {
68 public void setPayloadData(String payload) {
69 this.payloadData = payload;
72 public String getPayloadName() {
76 public void setPayloadName(String payloadName) {
77 this.payloadName = payloadName;
80 public String getDescription() {
84 public void setDescription(String description) {
85 this.description = description;
88 public List<String> getTags() {
92 public void setTags(List<String> tags) {
96 public List<UploadArtifactInfo> getArtifactList() {
100 public void setArtifactList(List<UploadArtifactInfo> artifactsList) {
101 this.artifactList = artifactsList;
105 public int hashCode() {
106 final int prime = 31;
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());
124 public boolean equals(Object obj) {
131 if (getClass() != obj.getClass()) {
134 UploadResourceInfo other = (UploadResourceInfo) obj;
135 if (artifactList == null) {
136 if (other.artifactList != null) {
139 } else if (!artifactList.equals(other.artifactList)) {
142 if (contactId == null) {
143 if (other.contactId != null) {
146 } else if (!contactId.equals(other.contactId)) {
149 if (description == null) {
150 if (other.description != null) {
153 } else if (!description.equals(other.description)) {
157 if (other.icon != null) {
160 } else if (!icon.equals(other.icon)) {
163 if (payloadData == null) {
164 if (other.payloadData != null) {
167 } else if (!payloadData.equals(other.payloadData)) {
170 if (payloadName == null) {
171 if (other.payloadName != null) {
174 } else if (!payloadName.equals(other.payloadName)) {
177 if (resourceIconPath == null) {
178 if (other.resourceIconPath != null) {
181 } else if (!resourceIconPath.equals(other.resourceIconPath)) {
185 if (other.name != null) {
188 } else if (!name.equals(other.name)) {
192 if (other.tags != null) {
195 } else if (!tags.equals(other.tags)) {
198 if (vendorName == null) {
199 if (other.vendorName != null) {
202 } else if (!vendorName.equals(other.vendorName)) {
205 if (resourceVendorModelNumber == null) {
206 if (other.resourceVendorModelNumber != null) {
209 } else if (!resourceVendorModelNumber.equals(other.resourceVendorModelNumber)) {
212 if (vendorRelease == null) {
213 if (other.vendorRelease != null) {
216 } else if (!vendorRelease.equals(other.vendorRelease)) {
222 public String getContactId() {
226 public void setContactId(String userId) {
227 this.contactId = userId;
230 public String getName() {
234 public void setName(String resourceName) {
235 this.name = resourceName;
238 // Icon when using UI import otherwise resourceIconPath
239 public String getResourceIconPath() {
240 return (resourceIconPath != null) ? resourceIconPath : icon;
243 public void setResourceIconPath(String resourceIconPath) {
244 this.resourceIconPath = resourceIconPath;
247 public String getVendorName() {
251 public void setVendorName(String vendorName) {
252 this.vendorName = vendorName;
255 public String getVendorRelease() {
256 return vendorRelease;
259 public void setVendorRelease(String vendorRelease) {
260 this.vendorRelease = vendorRelease;
263 public String getResourceVendorModelNumber() {
264 return resourceVendorModelNumber;
267 public void setResourceVendorModelNumber(String resourceVendorModelNumber) {
268 this.resourceVendorModelNumber = resourceVendorModelNumber;
271 public void setIcon(String icon) {
275 public String getResourceType() {
279 public void setResourceType(String resourceType) {
280 this.resourceType = resourceType;
283 public List<CategoryDefinition> getCategories() {
287 public void setCategories(List<CategoryDefinition> categories) {
288 this.categories = categories;
291 public void addSubCategory(String category, String subCategory) {
292 if (category != null || subCategory != null) {
293 if (categories == null) {
294 categories = new ArrayList<>();
296 CategoryDefinition selectedCategory = null;
297 for (CategoryDefinition categoryDef : categories) {
298 if (categoryDef.getName().equals(category)) {
299 selectedCategory = categoryDef;
302 if (selectedCategory == null) {
303 selectedCategory = new CategoryDefinition();
304 selectedCategory.setName(category);
305 categories.add(selectedCategory);
307 List<SubCategoryDefinition> subcategories = selectedCategory.getSubcategories();
308 if (subcategories == null) {
309 subcategories = new ArrayList<>();
310 selectedCategory.setSubcategories(subcategories);
312 SubCategoryDefinition selectedSubcategory = null;
313 for (SubCategoryDefinition subcategory : subcategories) {
314 if (subcategory.getName().equals(subCategory)) {
315 selectedSubcategory = subcategory;
318 if (selectedSubcategory == null) {
319 selectedSubcategory = new SubCategoryDefinition();
320 selectedSubcategory.setName(subCategory);
321 subcategories.add(selectedSubcategory);