Catalog alignment
[sdc.git] / catalog-model / src / main / java / org / openecomp / sdc / be / ui / model / UiLeftPaletteComponent.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2020 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
21 package org.openecomp.sdc.be.ui.model;
22
23 import com.fasterxml.jackson.annotation.JsonIgnore;
24 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
25 import org.openecomp.sdc.be.model.Component;
26 import org.openecomp.sdc.be.model.category.CategoryDefinition;
27 import org.openecomp.sdc.common.util.ICategorizedElement;
28
29 import java.util.List;
30
31 public class UiLeftPaletteComponent implements ICategorizedElement {
32     private String uniqueId;
33     private String name; // archiveName
34     private String version; // archiveVersion
35     private String description;
36     private List<String> tags;
37     private String icon;
38     private String UUID;
39     private String systemName;
40     private String invariantUUID;
41     private ComponentTypeEnum componentType;
42     private String resourceType;
43     private String categoryName;
44     private String subCategoryName;
45     private String searchFilterTerms;
46     private List<CategoryDefinition> categories;
47
48     public UiLeftPaletteComponent(Component component) {
49         this.uniqueId = component.getUniqueId();
50         this.name = component.getName();
51         this.version = component.getVersion();
52         this.description = component.getDescription();
53         this.tags = component.getTags();
54         this.icon = component.getIcon();
55         this.UUID = component.getUUID();
56         this.systemName = component.getSystemName();
57         this.invariantUUID = component.getInvariantUUID();
58         this.componentType = component.getComponentType();
59         this.resourceType = component.getActualComponentType();
60         this.categories = component.getCategories();
61         this.categoryName = getCategoryName();
62         this.subCategoryName = getSubcategoryName();
63         String tagString = convertListResultToString(tags);
64         setSearchFilterTerms(name + " " + description + " " + tagString + version);
65         this.searchFilterTerms = getSearchFilterTerms();
66     }
67
68     private String convertListResultToString(List<String> tags) {
69         StringBuilder sb = new StringBuilder();
70         tags.forEach(t->sb.append(t + " "));
71         return sb.toString().toLowerCase();
72     }
73
74     public String getUniqueId() {
75         return uniqueId;
76     }
77
78     public String getName() {
79         return name;
80     }
81
82     public String getVersion() {
83         return version;
84     }
85
86     public String getDescription() {
87         return description;
88     }
89
90     public List<String> getTags() {
91         return tags;
92     }
93     public String getIcon() {
94         return icon;
95     }
96
97     public String getUUID() {
98         return UUID;
99     }
100
101     public String getSystemName() {
102         return systemName;
103     }
104
105     public String getInvariantUUID() {
106         return invariantUUID;
107     }
108
109     public ComponentTypeEnum getComponentType() {
110         return componentType;
111     }
112
113     public String getResourceType() {
114         return resourceType;
115     }
116
117     public List<CategoryDefinition> getCategories() {
118         return categories;
119     }
120
121     public String getSearchFilterTerms() {
122         return searchFilterTerms;
123     }
124
125     public void setSearchFilterTerms(String searchFilterTerms) {
126         this.searchFilterTerms = searchFilterTerms;
127     }
128
129     @JsonIgnore
130     @Override
131     public String getComponentTypeAsString() {
132         return getComponentType().name();
133     }
134
135     @JsonIgnore
136     public String getCategoryName() {
137         return getCategories().get(0).getName();
138     }
139
140     @JsonIgnore
141     public String getSubcategoryName() {
142         if(componentType == ComponentTypeEnum.SERVICE){
143             return null;
144         }
145         return getCategories().get(0).getSubcategories().get(0).getName();
146     }
147 }