Containerization feature of SO
[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  * 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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.so.adapters.sdncrest;
22
23 import java.io.IOException;
24 import java.io.Serializable;
25
26 import javax.xml.bind.annotation.XmlElement;
27
28 import org.onap.so.logger.MsoLogger;
29
30 import com.fasterxml.jackson.annotation.JsonIgnore;
31 import com.fasterxml.jackson.annotation.JsonInclude.Include;
32 import com.fasterxml.jackson.annotation.JsonProperty;
33 import com.fasterxml.jackson.databind.ObjectMapper;
34 import com.fasterxml.jackson.databind.SerializationFeature;
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 MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA, 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,
56                         String bpTimeout) {
57                 this.sdncRequestId = sdncRequestId;
58                 this.bpNotificationUrl = bpNotificationUrl;
59                 this.bpTimeout = bpTimeout;
60         }
61
62         public SDNCRequestCommon() {
63         }
64
65         @JsonProperty("bpNotificationUrl")
66         @XmlElement(name = "bpNotificationUrl")
67         public String getBPNotificationUrl() {
68                 return bpNotificationUrl;
69         }
70
71         @JsonProperty("bpNotificationUrl")
72         public void setBPNotificationUrl(String bpNotificationUrl) {
73                 this.bpNotificationUrl = bpNotificationUrl;
74         }
75
76         @JsonProperty("bpTimeout")
77         @XmlElement(name = "bpTimeout")
78         public String getBPTimeout() {
79                 return bpTimeout;
80         }
81
82         @JsonProperty("bpTimeout")
83         public void setBPTimeout(String bpTimeout) {
84                 this.bpTimeout = bpTimeout;
85         }
86
87         @JsonProperty("sdncRequestId")
88         @XmlElement(name = "sdncRequestId")
89         public String getSdncRequestId() {
90                 return sdncRequestId;
91         }
92
93         @JsonProperty("sdncRequestId")
94         public void setSdncRequestId(String sdncRequestId) {
95                 this.sdncRequestId = sdncRequestId;
96         }
97
98         @JsonIgnore
99         public boolean isSynchronous() {
100                 return bpNotificationUrl == null || bpNotificationUrl.isEmpty();
101         }
102
103         public String toJson() {
104                 try {
105                         ObjectMapper mapper = new ObjectMapper();
106                         mapper.enable(SerializationFeature.WRAP_ROOT_VALUE);
107                         mapper.setSerializationInclusion(Include.NON_NULL);
108                         return mapper.writeValueAsString(this);
109                 } catch (IOException e) {
110                     LOGGER.debug("Exception:", e);
111                         throw new UnsupportedOperationException("Cannot convert "
112                                 + getClass().getSimpleName() + " to JSON", e);
113                 }
114         }
115 }