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