cbe16d864ac00f1dfe5058287953e6f29eeb3d88
[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
26 import org.apache.commons.lang3.builder.EqualsBuilder;
27 import org.apache.commons.lang3.builder.HashCodeBuilder;
28 import org.onap.sdc.api.notification.IArtifactInfo;
29 import org.onap.sdc.api.notification.INotificationData;
30 import org.onap.sdc.api.notification.IResourceInstance;
31 import org.springframework.stereotype.Component;
32
33 import com.fasterxml.jackson.annotation.JsonAutoDetect;
34 import com.fasterxml.jackson.annotation.JsonProperty;
35 import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
36
37 @Component
38 @JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE)
39 public class NotificationDataImpl implements INotificationData {
40
41         @JsonProperty("distributionID")
42         private String distributionID;
43         @JsonProperty("serviceName")
44         private String serviceName;
45         @JsonProperty("serviceVersion")
46         private String serviceVersion;
47         @JsonProperty("serviceUUID")
48         private String serviceUUID;
49         @JsonProperty("serviceDescription")
50         private String serviceDescription;
51         @JsonProperty("serviceInvariantUUID")
52         private String serviceInvariantUUID;
53         @JsonProperty("resources")
54         private List<ResourceInfoImpl> resources;
55         @JsonProperty("serviceArtifacts")
56         private List<ArtifactInfoImpl> serviceArtifacts;
57         @JsonProperty("workloadContext")
58         private String workloadContext;
59
60         @Override
61         public String getDistributionID() {
62                 return distributionID;
63         }
64
65         @Override
66         public String getServiceName() {
67                 return serviceName;
68         }
69
70         @Override
71         public String getServiceVersion() {
72                 return serviceVersion;
73         }
74
75         @Override
76         public String getServiceUUID() {
77                 return serviceUUID;
78         }
79
80         public void setDistributionID(String distributionID) {
81                 this.distributionID = distributionID;
82         }
83
84         public void setServiceName(String serviceName) {
85                 this.serviceName = serviceName;
86         }
87
88         public void setServiceVersion(String serviceVersion) {
89                 this.serviceVersion = serviceVersion;
90         }
91
92         public void setServiceUUID(String serviceUUID) {
93                 this.serviceUUID = serviceUUID;
94         }
95
96         
97
98         public String getServiceDescription() {
99                 return serviceDescription;
100         }
101
102         public void setServiceDescription(String serviceDescription) {
103                 this.serviceDescription = serviceDescription;
104         }
105
106         @Override
107         public String getWorkloadContext() { 
108                 return workloadContext; 
109         }
110
111         @Override
112         public void setWorkloadContext(String workloadContext) {
113                 this.workloadContext = workloadContext; 
114         }
115
116         @Override
117         public String toString() {
118                 return "NotificationDataImpl [distributionID=" + distributionID + ", serviceName=" + serviceName
119                                 + ", serviceVersion=" + serviceVersion + ", serviceUUID=" + serviceUUID + ", serviceDescription="
120                                 + serviceDescription + ", serviceInvariantUUID=" + serviceInvariantUUID + ", resources=" + resources
121                                 + ", serviceArtifacts=" + serviceArtifacts + ", workloadContext=" + workloadContext + "]";
122         }
123
124         @Override
125         public List<IResourceInstance> getResources() {
126                 List<IResourceInstance> ret = new ArrayList<IResourceInstance>();
127                 if( resources != null ){
128                         ret.addAll(resources);
129                 }
130                 return ret;
131         }
132         
133         public List<ResourceInfoImpl> getResourcesImpl(){
134                 return resources;
135         }
136         
137         List<ArtifactInfoImpl> getServiceArtifactsImpl(){
138                 return serviceArtifacts;
139         }
140
141         @Override
142         public List<IArtifactInfo> getServiceArtifacts() {
143                 List<IArtifactInfo> temp = new ArrayList<IArtifactInfo>();
144                 if( serviceArtifacts != null ){
145                         temp.addAll(serviceArtifacts);
146                 }
147                 return temp;
148         }
149         
150         public void setServiceArtifacts(List<ArtifactInfoImpl> relevantServiceArtifacts) {
151                 serviceArtifacts = relevantServiceArtifacts;
152                 
153         }
154         
155         @Override
156         public String getServiceInvariantUUID() {
157                 return serviceInvariantUUID;
158         }
159         
160         
161         public void setServiceInvariantUUID(String serviceInvariantUUID) {
162                 this.serviceInvariantUUID = serviceInvariantUUID;
163         }
164         @Override
165         public IArtifactInfo getArtifactMetadataByUUID(String artifactUUID){
166                 IArtifactInfo ret = findArtifactInfoByUUID(artifactUUID, serviceArtifacts);
167                 if( ret == null && resources != null ){
168                         for( ResourceInfoImpl currResourceInstance : resources ){
169                                 ret = findArtifactInfoByUUID(artifactUUID, currResourceInstance.getArtifactsImpl());
170                                 if( ret != null ){
171                                         break;
172                                 }
173                         }
174                 }
175                 return ret;
176
177         }
178
179         private IArtifactInfo findArtifactInfoByUUID(String artifactUUID, List<ArtifactInfoImpl> listToCheck) {
180                 IArtifactInfo ret = null;
181                 if( listToCheck != null ){
182                         for(IArtifactInfo curr: listToCheck ){
183                                 if(curr.getArtifactUUID().equals(artifactUUID) ){
184                                         ret = curr;
185                                         break;
186                                 }
187                         }
188                 }
189                 return ret;
190         }
191
192         @Override
193         public boolean equals(final Object other) {
194                 if (!(other instanceof NotificationDataImpl)) {
195                         return false;
196                 }
197                 NotificationDataImpl castOther = (NotificationDataImpl) other;
198                 return new EqualsBuilder().append(serviceUUID, castOther.serviceUUID)
199                                 .append(serviceVersion, castOther.serviceVersion).isEquals();
200         }
201
202         @Override
203         public int hashCode() {
204                 return new HashCodeBuilder().append(distributionID).append(serviceName).append(serviceVersion)
205                                 .append(serviceUUID).append(serviceDescription).append(serviceInvariantUUID).append(resources)
206                                 .append(serviceArtifacts).append(workloadContext).toHashCode();
207         }
208
209 }