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=========================================================
20 package org.openecomp.mso.adapters.sdncrest;
22 import java.io.IOException;
23 import java.io.Serializable;
25 import javax.xml.bind.annotation.XmlElement;
27 import org.openecomp.mso.logger.MsoLogger;
29 import com.fasterxml.jackson.annotation.JsonIgnore;
30 import com.fasterxml.jackson.annotation.JsonInclude.Include;
31 import com.fasterxml.jackson.annotation.JsonProperty;
32 import com.fasterxml.jackson.databind.ObjectMapper;
33 import com.fasterxml.jackson.databind.SerializationFeature;
36 * Base class for all SDNC adapter requests.
38 public abstract class SDNCRequestCommon implements Serializable {
39 private static final long serialVersionUID = 1L;
41 private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
43 // Endpoint on which BPMN can receive notifications from the SDNC adapter.
44 private String bpNotificationUrl;
46 // BPMN flow timeout value in ISO 8601 format, e.g. PT5M.
47 // Not currently used by the SDNC adapter.
48 private String bpTimeout;
50 // Identifies the MSO transaction with SDNC.
51 // Maps to sdnc-request-header/requestId in the SDNC request.
52 private String sdncRequestId;
54 public SDNCRequestCommon(String sdncRequestId, String bpNotificationUrl,
56 this.sdncRequestId = sdncRequestId;
57 this.bpNotificationUrl = bpNotificationUrl;
58 this.bpTimeout = bpTimeout;
61 public SDNCRequestCommon() {
64 @JsonProperty("bpNotificationUrl")
65 @XmlElement(name = "bpNotificationUrl")
66 public String getBPNotificationUrl() {
67 return bpNotificationUrl;
70 @JsonProperty("bpNotificationUrl")
71 public void setBPNotificationUrl(String bpNotificationUrl) {
72 this.bpNotificationUrl = bpNotificationUrl;
75 @JsonProperty("bpTimeout")
76 @XmlElement(name = "bpTimeout")
77 public String getBPTimeout() {
81 @JsonProperty("bpTimeout")
82 public void setBPTimeout(String bpTimeout) {
83 this.bpTimeout = bpTimeout;
86 @JsonProperty("sdncRequestId")
87 @XmlElement(name = "sdncRequestId")
88 public String getSDNCRequestId() {
92 @JsonProperty("sdncRequestId")
93 public void setSDNCRequestId(String sdncRequestId) {
94 this.sdncRequestId = sdncRequestId;
98 public boolean isSynchronous() {
99 return bpNotificationUrl == null || bpNotificationUrl.isEmpty();
102 public String toJson() {
104 ObjectMapper mapper = new ObjectMapper();
105 mapper.enable(SerializationFeature.WRAP_ROOT_VALUE);
106 mapper.setSerializationInclusion(Include.NON_NULL);
107 return mapper.writeValueAsString(this);
108 } catch (IOException e) {
109 LOGGER.debug("Exception:", e);
110 throw new UnsupportedOperationException("Cannot convert "
111 + getClass().getSimpleName() + " to JSON", e);