Rework of the unit tests (mainly IT)
[clamp.git] / src / main / java / org / onap / clamp / clds / model / CldsAsdcServiceInfo.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;
25
26 import java.math.BigDecimal;
27 import java.util.logging.Logger;
28
29 public class CldsAsdcServiceInfo implements Comparable<CldsAsdcServiceInfo> {
30     private static final Logger logger = Logger.getLogger(CldsAsdcServiceInfo.class.getName());
31
32     private String uuid;
33     private String invariantUUID;
34     private String name;
35     private String version;
36     private String toscaModelURL;
37     private String category;
38     private String lifecycleState;
39     private String lastUpdaterUserId;
40     private String distributionStatus;
41
42     public String getUuid() {
43         return uuid;
44     }
45
46     public void setUuid(String uuid) {
47         this.uuid = uuid;
48     }
49
50     public String getInvariantUUID() {
51         return invariantUUID;
52     }
53
54     public void setInvariantUUID(String invariantUUID) {
55         this.invariantUUID = invariantUUID;
56     }
57
58     public String getName() {
59         return name;
60     }
61
62     public void setName(String name) {
63         this.name = name;
64     }
65
66     public String getVersion() {
67         return version;
68     }
69
70     public void setVersion(String version) {
71         this.version = version;
72     }
73
74     public String getToscaModelURL() {
75         return toscaModelURL;
76     }
77
78     public void setToscaModelURL(String toscaModelURL) {
79         this.toscaModelURL = toscaModelURL;
80     }
81
82     public String getCategory() {
83         return category;
84     }
85
86     public void setCategory(String category) {
87         this.category = category;
88     }
89
90     public String getLifecycleState() {
91         return lifecycleState;
92     }
93
94     public void setLifecycleState(String lifecycleState) {
95         this.lifecycleState = lifecycleState;
96     }
97
98     public String getLastUpdaterUserId() {
99         return lastUpdaterUserId;
100     }
101
102     public void setLastUpdaterUserId(String lastUpdaterUserId) {
103         this.lastUpdaterUserId = lastUpdaterUserId;
104     }
105
106     public String getDistributionStatus() {
107         return distributionStatus;
108     }
109
110     public void setDistributionStatus(String distributionStatus) {
111         this.distributionStatus = distributionStatus;
112     }
113
114     /**
115      * Compare using name and then version.  Version is converted to a decimal.
116      */
117     @Override
118     public int compareTo(CldsAsdcServiceInfo in) {
119         // Compares this object with the specified object for order.
120         // Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
121         // first compare based on name
122         int rtn = name.compareToIgnoreCase(in.name);
123
124         if (rtn == 0) {
125             BigDecimal myVersion = convertVersion(version);
126             BigDecimal inVersion = convertVersion(in.version);
127             rtn = myVersion.compareTo(inVersion);
128         }
129
130         return rtn;
131     }
132
133     /**
134      * Convert version String into a BigDecimal
135      *
136      * @param versionText
137      * @return
138      */
139     private BigDecimal convertVersion(String versionText) {
140         try {
141             return new BigDecimal(versionText);
142         } catch (NumberFormatException nfe) {
143             logger.warning("ASDC version=" + versionText + " is not decimal for name=" + name);
144         }
145         return new BigDecimal(0.0);
146     }
147
148 }