2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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 * ===================================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
24 package org.onap.clamp.clds.model;
26 import com.att.eelf.configuration.EELFLogger;
27 import com.att.eelf.configuration.EELFManager;
28 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
30 import java.math.BigDecimal;
31 import java.util.List;
33 @JsonIgnoreProperties(ignoreUnknown = true)
34 public class CldsSdcResource implements Comparable<CldsSdcResource> {
36 protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsSdcResource.class);
37 protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
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;
47 public String getResourceInstanceName() {
48 return resourceInstanceName;
51 public void setResourceInstanceName(String resourceInstanceName) {
52 this.resourceInstanceName = resourceInstanceName;
55 public String getResourceName() {
59 public void setResourceName(String resourceName) {
60 this.resourceName = resourceName;
63 public String getResourceInvariantUUID() {
64 return resourceInvariantUuid;
67 public void setResourceInvariantUUID(String resourceInvariantUUID) {
68 this.resourceInvariantUuid = resourceInvariantUUID;
71 public String getResourceVersion() {
72 return resourceVersion;
75 public void setResourceVersion(String resourceVersion) {
76 this.resourceVersion = resourceVersion;
79 public String getResoucreType() {
83 public void setResoucreType(String resoucreType) {
84 this.resoucreType = resoucreType;
87 public String getResourceUUID() {
91 public void setResourceUUID(String resourceUUID) {
92 this.resourceUuid = resourceUUID;
95 public List<CldsSdcArtifact> getArtifacts() {
99 public void setArtifacts(List<CldsSdcArtifact> artifacts) {
100 this.artifacts = artifacts;
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.
109 // first compare based on name
110 int rtn = resourceInstanceName.compareToIgnoreCase(in.resourceInstanceName);
113 BigDecimal myVersion = convertVersion(resourceVersion);
114 BigDecimal inVersion = convertVersion(in.resourceVersion);
115 rtn = myVersion.compareTo(inVersion);
121 public int hashCode() {
122 final int prime = 31;
124 result = prime * result + ((resourceInstanceName == null) ? 0 : resourceInstanceName.hashCode());
125 result = prime * result + ((resourceVersion == null) ? 0 : resourceVersion.hashCode());
130 public boolean equals(Object obj) {
135 if (getClass() != obj.getClass())
137 CldsSdcResource other = (CldsSdcResource) obj;
138 if (resourceInstanceName == null) {
139 if (other.resourceInstanceName != null)
141 } else if (!resourceInstanceName.equals(other.resourceInstanceName))
143 if (resourceVersion == null) {
144 if (other.resourceVersion != null)
146 } else if (!resourceVersion.equals(other.resourceVersion))
152 * Convert version String into a BigDecimal
157 private BigDecimal convertVersion(String versionText) {
158 BigDecimal rtn = BigDecimal.valueOf(0.0);
160 rtn = new BigDecimal(versionText);
161 } catch (NumberFormatException nfe) {
162 logger.warn("SDC version=" + versionText + " is not decimal for name=" + resourceInstanceName);