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 org.codehaus.jackson.annotate.JsonProperty;
24 import org.codehaus.jackson.map.ObjectMapper;
25 import org.codehaus.jackson.map.SerializationConfig;
26 import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
28 import javax.xml.bind.annotation.XmlElement;
29 import java.io.IOException;
30 import java.io.Serializable;
31 import org.openecomp.mso.logger.MsoLogger;
34 * Base class for all SDNC adapter responses, including errors.
36 public abstract class SDNCResponseCommon implements Serializable {
37 private static final long serialVersionUID = 1L;
39 private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
41 // Identifies the MSO transaction with SDNC.
42 private String sdncRequestId;
44 // Response code, either from SDNC, or generated by the SDNC adapter.
45 // 2XX responses are considered success responses.
46 private String responseCode;
48 // Response message, either from SDNC, or generated by the SDNC adapter.
49 private String responseMessage;
51 // Indicates if the response is final (Y or N).
52 private String ackFinalIndicator;
54 public SDNCResponseCommon(String sdncRequestId, String responseCode,
55 String responseMessage, String ackFinalIndicator) {
56 this.sdncRequestId = sdncRequestId;
57 this.responseCode = responseCode;
58 this.responseMessage = responseMessage;
59 this.ackFinalIndicator = ackFinalIndicator;
62 public SDNCResponseCommon() {
65 @JsonProperty("sdncRequestId")
66 @XmlElement(name = "sdncRequestId")
67 public String getSDNCRequestId() {
71 @JsonProperty("sdncRequestId")
72 public void setSDNCRequestId(String sdncRequestId) {
73 this.sdncRequestId = sdncRequestId;
76 @JsonProperty("responseCode")
77 @XmlElement(name = "responseCode")
78 public String getResponseCode() {
82 @JsonProperty("responseCode")
83 public void setResponseCode(String responseCode) {
84 this.responseCode = responseCode;
87 @JsonProperty("responseMessage")
88 @XmlElement(name = "responseMessage")
89 public String getResponseMessage() {
90 return responseMessage;
93 @JsonProperty("responseMessage")
94 public void setResponseMessage(String responseMessage) {
95 this.responseMessage = responseMessage;
98 @JsonProperty("ackFinalIndicator")
99 @XmlElement(name = "ackFinalIndicator")
100 public String getAckFinalIndicator() {
101 return ackFinalIndicator;
104 @JsonProperty("ackFinalIndicator")
105 public void setAckFinalIndicator(String ackFinalIndicator) {
106 this.ackFinalIndicator = ackFinalIndicator;
109 public String toJson() {
111 ObjectMapper mapper = new ObjectMapper();
112 mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE);
113 mapper.setSerializationInclusion(Inclusion.NON_NULL);
114 return mapper.writeValueAsString(this);
115 } catch (IOException e) {
116 LOGGER.debug("Exception:", e);
117 throw new UnsupportedOperationException("Cannot convert "
118 + getClass().getSimpleName() + " to JSON", e);