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