Update the license for 2017-2018 license
[aai/traversal.git] / aai-traversal / src / main / java / org / onap / aai / rest / retired / RetiredConsumer.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 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.onap.aai.rest.retired;
21
22 import java.util.ArrayList;
23
24 import javax.servlet.http.HttpServletRequest;
25 import javax.ws.rs.DELETE;
26 import javax.ws.rs.GET;
27 import javax.ws.rs.POST;
28 import javax.ws.rs.PUT;
29 import javax.ws.rs.Path;
30 import javax.ws.rs.PathParam;
31 import javax.ws.rs.core.Context;
32 import javax.ws.rs.core.HttpHeaders;
33 import javax.ws.rs.core.Response;
34 import javax.ws.rs.core.UriInfo;
35
36 import io.swagger.jaxrs.PATCH;
37
38 import org.onap.aai.exceptions.AAIException;
39 import org.onap.aai.logging.ErrorLogHelper;
40 import org.onap.aai.restcore.RESTAPI;
41 import org.onap.aai.util.AAIConfig;
42
43 /**
44  * The Class RetiredConsumer.
45  */
46 public abstract class RetiredConsumer extends RESTAPI {
47
48         /**
49          * Creates the message get.
50          *
51          * @param versionParam the version param
52          * @param headers the headers
53          * @param info the info
54          * @param req the req
55          * @return the response
56          */
57         @GET
58         @Path("/{uri:.*}")
59         public Response createMessageGet(@PathParam("version")String versionParam, @Context HttpHeaders headers, @Context UriInfo info, @Context HttpServletRequest req) {
60                 return createMessage(versionParam, headers, info, req);
61         }
62         
63         /**
64          * Creates the message delete.
65          *
66          * @param versionParam the version param
67          * @param headers the headers
68          * @param info the info
69          * @param req the req
70          * @return the response
71          */
72         @DELETE
73         @Path("/{uri:.*}")
74         public Response createMessageDelete(@PathParam("version")String versionParam, @Context HttpHeaders headers, @Context UriInfo info, @Context HttpServletRequest req) {
75                 return createMessage(versionParam, headers, info, req);
76         }
77         
78         /**
79          * Creates the message post.
80          *
81          * @param versionParam the version param
82          * @param headers the headers
83          * @param info the info
84          * @param req the req
85          * @return the response
86          */
87         @POST
88         @Path("/{uri:.*}")
89         public Response createMessagePost(@PathParam("version")String versionParam, @Context HttpHeaders headers, @Context UriInfo info, @Context HttpServletRequest req) {
90                 return createMessage(versionParam, headers, info, req);
91         }
92         
93         @PATCH
94         @Path("/{uri:.*}")
95         public Response createMessagePatch(@PathParam("version")String versionParam, @Context HttpHeaders headers, @Context UriInfo info, @Context HttpServletRequest req) {
96                 return createMessage(versionParam, headers, info, req);
97         }
98         /**
99          * Creates the message put.
100          *
101          * @param versionParam the version param
102          * @param headers the headers
103          * @param info the info
104          * @param req the req
105          * @return the response
106          */
107         @PUT
108         @Path("/{uri:.*}")
109         public Response createMessagePut(@PathParam("version")String versionParam, @Context HttpHeaders headers, @Context UriInfo info, @Context HttpServletRequest req) {
110                 return createMessage(versionParam, headers, info, req);
111         }
112         
113         
114         /**
115          * Creates the message.
116          *
117          * @param versionParam the version param
118          * @param headers the headers
119          * @param info the info
120          * @param req the req
121          * @return the response
122          */
123         private Response createMessage(String versionParam, HttpHeaders headers, UriInfo info, HttpServletRequest req) {
124                 AAIException e = new AAIException("AAI_3007");
125                 
126                 ArrayList<String> templateVars = new ArrayList<String>();
127
128                 if (templateVars.size() == 0) {
129                         templateVars.add("PUT");
130                         templateVars.add(info.getPath().toString());
131                         templateVars.add(versionParam);
132                         templateVars.add(AAIConfig.get("aai.default.api.version", ""));
133                 }
134                                 
135                 Response response = Response
136                                 .status(e.getErrorObject().getHTTPResponseCode())
137                                 .entity(ErrorLogHelper.getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), e, 
138                                                 templateVars)).build(); 
139                 
140                 return response;
141         }
142 }