X-Git-Url: https://gerrit.onap.org/r/gitweb?p=dmaap%2Fdatarouter.git;a=blobdiff_plain;f=datarouter-prov%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdatarouter%2Fprovisioning%2Fbeans%2FGroup.java;h=da682d7411ef35dde60ec20d11f17cb95cf89fb9;hp=35363094d04be029d77e1f1e3328eb81bf264977;hb=534c164c124950a2019acf71d253ac96be12c78c;hpb=58f50f8f96d673513c40af8c6ff115a4424e66a2 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 35363094..da682d74 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 @@ -31,10 +31,10 @@ import java.sql.SQLException; import java.sql.Statement; import java.util.*; -import org.apache.log4j.Logger; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import org.json.JSONObject; import org.onap.dmaap.datarouter.provisioning.utils.DB; -import org.onap.dmaap.datarouter.provisioning.utils.URLUtilities; /** * The representation of a Subscription. Subscriptions can be retrieved from the DB, or stored/updated in the DB. @@ -43,8 +43,10 @@ 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 EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog"); private static int next_groupid = getMaxGroupID() + 1; + private static final String SQLEXCEPTION = "SQLException: "; private int groupid; private String authid; @@ -96,8 +98,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 +108,7 @@ public class Group extends Syncable { } db.release(conn); } catch (SQLException e) { - intlogger.error("SQLException " + e.getMessage()); + intlogger.error("PROV0009 getGroupsForSQL: " + e.getMessage(), e); } return list; } @@ -117,8 +119,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); } @@ -126,61 +128,11 @@ public class Group extends Syncable { } db.release(conn); } catch (SQLException e) { - intlogger.info("getMaxSubID: " + e.getMessage()); - intlogger.error("SQLException " + e.getMessage()); + intlogger.info("PROV0001 getMaxSubID: " + e.getMessage(), e); } return max; } - public static Collection getGroupsByClassfication(String classfication) { - List list = new ArrayList<>(); - String sql = "select * from GROUPS where classification = ?"; - try { - DB db = new DB(); - @SuppressWarnings("resource") - Connection conn = db.getConnection(); - try(PreparedStatement stmt = conn.prepareStatement(sql)) { - stmt.setString(1, classfication); - try(ResultSet rs = stmt.executeQuery()) { - while (rs.next()) { - int groupid = rs.getInt("groupid"); - - } - } - } - db.release(conn); - } catch (SQLException e) { - intlogger.error("SQLException " + e.getMessage()); - } - return list; - } - - /** - * Return a count of the number of active subscriptions in the DB. - * - * @return the count - */ - public static int countActiveSubscriptions() { - int count = 0; - try { - DB db = new DB(); - @SuppressWarnings("resource") - Connection conn = db.getConnection(); - try(Statement stmt = conn.createStatement()) { - try(ResultSet rs = stmt.executeQuery("select count(*) from SUBSCRIPTIONS")) { - if (rs.next()) { - count = rs.getInt(1); - } - } - } - db.release(conn); - } catch (SQLException e) { - intlogger.warn("PROV0008 countActiveSubscriptions: " + e.getMessage()); - intlogger.error("SQLException " + e.getMessage()); - } - return count; - } - public Group() { this("", "", ""); } @@ -210,7 +162,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,14 +173,17 @@ 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) { - throw new InvalidObjectException("invalid JSON: " + e.getMessage()); + intlogger.warn("Invalid JSON: " + e.getMessage(), e); + throw new InvalidObjectException("Invalid JSON: " + e.getMessage()); } } @@ -236,7 +191,7 @@ public class Group extends Syncable { return groupid; } - public static Logger getIntlogger() { + public static EELFLogger getIntlogger() { return intlogger; } @@ -244,18 +199,10 @@ public class Group extends Syncable { this.groupid = groupid; } - public static void setIntlogger(Logger intlogger) { + public static void setIntlogger(EELFLogger intlogger) { Group.intlogger = intlogger; } - public static int getNext_groupid() { - return next_groupid; - } - - public static void setNext_groupid(int next_groupid) { - Group.next_groupid = next_groupid; - } - public String getAuthid() { return authid; } @@ -292,19 +239,6 @@ public class Group extends Syncable { return members; } - public void setMembers(String members) { - this.members = members; - } - - public Date getLast_mod() { - return last_mod; - } - - public void setLast_mod(Date last_mod) { - this.last_mod = last_mod; - } - - @Override public JSONObject asJSONObject() { JSONObject jo = new JSONObject(); @@ -328,9 +262,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 (?, ?, ?, ?, ?, ?)"; @@ -345,15 +279,14 @@ public class Group extends Syncable { ps.close(); } catch (SQLException e) { rv = false; - intlogger.warn("PROV0005 doInsert: " + e.getMessage()); - intlogger.error("SQLException " + e.getMessage()); + intlogger.warn("PROV0005 doInsert: " + e.getMessage(), e); } finally { try { - if(ps!=null) { + if (ps != null) { ps.close(); } } catch (SQLException e) { - intlogger.error("SQLException " + e.getMessage()); + intlogger.error(SQLEXCEPTION + e.getMessage(), e); } } return rv; @@ -375,15 +308,14 @@ public class Group extends Syncable { ps.executeUpdate(); } catch (SQLException e) { rv = false; - intlogger.warn("PROV0006 doUpdate: " + e.getMessage()); - intlogger.error("SQLException " + e.getMessage()); + intlogger.warn("PROV0006 doUpdate: " + e.getMessage(), e); } finally { try { - if(ps!=null) { + if (ps != null) { ps.close(); } } catch (SQLException e) { - intlogger.error("SQLException " + e.getMessage()); + intlogger.error(SQLEXCEPTION + e.getMessage(), e); } } return rv; @@ -400,15 +332,14 @@ public class Group extends Syncable { ps.execute(); } catch (SQLException e) { rv = false; - intlogger.warn("PROV0007 doDelete: " + e.getMessage()); - intlogger.error("SQLException " + e.getMessage()); + intlogger.warn("PROV0007 doDelete: " + e.getMessage(), e); } finally { try { - if(ps!=null) { + if (ps != null) { ps.close(); } } catch (SQLException e) { - intlogger.error("SQLException " + e.getMessage()); + intlogger.error(SQLEXCEPTION + e.getMessage(), e); } } return rv; @@ -421,21 +352,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; }