2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.policy.controller;
24 import java.io.IOException;
25 import java.io.PrintWriter;
26 import java.util.HashMap;
29 import javax.servlet.http.HttpServletRequest;
30 import javax.servlet.http.HttpServletResponse;
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.policy.rest.dao.CommonClassDao;
36 import org.onap.policy.rest.jpa.GlobalRoleSettings;
37 import org.onap.policy.utils.PolicyUtils;
38 import org.onap.portalsdk.core.controller.RestrictedBaseController;
39 import org.onap.portalsdk.core.web.support.JsonMessage;
40 import org.onap.portalsdk.core.web.support.UserUtils;
41 import org.springframework.beans.factory.annotation.Autowired;
42 import org.springframework.http.MediaType;
43 import org.springframework.stereotype.Controller;
44 import org.springframework.web.bind.annotation.RequestMapping;
45 import org.springframework.web.servlet.ModelAndView;
47 import com.fasterxml.jackson.databind.DeserializationFeature;
48 import com.fasterxml.jackson.databind.JsonNode;
49 import com.fasterxml.jackson.databind.ObjectMapper;
52 @RequestMapping({"/"})
53 public class AdminTabController extends RestrictedBaseController{
55 private static final Logger LOGGER = FlexLogger.getLogger(AdminTabController.class);
57 private static CommonClassDao commonClassDao;
59 public AdminTabController() {
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;
76 @RequestMapping(value={"/get_LockDownData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
77 public void getAdminTabEntityData(HttpServletRequest request, HttpServletResponse response){
79 Map<String, Object> model = new HashMap<>();
80 ObjectMapper mapper = new ObjectMapper();
81 model.put("lockdowndata", mapper.writeValueAsString(commonClassDao.getData(GlobalRoleSettings.class)));
82 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
83 JSONObject j = new JSONObject(msg);
84 response.getWriter().write(j.toString());
87 LOGGER.error("Exception Occured"+e);
91 @RequestMapping(value={"/adminTabController/save_LockDownValue.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
92 public ModelAndView saveAdminTabLockdownValue(HttpServletRequest request, HttpServletResponse response) throws IOException{
94 ObjectMapper mapper = new ObjectMapper();
95 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
96 String userId = UserUtils.getUserSession(request).getOrgUserId();
97 LOGGER.info("****************************************Logging UserID for Application Lockdown Function*****************************************");
98 LOGGER.info("UserId: " + userId);
99 LOGGER.info("*********************************************************************************************************************************");
100 JsonNode root = mapper.readTree(request.getReader());
101 GlobalRoleSettings globalRole = mapper.readValue(root.get("lockdowndata").toString(), GlobalRoleSettings.class);
102 globalRole.setRole("super-admin");
103 commonClassDao.update(globalRole);
105 response.setCharacterEncoding("UTF-8");
106 response.setContentType("application / json");
107 request.setCharacterEncoding("UTF-8");
109 PrintWriter out = response.getWriter();
110 String responseString = mapper.writeValueAsString(commonClassDao.getData(GlobalRoleSettings.class));
111 JSONObject j = new JSONObject("{descriptiveScopeDictionaryDatas: " + responseString + "}");
113 out.write(j.toString());
118 LOGGER.error("Exception Occured"+e);
119 response.setCharacterEncoding("UTF-8");
120 request.setCharacterEncoding("UTF-8");
121 PrintWriter out = response.getWriter();
122 out.write(PolicyUtils.CATCH_EXCEPTION);