2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.openecomp.mso.adapters.sdncrest;
22 import org.openecomp.mso.adapters.json.MapDeserializer;
23 import org.openecomp.mso.adapters.json.MapSerializer;
24 import org.codehaus.jackson.annotate.JsonProperty;
25 import org.codehaus.jackson.map.ObjectMapper;
26 import org.codehaus.jackson.map.SerializationConfig;
27 import org.codehaus.jackson.map.annotate.JsonDeserialize;
28 import org.codehaus.jackson.map.annotate.JsonRootName;
29 import org.codehaus.jackson.map.annotate.JsonSerialize;
30 import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
31 import org.jboss.resteasy.annotations.providers.NoJackson;
33 import javax.xml.bind.annotation.XmlElement;
34 import javax.xml.bind.annotation.XmlRootElement;
35 import java.io.IOException;
36 import java.io.Serializable;
37 import java.util.LinkedHashMap;
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 * SDNC adapter success response for "agnostic" API services. Note that the
46 * map of response parameters is represented this way in JSON:
50 * {"key": "P1", "value": "V1"},
51 * {"key": "P2", "value": "V2"},
53 * {"key": "PN", "value": "VN"}
58 @JsonRootName("SDNCEvent")
59 @JsonSerialize(include= Inclusion.NON_NULL)
60 @XmlRootElement(name = "SDNCEvent")
62 public class SDNCEvent implements Serializable {
63 private static final long serialVersionUID = 1L;
66 private String eventType;
68 // Event correlator type
69 private String eventCorrelatorType;
71 // Event correlator value.
72 private String eventCorrelator;
74 // Map of response parameters (possibly none).
75 private Map<String, String> params = null;
77 public SDNCEvent(String eventType, String eventCorrelatorType, String eventCorrelator) {
78 this.eventType = eventType;
79 this.eventCorrelatorType = eventCorrelatorType;
80 this.eventCorrelator = eventCorrelator;
86 @JsonProperty("eventType")
87 @XmlElement(name = "eventType")
88 public String getEventType() {
92 @JsonProperty("eventType")
93 public void setEventType(String eventType) {
94 this.eventType = eventType;
97 @JsonProperty("eventCorrelatorType")
98 @XmlElement(name = "eventCorrelatorType")
99 public String getEventCorrelatorType() {
100 return eventCorrelatorType;
103 @JsonProperty("eventCorrelatorType")
104 public void setEventCorrelatorType(String eventCorrelatorType) {
105 this.eventCorrelatorType = eventCorrelatorType;
108 @JsonProperty("eventCorrelator")
109 @XmlElement(name = "eventCorrelator")
110 public String getEventCorrelator() {
111 return eventCorrelator;
114 @JsonProperty("eventCorrelator")
115 public void setEventCorrelator(String eventCorrelator) {
116 this.eventCorrelator = eventCorrelator;
119 @JsonProperty("params")
120 @JsonDeserialize(using = MapDeserializer.class)
121 @XmlElement(name = "params")
122 public Map<String, String> getParams() {
126 @JsonProperty("params")
127 @JsonSerialize(using = MapSerializer.class, include= Inclusion.NON_NULL)
128 public void setParams(Map<String, String> params) {
129 this.params = params;
132 public void addParam(String name, String value) {
133 if (params == null) {
134 params = new LinkedHashMap<String, String>();
136 params.put(name, value);
139 public String toJson() {
141 ObjectMapper mapper = new ObjectMapper();
142 mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE);
143 mapper.setSerializationInclusion(Inclusion.NON_NULL);
144 return mapper.writeValueAsString(this);
145 } catch (IOException e) {
147 throw new UnsupportedOperationException("Cannot convert "
148 + getClass().getSimpleName() + " to JSON", e);