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