2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.so.adapters.sdncrest;
24 import java.io.IOException;
25 import java.io.Serializable;
27 import javax.xml.bind.annotation.XmlElement;
29 import org.onap.so.logger.MsoLogger;
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;
37 * Base class for all SDNC adapter responses, including errors.
39 public abstract class SDNCResponseCommon implements Serializable {
40 private static final long serialVersionUID = 1L;
42 private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA, SDNCResponseCommon.class);
44 // Identifies the MSO transaction with SDNC.
45 private String sdncRequestId;
47 // Response code, either from SDNC, or generated by the SDNC adapter.
48 // 2XX responses are considered success responses.
49 private String responseCode;
51 // Response message, either from SDNC, or generated by the SDNC adapter.
52 private String responseMessage;
54 // Indicates if the response is final (Y or N).
55 private String ackFinalIndicator;
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;
65 public SDNCResponseCommon() {
68 @JsonProperty("sdncRequestId")
69 @XmlElement(name = "sdncRequestId")
70 public String getSdncRequestId() {
74 @JsonProperty("sdncRequestId")
75 public void setSdncRequestId(String sdncRequestId) {
76 this.sdncRequestId = sdncRequestId;
79 @JsonProperty("responseCode")
80 @XmlElement(name = "responseCode")
81 public String getResponseCode() {
85 @JsonProperty("responseCode")
86 public void setResponseCode(String responseCode) {
87 this.responseCode = responseCode;
90 @JsonProperty("responseMessage")
91 @XmlElement(name = "responseMessage")
92 public String getResponseMessage() {
93 return responseMessage;
96 @JsonProperty("responseMessage")
97 public void setResponseMessage(String responseMessage) {
98 this.responseMessage = responseMessage;
101 @JsonProperty("ackFinalIndicator")
102 @XmlElement(name = "ackFinalIndicator")
103 public String getAckFinalIndicator() {
104 return ackFinalIndicator;
107 @JsonProperty("ackFinalIndicator")
108 public void setAckFinalIndicator(String ackFinalIndicator) {
109 this.ackFinalIndicator = ackFinalIndicator;
112 public String toJson() {
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);