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 org.openecomp.mso.adapters.json.MapDeserializer;
24 import org.openecomp.mso.adapters.json.MapSerializer;
25 import org.codehaus.jackson.annotate.JsonProperty;
26 import org.codehaus.jackson.map.ObjectMapper;
27 import org.codehaus.jackson.map.SerializationConfig;
28 import org.codehaus.jackson.map.annotate.JsonDeserialize;
29 import org.codehaus.jackson.map.annotate.JsonRootName;
30 import org.codehaus.jackson.map.annotate.JsonSerialize;
31 import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
32 import org.jboss.resteasy.annotations.providers.NoJackson;
34 import javax.xml.bind.annotation.XmlElement;
35 import javax.xml.bind.annotation.XmlRootElement;
36 import java.io.IOException;
37 import java.io.Serializable;
38 import java.util.LinkedHashMap;
40 import org.openecomp.mso.logger.MsoLogger;
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 * SDNC adapter success response for "agnostic" API services. Note that the
48 * map of response parameters is represented this way in JSON:
52 * {"key": "P1", "value": "V1"},
53 * {"key": "P2", "value": "V2"},
55 * {"key": "PN", "value": "VN"}
60 @JsonRootName("SDNCEvent")
61 @JsonSerialize(include= Inclusion.NON_NULL)
62 @XmlRootElement(name = "SDNCEvent")
64 public class SDNCEvent implements Serializable {
65 private static final long serialVersionUID = 1L;
67 private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
70 private String eventType;
72 // Event correlator type
73 private String eventCorrelatorType;
75 // Event correlator value.
76 private String eventCorrelator;
78 // Map of response parameters (possibly none).
79 private Map<String, String> params = null;
81 public SDNCEvent(String eventType, String eventCorrelatorType, String eventCorrelator) {
82 this.eventType = eventType;
83 this.eventCorrelatorType = eventCorrelatorType;
84 this.eventCorrelator = eventCorrelator;
90 @JsonProperty("eventType")
91 @XmlElement(name = "eventType")
92 public String getEventType() {
96 @JsonProperty("eventType")
97 public void setEventType(String eventType) {
98 this.eventType = eventType;
101 @JsonProperty("eventCorrelatorType")
102 @XmlElement(name = "eventCorrelatorType")
103 public String getEventCorrelatorType() {
104 return eventCorrelatorType;
107 @JsonProperty("eventCorrelatorType")
108 public void setEventCorrelatorType(String eventCorrelatorType) {
109 this.eventCorrelatorType = eventCorrelatorType;
112 @JsonProperty("eventCorrelator")
113 @XmlElement(name = "eventCorrelator")
114 public String getEventCorrelator() {
115 return eventCorrelator;
118 @JsonProperty("eventCorrelator")
119 public void setEventCorrelator(String eventCorrelator) {
120 this.eventCorrelator = eventCorrelator;
123 @JsonProperty("params")
124 @JsonDeserialize(using = MapDeserializer.class)
125 @XmlElement(name = "params")
126 public Map<String, String> getParams() {
130 @JsonProperty("params")
131 @JsonSerialize(using = MapSerializer.class, include= Inclusion.NON_NULL)
132 public void setParams(Map<String, String> params) {
133 this.params = params;
136 public void addParam(String name, String value) {
137 if (params == null) {
138 params = new LinkedHashMap<>();
140 params.put(name, value);
143 public String toJson() {
145 ObjectMapper mapper = new ObjectMapper();
146 mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE);
147 mapper.setSerializationInclusion(Inclusion.NON_NULL);
148 return mapper.writeValueAsString(this);
149 } catch (IOException e) {
150 LOGGER.debug("Exception:", e);
151 throw new UnsupportedOperationException("Cannot convert "
152 + getClass().getSimpleName() + " to JSON", e);