2da94017ca8fbf42d2395ae6d62a2393ced4b8c0
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.so.adapters.sdncrest;
23
24 import java.io.IOException;
25 import java.io.Serializable;
26
27 import javax.xml.bind.annotation.XmlElement;
28
29 import org.onap.so.logger.MsoLogger;
30
31 import com.fasterxml.jackson.annotation.JsonInclude.Include;
32 import com.fasterxml.jackson.annotation.JsonProperty;
33 import com.fasterxml.jackson.databind.ObjectMapper;
34 import com.fasterxml.jackson.databind.SerializationFeature;
35
36 /**
37  * Base class for all SDNC adapter responses, including errors.
38  */
39 public abstract class SDNCResponseCommon implements Serializable {
40         private static final long serialVersionUID = 1L;
41         
42         private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA, SDNCResponseCommon.class);
43
44         // Identifies the MSO transaction with SDNC.
45         private String sdncRequestId;
46
47         // Response code, either from SDNC, or generated by the SDNC adapter.
48         // 2XX responses are considered success responses.
49         private String responseCode;
50
51         // Response message, either from SDNC, or generated by the SDNC adapter.
52         private String responseMessage;
53
54         // Indicates if the response is final (Y or N).
55         private String ackFinalIndicator;
56
57         public SDNCResponseCommon(String sdncRequestId, String responseCode,
58                         String responseMessage, String ackFinalIndicator) {
59                 this.sdncRequestId = sdncRequestId;
60                 this.responseCode = responseCode;
61                 this.responseMessage = responseMessage;
62                 this.ackFinalIndicator = ackFinalIndicator;
63         }
64
65         public SDNCResponseCommon() {
66         }
67
68         @JsonProperty("sdncRequestId")
69         @XmlElement(name = "sdncRequestId")
70         public String getSdncRequestId() {
71                 return sdncRequestId;
72         }
73
74         @JsonProperty("sdncRequestId")
75         public void setSdncRequestId(String sdncRequestId) {
76                 this.sdncRequestId = sdncRequestId;
77         }
78
79         @JsonProperty("responseCode")
80         @XmlElement(name = "responseCode")
81         public String getResponseCode() {
82                 return responseCode;
83         }
84
85         @JsonProperty("responseCode")
86         public void setResponseCode(String responseCode) {
87                 this.responseCode = responseCode;
88         }
89
90         @JsonProperty("responseMessage")
91         @XmlElement(name = "responseMessage")
92         public String getResponseMessage() {
93                 return responseMessage;
94         }
95
96         @JsonProperty("responseMessage")
97         public void setResponseMessage(String responseMessage) {
98                 this.responseMessage = responseMessage;
99         }
100
101         @JsonProperty("ackFinalIndicator")
102         @XmlElement(name = "ackFinalIndicator")
103         public String getAckFinalIndicator() {
104                 return ackFinalIndicator;
105         }
106
107         @JsonProperty("ackFinalIndicator")
108         public void setAckFinalIndicator(String ackFinalIndicator) {
109                 this.ackFinalIndicator = ackFinalIndicator;
110         }
111
112         public String toJson() {
113                 try {
114                         ObjectMapper mapper = new ObjectMapper();
115                         mapper.enable(SerializationFeature.WRAP_ROOT_VALUE);
116                         mapper.setSerializationInclusion(Include.NON_NULL);
117                         return mapper.writeValueAsString(this);
118                 } catch (IOException e) {
119                     LOGGER.debug("Exception:", e);
120                         throw new UnsupportedOperationException("Cannot convert "
121                                 + getClass().getSimpleName() + " to JSON", e);
122                 }
123         }
124 }