- private static Logger intlogger = Logger.getLogger("org.onap.dmaap.datarouter.provisioning.internal");\r
- private static int next_feedid = getMaxFeedID() + 1;\r
-\r
- private int feedid;\r
- private int groupid; //New field is added - Groups feature Rally:US708115 - 1610\r
- private String name;\r
- private String version;\r
- private String description;\r
- private String business_description; // New field is added - Groups feature Rally:US708102 - 1610\r
- private FeedAuthorization authorization;\r
- private String publisher;\r
- private FeedLinks links;\r
- private boolean deleted;\r
- private boolean suspended;\r
- private Date last_mod;\r
- private Date created_date;\r
-\r
- /**\r
- * Check if a feed ID is valid.\r
- * @param id the Feed ID\r
- * @return true if it is valid\r
- */\r
- @SuppressWarnings("resource")\r
- public static boolean isFeedValid(int id) {\r
- int count = 0;\r
- try {\r
- DB db = new DB();\r
- Connection conn = db.getConnection();\r
- Statement stmt = conn.createStatement();\r
- ResultSet rs = stmt.executeQuery("select COUNT(*) from FEEDS where FEEDID = " + id);\r
- if (rs.next()) {\r
- count = rs.getInt(1);\r
- }\r
- rs.close();\r
- stmt.close();\r
- db.release(conn);\r
- } catch (SQLException e) {\r
- e.printStackTrace();\r
- }\r
- return count != 0;\r
- }\r
- /**\r
- * Get a specific feed from the DB, based upon its ID.\r
- * @param id the Feed ID\r
- * @return the Feed object, or null if it does not exist\r
- */\r
- public static Feed getFeedById(int id) {\r
- String sql = "select * from FEEDS where FEEDID = " + id;\r
- return getFeedBySQL(sql);\r
- }\r
- /**\r
- * Get a specific feed from the DB, based upon its name and version.\r
- * @param name the name of the Feed\r
- * @param version the version of the Feed\r
- * @return the Feed object, or null if it does not exist\r
- */\r
- public static Feed getFeedByNameVersion(String name, String version) {\r
- name = name.replaceAll("'", "''");\r
- version = version.replaceAll("'", "''");\r
- String sql = "select * from FEEDS where NAME = '" + name + "' and VERSION ='" + version + "'";\r
- return getFeedBySQL(sql);\r
- }\r
- /**\r
- * Return a count of the number of active feeds in the DB.\r
- * @return the count\r
- */\r
- public static int countActiveFeeds() {\r
- int count = 0;\r
- try {\r
- DB db = new DB();\r
- @SuppressWarnings("resource")\r
- Connection conn = db.getConnection();\r
- Statement stmt = conn.createStatement();\r
- ResultSet rs = stmt.executeQuery("select count(*) from FEEDS where DELETED = 0");\r
- if (rs.next()) {\r
- count = rs.getInt(1);\r
- }\r
- rs.close();\r
- stmt.close();\r
- db.release(conn);\r
- } catch (SQLException e) {\r
- intlogger.info("countActiveFeeds: "+e.getMessage());\r
- e.printStackTrace();\r
- }\r
- return count;\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
- Statement stmt = conn.createStatement();\r
- ResultSet rs = stmt.executeQuery("select MAX(feedid) from FEEDS");\r
- if (rs.next()) {\r
- max = rs.getInt(1);\r
- }\r
- rs.close();\r
- stmt.close();\r
- db.release(conn);\r
- } catch (SQLException e) {\r
- intlogger.info("getMaxFeedID: "+e.getMessage());\r
- e.printStackTrace();\r
- }\r
- return max;\r
- }\r
- public static Collection<Feed> getAllFeeds() {\r
- Map<Integer, Feed> map = new HashMap<Integer, Feed>();\r
- try {\r
- DB db = new DB();\r
- @SuppressWarnings("resource")\r
- Connection conn = db.getConnection();\r
- Statement stmt = conn.createStatement();\r
- 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
- rs.close();\r
-\r
- String sql = "select * from FEED_ENDPOINT_IDS";\r
- rs = stmt.executeQuery(sql);\r
- while (rs.next()) {\r
- int id = rs.getInt("FEEDID");\r
- Feed feed = map.get(id);\r
- if (feed != null) {\r
- FeedEndpointID epi = new FeedEndpointID(rs);\r
- Collection<FeedEndpointID> ecoll = feed.getAuthorization().getEndpoint_ids();\r
- ecoll.add(epi);\r
- }\r
- }\r
- rs.close();\r
-\r
- sql = "select * from FEED_ENDPOINT_ADDRS";\r
- rs = stmt.executeQuery(sql);\r
- while (rs.next()) {\r
- int id = rs.getInt("FEEDID");\r
- Feed feed = map.get(id);\r
- if (feed != null) {\r
- Collection<String> acoll = feed.getAuthorization().getEndpoint_addrs();\r
- acoll.add(rs.getString("ADDR"));\r
- }\r
- }\r
- rs.close();\r
-\r
- stmt.close();\r
- db.release(conn);\r
- } catch (SQLException e) {\r
- e.printStackTrace();\r
- }\r
- return map.values();\r
- }\r
- public static List<String> getFilteredFeedUrlList(final String name, final String val) {\r
- List<String> list = new ArrayList<String>();\r
- String sql = "select SELF_LINK from FEEDS where DELETED = 0";\r
- if (name.equals("name")) {\r
- sql += " and NAME = ?";\r
- } else if (name.equals("publ")) {\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
- }\r
- try {\r
- DB db = new DB();\r
- @SuppressWarnings("resource")\r
- Connection conn = db.getConnection();\r
- PreparedStatement ps = conn.prepareStatement(sql);\r
- if (sql.indexOf('?') >= 0)\r
- ps.setString(1, val);\r
- ResultSet rs = ps.executeQuery();\r
- while (rs.next()) {\r
- String t = rs.getString(1);\r
- list.add(t.trim());\r
- }\r
- rs.close();\r
- ps.close();\r
- db.release(conn);\r
- } catch (SQLException e) {\r
- e.printStackTrace();\r
- }\r
- return list;\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
- Statement stmt = conn.createStatement();\r
- ResultSet rs = stmt.executeQuery(sql);\r
- if (rs.next()) {\r
- feed = new Feed(rs);\r
- rs.close();\r
-\r
- sql = "select * from FEED_ENDPOINT_IDS where FEEDID = " + feed.feedid;\r
- rs = stmt.executeQuery(sql);\r
- Collection<FeedEndpointID> ecoll = feed.getAuthorization().getEndpoint_ids();\r
- while (rs.next()) {\r
- FeedEndpointID epi = new FeedEndpointID(rs);\r
- ecoll.add(epi);\r
- }\r
- rs.close();\r
-\r
- sql = "select * from FEED_ENDPOINT_ADDRS where FEEDID = " + feed.feedid;\r
- rs = stmt.executeQuery(sql);\r
- Collection<String> acoll = feed.getAuthorization().getEndpoint_addrs();\r
- while (rs.next()) {\r
- acoll.add(rs.getString("ADDR"));\r
- }\r
- }\r
- rs.close();\r
- stmt.close();\r
- db.release(conn);\r
- } catch (SQLException e) {\r
- e.printStackTrace();\r
- }\r
- return feed;\r
- }\r
-\r
- public Feed() {\r
- this("", "", "","");\r
- }\r
-\r
- public Feed(String name, String version, String desc,String business_description) {\r
- this.feedid = -1;\r
- this.groupid = -1; //New field is added - Groups feature Rally:US708115 - 1610\r
- this.name = name;\r
- this.version = version;\r
- this.description = desc;\r
- this.business_description=business_description; // New field is added - Groups feature Rally:US708102 - 1610\r
- this.authorization = new FeedAuthorization();\r
- this.publisher = "";\r
- this.links = new FeedLinks();\r
- this.deleted = false;\r
- this.suspended = false;\r
- this.last_mod = new Date();\r
- this.created_date = new Date();\r
- }\r
- public Feed(ResultSet rs) throws SQLException {\r
- this.feedid = rs.getInt("FEEDID");\r
- this.groupid = rs.getInt("GROUPID"); //New field is added - Groups feature Rally:US708115 - 1610\r
- this.name = rs.getString("NAME");\r
- this.version = rs.getString("VERSION");\r
- this.description = rs.getString("DESCRIPTION");\r
- this.business_description=rs.getString("BUSINESS_DESCRIPTION"); // New field is added - Groups feature Rally:US708102 - 1610\r
- this.authorization = new FeedAuthorization();\r
- this.authorization.setClassification(rs.getString("AUTH_CLASS"));\r
- this.publisher = rs.getString("PUBLISHER");\r
- this.links = new FeedLinks();\r
- this.links.setSelf(rs.getString("SELF_LINK"));\r
- this.links.setPublish(rs.getString("PUBLISH_LINK"));\r
- this.links.setSubscribe(rs.getString("SUBSCRIBE_LINK"));\r
- this.links.setLog(rs.getString("LOG_LINK"));\r
- this.deleted = rs.getBoolean("DELETED");\r
- this.suspended = rs.getBoolean("SUSPENDED");\r
- this.last_mod = rs.getDate("LAST_MOD");\r
- this.created_date = rs.getTimestamp("CREATED_DATE");\r
- }\r
- public Feed(JSONObject jo) throws InvalidObjectException {\r
- this("", "", "","");\r
- try {\r
- // The JSONObject is assumed to contain a vnd.att-dr.feed representation\r
- this.feedid = jo.optInt("feedid", -1);\r
- this.groupid = jo.optInt("groupid"); //New field is added - Groups feature Rally:US708115 - 1610\r
- this.name = jo.getString("name");\r
- if (name.length() > 255)\r
- throw new InvalidObjectException("name field is too long");\r
- this.version = jo.getString("version");\r
- if (version.length() > 20)\r
- throw new InvalidObjectException("version field is too long");\r
- this.description = jo.optString("description");\r
- this.business_description = jo.optString("business_description"); // New field is added - Groups feature Rally:US708102 - 1610\r
- if (description.length() > 1000)\r
- throw new InvalidObjectException("technical description field is too long");\r
- \r
- if (business_description.length() > 1000) // New field is added - Groups feature Rally:US708102 - 1610\r
- throw new InvalidObjectException("business description field is too long");\r
-\r
- this.authorization = new FeedAuthorization();\r
- JSONObject jauth = jo.getJSONObject("authorization");\r
- this.authorization.setClassification(jauth.getString("classification"));\r
- if (this.authorization.getClassification().length() > 32)\r
- throw new InvalidObjectException("classification field is too long");\r
- JSONArray ja = jauth.getJSONArray("endpoint_ids");\r
- for (int i = 0; i < ja.length(); i++) {\r
- JSONObject id = ja.getJSONObject(i);\r
- FeedEndpointID fid = new FeedEndpointID(id.getString("id"), id.getString("password"));\r
- if (fid.getId().length() > 20)\r
- throw new InvalidObjectException("id field is too long ("+fid.getId()+")");\r
- if (fid.getPassword().length() > 32)\r
- throw new InvalidObjectException("password field is too long ("+fid.getPassword()+")");\r
- this.authorization.getEndpoint_ids().add(fid);\r
- }\r
- if (this.authorization.getEndpoint_ids().size() < 1)\r
- throw new InvalidObjectException("need to specify at least one endpoint_id");\r
- ja = jauth.getJSONArray("endpoint_addrs");\r
- for (int i = 0; i < ja.length(); i++) {\r
- String addr = ja.getString(i);\r
- if (!JSONUtilities.validIPAddrOrSubnet(addr))\r
- throw new InvalidObjectException("bad IP addr or subnet mask: "+addr);\r
- this.authorization.getEndpoint_addrs().add(addr);\r
- }\r
-\r
- this.publisher = jo.optString("publisher", "");\r
- this.deleted = jo.optBoolean("deleted", false);\r
- this.suspended = jo.optBoolean("suspend", false);\r
- JSONObject jol = jo.optJSONObject("links");\r
- this.links = (jol == null) ? (new FeedLinks()) : (new FeedLinks(jol));\r
- } catch (InvalidObjectException e) {\r
- throw e;\r
- } catch (Exception e) {\r
- throw new InvalidObjectException("invalid JSON: "+e.getMessage());\r
- }\r
- }\r
- public int getFeedid() {\r
- return feedid;\r
- }\r
- public void setFeedid(int feedid) {\r
- this.feedid = feedid;\r
-\r
- // Create link URLs\r
- FeedLinks fl = getLinks();\r
- fl.setSelf(URLUtilities.generateFeedURL(feedid));\r
- fl.setPublish(URLUtilities.generatePublishURL(feedid));\r
- fl.setSubscribe(URLUtilities.generateSubscribeURL(feedid));\r
- fl.setLog(URLUtilities.generateFeedLogURL(feedid));\r
- }\r
- \r
- //new getter setters for groups- Rally:US708115 - 1610\r
- public int getGroupid() {\r
- return groupid;\r
- }\r
-\r
- public void setGroupid(int groupid) {\r
- this.groupid = groupid;\r
- }\r
- \r
- public String getName() {\r
- return name;\r
- }\r
- public void setName(String name) {\r
- this.name = name;\r
- }\r
- public String getVersion() {\r
- return version;\r
- }\r
- public void setVersion(String version) {\r
- this.version = version;\r
- }\r
- public String getDescription() {\r
- return description;\r
- }\r
- public void setDescription(String description) {\r
- this.description = description;\r
- }\r
+\r
+ private static EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");\r
+ private static int nextFeedID = getMaxFeedID() + 1;\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
+ private static final String LAST_MOD = "last_mod";\r
+ private static final String CREATED_DATE = "created_date";\r
+\r
+ private int feedid;\r
+ private int groupid; //New field is added - Groups feature Rally:US708115 - 1610\r
+ private String name;\r
+ private String version;\r
+ private String description;\r
+ private String businessDescription; // New field is added - Groups feature Rally:US708102 - 1610\r
+ private FeedAuthorization authorization;\r
+ private String publisher;\r
+ private FeedLinks links;\r
+ private boolean deleted;\r
+ private boolean suspended;\r
+ private Date lastMod;\r
+ private Date createdDate;\r
+ private String aafInstance;\r
+\r
+ public Feed() {\r
+ this("", "", "", "");\r
+ }\r
+\r
+ /**\r
+ * Feed constructor.\r
+ * @param name feed name\r
+ * @param version feed version\r
+ * @param desc feed description\r
+ * @param businessDescription feed business description\r
+ */\r
+ public Feed(String name, String version, String desc, String businessDescription) {\r
+ this.feedid = -1;\r
+ this.groupid = -1; //New field is added - Groups feature Rally:US708115 - 1610\r
+ this.name = name;\r
+ this.version = version;\r
+ this.description = desc;\r
+ this.businessDescription = businessDescription; // New field is added - Groups feature Rally:US708102 - 1610\r
+ this.authorization = new FeedAuthorization();\r
+ this.publisher = "";\r
+ this.links = new FeedLinks();\r
+ this.deleted = false;\r
+ this.suspended = false;\r
+ this.lastMod = new Date();\r
+ this.createdDate = new Date();\r
+ this.aafInstance = "";\r
+ }\r
+\r
+ /**\r
+ * Feed Constructor from ResultSet.\r
+ * @param rs ResultSet\r
+ * @throws SQLException in case of SQL statement error\r
+ */\r
+ public Feed(ResultSet rs) throws SQLException {\r
+ this.feedid = rs.getInt(FEED_ID_SQL);\r
+ //New field is added - Groups feature Rally:US708115 - 1610\r
+ this.groupid = rs.getInt("GROUPID");\r
+ this.name = rs.getString("NAME");\r
+ this.version = rs.getString("VERSION");\r
+ this.description = rs.getString("DESCRIPTION");\r
+ // New field is added - Groups feature Rally:US708102 - 1610\r
+ this.businessDescription = rs.getString("BUSINESS_DESCRIPTION");\r
+ this.authorization = new FeedAuthorization();\r
+ this.authorization.setClassification(rs.getString("AUTH_CLASS"));\r
+ this.publisher = rs.getString("PUBLISHER");\r
+ this.links = new FeedLinks();\r
+ this.links.setSelf(rs.getString("SELF_LINK"));\r
+ this.links.setPublish(rs.getString("PUBLISH_LINK"));\r
+ this.links.setSubscribe(rs.getString("SUBSCRIBE_LINK"));\r
+ this.links.setLog(rs.getString("LOG_LINK"));\r
+ this.deleted = rs.getBoolean("DELETED");\r
+ this.suspended = rs.getBoolean("SUSPENDED");\r
+ this.lastMod = rs.getDate("LAST_MOD");\r
+ this.createdDate = rs.getTimestamp("CREATED_DATE");\r
+ this.aafInstance = rs.getString("AAF_INSTANCE");\r
+ }\r
+\r
+ /**\r
+ * Feed constructor from JSONObject.\r
+ * @param jo JSONObject\r
+ * @throws InvalidObjectException in case of JSON error\r
+ */\r
+ public Feed(JSONObject jo) throws InvalidObjectException {\r
+ this("", "", "", "");\r
+ try {\r
+ // The JSONObject is assumed to contain a vnd.dmaap-dr.feed representation\r
+ this.feedid = jo.optInt(FEED_ID, -1);\r
+ this.groupid = jo.optInt("groupid");\r
+ this.name = jo.getString("name");\r
+ this.aafInstance = jo.optString("aaf_instance", "legacy");\r
+ if (!("legacy".equalsIgnoreCase(aafInstance)) && aafInstance.length() > 255) {\r
+ throw new InvalidObjectException("aaf_instance field is too long");\r
+ }\r
+ if (name.length() > 255) {\r
+ throw new InvalidObjectException("name field is too long");\r
+ }\r
+ try {\r
+ this.version = jo.getString("version");\r
+ } catch (JSONException e) {\r
+ intlogger.warn("PROV0023 Feed.Feed: " + e.getMessage(), e);\r
+ this.version = null;\r
+ }\r
+ if (version != null && version.length() > 20) {\r
+ throw new InvalidObjectException("version field is too long");\r
+ }\r
+ this.description = jo.optString("description");\r
+ this.businessDescription = jo.optString("business_description");\r
+ if (description.length() > 1000) {\r
+ throw new InvalidObjectException("technical description field is too long");\r
+ }\r
+ if (businessDescription.length() > 1000) {\r
+ throw new InvalidObjectException("business description field is too long");\r
+ }\r
+ this.authorization = new FeedAuthorization();\r
+ JSONObject jauth = jo.getJSONObject("authorization");\r
+ this.authorization.setClassification(jauth.getString("classification"));\r
+ if (this.authorization.getClassification().length() > 32) {\r
+ throw new InvalidObjectException("classification field is too long");\r
+ }\r
+ JSONArray endPointIds = jauth.getJSONArray("endpoint_ids");\r
+ for (int i = 0; i < endPointIds.length(); i++) {\r
+ JSONObject id = endPointIds.getJSONObject(i);\r
+ FeedEndpointID fid = new FeedEndpointID(id.getString("id"), id.getString("password"));\r
+ if (fid.getId().length() > 60) {\r
+ throw new InvalidObjectException("id field is too long (" + fid.getId() + ")");\r
+ }\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
+ this.authorization.getEndpointIDS().add(fid);\r
+ }\r
+ if (this.authorization.getEndpointIDS().isEmpty()) {\r
+ throw new InvalidObjectException("need to specify at least one endpoint_id");\r
+ }\r
+ endPointIds = jauth.getJSONArray("endpoint_addrs");\r
+ for (int i = 0; i < endPointIds.length(); i++) {\r
+ String addr = endPointIds.getString(i);\r
+ if (!JSONUtilities.validIPAddrOrSubnet(addr)) {\r
+ throw new InvalidObjectException("bad IP addr or subnet mask: " + addr);\r
+ }\r
+ this.authorization.getEndpointAddrs().add(addr);\r
+ }\r
+\r
+ this.publisher = jo.optString("publisher", "");\r
+ this.deleted = jo.optBoolean(DEL, false);\r
+ this.suspended = jo.optBoolean("suspend", false);\r
+ JSONObject jol = jo.optJSONObject("links");\r
+ this.links = (jol == null) ? (new FeedLinks()) : (new FeedLinks(jol));\r
+ } catch (InvalidObjectException e) {\r
+ throw e;\r
+ } catch (Exception e) {\r
+ intlogger.warn("Invalid JSON: " + e.getMessage(), e);\r
+ throw new InvalidObjectException("Invalid JSON: " + e.getMessage());\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Check if a feed ID is valid.\r
+ *\r
+ * @param id the Feed ID\r
+ * @return true if it is valid\r
+ */\r
+ @SuppressWarnings("resource")\r
+ static boolean isFeedValid(int id) {\r
+ int count = 0;\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
+ } catch (SQLException e) {\r
+ intlogger.warn("PROV0024 Feed.isFeedValid: " + e.getMessage(), e);\r
+ }\r
+ return count != 0;\r
+ }\r
+\r
+ /**\r
+ * Get a specific feed from the DB, based upon its ID.\r
+ *\r
+ * @param id the Feed ID\r
+ * @return the Feed object, or null if it does not exist\r
+ */\r
+ public static Feed getFeedById(int id) {\r
+ String sql = "select * from FEEDS where FEEDID = " + id;\r
+ return getFeedBySQL(sql);\r
+ }\r
+\r
+ /**\r
+ * Get a specific feed from the DB, based upon its name and version.\r
+ *\r
+ * @param name the name of the Feed\r
+ * @param version the version of the Feed\r
+ * @return the Feed object, or null if it does not exist\r
+ */\r
+ public static Feed getFeedByNameVersion(String name, String version) {\r
+ name = name.replaceAll("'", "''");\r
+ version = version.replaceAll("'", "''");\r
+ String sql = "select * from FEEDS where NAME = '" + name + "' and VERSION ='" + version + "'";\r
+ return getFeedBySQL(sql);\r
+ }\r
+\r
+ /**\r
+ * Return a count of the number of active feeds in the DB.\r
+ *\r
+ * @return the count\r
+ */\r
+ public static int countActiveFeeds() {\r
+ int count = 0;\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
+ } catch (SQLException e) {\r
+ intlogger.warn("PROV0025 Feed.countActiveFeeds: " + e.getMessage(), e);\r
+ }\r
+ return count;\r
+ }\r
+\r
+ /**\r
+ * Method to get max feed id.\r
+ * @return int max feed id\r
+ */\r
+ public static int getMaxFeedID() {\r
+ int max = 0;\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
+ } catch (SQLException e) {\r
+ intlogger.warn("PROV0026 Feed.getMaxFeedID: " + e.getMessage(), e);\r
+ }\r
+ return max;\r
+ }\r
+\r
+ /**\r
+ * Gets all feeds.\r
+ * @return Collection of feeds\r
+ */\r
+ public static Collection<Feed> getAllFeeds() {\r
+ Map<Integer, Feed> map = new HashMap<>();\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
+ 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
+ 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
+ } catch (SQLException e) {\r
+ intlogger.warn("PROV0027 Feed.getAllFeeds: " + e.getMessage(), e);\r
+ }\r
+ return map.values();\r
+ }\r
+\r
+ /**\r
+ * Get Feed URL list.\r
+ * @param name of Feed\r
+ * @param val of feed\r
+ * @return List of feed names\r
+ */\r
+ public static List<String> getFilteredFeedUrlList(final String name, final String val) {\r
+ List<String> list = new ArrayList<>();\r
+ String sql = "select SELF_LINK from FEEDS where DELETED = 0";\r
+ if (name.equals("name")) {\r
+ sql += " and NAME = ?";\r
+ } else if (name.equals("publ")) {\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
+ }\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
+ } catch (SQLException e) {\r
+ intlogger.warn("PROV0028 Feed.getFilteredFeedUrlList: " + e.getMessage(), e);\r
+ }\r
+ return list;\r
+ }\r
+\r
+ @SuppressWarnings("resource")\r
+ private static Feed getFeedBySQL(String sql) {\r
+ Feed feed = null;\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
+ feed = new Feed(rs);\r
+ }\r
+ }\r
+ if (feed != null) {\r
+ sql = "select * from FEED_ENDPOINT_IDS where FEEDID = " + feed.feedid;\r
+ try (ResultSet rs = stmt.executeQuery(sql)) {\r
+ Collection<FeedEndpointID> ecoll = feed.getAuthorization().getEndpointIDS();\r
+ while (rs.next()) {\r
+ FeedEndpointID epi = new FeedEndpointID(rs);\r
+ ecoll.add(epi);\r
+ }\r
+ }\r
+ sql = "select * from FEED_ENDPOINT_ADDRS where FEEDID = " + feed.feedid;\r
+ try (ResultSet rs = stmt.executeQuery(sql)) {\r
+ Collection<String> acoll = feed.getAuthorization().getEndpointAddrs();\r
+ while (rs.next()) {\r
+ acoll.add(rs.getString("ADDR"));\r
+ }\r
+ }\r
+ }\r
+ }\r
+ } catch (SQLException e) {\r
+ intlogger.warn("PROV0029 Feed.getFeedBySQL: " + e.getMessage(), e);\r
+ }\r
+ return feed;\r
+ }\r
+\r
+\r
+\r
+ public int getFeedid() {\r
+ return feedid;\r
+ }\r
+\r
+ /**\r
+ * Set feedid with FeedLinks.\r
+ * @param feedid Feedid to set to\r
+ */\r
+ public void setFeedid(int feedid) {\r
+ this.feedid = feedid;\r
+\r
+ // Create link URLs\r
+ FeedLinks fl = getLinks();\r
+ fl.setSelf(URLUtilities.generateFeedURL(feedid));\r
+ fl.setPublish(URLUtilities.generatePublishURL(feedid));\r
+ fl.setSubscribe(URLUtilities.generateSubscribeURL(feedid));\r
+ fl.setLog(URLUtilities.generateFeedLogURL(feedid));\r
+ }\r
+\r
+ public String getAafInstance() {\r
+ return aafInstance;\r
+ }\r
+\r
+ //new getter setters for groups- Rally:US708115 - 1610\r
+ public int getGroupid() {\r
+ return groupid;\r
+ }\r
+\r
+ public void setGroupid(int groupid) {\r
+ this.groupid = groupid;\r
+ }\r
+\r
+ public String getName() {\r
+ return name;\r
+ }\r
+\r
+ public void setName(String name) {\r
+ this.name = name;\r
+ }\r
+\r
+ public String getVersion() {\r
+ return version;\r
+ }\r
+\r
+ public void setVersion(String version) {\r
+ this.version = version;\r
+ }\r
+\r
+ public String getDescription() {\r
+ return description;\r
+ }\r
+\r
+ public void setDescription(String description) {\r
+ this.description = description;\r
+ }\r
+\r