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