Release version 1.13.7
[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 tenant;
46     private String vendorRelease;
47     private String resourceVendorModelNumber;
48     private String resourceType = "VFC";
49     private String model;
50     private boolean isNormative;
51
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;
57         this.tags = tags;
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);
70             }
71         }
72     }
73
74     // Icon when using UI import otherwise resourceIconPath
75     public String getResourceIconPath() {
76         return (resourceIconPath != null) ? resourceIconPath : icon;
77     }
78
79     public void addSubCategory(String category, String subCategory) {
80         if (category != null || subCategory != null) {
81             if (categories == null) {
82                 categories = new ArrayList<>();
83             }
84             CategoryDefinition selectedCategory = null;
85             for (CategoryDefinition categoryDef : categories) {
86                 if (categoryDef.getName().equals(category)) {
87                     selectedCategory = categoryDef;
88                 }
89             }
90             if (selectedCategory == null) {
91                 selectedCategory = new CategoryDefinition();
92                 selectedCategory.setName(category);
93                 categories.add(selectedCategory);
94             }
95             List<SubCategoryDefinition> subcategories = selectedCategory.getSubcategories();
96             if (subcategories == null) {
97                 subcategories = new ArrayList<>();
98                 selectedCategory.setSubcategories(subcategories);
99             }
100             SubCategoryDefinition selectedSubcategory = null;
101             for (SubCategoryDefinition subcategory : subcategories) {
102                 if (subcategory.getName().equals(subCategory)) {
103                     selectedSubcategory = subcategory;
104                 }
105             }
106             if (selectedSubcategory == null) {
107                 selectedSubcategory = new SubCategoryDefinition();
108                 selectedSubcategory.setName(subCategory);
109                 subcategories.add(selectedSubcategory);
110             }
111         }
112     }
113 }