PNF ingestion in SO catalogdb
[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 void setResources(List<ResourceInfoImpl> resources){
134                 this.resources = resources;
135         }
136         
137         public List<ResourceInfoImpl> getResourcesImpl(){
138                 return resources;
139         }
140         
141         List<ArtifactInfoImpl> getServiceArtifactsImpl(){
142                 return serviceArtifacts;
143         }
144
145         @Override
146         public List<IArtifactInfo> getServiceArtifacts() {
147                 List<IArtifactInfo> temp = new ArrayList<IArtifactInfo>();
148                 if( serviceArtifacts != null ){
149                         temp.addAll(serviceArtifacts);
150                 }
151                 return temp;
152         }
153         
154         public void setServiceArtifacts(List<ArtifactInfoImpl> relevantServiceArtifacts) {
155                 serviceArtifacts = relevantServiceArtifacts;
156                 
157         }
158         
159         @Override
160         public String getServiceInvariantUUID() {
161                 return serviceInvariantUUID;
162         }
163         
164         
165         public void setServiceInvariantUUID(String serviceInvariantUUID) {
166                 this.serviceInvariantUUID = serviceInvariantUUID;
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 }