2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.openecomp.mso.adapters.sdncrest;
22 import org.codehaus.jackson.annotate.JsonProperty;
23 import org.codehaus.jackson.map.ObjectMapper;
24 import org.codehaus.jackson.map.SerializationConfig;
25 import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
27 import javax.xml.bind.annotation.XmlElement;
28 import java.io.IOException;
29 import java.io.Serializable;
32 * Base class for all SDNC adapter responses, including errors.
34 public abstract class SDNCResponseCommon implements Serializable {
35 private static final long serialVersionUID = 1L;
37 // Identifies the MSO transaction with SDNC.
38 private String sdncRequestId;
40 // Response code, either from SDNC, or generated by the SDNC adapter.
41 // 2XX responses are considered success responses.
42 private String responseCode;
44 // Response message, either from SDNC, or generated by the SDNC adapter.
45 private String responseMessage;
47 // Indicates if the response is final (Y or N).
48 private String ackFinalIndicator;
50 public SDNCResponseCommon(String sdncRequestId, String responseCode,
51 String responseMessage, String ackFinalIndicator) {
52 this.sdncRequestId = sdncRequestId;
53 this.responseCode = responseCode;
54 this.responseMessage = responseMessage;
55 this.ackFinalIndicator = ackFinalIndicator;
58 public SDNCResponseCommon() {
61 @JsonProperty("sdncRequestId")
62 @XmlElement(name = "sdncRequestId")
63 public String getSDNCRequestId() {
67 @JsonProperty("sdncRequestId")
68 public void setSDNCRequestId(String sdncRequestId) {
69 this.sdncRequestId = sdncRequestId;
72 @JsonProperty("responseCode")
73 @XmlElement(name = "responseCode")
74 public String getResponseCode() {
78 @JsonProperty("responseCode")
79 public void setResponseCode(String responseCode) {
80 this.responseCode = responseCode;
83 @JsonProperty("responseMessage")
84 @XmlElement(name = "responseMessage")
85 public String getResponseMessage() {
86 return responseMessage;
89 @JsonProperty("responseMessage")
90 public void setResponseMessage(String responseMessage) {
91 this.responseMessage = responseMessage;
94 @JsonProperty("ackFinalIndicator")
95 @XmlElement(name = "ackFinalIndicator")
96 public String getAckFinalIndicator() {
97 return ackFinalIndicator;
100 @JsonProperty("ackFinalIndicator")
101 public void setAckFinalIndicator(String ackFinalIndicator) {
102 this.ackFinalIndicator = ackFinalIndicator;
105 public String toJson() {
107 ObjectMapper mapper = new ObjectMapper();
108 mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE);
109 mapper.setSerializationInclusion(Inclusion.NON_NULL);
110 return mapper.writeValueAsString(this);
111 } catch (IOException e) {
113 throw new UnsupportedOperationException("Cannot convert "
114 + getClass().getSimpleName() + " to JSON", e);