2ab6ed5a8a68f6cf41162093756df6321592a621
[so.git] / adapters / mso-adapters-rest-interface / src / main / java / org / openecomp / mso / adapters / sdncrest / SDNCServiceResponse.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * OPENECOMP - MSO
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20 package org.openecomp.mso.adapters.sdncrest;
21
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.annotate.JsonDeserialize;
26 import org.codehaus.jackson.map.annotate.JsonRootName;
27 import org.codehaus.jackson.map.annotate.JsonSerialize;
28 import org.jboss.resteasy.annotations.providers.NoJackson;
29
30 import javax.xml.bind.annotation.XmlElement;
31 import javax.xml.bind.annotation.XmlRootElement;
32 import java.io.Serializable;
33 import java.util.LinkedHashMap;
34 import java.util.Map;
35
36 // NOTE: the JAXB (XML) annotations are required with JBoss AS7 and RESTEasy,
37 //       even though we are using JSON exclusively.  The @NoJackson annotation
38 //       is also required in this environment.
39
40 /**
41  * SDNC adapter success response for "agnostic" API services. Note that the
42  * map of response parameters is represented this way in JSON:
43  * <pre>
44  * "params": {
45  *   "entry": [
46  *     {"key": "P1", "value": "V1"},
47  *     {"key": "P2", "value": "V2"},
48  *     ...
49  *     {"key": "PN", "value": "VN"}
50  *   ]
51  * }
52  * </pre>
53  */
54 @JsonRootName("SDNCServiceResponse")
55 @JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
56 @XmlRootElement(name = "SDNCServiceResponse")
57 @NoJackson
58 public class SDNCServiceResponse extends SDNCResponseCommon implements Serializable {
59         private static final long serialVersionUID = 1L;
60
61         // Map of response parameters (possibly none).
62         private Map<String, String> params = null;
63
64         public SDNCServiceResponse(String sdncRequestId, String responseCode,
65                         String responseMessage, String ackFinalIndicator) {
66                 super(sdncRequestId, responseCode, responseMessage, ackFinalIndicator);
67         }
68
69         public SDNCServiceResponse() {
70         }
71
72         @JsonProperty("params")
73         @JsonDeserialize(using = MapDeserializer.class)
74         @XmlElement(name = "params")
75         public Map<String, String> getParams() {
76                 return params;
77         }
78
79         @JsonProperty("params")
80         @JsonSerialize(using = MapSerializer.class, include=JsonSerialize.Inclusion.NON_NULL)
81         public void setParams(Map<String, String> params) {
82                 this.params = params;
83         }
84
85         public void addParam(String name, String value) {
86                 if (params == null) {
87                         params = new LinkedHashMap<String, String>();
88                 }
89                 params.put(name, value);
90         }
91 }