2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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 * ===================================================================
24 package org.onap.clamp.clds.model.sdc;
26 import com.att.eelf.configuration.EELFLogger;
27 import com.att.eelf.configuration.EELFManager;
29 import java.math.BigDecimal;
30 import java.util.List;
32 public class SdcResource implements Comparable<SdcResource> {
34 protected static final EELFLogger logger = EELFManager.getInstance().getLogger(SdcResource.class);
35 protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
37 private String resourceInstanceName;
38 private String resourceName;
39 private String resourceInvariantUUID;
40 private String resourceVersion;
41 private String resoucreType;
42 private String resourceUuid;
43 private List<SdcArtifact> artifacts;
45 public String getResourceInstanceName() {
46 return resourceInstanceName;
49 public void setResourceInstanceName(String resourceInstanceName) {
50 this.resourceInstanceName = resourceInstanceName;
53 public String getResourceName() {
57 public void setResourceName(String resourceName) {
58 this.resourceName = resourceName;
61 public String getResourceInvariantUUID() {
62 return resourceInvariantUUID;
65 public void setResourceInvariantUUID(String resourceInvUuid) {
66 this.resourceInvariantUUID = resourceInvUuid;
69 public String getResourceVersion() {
70 return resourceVersion;
73 public void setResourceVersion(String resourceVersion) {
74 this.resourceVersion = resourceVersion;
77 public String getResoucreType() {
81 public void setResoucreType(String resoucreType) {
82 this.resoucreType = resoucreType;
85 public String getResourceUUID() {
89 public void setResourceUUID(String resourceUUID) {
90 this.resourceUuid = resourceUUID;
93 public List<SdcArtifact> getArtifacts() {
97 public void setArtifacts(List<SdcArtifact> artifacts) {
98 this.artifacts = artifacts;
102 public int compareTo(SdcResource in) {
103 // Compares this object with the specified object for order.
104 // Returns a negative integer, zero, or a positive integer as this
105 // object is less than, equal to, or greater than the specified object.
107 // first compare based on name
108 int rtn = resourceInstanceName.compareToIgnoreCase(in.resourceInstanceName);
111 BigDecimal myVersion = convertVersion(resourceVersion);
112 BigDecimal inVersion = convertVersion(in.resourceVersion);
113 rtn = myVersion.compareTo(inVersion);
119 public int hashCode() {
120 final int prime = 31;
122 result = prime * result + ((resourceInstanceName == null) ? 0 : resourceInstanceName.hashCode());
123 result = prime * result + ((resourceVersion == null) ? 0 : resourceVersion.hashCode());
128 public boolean equals(Object obj) {
133 if (getClass() != obj.getClass())
135 SdcResource other = (SdcResource) obj;
136 if (resourceInstanceName == null) {
137 if (other.resourceInstanceName != null)
139 } else if (!resourceInstanceName.equals(other.resourceInstanceName))
141 if (resourceVersion == null) {
142 if (other.resourceVersion != null)
144 } else if (!resourceVersion.equals(other.resourceVersion))
150 * Convert version String into a BigDecimal
155 private BigDecimal convertVersion(String versionText) {
156 BigDecimal rtn = BigDecimal.valueOf(0.0);
158 rtn = new BigDecimal(versionText);
159 } catch (NumberFormatException nfe) {
160 logger.warn("SDC version=" + versionText + " is not decimal for name=" + resourceInstanceName);