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