d135e79bc3e00da3dbff2db893d9184732b060b0
[policy/drools-applications.git] / vfwsim / src / main / java / org / openecomp / policy / sim / vfw / AppcResponseEvent.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * vFW simulator
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.openecomp.policy.sim.vfw;
22
23 import java.io.Serializable;
24 import java.util.UUID;
25
26 import org.openecomp.policy.appc.CommonHeader;
27 import org.openecomp.policy.appc.Response;
28 import org.openecomp.policy.appc.ResponseStatus;
29
30 public class AppcResponseEvent implements Serializable {
31
32         private static final long serialVersionUID = 6661836261200950007L;
33         
34         public final String requestID;
35         public final String appcTopic;
36         public final int code;
37         
38         public AppcResponseEvent(String requestID, String appcTopic, int code) {
39                 this.requestID = requestID;
40                 this.appcTopic = appcTopic;
41                 this.code = code;
42         }
43         
44         @Override
45         public int hashCode() {
46                 final int prime = 31;
47                 int result = 1;
48                 result = prime * result + ((appcTopic == null) ? 0 : appcTopic.hashCode());
49                 result = prime * result + code;
50                 result = prime * result + ((requestID == null) ? 0 : requestID.hashCode());
51                 return result;
52         }
53
54         @Override
55         public boolean equals(Object obj) {
56                 if (this == obj)
57                         return true;
58                 if (obj == null)
59                         return false;
60                 if (getClass() != obj.getClass())
61                         return false;
62                 AppcResponseEvent other = (AppcResponseEvent) obj;
63                 if (appcTopic == null) {
64                         if (other.appcTopic != null)
65                                 return false;
66                 } else if (!appcTopic.equals(other.appcTopic))
67                         return false;
68                 if (code != other.code)
69                         return false;
70                 if (requestID == null) {
71                         if (other.requestID != null)
72                                 return false;
73                 } else if (!requestID.equals(other.requestID))
74                         return false;
75                 return true;
76         }
77
78         @Override
79         public String toString() {
80                 return "AppcResponseEvent [requestID=" + requestID + ", appcTopic=" + appcTopic + ", code=" + code + "]";
81         }
82
83         public static Response toResponse(String requestId, int code) {
84                 Response response = new Response();
85                 
86                 CommonHeader commonHeader = new CommonHeader();
87                 commonHeader.RequestID = UUID.fromString(requestId);
88                 response.CommonHeader = commonHeader;
89
90                 ResponseStatus responseStatus = new ResponseStatus();
91                 responseStatus.Code = responseStatus.Code = code;
92                 response.Status = responseStatus;
93                 
94                 return response;
95         }
96
97 }