2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
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;
27 import java.util.LinkedHashMap;
30 import javax.xml.bind.annotation.XmlElement;
31 import javax.xml.bind.annotation.XmlRootElement;
33 import com.fasterxml.jackson.annotation.JsonInclude;
34 import com.fasterxml.jackson.annotation.JsonInclude.Include;
35 import com.fasterxml.jackson.annotation.JsonProperty;
36 import com.fasterxml.jackson.annotation.JsonRootName;
37 import com.fasterxml.jackson.databind.ObjectMapper;
38 import com.fasterxml.jackson.databind.SerializationFeature;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
42 // NOTE: the JAXB (XML) annotations are required with JBoss AS7 and RESTEasy,
43 // even though we are using JSON exclusively. The @NoJackson annotation
44 // is also required in this environment.
47 Map<String, String> elements when marshalled to XML produce a list of <entry><key>${MsoUtils.xmlEscape(key)}</key><value>${MsoUtils.xmlEscape(value)}</value></entry> elements.
48 When marshalling to JSON they create a list of "${key}" : "${value}" pairs with no extra wrappers.
51 @JsonRootName("SDNCEvent")
52 @JsonInclude(Include.NON_NULL)
53 @XmlRootElement(name = "SDNCEvent")
54 public class SDNCEvent implements Serializable {
55 private static final long serialVersionUID = 1L;
57 private static final Logger logger = LoggerFactory.getLogger(SDNCEvent.class);
60 private String eventType;
62 // Event correlator type
63 private String eventCorrelatorType;
65 // Event correlator value.
66 private String eventCorrelator;
68 // Map of response parameters (possibly none).
69 private Map<String, String> params = null;
71 public SDNCEvent(String eventType, String eventCorrelatorType, String eventCorrelator) {
72 this.eventType = eventType;
73 this.eventCorrelatorType = eventCorrelatorType;
74 this.eventCorrelator = eventCorrelator;
80 @JsonProperty("eventType")
81 @XmlElement(name = "eventType")
82 public String getEventType() {
86 @JsonProperty("eventType")
87 public void setEventType(String eventType) {
88 this.eventType = eventType;
91 @JsonProperty("eventCorrelatorType")
92 @XmlElement(name = "eventCorrelatorType")
93 public String getEventCorrelatorType() {
94 return eventCorrelatorType;
97 @JsonProperty("eventCorrelatorType")
98 public void setEventCorrelatorType(String eventCorrelatorType) {
99 this.eventCorrelatorType = eventCorrelatorType;
102 @JsonProperty("eventCorrelator")
103 @XmlElement(name = "eventCorrelator")
104 public String getEventCorrelator() {
105 return eventCorrelator;
108 @JsonProperty("eventCorrelator")
109 public void setEventCorrelator(String eventCorrelator) {
110 this.eventCorrelator = eventCorrelator;
113 @JsonProperty("params")
114 @XmlElement(name = "params")
115 public Map<String, String> getParams() {
119 @JsonProperty("params")
120 public void setParams(Map<String, String> params) {
121 this.params = params;
124 public void addParam(String name, String value) {
125 if (params == null) {
126 params = new LinkedHashMap<>();
128 params.put(name, value);
131 public String toJson() {
133 ObjectMapper mapper = new ObjectMapper();
134 mapper.enable(SerializationFeature.WRAP_ROOT_VALUE);
135 mapper.setSerializationInclusion(Include.NON_NULL);
136 return mapper.writeValueAsString(this);
137 } catch (IOException e) {
138 logger.debug("Exception:", e);
139 throw new UnsupportedOperationException("Cannot convert "
140 + getClass().getSimpleName() + " to JSON", e);