Enable identification of system deployed VFCs
[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 package org.openecomp.sdc.be.model;
21
22 import java.util.ArrayList;
23 import java.util.List;
24 import lombok.Data;
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;
29
30 @NoArgsConstructor
31 @Data
32 public class UploadResourceInfo {
33
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;
41     private String name;
42     private String resourceIconPath;
43     private String icon;
44     private String vendorName;
45     private String vendorRelease;
46     private String resourceVendorModelNumber;
47     private String resourceType = "VFC";
48     private String model;
49     private boolean isNormative;
50
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;
56         this.tags = tags;
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);
69             }
70         }
71     }
72
73     // Icon when using UI import otherwise resourceIconPath
74     public String getResourceIconPath() {
75         return (resourceIconPath != null) ? resourceIconPath : icon;
76     }
77
78     public void addSubCategory(String category, String subCategory) {
79         if (category != null || subCategory != null) {
80             if (categories == null) {
81                 categories = new ArrayList<>();
82             }
83             CategoryDefinition selectedCategory = null;
84             for (CategoryDefinition categoryDef : categories) {
85                 if (categoryDef.getName().equals(category)) {
86                     selectedCategory = categoryDef;
87                 }
88             }
89             if (selectedCategory == null) {
90                 selectedCategory = new CategoryDefinition();
91                 selectedCategory.setName(category);
92                 categories.add(selectedCategory);
93             }
94             List<SubCategoryDefinition> subcategories = selectedCategory.getSubcategories();
95             if (subcategories == null) {
96                 subcategories = new ArrayList<>();
97                 selectedCategory.setSubcategories(subcategories);
98             }
99             SubCategoryDefinition selectedSubcategory = null;
100             for (SubCategoryDefinition subcategory : subcategories) {
101                 if (subcategory.getName().equals(subCategory)) {
102                     selectedSubcategory = subcategory;
103                 }
104             }
105             if (selectedSubcategory == null) {
106                 selectedSubcategory = new SubCategoryDefinition();
107                 selectedSubcategory.setName(subCategory);
108                 subcategories.add(selectedSubcategory);
109             }
110         }
111     }
112 }