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 * Modifications Copyright (c) 2019 Samsung
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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 * ============LICENSE_END=========================================================
23 package org.onap.so.adapters.sdncrest;
25 import java.io.IOException;
26 import java.io.Serializable;
28 import javax.xml.bind.annotation.XmlElement;
30 import com.fasterxml.jackson.annotation.JsonInclude.Include;
31 import com.fasterxml.jackson.annotation.JsonProperty;
32 import com.fasterxml.jackson.databind.ObjectMapper;
33 import com.fasterxml.jackson.databind.SerializationFeature;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
39 * Base class for all SDNC adapter responses, including errors.
41 public abstract class SDNCResponseCommon implements Serializable {
42 private static final long serialVersionUID = 1L;
44 private static final Logger logger = LoggerFactory.getLogger(SDNCResponseCommon.class);
46 // Identifies the MSO transaction with SDNC.
47 private String sdncRequestId;
49 // Response code, either from SDNC, or generated by the SDNC adapter.
50 // 2XX responses are considered success responses.
51 private String responseCode;
53 // Response message, either from SDNC, or generated by the SDNC adapter.
54 private String responseMessage;
56 // Indicates if the response is final (Y or N).
57 private String ackFinalIndicator;
59 public SDNCResponseCommon(String sdncRequestId, String responseCode,
60 String responseMessage, String ackFinalIndicator) {
61 this.sdncRequestId = sdncRequestId;
62 this.responseCode = responseCode;
63 this.responseMessage = responseMessage;
64 this.ackFinalIndicator = ackFinalIndicator;
67 public SDNCResponseCommon() {
70 @JsonProperty("sdncRequestId")
71 @XmlElement(name = "sdncRequestId")
72 public String getSdncRequestId() {
76 @JsonProperty("sdncRequestId")
77 public void setSdncRequestId(String sdncRequestId) {
78 this.sdncRequestId = sdncRequestId;
81 @JsonProperty("responseCode")
82 @XmlElement(name = "responseCode")
83 public String getResponseCode() {
87 @JsonProperty("responseCode")
88 public void setResponseCode(String responseCode) {
89 this.responseCode = responseCode;
92 @JsonProperty("responseMessage")
93 @XmlElement(name = "responseMessage")
94 public String getResponseMessage() {
95 return responseMessage;
98 @JsonProperty("responseMessage")
99 public void setResponseMessage(String responseMessage) {
100 this.responseMessage = responseMessage;
103 @JsonProperty("ackFinalIndicator")
104 @XmlElement(name = "ackFinalIndicator")
105 public String getAckFinalIndicator() {
106 return ackFinalIndicator;
109 @JsonProperty("ackFinalIndicator")
110 public void setAckFinalIndicator(String ackFinalIndicator) {
111 this.ackFinalIndicator = ackFinalIndicator;
114 public String toJson() {
116 ObjectMapper mapper = new ObjectMapper();
117 mapper.enable(SerializationFeature.WRAP_ROOT_VALUE);
118 mapper.setSerializationInclusion(Include.NON_NULL);
119 return mapper.writeValueAsString(this);
120 } catch (IOException e) {
121 logger.debug("Exception:", e);
122 throw new UnsupportedOperationException("Cannot convert "
123 + getClass().getSimpleName() + " to JSON", e);