X-Git-Url: https://gerrit.onap.org/r/gitweb?p=policy%2Fengine.git;a=blobdiff_plain;f=ONAP-PAP-REST%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fpap%2Fxacml%2Frest%2FConsoleAndApiService.java;h=16340e5fec360b5e4beae22a1ecda52692df038a;hp=41c91ec27bde0b486fe4eee842c6717f712f5bdd;hb=5a5842e77e4e0f0b6207192b374d99753db26c7e;hpb=79ba275a19253eb1e63b128520a29e4516f89a3e diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/ConsoleAndApiService.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/ConsoleAndApiService.java index 41c91ec27..16340e5fe 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/ConsoleAndApiService.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/ConsoleAndApiService.java @@ -3,6 +3,7 @@ * ONAP-PAP-REST * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +23,7 @@ package org.onap.policy.pap.xacml.rest; import com.att.research.xacml.api.pap.PAPException; import com.fasterxml.jackson.databind.ObjectMapper; + import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; @@ -32,16 +34,18 @@ import java.util.HashSet; import java.util.List; import java.util.Scanner; import java.util.Set; + import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.onap.policy.common.logging.ONAPLoggingContext; + +import org.onap.policy.common.logging.OnapLoggingContext; import org.onap.policy.common.logging.eelf.MessageCodes; import org.onap.policy.common.logging.eelf.PolicyLogger; import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; -import org.onap.policy.pap.xacml.rest.components.PolicyDBDao; -import org.onap.policy.pap.xacml.rest.components.PolicyDBDaoTransaction; +import org.onap.policy.pap.xacml.rest.components.PolicyDbDao; +import org.onap.policy.pap.xacml.rest.components.PolicyDbDaoTransaction; import org.onap.policy.pap.xacml.rest.handler.PushPolicyHandler; import org.onap.policy.xacml.api.XACMLErrorConstants; import org.onap.policy.xacml.api.pap.OnapPDP; @@ -53,6 +57,15 @@ import org.onap.policy.xacml.std.pap.StdPDPPolicy; public class ConsoleAndApiService { + private static final String SPACE_UNIMPLEMENTED = " UNIMPLEMENTED"; + private static final String XACMLPAPSERVLET_DO_AC_PUT_COMMIT_TRANS = "XACMLPapServlet doACPut commitTransaction"; + private static final String UNIMPLEMENTED = "UNIMPLEMENTED"; + private static final String APPLICATION_JSON = "application/json"; + private static final String CONTENT_TYPE = "content-type"; + private static final String TO_GROUP = ",to group="; + private static final String PDP_ID = "pdpId"; + private static final String XACML_PAP_SERVLET_DO_AC_PUT = "XACMLPapServlet.doACPut"; + private static final String UNKNOWN_GROUP_ID = "Unknown groupId '"; private static final Logger LOGGER = FlexLogger.getLogger(ConsoleAndApiService.class); private static final Logger auditLogger = FlexLogger.getLogger("auditLogger"); private static final String ADD_GROUP_ERROR = "addGroupError"; @@ -79,8 +92,8 @@ public class ConsoleAndApiService { * @throws IOException Signals that an I/O exception has occurred. */ public void doAcPost(HttpServletRequest request, HttpServletResponse response, String groupId, - ONAPLoggingContext loggingContext, PAPPolicyEngine papEngine) throws IOException { - PolicyDBDaoTransaction doAcPostTransaction = null; + OnapLoggingContext loggingContext, PAPPolicyEngine papEngine) throws IOException { + PolicyDbDaoTransaction doAcPostTransaction = null; try { String groupName = request.getParameter("groupName"); String groupDescription = request.getParameter("groupDescription"); @@ -98,9 +111,9 @@ public class ConsoleAndApiService { } catch (UnsupportedEncodingException e) { LOGGER.error(e); } - PolicyDBDaoTransaction newGroupTransaction = XACMLPapServlet.getPolicyDbDao().getNewTransaction(); + PolicyDbDaoTransaction newGroupTransaction = XACMLPapServlet.getPolicyDbDao().getNewTransaction(); try { - newGroupTransaction.createGroup(PolicyDBDao.createNewPDPGroupId(unescapedName), unescapedName, + newGroupTransaction.createGroup(PolicyDbDao.createNewPdpGroupId(unescapedName), unescapedName, unescapedDescription, PAPSERVLETDOACPOST); papEngine.newGroup(unescapedName, unescapedDescription); loggingContext.metricStarted(); @@ -134,7 +147,7 @@ public class ConsoleAndApiService { LOGGER.error(e); } if (group == null) { - String message = "Unknown groupId '" + groupId + "'"; + String message = UNKNOWN_GROUP_ID + groupId + "'"; // for fixing Header Manipulation of Fortify issue if (!message.matches(REGEX)) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); @@ -168,7 +181,7 @@ public class ConsoleAndApiService { StdPDPGroup updatedGroup = null; StdPDPPolicy policyForSafetyCheck = new StdPDPPolicy(); for (String policyId : policyIdList) { - PolicyDBDaoTransaction addPolicyToGroupTransaction = + PolicyDbDaoTransaction addPolicyToGroupTransaction = XACMLPapServlet.getPolicyDbDao().getNewTransaction(); try { // Copying the policy to the file system and updating groups @@ -185,7 +198,8 @@ public class ConsoleAndApiService { if (policyId.contains("Config_MS_") || policyId.contains("BRMS_Param")) { PushPolicyHandler pushPolicyHandler = PushPolicyHandler.getInstance(); policyForSafetyCheck.setId(policyId); - if (pushPolicyHandler.preSafetyCheck(policyForSafetyCheck, XACMLPapServlet.getConfigHome())) { + if (pushPolicyHandler.preSafetyCheck(policyForSafetyCheck, + XACMLPapServlet.getConfigHome())) { LOGGER.debug("Precheck Successful."); } } @@ -218,18 +232,18 @@ public class ConsoleAndApiService { } /* - * If request comes from the API we need to run the PolicyDBDao updateGroup() to - * notify other paps of the change. The GUI does this from the POLICY-SDK-APP code. + * If request comes from the API we need to run the PolicyDBDao updateGroup() to notify other paps of + * the change. The GUI does this from the POLICY-SDK-APP code. */ // Get new transaction to perform updateGroup() - PolicyDBDaoTransaction acPutTransaction = XACMLPapServlet.getPolicyDbDao().getNewTransaction(); + PolicyDbDaoTransaction acPutTransaction = XACMLPapServlet.getPolicyDbDao().getNewTransaction(); try { // Assume that this is an update of an existing PDP // Group loggingContext.setServiceName("PolicyEngineAPI:PAP.updateGroup"); try { - acPutTransaction.updateGroup(updatedGroup, "XACMLPapServlet.doACPut", userId); + acPutTransaction.updateGroup(updatedGroup, XACML_PAP_SERVLET_DO_AC_PUT, userId); } catch (Exception e) { PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, XACMLPAPSERVLET, " Error occurred when notifying PAPs of a group change: " + e); @@ -275,8 +289,6 @@ public class ConsoleAndApiService { loggingContext.transactionEnded(); auditLogger.info(SUCCESS); LOGGER.info(TRANSENDED); - - return; } else if (request.getParameter("default") != null) { // Args: group= default=true <= make default // change the current default group to be the one identified in @@ -288,7 +300,8 @@ public class ConsoleAndApiService { // It should never be the case that multiple groups are // currently marked as the default, but protect against that // anyway. - PolicyDBDaoTransaction setDefaultGroupTransaction = XACMLPapServlet.getPolicyDbDao().getNewTransaction(); + PolicyDbDaoTransaction setDefaultGroupTransaction = + XACMLPapServlet.getPolicyDbDao().getNewTransaction(); try { setDefaultGroupTransaction.changeDefaultGroup(group, PAPSERVLETDOACPOST); papEngine.setDefaultGroup(group); @@ -311,20 +324,19 @@ public class ConsoleAndApiService { } auditLogger.info(SUCCESS); LOGGER.info(TRANSENDED); - return; - } else if (request.getParameter("pdpId") != null) { + } else if (request.getParameter(PDP_ID) != null) { doAcPostTransaction = XACMLPapServlet.getPolicyDbDao().getNewTransaction(); // Args: group= pdpId= <= move PDP to group loggingContext.setServiceName("AC:PAP.movePDP"); - String pdpId = request.getParameter("pdpId"); + String pdpId = request.getParameter(PDP_ID); OnapPDP pdp = papEngine.getPDP(pdpId); - OnapPDPGroup originalGroup = papEngine.getPDPGroup(pdp); + final OnapPDPGroup originalGroup = papEngine.getPDPGroup(pdp); try { doAcPostTransaction.movePdp(pdp, group, PAPSERVLETDOACPOST); } catch (Exception e) { doAcPostTransaction.rollbackTransaction(); PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, XACMLPAPSERVLET, - " Error while moving pdp in the database: " + "pdp=" + pdp.getId() + ",to group=" + " Error while moving pdp in the database: " + "pdp=" + pdp.getId() + TO_GROUP + group.getId()); throw new PAPException(e.getMessage()); } @@ -346,14 +358,12 @@ public class ConsoleAndApiService { loggingContext.transactionEnded(); auditLogger.info(SUCCESS); PolicyLogger.audit(TRANSENDED); - return; } } catch (PAPException e) { PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, XACMLPAPSERVLET, " AC POST exception"); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); - return; } } @@ -368,10 +378,10 @@ public class ConsoleAndApiService { * @throws IOException Signals that an I/O exception has occurred. */ public void doAcGet(HttpServletRequest request, HttpServletResponse response, String groupId, - ONAPLoggingContext loggingContext, PAPPolicyEngine papEngine) throws IOException { + OnapLoggingContext loggingContext, PAPPolicyEngine papEngine) throws IOException { try { String parameterDefault = request.getParameter("default"); - String pdpId = request.getParameter("pdpId"); + String pdpId = request.getParameter(PDP_ID); String pdpGroup = request.getParameter("getPDPGroup"); if ("".equals(groupId)) { // request IS from AC but does not identify a group by name @@ -386,7 +396,7 @@ public class ConsoleAndApiService { LOGGER.debug("GET Default group req from '" + request.getRequestURL() + "'"); } response.setStatus(HttpServletResponse.SC_OK); - response.setHeader("content-type", "application/json"); + response.setHeader(CONTENT_TYPE, APPLICATION_JSON); try { response.getOutputStream().close(); } catch (IOException e) { @@ -415,7 +425,7 @@ public class ConsoleAndApiService { LOGGER.debug("GET pdp '" + pdpId + "' req from '" + request.getRequestURL() + "'"); } response.setStatus(HttpServletResponse.SC_OK); - response.setHeader("content-type", "application/json"); + response.setHeader(CONTENT_TYPE, APPLICATION_JSON); try { response.getOutputStream().close(); } catch (IOException e) { @@ -442,7 +452,7 @@ public class ConsoleAndApiService { LOGGER.debug("GET PDP '" + pdpId + "' Group req from '" + request.getRequestURL() + "'"); } response.setStatus(HttpServletResponse.SC_OK); - response.setHeader("content-type", "application/json"); + response.setHeader(CONTENT_TYPE, APPLICATION_JSON); try { response.getOutputStream().close(); } catch (IOException e) { @@ -473,7 +483,7 @@ public class ConsoleAndApiService { LOGGER.debug("GET All groups req"); } response.setStatus(HttpServletResponse.SC_OK); - response.setHeader("content-type", "application/json"); + response.setHeader(CONTENT_TYPE, APPLICATION_JSON); try { response.getOutputStream().close(); } catch (IOException e) { @@ -494,7 +504,7 @@ public class ConsoleAndApiService { LOGGER.error(e); } if (group == null) { - String message = "Unknown groupId '" + groupId + "'"; + String message = UNKNOWN_GROUP_ID + groupId + "'"; // for fixing Header Manipulation of Fortify issue if (!message.matches(REGEX)) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); @@ -527,7 +537,7 @@ public class ConsoleAndApiService { LOGGER.debug("GET group '" + group.getId() + "' req from '" + request.getRequestURL() + "'"); } response.setStatus(HttpServletResponse.SC_OK); - response.setHeader("content-type", "application/json"); + response.setHeader(CONTENT_TYPE, APPLICATION_JSON); try { response.getOutputStream().close(); } catch (IOException e) { @@ -549,13 +559,12 @@ public class ConsoleAndApiService { PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " UNIMPLEMENTED "); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); - setResponseError(response, HttpServletResponse.SC_BAD_REQUEST, "UNIMPLEMENTED"); + setResponseError(response, HttpServletResponse.SC_BAD_REQUEST, UNIMPLEMENTED); } catch (PAPException e) { PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, XACMLPAPSERVLET, " AC Get exception"); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); - return; } } @@ -570,8 +579,8 @@ public class ConsoleAndApiService { * @throws IOException Signals that an I/O exception has occurred. */ public void doAcPut(HttpServletRequest request, HttpServletResponse response, String groupId, - ONAPLoggingContext loggingContext, PAPPolicyEngine papEngine) throws IOException { - PolicyDBDaoTransaction acPutTransaction = XACMLPapServlet.getPolicyDbDao().getNewTransaction(); + OnapLoggingContext loggingContext, PAPPolicyEngine papEngine) throws IOException { + PolicyDbDaoTransaction acPutTransaction = XACMLPapServlet.getPolicyDbDao().getNewTransaction(); try { String userId = request.getParameter("userId"); // for PUT operations the group may or may not need to exist before @@ -582,11 +591,12 @@ public class ConsoleAndApiService { // for remaining operations the group must exist before the // operation can be done if (group == null) { - String message = "Unknown groupId '" + groupId + "'"; + String message = UNKNOWN_GROUP_ID + groupId + "'"; PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); setResponseError(response, HttpServletResponse.SC_NOT_FOUND, message); + acPutTransaction.rollbackTransaction(); return; } if (request.getParameter("policy") != null) { @@ -601,11 +611,11 @@ public class ConsoleAndApiService { PolicyLogger.audit(TRANSACTIONFAILED); auditLogger.info(SUCCESS); PolicyLogger.audit(TRANSENDED); - return; - } else if (request.getParameter("pdpId") != null) { + acPutTransaction.rollbackTransaction(); + } else if (request.getParameter(PDP_ID) != null) { // ARGS: group= pdpId= <= create a new PDP // or Update an Existing one - String pdpId = request.getParameter("pdpId"); + String pdpId = request.getParameter(PDP_ID); if (papEngine.getPDP(pdpId) == null) { loggingContext.setServiceName("AC:PAP.createPDP"); } else { @@ -654,18 +664,18 @@ public class ConsoleAndApiService { // this is a request to create a new PDP object try { acPutTransaction.addPdpToGroup(pdp.getId(), group.getId(), pdp.getName(), - pdp.getDescription(), pdp.getJmxPort(), "XACMLPapServlet.doACPut"); + pdp.getDescription(), pdp.getJmxPort(), XACML_PAP_SERVLET_DO_AC_PUT); papEngine.newPDP(pdp.getId(), group, pdp.getName(), pdp.getDescription(), pdp.getJmxPort()); } catch (Exception e) { PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, XACMLPAPSERVLET, " Error while adding pdp to group in the database: " + "pdp=" + (pdp.getId()) - + ",to group=" + group.getId()); + + TO_GROUP + group.getId()); throw new PAPException(e.getMessage()); } } else { // this is a request to update the pdp try { - acPutTransaction.updatePdp(pdp, "XACMLPapServlet.doACPut"); + acPutTransaction.updatePdp(pdp, XACML_PAP_SERVLET_DO_AC_PUT); papEngine.updatePDP(pdp); } catch (Exception e) { PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, XACMLPAPSERVLET, @@ -684,15 +694,14 @@ public class ConsoleAndApiService { loggingContext.metricStarted(); acPutTransaction.commitTransaction(); loggingContext.metricEnded(); - PolicyLogger.metrics("XACMLPapServlet doACPut commitTransaction"); + PolicyLogger.metrics(XACMLPAPSERVLET_DO_AC_PUT_COMMIT_TRANS); loggingContext.transactionEnded(); auditLogger.info(SUCCESS); PolicyLogger.audit(TRANSENDED); - return; } else { try { PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, XACMLPAPSERVLET, - " Error while adding pdp to group in the database: " + "pdp=null" + ",to group=" + " Error while adding pdp to group in the database: " + "pdp=null" + TO_GROUP + group.getId()); throw new PAPException("PDP is null"); } catch (Exception e) { @@ -704,11 +713,11 @@ public class ConsoleAndApiService { // <= add a PIP to pip config, or replace it if it already // exists (lenient operation) loggingContext.setServiceName("AC:PAP.putPIP"); - PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " UNIMPLEMENTED"); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + UNIMPLEMENTED); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); - setResponseError(response, HttpServletResponse.SC_BAD_REQUEST, "UNIMPLEMENTED"); - return; + setResponseError(response, HttpServletResponse.SC_BAD_REQUEST, UNIMPLEMENTED); + acPutTransaction.rollbackTransaction(); } else { // Assume that this is an update of an existing PDP Group // ARGS: group= <= Update an Existing Group @@ -734,7 +743,7 @@ public class ConsoleAndApiService { } catch (Exception e) { LOGGER.error(e); } - if (objectFromJson == null || !(objectFromJson instanceof StdPDPGroup) + if (!(objectFromJson instanceof StdPDPGroup) || !((StdPDPGroup) objectFromJson).getId().equals(group.getId())) { PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " Group update had bad input. id=" + group.getId() + " objectFromJSON=" + objectFromJson); @@ -755,7 +764,7 @@ public class ConsoleAndApiService { if ("delete".equals(((StdPDPGroup) objectFromJson).getOperation())) { acPutTransaction.updateGroup((StdPDPGroup) objectFromJson, "XACMLPapServlet.doDelete", userId); } else { - acPutTransaction.updateGroup((StdPDPGroup) objectFromJson, "XACMLPapServlet.doACPut", userId); + acPutTransaction.updateGroup((StdPDPGroup) objectFromJson, XACML_PAP_SERVLET_DO_AC_PUT, userId); } } catch (Exception e) { PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW + " Error while updating group in the database: " @@ -781,13 +790,12 @@ public class ConsoleAndApiService { loggingContext.metricStarted(); acPutTransaction.commitTransaction(); loggingContext.metricEnded(); - PolicyLogger.metrics("XACMLPapServlet doACPut commitTransaction"); + PolicyLogger.metrics(XACMLPAPSERVLET_DO_AC_PUT_COMMIT_TRANS); // Group changed, which might include changing the policies getPapInstance().groupChanged(group, loggingContext); loggingContext.transactionEnded(); auditLogger.info(SUCCESS); PolicyLogger.audit(TRANSENDED); - return; } } catch (PAPException e) { LOGGER.debug(e); @@ -796,7 +804,6 @@ public class ConsoleAndApiService { loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); - return; } } @@ -811,19 +818,20 @@ public class ConsoleAndApiService { * @throws IOException Signals that an I/O exception has occurred. */ public void doAcDelete(HttpServletRequest request, HttpServletResponse response, String groupId, - ONAPLoggingContext loggingContext, PAPPolicyEngine papEngine) throws IOException { - PolicyDBDaoTransaction removePdpOrGroupTransaction = XACMLPapServlet.getPolicyDbDao().getNewTransaction(); + OnapLoggingContext loggingContext, PAPPolicyEngine papEngine) throws IOException { + PolicyDbDaoTransaction removePdpOrGroupTransaction = XACMLPapServlet.getPolicyDbDao().getNewTransaction(); try { // for all DELETE operations the group must exist before the // operation can be done loggingContext.setServiceName("AC:PAP.delete"); OnapPDPGroup group = papEngine.getGroup(groupId); if (group == null) { - String message = "Unknown groupId '" + groupId + "'"; + String message = UNKNOWN_GROUP_ID + groupId + "'"; PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); - setResponseError(response, HttpServletResponse.SC_NOT_FOUND, "Unknown groupId '" + groupId + "'"); + setResponseError(response, HttpServletResponse.SC_NOT_FOUND, UNKNOWN_GROUP_ID + groupId + "'"); + removePdpOrGroupTransaction.rollbackTransaction(); return; } // determine the operation needed based on the parameters in the @@ -832,14 +840,14 @@ public class ConsoleAndApiService { // group= policy= [delete=] <= // delete policy file from group loggingContext.setServiceName("AC:PAP.deletePolicy"); - PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " UNIMPLEMENTED"); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + SPACE_UNIMPLEMENTED); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); - setResponseError(response, HttpServletResponse.SC_BAD_REQUEST, "UNIMPLEMENTED"); - return; - } else if (request.getParameter("pdpId") != null) { + setResponseError(response, HttpServletResponse.SC_BAD_REQUEST, UNIMPLEMENTED); + removePdpOrGroupTransaction.rollbackTransaction(); + } else if (request.getParameter(PDP_ID) != null) { // ARGS: group= pdpId= <= delete PDP - String pdpId = request.getParameter("pdpId"); + String pdpId = request.getParameter(PDP_ID); OnapPDP pdp = papEngine.getPDP(pdpId); removePdpFromGroup(removePdpOrGroupTransaction, pdp, papEngine); // adjust the status of the group, which may have changed when @@ -852,20 +860,19 @@ public class ConsoleAndApiService { loggingContext.metricStarted(); removePdpOrGroupTransaction.commitTransaction(); loggingContext.metricEnded(); - PolicyLogger.metrics("XACMLPapServlet doACPut commitTransaction"); + PolicyLogger.metrics(XACMLPAPSERVLET_DO_AC_PUT_COMMIT_TRANS); loggingContext.transactionEnded(); auditLogger.info(SUCCESS); PolicyLogger.audit(TRANSENDED); - return; } else if (request.getParameter("pipId") != null) { // group= pipId= <= delete PIP config for // given engine loggingContext.setServiceName("AC:PAP.deletePIPConfig"); - PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " UNIMPLEMENTED"); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + SPACE_UNIMPLEMENTED); loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); - setResponseError(response, HttpServletResponse.SC_BAD_REQUEST, "UNIMPLEMENTED"); - return; + setResponseError(response, HttpServletResponse.SC_BAD_REQUEST, UNIMPLEMENTED); + removePdpOrGroupTransaction.rollbackTransaction(); } else { // ARGS: group= movePDPsToGroupId= // <= delete a group and move all its PDPs to the given group @@ -893,11 +900,10 @@ public class ConsoleAndApiService { loggingContext.metricStarted(); removePdpOrGroupTransaction.commitTransaction(); loggingContext.metricEnded(); - PolicyLogger.metrics("XACMLPapServlet doACPut commitTransaction"); + PolicyLogger.metrics(XACMLPAPSERVLET_DO_AC_PUT_COMMIT_TRANS); loggingContext.transactionEnded(); auditLogger.info(SUCCESS); PolicyLogger.audit(TRANSENDED); - return; } } catch (PAPException e) { removePdpOrGroupTransaction.rollbackTransaction(); @@ -905,11 +911,10 @@ public class ConsoleAndApiService { loggingContext.transactionEnded(); PolicyLogger.audit(TRANSACTIONFAILED); setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); - return; } } - private void deleteGroup(PolicyDBDaoTransaction removePdpOrGroupTransaction, OnapPDPGroup group, + private void deleteGroup(PolicyDbDaoTransaction removePdpOrGroupTransaction, OnapPDPGroup group, OnapPDPGroup moveToGroup, PAPPolicyEngine papEngine) throws PAPException { try { removePdpOrGroupTransaction.deleteGroup(group, moveToGroup, "XACMLPapServlet.doACDelete"); @@ -921,7 +926,7 @@ public class ConsoleAndApiService { } } - private void removePdpFromGroup(PolicyDBDaoTransaction removePdpOrGroupTransaction, OnapPDP pdp, + private void removePdpFromGroup(PolicyDbDaoTransaction removePdpOrGroupTransaction, OnapPDP pdp, PAPPolicyEngine papEngine) throws PAPException { try { removePdpOrGroupTransaction.removePdpFromGroup(pdp.getId(), "XACMLPapServlet.doACDelete"); @@ -951,6 +956,5 @@ public class ConsoleAndApiService { } catch (IOException e) { LOGGER.error("Error setting Error response Header ", e); } - return; } }