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