[VID-6] Initial rebase push
[vid.git] / vid-app-common / src / main / java / org / openecomp / vid / controller / test / TestAsdcController.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 TestAsdcController.\r
40  */\r
41 @RestController\r
42 @RequestMapping("testasdc")\r
43 public class TestAsdcController extends RestrictedBaseController {\r
44 \r
45         /**\r
46          * Gets the model.\r
47          *\r
48          * @param modelId the model id\r
49          * @param request the request\r
50          * @return the model\r
51          * @throws Exception the exception\r
52          */\r
53         @RequestMapping(value = "/getModel/{modelId}", method = RequestMethod.GET)\r
54         public String getModel(@PathVariable("modelId") String modelId, HttpServletRequest request) throws Exception {\r
55 \r
56                 System.err.println("SDC: GET MODEL: modelId: " + modelId);\r
57 \r
58                 // @formatter:off\r
59                 return\r
60                    "{" +\r
61                        "\"uuid\": \"5be686dc-fdca-4d54-8548-5d0ed23e962b\"," +\r
62                        "\"invariantUUID\": \"e5962da9-fe4f-433a-bc99-b43e0d88a9a1\"," +\r
63                        "\"name\": \"DE220127\"," +\r
64                        "\"version\": \"0.1\"," +       \r
65                    "\"inputs\": {" +\r
66                      "\"defaultGateway\": {" +\r
67                             "\"type\": \"String\"," +\r
68                             "\"default\": \"192.168.1.1\"," +\r
69                             "\"description\": \"Router default gateway - use any valid IPv4 address\"" +\r
70                      "}," +\r
71                      "\"subnetMask\": {" +\r
72                             "\"type\": \"String\"," +\r
73                             "\"default\": \"255.255.255.0\"," +\r
74                             "\"description\": \"Router subnet mask - example (255.255.255.0)\"" +\r
75                      "}" +\r
76                     "}" +\r
77                         "}";\r
78                 // @formatter:on\r
79         }\r
80 \r
81         /**\r
82          * Exception.\r
83          *\r
84          * @param e the e\r
85          * @param response the response\r
86          * @throws IOException Signals that an I/O exception has occurred.\r
87          */\r
88         @ExceptionHandler(Exception.class)\r
89         private void exception(Exception e, HttpServletResponse response) throws IOException {\r
90 \r
91                 /*\r
92                  * This logging step should preferably be replaced with an appropriate\r
93                  * logging method consistent whatever logging mechanism the rest of the\r
94                  * application code uses.\r
95                  */\r
96 \r
97                 e.printStackTrace(System.err);\r
98 \r
99                 response.setContentType("application/json; charset=UTF-8");\r
100                 response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);\r
101 \r
102                 ExceptionResponse exceptionResponse = new ExceptionResponse();\r
103                 exceptionResponse.setException(e.getClass().toString().replaceFirst("^.*\\.", ""));\r
104                 exceptionResponse.setMessage(e.getMessage());\r
105 \r
106                 response.getWriter().write(new ObjectMapper().writeValueAsString(exceptionResponse));\r
107 \r
108                 response.flushBuffer();\r
109 \r
110         }\r
111 \r
112 }\r