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.openecomp.policy.controller;
24 import java.io.PrintWriter;
25 import java.util.HashMap;
28 import javax.servlet.http.HttpServletRequest;
29 import javax.servlet.http.HttpServletResponse;
31 import org.json.JSONObject;
32 import org.openecomp.policy.rest.dao.CommonClassDao;
33 import org.openecomp.policy.rest.jpa.GlobalRoleSettings;
34 import org.openecomp.portalsdk.core.controller.RestrictedBaseController;
35 import org.openecomp.portalsdk.core.web.support.JsonMessage;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.http.MediaType;
38 import org.springframework.stereotype.Controller;
39 import org.springframework.web.bind.annotation.RequestMapping;
40 import org.springframework.web.servlet.ModelAndView;
42 import com.fasterxml.jackson.databind.DeserializationFeature;
43 import com.fasterxml.jackson.databind.JsonNode;
44 import com.fasterxml.jackson.databind.ObjectMapper;
47 @RequestMapping({"/"})
48 public class AdminTabController extends RestrictedBaseController{
51 CommonClassDao commonClassDao;
55 @RequestMapping(value={"/get_LockDownData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
56 public void getAdminTabEntityData(HttpServletRequest request, HttpServletResponse response){
58 Map<String, Object> model = new HashMap<String, Object>();
59 ObjectMapper mapper = new ObjectMapper();
60 model.put("lockdowndata", mapper.writeValueAsString(commonClassDao.getData(GlobalRoleSettings.class)));
61 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
62 JSONObject j = new JSONObject(msg);
63 response.getWriter().write(j.toString());
70 @RequestMapping(value={"/adminTabController/save_LockDownValue.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
71 public ModelAndView saveAdminTabLockdownValue(HttpServletRequest request, HttpServletResponse response) throws Exception{
73 ObjectMapper mapper = new ObjectMapper();
74 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
75 JsonNode root = mapper.readTree(request.getReader());
76 GlobalRoleSettings globalRole = mapper.readValue(root.get("lockdowndata").toString(), GlobalRoleSettings.class);
77 globalRole.setRole("super-admin");
78 commonClassDao.update(globalRole);
80 response.setCharacterEncoding("UTF-8");
81 response.setContentType("application / json");
82 request.setCharacterEncoding("UTF-8");
84 PrintWriter out = response.getWriter();
85 String responseString = mapper.writeValueAsString(commonClassDao.getData(GlobalRoleSettings.class));
86 JSONObject j = new JSONObject("{descriptiveScopeDictionaryDatas: " + responseString + "}");
88 out.write(j.toString());
93 response.setCharacterEncoding("UTF-8");
94 request.setCharacterEncoding("UTF-8");
95 PrintWriter out = response.getWriter();
96 out.write(e.getMessage());