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;
28 import javax.xml.bind.annotation.XmlElement;
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;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
40 * Base class for all SDNC adapter requests.
42 public abstract class SDNCRequestCommon implements Serializable {
43 private static final long serialVersionUID = 1L;
45 private static final Logger logger = LoggerFactory.getLogger(SDNCRequestCommon.class);
47 // Endpoint on which BPMN can receive notifications from the SDNC adapter.
48 private String bpNotificationUrl;
50 // BPMN flow timeout value in ISO 8601 format, e.g. PT5M.
51 // Not currently used by the SDNC adapter.
52 private String bpTimeout;
54 // Identifies the MSO transaction with SDNC.
55 // Maps to sdnc-request-header/requestId in the SDNC request.
56 private String sdncRequestId;
58 public SDNCRequestCommon(String sdncRequestId, String bpNotificationUrl,
60 this.sdncRequestId = sdncRequestId;
61 this.bpNotificationUrl = bpNotificationUrl;
62 this.bpTimeout = bpTimeout;
65 public SDNCRequestCommon() {
68 @JsonProperty("bpNotificationUrl")
69 @XmlElement(name = "bpNotificationUrl")
70 public String getBPNotificationUrl() {
71 return bpNotificationUrl;
74 @JsonProperty("bpNotificationUrl")
75 public void setBPNotificationUrl(String bpNotificationUrl) {
76 this.bpNotificationUrl = bpNotificationUrl;
79 @JsonProperty("bpTimeout")
80 @XmlElement(name = "bpTimeout")
81 public String getBPTimeout() {
85 @JsonProperty("bpTimeout")
86 public void setBPTimeout(String bpTimeout) {
87 this.bpTimeout = bpTimeout;
90 @JsonProperty("sdncRequestId")
91 @XmlElement(name = "sdncRequestId")
92 public String getSdncRequestId() {
96 @JsonProperty("sdncRequestId")
97 public void setSdncRequestId(String sdncRequestId) {
98 this.sdncRequestId = sdncRequestId;
102 public boolean isSynchronous() {
103 return bpNotificationUrl == null || bpNotificationUrl.isEmpty();
106 public String toJson() {
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);