Reformat catalog-model
[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 package org.openecomp.sdc.be.ui.model;
21
22 import com.fasterxml.jackson.annotation.JsonIgnore;
23 import java.util.List;
24 import lombok.Getter;
25 import lombok.Setter;
26 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
27 import org.openecomp.sdc.be.model.Component;
28 import org.openecomp.sdc.be.model.category.CategoryDefinition;
29 import org.openecomp.sdc.common.util.ICategorizedElement;
30
31 @Getter
32 @Setter
33 public class UiLeftPaletteComponent implements ICategorizedElement {
34
35     private final String uniqueId;
36     private final String name; // archiveName
37
38     private final String version; // archiveVersion
39     private final String description;
40     private final List<String> tags;
41     private final String icon;
42     private final String UUID;
43     private final String systemName;
44     private final String invariantUUID;
45     private final ComponentTypeEnum componentType;
46     private final String resourceType;
47     private final String categoryName;
48     private final String subCategoryName;
49     private final String searchFilterTerms;
50     private final List<CategoryDefinition> categories;
51
52     public UiLeftPaletteComponent(final Component component) {
53         this.uniqueId = component.getUniqueId();
54         this.name = component.getName();
55         this.version = component.getVersion();
56         this.description = component.getDescription();
57         this.tags = component.getTags();
58         this.icon = component.getIcon();
59         this.UUID = component.getUUID();
60         this.systemName = component.getSystemName();
61         this.invariantUUID = component.getInvariantUUID();
62         this.componentType = component.getComponentType();
63         this.resourceType = component.getActualComponentType();
64         this.categories = component.getCategories();
65         this.categoryName = getCategoryName();
66         this.subCategoryName = getSubcategoryName();
67         this.searchFilterTerms = (name + " " + description + " " + convertListResultToString(tags) + version);
68     }
69
70     private String convertListResultToString(final List<String> tags) {
71         final StringBuilder sb = new StringBuilder();
72         if (tags != null) {
73             tags.forEach(t -> sb.append(t + " "));
74         }
75         return sb.toString().toLowerCase();
76     }
77
78     @JsonIgnore
79     @Override
80     public String getComponentTypeAsString() {
81         return componentType.name();
82     }
83
84     @JsonIgnore
85     public String getCategoryName() {
86         return categories.get(0).getName();
87     }
88
89     @JsonIgnore
90     public String getSubcategoryName() {
91         if (componentType == ComponentTypeEnum.SERVICE) {
92             return null;
93         }
94         return categories.get(0).getSubcategories().get(0).getName();
95     }
96 }