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=========================================================
21 package org.openecomp.mso.adapters.sdncrest;
23 import java.io.IOException;
24 import java.io.Serializable;
26 import javax.xml.bind.annotation.XmlElement;
28 import org.openecomp.mso.logger.MsoLogger;
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;
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 MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
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,
57 String responseMessage, String ackFinalIndicator) {
58 this.sdncRequestId = sdncRequestId;
59 this.responseCode = responseCode;
60 this.responseMessage = responseMessage;
61 this.ackFinalIndicator = ackFinalIndicator;
64 public SDNCResponseCommon() {
67 @JsonProperty("sdncRequestId")
68 @XmlElement(name = "sdncRequestId")
69 public String getSDNCRequestId() {
73 @JsonProperty("sdncRequestId")
74 public void setSDNCRequestId(String sdncRequestId) {
75 this.sdncRequestId = sdncRequestId;
78 @JsonProperty("responseCode")
79 @XmlElement(name = "responseCode")
80 public String getResponseCode() {
84 @JsonProperty("responseCode")
85 public void setResponseCode(String responseCode) {
86 this.responseCode = responseCode;
89 @JsonProperty("responseMessage")
90 @XmlElement(name = "responseMessage")
91 public String getResponseMessage() {
92 return responseMessage;
95 @JsonProperty("responseMessage")
96 public void setResponseMessage(String responseMessage) {
97 this.responseMessage = responseMessage;
100 @JsonProperty("ackFinalIndicator")
101 @XmlElement(name = "ackFinalIndicator")
102 public String getAckFinalIndicator() {
103 return ackFinalIndicator;
106 @JsonProperty("ackFinalIndicator")
107 public void setAckFinalIndicator(String ackFinalIndicator) {
108 this.ackFinalIndicator = ackFinalIndicator;
111 public String toJson() {
113 ObjectMapper mapper = new ObjectMapper();
114 mapper.enable(SerializationFeature.WRAP_ROOT_VALUE);
115 mapper.setSerializationInclusion(Include.NON_NULL);
116 return mapper.writeValueAsString(this);
117 } catch (IOException e) {
118 LOGGER.debug("Exception:", e);
119 throw new UnsupportedOperationException("Cannot convert "
120 + getClass().getSimpleName() + " to JSON", e);