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 org.codehaus.jackson.annotate.JsonIgnore;
23 import org.codehaus.jackson.annotate.JsonProperty;
24 import org.codehaus.jackson.map.ObjectMapper;
25 import org.codehaus.jackson.map.SerializationConfig;
26 import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
28 import javax.xml.bind.annotation.XmlElement;
29 import java.io.IOException;
30 import java.io.Serializable;
33 * Base class for all SDNC adapter requests.
35 public abstract class SDNCRequestCommon implements Serializable {
36 private static final long serialVersionUID = 1L;
38 // Endpoint on which BPMN can receive notifications from the SDNC adapter.
39 private String bpNotificationUrl;
41 // BPMN flow timeout value in ISO 8601 format, e.g. PT5M.
42 // Not currently used by the SDNC adapter.
43 private String bpTimeout;
45 // Identifies the MSO transaction with SDNC.
46 // Maps to sdnc-request-header/requestId in the SDNC request.
47 private String sdncRequestId;
49 public SDNCRequestCommon(String sdncRequestId, String bpNotificationUrl,
51 this.sdncRequestId = sdncRequestId;
52 this.bpNotificationUrl = bpNotificationUrl;
53 this.bpTimeout = bpTimeout;
56 public SDNCRequestCommon() {
59 @JsonProperty("bpNotificationUrl")
60 @XmlElement(name = "bpNotificationUrl")
61 public String getBPNotificationUrl() {
62 return bpNotificationUrl;
65 @JsonProperty("bpNotificationUrl")
66 public void setBPNotificationUrl(String bpNotificationUrl) {
67 this.bpNotificationUrl = bpNotificationUrl;
70 @JsonProperty("bpTimeout")
71 @XmlElement(name = "bpTimeout")
72 public String getBPTimeout() {
76 @JsonProperty("bpTimeout")
77 public void setBPTimeout(String bpTimeout) {
78 this.bpTimeout = bpTimeout;
81 @JsonProperty("sdncRequestId")
82 @XmlElement(name = "sdncRequestId")
83 public String getSDNCRequestId() {
87 @JsonProperty("sdncRequestId")
88 public void setSDNCRequestId(String sdncRequestId) {
89 this.sdncRequestId = sdncRequestId;
93 public boolean isSynchronous() {
94 return bpNotificationUrl == null || bpNotificationUrl.isEmpty();
97 public String toJson() {
99 ObjectMapper mapper = new ObjectMapper();
100 mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE);
101 mapper.setSerializationInclusion(Inclusion.NON_NULL);
102 return mapper.writeValueAsString(this);
103 } catch (IOException e) {
105 throw new UnsupportedOperationException("Cannot convert "
106 + getClass().getSimpleName() + " to JSON", e);