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;
25 import lombok.NoArgsConstructor;
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;
32 public class UploadResourceInfo {
34 private String payloadData;
35 private String payloadName;
36 private String description;
37 private List<String> tags;
38 private List<CategoryDefinition> categories;
39 private List<UploadArtifactInfo> artifactList;
40 private String contactId;
42 private String resourceIconPath;
44 private String vendorName;
45 private String tenant;
46 private String vendorRelease;
47 private String resourceVendorModelNumber;
48 private String resourceType = "VFC";
50 private boolean isNormative;
52 public UploadResourceInfo(String payload, String payloadName, String description, String category, List<String> tags,
53 List<UploadArtifactInfo> artifactsList, String modelName) {
54 this.payloadData = payload;
55 this.payloadName = payloadName;
56 this.description = description;
58 this.artifactList = artifactsList;
59 this.model = modelName;
60 if (category != null) {
61 String[] arr = category.split("/");
62 if (arr.length >= 2) {
63 categories = new ArrayList<>();
64 CategoryDefinition catDef = new CategoryDefinition();
65 catDef.setName(arr[0]);
66 SubCategoryDefinition subCat = new SubCategoryDefinition();
67 subCat.setName(arr[1]);
68 catDef.addSubCategory(subCat);
69 categories.add(catDef);
74 // Icon when using UI import otherwise resourceIconPath
75 public String getResourceIconPath() {
76 return (resourceIconPath != null) ? resourceIconPath : icon;
79 public void addSubCategory(String category, String subCategory) {
80 if (category != null || subCategory != null) {
81 if (categories == null) {
82 categories = new ArrayList<>();
84 CategoryDefinition selectedCategory = null;
85 for (CategoryDefinition categoryDef : categories) {
86 if (categoryDef.getName().equals(category)) {
87 selectedCategory = categoryDef;
90 if (selectedCategory == null) {
91 selectedCategory = new CategoryDefinition();
92 selectedCategory.setName(category);
93 categories.add(selectedCategory);
95 List<SubCategoryDefinition> subcategories = selectedCategory.getSubcategories();
96 if (subcategories == null) {
97 subcategories = new ArrayList<>();
98 selectedCategory.setSubcategories(subcategories);
100 SubCategoryDefinition selectedSubcategory = null;
101 for (SubCategoryDefinition subcategory : subcategories) {
102 if (subcategory.getName().equals(subCategory)) {
103 selectedSubcategory = subcategory;
106 if (selectedSubcategory == null) {
107 selectedSubcategory = new SubCategoryDefinition();
108 selectedSubcategory.setName(subCategory);
109 subcategories.add(selectedSubcategory);