1 /*******************************************************************************
\r
2 * ============LICENSE_START==================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * ===========================================================================
\r
7 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * * you may not use this file except in compliance with the License.
\r
9 * * You may obtain a copy of the License at
\r
11 * * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * * Unless required by applicable law or agreed to in writing, software
\r
14 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * * See the License for the specific language governing permissions and
\r
17 * * limitations under the License.
\r
18 * * ============LICENSE_END====================================================
\r
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
25 package org.onap.dmaap.datarouter.provisioning.beans;
\r
27 import org.apache.log4j.Level;
\r
28 import org.apache.log4j.Logger;
\r
29 import org.json.JSONArray;
\r
30 import org.json.JSONException;
\r
31 import org.json.JSONObject;
\r
32 import org.onap.dmaap.datarouter.provisioning.utils.DB;
\r
33 import org.onap.dmaap.datarouter.provisioning.utils.JSONUtilities;
\r
34 import org.onap.dmaap.datarouter.provisioning.utils.PasswordProcessor;
\r
35 import org.onap.dmaap.datarouter.provisioning.utils.URLUtilities;
\r
37 import java.io.InvalidObjectException;
\r
38 import java.security.GeneralSecurityException;
\r
40 import java.util.Date;
\r
44 * The representation of a Feed. Feeds can be retrieved from the DB, or stored/updated in the DB.
\r
46 * @author Robert Eby
\r
47 * @version $Id: Feed.java,v 1.13 2013/10/28 18:06:52 eby Exp $
\r
49 public class Feed extends Syncable {
\r
50 private static Logger intlogger = Logger.getLogger("org.onap.dmaap.datarouter.provisioning.internal");
\r
51 private static int next_feedid = getMaxFeedID() + 1;
\r
54 private int groupid; //New field is added - Groups feature Rally:US708115 - 1610
\r
55 private String name;
\r
56 private String version;
\r
57 private String description;
\r
58 private String business_description; // New field is added - Groups feature Rally:US708102 - 1610
\r
59 private FeedAuthorization authorization;
\r
60 private String publisher;
\r
61 private FeedLinks links;
\r
62 private boolean deleted;
\r
63 private boolean suspended;
\r
64 private Date last_mod;
\r
65 private Date created_date;
\r
66 private String aaf_instance;
\r
69 * Check if a feed ID is valid.
\r
71 * @param id the Feed ID
\r
72 * @return true if it is valid
\r
74 @SuppressWarnings("resource")
\r
75 public static boolean isFeedValid(int id) {
\r
79 Connection conn = db.getConnection();
\r
80 try(PreparedStatement stmt = conn.prepareStatement("select COUNT(*) from FEEDS where FEEDID = ?")) {
\r
82 try(ResultSet rs = stmt.executeQuery()) {
\r
84 count = rs.getInt(1);
\r
89 } catch (SQLException e) {
\r
90 intlogger.log(Level.WARN, "PROV0024 Feed.isFeedValid: ", e);
\r
96 * Get a specific feed from the DB, based upon its ID.
\r
98 * @param id the Feed ID
\r
99 * @return the Feed object, or null if it does not exist
\r
101 public static Feed getFeedById(int id) {
\r
102 String sql = "select * from FEEDS where FEEDID = " + id;
\r
103 return getFeedBySQL(sql);
\r
107 * Get a specific feed from the DB, based upon its name and version.
\r
109 * @param name the name of the Feed
\r
110 * @param version the version of the Feed
\r
111 * @return the Feed object, or null if it does not exist
\r
113 public static Feed getFeedByNameVersion(String name, String version) {
\r
114 name = name.replaceAll("'", "''");
\r
115 version = version.replaceAll("'", "''");
\r
116 String sql = "select * from FEEDS where NAME = '" + name + "' and VERSION ='" + version + "'";
\r
117 return getFeedBySQL(sql);
\r
121 * Return a count of the number of active feeds in the DB.
\r
123 * @return the count
\r
125 public static int countActiveFeeds() {
\r
129 @SuppressWarnings("resource")
\r
130 Connection conn = db.getConnection();
\r
131 try(Statement stmt = conn.createStatement()) {
\r
132 try (ResultSet rs = stmt.executeQuery("select count(*) from FEEDS where DELETED = 0")) {
\r
134 count = rs.getInt(1);
\r
139 } catch (SQLException e) {
\r
140 intlogger.info("PROV0025 Feed.countActiveFeeds: " + e.getMessage());
\r
141 intlogger.log(Level.WARN, "PROV0025 Feed.countActiveFeeds: ", e);
\r
146 public static int getMaxFeedID() {
\r
150 @SuppressWarnings("resource")
\r
151 Connection conn = db.getConnection();
\r
152 try(Statement stmt = conn.createStatement()) {
\r
153 try (ResultSet rs = stmt.executeQuery("select MAX(feedid) from FEEDS")) {
\r
155 max = rs.getInt(1);
\r
160 } catch (SQLException e) {
\r
161 intlogger.info("PROV0026 Feed.getMaxFeedID: "+e.getMessage());
\r
162 intlogger.log(Level.WARN, "PROV0026 Feed.getMaxFeedID: ", e);
\r
167 public static Collection<Feed> getAllFeeds() {
\r
168 Map<Integer, Feed> map = new HashMap<Integer, Feed>();
\r
171 @SuppressWarnings("resource")
\r
172 Connection conn = db.getConnection();
\r
173 try(Statement stmt = conn.createStatement()) {
\r
174 try(ResultSet rs = stmt.executeQuery("select * from FEEDS")) {
\r
175 while (rs.next()) {
\r
176 Feed feed = new Feed(rs);
\r
177 map.put(feed.getFeedid(), feed);
\r
181 String sql = "select * from FEED_ENDPOINT_IDS";
\r
182 try(ResultSet rs = stmt.executeQuery(sql)){
\r
183 while (rs.next()) {
\r
184 int id = rs.getInt("FEEDID");
\r
185 Feed feed = map.get(id);
\r
186 if (feed != null) {
\r
187 FeedEndpointID epi = new FeedEndpointID(rs);
\r
188 Collection<FeedEndpointID> ecoll = feed.getAuthorization().getEndpoint_ids();
\r
194 sql = "select * from FEED_ENDPOINT_ADDRS";
\r
195 try(ResultSet rs = stmt.executeQuery(sql)) {
\r
196 while (rs.next()) {
\r
197 int id = rs.getInt("FEEDID");
\r
198 Feed feed = map.get(id);
\r
199 if (feed != null) {
\r
200 Collection<String> acoll = feed.getAuthorization().getEndpoint_addrs();
\r
201 acoll.add(rs.getString("ADDR"));
\r
207 } catch (SQLException e) {
\r
208 intlogger.log(Level.WARN, "PROV0027 Feed.getAllFeeds: ", e);
\r
210 return map.values();
\r
213 public static List<String> getFilteredFeedUrlList(final String name, final String val) {
\r
214 List<String> list = new ArrayList<String>();
\r
215 String sql = "select SELF_LINK from FEEDS where DELETED = 0";
\r
216 if (name.equals("name")) {
\r
217 sql += " and NAME = ?";
\r
218 } else if (name.equals("publ")) {
\r
219 sql += " and PUBLISHER = ?";
\r
220 } else if (name.equals("subs")) {
\r
221 sql = "select distinct FEEDS.SELF_LINK from FEEDS, SUBSCRIPTIONS " +
\r
222 "where DELETED = 0 " +
\r
223 "and FEEDS.FEEDID = SUBSCRIPTIONS.FEEDID " +
\r
224 "and SUBSCRIPTIONS.SUBSCRIBER = ?";
\r
228 @SuppressWarnings("resource")
\r
229 Connection conn = db.getConnection();
\r
230 try(PreparedStatement ps = conn.prepareStatement(sql)) {
\r
231 if (sql.indexOf('?') >= 0)
\r
232 ps.setString(1, val);
\r
233 try(ResultSet rs = ps.executeQuery()) {
\r
234 while (rs.next()) {
\r
235 String t = rs.getString(1);
\r
236 list.add(t.trim());
\r
241 } catch (SQLException e) {
\r
242 intlogger.log(Level.WARN, "PROV0028 Feed.getFilteredFeedUrlList: ", e);
\r
247 @SuppressWarnings("resource")
\r
248 private static Feed getFeedBySQL(String sql) {
\r
252 Connection conn = db.getConnection();
\r
253 try (Statement stmt = conn.createStatement()) {
\r
254 try (ResultSet rs = stmt.executeQuery(sql)) {
\r
256 feed = new Feed(rs);
\r
259 if (feed != null) {
\r
260 sql = "select * from FEED_ENDPOINT_IDS where FEEDID = " + feed.feedid;
\r
261 try (ResultSet rs = stmt.executeQuery(sql)) {
\r
262 Collection<FeedEndpointID> ecoll = feed.getAuthorization().getEndpoint_ids();
\r
263 while (rs.next()) {
\r
264 FeedEndpointID epi = new FeedEndpointID(rs);
\r
268 sql = "select * from FEED_ENDPOINT_ADDRS where FEEDID = " + feed.feedid;
\r
269 try (ResultSet rs = stmt.executeQuery(sql)) {
\r
270 Collection<String> acoll = feed.getAuthorization().getEndpoint_addrs();
\r
271 while (rs.next()) {
\r
272 acoll.add(rs.getString("ADDR"));
\r
278 } catch (SQLException e) {
\r
279 intlogger.log(Level.WARN, "PROV0029 Feed.getFeedBySQL: ", e);
\r
285 this("", "", "", "");
\r
288 public Feed(String name, String version, String desc, String business_description) {
\r
290 this.groupid = -1; //New field is added - Groups feature Rally:US708115 - 1610
\r
292 this.version = version;
\r
293 this.description = desc;
\r
294 this.business_description = business_description; // New field is added - Groups feature Rally:US708102 - 1610
\r
295 this.authorization = new FeedAuthorization();
\r
296 this.publisher = "";
\r
297 this.links = new FeedLinks();
\r
298 this.deleted = false;
\r
299 this.suspended = false;
\r
300 this.last_mod = new Date();
\r
301 this.created_date = new Date();
\r
302 this.aaf_instance = "";
\r
305 public Feed(ResultSet rs) throws SQLException {
\r
306 this.feedid = rs.getInt("FEEDID");
\r
307 this.groupid = rs.getInt("GROUPID"); //New field is added - Groups feature Rally:US708115 - 1610
\r
308 this.name = rs.getString("NAME");
\r
309 this.version = rs.getString("VERSION");
\r
310 this.description = rs.getString("DESCRIPTION");
\r
311 this.business_description = rs.getString("BUSINESS_DESCRIPTION"); // New field is added - Groups feature Rally:US708102 - 1610
\r
312 this.authorization = new FeedAuthorization();
\r
313 this.authorization.setClassification(rs.getString("AUTH_CLASS"));
\r
314 this.publisher = rs.getString("PUBLISHER");
\r
315 this.links = new FeedLinks();
\r
316 this.links.setSelf(rs.getString("SELF_LINK"));
\r
317 this.links.setPublish(rs.getString("PUBLISH_LINK"));
\r
318 this.links.setSubscribe(rs.getString("SUBSCRIBE_LINK"));
\r
319 this.links.setLog(rs.getString("LOG_LINK"));
\r
320 this.deleted = rs.getBoolean("DELETED");
\r
321 this.suspended = rs.getBoolean("SUSPENDED");
\r
322 this.last_mod = rs.getDate("LAST_MOD");
\r
323 this.created_date = rs.getTimestamp("CREATED_DATE");
\r
324 this.aaf_instance = rs.getString("AAF_INSTANCE");
\r
327 public Feed(JSONObject jo) throws InvalidObjectException {
\r
328 this("", "", "", "");
\r
330 // The JSONObject is assumed to contain a vnd.dmaap-dr.feed representation
\r
331 this.feedid = jo.optInt("feedid", -1);
\r
332 this.groupid = jo.optInt("groupid");
\r
333 this.name = jo.getString("name");
\r
334 this.aaf_instance = jo.optString("aaf_instance", "legacy");
\r
335 if(!(aaf_instance.equalsIgnoreCase("legacy"))){
\r
336 if (aaf_instance.length() > 255){
\r
337 throw new InvalidObjectException("aaf_instance field is too long");
\r
340 if (name.length() > 255)
\r
341 throw new InvalidObjectException("name field is too long");
\r
343 this.version = jo.getString("version");
\r
344 } catch (JSONException e) {
\r
345 this.version = null;
\r
347 if(version != null && version.length() > 20)
\r
348 throw new InvalidObjectException("version field is too long");
\r
349 this.description = jo.optString("description");
\r
350 this.business_description = jo.optString("business_description");
\r
351 if (description.length() > 1000)
\r
352 throw new InvalidObjectException("technical description field is too long");
\r
353 if (business_description.length() > 1000)
\r
354 throw new InvalidObjectException("business description field is too long");
\r
355 this.authorization = new FeedAuthorization();
\r
356 JSONObject jauth = jo.getJSONObject("authorization");
\r
357 this.authorization.setClassification(jauth.getString("classification"));
\r
358 if (this.authorization.getClassification().length() > 32)
\r
359 throw new InvalidObjectException("classification field is too long");
\r
360 JSONArray endPointIds = jauth.getJSONArray("endpoint_ids");
\r
361 for (int i = 0; i < endPointIds.length(); i++) {
\r
362 JSONObject id = endPointIds.getJSONObject(i);
\r
363 FeedEndpointID fid = new FeedEndpointID(id.getString("id"), id.getString("password"));
\r
364 if (fid.getId().length() > 60)
\r
365 throw new InvalidObjectException("id field is too long (" + fid.getId() + ")");
\r
366 if (fid.getPassword().length() > 32)
\r
367 throw new InvalidObjectException("password field is too long ("+ fid.getPassword()+")"); //Fortify scan fixes - Privacy Violation
\r
368 this.authorization.getEndpoint_ids().add(fid);
\r
370 if (this.authorization.getEndpoint_ids().size() < 1)
\r
371 throw new InvalidObjectException("need to specify at least one endpoint_id");
\r
372 endPointIds = jauth.getJSONArray("endpoint_addrs");
\r
373 for (int i = 0; i < endPointIds.length(); i++) {
\r
374 String addr = endPointIds.getString(i);
\r
375 if (!JSONUtilities.validIPAddrOrSubnet(addr))
\r
376 throw new InvalidObjectException("bad IP addr or subnet mask: " + addr);
\r
377 this.authorization.getEndpoint_addrs().add(addr);
\r
380 this.publisher = jo.optString("publisher", "");
\r
381 this.deleted = jo.optBoolean("deleted", false);
\r
382 this.suspended = jo.optBoolean("suspend", false);
\r
383 JSONObject jol = jo.optJSONObject("links");
\r
384 this.links = (jol == null) ? (new FeedLinks()) : (new FeedLinks(jol));
\r
385 } catch (InvalidObjectException e) {
\r
386 intlogger.log(Level.WARN, "PROV0030 Feed.Feed: ", e);
\r
388 } catch (Exception e) {
\r
389 intlogger.error("PROV0031 Feed.Feed: invalid JSON: "+e);
\r
390 throw new InvalidObjectException("invalid JSON: " + e.getMessage());
\r
394 public int getFeedid() {
\r
398 public void setFeedid(int feedid) {
\r
399 this.feedid = feedid;
\r
401 // Create link URLs
\r
402 FeedLinks fl = getLinks();
\r
403 fl.setSelf(URLUtilities.generateFeedURL(feedid));
\r
404 fl.setPublish(URLUtilities.generatePublishURL(feedid));
\r
405 fl.setSubscribe(URLUtilities.generateSubscribeURL(feedid));
\r
406 fl.setLog(URLUtilities.generateFeedLogURL(feedid));
\r
409 public String getAafInstance() {
\r
410 return aaf_instance;
\r
413 public void setAaf_instance(String aaf_instance) {
\r
414 this.aaf_instance = aaf_instance;
\r
417 //new getter setters for groups- Rally:US708115 - 1610
\r
418 public int getGroupid() {
\r
422 public void setGroupid(int groupid) {
\r
423 this.groupid = groupid;
\r
426 public String getName() {
\r
430 public void setName(String name) {
\r
434 public String getVersion() {
\r
438 public void setVersion(String version) {
\r
439 this.version = version;
\r
442 public String getDescription() {
\r
443 return description;
\r
446 public void setDescription(String description) {
\r
447 this.description = description;
\r
450 // New field is added - Groups feature Rally:US708102 - 1610
\r
451 public String getBusiness_description() {
\r
452 return business_description;
\r
455 public void setBusiness_description(String business_description) {
\r
456 this.business_description = business_description;
\r
459 public FeedAuthorization getAuthorization() {
\r
460 return authorization;
\r
463 public void setAuthorization(FeedAuthorization authorization) {
\r
464 this.authorization = authorization;
\r
467 public String getPublisher() {
\r
471 public void setPublisher(String publisher) {
\r
472 if (publisher != null) {
\r
473 if (publisher.length() > 8)
\r
474 publisher = publisher.substring(0, 8);
\r
475 this.publisher = publisher;
\r
479 public FeedLinks getLinks() {
\r
483 public void setLinks(FeedLinks links) {
\r
484 this.links = links;
\r
487 public boolean isDeleted() {
\r
491 public void setDeleted(boolean deleted) {
\r
492 this.deleted = deleted;
\r
495 public boolean isSuspended() {
\r
499 public void setSuspended(boolean suspended) {
\r
500 this.suspended = suspended;
\r
503 public Date getLast_mod() {
\r
507 public Date getCreated_date() {
\r
508 return created_date;
\r
512 public JSONObject asJSONObject() {
\r
513 JSONObject jo = new JSONObject();
\r
514 jo.put("feedid", feedid);
\r
515 jo.put("groupid", groupid); //New field is added - Groups feature Rally:US708115 - 1610
\r
516 jo.put("name", name);
\r
517 jo.put("version", version);
\r
518 jo.put("description", description);
\r
519 jo.put("business_description", business_description); // New field is added - Groups feature Rally:US708102 - 1610
\r
520 jo.put("authorization", authorization.asJSONObject());
\r
521 jo.put("publisher", publisher);
\r
522 jo.put("links", links.asJSONObject());
\r
523 jo.put("deleted", deleted);
\r
524 jo.put("suspend", suspended);
\r
525 jo.put("last_mod", last_mod.getTime());
\r
526 jo.put("created_date", created_date.getTime());
\r
527 jo.put("aaf_instance", aaf_instance);
\r
531 public JSONObject asLimitedJSONObject() {
\r
532 JSONObject jo = asJSONObject();
\r
533 jo.remove("deleted");
\r
534 jo.remove("feedid");
\r
535 jo.remove("last_mod");
\r
536 jo.remove("created_date");
\r
540 public JSONObject asJSONObject(boolean hidepasswords) {
\r
541 JSONObject jo = asJSONObject();
\r
542 if (hidepasswords) {
\r
543 jo.remove("feedid"); // we no longer hide passwords, however we do hide these
\r
544 jo.remove("deleted");
\r
545 jo.remove("last_mod");
\r
546 jo.remove("created_date");
\r
552 public boolean doDelete(Connection c) {
\r
554 PreparedStatement ps = null;
\r
556 String sql = "delete from FEEDS where FEEDID = ?";
\r
557 ps = c.prepareStatement(sql);
\r
558 ps.setInt(1, feedid);
\r
560 } catch (SQLException e) {
\r
562 intlogger.warn("PROV0007 doDelete: " + e.getMessage());
\r
563 intlogger.error("SQLException " + e.getMessage());
\r
569 } catch (SQLException e) {
\r
570 intlogger.error("SQLException " + e.getMessage());
\r
577 public synchronized boolean doInsert(Connection c) {
\r
580 if (feedid == -1) {
\r
581 setFeedid(next_feedid++);
\r
583 // In case we insert a feed from synchronization
\r
584 if (feedid > next_feedid)
\r
585 next_feedid = feedid + 1;
\r
587 // Create FEED_ENDPOINT_IDS rows
\r
588 FeedAuthorization auth = getAuthorization();
\r
589 String sql = "insert into FEED_ENDPOINT_IDS values (?, ?, ?)";
\r
590 try(PreparedStatement ps2 = c.prepareStatement(sql)) {
\r
591 for (FeedEndpointID fid : auth.getEndpoint_ids()) {
\r
592 ps2.setInt(1, feedid);
\r
593 ps2.setString(2, fid.getId());
\r
594 ps2.setString(3, fid.getPassword());
\r
595 ps2.executeUpdate();
\r
599 // Create FEED_ENDPOINT_ADDRS rows
\r
600 sql = "insert into FEED_ENDPOINT_ADDRS values (?, ?)";
\r
601 try(PreparedStatement ps2 = c.prepareStatement(sql)) {
\r
602 for (String t : auth.getEndpoint_addrs()) {
\r
603 ps2.setInt(1, feedid);
\r
604 ps2.setString(2, t);
\r
605 ps2.executeUpdate();
\r
609 // Finally, create the FEEDS row
\r
610 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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
\r
611 try(PreparedStatement ps2 = c.prepareStatement(sql)) {
\r
612 ps2.setInt(1, feedid);
\r
613 ps2.setString(2, getName());
\r
614 ps2.setString(3, getVersion());
\r
615 ps2.setString(4, getDescription());
\r
616 ps2.setString(5, getAuthorization().getClassification());
\r
617 ps2.setString(6, getPublisher());
\r
618 ps2.setString(7, getLinks().getSelf());
\r
619 ps2.setString(8, getLinks().getPublish());
\r
620 ps2.setString(9, getLinks().getSubscribe());
\r
621 ps2.setString(10, getLinks().getLog());
\r
622 ps2.setBoolean(11, isDeleted());
\r
623 ps2.setBoolean(12, isSuspended());
\r
624 ps2.setString(13, getBusiness_description());
\r
625 ps2.setInt(14, groupid);
\r
626 ps2.setString(15, getAafInstance());
\r
627 ps2.executeUpdate();
\r
629 } catch (SQLException e) {
\r
631 intlogger.warn("PROV0005 doInsert: " + e.getMessage());
\r
632 intlogger.error("SQLException " + e.getMessage());
\r
638 public boolean doUpdate(Connection c) {
\r
640 Feed oldobj = getFeedById(feedid);
\r
641 PreparedStatement ps = null;
\r
643 Set<FeedEndpointID> newset = getAuthorization().getEndpoint_ids();
\r
644 Set<FeedEndpointID> oldset = oldobj.getAuthorization().getEndpoint_ids();
\r
646 // Insert new FEED_ENDPOINT_IDS rows
\r
647 String sql = "insert into FEED_ENDPOINT_IDS values (?, ?, ?)";
\r
648 ps = c.prepareStatement(sql);
\r
649 for (FeedEndpointID fid : newset) {
\r
650 if (!oldset.contains(fid)) {
\r
651 ps.setInt(1, feedid);
\r
652 ps.setString(2, fid.getId());
\r
653 ps.setString(3, fid.getPassword());
\r
654 ps.executeUpdate();
\r
659 // Delete old FEED_ENDPOINT_IDS rows
\r
660 sql = "delete from FEED_ENDPOINT_IDS where FEEDID = ? AND USERID = ? AND PASSWORD = ?";
\r
661 ps = c.prepareStatement(sql);
\r
662 for (FeedEndpointID fid : oldset) {
\r
663 if (!newset.contains(fid)) {
\r
664 ps.setInt(1, feedid);
\r
665 ps.setString(2, fid.getId());
\r
666 ps.setString(3, fid.getPassword());
\r
667 ps.executeUpdate();
\r
672 // Insert new FEED_ENDPOINT_ADDRS rows
\r
673 Set<String> newset2 = getAuthorization().getEndpoint_addrs();
\r
674 Set<String> oldset2 = oldobj.getAuthorization().getEndpoint_addrs();
\r
675 sql = "insert into FEED_ENDPOINT_ADDRS values (?, ?)";
\r
676 ps = c.prepareStatement(sql);
\r
677 for (String t : newset2) {
\r
678 if (!oldset2.contains(t)) {
\r
679 ps.setInt(1, feedid);
\r
680 ps.setString(2, t);
\r
681 ps.executeUpdate();
\r
686 // Delete old FEED_ENDPOINT_ADDRS rows
\r
687 sql = "delete from FEED_ENDPOINT_ADDRS where FEEDID = ? AND ADDR = ?";
\r
688 ps = c.prepareStatement(sql);
\r
689 for (String t : oldset2) {
\r
690 if (!newset2.contains(t)) {
\r
691 ps.setInt(1, feedid);
\r
692 ps.setString(2, t);
\r
693 ps.executeUpdate();
\r
698 // Finally, update the FEEDS row
\r
699 sql = "update FEEDS set DESCRIPTION = ?, AUTH_CLASS = ?, DELETED = ?, SUSPENDED = ?, BUSINESS_DESCRIPTION=?, GROUPID=? where FEEDID = ?";
\r
700 ps = c.prepareStatement(sql);
\r
701 ps.setString(1, getDescription());
\r
702 ps.setString(2, getAuthorization().getClassification());
\r
703 ps.setInt(3, deleted ? 1 : 0);
\r
704 ps.setInt(4, suspended ? 1 : 0);
\r
705 ps.setString(5, getBusiness_description());
\r
706 ps.setInt(6, groupid);
\r
707 ps.setInt(7, feedid);
\r
708 ps.executeUpdate();
\r
710 } catch (SQLException e) {
\r
712 intlogger.warn("PROV0006 doUpdate: " + e.getMessage());
\r
717 } catch (SQLException e) {
\r
718 intlogger.error("SQLException " + e.getMessage());
\r
726 * Change Ownership of FEED - 1610
\r
728 public boolean changeOwnerShip() {
\r
730 PreparedStatement ps = null;
\r
734 @SuppressWarnings("resource")
\r
735 Connection c = db.getConnection();
\r
736 String sql = "update FEEDS set PUBLISHER = ? where FEEDID = ?";
\r
737 ps = c.prepareStatement(sql);
\r
738 ps.setString(1, this.publisher);
\r
739 ps.setInt(2, feedid);
\r
742 } catch (SQLException e) {
\r
744 intlogger.warn("PROV0006 doUpdate: " + e.getMessage());
\r
750 } catch (SQLException e) {
\r
751 intlogger.error("SQLException " + e.getMessage());
\r
759 public String getKey() {
\r
760 return "" + getFeedid();
\r
764 public boolean equals(Object obj) {
\r
765 if (!(obj instanceof Feed))
\r
767 Feed of = (Feed) obj;
\r
768 if (feedid != of.feedid)
\r
770 if (groupid != of.groupid) //New field is added - Groups feature Rally:US708115 - 1610
\r
772 if (!name.equals(of.name))
\r
774 if (!version.equals(of.version))
\r
776 if (!description.equals(of.description))
\r
778 if (!business_description.equals(of.business_description)) // New field is added - Groups feature Rally:US708102 - 1610
\r
780 if (!publisher.equals(of.publisher))
\r
782 if (!authorization.equals(of.authorization))
\r
784 if (!links.equals(of.links))
\r
786 if (deleted != of.deleted)
\r
788 if (suspended != of.suspended)
\r
790 if (!aaf_instance.equals(of.aaf_instance))
\r
796 public String toString() {
\r
797 return "FEED: feedid=" + feedid + ", name=" + name + ", version=" + version;
\r
801 public int hashCode() {
\r
802 return super.hashCode();
\r