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 vendorRelease;
46 private String resourceVendorModelNumber;
47 private String resourceType = "VFC";
49 private boolean isNormative;
51 public UploadResourceInfo(String payload, String payloadName, String description, String category, List<String> tags,
52 List<UploadArtifactInfo> artifactsList, String modelName) {
53 this.payloadData = payload;
54 this.payloadName = payloadName;
55 this.description = description;
57 this.artifactList = artifactsList;
58 this.model = modelName;
59 if (category != null) {
60 String[] arr = category.split("/");
61 if (arr.length >= 2) {
62 categories = new ArrayList<>();
63 CategoryDefinition catDef = new CategoryDefinition();
64 catDef.setName(arr[0]);
65 SubCategoryDefinition subCat = new SubCategoryDefinition();
66 subCat.setName(arr[1]);
67 catDef.addSubCategory(subCat);
68 categories.add(catDef);
73 // Icon when using UI import otherwise resourceIconPath
74 public String getResourceIconPath() {
75 return (resourceIconPath != null) ? resourceIconPath : icon;
78 public void addSubCategory(String category, String subCategory) {
79 if (category != null || subCategory != null) {
80 if (categories == null) {
81 categories = new ArrayList<>();
83 CategoryDefinition selectedCategory = null;
84 for (CategoryDefinition categoryDef : categories) {
85 if (categoryDef.getName().equals(category)) {
86 selectedCategory = categoryDef;
89 if (selectedCategory == null) {
90 selectedCategory = new CategoryDefinition();
91 selectedCategory.setName(category);
92 categories.add(selectedCategory);
94 List<SubCategoryDefinition> subcategories = selectedCategory.getSubcategories();
95 if (subcategories == null) {
96 subcategories = new ArrayList<>();
97 selectedCategory.setSubcategories(subcategories);
99 SubCategoryDefinition selectedSubcategory = null;
100 for (SubCategoryDefinition subcategory : subcategories) {
101 if (subcategory.getName().equals(subCategory)) {
102 selectedSubcategory = subcategory;
105 if (selectedSubcategory == null) {
106 selectedSubcategory = new SubCategoryDefinition();
107 selectedSubcategory.setName(subCategory);
108 subcategories.add(selectedSubcategory);