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%2FFeed.java;h=76b9e4b7048f259f9986c7d2b36e7bca43b6fc36;hp=c08bce57b59f2cbb6d3a12537cdf8bbc0600db99;hb=8280a5e1a6cfd155edfafe882439b8c04c6a4509;hpb=079a007f29994785912ca891c58e09f755189e58 diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Feed.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Feed.java index c08bce57..76b9e4b7 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Feed.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Feed.java @@ -24,17 +24,29 @@ package org.onap.dmaap.datarouter.provisioning.beans; -import org.apache.log4j.Logger; +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.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; import org.json.JSONArray; +import org.json.JSONException; import org.json.JSONObject; import org.onap.dmaap.datarouter.provisioning.utils.DB; import org.onap.dmaap.datarouter.provisioning.utils.JSONUtilities; import org.onap.dmaap.datarouter.provisioning.utils.URLUtilities; -import java.io.InvalidObjectException; -import java.sql.*; -import java.util.*; -import java.util.Date; + /** * The representation of a Feed. Feeds can be retrieved from the DB, or stored/updated in the DB. @@ -43,22 +55,167 @@ import java.util.Date; * @version $Id: Feed.java,v 1.13 2013/10/28 18:06:52 eby Exp $ */ public class Feed extends Syncable { - private static Logger intlogger = Logger.getLogger("org.onap.dmaap.datarouter.provisioning.internal"); - private static int next_feedid = getMaxFeedID() + 1; + + private static EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog"); + private static int nextFeedID = getMaxFeedID() + 1; + private static final String SQLEXCEPTION = "SQLException: "; + private static final String FEEDID = "FEEDID"; + private static final String feedIDStr = "feedid"; + private static final String deletedStr = "deleted"; + private static final String lastModStr = "last_mod"; + private static final String createdDateStr ="created_date"; private int feedid; private int groupid; //New field is added - Groups feature Rally:US708115 - 1610 private String name; private String version; private String description; - private String business_description; // New field is added - Groups feature Rally:US708102 - 1610 + private String businessDescription; // New field is added - Groups feature Rally:US708102 - 1610 private FeedAuthorization authorization; private String publisher; private FeedLinks links; private boolean deleted; private boolean suspended; - private Date last_mod; - private Date created_date; + private Date lastMod; + private Date createdDate; + private String aafInstance; + + public Feed() { + this("", "", "", ""); + } + + /** + * Feed constructor. + * @param name feed name + * @param version feed version + * @param desc feed description + * @param businessDescription feed business description + */ + public Feed(String name, String version, String desc, String businessDescription) { + this.feedid = -1; + this.groupid = -1; //New field is added - Groups feature Rally:US708115 - 1610 + this.name = name; + this.version = version; + this.description = desc; + this.businessDescription = businessDescription; // New field is added - Groups feature Rally:US708102 - 1610 + this.authorization = new FeedAuthorization(); + this.publisher = ""; + this.links = new FeedLinks(); + this.deleted = false; + this.suspended = false; + this.lastMod = new Date(); + this.createdDate = new Date(); + this.aafInstance = ""; + } + + /** + * Feed Constructor from ResultSet. + * @param rs ResultSet + * @throws SQLException in case of SQL statement error + */ + public Feed(ResultSet rs) throws SQLException { + this.feedid = rs.getInt(FEEDID); + //New field is added - Groups feature Rally:US708115 - 1610 + this.groupid = rs.getInt("GROUPID"); + this.name = rs.getString("NAME"); + this.version = rs.getString("VERSION"); + this.description = rs.getString("DESCRIPTION"); + // New field is added - Groups feature Rally:US708102 - 1610 + this.businessDescription = rs.getString("BUSINESS_DESCRIPTION"); + this.authorization = new FeedAuthorization(); + this.authorization.setClassification(rs.getString("AUTH_CLASS")); + this.publisher = rs.getString("PUBLISHER"); + this.links = new FeedLinks(); + this.links.setSelf(rs.getString("SELF_LINK")); + this.links.setPublish(rs.getString("PUBLISH_LINK")); + this.links.setSubscribe(rs.getString("SUBSCRIBE_LINK")); + this.links.setLog(rs.getString("LOG_LINK")); + this.deleted = rs.getBoolean("DELETED"); + this.suspended = rs.getBoolean("SUSPENDED"); + this.lastMod = rs.getDate("LAST_MOD"); + this.createdDate = rs.getTimestamp("CREATED_DATE"); + this.aafInstance = rs.getString("AAF_INSTANCE"); + } + + /** + * Feed constructor from JSONObject. + * @param jo JSONObject + * @throws InvalidObjectException in case of JSON error + */ + public Feed(JSONObject jo) throws InvalidObjectException { + this("", "", "", ""); + try { + // The JSONObject is assumed to contain a vnd.dmaap-dr.feed representation + this.feedid = jo.optInt(feedIDStr, -1); + this.groupid = jo.optInt("groupid"); + this.name = jo.getString("name"); + this.aafInstance = jo.optString("aaf_instance", "legacy"); + if (!(aafInstance.equalsIgnoreCase("legacy")) && aafInstance.length() > 255) { + throw new InvalidObjectException("aaf_instance field is too long"); + } + if (name.length() > 255) { + throw new InvalidObjectException("name field is too long"); + } + try { + this.version = jo.getString("version"); + } catch (JSONException e) { + intlogger.warn("PROV0023 Feed.Feed: " + e.getMessage(), e); + this.version = null; + } + if (version != null && version.length() > 20) { + throw new InvalidObjectException("version field is too long"); + } + this.description = jo.optString("description"); + this.businessDescription = jo.optString("business_description"); + if (description.length() > 1000) { + throw new InvalidObjectException("technical description field is too long"); + } + if (businessDescription.length() > 1000) { + throw new InvalidObjectException("business description field is too long"); + } + this.authorization = new FeedAuthorization(); + JSONObject jauth = jo.getJSONObject("authorization"); + this.authorization.setClassification(jauth.getString("classification")); + if (this.authorization.getClassification().length() > 32) { + throw new InvalidObjectException("classification field is too long"); + } + JSONArray endPointIds = jauth.getJSONArray("endpoint_ids"); + for (int i = 0; i < endPointIds.length(); i++) { + JSONObject id = endPointIds.getJSONObject(i); + FeedEndpointID fid = new FeedEndpointID(id.getString("id"), id.getString("password")); + if (fid.getId().length() > 60) { + throw new InvalidObjectException("id field is too long (" + fid.getId() + ")"); + } + if (fid.getPassword().length() > 32) { + //Fortify scan fixes - Privacy Violation + throw new InvalidObjectException("password field is too long (" + fid.getPassword() + ")"); + } + this.authorization.getEndpointIDS().add(fid); + } + if (this.authorization.getEndpointIDS().isEmpty()) { + throw new InvalidObjectException("need to specify at least one endpoint_id"); + } + endPointIds = jauth.getJSONArray("endpoint_addrs"); + for (int i = 0; i < endPointIds.length(); i++) { + String addr = endPointIds.getString(i); + if (!JSONUtilities.validIPAddrOrSubnet(addr)) { + throw new InvalidObjectException("bad IP addr or subnet mask: " + addr); + } + this.authorization.getEndpointAddrs().add(addr); + } + + this.publisher = jo.optString("publisher", ""); + this.deleted = jo.optBoolean(deletedStr, false); + this.suspended = jo.optBoolean("suspend", false); + JSONObject jol = jo.optJSONObject("links"); + this.links = (jol == null) ? (new FeedLinks()) : (new FeedLinks(jol)); + } catch (InvalidObjectException e) { + throw e; + } catch (Exception e) { + intlogger.warn("Invalid JSON: " + e.getMessage(), e); + throw new InvalidObjectException("Invalid JSON: " + e.getMessage()); + } + } /** * Check if a feed ID is valid. @@ -72,8 +229,9 @@ public class Feed extends Syncable { try { DB db = new DB(); Connection conn = db.getConnection(); - try(Statement stmt = conn.createStatement()) { - try(ResultSet rs = stmt.executeQuery("select COUNT(*) from FEEDS where FEEDID = " + id)) { + try (PreparedStatement stmt = conn.prepareStatement("select COUNT(*) from FEEDS where FEEDID = ?")) { + stmt.setInt(1, id); + try (ResultSet rs = stmt.executeQuery()) { if (rs.next()) { count = rs.getInt(1); } @@ -81,7 +239,7 @@ public class Feed extends Syncable { } db.release(conn); } catch (SQLException e) { - e.printStackTrace(); + intlogger.warn("PROV0024 Feed.isFeedValid: " + e.getMessage(), e); } return count != 0; } @@ -120,9 +278,8 @@ public class Feed extends Syncable { int count = 0; try { DB db = new DB(); - @SuppressWarnings("resource") - Connection conn = db.getConnection(); - try(Statement stmt = conn.createStatement()) { + @SuppressWarnings("resource") Connection conn = db.getConnection(); + try (Statement stmt = conn.createStatement()) { try (ResultSet rs = stmt.executeQuery("select count(*) from FEEDS where DELETED = 0")) { if (rs.next()) { count = rs.getInt(1); @@ -131,19 +288,22 @@ public class Feed extends Syncable { } db.release(conn); } catch (SQLException e) { - intlogger.info("countActiveFeeds: " + e.getMessage()); - e.printStackTrace(); + intlogger.warn("PROV0025 Feed.countActiveFeeds: " + e.getMessage(), e); } return count; } + /** + * Method to get max feed id. + * @return int max feed id + */ public static int getMaxFeedID() { int max = 0; try { DB db = new DB(); @SuppressWarnings("resource") Connection conn = db.getConnection(); - try(Statement stmt = conn.createStatement()) { + try (Statement stmt = conn.createStatement()) { try (ResultSet rs = stmt.executeQuery("select MAX(feedid) from FEEDS")) { if (rs.next()) { max = rs.getInt(1); @@ -152,20 +312,23 @@ public class Feed extends Syncable { } db.release(conn); } catch (SQLException e) { - intlogger.info("getMaxFeedID: " + e.getMessage()); - e.printStackTrace(); + intlogger.warn("PROV0026 Feed.getMaxFeedID: " + e.getMessage(), e); } return max; } + /** + * Gets all feeds. + * @return Collection of feeds + */ public static Collection getAllFeeds() { - Map map = new HashMap(); + Map map = new HashMap<>(); try { DB db = new DB(); @SuppressWarnings("resource") Connection conn = db.getConnection(); - try(Statement stmt = conn.createStatement()) { - try(ResultSet rs = stmt.executeQuery("select * from FEEDS")) { + try (Statement stmt = conn.createStatement()) { + try (ResultSet rs = stmt.executeQuery("select * from FEEDS")) { while (rs.next()) { Feed feed = new Feed(rs); map.put(feed.getFeedid(), feed); @@ -173,25 +336,25 @@ public class Feed extends Syncable { } String sql = "select * from FEED_ENDPOINT_IDS"; - try(ResultSet rs = stmt.executeQuery(sql)){ + try (ResultSet rs = stmt.executeQuery(sql)) { while (rs.next()) { - int id = rs.getInt("FEEDID"); + int id = rs.getInt(FEEDID); Feed feed = map.get(id); if (feed != null) { FeedEndpointID epi = new FeedEndpointID(rs); - Collection ecoll = feed.getAuthorization().getEndpoint_ids(); + Collection ecoll = feed.getAuthorization().getEndpointIDS(); ecoll.add(epi); } } } sql = "select * from FEED_ENDPOINT_ADDRS"; - try(ResultSet rs = stmt.executeQuery(sql)) { + try (ResultSet rs = stmt.executeQuery(sql)) { while (rs.next()) { - int id = rs.getInt("FEEDID"); + int id = rs.getInt(FEEDID); Feed feed = map.get(id); if (feed != null) { - Collection acoll = feed.getAuthorization().getEndpoint_addrs(); + Collection acoll = feed.getAuthorization().getEndpointAddrs(); acoll.add(rs.getString("ADDR")); } } @@ -199,41 +362,48 @@ public class Feed extends Syncable { } db.release(conn); } catch (SQLException e) { - e.printStackTrace(); + intlogger.warn("PROV0027 Feed.getAllFeeds: " + e.getMessage(), e); } return map.values(); } + /** + * Get Feed URL list. + * @param name of Feed + * @param val of feed + * @return List of feed names + */ public static List getFilteredFeedUrlList(final String name, final String val) { - List list = new ArrayList(); + List list = new ArrayList<>(); String sql = "select SELF_LINK from FEEDS where DELETED = 0"; if (name.equals("name")) { sql += " and NAME = ?"; } else if (name.equals("publ")) { sql += " and PUBLISHER = ?"; } else if (name.equals("subs")) { - sql = "select distinct FEEDS.SELF_LINK from FEEDS, SUBSCRIPTIONS " + - "where DELETED = 0 " + - "and FEEDS.FEEDID = SUBSCRIPTIONS.FEEDID " + - "and SUBSCRIPTIONS.SUBSCRIBER = ?"; + sql = "select distinct FEEDS.SELF_LINK from FEEDS, SUBSCRIPTIONS " + + "where DELETED = 0 " + + "and FEEDS.FEEDID = SUBSCRIPTIONS.FEEDID " + + "and SUBSCRIPTIONS.SUBSCRIBER = ?"; } try { DB db = new DB(); @SuppressWarnings("resource") Connection conn = db.getConnection(); - try(PreparedStatement ps = conn.prepareStatement(sql)) { - if (sql.indexOf('?') >= 0) + try (PreparedStatement ps = conn.prepareStatement(sql)) { + if (sql.indexOf('?') >= 0) { ps.setString(1, val); - try(ResultSet rs = ps.executeQuery()) { + } + try (ResultSet rs = ps.executeQuery()) { while (rs.next()) { - String t = rs.getString(1); - list.add(t.trim()); + String str = rs.getString(1); + list.add(str.trim()); } } } db.release(conn); } catch (SQLException e) { - e.printStackTrace(); + intlogger.warn("PROV0028 Feed.getFilteredFeedUrlList: " + e.getMessage(), e); } return list; } @@ -253,7 +423,7 @@ public class Feed extends Syncable { if (feed != null) { sql = "select * from FEED_ENDPOINT_IDS where FEEDID = " + feed.feedid; try (ResultSet rs = stmt.executeQuery(sql)) { - Collection ecoll = feed.getAuthorization().getEndpoint_ids(); + Collection ecoll = feed.getAuthorization().getEndpointIDS(); while (rs.next()) { FeedEndpointID epi = new FeedEndpointID(rs); ecoll.add(epi); @@ -261,7 +431,7 @@ public class Feed extends Syncable { } sql = "select * from FEED_ENDPOINT_ADDRS where FEEDID = " + feed.feedid; try (ResultSet rs = stmt.executeQuery(sql)) { - Collection acoll = feed.getAuthorization().getEndpoint_addrs(); + Collection acoll = feed.getAuthorization().getEndpointAddrs(); while (rs.next()) { acoll.add(rs.getString("ADDR")); } @@ -270,113 +440,21 @@ public class Feed extends Syncable { } db.release(conn); } catch (SQLException e) { - e.printStackTrace(); + intlogger.warn("PROV0029 Feed.getFeedBySQL: " + e.getMessage(), e); } return feed; } - public Feed() { - this("", "", "", ""); - } - - public Feed(String name, String version, String desc, String business_description) { - this.feedid = -1; - this.groupid = -1; //New field is added - Groups feature Rally:US708115 - 1610 - this.name = name; - this.version = version; - this.description = desc; - this.business_description = business_description; // New field is added - Groups feature Rally:US708102 - 1610 - this.authorization = new FeedAuthorization(); - this.publisher = ""; - this.links = new FeedLinks(); - this.deleted = false; - this.suspended = false; - this.last_mod = new Date(); - this.created_date = new Date(); - } - - public Feed(ResultSet rs) throws SQLException { - this.feedid = rs.getInt("FEEDID"); - this.groupid = rs.getInt("GROUPID"); //New field is added - Groups feature Rally:US708115 - 1610 - this.name = rs.getString("NAME"); - this.version = rs.getString("VERSION"); - this.description = rs.getString("DESCRIPTION"); - this.business_description = rs.getString("BUSINESS_DESCRIPTION"); // New field is added - Groups feature Rally:US708102 - 1610 - this.authorization = new FeedAuthorization(); - this.authorization.setClassification(rs.getString("AUTH_CLASS")); - this.publisher = rs.getString("PUBLISHER"); - this.links = new FeedLinks(); - this.links.setSelf(rs.getString("SELF_LINK")); - this.links.setPublish(rs.getString("PUBLISH_LINK")); - this.links.setSubscribe(rs.getString("SUBSCRIBE_LINK")); - this.links.setLog(rs.getString("LOG_LINK")); - this.deleted = rs.getBoolean("DELETED"); - this.suspended = rs.getBoolean("SUSPENDED"); - this.last_mod = rs.getDate("LAST_MOD"); - this.created_date = rs.getTimestamp("CREATED_DATE"); - } - - public Feed(JSONObject jo) throws InvalidObjectException { - this("", "", "", ""); - try { - // The JSONObject is assumed to contain a vnd.att-dr.feed representation - this.feedid = jo.optInt("feedid", -1); - this.groupid = jo.optInt("groupid"); //New field is added - Groups feature Rally:US708115 - 1610 - this.name = jo.getString("name"); - if (name.length() > 255) - throw new InvalidObjectException("name field is too long"); - this.version = jo.getString("version"); - if (version.length() > 20) - throw new InvalidObjectException("version field is too long"); - this.description = jo.optString("description"); - this.business_description = jo.optString("business_description"); // New field is added - Groups feature Rally:US708102 - 1610 - if (description.length() > 1000) - throw new InvalidObjectException("technical description field is too long"); - - if (business_description.length() > 1000) // New field is added - Groups feature Rally:US708102 - 1610 - throw new InvalidObjectException("business description field is too long"); - - this.authorization = new FeedAuthorization(); - JSONObject jauth = jo.getJSONObject("authorization"); - this.authorization.setClassification(jauth.getString("classification")); - if (this.authorization.getClassification().length() > 32) - throw new InvalidObjectException("classification field is too long"); - JSONArray ja = jauth.getJSONArray("endpoint_ids"); - for (int i = 0; i < ja.length(); i++) { - JSONObject id = ja.getJSONObject(i); - FeedEndpointID fid = new FeedEndpointID(id.getString("id"), id.getString("password")); - if (fid.getId().length() > 20) - throw new InvalidObjectException("id field is too long (" + fid.getId() + ")"); - if (fid.getPassword().length() > 32) - throw new InvalidObjectException("password field is too long (" + fid.getPassword() + ")"); - this.authorization.getEndpoint_ids().add(fid); - } - if (this.authorization.getEndpoint_ids().size() < 1) - throw new InvalidObjectException("need to specify at least one endpoint_id"); - ja = jauth.getJSONArray("endpoint_addrs"); - for (int i = 0; i < ja.length(); i++) { - String addr = ja.getString(i); - if (!JSONUtilities.validIPAddrOrSubnet(addr)) - throw new InvalidObjectException("bad IP addr or subnet mask: " + addr); - this.authorization.getEndpoint_addrs().add(addr); - } - this.publisher = jo.optString("publisher", ""); - this.deleted = jo.optBoolean("deleted", false); - this.suspended = jo.optBoolean("suspend", false); - JSONObject jol = jo.optJSONObject("links"); - this.links = (jol == null) ? (new FeedLinks()) : (new FeedLinks(jol)); - } catch (InvalidObjectException e) { - throw e; - } catch (Exception e) { - throw new InvalidObjectException("invalid JSON: " + e.getMessage()); - } - } public int getFeedid() { return feedid; } + /** + * Set feedid with FeedLinks. + * @param feedid Feedid to set to + */ public void setFeedid(int feedid) { this.feedid = feedid; @@ -388,6 +466,14 @@ public class Feed extends Syncable { fl.setLog(URLUtilities.generateFeedLogURL(feedid)); } + public String getAafInstance() { + return aafInstance; + } + + public void setAafInstance(String aafInstance) { + this.aafInstance = aafInstance; + } + //new getter setters for groups- Rally:US708115 - 1610 public int getGroupid() { return groupid; @@ -422,12 +508,12 @@ public class Feed extends Syncable { } // New field is added - Groups feature Rally:US708102 - 1610 - public String getBusiness_description() { - return business_description; + public String getBusinessDescription() { + return businessDescription; } - public void setBusiness_description(String business_description) { - this.business_description = business_description; + public void setBusinessDescription(String businessDescription) { + this.businessDescription = businessDescription; } public FeedAuthorization getAuthorization() { @@ -442,10 +528,15 @@ public class Feed extends Syncable { return publisher; } + /** + * Set publisher. + * @param publisher Publisher name + */ public void setPublisher(String publisher) { if (publisher != null) { - if (publisher.length() > 8) + if (publisher.length() > 8) { publisher = publisher.substring(0, 8); + } this.publisher = publisher; } } @@ -474,94 +565,100 @@ public class Feed extends Syncable { this.suspended = suspended; } - public Date getLast_mod() { - return last_mod; - } - - public Date getCreated_date() { - return created_date; - } - @Override public JSONObject asJSONObject() { JSONObject jo = new JSONObject(); - jo.put("feedid", feedid); - jo.put("groupid", groupid); //New field is added - Groups feature Rally:US708115 - 1610 + jo.put(feedIDStr, feedid); + //New field is added - Groups feature Rally:US708115 - 1610 + jo.put("groupid", groupid); jo.put("name", name); jo.put("version", version); jo.put("description", description); - jo.put("business_description", business_description); // New field is added - Groups feature Rally:US708102 - 1610 + // New field is added - Groups feature Rally:US708102 - 1610 + jo.put("business_description", businessDescription); jo.put("authorization", authorization.asJSONObject()); jo.put("publisher", publisher); jo.put("links", links.asJSONObject()); - jo.put("deleted", deleted); + jo.put(deletedStr, deleted); jo.put("suspend", suspended); - jo.put("last_mod", last_mod.getTime()); - jo.put("created_date", created_date.getTime()); + jo.put(lastModStr, lastMod.getTime()); + jo.put(createdDateStr, createdDate.getTime()); + jo.put("aaf_instance", aafInstance); return jo; } - public JSONObject asLimitedJSONObject() { + /** + * Method to hide some attributes. + * @param hidepasswords true/false + * @return JSONObject + */ + public JSONObject asJSONObject(boolean hidepasswords) { JSONObject jo = asJSONObject(); - jo.remove("deleted"); - jo.remove("feedid"); - jo.remove("last_mod"); - jo.remove("created_date"); + if (hidepasswords) { + jo.remove(feedIDStr); // we no longer hide passwords, however we do hide these + jo.remove(deletedStr); + jo.remove(lastModStr); + jo.remove(createdDateStr); + } return jo; } - public JSONObject asJSONObject(boolean hidepasswords) { + /** + * Method to limit JSONObject. + * @return JSONObject + */ + public JSONObject asLimitedJSONObject() { JSONObject jo = asJSONObject(); - if (hidepasswords) { - jo.remove("feedid"); // we no longer hide passwords, however we do hide these - jo.remove("deleted"); - jo.remove("last_mod"); - jo.remove("created_date"); - } + jo.remove(deletedStr); + jo.remove(feedIDStr); + jo.remove(lastModStr); + jo.remove(createdDateStr); return jo; } + + @Override - public boolean doDelete(Connection c) { + public boolean doDelete(Connection conn) { boolean rv = true; PreparedStatement ps = null; try { String sql = "delete from FEEDS where FEEDID = ?"; - ps = c.prepareStatement(sql); + ps = conn.prepareStatement(sql); ps.setInt(1, feedid); ps.execute(); } catch (SQLException e) { rv = false; - intlogger.warn("PROV0007 doDelete: " + e.getMessage()); - e.printStackTrace(); + intlogger.error("PROV0007 doDelete: " + e.getMessage(), e); } finally { try { - if(ps!=null) { + if (ps != null) { ps.close(); } } catch (SQLException e) { - e.printStackTrace(); + intlogger.error(SQLEXCEPTION + e.getMessage(), e); } } return rv; } @Override - public synchronized boolean doInsert(Connection c) { + public synchronized boolean doInsert(Connection conn) { boolean rv = true; try { if (feedid == -1) { - setFeedid(next_feedid++); + setFeedid(nextFeedID++); } // In case we insert a feed from synchronization - if (feedid > next_feedid) - next_feedid = feedid + 1; + if (feedid > nextFeedID) { + nextFeedID = feedid + 1; + } // Create FEED_ENDPOINT_IDS rows FeedAuthorization auth = getAuthorization(); String sql = "insert into FEED_ENDPOINT_IDS values (?, ?, ?)"; - try(PreparedStatement ps2 = c.prepareStatement(sql)) { - for (FeedEndpointID fid : auth.getEndpoint_ids()) { + try (PreparedStatement ps2 = conn.prepareStatement(sql)) { + for (FeedEndpointID fid : auth.getEndpointIDS()) { ps2.setInt(1, feedid); ps2.setString(2, fid.getId()); ps2.setString(3, fid.getPassword()); @@ -571,8 +668,8 @@ public class Feed extends Syncable { // Create FEED_ENDPOINT_ADDRS rows sql = "insert into FEED_ENDPOINT_ADDRS values (?, ?)"; - try(PreparedStatement ps2 = c.prepareStatement(sql)) { - for (String t : auth.getEndpoint_addrs()) { + try (PreparedStatement ps2 = conn.prepareStatement(sql)) { + for (String t : auth.getEndpointAddrs()) { ps2.setInt(1, feedid); ps2.setString(2, t); ps2.executeUpdate(); @@ -580,8 +677,11 @@ public class Feed extends Syncable { } // Finally, create the FEEDS row - sql = "insert into FEEDS (FEEDID, NAME, VERSION, DESCRIPTION, AUTH_CLASS, PUBLISHER, SELF_LINK, PUBLISH_LINK, SUBSCRIBE_LINK, LOG_LINK, DELETED, SUSPENDED,BUSINESS_DESCRIPTION, GROUPID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?, ?)"; - try(PreparedStatement ps2 = c.prepareStatement(sql)) { + sql = "insert into FEEDS (FEEDID, NAME, VERSION, DESCRIPTION, AUTH_CLASS, PUBLISHER, SELF_LINK, " + + "PUBLISH_LINK, SUBSCRIBE_LINK, LOG_LINK, DELETED, SUSPENDED," + + "BUSINESS_DESCRIPTION, GROUPID, AAF_INSTANCE) " + + "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + try (PreparedStatement ps2 = conn.prepareStatement(sql)) { ps2.setInt(1, feedid); ps2.setString(2, getName()); ps2.setString(3, getVersion()); @@ -594,30 +694,30 @@ public class Feed extends Syncable { ps2.setString(10, getLinks().getLog()); ps2.setBoolean(11, isDeleted()); ps2.setBoolean(12, isSuspended()); - ps2.setString(13, getBusiness_description()); // New field is added - Groups feature Rally:US708102 - 1610 - ps2.setInt(14, groupid); //New field is added - Groups feature Rally:US708115 - 1610 + ps2.setString(13, getBusinessDescription()); + ps2.setInt(14, groupid); + ps2.setString(15, getAafInstance()); ps2.executeUpdate(); } } catch (SQLException e) { rv = false; - intlogger.warn("PROV0005 doInsert: " + e.getMessage()); - e.printStackTrace(); + intlogger.error("PROV0005 doInsert: " + e.getMessage(), e); } return rv; } @Override - public boolean doUpdate(Connection c) { + public boolean doUpdate(Connection conn) { boolean rv = true; Feed oldobj = getFeedById(feedid); PreparedStatement ps = null; try { - Set newset = getAuthorization().getEndpoint_ids(); - Set oldset = oldobj.getAuthorization().getEndpoint_ids(); + Set newset = getAuthorization().getEndpointIDS(); + Set oldset = oldobj.getAuthorization().getEndpointIDS(); // Insert new FEED_ENDPOINT_IDS rows String sql = "insert into FEED_ENDPOINT_IDS values (?, ?, ?)"; - ps = c.prepareStatement(sql); + ps = conn.prepareStatement(sql); for (FeedEndpointID fid : newset) { if (!oldset.contains(fid)) { ps.setInt(1, feedid); @@ -630,7 +730,7 @@ public class Feed extends Syncable { // Delete old FEED_ENDPOINT_IDS rows sql = "delete from FEED_ENDPOINT_IDS where FEEDID = ? AND USERID = ? AND PASSWORD = ?"; - ps = c.prepareStatement(sql); + ps = conn.prepareStatement(sql); for (FeedEndpointID fid : oldset) { if (!newset.contains(fid)) { ps.setInt(1, feedid); @@ -642,10 +742,10 @@ public class Feed extends Syncable { ps.close(); // Insert new FEED_ENDPOINT_ADDRS rows - Set newset2 = getAuthorization().getEndpoint_addrs(); - Set oldset2 = oldobj.getAuthorization().getEndpoint_addrs(); + Set newset2 = getAuthorization().getEndpointAddrs(); + Set oldset2 = oldobj.getAuthorization().getEndpointAddrs(); sql = "insert into FEED_ENDPOINT_ADDRS values (?, ?)"; - ps = c.prepareStatement(sql); + ps = conn.prepareStatement(sql); for (String t : newset2) { if (!oldset2.contains(t)) { ps.setInt(1, feedid); @@ -657,7 +757,7 @@ public class Feed extends Syncable { // Delete old FEED_ENDPOINT_ADDRS rows sql = "delete from FEED_ENDPOINT_ADDRS where FEEDID = ? AND ADDR = ?"; - ps = c.prepareStatement(sql); + ps = conn.prepareStatement(sql); for (String t : oldset2) { if (!newset2.contains(t)) { ps.setInt(1, feedid); @@ -668,34 +768,35 @@ public class Feed extends Syncable { ps.close(); // Finally, update the FEEDS row - sql = "update FEEDS set DESCRIPTION = ?, AUTH_CLASS = ?, DELETED = ?, SUSPENDED = ?, BUSINESS_DESCRIPTION=?, GROUPID=? where FEEDID = ?"; - ps = c.prepareStatement(sql); + sql = "update FEEDS set DESCRIPTION = ?, AUTH_CLASS = ?, DELETED = ?, SUSPENDED = ?, " + + "BUSINESS_DESCRIPTION=?, GROUPID=? where FEEDID = ?"; + ps = conn.prepareStatement(sql); ps.setString(1, getDescription()); ps.setString(2, getAuthorization().getClassification()); ps.setInt(3, deleted ? 1 : 0); ps.setInt(4, suspended ? 1 : 0); - ps.setString(5, getBusiness_description()); // New field is added - Groups feature Rally:US708102 - 1610 - ps.setInt(6, groupid); //New field is added - Groups feature Rally:US708115 - 1610 + ps.setString(5, getBusinessDescription()); + ps.setInt(6, groupid); ps.setInt(7, feedid); ps.executeUpdate(); ps.close(); } catch (SQLException e) { rv = false; - intlogger.warn("PROV0006 doUpdate: " + e.getMessage()); - e.printStackTrace(); + intlogger.warn("PROV0006 doUpdate: " + e.getMessage(), e); } finally { try { - if (ps != null) + if (ps != null) { ps.close(); + } } catch (SQLException e) { - e.printStackTrace(); + intlogger.error(SQLEXCEPTION + e.getMessage(), e); } } return rv; } /** - * Rally US708115 + * Rally US708115. * Change Ownership of FEED - 1610 */ public boolean changeOwnerShip() { @@ -705,24 +806,23 @@ public class Feed extends Syncable { DB db = new DB(); @SuppressWarnings("resource") - Connection c = db.getConnection(); + Connection conn = db.getConnection(); String sql = "update FEEDS set PUBLISHER = ? where FEEDID = ?"; - ps = c.prepareStatement(sql); + ps = conn.prepareStatement(sql); ps.setString(1, this.publisher); ps.setInt(2, feedid); ps.execute(); ps.close(); } catch (SQLException e) { rv = false; - intlogger.warn("PROV0006 doUpdate: " + e.getMessage()); - e.printStackTrace(); + intlogger.warn("PROV0008 changeOwnerShip: " + e.getMessage(), e); } finally { try { - if(ps!=null) { + if (ps != null) { ps.close(); } } catch (SQLException e) { - e.printStackTrace(); + intlogger.error(SQLEXCEPTION + e.getMessage(), e); } } return rv; @@ -736,31 +836,48 @@ public class Feed extends Syncable { @Override public boolean equals(Object obj) { - if (!(obj instanceof Feed)) + if (!(obj instanceof Feed)) { return false; + } Feed of = (Feed) obj; - if (feedid != of.feedid) + if (feedid != of.feedid) { return false; - if (groupid != of.groupid) //New field is added - Groups feature Rally:US708115 - 1610 + } + if (groupid != of.groupid) { + //New field is added - Groups feature Rally:US708115 - 1610 return false; - if (!name.equals(of.name)) + } + if (!name.equals(of.name)) { return false; - if (!version.equals(of.version)) + } + if (!version.equals(of.version)) { return false; - if (!description.equals(of.description)) + } + if (!description.equals(of.description)) { return false; - if (!business_description.equals(of.business_description)) // New field is added - Groups feature Rally:US708102 - 1610 + } + if (!businessDescription.equals(of.businessDescription)) { + // New field is added - Groups feature Rally:US708102 - 1610 return false; - if (!publisher.equals(of.publisher)) + } + if (!publisher.equals(of.publisher)) { return false; - if (!authorization.equals(of.authorization)) + } + if (!authorization.equals(of.authorization)) { return false; - if (!links.equals(of.links)) + } + if (!links.equals(of.links)) { + return false; + } + if (deleted != of.deleted) { return false; - if (deleted != of.deleted) + } + if (suspended != of.suspended) { return false; - if (suspended != of.suspended) + } + if (!aafInstance.equals(of.aafInstance)) { return false; + } return true; } @@ -771,6 +888,6 @@ public class Feed extends Syncable { @Override public int hashCode() { - return Objects.hash(feedid, groupid, name, version, description, business_description, authorization, publisher, links, deleted, suspended, last_mod, created_date); + return super.hashCode(); } -} +} \ No newline at end of file