2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.adapters.sdncrest;
23 import java.io.IOException;
24 import java.io.Serializable;
26 import javax.xml.bind.annotation.XmlElement;
28 import org.onap.so.logger.MsoLogger;
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;
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 MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA, 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,
57 this.sdncRequestId = sdncRequestId;
58 this.bpNotificationUrl = bpNotificationUrl;
59 this.bpTimeout = bpTimeout;
62 public SDNCRequestCommon() {
65 @JsonProperty("bpNotificationUrl")
66 @XmlElement(name = "bpNotificationUrl")
67 public String getBPNotificationUrl() {
68 return bpNotificationUrl;
71 @JsonProperty("bpNotificationUrl")
72 public void setBPNotificationUrl(String bpNotificationUrl) {
73 this.bpNotificationUrl = bpNotificationUrl;
76 @JsonProperty("bpTimeout")
77 @XmlElement(name = "bpTimeout")
78 public String getBPTimeout() {
82 @JsonProperty("bpTimeout")
83 public void setBPTimeout(String bpTimeout) {
84 this.bpTimeout = bpTimeout;
87 @JsonProperty("sdncRequestId")
88 @XmlElement(name = "sdncRequestId")
89 public String getSdncRequestId() {
93 @JsonProperty("sdncRequestId")
94 public void setSdncRequestId(String sdncRequestId) {
95 this.sdncRequestId = sdncRequestId;
99 public boolean isSynchronous() {
100 return bpNotificationUrl == null || bpNotificationUrl.isEmpty();
103 public String toJson() {
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);