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 / SDNCRequestCommon.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
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.JsonIgnore;
29 import com.fasterxml.jackson.annotation.JsonInclude.Include;
30 import com.fasterxml.jackson.annotation.JsonProperty;
31 import com.fasterxml.jackson.databind.ObjectMapper;
32 import com.fasterxml.jackson.databind.SerializationFeature;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35
36 /**
37  * Base class for all SDNC adapter requests.
38  */
39 public abstract class SDNCRequestCommon implements Serializable {
40     private static final long serialVersionUID = 1L;
41
42     private static final Logger logger = LoggerFactory.getLogger(SDNCRequestCommon.class);
43
44     // Endpoint on which BPMN can receive notifications from the SDNC adapter.
45     private String bpNotificationUrl;
46
47     // BPMN flow timeout value in ISO 8601 format, e.g. PT5M.
48     // Not currently used by the SDNC adapter.
49     private String bpTimeout;
50
51     // Identifies the MSO transaction with SDNC.
52     // Maps to sdnc-request-header/requestId in the SDNC request.
53     private String sdncRequestId;
54
55     public SDNCRequestCommon(String sdncRequestId, String bpNotificationUrl, String bpTimeout) {
56         this.sdncRequestId = sdncRequestId;
57         this.bpNotificationUrl = bpNotificationUrl;
58         this.bpTimeout = bpTimeout;
59     }
60
61     public SDNCRequestCommon() {}
62
63     @JsonProperty("bpNotificationUrl")
64     @XmlElement(name = "bpNotificationUrl")
65     public String getBPNotificationUrl() {
66         return bpNotificationUrl;
67     }
68
69     @JsonProperty("bpNotificationUrl")
70     public void setBPNotificationUrl(String bpNotificationUrl) {
71         this.bpNotificationUrl = bpNotificationUrl;
72     }
73
74     @JsonProperty("bpTimeout")
75     @XmlElement(name = "bpTimeout")
76     public String getBPTimeout() {
77         return bpTimeout;
78     }
79
80     @JsonProperty("bpTimeout")
81     public void setBPTimeout(String bpTimeout) {
82         this.bpTimeout = bpTimeout;
83     }
84
85     @JsonProperty("sdncRequestId")
86     @XmlElement(name = "sdncRequestId")
87     public String getSdncRequestId() {
88         return sdncRequestId;
89     }
90
91     @JsonProperty("sdncRequestId")
92     public void setSdncRequestId(String sdncRequestId) {
93         this.sdncRequestId = sdncRequestId;
94     }
95
96     @JsonIgnore
97     public boolean isSynchronous() {
98         return bpNotificationUrl == null || bpNotificationUrl.isEmpty();
99     }
100
101     public String toJson() {
102         try {
103             ObjectMapper mapper = new ObjectMapper();
104             mapper.enable(SerializationFeature.WRAP_ROOT_VALUE);
105             mapper.setSerializationInclusion(Include.NON_NULL);
106             return mapper.writeValueAsString(this);
107         } catch (IOException e) {
108             logger.debug("Exception:", e);
109             throw new UnsupportedOperationException("Cannot convert " + getClass().getSimpleName() + " to JSON", e);
110         }
111     }
112 }