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);
55 private static final String CHARACTER_ENCODING = "UTF-8";
57 private static CommonClassDao commonClassDao;
59 public AdminTabController() {
60 // default constructor
64 private AdminTabController(CommonClassDao commonClassDao) {
65 AdminTabController.commonClassDao = commonClassDao;
68 public static CommonClassDao getCommonClassDao() {
69 return commonClassDao;
72 public static void setCommonClassDao(CommonClassDao commonClassDao) {
73 AdminTabController.commonClassDao = commonClassDao;
77 * getAdminTabEntityData.
79 * @param request HttpServletRequest
80 * @param response HttpServletResponse
83 value = {"/get_LockDownData"},
84 method = {org.springframework.web.bind.annotation.RequestMethod.GET},
85 produces = MediaType.APPLICATION_JSON_VALUE)
86 public void getAdminTabEntityData(HttpServletRequest request, HttpServletResponse response) {
88 Map<String, Object> model = new HashMap<>();
89 ObjectMapper mapper = new ObjectMapper();
90 model.put("lockdowndata", mapper.writeValueAsString(commonClassDao.getData(GlobalRoleSettings.class)));
91 response.getWriter().write(new JSONObject(new JsonMessage(mapper.writeValueAsString(model))).toString());
92 } catch (Exception e) {
93 LOGGER.error("Exception Occured" + e);
98 * saveAdminTabLockdownValue.
100 * @param request HttpServletRequest
101 * @param response HttpServletResponse
102 * @return ModelAndView object
103 * @throws IOException IOException
106 value = {"/adminTabController/save_LockDownValue.htm"},
107 method = {org.springframework.web.bind.annotation.RequestMethod.POST})
108 public ModelAndView saveAdminTabLockdownValue(HttpServletRequest request, HttpServletResponse response)
110 response.setCharacterEncoding(CHARACTER_ENCODING);
111 request.setCharacterEncoding(CHARACTER_ENCODING);
113 ObjectMapper mapper = new ObjectMapper();
114 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
115 String userId = UserUtils.getUserSession(request).getOrgUserId();
117 "********************Logging UserID for Application Lockdown Function**************************");
118 LOGGER.info("UserId: " + userId);
120 "**********************************************************************************************");
121 JsonNode root = mapper.readTree(request.getReader());
122 GlobalRoleSettings globalRole =
123 mapper.readValue(root.get("lockdowndata").toString(), GlobalRoleSettings.class);
124 globalRole.setRole("super-admin");
125 commonClassDao.update(globalRole);
127 response.setContentType("application / json");
129 String responseString = mapper.writeValueAsString(commonClassDao.getData(GlobalRoleSettings.class));
131 response.getWriter().write(new JSONObject("{descriptiveScopeDictionaryDatas: " + responseString
133 } catch (Exception e) {
134 LOGGER.error("Exception Occured" + e);
135 response.getWriter().write(PolicyUtils.CATCH_EXCEPTION);