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