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%2FSubscription.java;h=5741881c5306241490682df6fa5e3ad9d382d01c;hp=027d859cf83c73692457b76d6eadcfed22424bd4;hb=68a9ca240970fceaf12bbe91b7bad8e1d98ecd93;hpb=8cbe8a88bc6dfe8673a33a017fe6a5a3e7ce86c3 diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Subscription.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Subscription.java index 027d859c..5741881c 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Subscription.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Subscription.java @@ -23,23 +23,23 @@ package org.onap.dmaap.datarouter.provisioning.beans; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import java.io.InvalidObjectException; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.sql.Statement; import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.List; - -import org.apache.log4j.Logger; +import java.util.Properties; import org.json.JSONObject; -import org.onap.dmaap.datarouter.provisioning.utils.DB; +import org.onap.dmaap.datarouter.provisioning.ProvRunner; +import org.onap.dmaap.datarouter.provisioning.utils.ProvDbUtils; import org.onap.dmaap.datarouter.provisioning.utils.URLUtilities; -import java.util.Properties; /** * The representation of a Subscription. Subscriptions can be retrieved from the DB, or stored/updated in the DB. @@ -47,106 +47,232 @@ import java.util.Properties; * @author Robert Eby * @version $Id: Subscription.java,v 1.9 2013/10/28 18:06:53 eby Exp $ */ + public class Subscription extends Syncable { - private static Logger intlogger = Logger.getLogger("org.onap.dmaap.datarouter.provisioning.internal"); - private static int next_subid = getMaxSubID() + 1; + + private static final String SQLEXCEPTION = "SQLException: "; + private static final String SUBID_KEY = "subid"; + private static final String SUBID_COL = "SUBID"; + private static final String FEEDID_KEY = "feedid"; + private static final String GROUPID_KEY = "groupid"; + private static final String LAST_MOD_KEY = "last_mod"; + private static final String CREATED_DATE = "created_date"; + private static EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog"); + private static int nextSubid = getMaxSubID() + 1; private int subid; private int feedid; private int groupid; //New field is added - Groups feature Rally:US708115 - 1610 private SubDelivery delivery; + private boolean followRedirect; private boolean metadataOnly; private String subscriber; private SubLinks links; private boolean suspended; - private Date last_mod; - private Date created_date; + private Date lastMod; + private Date createdDate; + private boolean privilegedSubscriber; + private String aafInstance; + private boolean decompress; + + public Subscription() { + this("", "", ""); + } + + /** + * Subscription constructor. + * @param url url string + * @param user user string + * @param password password string + */ + public Subscription(String url, String user, String password) { + this.subid = -1; + this.feedid = -1; + this.groupid = -1; //New field is added - Groups feature Rally:US708115 - 1610 + this.delivery = new SubDelivery(url, user, password, false); + this.metadataOnly = false; + this.followRedirect = false; + this.subscriber = ""; + this.links = new SubLinks(); + this.suspended = false; + this.lastMod = new Date(); + this.createdDate = new Date(); + this.privilegedSubscriber = false; + this.aafInstance = ""; + this.decompress = false; + } + + /** + * Subscription constructor. + * @param rs resultset from SQL + * @throws SQLException in case of SQL error + */ + public Subscription(ResultSet rs) throws SQLException { + this.subid = rs.getInt(SUBID_COL); + this.feedid = rs.getInt("FEEDID"); + this.groupid = rs.getInt("GROUPID"); //New field is added - Groups feature Rally:US708115 - 1610 + this.delivery = new SubDelivery(rs); + this.metadataOnly = rs.getBoolean("METADATA_ONLY"); + this.followRedirect = rs.getBoolean("FOLLOW_REDIRECTS"); + this.subscriber = rs.getString("SUBSCRIBER"); + this.links = new SubLinks(rs.getString("SELF_LINK"), URLUtilities.generateFeedURL(feedid), + rs.getString("LOG_LINK")); + this.suspended = rs.getBoolean("SUSPENDED"); + this.lastMod = rs.getDate("LAST_MOD"); + this.createdDate = rs.getDate("CREATED_DATE"); + this.privilegedSubscriber = rs.getBoolean("PRIVILEGED_SUBSCRIBER"); + this.aafInstance = rs.getString("AAF_INSTANCE"); + this.decompress = rs.getBoolean("DECOMPRESS"); + } + + /** + * Subscription constructor. + * @param jo JSONObject + * @throws InvalidObjectException in case of object error + */ + public Subscription(JSONObject jo) throws InvalidObjectException { + this("", "", ""); + try { + // The JSONObject is assumed to contain a vnd.dmaap-dr.subscription representation + this.subid = jo.optInt(SUBID_KEY, -1); + this.feedid = jo.optInt(FEEDID_KEY, -1); + this.groupid = jo.optInt(GROUPID_KEY, -1); //New field is added - Groups feature Rally:US708115 - 1610 + this.aafInstance = jo.optString("aaf_instance", "legacy"); + if (!(aafInstance.equalsIgnoreCase("legacy")) && aafInstance.length() > 255) { + throw new InvalidObjectException("aaf_instance field is too long"); + } + JSONObject jdeli = jo.getJSONObject("delivery"); + String url = jdeli.getString("url"); + String user = jdeli.getString("user"); + final String password = jdeli.getString("password"); + final boolean use100 = jdeli.getBoolean("use100"); + + //Data Router Subscriber HTTPS Relaxation feature USERSTORYID:US674047. + Properties prop = ProvRunner.getProvProperties(); + if (!url.startsWith("https://") && isHttpsRelaxationFalseAndHasSyncKey(jo, prop)) { + throw new InvalidObjectException("delivery URL is not HTTPS"); + } + + if (url.length() > 256) { + throw new InvalidObjectException("delivery url field is too long"); + } + if (user.length() > 60) { + throw new InvalidObjectException("delivery user field is too long"); + } + if (password.length() > 32) { + throw new InvalidObjectException("delivery password field is too long"); + } + this.delivery = new SubDelivery(url, user, password, use100); + this.metadataOnly = jo.getBoolean("metadataOnly"); + this.followRedirect = jo.optBoolean("follow_redirect", false); + this.suspended = jo.optBoolean("suspend", false); + this.privilegedSubscriber = jo.optBoolean("privilegedSubscriber", false); + this.decompress = jo.optBoolean("decompress", false); + this.subscriber = jo.optString("subscriber", ""); + JSONObject jol = jo.optJSONObject("links"); + this.links = (jol == null) ? (new SubLinks()) : (new SubLinks(jol)); + } catch (InvalidObjectException e) { + throw e; + } catch (Exception e) { + intlogger.warn("Invalid JSON: " + e.getMessage(), e); + throw new InvalidObjectException("Invalid JSON: " + e.getMessage()); + } + } + /** + * Get specific subscription. + * @param sub subscription object + * @return subscription + */ public static Subscription getSubscriptionMatching(Subscription sub) { SubDelivery deli = sub.getDelivery(); String sql = String.format( - "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", - sub.getFeedid(), - deli.getUrl(), - deli.getUser(), - deli.getPassword(), - deli.isUse100() ? 1 : 0, - sub.isMetadataOnly() ? 1 : 0 + "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", + sub.getFeedid(), + deli.getUrl(), + deli.getUser(), + deli.getPassword(), + deli.isUse100() ? 1 : 0, + sub.isMetadataOnly() ? 1 : 0, + sub.isFollowRedirect() ? 1 : 0 ); List list = getSubscriptionsForSQL(sql); - return list.size() > 0 ? list.get(0) : null; + return !list.isEmpty() ? list.get(0) : null; } + /** + * Get subscription by id. + * @param id subscription id string + * @return subscription + */ public static Subscription getSubscriptionById(int id) { String sql = "select * from SUBSCRIPTIONS where SUBID = " + id; List list = getSubscriptionsForSQL(sql); - return list.size() > 0 ? list.get(0) : null; + return !list.isEmpty() ? list.get(0) : null; } public static Collection getAllSubscriptions() { return getSubscriptionsForSQL("select * from SUBSCRIPTIONS"); } + /** + * Get subscriptions from SQL. + * @param sql SQL statement + * @return List of subscriptions + */ private static List getSubscriptionsForSQL(String sql) { - List list = new ArrayList(); - try { - DB db = new DB(); - @SuppressWarnings("resource") - Connection conn = db.getConnection(); - Statement stmt = conn.createStatement(); - ResultSet rs = stmt.executeQuery(sql); + List list = new ArrayList<>(); + try (Connection conn = ProvDbUtils.getInstance().getConnection(); + PreparedStatement ps = conn.prepareStatement(sql); + ResultSet rs = ps.executeQuery()) { while (rs.next()) { Subscription sub = new Subscription(rs); list.add(sub); } - rs.close(); - stmt.close(); - db.release(conn); } catch (SQLException e) { - e.printStackTrace(); + intlogger.error("PROV0001 getSubscriptionsForSQL: " + e.toString(), e); } return list; } + /** + * Get max subid. + * @return subid int + */ public static int getMaxSubID() { int max = 0; - try { - DB db = new DB(); - @SuppressWarnings("resource") - Connection conn = db.getConnection(); - Statement stmt = conn.createStatement(); - ResultSet rs = stmt.executeQuery("select MAX(subid) from SUBSCRIPTIONS"); + try (Connection conn = ProvDbUtils.getInstance().getConnection(); + PreparedStatement ps = conn.prepareStatement("select MAX(subid) from SUBSCRIPTIONS"); + ResultSet rs = ps.executeQuery()) { if (rs.next()) { max = rs.getInt(1); } - rs.close(); - stmt.close(); - db.release(conn); } catch (SQLException e) { - intlogger.info("getMaxSubID: " + e.getMessage()); - e.printStackTrace(); + intlogger.info("getMaxSubID: " + e.getMessage(), e); } return max; } + /** + * Get subscription URL list. + * @param feedid feedid int + * @return collection of subscription URL + */ public static Collection getSubscriptionUrlList(int feedid) { - List list = new ArrayList(); - String sql = "select SUBID from SUBSCRIPTIONS where FEEDID = " + feedid; - try { - DB db = new DB(); - @SuppressWarnings("resource") - Connection conn = db.getConnection(); - Statement stmt = conn.createStatement(); - ResultSet rs = stmt.executeQuery(sql); - while (rs.next()) { - int subid = rs.getInt("SUBID"); - list.add(URLUtilities.generateSubscriptionURL(subid)); + List list = new ArrayList<>(); + try (Connection conn = ProvDbUtils.getInstance().getConnection(); + PreparedStatement stmt = conn.prepareStatement("select SUBID from SUBSCRIPTIONS where FEEDID = ?")) { + stmt.setString(1, String.valueOf(feedid)); + try (ResultSet rs = stmt.executeQuery()) { + while (rs.next()) { + int subid = rs.getInt(SUBID_COL); + list.add(URLUtilities.generateSubscriptionURL(subid)); + } } - rs.close(); - stmt.close(); - db.release(conn); } catch (SQLException e) { - e.printStackTrace(); + intlogger.error(SQLEXCEPTION + e.getMessage(), e); } return list; } @@ -158,102 +284,31 @@ public class Subscription extends Syncable { */ public static int countActiveSubscriptions() { int count = 0; - try { - DB db = new DB(); - @SuppressWarnings("resource") - Connection conn = db.getConnection(); - Statement stmt = conn.createStatement(); - ResultSet rs = stmt.executeQuery("select count(*) from SUBSCRIPTIONS"); + try (Connection conn = ProvDbUtils.getInstance().getConnection(); + PreparedStatement ps = conn.prepareStatement("select count(*) from SUBSCRIPTIONS"); + ResultSet rs = ps.executeQuery()) { if (rs.next()) { count = rs.getInt(1); } - rs.close(); - stmt.close(); - db.release(conn); } catch (SQLException e) { - intlogger.warn("PROV0008 countActiveSubscriptions: " + e.getMessage()); - e.printStackTrace(); + intlogger.warn("PROV0008 countActiveSubscriptions: " + e.getMessage(), e); } return count; } - public Subscription() { - this("", "", ""); - } - - public Subscription(String url, String user, String password) { - this.subid = -1; - this.feedid = -1; - this.groupid = -1; //New field is added - Groups feature Rally:US708115 - 1610 - this.delivery = new SubDelivery(url, user, password, false); - this.metadataOnly = false; - this.subscriber = ""; - this.links = new SubLinks(); - this.suspended = false; - this.last_mod = new Date(); - this.created_date = new Date(); - } - - public Subscription(ResultSet rs) throws SQLException { - this.subid = rs.getInt("SUBID"); - this.feedid = rs.getInt("FEEDID"); - this.groupid = rs.getInt("GROUPID"); //New field is added - Groups feature Rally:US708115 - 1610 - this.delivery = new SubDelivery(rs); - this.metadataOnly = rs.getBoolean("METADATA_ONLY"); - this.subscriber = rs.getString("SUBSCRIBER"); - this.links = new SubLinks(rs.getString("SELF_LINK"), URLUtilities.generateFeedURL(feedid), rs.getString("LOG_LINK")); - this.suspended = rs.getBoolean("SUSPENDED"); - this.last_mod = rs.getDate("LAST_MOD"); - this.created_date = rs.getDate("CREATED_DATE"); - } - - public Subscription(JSONObject jo) throws InvalidObjectException { - this("", "", ""); - try { - // The JSONObject is assumed to contain a vnd.att-dr.subscription representation - this.subid = jo.optInt("subid", -1); - this.feedid = jo.optInt("feedid", -1); - this.groupid = jo.optInt("groupid", -1); //New field is added - Groups feature Rally:US708115 - 1610 - - JSONObject jdeli = jo.getJSONObject("delivery"); - String url = jdeli.getString("url"); - String user = jdeli.getString("user"); - String password = jdeli.getString("password"); - boolean use100 = jdeli.getBoolean("use100"); - - - //Data Router Subscriber HTTPS Relaxation feature USERSTORYID:US674047. - Properties p = (new DB()).getProperties(); - if (p.get("org.onap.dmaap.datarouter.provserver.https.relaxation").toString().equals("false") && !jo.has("sync")) { - if (!url.startsWith("https://")) - throw new InvalidObjectException("delivery URL is not HTTPS"); - } - - if (url.length() > 256) - throw new InvalidObjectException("delivery url field is too long"); - if (user.length() > 20) - throw new InvalidObjectException("delivery user field is too long"); - if (password.length() > 32) - throw new InvalidObjectException("delivery password field is too long"); - this.delivery = new SubDelivery(url, user, password, use100); - - this.metadataOnly = jo.getBoolean("metadataOnly"); - this.suspended = jo.optBoolean("suspend", false); - - this.subscriber = jo.optString("subscriber", ""); - JSONObject jol = jo.optJSONObject("links"); - this.links = (jol == null) ? (new SubLinks()) : (new SubLinks(jol)); - } catch (InvalidObjectException e) { - throw e; - } catch (Exception e) { - throw new InvalidObjectException("invalid JSON: " + e.getMessage()); - } + private boolean isHttpsRelaxationFalseAndHasSyncKey(JSONObject jo, Properties prop) { + return prop.get("org.onap.dmaap.datarouter.provserver.https.relaxation").toString().equals("false") && !jo + .has("sync"); } public int getSubid() { return subid; } + /** + * Subid setter. + * @param subid subid string + */ public void setSubid(int subid) { this.subid = subid; @@ -267,6 +322,10 @@ public class Subscription extends Syncable { return feedid; } + /** + * feedid setter. + * @param feedid feedid string + */ public void setFeedid(int feedid) { this.feedid = feedid; @@ -275,6 +334,14 @@ public class Subscription extends Syncable { sl.setFeed(URLUtilities.generateFeedURL(feedid)); } + public String getAafInstance() { + return aafInstance; + } + + public void setAafInstance(String aafInstance) { + this.aafInstance = aafInstance; + } + //New getter setters for Groups feature Rally:US708115 - 1610 public int getGroupid() { return groupid; @@ -300,7 +367,15 @@ public class Subscription extends Syncable { this.metadataOnly = metadataOnly; } - public boolean isSuspended() { + private boolean isFollowRedirect() { + return followRedirect; + } + + public void setFollowRedirect(boolean followRedirect) { + this.followRedirect = followRedirect; + } + + boolean isSuspended() { return suspended; } @@ -308,14 +383,27 @@ public class Subscription extends Syncable { this.suspended = suspended; } + public boolean isPrivilegedSubscriber() { + return privilegedSubscriber; + } + + public void setPrivilegedSubscriber(boolean privilegedSubscriber) { + this.privilegedSubscriber = privilegedSubscriber; + } + public String getSubscriber() { return subscriber; } + /** + * Subscriber setter. + * @param subscriber subscriber string + */ public void setSubscriber(String subscriber) { if (subscriber != null) { - if (subscriber.length() > 8) + if (subscriber.length() > 8) { subscriber = subscriber.substring(0, 8); + } this.subscriber = subscriber; } } @@ -324,61 +412,87 @@ public class Subscription extends Syncable { return links; } - public void setLinks(SubLinks links) { + void setLinks(SubLinks links) { this.links = links; } + public boolean isDecompress() { + return decompress; + } + + public void setDecompress(boolean decompress) { + this.decompress = decompress; + } + @Override public JSONObject asJSONObject() { JSONObject jo = new JSONObject(); - jo.put("subid", subid); - jo.put("feedid", feedid); - jo.put("groupid", groupid); //New field is added - Groups feature Rally:US708115 - 1610 + jo.put(SUBID_KEY, subid); + jo.put(FEEDID_KEY, feedid); + jo.put(GROUPID_KEY, groupid); //New field is added - Groups feature Rally:US708115 - 1610 jo.put("delivery", delivery.asJSONObject()); jo.put("metadataOnly", metadataOnly); + jo.put("follow_redirect", followRedirect); jo.put("subscriber", subscriber); jo.put("links", links.asJSONObject()); jo.put("suspend", suspended); - jo.put("last_mod", last_mod.getTime()); - jo.put("created_date", created_date.getTime()); + jo.put(LAST_MOD_KEY, lastMod.getTime()); + jo.put(CREATED_DATE, createdDate.getTime()); + jo.put("privilegedSubscriber", privilegedSubscriber); + jo.put("aaf_instance", aafInstance); + jo.put("decompress", decompress); return jo; } - public JSONObject asLimitedJSONObject() { + /** + * Method to hide attributes. + * @param hidepasswords true/false + * @return JSONObject + */ + public JSONObject asJSONObject(boolean hidepasswords) { JSONObject jo = asJSONObject(); - jo.remove("subid"); - jo.remove("feedid"); - jo.remove("last_mod"); + if (hidepasswords) { + jo.remove(SUBID_KEY); // we no longer hide passwords, however we do hide these + jo.remove(FEEDID_KEY); + jo.remove(LAST_MOD_KEY); + jo.remove(CREATED_DATE); + } return jo; } - public JSONObject asJSONObject(boolean hidepasswords) { + /** + * Method to remove some attributes from JSON. + * @ JSONObject + */ + public JSONObject asLimitedJSONObject() { JSONObject jo = asJSONObject(); - if (hidepasswords) { - jo.remove("subid"); // we no longer hide passwords, however we do hide these - jo.remove("feedid"); - jo.remove("last_mod"); - jo.remove("created_date"); - } + jo.remove(SUBID_KEY); + jo.remove(FEEDID_KEY); + jo.remove(LAST_MOD_KEY); return jo; } + @Override - public boolean doInsert(Connection c) { + public boolean doInsert(Connection conn) { boolean rv = true; PreparedStatement ps = null; try { if (subid == -1) { // No feed ID assigned yet, so assign the next available one - setSubid(next_subid++); + setSubid(nextSubid++); } // In case we insert a feed from synchronization - if (subid > next_subid) - next_subid = subid + 1; + if (subid > nextSubid) { + nextSubid = subid + 1; + } // Create the SUBSCRIPTIONS row - String sql = "insert into SUBSCRIPTIONS (SUBID, FEEDID, DELIVERY_URL, DELIVERY_USER, DELIVERY_PASSWORD, DELIVERY_USE100, METADATA_ONLY, SUBSCRIBER, SUSPENDED, GROUPID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; - ps = c.prepareStatement(sql, new String[]{"SUBID"}); + 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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + ps = conn.prepareStatement(sql, new String[]{SUBID_COL}); ps.setInt(1, subid); ps.setInt(2, feedid); ps.setString(3, getDelivery().getUrl()); @@ -389,16 +503,15 @@ public class Subscription extends Syncable { ps.setString(8, getSubscriber()); ps.setBoolean(9, isSuspended()); ps.setInt(10, groupid); //New field is added - Groups feature Rally:US708115 - 1610 + ps.setBoolean(11, isPrivilegedSubscriber()); + ps.setInt(12, isFollowRedirect() ? 1 : 0); + ps.setBoolean(13, isDecompress()); + ps.setString(14, getAafInstance()); ps.execute(); ps.close(); -// ResultSet rs = ps.getGeneratedKeys(); -// rs.first(); -// setSubid(rs.getInt(1)); // side effect - sets the link URLs -// ps.close(); - // Update the row to set the URLs sql = "update SUBSCRIPTIONS set SELF_LINK = ?, LOG_LINK = ? where SUBID = ?"; - ps = c.prepareStatement(sql); + ps = conn.prepareStatement(sql); ps.setString(1, getLinks().getSelf()); ps.setString(2, getLinks().getLog()); ps.setInt(3, subid); @@ -406,25 +519,26 @@ public class Subscription extends Syncable { ps.close(); } catch (SQLException e) { rv = false; - intlogger.warn("PROV0005 doInsert: " + e.getMessage()); - e.printStackTrace(); + intlogger.warn("PROV0005 doInsert: " + e.getMessage(), e); } finally { try { - ps.close(); + if (ps != null) { + ps.close(); + } } catch (SQLException e) { - e.printStackTrace(); + intlogger.error(SQLEXCEPTION + e.getMessage(), e); } } return rv; } @Override - public boolean doUpdate(Connection c) { + public boolean doUpdate(Connection conn) { boolean rv = true; - PreparedStatement ps = null; - try { - String sql = "update SUBSCRIPTIONS set DELIVERY_URL = ?, DELIVERY_USER = ?, DELIVERY_PASSWORD = ?, DELIVERY_USE100 = ?, METADATA_ONLY = ?, SUSPENDED = ?, GROUPID = ? where SUBID = ?"; - ps = c.prepareStatement(sql); + try (PreparedStatement ps = conn.prepareStatement( + "update SUBSCRIPTIONS set DELIVERY_URL = ?, DELIVERY_USER = ?, DELIVERY_PASSWORD = ?, " + + "DELIVERY_USE100 = ?, METADATA_ONLY = ?, SUSPENDED = ?, GROUPID = ?, PRIVILEGED_SUBSCRIBER = ?, " + + "FOLLOW_REDIRECTS = ?, DECOMPRESS = ? where SUBID = ?")) { ps.setString(1, delivery.getUrl()); ps.setString(2, delivery.getUser()); ps.setString(3, delivery.getPassword()); @@ -432,75 +546,47 @@ public class Subscription extends Syncable { ps.setInt(5, isMetadataOnly() ? 1 : 0); ps.setInt(6, suspended ? 1 : 0); ps.setInt(7, groupid); //New field is added - Groups feature Rally:US708115 - 1610 - ps.setInt(8, subid); + ps.setInt(8, privilegedSubscriber ? 1 : 0); + ps.setInt(9, isFollowRedirect() ? 1 : 0); + ps.setInt(10, isDecompress() ? 1 : 0); + ps.setInt(11, subid); ps.executeUpdate(); } catch (SQLException e) { rv = false; - intlogger.warn("PROV0006 doUpdate: " + e.getMessage()); - e.printStackTrace(); - } finally { - try { - ps.close(); - } catch (SQLException e) { - e.printStackTrace(); - } + intlogger.warn("PROV0006 doUpdate: " + e.getMessage(), e); } return rv; } /** - * Rally US708115 - * Change Ownership of Subscription - 1610 + * Rally US708115 Change Ownership of Subscription - 1610. */ public boolean changeOwnerShip() { boolean rv = true; - PreparedStatement ps = null; - try { - - DB db = new DB(); - @SuppressWarnings("resource") - Connection c = db.getConnection(); - String sql = "update SUBSCRIPTIONS set SUBSCRIBER = ? where SUBID = ?"; - ps = c.prepareStatement(sql); + try (Connection conn = ProvDbUtils.getInstance().getConnection(); + PreparedStatement ps = conn.prepareStatement( + "update SUBSCRIPTIONS set SUBSCRIBER = ? where SUBID = ?")) { ps.setString(1, this.subscriber); ps.setInt(2, subid); ps.execute(); - ps.close(); } catch (SQLException e) { rv = false; - intlogger.warn("PROV0006 doUpdate: " + e.getMessage()); - e.printStackTrace(); - } finally { - try { - ps.close(); - } catch (SQLException e) { - e.printStackTrace(); - } + intlogger.warn("PROV0006 doUpdate: " + e.getMessage(), e); } return rv; } @Override - public boolean doDelete(Connection c) { + public boolean doDelete(Connection conn) { boolean rv = true; - PreparedStatement ps = null; - try { - String sql = "delete from SUBSCRIPTIONS where SUBID = ?"; - ps = c.prepareStatement(sql); + try (PreparedStatement ps = conn.prepareStatement("delete from SUBSCRIPTIONS where SUBID = ?")) { ps.setInt(1, subid); ps.execute(); } catch (SQLException e) { rv = false; - intlogger.warn("PROV0007 doDelete: " + e.getMessage()); - e.printStackTrace(); - } finally { - try { - ps.close(); - } catch (SQLException e) { - e.printStackTrace(); - } + intlogger.warn("PROV0007 doDelete: " + e.getMessage(), e); } return rv; } @@ -512,28 +598,49 @@ public class Subscription extends Syncable { @Override public boolean equals(Object obj) { - if (!(obj instanceof Subscription)) + if (!(obj instanceof Subscription)) { return false; + } Subscription os = (Subscription) obj; - if (subid != os.subid) + if (subid != os.subid) { return false; - if (feedid != os.feedid) + } + if (feedid != os.feedid) { return false; - if (groupid != os.groupid) //New field is added - Groups feature Rally:US708115 - 1610 + } + if (groupid != os.groupid) { + //New field is added - Groups feature Rally:US708115 - 1610 return false; - if (!delivery.equals(os.delivery)) + } + if (!delivery.equals(os.delivery)) { return false; - if (metadataOnly != os.metadataOnly) + } + if (metadataOnly != os.metadataOnly) { + return false; + } + if (followRedirect != os.followRedirect) { return false; - if (!subscriber.equals(os.subscriber)) + } + if (!subscriber.equals(os.subscriber)) { + return false; + } + if (!links.equals(os.links)) { return false; - if (!links.equals(os.links)) + } + if (suspended != os.suspended) { return false; - if (suspended != os.suspended) + } + if (!aafInstance.equals(os.aafInstance)) { return false; + } return true; } + @Override + public int hashCode() { + return super.hashCode(); + } + @Override public String toString() { return "SUB: subid=" + subid + ", feedid=" + feedid;