X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ECOMP-PAP-REST%2Fsrc%2Fmain%2Fjava%2Forg%2Fopenecomp%2Fpolicy%2Fpap%2Fxacml%2Frest%2Fhandler%2FDeleteHandler.java;h=88548ffa4cd5b6424a2bd87a1fbecd441b6ec8c8;hb=fc5c07705edc4dcb7083b39116a43844bb6a1490;hp=15e1faa0414b0c903475d805c0f66fe126288503;hpb=e0addf5b588a1244f9679becd90999dfcb4c3a94;p=policy%2Fengine.git diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/handler/DeleteHandler.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/handler/DeleteHandler.java index 15e1faa04..88548ffa4 100644 --- a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/handler/DeleteHandler.java +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/handler/DeleteHandler.java @@ -123,7 +123,14 @@ public class DeleteHandler { }else if(policyName.contains("Decision_")){ splitPolicyName = removeVersionExtension.replace(".Decision_", ":Decision_"); } - split = splitPolicyName.split(":"); + if(splitPolicyName != null){ + split = splitPolicyName.split(":"); + }else{ + PolicyLogger.error(MessageCodes.ERROR_UNKNOWN + "Failed to delete the policy. Please, provide the valid policyname."); + response.addHeader("error", "unknown"); + response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR ); + return; + } policyEntityQuery = em.createQuery("SELECT p FROM PolicyEntity p WHERE p.policyName LIKE :pName and p.scope=:pScope"); }else if(policy.getDeleteCondition().equalsIgnoreCase("Current Version")) { if(policyName.contains("Config_")){ @@ -249,7 +256,9 @@ public class DeleteHandler { return; } finally { em.close(); - con.close(); + if(con != null){ + con.close(); + } } if (policyVersionDeleted) { @@ -290,12 +299,18 @@ public class DeleteHandler { PolicyEntity policyEntity = (PolicyEntity) peData; Statement st = null; ResultSet rs = null; - st = con.createStatement(); - rs = st.executeQuery("Select * from PolicyGroupEntity where policyid = '"+policyEntity.getPolicyId()+"'"); - boolean gEntityList = rs.next(); - rs.close(); - if(gEntityList){ - return true; + try{ + st = con.createStatement(); + rs = st.executeQuery("Select * from PolicyGroupEntity where policyid = '"+policyEntity.getPolicyId()+"'"); + boolean gEntityList = rs.next(); + rs.close(); + if(gEntityList){ + return true; + } + }finally{ + if(st != null){ + st.close(); + } } } return false; @@ -392,8 +407,8 @@ public class DeleteHandler { } catch (PAPException e1) { PolicyLogger.error("Exception occured While Deleting Policy From PDP Group"+e1); } - if (group == null || ! (group instanceof StdPDPGroup) || ! (group.getId().equals(existingGroup.getId()))) { - PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " Group update had bad input. id=" + existingGroup.getId() + " objectFromJSON="+group); + if (group == null || ! (group instanceof StdPDPGroup) || existingGroup == null || ! (group.getId().equals(existingGroup.getId()))) { + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " Group update had bad input. id=" + existingGroup != null ? existingGroup.getId() : "null" + " objectFromJSON="+group); loggingContext.transactionEnded(); PolicyLogger.audit("Transaction Failed - See Error.log"); response = "No Group";