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