26cee8447c21257ab6b544ee86e0b4802cdc7184
[sdc.git] / catalog-model / src / main / java / org / openecomp / sdc / be / model / UploadServiceInfo.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2020 CMCC 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.Getter;
25 import lombok.Setter;
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 @Getter
31 @Setter
32 public class UploadServiceInfo {
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 String invariantUUID;
40     private String UUID;
41     private String type;
42     private String category;
43     private String subcategory;
44     private String resourceVendor;
45     private String resourceVendorRelease;
46     private String serviceRole;
47     private String serviceEcompNaming;
48     private String ecompGeneratedNaming;
49     private String namingPolicy;
50     private String projectCode;
51     private List<UploadArtifactInfo> artifactList;
52     private String contactId, name, serviceIconPath, icon, vendorName, vendorRelease, serviceVendorModelNumber;
53     private String serviceType = "";
54     private String model;
55
56     public UploadServiceInfo(String payloadData, String payloadName, String description, List<String> tags, String invariantUUID, String UUID,
57                              String type, String category, String subcategory, String resourceVendor, String resourceVendorRelease,
58                              String serviceRole, String serviceEcompNaming, String ecompGeneratedNaming, String namingPolicy,
59                              List<UploadArtifactInfo> artifactList, String contactId, String name, String resourceIconPath, String icon,
60                              String vendorName, String vendorRelease, String serviceVendorModelNumber, String serviceType, String projectCode, String model) {
61         this.payloadData = payloadData;
62         this.payloadName = payloadName;
63         this.description = description;
64         this.tags = tags;
65         this.invariantUUID = invariantUUID;
66         this.UUID = UUID;
67         this.type = type;
68         this.category = category;
69         this.subcategory = subcategory;
70         this.resourceVendor = resourceVendor;
71         this.resourceVendorRelease = resourceVendorRelease;
72         this.serviceRole = serviceRole;
73         this.serviceEcompNaming = serviceEcompNaming;
74         this.ecompGeneratedNaming = ecompGeneratedNaming;
75         this.namingPolicy = namingPolicy;
76         this.artifactList = artifactList;
77         this.contactId = contactId;
78         this.name = name;
79         this.serviceIconPath = serviceIconPath;
80         this.icon = icon;
81         this.vendorName = vendorName;
82         this.vendorRelease = vendorRelease;
83         this.serviceVendorModelNumber = serviceVendorModelNumber;
84         this.serviceType = serviceType;
85         this.projectCode = projectCode;
86         this.model = model;
87         if (category != null) {
88             String[] arr = category.split("/");
89             if (arr.length >= 2) {
90                 categories = new ArrayList<>();
91                 CategoryDefinition catDef = new CategoryDefinition();
92                 catDef.setName(arr[0]);
93                 SubCategoryDefinition subCat = new SubCategoryDefinition();
94                 subCat.setName(arr[1]);
95                 catDef.addSubCategory(subCat);
96                 categories.add(catDef);
97             }
98         }
99     }
100
101     public UploadServiceInfo() {
102     }
103
104     public void addSubCategory(String category, String subCategory) {
105         if (category != null || subCategory != null) {
106             if (categories == null) {
107                 categories = new ArrayList<>();
108             }
109             CategoryDefinition selectedCategory = null;
110             for (CategoryDefinition categoryDef : categories) {
111                 if (categoryDef.getName().equals(category)) {
112                     selectedCategory = categoryDef;
113                 }
114             }
115             if (selectedCategory == null) {
116                 selectedCategory = new CategoryDefinition();
117                 selectedCategory.setName(category);
118                 categories.add(selectedCategory);
119             }
120             List<SubCategoryDefinition> subcategories = selectedCategory.getSubcategories();
121             if (subcategories == null) {
122                 subcategories = new ArrayList<>();
123                 selectedCategory.setSubcategories(subcategories);
124             }
125             SubCategoryDefinition selectedSubcategory = null;
126             for (SubCategoryDefinition subcategory : subcategories) {
127                 if (subcategory.getName().equals(subCategory)) {
128                     selectedSubcategory = subcategory;
129                 }
130             }
131             if (selectedSubcategory == null) {
132                 selectedSubcategory = new SubCategoryDefinition();
133                 selectedSubcategory.setName(subCategory);
134                 subcategories.add(selectedSubcategory);
135             }
136         }
137     }
138 }