a42174dc2e32c42b7ef0f0c3904018554c6012c1
[appc.git] / appc-event-listener / appc-event-listener-bundle / src / main / java / org / onap / appc / listener / LCM / model / OutputBody.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * =============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * 
21  * ============LICENSE_END=========================================================
22  */
23
24 package org.onap.appc.listener.LCM.model;
25
26 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
27 import com.fasterxml.jackson.annotation.JsonProperty;
28 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
29 import org.json.JSONObject;
30 import org.onap.appc.listener.util.Mapper;
31
32 /**
33  * This class represents a message being sent out to DMaaP by APPC to update listeners on the status of a request
34  */
35 @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
36 @JsonIgnoreProperties(ignoreUnknown = true)
37 public class OutputBody {
38
39     @JsonProperty("common-header")
40     private CommonHeader header;
41
42     @JsonProperty("status")
43     private ResponseStatus status;
44
45     @JsonProperty("payload")
46     private String payload;
47
48     @JsonProperty("locked")
49     private String locked;
50
51     public OutputBody() {
52     }
53
54     public OutputBody(InputBody msg) {
55         this.header = new CommonHeader(msg.getCommonHeader());
56     }
57
58
59     public JSONObject toResponse() {
60         return Mapper.toJsonObject(this);
61     }
62
63     public String getLocked() {
64         return locked;
65     }
66
67     public String getPayload() {
68         return payload;
69     }
70
71     public CommonHeader getHeader() {
72         return header;
73     }
74
75     public ResponseStatus getStatus() {
76         return status;
77     }
78
79     public void setStatus(ResponseStatus status) {
80         this.status = status;
81     }
82
83     public void setLocked(String locked) {
84         this.locked = locked;
85     }
86
87     public void setHeader(CommonHeader header) {
88         this.header = header;
89     }
90
91     public void setPayload(String payload) {
92         this.payload = payload;
93     }
94
95     @Override
96     public String toString() {
97         return String.format("%s - %s(%s)", getHeader().getRequestID(), getStatus().getCode(), getStatus().getValue());
98     }
99 }
100