* @author Robert Eby\r
* @version $Id: Subscription.java,v 1.9 2013/10/28 18:06:53 eby Exp $\r
*/\r
+\r
public class Subscription extends Syncable {\r
\r
private static final String SQLEXCEPTION = "SQLException: ";\r
private String aafInstance;\r
private boolean decompress;\r
\r
+ /**\r
+ * Get specific subscription.\r
+ * @param sub subscription object\r
+ * @return subscription\r
+ */\r
public static Subscription getSubscriptionMatching(Subscription sub) {\r
SubDelivery deli = sub.getDelivery();\r
String sql = String.format(\r
- "select * from SUBSCRIPTIONS where FEEDID = %d and DELIVERY_URL = \"%s\" and DELIVERY_USER = \"%s\" and DELIVERY_PASSWORD = \"%s\" and DELIVERY_USE100 = %d and METADATA_ONLY = %d and FOLLOW_REDIRECTS = %d",\r
+ "select * from SUBSCRIPTIONS where FEEDID = %d and DELIVERY_URL = \"%s\" and DELIVERY_USER = \"%s\" "\r
+ + "and DELIVERY_PASSWORD = \"%s\" and DELIVERY_USE100 = %d and METADATA_ONLY = %d "\r
+ + "and FOLLOW_REDIRECTS = %d",\r
sub.getFeedid(),\r
deli.getUrl(),\r
deli.getUser(),\r
deli.getPassword(),\r
deli.isUse100() ? 1 : 0,\r
sub.isMetadataOnly() ? 1 : 0,\r
- sub.isFollowRedirect() ? 1 :0\r
+ sub.isFollowRedirect() ? 1 : 0\r
);\r
List<Subscription> list = getSubscriptionsForSQL(sql);\r
return !list.isEmpty() ? list.get(0) : null;\r
}\r
\r
+ /**\r
+ * Get subscription by id.\r
+ * @param id subscription id string\r
+ * @return subscription\r
+ */\r
public static Subscription getSubscriptionById(int id) {\r
String sql = "select * from SUBSCRIPTIONS where SUBID = " + id;\r
List<Subscription> list = getSubscriptionsForSQL(sql);\r
return getSubscriptionsForSQL("select * from SUBSCRIPTIONS");\r
}\r
\r
+ /**\r
+ * Get subscriptions from SQL.\r
+ * @param sql SQL statement\r
+ * @return List of subscriptions\r
+ */\r
private static List<Subscription> getSubscriptionsForSQL(String sql) {\r
List<Subscription> list = new ArrayList<>();\r
try {\r
return list;\r
}\r
\r
+ /**\r
+ * Get max subid.\r
+ * @return subid int\r
+ */\r
public static int getMaxSubID() {\r
int max = 0;\r
try {\r
return max;\r
}\r
\r
+ /**\r
+ * Get subscription URL list.\r
+ * @param feedid feedid int\r
+ * @return collection of subscription URL\r
+ */\r
public static Collection<String> getSubscriptionUrlList(int feedid) {\r
List<String> list = new ArrayList<>();\r
String sql = "select SUBID from SUBSCRIPTIONS where FEEDID = ?";\r
this("", "", "");\r
}\r
\r
+ /**\r
+ * Subscription constructor.\r
+ * @param url url string\r
+ * @param user user string\r
+ * @param password password string\r
+ */\r
public Subscription(String url, String user, String password) {\r
this.subid = -1;\r
this.feedid = -1;\r
this.decompress = false;\r
}\r
\r
+ /**\r
+ * Subscription constructor.\r
+ * @param rs resultset from SQL\r
+ * @throws SQLException in case of SQL error\r
+ */\r
public Subscription(ResultSet rs) throws SQLException {\r
this.subid = rs.getInt(SUBID_COL);\r
this.feedid = rs.getInt("FEEDID");\r
this.metadataOnly = rs.getBoolean("METADATA_ONLY");\r
this.followRedirect = rs.getBoolean("FOLLOW_REDIRECTS");\r
this.subscriber = rs.getString("SUBSCRIBER");\r
- this.links = new SubLinks(rs.getString("SELF_LINK"), URLUtilities.generateFeedURL(feedid), rs.getString("LOG_LINK"));\r
+ this.links = new SubLinks(rs.getString("SELF_LINK"), URLUtilities.generateFeedURL(feedid),\r
+ rs.getString("LOG_LINK"));\r
this.suspended = rs.getBoolean("SUSPENDED");\r
this.lastMod = rs.getDate("LAST_MOD");\r
this.createdDate = rs.getDate("CREATED_DATE");\r
this.decompress = rs.getBoolean("DECOMPRESS");\r
}\r
\r
+ /**\r
+ * Subscription constructor.\r
+ * @param jo JSONObject\r
+ * @throws InvalidObjectException in case of object error\r
+ */\r
public Subscription(JSONObject jo) throws InvalidObjectException {\r
this("", "", "");\r
try {\r
this.feedid = jo.optInt(FEEDID_KEY, -1);\r
this.groupid = jo.optInt(GROUPID_KEY, -1); //New field is added - Groups feature Rally:US708115 - 1610\r
this.aafInstance = jo.optString("aaf_instance", "legacy");\r
- if(!(aafInstance.equalsIgnoreCase("legacy"))){\r
- if (aafInstance.length() > 255)\r
- throw new InvalidObjectException("aaf_instance field is too long");\r
+ if (!(aafInstance.equalsIgnoreCase("legacy")) && aafInstance.length() > 255) {\r
+ throw new InvalidObjectException("aaf_instance field is too long");\r
}\r
JSONObject jdeli = jo.getJSONObject("delivery");\r
String url = jdeli.getString("url");\r
String user = jdeli.getString("user");\r
- String password = jdeli.getString("password");\r
- boolean use100 = jdeli.getBoolean("use100");\r
+ final String password = jdeli.getString("password");\r
+ final boolean use100 = jdeli.getBoolean("use100");\r
\r
//Data Router Subscriber HTTPS Relaxation feature USERSTORYID:US674047.\r
- Properties p = (new DB()).getProperties();\r
- if (!url.startsWith("https://") && isHttpsRelaxationFalseAndHasSyncKey(jo, p)) {\r
+ Properties prop = (new DB()).getProperties();\r
+ if (!url.startsWith("https://") && isHttpsRelaxationFalseAndHasSyncKey(jo, prop)) {\r
throw new InvalidObjectException("delivery URL is not HTTPS");\r
}\r
\r
}\r
}\r
\r
- private boolean isHttpsRelaxationFalseAndHasSyncKey(JSONObject jo, Properties p) {\r
- return p.get("org.onap.dmaap.datarouter.provserver.https.relaxation").toString().equals("false") && !jo\r
+ private boolean isHttpsRelaxationFalseAndHasSyncKey(JSONObject jo, Properties prop) {\r
+ return prop.get("org.onap.dmaap.datarouter.provserver.https.relaxation").toString().equals("false") && !jo\r
.has("sync");\r
}\r
\r
return subid;\r
}\r
\r
+ /**\r
+ * Subid setter.\r
+ * @param subid subid string\r
+ */\r
public void setSubid(int subid) {\r
this.subid = subid;\r
\r
return feedid;\r
}\r
\r
+ /**\r
+ * feedid setter.\r
+ * @param feedid feedid string\r
+ */\r
public void setFeedid(int feedid) {\r
this.feedid = feedid;\r
\r
SubLinks sl = getLinks();\r
sl.setFeed(URLUtilities.generateFeedURL(feedid));\r
}\r
+\r
public String getAafInstance() {\r
return aafInstance;\r
}\r
private boolean isFollowRedirect() {\r
return followRedirect;\r
}\r
+\r
public void setFollowRedirect(boolean followRedirect) {\r
this.followRedirect = followRedirect;\r
}\r
return subscriber;\r
}\r
\r
+ /**\r
+ * Subscriber setter.\r
+ * @param subscriber subscriber string\r
+ */\r
public void setSubscriber(String subscriber) {\r
if (subscriber != null) {\r
if (subscriber.length() > 8) {\r
return jo;\r
}\r
\r
- public JSONObject asLimitedJSONObject() {\r
- JSONObject jo = asJSONObject();\r
- jo.remove(SUBID_KEY);\r
- jo.remove(FEEDID_KEY);\r
- jo.remove(LAST_MOD_KEY);\r
- return jo;\r
- }\r
-\r
+ /**\r
+ * Method to hide attributes.\r
+ * @param hidepasswords true/false\r
+ * @return JSONObject\r
+ */\r
public JSONObject asJSONObject(boolean hidepasswords) {\r
JSONObject jo = asJSONObject();\r
if (hidepasswords) {\r
return jo;\r
}\r
\r
+ /**\r
+ * Method to remove some attributes from JSON.\r
+ * @ JSONObject\r
+ */\r
+ public JSONObject asLimitedJSONObject() {\r
+ JSONObject jo = asJSONObject();\r
+ jo.remove(SUBID_KEY);\r
+ jo.remove(FEEDID_KEY);\r
+ jo.remove(LAST_MOD_KEY);\r
+ return jo;\r
+ }\r
+\r
+\r
@Override\r
- public boolean doInsert(Connection c) {\r
+ public boolean doInsert(Connection conn) {\r
boolean rv = true;\r
PreparedStatement ps = null;\r
try {\r
}\r
\r
// Create the SUBSCRIPTIONS row\r
- String sql = "insert into SUBSCRIPTIONS (SUBID, FEEDID, DELIVERY_URL, DELIVERY_USER, DELIVERY_PASSWORD, DELIVERY_USE100, METADATA_ONLY, SUBSCRIBER, SUSPENDED, GROUPID, PRIVILEGED_SUBSCRIBER, FOLLOW_REDIRECTS, DECOMPRESS, AAF_INSTANCE) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";\r
- ps = c.prepareStatement(sql, new String[]{SUBID_COL});\r
+ String sql = "insert into SUBSCRIPTIONS (SUBID, FEEDID, DELIVERY_URL, DELIVERY_USER, DELIVERY_PASSWORD, "\r
+ + "DELIVERY_USE100, METADATA_ONLY, SUBSCRIBER, SUSPENDED, GROUPID, "\r
+ + "PRIVILEGED_SUBSCRIBER, FOLLOW_REDIRECTS, DECOMPRESS, AAF_INSTANCE) "\r
+ + "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";\r
+ ps = conn.prepareStatement(sql, new String[]{SUBID_COL});\r
ps.setInt(1, subid);\r
ps.setInt(2, feedid);\r
ps.setString(3, getDelivery().getUrl());\r
ps.close();\r
// Update the row to set the URLs\r
sql = "update SUBSCRIPTIONS set SELF_LINK = ?, LOG_LINK = ? where SUBID = ?";\r
- ps = c.prepareStatement(sql);\r
+ ps = conn.prepareStatement(sql);\r
ps.setString(1, getLinks().getSelf());\r
ps.setString(2, getLinks().getLog());\r
ps.setInt(3, subid);\r
}\r
\r
@Override\r
- public boolean doUpdate(Connection c) {\r
+ public boolean doUpdate(Connection conn) {\r
boolean rv = true;\r
PreparedStatement ps = null;\r
try {\r
- String sql = "update SUBSCRIPTIONS set DELIVERY_URL = ?, DELIVERY_USER = ?, DELIVERY_PASSWORD = ?, DELIVERY_USE100 = ?, METADATA_ONLY = ?, SUSPENDED = ?, GROUPID = ?, PRIVILEGED_SUBSCRIBER = ?, FOLLOW_REDIRECTS = ?, DECOMPRESS = ? where SUBID = ?";\r
- ps = c.prepareStatement(sql);\r
+ String sql = "update SUBSCRIPTIONS set DELIVERY_URL = ?, DELIVERY_USER = ?, DELIVERY_PASSWORD = ?, "\r
+ + "DELIVERY_USE100 = ?, METADATA_ONLY = ?, " + "SUSPENDED = ?, GROUPID = ?, "\r
+ + "PRIVILEGED_SUBSCRIBER = ?, "\r
+ + "FOLLOW_REDIRECTS = ?, DECOMPRESS = ? where SUBID = ?";\r
+ ps = conn.prepareStatement(sql);\r
ps.setString(1, delivery.getUrl());\r
ps.setString(2, delivery.getUser());\r
ps.setString(3, delivery.getPassword());\r
\r
\r
/**\r
- * Rally US708115 Change Ownership of Subscription - 1610\r
+ * Rally US708115 Change Ownership of Subscription - 1610.\r
*/\r
public boolean changeOwnerShip() {\r
boolean rv = true;\r
\r
DB db = new DB();\r
@SuppressWarnings("resource")\r
- Connection c = db.getConnection();\r
+ Connection conn = db.getConnection();\r
String sql = "update SUBSCRIPTIONS set SUBSCRIBER = ? where SUBID = ?";\r
- ps = c.prepareStatement(sql);\r
+ ps = conn.prepareStatement(sql);\r
ps.setString(1, this.subscriber);\r
ps.setInt(2, subid);\r
ps.execute();\r
\r
\r
@Override\r
- public boolean doDelete(Connection c) {\r
+ public boolean doDelete(Connection conn) {\r
boolean rv = true;\r
PreparedStatement ps = null;\r
try {\r
String sql = "delete from SUBSCRIPTIONS where SUBID = ?";\r
- ps = c.prepareStatement(sql);\r
+ ps = conn.prepareStatement(sql);\r
ps.setInt(1, subid);\r
ps.execute();\r
} catch (SQLException e) {\r