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=========================================================
21 package org.openecomp.mso.adapters.sdncrest;
23 import java.io.IOException;
24 import java.io.Serializable;
25 import java.util.LinkedHashMap;
28 import javax.xml.bind.annotation.XmlElement;
29 import javax.xml.bind.annotation.XmlRootElement;
31 import org.openecomp.mso.logger.MsoLogger;
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;
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 <entry><key>${key}</key><value>${value}</value></entry> elements.
46 When marshalling to JSON they create a list of "${key}" : "${value}" pairs with no extra wrappers.
49 @JsonRootName("SDNCEvent")
50 @JsonInclude(Include.NON_NULL)
51 @XmlRootElement(name = "SDNCEvent")
52 public class SDNCEvent implements Serializable {
53 private static final long serialVersionUID = 1L;
55 private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
58 private String eventType;
60 // Event correlator type
61 private String eventCorrelatorType;
63 // Event correlator value.
64 private String eventCorrelator;
66 // Map of response parameters (possibly none).
67 private Map<String, String> params = null;
69 public SDNCEvent(String eventType, String eventCorrelatorType, String eventCorrelator) {
70 this.eventType = eventType;
71 this.eventCorrelatorType = eventCorrelatorType;
72 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 "
138 + getClass().getSimpleName() + " to JSON", e);