3a60f6dcc835fa0906032eebebc61bda3b6f149f
[clamp.git] / src / main / java / org / onap / clamp / clds / model / sdc / SdcResourceBasicInfo.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END============================================
20  * ===================================================================
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  */
23
24 package org.onap.clamp.clds.model.sdc;
25
26 import com.att.eelf.configuration.EELFLogger;
27 import com.att.eelf.configuration.EELFManager;
28 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
29
30 import java.math.BigDecimal;
31
32 @JsonIgnoreProperties(ignoreUnknown = true)
33 public class SdcResourceBasicInfo implements Comparable<SdcResourceBasicInfo> {
34
35     protected static final EELFLogger logger        = EELFManager.getInstance()
36             .getLogger(SdcResourceBasicInfo.class);
37     protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
38
39     private String                    uuid;
40     private String                    invariantUUID;
41     private String                    name;
42     private String                    version;
43     private String                    toscaModelURL;
44     private String                    category;
45     private String                    subCategory;
46     private String                    resourceType;
47     private String                    lifecycleState;
48     private String                    lastUpdaterUserId;
49
50     @Override
51     public int compareTo(SdcResourceBasicInfo in) {
52         // Compares this object with the specified object for order.
53         // Returns a negative integer, zero, or a positive integer as this
54         // object is less than, equal to, or greater than the specified object.
55         // first compare based on name
56         int rtn = name.compareToIgnoreCase(in.name);
57
58         if (rtn == 0) {
59             BigDecimal myVersion = convertVersion(version);
60             BigDecimal inVersion = convertVersion(in.version);
61             rtn = myVersion.compareTo(inVersion);
62         }
63         return rtn;
64     }
65
66     @Override
67     public int hashCode() {
68         final int prime = 31;
69         int result = 1;
70         result = prime * result + ((name == null) ? 0 : name.hashCode());
71         result = prime * result + ((version == null) ? 0 : version.hashCode());
72         return result;
73     }
74
75     @Override
76     public boolean equals(Object obj) {
77         if (this == obj)
78             return true;
79         if (obj == null)
80             return false;
81         if (getClass() != obj.getClass())
82             return false;
83         SdcResourceBasicInfo other = (SdcResourceBasicInfo) obj;
84         if (name == null) {
85             if (other.name != null)
86                 return false;
87         } else if (!name.equals(other.name))
88             return false;
89         if (version == null) {
90             if (other.version != null)
91                 return false;
92         } else if (!version.equals(other.version))
93             return false;
94         return true;
95     }
96
97     /**
98      * Convert version String into a BigDecimal
99      *
100      * @param version
101      * @return
102      */
103     private BigDecimal convertVersion(String version) {
104         BigDecimal rtn = BigDecimal.valueOf(0.0);
105         try {
106             rtn = new BigDecimal(version);
107         } catch (NumberFormatException nfe) {
108             logger.warn("SDC version=" + version + " is not decimal for name=" + name);
109         }
110         return rtn;
111     }
112
113     public String getUuid() {
114         return uuid;
115     }
116
117     public void setUuid(String uuid) {
118         this.uuid = uuid;
119     }
120
121     public String getInvariantUUID() {
122         return invariantUUID;
123     }
124
125     public void setInvariantUUID(String invariantUUID) {
126         this.invariantUUID = invariantUUID;
127     }
128
129     public String getName() {
130         return name;
131     }
132
133     public void setName(String name) {
134         this.name = name;
135     }
136
137     public String getVersion() {
138         return version;
139     }
140
141     public void setVersion(String version) {
142         this.version = version;
143     }
144
145     public String getToscaModelURL() {
146         return toscaModelURL;
147     }
148
149     public void setToscaModelURL(String toscaModelURL) {
150         this.toscaModelURL = toscaModelURL;
151     }
152
153     public String getCategory() {
154         return category;
155     }
156
157     public void setCategory(String category) {
158         this.category = category;
159     }
160
161     public String getSubCategory() {
162         return subCategory;
163     }
164
165     public void setSubCategory(String subCategory) {
166         this.subCategory = subCategory;
167     }
168
169     public String getResourceType() {
170         return resourceType;
171     }
172
173     public void setResourceType(String resourceType) {
174         this.resourceType = resourceType;
175     }
176
177     public String getLifecycleState() {
178         return lifecycleState;
179     }
180
181     public void setLifecycleState(String lifecycleState) {
182         this.lifecycleState = lifecycleState;
183     }
184
185     public String getLastUpdaterUserId() {
186         return lastUpdaterUserId;
187     }
188
189     public void setLastUpdaterUserId(String lastUpdaterUserId) {
190         this.lastUpdaterUserId = lastUpdaterUserId;
191     }
192
193     public EELFLogger getLOGGER() {
194         return logger;
195     }
196 }