[VID-6] Initial rebase push
[vid.git] / vid-app-common / src / main / java / org / openecomp / vid / controller / test / TestAaiController.java
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * VID\r
4  * ================================================================================\r
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
6  * ================================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  * \r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * \r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ============LICENSE_END=========================================================\r
19  */\r
20 \r
21 package org.openecomp.vid.controller.test;\r
22 \r
23 import java.io.IOException;\r
24 \r
25 import javax.servlet.http.HttpServletRequest;\r
26 import javax.servlet.http.HttpServletResponse;\r
27 \r
28 import org.codehaus.jackson.map.ObjectMapper;\r
29 import org.openecomp.vid.model.ExceptionResponse;\r
30 import org.springframework.web.bind.annotation.ExceptionHandler;\r
31 import org.springframework.web.bind.annotation.PathVariable;\r
32 import org.springframework.web.bind.annotation.RequestMapping;\r
33 import org.springframework.web.bind.annotation.RequestMethod;\r
34 import org.springframework.web.bind.annotation.RestController;\r
35 \r
36 import org.openecomp.portalsdk.core.controller.RestrictedBaseController;\r
37 \r
38 /**\r
39  * The Class TestAaiController.\r
40  */\r
41 @RestController\r
42 @RequestMapping("testaai")\r
43 public class TestAaiController extends RestrictedBaseController {\r
44 \r
45         /**\r
46          * Gets the subscription service type list.\r
47          *\r
48          * @param globalCustomerId the global customer id\r
49          * @param request the request\r
50          * @return the subscription service type list\r
51          * @throws Exception the exception\r
52          */\r
53         @RequestMapping(value = "/getSubscriptionServiceTypeList/{globalCustomerId}", method = RequestMethod.GET)\r
54         public String getSubscriptionServiceTypeList(@PathVariable("globalCustomerId") String globalCustomerId, HttpServletRequest request)\r
55                         throws Exception {\r
56 \r
57                 System.err.println("GET SUBSCRIPTION SERVICE TYPE LIST: globalCustomerId: " + globalCustomerId);\r
58 \r
59                 return "[\"vMOG\", \"sevice type 2\", \"sevice type 3\", \"sevice type 4\"]";\r
60         }\r
61 \r
62         /**\r
63          * Exception.\r
64          *\r
65          * @param e the e\r
66          * @param response the response\r
67          * @throws IOException Signals that an I/O exception has occurred.\r
68          */\r
69         @ExceptionHandler(Exception.class)\r
70         private void exception(Exception e, HttpServletResponse response) throws IOException {\r
71 \r
72                 /*\r
73                  * This logging step should preferably be replaced with an appropriate\r
74                  * logging method consistent whatever logging mechanism the rest of the\r
75                  * application code uses.\r
76                  */\r
77 \r
78                 e.printStackTrace(System.err);\r
79 \r
80                 response.setContentType("application/json; charset=UTF-8");\r
81                 response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);\r
82 \r
83                 ExceptionResponse exceptionResponse = new ExceptionResponse();\r
84                 exceptionResponse.setException(e.getClass().toString().replaceFirst("^.*\\.", ""));\r
85                 exceptionResponse.setMessage(e.getMessage());\r
86 \r
87                 response.getWriter().write(new ObjectMapper().writeValueAsString(exceptionResponse));\r
88 \r
89                 response.flushBuffer();\r
90 \r
91         }\r
92 \r
93 }\r