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