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