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 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.so.adapters.sdncrest;
24 import java.io.IOException;
25 import java.io.Serializable;
26 import java.util.LinkedHashMap;
29 import javax.xml.bind.annotation.XmlElement;
30 import javax.xml.bind.annotation.XmlRootElement;
32 import org.onap.so.logger.MsoLogger;
34 import com.fasterxml.jackson.annotation.JsonInclude;
35 import com.fasterxml.jackson.annotation.JsonInclude.Include;
36 import com.fasterxml.jackson.annotation.JsonProperty;
37 import com.fasterxml.jackson.annotation.JsonRootName;
38 import com.fasterxml.jackson.databind.ObjectMapper;
39 import com.fasterxml.jackson.databind.SerializationFeature;
41 // NOTE: the JAXB (XML) annotations are required with JBoss AS7 and RESTEasy,
42 // even though we are using JSON exclusively. The @NoJackson annotation
43 // is also required in this environment.
46 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.
47 When 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 MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA, 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;
79 @JsonProperty("eventType")
80 @XmlElement(name = "eventType")
81 public String getEventType() {
85 @JsonProperty("eventType")
86 public void setEventType(String eventType) {
87 this.eventType = eventType;
90 @JsonProperty("eventCorrelatorType")
91 @XmlElement(name = "eventCorrelatorType")
92 public String getEventCorrelatorType() {
93 return eventCorrelatorType;
96 @JsonProperty("eventCorrelatorType")
97 public void setEventCorrelatorType(String eventCorrelatorType) {
98 this.eventCorrelatorType = eventCorrelatorType;
101 @JsonProperty("eventCorrelator")
102 @XmlElement(name = "eventCorrelator")
103 public String getEventCorrelator() {
104 return eventCorrelator;
107 @JsonProperty("eventCorrelator")
108 public void setEventCorrelator(String eventCorrelator) {
109 this.eventCorrelator = eventCorrelator;
112 @JsonProperty("params")
113 @XmlElement(name = "params")
114 public Map<String, String> getParams() {
118 @JsonProperty("params")
119 public void setParams(Map<String, String> params) {
120 this.params = params;
123 public void addParam(String name, String value) {
124 if (params == null) {
125 params = new LinkedHashMap<>();
127 params.put(name, value);
130 public String toJson() {
132 ObjectMapper mapper = new ObjectMapper();
133 mapper.enable(SerializationFeature.WRAP_ROOT_VALUE);
134 mapper.setSerializationInclusion(Include.NON_NULL);
135 return mapper.writeValueAsString(this);
136 } catch (IOException e) {
137 LOGGER.debug("Exception:", e);
138 throw new UnsupportedOperationException("Cannot convert "
139 + getClass().getSimpleName() + " to JSON", e);