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;
27 import javax.xml.bind.annotation.XmlElement;
28 import com.fasterxml.jackson.annotation.JsonInclude.Include;
29 import com.fasterxml.jackson.annotation.JsonProperty;
30 import com.fasterxml.jackson.databind.ObjectMapper;
31 import com.fasterxml.jackson.databind.SerializationFeature;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
36 * Base class for all SDNC adapter responses, including errors.
38 public abstract class SDNCResponseCommon implements Serializable {
39 private static final long serialVersionUID = 1L;
41 private static final Logger logger = LoggerFactory.getLogger(SDNCResponseCommon.class);
43 // Identifies the MSO transaction with SDNC.
44 private String sdncRequestId;
46 // Response code, either from SDNC, or generated by the SDNC adapter.
47 // 2XX responses are considered success responses.
48 private String responseCode;
50 // Response message, either from SDNC, or generated by the SDNC adapter.
51 private String responseMessage;
53 // Indicates if the response is final (Y or N).
54 private String ackFinalIndicator;
56 public SDNCResponseCommon(String sdncRequestId, String responseCode, String responseMessage,
57 String ackFinalIndicator) {
58 this.sdncRequestId = sdncRequestId;
59 this.responseCode = responseCode;
60 this.responseMessage = responseMessage;
61 this.ackFinalIndicator = ackFinalIndicator;
64 public SDNCResponseCommon() {}
66 @JsonProperty("sdncRequestId")
67 @XmlElement(name = "sdncRequestId")
68 public String getSdncRequestId() {
72 @JsonProperty("sdncRequestId")
73 public void setSdncRequestId(String sdncRequestId) {
74 this.sdncRequestId = sdncRequestId;
77 @JsonProperty("responseCode")
78 @XmlElement(name = "responseCode")
79 public String getResponseCode() {
83 @JsonProperty("responseCode")
84 public void setResponseCode(String responseCode) {
85 this.responseCode = responseCode;
88 @JsonProperty("responseMessage")
89 @XmlElement(name = "responseMessage")
90 public String getResponseMessage() {
91 return responseMessage;
94 @JsonProperty("responseMessage")
95 public void setResponseMessage(String responseMessage) {
96 this.responseMessage = responseMessage;
99 @JsonProperty("ackFinalIndicator")
100 @XmlElement(name = "ackFinalIndicator")
101 public String getAckFinalIndicator() {
102 return ackFinalIndicator;
105 @JsonProperty("ackFinalIndicator")
106 public void setAckFinalIndicator(String ackFinalIndicator) {
107 this.ackFinalIndicator = ackFinalIndicator;
110 public String toJson() {
112 ObjectMapper mapper = new ObjectMapper();
113 mapper.enable(SerializationFeature.WRAP_ROOT_VALUE);
114 mapper.setSerializationInclusion(Include.NON_NULL);
115 return mapper.writeValueAsString(this);
116 } catch (IOException e) {
117 logger.debug("Exception:", e);
118 throw new UnsupportedOperationException("Cannot convert " + getClass().getSimpleName() + " to JSON", e);