2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
23 package org.onap.so.adapters.sdncrest;
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;
37 * Base class for all SDNC adapter requests.
39 public abstract class SDNCRequestCommon implements Serializable {
40 private static final long serialVersionUID = 1L;
42 private static final Logger logger = LoggerFactory.getLogger(SDNCRequestCommon.class);
44 // Endpoint on which BPMN can receive notifications from the SDNC adapter.
45 private String bpNotificationUrl;
47 // BPMN flow timeout value in ISO 8601 format, e.g. PT5M.
48 // Not currently used by the SDNC adapter.
49 private String bpTimeout;
51 // Identifies the MSO transaction with SDNC.
52 // Maps to sdnc-request-header/requestId in the SDNC request.
53 private String sdncRequestId;
55 public SDNCRequestCommon(String sdncRequestId, String bpNotificationUrl, String bpTimeout) {
56 this.sdncRequestId = sdncRequestId;
57 this.bpNotificationUrl = bpNotificationUrl;
58 this.bpTimeout = bpTimeout;
61 public SDNCRequestCommon() {}
63 @JsonProperty("bpNotificationUrl")
64 @XmlElement(name = "bpNotificationUrl")
65 public String getBPNotificationUrl() {
66 return bpNotificationUrl;
69 @JsonProperty("bpNotificationUrl")
70 public void setBPNotificationUrl(String bpNotificationUrl) {
71 this.bpNotificationUrl = bpNotificationUrl;
74 @JsonProperty("bpTimeout")
75 @XmlElement(name = "bpTimeout")
76 public String getBPTimeout() {
80 @JsonProperty("bpTimeout")
81 public void setBPTimeout(String bpTimeout) {
82 this.bpTimeout = bpTimeout;
85 @JsonProperty("sdncRequestId")
86 @XmlElement(name = "sdncRequestId")
87 public String getSdncRequestId() {
91 @JsonProperty("sdncRequestId")
92 public void setSdncRequestId(String sdncRequestId) {
93 this.sdncRequestId = sdncRequestId;
97 public boolean isSynchronous() {
98 return bpNotificationUrl == null || bpNotificationUrl.isEmpty();
101 public String toJson() {
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);