- @RequestMapping(value={"/get_PDPGroupData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
- public void getPDPGroupEntityData(HttpServletRequest request, HttpServletResponse response){
- try{
- ObjectMapper mapper = new ObjectMapper();
- refreshGroups(request);
- JsonMessage msg = new JsonMessage(mapper.writeValueAsString(groups));
- JSONObject j = new JSONObject(msg);
- response.getWriter().write(j.toString());
- }
- catch (Exception e){
- policyLogger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Error Occured while retrieving the PDP Group data" + e);
- }
- }
-
- @RequestMapping(value={"/pdp_Group/save_pdp_group"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
- public void savePDPGroup(HttpServletRequest request, HttpServletResponse response){
- try {
- ObjectMapper mapper = new ObjectMapper();
- PolicyController controller = getPolicyControllerInstance();
- mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
- JsonNode root = mapper.readTree(request.getReader());
- this.container = new PDPGroupContainer(controller.getPapEngine());
- StdPDPGroup pdpGroupData = mapper.readValue(root.get("pdpGroupData").toString().replace("groupName", "name"), StdPDPGroup.class);
- try {
- if(pdpGroupData.getId() == null){
- this.container.addNewGroup(pdpGroupData.getName(), pdpGroupData.getDescription());
- }else{
- this.container.updateGroup(pdpGroupData);
- }
-
- } catch (Exception e) {
- String message = "Unable to create Group. Reason:\n" + e.getMessage();
- policyLogger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Error Occured while creating the PDP Group" + message + e);
- }
-
-
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application / json");
- request.setCharacterEncoding("UTF-8");
-
- PrintWriter out = response.getWriter();
- refreshGroups(request);
- JsonMessage msg = new JsonMessage(mapper.writeValueAsString(groups));
- JSONObject j = new JSONObject(msg);
- out.write(j.toString());
- }
- catch (Exception e){
- policyLogger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Error Occured while Saving the PDP Group" + e);
- response.setCharacterEncoding("UTF-8");
- PrintWriter out = null;
- try {
- request.setCharacterEncoding("UTF-8");
- out = response.getWriter();
- out.write(e.getMessage());
- } catch (Exception e1) {
- policyLogger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Error Occured while Saving the PDP Group" + e1);
- }
- }
- }
-
- @RequestMapping(value={"/pdp_Group/remove_pdp_group"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
- public void removePDPGroup(HttpServletRequest request, HttpServletResponse response){
- try{
- ObjectMapper mapper = new ObjectMapper();
- mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
- JsonNode root = mapper.readTree(request.getReader());
- PolicyController controller = getPolicyControllerInstance();
- this.container = new PDPGroupContainer(controller.getPapEngine());
- StdPDPGroup pdpGroupData = mapper.readValue(root.get("pdpGroupData").toString(), StdPDPGroup.class);
- if(pdpGroupData.getName().equals("Default")) {
- throw new UnsupportedOperationException("You can't remove the Default Group.");
- }else{
- this.container.removeGroup(pdpGroupData, null);
- }
-
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application / json");
- request.setCharacterEncoding("UTF-8");
-
- PrintWriter out = response.getWriter();
-
- refreshGroups(request);
- JsonMessage msg = new JsonMessage(mapper.writeValueAsString(groups));
- JSONObject j = new JSONObject(msg);
- out.write(j.toString());
- }
- catch (Exception e){
- policyLogger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Error Occured while Removing the PDP Group" + e);
- PrintWriter out;
- try {
- response.setCharacterEncoding("UTF-8");
- request.setCharacterEncoding("UTF-8");
- out = response.getWriter();
- out.write(e.getMessage());
- } catch (Exception e1) {
- policyLogger.error("Exception Occured"+ e1);
- }
- }
- }
-
- @RequestMapping(value={"/pdp_Group/save_pdpTogroup"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
- public void savePDPToGroup(HttpServletRequest request, HttpServletResponse response){
- try {
- ObjectMapper mapper = new ObjectMapper();
- mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
- JsonNode root = mapper.readTree(request.getReader());
- PolicyController controller = getPolicyControllerInstance();
- this.container = new PDPGroupContainer(controller.getPapEngine());
- String update = root.get("update").toString();
- PdpData pdpGroupData = (PdpData)mapper.readValue(root.get("pdpInGroup").toString(), PdpData.class);
- StdPDPGroup activeGroupData = mapper.readValue(root.get("activePDP").toString(), StdPDPGroup.class);
- try {
-
- if(update.contains("false")){
- this.container.addNewPDP(pdpGroupData.getId(), activeGroupData, pdpGroupData.getName(), pdpGroupData.getDescription(), pdpGroupData.getJmxPort());
- }else{
- this.container.updateGroup(activeGroupData);
- }
- } catch (Exception e) {
- String message = "Unable to create Group. Reason:\n" + e.getMessage();
- policyLogger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Error Occured while Creating Pdp in PDP Group" + message + e);
- }
-
-
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application / json");
- request.setCharacterEncoding("UTF-8");
-
- PrintWriter out = response.getWriter();
- refreshGroups(request);
- JsonMessage msg = new JsonMessage(mapper.writeValueAsString(groups));
- JSONObject j = new JSONObject(msg);
- out.write(j.toString());
- }
- catch (Exception e){
- policyLogger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Error Occured while Creating Pdp in PDP Group" + e);
- PrintWriter out;
- try {
- response.setCharacterEncoding("UTF-8");
- request.setCharacterEncoding("UTF-8");
- out = response.getWriter();
- out.write(e.getMessage());
- } catch (Exception e1) {
- policyLogger.error("Exception Occured"+ e1);
- }
- }
- }
-
- @RequestMapping(value={"/pdp_Group/remove_pdpFromGroup"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
- public void removePDPFromGroup(HttpServletRequest request, HttpServletResponse response){
- try{
- ObjectMapper mapper = new ObjectMapper();
- mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
- JsonNode root = mapper.readTree(request.getReader());
- PolicyController controller = getPolicyControllerInstance();
- this.container = new PDPGroupContainer(controller.getPapEngine());
- StdPDP deletePdp = mapper.readValue(root.get("data").toString(), StdPDP.class);
- StdPDPGroup activeGroupData = mapper.readValue(root.get("activePDP").toString(), StdPDPGroup.class);
-
- this.container.removePDP(deletePdp, activeGroupData);
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application / json");
- request.setCharacterEncoding("UTF-8");
-
- PrintWriter out = response.getWriter();
- refreshGroups(request);
- String responseString = mapper.writeValueAsString(groups);
- JSONObject j = new JSONObject("{pdpEntityDatas: " + responseString + "}");
- out.write(j.toString());
- }
- catch (Exception e){
- policyLogger.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Error Occured while Removing Pdp from PDP Group" + e);
- PrintWriter out;
- try {
- response.setCharacterEncoding("UTF-8");
- request.setCharacterEncoding("UTF-8");
- out = response.getWriter();
- out.write(e.getMessage());
- } catch (Exception e1) {
- policyLogger.error("Exception Occured"+ e1);
- }
- }
- }
-
- private PolicyController getPolicyControllerInstance(){
- return policyController != null ? getPolicyController() : new PolicyController();
- }
-
- public boolean isJunit() {
- return junit;
- }
-
- public void setJunit(boolean junit) {
- this.junit = junit;
- }
-
- public Set<OnapPDPGroup> getGroupsData() {
- return groupsData;
- }
-
- public void setGroupsData(Set<OnapPDPGroup> groupsData) {
- this.groupsData = groupsData;
- }
+ /**
+ * removePDPFromGroup.
+ *
+ * @param request HttpServletRequest
+ * @param response HttpServletResponse
+ */
+ @RequestMapping(
+ value = {"/pdp_Group/remove_pdpFromGroup"},
+ method = {org.springframework.web.bind.annotation.RequestMethod.POST})
+ public void removePDPFromGroup(HttpServletRequest request, HttpServletResponse response) {
+ try {
+ response.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
+ request.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
+ //
+ //
+ //
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ JsonNode root = mapper.readTree(request.getReader());
+ PolicyController controller = getPolicyControllerInstance();
+ this.container = new PDPGroupContainer(controller.getPapEngine());
+
+ String userId = UserUtils.getUserSession(request).getOrgUserId();
+ policyLogger.info(
+ "********************Logging UserID while Removing pdp from PDP Group**************************");
+ policyLogger.info("UserId: " + userId + "Delete PDP Group Data: " + root.get("data").toString()
+ + "Active Group Data: " + root.get("activePDP").toString());
+ policyLogger.info(
+ "************************************************************************************************");
+
+ StdPDP deletePdp = mapper.readValue(root.get("data").toString(), StdPDP.class);
+ StdPDPGroup activeGroupData = mapper.readValue(root.get("activePDP").toString(), StdPDPGroup.class);
+ this.container.removePDP(deletePdp, activeGroupData);
+ response.setContentType(PolicyUtils.APPLICATION_JSON);
+
+ refreshGroups(request);
+ response.getWriter().write(new JSONObject(new JsonMessage(mapper.writeValueAsString(groups))).toString());
+ } catch (Exception e) {
+ policyLogger.error(
+ XACMLErrorConstants.ERROR_DATA_ISSUE + "Error Occured while Removing Pdp from PDP Group" + e);
+ try {
+ response.getWriter().write(e.getMessage());
+ } catch (Exception e1) {
+ policyLogger.error("Exception Occured" + e1);
+ }
+ }
+ }
+
+ private PolicyController getPolicyControllerInstance() {
+ return policyController != null ? getPolicyController() : new PolicyController();
+ }
+
+ public boolean isJunit() {
+ return junit;
+ }
+
+ public void setJunit(boolean junit) {
+ this.junit = junit;
+ }
+
+ public Set<OnapPDPGroup> getGroupsData() {
+ return groupsData;
+ }
+
+ public void setGroupsData(Set<OnapPDPGroup> groupsData) {
+ this.groupsData = groupsData;
+ }