X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=datarouter-prov%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdatarouter%2Fprovisioning%2Fbeans%2FGroup.java;h=30fc87c4b438f5e00b44cb5d48d2da718b781b42;hb=ee6fa61e2cd7df99891092709765235b6166a041;hp=91d6c1b4ff2940645fd7a2f20fef1eabb5f97083;hpb=46ef61c0fe477483be17dbf9af2ef3b1023da0d8;p=dmaap%2Fdatarouter.git diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Group.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Group.java index 91d6c1b4..30fc87c4 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Group.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Group.java @@ -43,6 +43,7 @@ import org.onap.dmaap.datarouter.provisioning.utils.URLUtilities; * @version $Id: Group.java,v 1.0 2016/07/19 */ public class Group extends Syncable { + private static Logger intlogger = Logger.getLogger("org.onap.dmaap.datarouter.provisioning.internal"); private static int next_groupid = getMaxGroupID() + 1; @@ -96,8 +97,8 @@ public class Group extends Syncable { DB db = new DB(); @SuppressWarnings("resource") Connection conn = db.getConnection(); - try(Statement stmt = conn.createStatement()) { - try(ResultSet rs = stmt.executeQuery(sql)) { + try (Statement stmt = conn.createStatement()) { + try (ResultSet rs = stmt.executeQuery(sql)) { while (rs.next()) { Group group = new Group(rs); list.add(group); @@ -106,7 +107,7 @@ public class Group extends Syncable { } db.release(conn); } catch (SQLException e) { - e.printStackTrace(); + intlogger.error("SQLException " + e.getMessage()); } return list; } @@ -117,8 +118,8 @@ public class Group extends Syncable { DB db = new DB(); @SuppressWarnings("resource") Connection conn = db.getConnection(); - try(Statement stmt = conn.createStatement()) { - try(ResultSet rs = stmt.executeQuery("select MAX(groupid) from GROUPS")) { + try (Statement stmt = conn.createStatement()) { + try (ResultSet rs = stmt.executeQuery("select MAX(groupid) from GROUPS")) { if (rs.next()) { max = rs.getInt(1); } @@ -127,7 +128,6 @@ public class Group extends Syncable { db.release(conn); } catch (SQLException e) { intlogger.info("getMaxSubID: " + e.getMessage()); - e.printStackTrace(); } return max; } @@ -139,9 +139,9 @@ public class Group extends Syncable { DB db = new DB(); @SuppressWarnings("resource") Connection conn = db.getConnection(); - try(PreparedStatement stmt = conn.prepareStatement(sql)) { + try (PreparedStatement stmt = conn.prepareStatement(sql)) { stmt.setString(1, classfication); - try(ResultSet rs = stmt.executeQuery()) { + try (ResultSet rs = stmt.executeQuery()) { while (rs.next()) { int groupid = rs.getInt("groupid"); @@ -150,7 +150,7 @@ public class Group extends Syncable { } db.release(conn); } catch (SQLException e) { - e.printStackTrace(); + intlogger.error("SQLException " + e.getMessage()); } return list; } @@ -166,8 +166,8 @@ public class Group extends Syncable { DB db = new DB(); @SuppressWarnings("resource") Connection conn = db.getConnection(); - try(Statement stmt = conn.createStatement()) { - try(ResultSet rs = stmt.executeQuery("select count(*) from SUBSCRIPTIONS")) { + try (Statement stmt = conn.createStatement()) { + try (ResultSet rs = stmt.executeQuery("select count(*) from SUBSCRIPTIONS")) { if (rs.next()) { count = rs.getInt(1); } @@ -176,7 +176,6 @@ public class Group extends Syncable { db.release(conn); } catch (SQLException e) { intlogger.warn("PROV0008 countActiveSubscriptions: " + e.getMessage()); - e.printStackTrace(); } return count; } @@ -210,7 +209,7 @@ public class Group extends Syncable { public Group(JSONObject jo) throws InvalidObjectException { this("", "", ""); try { - // The JSONObject is assumed to contain a vnd.att-dr.group representation + // The JSONObject is assumed to contain a vnd.dmaap-dr.group representation this.groupid = jo.optInt("groupid", -1); String gname = jo.getString("name"); String gdescription = jo.getString("description"); @@ -221,10 +220,12 @@ public class Group extends Syncable { this.classification = jo.getString("classification"); this.members = jo.getString("members"); - if (gname.length() > 50) + if (gname.length() > 50) { throw new InvalidObjectException("Group name is too long"); - if (gdescription.length() > 256) + } + if (gdescription.length() > 256) { throw new InvalidObjectException("Group Description is too long"); + } } catch (InvalidObjectException e) { throw e; } catch (Exception e) { @@ -328,9 +329,9 @@ public class Group extends Syncable { setGroupid(next_groupid++); } // In case we insert a gropup from synchronization - if (groupid > next_groupid) + if (groupid > next_groupid) { next_groupid = groupid + 1; - + } // Create the GROUPS row String sql = "insert into GROUPS (GROUPID, AUTHID, NAME, DESCRIPTION, CLASSIFICATION, MEMBERS) values (?, ?, ?, ?, ?, ?)"; @@ -346,14 +347,13 @@ public class Group extends Syncable { } catch (SQLException e) { rv = false; intlogger.warn("PROV0005 doInsert: " + e.getMessage()); - e.printStackTrace(); } finally { try { - if(ps!=null) { + if (ps != null) { ps.close(); } } catch (SQLException e) { - e.printStackTrace(); + intlogger.error("SQLException " + e.getMessage()); } } return rv; @@ -376,14 +376,13 @@ public class Group extends Syncable { } catch (SQLException e) { rv = false; intlogger.warn("PROV0006 doUpdate: " + e.getMessage()); - e.printStackTrace(); } finally { try { - if(ps!=null) { + if (ps != null) { ps.close(); } } catch (SQLException e) { - e.printStackTrace(); + intlogger.error("SQLException " + e.getMessage()); } } return rv; @@ -401,14 +400,13 @@ public class Group extends Syncable { } catch (SQLException e) { rv = false; intlogger.warn("PROV0007 doDelete: " + e.getMessage()); - e.printStackTrace(); } finally { try { - if(ps!=null) { + if (ps != null) { ps.close(); } } catch (SQLException e) { - e.printStackTrace(); + intlogger.error("SQLException " + e.getMessage()); } } return rv; @@ -421,21 +419,28 @@ public class Group extends Syncable { @Override public boolean equals(Object obj) { - if (!(obj instanceof Group)) + if (!(obj instanceof Group)) { return false; + } Group os = (Group) obj; - if (groupid != os.groupid) + if (groupid != os.groupid) { return false; - if (authid != os.authid) + } + if (authid != os.authid) { return false; - if (!name.equals(os.name)) + } + if (!name.equals(os.name)) { return false; - if (description != os.description) + } + if (description != os.description) { return false; - if (!classification.equals(os.classification)) + } + if (!classification.equals(os.classification)) { return false; - if (!members.equals(os.members)) + } + if (!members.equals(os.members)) { return false; + } return true; }