Replaced all tabs with spaces in java and pom.xml
[so.git] / adapters / mso-adapters-rest-interface / src / main / java / org / onap / so / adapters / sdncrest / SDNCResponseCommon.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
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=========================================================
21  */
22
23 package org.onap.so.adapters.sdncrest;
24
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;
34
35 /**
36  * Base class for all SDNC adapter responses, including errors.
37  */
38 public abstract class SDNCResponseCommon implements Serializable {
39     private static final long serialVersionUID = 1L;
40
41     private static final Logger logger = LoggerFactory.getLogger(SDNCResponseCommon.class);
42
43     // Identifies the MSO transaction with SDNC.
44     private String sdncRequestId;
45
46     // Response code, either from SDNC, or generated by the SDNC adapter.
47     // 2XX responses are considered success responses.
48     private String responseCode;
49
50     // Response message, either from SDNC, or generated by the SDNC adapter.
51     private String responseMessage;
52
53     // Indicates if the response is final (Y or N).
54     private String ackFinalIndicator;
55
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;
62     }
63
64     public SDNCResponseCommon() {}
65
66     @JsonProperty("sdncRequestId")
67     @XmlElement(name = "sdncRequestId")
68     public String getSdncRequestId() {
69         return sdncRequestId;
70     }
71
72     @JsonProperty("sdncRequestId")
73     public void setSdncRequestId(String sdncRequestId) {
74         this.sdncRequestId = sdncRequestId;
75     }
76
77     @JsonProperty("responseCode")
78     @XmlElement(name = "responseCode")
79     public String getResponseCode() {
80         return responseCode;
81     }
82
83     @JsonProperty("responseCode")
84     public void setResponseCode(String responseCode) {
85         this.responseCode = responseCode;
86     }
87
88     @JsonProperty("responseMessage")
89     @XmlElement(name = "responseMessage")
90     public String getResponseMessage() {
91         return responseMessage;
92     }
93
94     @JsonProperty("responseMessage")
95     public void setResponseMessage(String responseMessage) {
96         this.responseMessage = responseMessage;
97     }
98
99     @JsonProperty("ackFinalIndicator")
100     @XmlElement(name = "ackFinalIndicator")
101     public String getAckFinalIndicator() {
102         return ackFinalIndicator;
103     }
104
105     @JsonProperty("ackFinalIndicator")
106     public void setAckFinalIndicator(String ackFinalIndicator) {
107         this.ackFinalIndicator = ackFinalIndicator;
108     }
109
110     public String toJson() {
111         try {
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);
119         }
120     }
121 }