Format java POLICY-SDK-APP
[policy/engine.git] / POLICY-SDK-APP / src / main / java / org / onap / policy / admin / PolicyUserInfoController.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Engine
4  * ================================================================================
5  * Copyright (C) 2017, 2019 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2019 Bell Canada
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.admin;
23
24 import com.fasterxml.jackson.databind.ObjectMapper;
25
26 import java.util.HashMap;
27 import java.util.Map;
28
29 import javax.servlet.http.HttpServletRequest;
30 import javax.servlet.http.HttpServletResponse;
31
32 import org.json.JSONObject;
33 import org.onap.policy.common.logging.flexlogger.FlexLogger;
34 import org.onap.policy.common.logging.flexlogger.Logger;
35 import org.onap.portalsdk.core.controller.RestrictedBaseController;
36 import org.onap.portalsdk.core.web.support.JsonMessage;
37 import org.onap.portalsdk.core.web.support.UserUtils;
38 import org.springframework.stereotype.Controller;
39 import org.springframework.web.bind.annotation.RequestMapping;
40 import org.springframework.web.bind.annotation.RequestMethod;
41
42 @Controller
43 @RequestMapping("/")
44 public class PolicyUserInfoController extends RestrictedBaseController {
45
46     private static final Logger LOGGER = FlexLogger.getLogger(PolicyUserInfoController.class);
47
48     @RequestMapping(value = "/get_PolicyUserInfo", method = RequestMethod.GET)
49     public void getPolicyUserInfo(HttpServletRequest request, HttpServletResponse response) {
50         JsonMessage msg;
51         try {
52             String userId = UserUtils.getUserSession(request).getOrgUserId();
53             Map<String, Object> model = new HashMap<>();
54             ObjectMapper mapper = new ObjectMapper();
55             model.put("userid", userId);
56             msg = new JsonMessage(mapper.writeValueAsString(model));
57             JSONObject j = new JSONObject(msg);
58             response.getWriter().write(j.toString());
59         } catch (Exception e) {
60             LOGGER.error("Exception Occurred" + e);
61         }
62     }
63 }