Merge from ECOMP's repository
[vid.git] / vid-app-common / src / main / java / org / onap / vid / mso / rest / RequestDetails.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
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
21 package org.onap.vid.mso.rest;
22
23 import com.fasterxml.jackson.annotation.*;
24 import org.apache.commons.lang3.builder.EqualsBuilder;
25 import org.apache.commons.lang3.builder.HashCodeBuilder;
26 import org.apache.commons.lang3.builder.ToStringBuilder;
27 import org.onap.vid.exceptions.NotFoundException;
28 import org.onap.vid.mso.model.CloudConfiguration;
29 import org.onap.vid.mso.model.ModelInfo;
30 import org.onap.vid.mso.model.RequestInfo;
31 import org.onap.vid.mso.model.RequestParameters;
32
33 import java.util.HashMap;
34 import java.util.List;
35 import java.util.Map;
36
37
38 /**
39  * aggregates the context, configuraiton and detailed parameters associated with the request into a single structure.
40  */
41 @JsonInclude(JsonInclude.Include.NON_NULL)
42 @JsonPropertyOrder({
43         "cloudConfiguration",
44         "modelInfo",
45         "relatedModelList",
46         "requestInfo",
47         "subscriberInfo",
48         "requestParameters",
49         "configurationParameters"
50 })
51 public class RequestDetails{
52
53
54
55     /** The cloud configuration. */
56     @JsonProperty("cloudConfiguration")
57     private CloudConfiguration cloudConfiguration;
58
59     /** The model info. */
60     @JsonProperty("modelInfo")
61     private ModelInfo modelInfo;
62
63     /** The related model list. */
64     @JsonProperty("relatedInstanceList")
65     private List<RelatedInstanceWrapper> relatedInstanceList;
66
67     /** The request info. */
68     @JsonProperty("requestInfo")
69     private RequestInfo requestInfo;
70
71     /** The subscriber info. */
72     @JsonProperty("subscriberInfo")
73     private SubscriberInfo subscriberInfo;
74
75     /** The request parameters. */
76     @JsonProperty("requestParameters")
77     private RequestParameters requestParameters;
78
79     @JsonProperty("configurationParameters")
80     protected List<Map<String, String>> configurationParameters;
81
82     /** The additional properties. */
83     @JsonIgnore
84     private Map<String, Object> additionalProperties = new HashMap<>();
85
86     /**
87      * Gets the cloud configuration.
88      *
89      * @return     The cloudConfiguration
90      */
91     @JsonProperty("cloudConfiguration")
92     public CloudConfiguration getCloudConfiguration() {
93         return cloudConfiguration;
94     }
95
96     /**
97      * Sets the cloud configuration.
98      *
99      * @param cloudConfiguration     The cloudConfiguration
100      */
101     @JsonProperty("cloudConfiguration")
102     public void setCloudConfiguration(CloudConfiguration cloudConfiguration) {
103         this.cloudConfiguration = cloudConfiguration;
104     }
105
106     /**
107      * Gets the model info.
108      *
109      * @return     The modelInfo
110      */
111     @JsonProperty("modelInfo")
112     public ModelInfo getModelInfo() {
113         return modelInfo;
114     }
115
116     /**
117      * Sets the model info.
118      *
119      * @param modelInfo     The modelInfo
120      */
121     @JsonProperty("modelInfo")
122     public void setModelInfo(ModelInfo modelInfo) {
123         this.modelInfo = modelInfo;
124     }
125     /**
126      * Gets the related instance list.
127      *
128      * @return     The relatedInstanceList
129      */
130     @JsonProperty("relatedInstanceList")
131     public List<RelatedInstanceWrapper> getRelatedInstanceList() {
132         return relatedInstanceList;
133     }
134
135     /**
136      * Sets the related model list.
137      *
138      * @param relatedInstanceList     The relatedInstanceList
139      */
140     @JsonProperty("relatedInstanceList")
141     public void setRelatedInstanceList(List<RelatedInstanceWrapper> relatedInstanceList) {
142         this.relatedInstanceList = relatedInstanceList;
143     }
144
145     /**
146      * Gets the request info.
147      *
148      * @return     The requestInfo
149      */
150     @JsonProperty("requestInfo")
151     public RequestInfo getRequestInfo() {
152         return requestInfo;
153     }
154
155     /**
156      * Sets the request info.
157      *
158      * @param requestInfo     The requestInfo
159      */
160     @JsonProperty("requestInfo")
161     public void setRequestInfo(RequestInfo requestInfo) {
162         this.requestInfo = requestInfo;
163     }
164
165     /**
166      * Gets the subscriber info.
167      *
168      * @return     The subscriberInfo
169      */
170     @JsonProperty("subscriberInfo")
171     public SubscriberInfo getSubscriberInfo() {
172         return subscriberInfo;
173     }
174
175     /**
176      * Sets the subscriber info.
177      *
178      * @param subscriberInfo     The subscriberInfo
179      */
180     @JsonProperty("subscriberInfo")
181     public void setSubscriberInfo(SubscriberInfo subscriberInfo) {
182         this.subscriberInfo = subscriberInfo;
183     }
184
185     /* (non-Javadoc)
186      * @see org.onap.vid.domain.mso.RequestDetails#toString()
187      */
188     @Override
189     public String toString() {
190         return ToStringBuilder.reflectionToString(this);
191     }
192
193     /* (non-Javadoc)
194      * @see org.onap.vid.domain.mso.RequestDetails#getAdditionalProperties()
195      */
196     @JsonAnyGetter
197     public Map<String, Object> getAdditionalProperties() {
198         return this.additionalProperties;
199     }
200
201     /* (non-Javadoc)
202      * @see org.onap.vid.domain.mso.RequestDetails#setAdditionalProperty(java.lang.String, java.lang.Object)
203      */
204     @JsonAnySetter
205     public void setAdditionalProperty(String name, Object value) {
206         this.additionalProperties.put(name, value);
207     }
208
209     @JsonProperty("configurationParameters")
210     public List<Map<String, String>> getConfigurationParameters() {
211         return configurationParameters;
212     }
213
214     @JsonProperty("configurationParameters")
215     public void setConfigurationParameters(List<Map<String, String>> configurationParameters) {
216         this.configurationParameters = configurationParameters;
217     }
218
219     /* (non-Javadoc)
220      * @see org.onap.vid.domain.mso.RequestDetails#hashCode()
221      */
222     @Override
223     public int hashCode() {
224         return new HashCodeBuilder()
225                 .append(cloudConfiguration)
226                 .append(modelInfo)
227                 .append(relatedInstanceList)
228                 .append(requestInfo)
229                 .append(getRequestParameters())
230                 .append(subscriberInfo)
231                 .append(additionalProperties)
232                 .append(configurationParameters)
233                 .toHashCode();
234     }
235
236     /* (non-Javadoc)
237      * @see org.onap.vid.domain.mso.RequestDetails#equals(java.lang.Object)
238      */
239     @Override
240     public boolean equals(Object other) {
241         if (other == this) {
242             return true;
243         }
244         if (!(other instanceof RequestDetails)) {
245             return false;
246         }
247         RequestDetails rhs = ((RequestDetails) other);
248         return new EqualsBuilder()
249                 .append(cloudConfiguration, rhs.cloudConfiguration)
250                 .append(modelInfo, rhs.modelInfo)
251                 .append(relatedInstanceList, rhs.relatedInstanceList)
252                 .append(requestInfo, rhs.requestInfo)
253                 .append(getRequestParameters(), rhs.getRequestParameters())
254                 .append(subscriberInfo, rhs.subscriberInfo)
255                 .append(additionalProperties, rhs.additionalProperties)
256                 .append(configurationParameters, rhs.configurationParameters)
257                 .isEquals();
258     }
259
260     public RequestParameters getRequestParameters() {
261         return requestParameters;
262     }
263
264     public void setRequestParameters(RequestParameters requestParameters) {
265         this.requestParameters = requestParameters;
266     }
267
268     public <T> T extractValueByPathUsingAdditionalProperties (List<String> keys, Class<T> clazz) {
269         Object result = getAdditionalProperties();
270         for (String key : keys) {
271             if (result instanceof Map) {
272                 result = ((Map) result).get(key);
273             }
274
275             else {
276                 throw new NotFoundException("failed to find key: "+key+" in path: "+String.join("\\", keys));
277             }
278         }
279         if (clazz.isInstance(result)) {
280             return clazz.cast(result);
281         }
282
283         throw new NotFoundException(
284                 String.format("failed to extract value from path:%s because %s is not of type %s",
285                 String.join("\\", keys), String.valueOf(result) , clazz));
286     }
287
288
289 }