import org.json.JSONArray;\r
import org.json.JSONException;\r
import org.json.JSONObject;\r
-import org.onap.dmaap.datarouter.provisioning.utils.DB;\r
import org.onap.dmaap.datarouter.provisioning.utils.JSONUtilities;\r
+import org.onap.dmaap.datarouter.provisioning.utils.ProvDbUtils;\r
import org.onap.dmaap.datarouter.provisioning.utils.URLUtilities;\r
\r
\r
\r
private static EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");\r
private static int nextFeedID = getMaxFeedID() + 1;\r
- private static final String SQLEXCEPTION = "SQLException: ";\r
private static final String FEED_ID_SQL = "FEEDID";\r
private static final String FEED_ID = "feedid";\r
private static final String DEL = "deleted";\r
if (fid.getId().length() > 60) {\r
throw new InvalidObjectException("id field is too long (" + fid.getId() + ")");\r
}\r
- if (fid.getPassword().length() > 32) {\r
+ if (fid.getPassword().length() > 100) {\r
//Fortify scan fixes - Privacy Violation\r
throw new InvalidObjectException("password field is too long (" + fid.getPassword() + ")");\r
}\r
* @return true if it is valid\r
*/\r
@SuppressWarnings("resource")\r
- public static boolean isFeedValid(int id) {\r
+ static boolean isFeedValid(int id) {\r
int count = 0;\r
- try {\r
- DB db = new DB();\r
- Connection conn = db.getConnection();\r
- try (PreparedStatement stmt = conn.prepareStatement("select COUNT(*) from FEEDS where FEEDID = ?")) {\r
- stmt.setInt(1, id);\r
- try (ResultSet rs = stmt.executeQuery()) {\r
- if (rs.next()) {\r
- count = rs.getInt(1);\r
- }\r
+ try (Connection conn = ProvDbUtils.getInstance().getConnection();\r
+ PreparedStatement ps = conn.prepareStatement(\r
+ "select COUNT(*) from FEEDS where FEEDID = ?")) {\r
+ ps.setInt(1, id);\r
+ try (ResultSet rs = ps.executeQuery()) {\r
+ if (rs.next()) {\r
+ count = rs.getInt(1);\r
}\r
}\r
- db.release(conn);\r
} catch (SQLException e) {\r
intlogger.warn("PROV0024 Feed.isFeedValid: " + e.getMessage(), e);\r
}\r
*/\r
public static int countActiveFeeds() {\r
int count = 0;\r
- try {\r
- DB db = new DB();\r
- @SuppressWarnings("resource") Connection conn = db.getConnection();\r
- try (Statement stmt = conn.createStatement()) {\r
- try (ResultSet rs = stmt.executeQuery("select count(*) from FEEDS where DELETED = 0")) {\r
- if (rs.next()) {\r
- count = rs.getInt(1);\r
- }\r
+ try (Connection conn = ProvDbUtils.getInstance().getConnection();\r
+ PreparedStatement ps = conn.prepareStatement(\r
+ "select count(*) from FEEDS where DELETED = 0")) {\r
+ try (ResultSet rs = ps.executeQuery()) {\r
+ if (rs.next()) {\r
+ count = rs.getInt(1);\r
}\r
}\r
- db.release(conn);\r
} catch (SQLException e) {\r
intlogger.warn("PROV0025 Feed.countActiveFeeds: " + e.getMessage(), e);\r
}\r
*/\r
public static int getMaxFeedID() {\r
int max = 0;\r
- try {\r
- DB db = new DB();\r
- @SuppressWarnings("resource")\r
- Connection conn = db.getConnection();\r
- try (Statement stmt = conn.createStatement()) {\r
- try (ResultSet rs = stmt.executeQuery("select MAX(feedid) from FEEDS")) {\r
- if (rs.next()) {\r
- max = rs.getInt(1);\r
- }\r
+ try (Connection conn = ProvDbUtils.getInstance().getConnection();\r
+ PreparedStatement ps = conn.prepareStatement(\r
+ "select MAX(feedid) from FEEDS")) {\r
+ try (ResultSet rs = ps.executeQuery()) {\r
+ if (rs.next()) {\r
+ max = rs.getInt(1);\r
}\r
}\r
- db.release(conn);\r
} catch (SQLException e) {\r
intlogger.warn("PROV0026 Feed.getMaxFeedID: " + e.getMessage(), e);\r
}\r
*/\r
public static Collection<Feed> getAllFeeds() {\r
Map<Integer, Feed> map = new HashMap<>();\r
- try {\r
- DB db = new DB();\r
- @SuppressWarnings("resource")\r
- Connection conn = db.getConnection();\r
- try (Statement stmt = conn.createStatement()) {\r
- try (ResultSet rs = stmt.executeQuery("select * from FEEDS")) {\r
- while (rs.next()) {\r
- Feed feed = new Feed(rs);\r
- map.put(feed.getFeedid(), feed);\r
- }\r
+ try (Connection conn = ProvDbUtils.getInstance().getConnection()) {\r
+ try (PreparedStatement ps = conn.prepareStatement("select * from FEEDS");\r
+ ResultSet rs = ps.executeQuery()) {\r
+ while (rs.next()) {\r
+ Feed feed = new Feed(rs);\r
+ map.put(feed.getFeedid(), feed);\r
}\r
-\r
- String sql = "select * from FEED_ENDPOINT_IDS";\r
- try (ResultSet rs = stmt.executeQuery(sql)) {\r
- while (rs.next()) {\r
- int id = rs.getInt(FEED_ID_SQL);\r
- Feed feed = map.get(id);\r
- if (feed != null) {\r
- FeedEndpointID epi = new FeedEndpointID(rs);\r
- Collection<FeedEndpointID> ecoll = feed.getAuthorization().getEndpointIDS();\r
- ecoll.add(epi);\r
- }\r
+ }\r
+ try (PreparedStatement ps = conn.prepareStatement("select * from FEED_ENDPOINT_IDS");\r
+ ResultSet rs = ps.executeQuery()) {\r
+ while (rs.next()) {\r
+ int id = rs.getInt(FEED_ID_SQL);\r
+ Feed feed = map.get(id);\r
+ if (feed != null) {\r
+ FeedEndpointID epi = new FeedEndpointID(rs);\r
+ Collection<FeedEndpointID> ecoll = feed.getAuthorization().getEndpointIDS();\r
+ ecoll.add(epi);\r
}\r
}\r
-\r
- sql = "select * from FEED_ENDPOINT_ADDRS";\r
- try (ResultSet rs = stmt.executeQuery(sql)) {\r
- while (rs.next()) {\r
- int id = rs.getInt(FEED_ID_SQL);\r
- Feed feed = map.get(id);\r
- if (feed != null) {\r
- Collection<String> acoll = feed.getAuthorization().getEndpointAddrs();\r
- acoll.add(rs.getString("ADDR"));\r
- }\r
+ }\r
+ try (PreparedStatement ps = conn.prepareStatement("select * from FEED_ENDPOINT_ADDRS");\r
+ ResultSet rs = ps.executeQuery()) {\r
+ while (rs.next()) {\r
+ int id = rs.getInt(FEED_ID_SQL);\r
+ Feed feed = map.get(id);\r
+ if (feed != null) {\r
+ Collection<String> acoll = feed.getAuthorization().getEndpointAddrs();\r
+ acoll.add(rs.getString("ADDR"));\r
}\r
}\r
}\r
- db.release(conn);\r
} catch (SQLException e) {\r
intlogger.warn("PROV0027 Feed.getAllFeeds: " + e.getMessage(), e);\r
}\r
sql += " and PUBLISHER = ?";\r
} else if (name.equals("subs")) {\r
sql = "select distinct FEEDS.SELF_LINK from FEEDS, SUBSCRIPTIONS "\r
- + "where DELETED = 0 "\r
- + "and FEEDS.FEEDID = SUBSCRIPTIONS.FEEDID "\r
- + "and SUBSCRIPTIONS.SUBSCRIBER = ?";\r
+ + "where DELETED = 0 "\r
+ + "and FEEDS.FEEDID = SUBSCRIPTIONS.FEEDID "\r
+ + "and SUBSCRIPTIONS.SUBSCRIBER = ?";\r
}\r
- try {\r
- DB db = new DB();\r
- @SuppressWarnings("resource")\r
- Connection conn = db.getConnection();\r
- try (PreparedStatement ps = conn.prepareStatement(sql)) {\r
- if (sql.indexOf('?') >= 0) {\r
- ps.setString(1, val);\r
- }\r
- try (ResultSet rs = ps.executeQuery()) {\r
- while (rs.next()) {\r
- String str = rs.getString(1);\r
- list.add(str.trim());\r
- }\r
+ try (Connection conn = ProvDbUtils.getInstance().getConnection();\r
+ PreparedStatement ps = conn.prepareStatement(sql)) {\r
+ if (sql.indexOf('?') >= 0) {\r
+ ps.setString(1, val);\r
+ }\r
+ try (ResultSet rs = ps.executeQuery()) {\r
+ while (rs.next()) {\r
+ String str = rs.getString(1);\r
+ list.add(str.trim());\r
}\r
}\r
- db.release(conn);\r
} catch (SQLException e) {\r
intlogger.warn("PROV0028 Feed.getFilteredFeedUrlList: " + e.getMessage(), e);\r
}\r
@SuppressWarnings("resource")\r
private static Feed getFeedBySQL(String sql) {\r
Feed feed = null;\r
- try {\r
- DB db = new DB();\r
- Connection conn = db.getConnection();\r
+ try (Connection conn = ProvDbUtils.getInstance().getConnection()) {\r
try (Statement stmt = conn.createStatement()) {\r
try (ResultSet rs = stmt.executeQuery(sql)) {\r
if (rs.next()) {\r
}\r
}\r
}\r
- db.release(conn);\r
} catch (SQLException e) {\r
intlogger.warn("PROV0029 Feed.getFeedBySQL: " + e.getMessage(), e);\r
}\r
\r
/**\r
* Set feedid with FeedLinks.\r
- * @param feedid Feedid to set to\r
+ * @param feedid Feedid to set to\r
*/\r
public void setFeedid(int feedid) {\r
this.feedid = feedid;\r
return aafInstance;\r
}\r
\r
- public void setAafInstance(String aafInstance) {\r
- this.aafInstance = aafInstance;\r
- }\r
-\r
//new getter setters for groups- Rally:US708115 - 1610\r
public int getGroupid() {\r
return groupid;\r
}\r
\r
// New field is added - Groups feature Rally:US708102 - 1610\r
- public String getBusinessDescription() {\r
+ String getBusinessDescription() {\r
return businessDescription;\r
}\r
\r
- public void setBusinessDescription(String businessDescription) {\r
+ void setBusinessDescription(String businessDescription) {\r
this.businessDescription = businessDescription;\r
}\r
\r
return links;\r
}\r
\r
- public void setLinks(FeedLinks links) {\r
+ void setLinks(FeedLinks links) {\r
this.links = links;\r
}\r
\r
this.deleted = deleted;\r
}\r
\r
- public boolean isSuspended() {\r
+ boolean isSuspended() {\r
return suspended;\r
}\r
\r
- public void setSuspended(boolean suspended) {\r
+ void setSuspended(boolean suspended) {\r
this.suspended = suspended;\r
}\r
\r
@Override\r
public boolean doDelete(Connection conn) {\r
boolean rv = true;\r
- PreparedStatement ps = null;\r
- try {\r
- String sql = "delete from FEEDS where FEEDID = ?";\r
- ps = conn.prepareStatement(sql);\r
+ try (PreparedStatement ps = conn.prepareStatement("delete from FEEDS where FEEDID = ?")) {\r
ps.setInt(1, feedid);\r
ps.execute();\r
} catch (SQLException e) {\r
rv = false;\r
intlogger.error("PROV0007 doDelete: " + e.getMessage(), e);\r
- } finally {\r
- try {\r
- if (ps != null) {\r
- ps.close();\r
- }\r
- } catch (SQLException e) {\r
- intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
- }\r
}\r
return rv;\r
}\r
if (feedid > nextFeedID) {\r
nextFeedID = feedid + 1;\r
}\r
-\r
// Create FEED_ENDPOINT_IDS rows\r
FeedAuthorization auth = getAuthorization();\r
- String sql = "insert into FEED_ENDPOINT_IDS values (?, ?, ?)";\r
- try (PreparedStatement ps2 = conn.prepareStatement(sql)) {\r
+ try (PreparedStatement ps = conn.prepareStatement("insert into FEED_ENDPOINT_IDS values (?, ?, ?)")) {\r
for (FeedEndpointID fid : auth.getEndpointIDS()) {\r
- ps2.setInt(1, feedid);\r
- ps2.setString(2, fid.getId());\r
- ps2.setString(3, fid.getPassword());\r
- ps2.executeUpdate();\r
+ ps.setInt(1, feedid);\r
+ ps.setString(2, fid.getId());\r
+ ps.setString(3, fid.getPassword());\r
+ ps.executeUpdate();\r
}\r
}\r
-\r
// Create FEED_ENDPOINT_ADDRS rows\r
- sql = "insert into FEED_ENDPOINT_ADDRS values (?, ?)";\r
- try (PreparedStatement ps2 = conn.prepareStatement(sql)) {\r
+ try (PreparedStatement ps = conn.prepareStatement("insert into FEED_ENDPOINT_ADDRS values (?, ?)")) {\r
for (String t : auth.getEndpointAddrs()) {\r
- ps2.setInt(1, feedid);\r
- ps2.setString(2, t);\r
- ps2.executeUpdate();\r
+ ps.setInt(1, feedid);\r
+ ps.setString(2, t);\r
+ ps.executeUpdate();\r
}\r
}\r
-\r
// Finally, create the FEEDS row\r
- sql = "insert into FEEDS (FEEDID, NAME, VERSION, DESCRIPTION, AUTH_CLASS, PUBLISHER, SELF_LINK, "\r
- + "PUBLISH_LINK, SUBSCRIBE_LINK, LOG_LINK, DELETED, SUSPENDED,"\r
- + "BUSINESS_DESCRIPTION, GROUPID, AAF_INSTANCE) "\r
- + "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";\r
- try (PreparedStatement ps2 = conn.prepareStatement(sql)) {\r
- ps2.setInt(1, feedid);\r
- ps2.setString(2, getName());\r
- ps2.setString(3, getVersion());\r
- ps2.setString(4, getDescription());\r
- ps2.setString(5, getAuthorization().getClassification());\r
- ps2.setString(6, getPublisher());\r
- ps2.setString(7, getLinks().getSelf());\r
- ps2.setString(8, getLinks().getPublish());\r
- ps2.setString(9, getLinks().getSubscribe());\r
- ps2.setString(10, getLinks().getLog());\r
- ps2.setBoolean(11, isDeleted());\r
- ps2.setBoolean(12, isSuspended());\r
- ps2.setString(13, getBusinessDescription());\r
- ps2.setInt(14, groupid);\r
- ps2.setString(15, getAafInstance());\r
- ps2.executeUpdate();\r
+ try (PreparedStatement ps = conn.prepareStatement(\r
+ "insert into FEEDS (FEEDID, NAME, VERSION, DESCRIPTION, AUTH_CLASS, PUBLISHER, SELF_LINK, "\r
+ + "PUBLISH_LINK, SUBSCRIBE_LINK, LOG_LINK, DELETED, SUSPENDED,"\r
+ + "BUSINESS_DESCRIPTION, GROUPID, AAF_INSTANCE) "\r
+ + "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) {\r
+ ps.setInt(1, feedid);\r
+ ps.setString(2, getName());\r
+ ps.setString(3, getVersion());\r
+ ps.setString(4, getDescription());\r
+ ps.setString(5, getAuthorization().getClassification());\r
+ ps.setString(6, getPublisher());\r
+ ps.setString(7, getLinks().getSelf());\r
+ ps.setString(8, getLinks().getPublish());\r
+ ps.setString(9, getLinks().getSubscribe());\r
+ ps.setString(10, getLinks().getLog());\r
+ ps.setBoolean(11, isDeleted());\r
+ ps.setBoolean(12, isSuspended());\r
+ ps.setString(13, getBusinessDescription());\r
+ ps.setInt(14, groupid);\r
+ ps.setString(15, getAafInstance());\r
+ ps.executeUpdate();\r
}\r
} catch (SQLException e) {\r
rv = false;\r
@Override\r
public boolean doUpdate(Connection conn) {\r
boolean rv = true;\r
- Feed oldobj = getFeedById(feedid);\r
- PreparedStatement ps = null;\r
try {\r
+ Feed oldobj = getFeedById(feedid);\r
Set<FeedEndpointID> newset = getAuthorization().getEndpointIDS();\r
Set<FeedEndpointID> oldset = oldobj.getAuthorization().getEndpointIDS();\r
-\r
- // Insert new FEED_ENDPOINT_IDS rows\r
- String sql = "insert into FEED_ENDPOINT_IDS values (?, ?, ?)";\r
- ps = conn.prepareStatement(sql);\r
- for (FeedEndpointID fid : newset) {\r
- if (!oldset.contains(fid)) {\r
- ps.setInt(1, feedid);\r
- ps.setString(2, fid.getId());\r
- ps.setString(3, fid.getPassword());\r
- ps.executeUpdate();\r
+ try (PreparedStatement ps = conn.prepareStatement("insert into FEED_ENDPOINT_IDS values (?, ?, ?)")) {\r
+ // Insert new FEED_ENDPOINT_IDS rows\r
+ for (FeedEndpointID fid : newset) {\r
+ if (!oldset.contains(fid)) {\r
+ ps.setInt(1, feedid);\r
+ ps.setString(2, fid.getId());\r
+ ps.setString(3, fid.getPassword());\r
+ ps.executeUpdate();\r
+ }\r
}\r
}\r
- ps.close();\r
-\r
// Delete old FEED_ENDPOINT_IDS rows\r
- sql = "delete from FEED_ENDPOINT_IDS where FEEDID = ? AND USERID = ? AND PASSWORD = ?";\r
- ps = conn.prepareStatement(sql);\r
- for (FeedEndpointID fid : oldset) {\r
- if (!newset.contains(fid)) {\r
- ps.setInt(1, feedid);\r
- ps.setString(2, fid.getId());\r
- ps.setString(3, fid.getPassword());\r
- ps.executeUpdate();\r
+ try (PreparedStatement ps = conn.prepareStatement(\r
+ "delete from FEED_ENDPOINT_IDS where FEEDID = ? AND USERID = ? AND PASSWORD = ?")) {\r
+ for (FeedEndpointID fid : oldset) {\r
+ if (!newset.contains(fid)) {\r
+ ps.setInt(1, feedid);\r
+ ps.setString(2, fid.getId());\r
+ ps.setString(3, fid.getPassword());\r
+ ps.executeUpdate();\r
+ }\r
}\r
}\r
- ps.close();\r
-\r
- // Insert new FEED_ENDPOINT_ADDRS rows\r
Set<String> newset2 = getAuthorization().getEndpointAddrs();\r
Set<String> oldset2 = oldobj.getAuthorization().getEndpointAddrs();\r
- sql = "insert into FEED_ENDPOINT_ADDRS values (?, ?)";\r
- ps = conn.prepareStatement(sql);\r
- for (String t : newset2) {\r
- if (!oldset2.contains(t)) {\r
- ps.setInt(1, feedid);\r
- ps.setString(2, t);\r
- ps.executeUpdate();\r
+ // Insert new FEED_ENDPOINT_ADDRS rows\r
+ try (PreparedStatement ps = conn.prepareStatement("insert into FEED_ENDPOINT_ADDRS values (?, ?)")) {\r
+ for (String t : newset2) {\r
+ if (!oldset2.contains(t)) {\r
+ ps.setInt(1, feedid);\r
+ ps.setString(2, t);\r
+ ps.executeUpdate();\r
+ }\r
}\r
}\r
- ps.close();\r
-\r
// Delete old FEED_ENDPOINT_ADDRS rows\r
- sql = "delete from FEED_ENDPOINT_ADDRS where FEEDID = ? AND ADDR = ?";\r
- ps = conn.prepareStatement(sql);\r
- for (String t : oldset2) {\r
- if (!newset2.contains(t)) {\r
- ps.setInt(1, feedid);\r
- ps.setString(2, t);\r
- ps.executeUpdate();\r
+ try (PreparedStatement ps = conn.prepareStatement(\r
+ "delete from FEED_ENDPOINT_ADDRS where FEEDID = ? AND ADDR = ?")) {\r
+ for (String t : oldset2) {\r
+ if (!newset2.contains(t)) {\r
+ ps.setInt(1, feedid);\r
+ ps.setString(2, t);\r
+ ps.executeUpdate();\r
+ }\r
}\r
}\r
- ps.close();\r
-\r
- // Finally, update the FEEDS row\r
- sql = "update FEEDS set DESCRIPTION = ?, AUTH_CLASS = ?, DELETED = ?, SUSPENDED = ?, "\r
- + "BUSINESS_DESCRIPTION=?, GROUPID=? where FEEDID = ?";\r
- ps = conn.prepareStatement(sql);\r
- ps.setString(1, getDescription());\r
- ps.setString(2, getAuthorization().getClassification());\r
- ps.setInt(3, deleted ? 1 : 0);\r
- ps.setInt(4, suspended ? 1 : 0);\r
- ps.setString(5, getBusinessDescription());\r
- ps.setInt(6, groupid);\r
- ps.setInt(7, feedid);\r
- ps.executeUpdate();\r
- ps.close();\r
+ try (PreparedStatement ps = conn.prepareStatement(\r
+ "update FEEDS set DESCRIPTION = ?, AUTH_CLASS = ?, DELETED = ?, SUSPENDED = ?, "\r
+ + "BUSINESS_DESCRIPTION=?, GROUPID=? where FEEDID = ?")) {\r
+ // Finally, update the FEEDS row\r
+ ps.setString(1, getDescription());\r
+ ps.setString(2, getAuthorization().getClassification());\r
+ ps.setInt(3, deleted ? 1 : 0);\r
+ ps.setInt(4, suspended ? 1 : 0);\r
+ ps.setString(5, getBusinessDescription());\r
+ ps.setInt(6, groupid);\r
+ ps.setInt(7, feedid);\r
+ ps.executeUpdate();\r
+ }\r
} catch (SQLException e) {\r
rv = false;\r
intlogger.warn("PROV0006 doUpdate: " + e.getMessage(), e);\r
- } finally {\r
- try {\r
- if (ps != null) {\r
- ps.close();\r
- }\r
- } catch (SQLException e) {\r
- intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
- }\r
}\r
return rv;\r
}\r
*/\r
public boolean changeOwnerShip() {\r
boolean rv = true;\r
- PreparedStatement ps = null;\r
- try {\r
-\r
- DB db = new DB();\r
- @SuppressWarnings("resource")\r
- Connection conn = db.getConnection();\r
- String sql = "update FEEDS set PUBLISHER = ? where FEEDID = ?";\r
- ps = conn.prepareStatement(sql);\r
+ try (Connection conn = ProvDbUtils.getInstance().getConnection();\r
+ PreparedStatement ps = conn.prepareStatement(\r
+ "update FEEDS set PUBLISHER = ? where FEEDID = ?")) {\r
ps.setString(1, this.publisher);\r
ps.setInt(2, feedid);\r
ps.execute();\r
- ps.close();\r
} catch (SQLException e) {\r
rv = false;\r
intlogger.warn("PROV0008 changeOwnerShip: " + e.getMessage(), e);\r
- } finally {\r
- try {\r
- if (ps != null) {\r
- ps.close();\r
- }\r
- } catch (SQLException e) {\r
- intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
- }\r
}\r
return rv;\r
}\r