Repair healthcheck
[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  *
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
29 import java.math.BigDecimal;
30
31 public class SdcResourceBasicInfo implements Comparable<SdcResourceBasicInfo> {
32
33     protected static final EELFLogger logger = EELFManager.getInstance().getLogger(SdcResourceBasicInfo.class);
34     protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
35
36     private String uuid;
37     private String invariantUUID;
38     private String name;
39     private String version;
40     private String toscaModelURL;
41     private String category;
42     private String subCategory;
43     private String resourceType;
44     private String lifecycleState;
45     private String lastUpdaterUserId;
46
47     @Override
48     public int compareTo(SdcResourceBasicInfo in) {
49         // Compares this object with the specified object for order.
50         // Returns a negative integer, zero, or a positive integer as this
51         // object is less than, equal to, or greater than the specified object.
52         // first compare based on name
53         int rtn = name.compareToIgnoreCase(in.name);
54
55         if (rtn == 0) {
56             BigDecimal myVersion = convertVersion(version);
57             BigDecimal inVersion = convertVersion(in.version);
58             rtn = myVersion.compareTo(inVersion);
59         }
60         return rtn;
61     }
62
63     @Override
64     public int hashCode() {
65         final int prime = 31;
66         int result = 1;
67         result = prime * result + ((name == null) ? 0 : name.hashCode());
68         result = prime * result + ((version == null) ? 0 : version.hashCode());
69         return result;
70     }
71
72     @Override
73     public boolean equals(Object obj) {
74         if (this == obj) {
75             return true;
76         }
77         if (obj == null) {
78             return false;
79         }
80         if (getClass() != obj.getClass()) {
81             return false;
82         }
83         SdcResourceBasicInfo other = (SdcResourceBasicInfo) obj;
84         if (name == null) {
85             if (other.name != null) {
86                 return false;
87             }
88         } else if (!name.equals(other.name)) {
89             return false;
90         }
91         if (version == null) {
92             if (other.version != null) {
93                 return false;
94             }
95         } else if (!version.equals(other.version)) {
96             return false;
97         }
98         return true;
99     }
100
101     /**
102      * Convert version String into a BigDecimal.
103      *
104      * @param version version
105      * @return version in BigDecimal
106      */
107     private BigDecimal convertVersion(String version) {
108         BigDecimal rtn = BigDecimal.valueOf(0.0);
109         try {
110             rtn = new BigDecimal(version);
111         } catch (NumberFormatException nfe) {
112             logger.warn("SDC version=" + version + " is not decimal for name=" + name);
113         }
114         return rtn;
115     }
116
117     public String getUuid() {
118         return uuid;
119     }
120
121     public void setUuid(String uuid) {
122         this.uuid = uuid;
123     }
124
125     public String getInvariantUUID() {
126         return invariantUUID;
127     }
128
129     public void setInvariantUUID(String invariantUUID) {
130         this.invariantUUID = invariantUUID;
131     }
132
133     public String getName() {
134         return name;
135     }
136
137     public void setName(String name) {
138         this.name = name;
139     }
140
141     public String getVersion() {
142         return version;
143     }
144
145     public void setVersion(String version) {
146         this.version = version;
147     }
148
149     public String getToscaModelURL() {
150         return toscaModelURL;
151     }
152
153     public void setToscaModelURL(String toscaModelURL) {
154         this.toscaModelURL = toscaModelURL;
155     }
156
157     public String getCategory() {
158         return category;
159     }
160
161     public void setCategory(String category) {
162         this.category = category;
163     }
164
165     public String getSubCategory() {
166         return subCategory;
167     }
168
169     public void setSubCategory(String subCategory) {
170         this.subCategory = subCategory;
171     }
172
173     public String getResourceType() {
174         return resourceType;
175     }
176
177     public void setResourceType(String resourceType) {
178         this.resourceType = resourceType;
179     }
180
181     public String getLifecycleState() {
182         return lifecycleState;
183     }
184
185     public void setLifecycleState(String lifecycleState) {
186         this.lifecycleState = lifecycleState;
187     }
188
189     public String getLastUpdaterUserId() {
190         return lastUpdaterUserId;
191     }
192
193     public void setLastUpdaterUserId(String lastUpdaterUserId) {
194         this.lastUpdaterUserId = lastUpdaterUserId;
195     }
196
197     public EELFLogger getLOGGER() {
198         return logger;
199     }
200 }