org.onap migration
[vid.git] / vid-app-common / src / main / java / org / onap / vid / controller / test / TestAaiController.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.controller.test;
22
23 import org.codehaus.jackson.map.ObjectMapper;
24 import org.openecomp.portalsdk.core.controller.RestrictedBaseController;
25 import org.onap.vid.model.ExceptionResponse;
26 import org.springframework.web.bind.annotation.*;
27
28 import javax.servlet.http.HttpServletRequest;
29 import javax.servlet.http.HttpServletResponse;
30 import java.io.IOException;
31
32 /**
33  * The Class TestAaiController.
34  */
35 @RestController
36 @RequestMapping("testaai")
37 public class TestAaiController extends RestrictedBaseController {
38
39         /**
40          * Gets the subscription service type list.
41          *
42          * @param globalCustomerId the global customer id
43          * @param request the request
44          * @return the subscription service type list
45          * @throws Exception the exception
46          */
47         @RequestMapping(value = "/getSubscriptionServiceTypeList/{globalCustomerId}", method = RequestMethod.GET)
48         public String getSubscriptionServiceTypeList(@PathVariable("globalCustomerId") String globalCustomerId, HttpServletRequest request)
49                         throws Exception {
50
51                 System.err.println("GET SUBSCRIPTION SERVICE TYPE LIST: globalCustomerId: " + globalCustomerId);
52
53                 return "[\"vMOG\", \"sevice type 2\", \"sevice type 3\", \"sevice type 4\"]";
54         }
55
56         /**
57          * Exception.
58          *
59          * @param e the e
60          * @param response the response
61          * @throws IOException Signals that an I/O exception has occurred.
62          */
63         @ExceptionHandler(Exception.class)
64         private void exception(Exception e, HttpServletResponse response) throws IOException {
65
66                 /*
67                  * This logging step should preferably be replaced with an appropriate
68                  * logging method consistent whatever logging mechanism the rest of the
69                  * application code uses.
70                  */
71
72                 e.printStackTrace(System.err);
73
74                 response.setContentType("application/json; charset=UTF-8");
75                 response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
76
77                 ExceptionResponse exceptionResponse = new ExceptionResponse();
78                 exceptionResponse.setException(e.getClass().toString().replaceFirst("^.*\\.", ""));
79                 exceptionResponse.setMessage(e.getMessage());
80
81                 response.getWriter().write(new ObjectMapper().writeValueAsString(exceptionResponse));
82
83                 response.flushBuffer();
84
85         }
86
87 }