[CLAMP-1] Initial ONAP CLAMP seed code commit
[clamp.git] / src / main / java / org / onap / clamp / clds / model / CldsAsdcResource.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 com.fasterxml.jackson.annotation.JsonIgnoreProperties;
27
28 import java.math.BigDecimal;
29 import java.util.List;
30 import java.util.logging.Logger;
31
32 @JsonIgnoreProperties(ignoreUnknown = true)
33 public class CldsAsdcResource implements Comparable<CldsAsdcResource> {
34     private static final Logger logger = Logger.getLogger(CldsAsdcServiceInfo.class.getName());
35
36     private String resourceInstanceName;
37     private String resourceName;
38     private String resourceInvariantUUID;
39     private String resourceVersion;
40     private String resoucreType;
41     private String resourceUUID;
42     private List<CldsAsdcArtifact> artifacts;
43
44     public String getResourceInstanceName() {
45         return resourceInstanceName;
46     }
47
48     public void setResourceInstanceName(String resourceInstanceName) {
49         this.resourceInstanceName = resourceInstanceName;
50     }
51
52     public String getResourceName() {
53         return resourceName;
54     }
55
56     public void setResourceName(String resourceName) {
57         this.resourceName = resourceName;
58     }
59
60     public String getResourceInvariantUUID() {
61         return resourceInvariantUUID;
62     }
63
64     public void setResourceInvariantUUID(String resourceInvariantUUID) {
65         this.resourceInvariantUUID = resourceInvariantUUID;
66     }
67
68     public String getResourceVersion() {
69         return resourceVersion;
70     }
71
72     public void setResourceVersion(String resourceVersion) {
73         this.resourceVersion = resourceVersion;
74     }
75
76     public String getResoucreType() {
77         return resoucreType;
78     }
79
80     public void setResoucreType(String resoucreType) {
81         this.resoucreType = resoucreType;
82     }
83
84     public String getResourceUUID() {
85         return resourceUUID;
86     }
87
88     public void setResourceUUID(String resourceUUID) {
89         this.resourceUUID = resourceUUID;
90     }
91
92     public List<CldsAsdcArtifact> getArtifacts() {
93         return artifacts;
94     }
95
96     public void setArtifacts(List<CldsAsdcArtifact> artifacts) {
97         this.artifacts = artifacts;
98     }
99
100     @Override
101     public int compareTo(CldsAsdcResource in) {
102         // Compares this object with the specified object for order.
103         // Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
104
105         // first compare based on name
106         int rtn = resourceInstanceName.compareToIgnoreCase(in.resourceInstanceName);
107
108         if (rtn == 0) {
109             BigDecimal myVersion = convertVersion(resourceVersion);
110             BigDecimal inVersion = convertVersion(in.resourceVersion);
111             rtn = myVersion.compareTo(inVersion);
112         }
113         return rtn;
114     }
115
116     /**
117      * Convert version String into a BigDecimal
118      *
119      * @param versionText
120      * @return
121      */
122     private BigDecimal convertVersion(String versionText) {
123         BigDecimal rtn = new BigDecimal(0.0);
124         try {
125             rtn = new BigDecimal(versionText);
126         } catch (NumberFormatException nfe) {
127             logger.warning("ASDC version=" + versionText + " is not decimal for name=" + resourceInstanceName);
128         }
129         return rtn;
130     }
131 }