Remove ECOMP in headers
[clamp.git] / src / main / java / org / onap / clamp / clds / model / sdc / SdcResource.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2017-2018 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 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
29
30 import java.math.BigDecimal;
31 import java.util.List;
32
33 @JsonIgnoreProperties(ignoreUnknown = true)
34 public class SdcResource implements Comparable<SdcResource> {
35
36     protected static final EELFLogger logger        = EELFManager.getInstance().getLogger(SdcResource.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<SdcArtifact>     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 resourceInvUuid) {
68         this.resourceInvariantUUID = resourceInvUuid;
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<SdcArtifact> getArtifacts() {
96         return artifacts;
97     }
98
99     public void setArtifacts(List<SdcArtifact> artifacts) {
100         this.artifacts = artifacts;
101     }
102
103     @Override
104     public int compareTo(SdcResource 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     @Override
121     public int hashCode() {
122         final int prime = 31;
123         int result = 1;
124         result = prime * result + ((resourceInstanceName == null) ? 0 : resourceInstanceName.hashCode());
125         result = prime * result + ((resourceVersion == null) ? 0 : resourceVersion.hashCode());
126         return result;
127     }
128
129     @Override
130     public boolean equals(Object obj) {
131         if (this == obj)
132             return true;
133         if (obj == null)
134             return false;
135         if (getClass() != obj.getClass())
136             return false;
137         SdcResource other = (SdcResource) obj;
138         if (resourceInstanceName == null) {
139             if (other.resourceInstanceName != null)
140                 return false;
141         } else if (!resourceInstanceName.equals(other.resourceInstanceName))
142             return false;
143         if (resourceVersion == null) {
144             if (other.resourceVersion != null)
145                 return false;
146         } else if (!resourceVersion.equals(other.resourceVersion))
147             return false;
148         return true;
149     }
150
151     /**
152      * Convert version String into a BigDecimal
153      *
154      * @param versionText
155      * @return
156      */
157     private BigDecimal convertVersion(String versionText) {
158         BigDecimal rtn = BigDecimal.valueOf(0.0);
159         try {
160             rtn = new BigDecimal(versionText);
161         } catch (NumberFormatException nfe) {
162             logger.warn("SDC version=" + versionText + " is not decimal for name=" + resourceInstanceName);
163         }
164         return rtn;
165     }
166 }