e853621b49b2d7c15fe6edfad23704b5017fbc1b
[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         if (obj == null)
77             return false;
78         if (getClass() != obj.getClass())
79             return false;
80         SdcResourceBasicInfo other = (SdcResourceBasicInfo) obj;
81         if (name == null) {
82             if (other.name != null)
83                 return false;
84         } else if (!name.equals(other.name))
85             return false;
86         if (version == null) {
87             if (other.version != null)
88                 return false;
89         } else if (!version.equals(other.version))
90             return false;
91         return true;
92     }
93
94     /**
95      * Convert version String into a BigDecimal
96      *
97      * @param version
98      * @return
99      */
100     private BigDecimal convertVersion(String version) {
101         BigDecimal rtn = BigDecimal.valueOf(0.0);
102         try {
103             rtn = new BigDecimal(version);
104         } catch (NumberFormatException nfe) {
105             logger.warn("SDC version=" + version + " is not decimal for name=" + name);
106         }
107         return rtn;
108     }
109
110     public String getUuid() {
111         return uuid;
112     }
113
114     public void setUuid(String uuid) {
115         this.uuid = uuid;
116     }
117
118     public String getInvariantUUID() {
119         return invariantUUID;
120     }
121
122     public void setInvariantUUID(String invariantUUID) {
123         this.invariantUUID = invariantUUID;
124     }
125
126     public String getName() {
127         return name;
128     }
129
130     public void setName(String name) {
131         this.name = name;
132     }
133
134     public String getVersion() {
135         return version;
136     }
137
138     public void setVersion(String version) {
139         this.version = version;
140     }
141
142     public String getToscaModelURL() {
143         return toscaModelURL;
144     }
145
146     public void setToscaModelURL(String toscaModelURL) {
147         this.toscaModelURL = toscaModelURL;
148     }
149
150     public String getCategory() {
151         return category;
152     }
153
154     public void setCategory(String category) {
155         this.category = category;
156     }
157
158     public String getSubCategory() {
159         return subCategory;
160     }
161
162     public void setSubCategory(String subCategory) {
163         this.subCategory = subCategory;
164     }
165
166     public String getResourceType() {
167         return resourceType;
168     }
169
170     public void setResourceType(String resourceType) {
171         this.resourceType = resourceType;
172     }
173
174     public String getLifecycleState() {
175         return lifecycleState;
176     }
177
178     public void setLifecycleState(String lifecycleState) {
179         this.lifecycleState = lifecycleState;
180     }
181
182     public String getLastUpdaterUserId() {
183         return lastUpdaterUserId;
184     }
185
186     public void setLastUpdaterUserId(String lastUpdaterUserId) {
187         this.lastUpdaterUserId = lastUpdaterUserId;
188     }
189
190     public EELFLogger getLOGGER() {
191         return logger;
192     }
193 }