X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ONAP-PAP-REST%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fpap%2Fxacml%2Frest%2Felk%2Fclient%2FElasticSearchPolicyUpdate.java;h=dcabefcc8fcf028fb2350c1ac5e0f9f339134096;hb=eef3c224cb6cad4b82a96938ade1e42ca881eea2;hp=5de09215cf9b1b65943dfa8e52659b2b23a924d9;hpb=44fd25bcbb86f8600ec88eeeac6bb8312672c470;p=policy%2Fengine.git diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElasticSearchPolicyUpdate.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElasticSearchPolicyUpdate.java index 5de09215c..dcabefcc8 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElasticSearchPolicyUpdate.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElasticSearchPolicyUpdate.java @@ -115,6 +115,7 @@ public class ElasticSearchPolicyUpdate { Connection conn = null; Statement stmt = null; + ResultSet result = null; List listIndex = new ArrayList<>(); @@ -124,7 +125,7 @@ public class ElasticSearchPolicyUpdate { stmt = conn.createStatement(); String policyEntityQuery = "Select * from PolicyEntity"; - ResultSet result = stmt.executeQuery(policyEntityQuery); + result = stmt.executeQuery(policyEntityQuery); while(result.next()){ StringBuilder policyDataString = new StringBuilder("{"); @@ -171,36 +172,10 @@ public class ElasticSearchPolicyUpdate { if(!"decision".equals(_type)){ if(configurationdataid != null){ - String configEntityQuery = "Select * from ConfigurationDataEntity where configurationDataId = ?"; - PreparedStatement pstmt = null; - pstmt = conn.prepareStatement(configEntityQuery); - pstmt.setString(1, configurationdataid); - ResultSet configResult = pstmt.executeQuery(); - while(configResult.next()){ - String configBody = configResult.getString("configbody"); - String configType = configResult.getString("configtype"); - if(configBody!=null){ - configBody = configBody.replace("null", "\"\""); - configBody= configBody.replace("\"", "\\\""); - policyDataString.append("\"jsonBodyData\":\""+configBody+"\",\"configType\":\""+configType+"\","); - } - } - configResult.close(); + updateConfigData(conn, configurationdataid, policyDataString); } - if(actionbodyid != null){ - String actionEntityQuery = "Select * from ActionBodyEntity where actionBodyId = ?"; - PreparedStatement pstmt = null; - pstmt = conn.prepareStatement(actionEntityQuery); - pstmt.setString(1, actionbodyid); - ResultSet actionResult = pstmt.executeQuery(); - while(actionResult.next()){ - String actionBody = actionResult.getString("actionbody"); - actionBody = actionBody.replace("null", "\"\""); - actionBody = actionBody.replace("\"", "\\\""); - policyDataString.append("\"jsonBodyData\":\""+actionBody+"\","); - } - actionResult.close(); + updateActionData(conn, actionbodyid, policyDataString); } } @@ -245,6 +220,20 @@ public class ElasticSearchPolicyUpdate { } catch (Exception e) { LOGGER.error("Exception Occured while performing database Operation for Elastic Search Policy Upgrade"+e); }finally{ + if(result != null){ + try { + result.close(); + } catch (Exception e) { + LOGGER.error("Exception Occured while closing the resultset"+e); + } + } + if(stmt != null){ + try { + stmt.close(); + } catch (Exception e) { + LOGGER.error("Exception Occured while closing the statement"+e); + } + } if(conn != null){ try { conn.close(); @@ -315,4 +304,79 @@ public class ElasticSearchPolicyUpdate { return policyDataString.toString(); } + private static void updateConfigData(Connection conn, String configurationdataid, StringBuilder policyDataString) throws Exception { + + PreparedStatement pstmt = null; + ResultSet configResult = null; + try { + String configEntityQuery = "Select * from ConfigurationDataEntity where configurationDataId = ?"; + pstmt = null; + pstmt = conn.prepareStatement(configEntityQuery); + pstmt.setString(1, configurationdataid); + configResult = pstmt.executeQuery(); + while(configResult.next()){ + String configBody = configResult.getString("configbody"); + String configType = configResult.getString("configtype"); + if(configBody!=null){ + configBody = configBody.replace("null", "\"\""); + configBody= configBody.replace("\"", "\\\""); + policyDataString.append("\"jsonBodyData\":\""+configBody+"\",\"configType\":\""+configType+"\","); + } + } + } catch(Exception e) { + LOGGER.error("Exception Occured while updating configData"+e); + throw(e); + } finally { + if(configResult != null){ + try { + configResult.close(); + } catch (Exception e) { + LOGGER.error("Exception Occured while closing the ResultSet"+e); + } + } + if(pstmt != null){ + try { + pstmt.close(); + } catch (Exception e) { + LOGGER.error("Exception Occured while closing the PreparedStatement"+e); + } + } + } + } + + private static void updateActionData(Connection conn, String actionbodyid, StringBuilder policyDataString) throws Exception { + + PreparedStatement pstmt = null; + ResultSet actionResult = null; + try { + String actionEntityQuery = "Select * from ActionBodyEntity where actionBodyId = ?"; + pstmt = conn.prepareStatement(actionEntityQuery); + pstmt.setString(1, actionbodyid); + actionResult = pstmt.executeQuery(); + while(actionResult.next()){ + String actionBody = actionResult.getString("actionbody"); + actionBody = actionBody.replace("null", "\"\""); + actionBody = actionBody.replace("\"", "\\\""); + policyDataString.append("\"jsonBodyData\":\""+actionBody+"\","); + } + } catch(Exception e) { + LOGGER.error("Exception Occured while updating actionData"+e); + throw(e); + } finally { + if(actionResult != null){ + try { + actionResult.close(); + } catch (Exception e) { + LOGGER.error("Exception Occured while closing the ResultSet"+e); + } + } + if(pstmt != null){ + try { + pstmt.close(); + } catch (Exception e) { + LOGGER.error("Exception Occured while closing the PreparedStatement"+e); + } + } + } + } } \ No newline at end of file