Replaced all tabs with spaces in java and pom.xml
[so.git] / asdc-controller / src / main / java / org / onap / so / asdc / client / test / emulators / NotificationDataImpl.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.asdc.client.test.emulators;
22
23 import java.util.ArrayList;
24 import java.util.List;
25 import org.apache.commons.lang3.builder.EqualsBuilder;
26 import org.apache.commons.lang3.builder.HashCodeBuilder;
27 import org.onap.sdc.api.notification.IArtifactInfo;
28 import org.onap.sdc.api.notification.INotificationData;
29 import org.onap.sdc.api.notification.IResourceInstance;
30 import org.springframework.stereotype.Component;
31 import com.fasterxml.jackson.annotation.JsonAutoDetect;
32 import com.fasterxml.jackson.annotation.JsonProperty;
33 import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
34
35 @Component
36 @JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE,
37         setterVisibility = Visibility.NONE)
38 public class NotificationDataImpl implements INotificationData {
39
40     @JsonProperty("distributionID")
41     private String distributionID;
42     @JsonProperty("serviceName")
43     private String serviceName;
44     @JsonProperty("serviceVersion")
45     private String serviceVersion;
46     @JsonProperty("serviceUUID")
47     private String serviceUUID;
48     @JsonProperty("serviceDescription")
49     private String serviceDescription;
50     @JsonProperty("serviceInvariantUUID")
51     private String serviceInvariantUUID;
52     @JsonProperty("resources")
53     private List<ResourceInfoImpl> resources;
54     @JsonProperty("serviceArtifacts")
55     private List<ArtifactInfoImpl> serviceArtifacts;
56     @JsonProperty("workloadContext")
57     private String workloadContext;
58
59     @Override
60     public String getDistributionID() {
61         return distributionID;
62     }
63
64     @Override
65     public String getServiceName() {
66         return serviceName;
67     }
68
69     @Override
70     public String getServiceVersion() {
71         return serviceVersion;
72     }
73
74     @Override
75     public String getServiceUUID() {
76         return serviceUUID;
77     }
78
79     public void setDistributionID(String distributionID) {
80         this.distributionID = distributionID;
81     }
82
83     public void setServiceName(String serviceName) {
84         this.serviceName = serviceName;
85     }
86
87     public void setServiceVersion(String serviceVersion) {
88         this.serviceVersion = serviceVersion;
89     }
90
91     public void setServiceUUID(String serviceUUID) {
92         this.serviceUUID = serviceUUID;
93     }
94
95
96
97     public String getServiceDescription() {
98         return serviceDescription;
99     }
100
101     public void setServiceDescription(String serviceDescription) {
102         this.serviceDescription = serviceDescription;
103     }
104
105     @Override
106     public String getWorkloadContext() {
107         return workloadContext;
108     }
109
110     @Override
111     public void setWorkloadContext(String workloadContext) {
112         this.workloadContext = workloadContext;
113     }
114
115     @Override
116     public String toString() {
117         return "NotificationDataImpl [distributionID=" + distributionID + ", serviceName=" + serviceName
118                 + ", serviceVersion=" + serviceVersion + ", serviceUUID=" + serviceUUID + ", serviceDescription="
119                 + serviceDescription + ", serviceInvariantUUID=" + serviceInvariantUUID + ", resources=" + resources
120                 + ", serviceArtifacts=" + serviceArtifacts + ", workloadContext=" + workloadContext + "]";
121     }
122
123     @Override
124     public List<IResourceInstance> getResources() {
125         List<IResourceInstance> ret = new ArrayList<IResourceInstance>();
126         if (resources != null) {
127             ret.addAll(resources);
128         }
129         return ret;
130     }
131
132     public void setResources(List<ResourceInfoImpl> resources) {
133         this.resources = resources;
134     }
135
136     public List<ResourceInfoImpl> getResourcesImpl() {
137         return resources;
138     }
139
140     List<ArtifactInfoImpl> getServiceArtifactsImpl() {
141         return serviceArtifacts;
142     }
143
144     @Override
145     public List<IArtifactInfo> getServiceArtifacts() {
146         List<IArtifactInfo> temp = new ArrayList<IArtifactInfo>();
147         if (serviceArtifacts != null) {
148             temp.addAll(serviceArtifacts);
149         }
150         return temp;
151     }
152
153     public void setServiceArtifacts(List<ArtifactInfoImpl> relevantServiceArtifacts) {
154         serviceArtifacts = relevantServiceArtifacts;
155
156     }
157
158     @Override
159     public String getServiceInvariantUUID() {
160         return serviceInvariantUUID;
161     }
162
163
164     public void setServiceInvariantUUID(String serviceInvariantUUID) {
165         this.serviceInvariantUUID = serviceInvariantUUID;
166     }
167
168     @Override
169     public IArtifactInfo getArtifactMetadataByUUID(String artifactUUID) {
170         IArtifactInfo ret = findArtifactInfoByUUID(artifactUUID, serviceArtifacts);
171         if (ret == null && resources != null) {
172             for (ResourceInfoImpl currResourceInstance : resources) {
173                 ret = findArtifactInfoByUUID(artifactUUID, currResourceInstance.getArtifactsImpl());
174                 if (ret != null) {
175                     break;
176                 }
177             }
178         }
179         return ret;
180
181     }
182
183     private IArtifactInfo findArtifactInfoByUUID(String artifactUUID, List<ArtifactInfoImpl> listToCheck) {
184         IArtifactInfo ret = null;
185         if (listToCheck != null) {
186             for (IArtifactInfo curr : listToCheck) {
187                 if (curr.getArtifactUUID().equals(artifactUUID)) {
188                     ret = curr;
189                     break;
190                 }
191             }
192         }
193         return ret;
194     }
195
196     @Override
197     public boolean equals(final Object other) {
198         if (!(other instanceof NotificationDataImpl)) {
199             return false;
200         }
201         NotificationDataImpl castOther = (NotificationDataImpl) other;
202         return new EqualsBuilder().append(serviceUUID, castOther.serviceUUID)
203                 .append(serviceVersion, castOther.serviceVersion).isEquals();
204     }
205
206     @Override
207     public int hashCode() {
208         return new HashCodeBuilder().append(distributionID).append(serviceName).append(serviceVersion)
209                 .append(serviceUUID).append(serviceDescription).append(serviceInvariantUUID).append(resources)
210                 .append(serviceArtifacts).append(workloadContext).toHashCode();
211     }
212
213 }