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;
29 import javax.xml.bind.annotation.XmlElement;
30 import javax.xml.bind.annotation.XmlRootElement;
31 import com.fasterxml.jackson.annotation.JsonInclude;
32 import com.fasterxml.jackson.annotation.JsonInclude.Include;
33 import com.fasterxml.jackson.annotation.JsonProperty;
34 import com.fasterxml.jackson.annotation.JsonRootName;
35 import com.fasterxml.jackson.databind.ObjectMapper;
36 import com.fasterxml.jackson.databind.SerializationFeature;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
40 // NOTE: the JAXB (XML) annotations are required with JBoss AS7 and RESTEasy,
41 // even though we are using JSON exclusively. The @NoJackson annotation
42 // is also required in this environment.
45 * Map<String, String> elements when marshalled to XML produce a list of
46 * <entry><key>${MsoUtils.xmlEscape(key)}</key><value>${MsoUtils.xmlEscape(value)}</value></entry> elements. When
47 * marshalling to JSON they create a list of "${key}" : "${value}" pairs with no extra wrappers.
50 @JsonRootName("SDNCEvent")
51 @JsonInclude(Include.NON_NULL)
52 @XmlRootElement(name = "SDNCEvent")
53 public class SDNCEvent implements Serializable {
54 private static final long serialVersionUID = 1L;
56 private static final Logger logger = LoggerFactory.getLogger(SDNCEvent.class);
59 private String eventType;
61 // Event correlator type
62 private String eventCorrelatorType;
64 // Event correlator value.
65 private String eventCorrelator;
67 // Map of response parameters (possibly none).
68 private Map<String, String> params = null;
70 public SDNCEvent(String eventType, String eventCorrelatorType, String eventCorrelator) {
71 this.eventType = eventType;
72 this.eventCorrelatorType = eventCorrelatorType;
73 this.eventCorrelator = eventCorrelator;
78 @JsonProperty("eventType")
79 @XmlElement(name = "eventType")
80 public String getEventType() {
84 @JsonProperty("eventType")
85 public void setEventType(String eventType) {
86 this.eventType = eventType;
89 @JsonProperty("eventCorrelatorType")
90 @XmlElement(name = "eventCorrelatorType")
91 public String getEventCorrelatorType() {
92 return eventCorrelatorType;
95 @JsonProperty("eventCorrelatorType")
96 public void setEventCorrelatorType(String eventCorrelatorType) {
97 this.eventCorrelatorType = eventCorrelatorType;
100 @JsonProperty("eventCorrelator")
101 @XmlElement(name = "eventCorrelator")
102 public String getEventCorrelator() {
103 return eventCorrelator;
106 @JsonProperty("eventCorrelator")
107 public void setEventCorrelator(String eventCorrelator) {
108 this.eventCorrelator = eventCorrelator;
111 @JsonProperty("params")
112 @XmlElement(name = "params")
113 public Map<String, String> getParams() {
117 @JsonProperty("params")
118 public void setParams(Map<String, String> params) {
119 this.params = params;
122 public void addParam(String name, String value) {
123 if (params == null) {
124 params = new LinkedHashMap<>();
126 params.put(name, value);
129 public String toJson() {
131 ObjectMapper mapper = new ObjectMapper();
132 mapper.enable(SerializationFeature.WRAP_ROOT_VALUE);
133 mapper.setSerializationInclusion(Include.NON_NULL);
134 return mapper.writeValueAsString(this);
135 } catch (IOException e) {
136 logger.debug("Exception:", e);
137 throw new UnsupportedOperationException("Cannot convert " + getClass().getSimpleName() + " to JSON", e);