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;
31 import org.openecomp.mso.logger.MsoLogger;
34 * Base class for all SDNC adapter requests.
36 public abstract class SDNCRequestCommon implements Serializable {
37 private static final long serialVersionUID = 1L;
39 private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
41 // Endpoint on which BPMN can receive notifications from the SDNC adapter.
42 private String bpNotificationUrl;
44 // BPMN flow timeout value in ISO 8601 format, e.g. PT5M.
45 // Not currently used by the SDNC adapter.
46 private String bpTimeout;
48 // Identifies the MSO transaction with SDNC.
49 // Maps to sdnc-request-header/requestId in the SDNC request.
50 private String sdncRequestId;
52 public SDNCRequestCommon(String sdncRequestId, String bpNotificationUrl,
54 this.sdncRequestId = sdncRequestId;
55 this.bpNotificationUrl = bpNotificationUrl;
56 this.bpTimeout = bpTimeout;
59 public SDNCRequestCommon() {
62 @JsonProperty("bpNotificationUrl")
63 @XmlElement(name = "bpNotificationUrl")
64 public String getBPNotificationUrl() {
65 return bpNotificationUrl;
68 @JsonProperty("bpNotificationUrl")
69 public void setBPNotificationUrl(String bpNotificationUrl) {
70 this.bpNotificationUrl = bpNotificationUrl;
73 @JsonProperty("bpTimeout")
74 @XmlElement(name = "bpTimeout")
75 public String getBPTimeout() {
79 @JsonProperty("bpTimeout")
80 public void setBPTimeout(String bpTimeout) {
81 this.bpTimeout = bpTimeout;
84 @JsonProperty("sdncRequestId")
85 @XmlElement(name = "sdncRequestId")
86 public String getSDNCRequestId() {
90 @JsonProperty("sdncRequestId")
91 public void setSDNCRequestId(String sdncRequestId) {
92 this.sdncRequestId = sdncRequestId;
96 public boolean isSynchronous() {
97 return bpNotificationUrl == null || bpNotificationUrl.isEmpty();
100 public String toJson() {
102 ObjectMapper mapper = new ObjectMapper();
103 mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE);
104 mapper.setSerializationInclusion(Inclusion.NON_NULL);
105 return mapper.writeValueAsString(this);
106 } catch (IOException e) {
107 LOGGER.debug("Exception:", e);
108 throw new UnsupportedOperationException("Cannot convert "
109 + getClass().getSimpleName() + " to JSON", e);