2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.policy.controller;
24 import com.fasterxml.jackson.databind.DeserializationFeature;
25 import com.fasterxml.jackson.databind.JsonNode;
26 import com.fasterxml.jackson.databind.ObjectMapper;
28 import java.io.IOException;
29 import java.util.HashMap;
32 import javax.servlet.http.HttpServletRequest;
33 import javax.servlet.http.HttpServletResponse;
35 import org.json.JSONObject;
36 import org.onap.policy.common.logging.flexlogger.FlexLogger;
37 import org.onap.policy.common.logging.flexlogger.Logger;
38 import org.onap.policy.rest.dao.CommonClassDao;
39 import org.onap.policy.rest.jpa.GlobalRoleSettings;
40 import org.onap.policy.utils.PolicyUtils;
41 import org.onap.portalsdk.core.controller.RestrictedBaseController;
42 import org.onap.portalsdk.core.web.support.JsonMessage;
43 import org.onap.portalsdk.core.web.support.UserUtils;
44 import org.springframework.beans.factory.annotation.Autowired;
45 import org.springframework.http.MediaType;
46 import org.springframework.stereotype.Controller;
47 import org.springframework.web.bind.annotation.RequestMapping;
48 import org.springframework.web.servlet.ModelAndView;
51 @RequestMapping({"/"})
52 public class AdminTabController extends RestrictedBaseController {
54 private static final Logger LOGGER = FlexLogger.getLogger(AdminTabController.class);
56 private static CommonClassDao commonClassDao;
58 public AdminTabController() {
59 // default constructor
63 private AdminTabController(CommonClassDao commonClassDao) {
64 AdminTabController.commonClassDao = commonClassDao;
67 public static CommonClassDao getCommonClassDao() {
68 return commonClassDao;
71 public static void setCommonClassDao(CommonClassDao commonClassDao) {
72 AdminTabController.commonClassDao = commonClassDao;
76 * getAdminTabEntityData.
78 * @param request HttpServletRequest
79 * @param response HttpServletResponse
82 value = {"/get_LockDownData"},
83 method = {org.springframework.web.bind.annotation.RequestMethod.GET},
84 produces = MediaType.APPLICATION_JSON_VALUE)
85 public void getAdminTabEntityData(HttpServletRequest request, HttpServletResponse response) {
87 Map<String, Object> model = new HashMap<>();
88 ObjectMapper mapper = new ObjectMapper();
89 model.put("lockdowndata", mapper.writeValueAsString(commonClassDao.getData(GlobalRoleSettings.class)));
90 response.getWriter().write(new JSONObject(new JsonMessage(mapper.writeValueAsString(model))).toString());
91 } catch (Exception e) {
92 LOGGER.error("Exception Occured" + e);
97 * saveAdminTabLockdownValue.
99 * @param request HttpServletRequest
100 * @param response HttpServletResponse
101 * @return ModelAndView object
102 * @throws IOException IOException
105 value = {"/adminTabController/save_LockDownValue.htm"},
106 method = {org.springframework.web.bind.annotation.RequestMethod.POST})
107 public ModelAndView saveAdminTabLockdownValue(HttpServletRequest request, HttpServletResponse response)
109 response.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
110 request.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
112 ObjectMapper mapper = new ObjectMapper();
113 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
114 String userId = UserUtils.getUserSession(request).getOrgUserId();
116 "********************Logging UserID for Application Lockdown Function**************************");
117 LOGGER.info("UserId: " + userId);
119 "**********************************************************************************************");
120 JsonNode root = mapper.readTree(request.getReader());
121 GlobalRoleSettings globalRole =
122 mapper.readValue(root.get("lockdowndata").toString(), GlobalRoleSettings.class);
123 globalRole.setRole("super-admin");
124 commonClassDao.update(globalRole);
126 response.setContentType(PolicyUtils.APPLICATION_JSON);
128 String responseString = mapper.writeValueAsString(commonClassDao.getData(GlobalRoleSettings.class));
130 response.getWriter().write(new JSONObject("{descriptiveScopeDictionaryDatas: " + responseString
132 } catch (Exception e) {
133 LOGGER.error("Exception Occured" + e);
134 response.getWriter().write(PolicyUtils.CATCH_EXCEPTION);