From c8961a6aa9a7315b3fb19edd9ce986e87d910a44 Mon Sep 17 00:00:00 2001 From: Seshu-Kumar-M Date: Tue, 5 Sep 2017 19:02:54 +0800 Subject: Sonar critical issues fix Issue-Id : SO-98 Change-Id: I229819e850c36fce9f8715d1534f8e5c5d812a0a Signed-off-by: Seshu-Kumar-M --- .../camunda/bpmn/plugin/urnmap/URNMapPlugin.java | 7 +- .../bpmn/plugin/urnmap/resources/URNResource.java | 89 +++++++++++++++------- 2 files changed, 67 insertions(+), 29 deletions(-) (limited to 'bpmn/MSOURN-plugin/src/main/java') diff --git a/bpmn/MSOURN-plugin/src/main/java/org/openecomp/camunda/bpmn/plugin/urnmap/URNMapPlugin.java b/bpmn/MSOURN-plugin/src/main/java/org/openecomp/camunda/bpmn/plugin/urnmap/URNMapPlugin.java index 09fdc1c85e..4f6ead0299 100644 --- a/bpmn/MSOURN-plugin/src/main/java/org/openecomp/camunda/bpmn/plugin/urnmap/URNMapPlugin.java +++ b/bpmn/MSOURN-plugin/src/main/java/org/openecomp/camunda/bpmn/plugin/urnmap/URNMapPlugin.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * OPENECOMP - MSO + * ONAP - SO * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ @@ -32,14 +32,15 @@ import org.openecomp.camunda.bpmn.plugin.urnmap.resources.URNMapPluginRootResour public class URNMapPlugin extends AbstractCockpitPlugin{ public static final String ID = "urnMap-plugin"; - + + @Override public String getId() { return ID; } @Override public Set> getResourceClasses() { - Set> classes = new HashSet>(); + Set> classes = new HashSet<>(); classes.add(URNMapPluginRootResource.class); diff --git a/bpmn/MSOURN-plugin/src/main/java/org/openecomp/camunda/bpmn/plugin/urnmap/resources/URNResource.java b/bpmn/MSOURN-plugin/src/main/java/org/openecomp/camunda/bpmn/plugin/urnmap/resources/URNResource.java index 3dc6c249f5..5ef77eec40 100644 --- a/bpmn/MSOURN-plugin/src/main/java/org/openecomp/camunda/bpmn/plugin/urnmap/resources/URNResource.java +++ b/bpmn/MSOURN-plugin/src/main/java/org/openecomp/camunda/bpmn/plugin/urnmap/resources/URNResource.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * OPENECOMP - MSO + * ONAP - SO * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ @@ -28,6 +28,7 @@ import java.sql.SQLException; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; +import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; @@ -60,11 +61,11 @@ public class URNResource extends AbstractCockpitPluginResource{ public List getUrnDataMap() { List list = new ArrayList(); - + PreparedStatement psData = null; try { conn = getDBConnection(); - PreparedStatement psData = conn + psData = conn .prepareStatement("select * from MSO_URN_MAPPING order by NAME_"); ResultSet r = psData.executeQuery(); @@ -79,13 +80,25 @@ public class URNResource extends AbstractCockpitPluginResource{ list.add(d); } - psData.close(); - conn.close(); - } catch (Exception e) { - - e.printStackTrace(); + msoLogger.debug("Exception in getUrnDataMap " + e); + } finally { + if(psData != null){ + try { + psData.close(); + conn.close(); + } catch (SQLException e) { + msoLogger.debug("Exception while closing the PreparedStatement: " + e); + } + } + if(conn != null){ + try { + conn.close(); + } catch (SQLException e) { + msoLogger.debug("Exception while closing the connection: " + e); + } + } } for(URNData d: list) @@ -130,8 +143,7 @@ public class URNResource extends AbstractCockpitPluginResource{ } catch (Exception e) { - - e.printStackTrace(); + msoLogger.debug("Exception in DBConnection " + e); } return conn; @@ -158,24 +170,36 @@ public class URNResource extends AbstractCockpitPluginResource{ nRow.setVer_("1"); final String myKey = key_; final String myValue = value_; - + PreparedStatement psData = null; + msoLogger.debug("----------- START ----------------------"); try { conn = getDBConnection(); - PreparedStatement psData = conn + psData = conn .prepareStatement("Insert into MSO_URN_MAPPING values ('" + key_ + "', '" + value_ + "', '1')"); - psData.executeUpdate(); - - psData.close(); - conn.close(); - //} + psData.executeUpdate(); } catch (Exception e) { - - e.printStackTrace(); + msoLogger.debug("Exception in insertNewRow " + e); + }finally { + if(psData != null){ + try { + psData.close(); + conn.close(); + } catch (SQLException e) { + msoLogger.debug("Exception while closing the PreparedStatement: " + e); + } + } + if(conn != null){ + try { + conn.close(); + } catch (SQLException e) { + msoLogger.debug("Exception while closing the connection: " + e); + } + } } // getQueryService().executeQuery("cockpit.urnMap.insertNewRow", nRow, URNData.class); } @@ -184,21 +208,34 @@ public class URNResource extends AbstractCockpitPluginResource{ public void getPersistData(URNData d) { //getQueryService().executeQuery("cockpit.urnMap.persistURNData", d, URNData.class); - + PreparedStatement psData = null; try { conn = getDBConnection(); - PreparedStatement psData = conn + psData = conn .prepareStatement("UPDATE MSO_URN_MAPPING set VALUE_ ='"+ d.getURNValue() + "' WHERE NAME_='" + d.getURNName() + "'"); psData.executeUpdate(); - - psData.close(); - conn.close(); + } catch (Exception e) { - - e.printStackTrace(); + msoLogger.debug("Exception in PersistData " + e); + }finally { + if(psData != null){ + try { + psData.close(); + conn.close(); + } catch (SQLException e) { + msoLogger.debug("Exception while closing the PreparedStatement: " + e); + } + } + if(conn != null){ + try { + conn.close(); + } catch (SQLException e) { + msoLogger.debug("Exception while closing the connection: " + e); + } + } } } -- cgit 1.2.3-korg