- 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
+ 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
+ *\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
+ 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
+ }\r
+ }\r
+ db.release(conn);\r
+ } catch (SQLException e) {\r
+ intlogger.error("SQLException " + e.getMessage());\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 {\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 count(*) from FEEDS where DELETED = 0")) {\r
+ if (rs.next()) {\r
+ count = rs.getInt(1);\r
+ }\r
+ }\r
+ }\r
+ db.release(conn);\r
+ } catch (SQLException e) {\r
+ intlogger.info("countActiveFeeds: " + e.getMessage());\r
+ intlogger.error("SQLException " + e.getMessage());\r
+ }\r
+ return count;\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
+ }\r
+ }\r
+ db.release(conn);\r
+ } catch (SQLException e) {\r
+ intlogger.info("getMaxFeedID: " + e.getMessage());\r
+ intlogger.error("SQLException " + e.getMessage());\r
+ }\r
+ return max;\r
+ }\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
+ 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
+ }\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("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
+ }\r
+\r
+ sql = "select * from FEED_ENDPOINT_ADDRS";\r
+ try(ResultSet 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
+ }\r
+ }\r
+ db.release(conn);\r
+ } catch (SQLException e) {\r
+ intlogger.error("SQLException " + e.getMessage());\r
+ }\r
+ return map.values();\r
+ }\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
+ try(PreparedStatement ps = conn.prepareStatement(sql)) {\r
+ if (sql.indexOf('?') >= 0)\r
+ ps.setString(1, val);\r
+ try(ResultSet rs = ps.executeQuery()) {\r
+ while (rs.next()) {\r
+ String t = rs.getString(1);\r
+ list.add(t.trim());\r
+ }\r
+ }\r
+ }\r
+ db.release(conn);\r
+ } catch (SQLException e) {\r
+ intlogger.error("SQLException " + e.getMessage());\r
+ }\r
+ return list;\r
+ }\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 (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().getEndpoint_ids();\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().getEndpoint_addrs();\r
+ while (rs.next()) {\r
+ acoll.add(rs.getString("ADDR"));\r
+ }\r
+ }\r
+ }\r
+ }\r
+ db.release(conn);\r
+ } catch (SQLException e) {\r
+ intlogger.error("SQLException " + e.getMessage());\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
+\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
+\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
+\r
+ public int getFeedid() {\r
+ return feedid;\r
+ }\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
+\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