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 com.att.eelf.configuration.EELFLogger;
\r
28 import com.att.eelf.configuration.EELFManager;
\r
29 import java.io.InvalidObjectException;
\r
30 import java.sql.Connection;
\r
31 import java.sql.PreparedStatement;
\r
32 import java.sql.ResultSet;
\r
33 import java.sql.SQLException;
\r
34 import java.sql.Statement;
\r
35 import java.util.ArrayList;
\r
36 import java.util.Collection;
\r
37 import java.util.Date;
\r
38 import java.util.HashMap;
\r
39 import java.util.List;
\r
40 import java.util.Map;
\r
41 import java.util.Set;
\r
42 import org.json.JSONArray;
\r
43 import org.json.JSONException;
\r
44 import org.json.JSONObject;
\r
45 import org.onap.dmaap.datarouter.provisioning.utils.DB;
\r
46 import org.onap.dmaap.datarouter.provisioning.utils.JSONUtilities;
\r
47 import org.onap.dmaap.datarouter.provisioning.utils.URLUtilities;
\r
52 * The representation of a Feed. Feeds can be retrieved from the DB, or stored/updated in the DB.
\r
54 * @author Robert Eby
\r
55 * @version $Id: Feed.java,v 1.13 2013/10/28 18:06:52 eby Exp $
\r
57 public class Feed extends Syncable {
\r
59 private static EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");
\r
60 private static int nextFeedID = getMaxFeedID() + 1;
\r
61 private static final String SQLEXCEPTION = "SQLException: ";
\r
62 private static final String FEED_ID_SQL = "FEEDID";
\r
63 private static final String FEED_ID = "feedid";
\r
64 private static final String DEL = "deleted";
\r
65 private static final String LAST_MOD = "last_mod";
\r
66 private static final String CREATED_DATE = "created_date";
\r
69 private int groupid; //New field is added - Groups feature Rally:US708115 - 1610
\r
70 private String name;
\r
71 private String version;
\r
72 private String description;
\r
73 private String businessDescription; // New field is added - Groups feature Rally:US708102 - 1610
\r
74 private FeedAuthorization authorization;
\r
75 private String publisher;
\r
76 private FeedLinks links;
\r
77 private boolean deleted;
\r
78 private boolean suspended;
\r
79 private Date lastMod;
\r
80 private Date createdDate;
\r
81 private String aafInstance;
\r
84 this("", "", "", "");
\r
89 * @param name feed name
\r
90 * @param version feed version
\r
91 * @param desc feed description
\r
92 * @param businessDescription feed business description
\r
94 public Feed(String name, String version, String desc, String businessDescription) {
\r
96 this.groupid = -1; //New field is added - Groups feature Rally:US708115 - 1610
\r
98 this.version = version;
\r
99 this.description = desc;
\r
100 this.businessDescription = businessDescription; // New field is added - Groups feature Rally:US708102 - 1610
\r
101 this.authorization = new FeedAuthorization();
\r
102 this.publisher = "";
\r
103 this.links = new FeedLinks();
\r
104 this.deleted = false;
\r
105 this.suspended = false;
\r
106 this.lastMod = new Date();
\r
107 this.createdDate = new Date();
\r
108 this.aafInstance = "";
\r
112 * Feed Constructor from ResultSet.
\r
113 * @param rs ResultSet
\r
114 * @throws SQLException in case of SQL statement error
\r
116 public Feed(ResultSet rs) throws SQLException {
\r
117 this.feedid = rs.getInt(FEED_ID_SQL);
\r
118 //New field is added - Groups feature Rally:US708115 - 1610
\r
119 this.groupid = rs.getInt("GROUPID");
\r
120 this.name = rs.getString("NAME");
\r
121 this.version = rs.getString("VERSION");
\r
122 this.description = rs.getString("DESCRIPTION");
\r
123 // New field is added - Groups feature Rally:US708102 - 1610
\r
124 this.businessDescription = rs.getString("BUSINESS_DESCRIPTION");
\r
125 this.authorization = new FeedAuthorization();
\r
126 this.authorization.setClassification(rs.getString("AUTH_CLASS"));
\r
127 this.publisher = rs.getString("PUBLISHER");
\r
128 this.links = new FeedLinks();
\r
129 this.links.setSelf(rs.getString("SELF_LINK"));
\r
130 this.links.setPublish(rs.getString("PUBLISH_LINK"));
\r
131 this.links.setSubscribe(rs.getString("SUBSCRIBE_LINK"));
\r
132 this.links.setLog(rs.getString("LOG_LINK"));
\r
133 this.deleted = rs.getBoolean("DELETED");
\r
134 this.suspended = rs.getBoolean("SUSPENDED");
\r
135 this.lastMod = rs.getDate("LAST_MOD");
\r
136 this.createdDate = rs.getTimestamp("CREATED_DATE");
\r
137 this.aafInstance = rs.getString("AAF_INSTANCE");
\r
141 * Feed constructor from JSONObject.
\r
142 * @param jo JSONObject
\r
143 * @throws InvalidObjectException in case of JSON error
\r
145 public Feed(JSONObject jo) throws InvalidObjectException {
\r
146 this("", "", "", "");
\r
148 // The JSONObject is assumed to contain a vnd.dmaap-dr.feed representation
\r
149 this.feedid = jo.optInt(FEED_ID, -1);
\r
150 this.groupid = jo.optInt("groupid");
\r
151 this.name = jo.getString("name");
\r
152 this.aafInstance = jo.optString("aaf_instance", "legacy");
\r
153 if (!(aafInstance.equalsIgnoreCase("legacy")) && aafInstance.length() > 255) {
\r
154 throw new InvalidObjectException("aaf_instance field is too long");
\r
156 if (name.length() > 255) {
\r
157 throw new InvalidObjectException("name field is too long");
\r
160 this.version = jo.getString("version");
\r
161 } catch (JSONException e) {
\r
162 intlogger.warn("PROV0023 Feed.Feed: " + e.getMessage(), e);
\r
163 this.version = null;
\r
165 if (version != null && version.length() > 20) {
\r
166 throw new InvalidObjectException("version field is too long");
\r
168 this.description = jo.optString("description");
\r
169 this.businessDescription = jo.optString("business_description");
\r
170 if (description.length() > 1000) {
\r
171 throw new InvalidObjectException("technical description field is too long");
\r
173 if (businessDescription.length() > 1000) {
\r
174 throw new InvalidObjectException("business description field is too long");
\r
176 this.authorization = new FeedAuthorization();
\r
177 JSONObject jauth = jo.getJSONObject("authorization");
\r
178 this.authorization.setClassification(jauth.getString("classification"));
\r
179 if (this.authorization.getClassification().length() > 32) {
\r
180 throw new InvalidObjectException("classification field is too long");
\r
182 JSONArray endPointIds = jauth.getJSONArray("endpoint_ids");
\r
183 for (int i = 0; i < endPointIds.length(); i++) {
\r
184 JSONObject id = endPointIds.getJSONObject(i);
\r
185 FeedEndpointID fid = new FeedEndpointID(id.getString("id"), id.getString("password"));
\r
186 if (fid.getId().length() > 60) {
\r
187 throw new InvalidObjectException("id field is too long (" + fid.getId() + ")");
\r
189 if (fid.getPassword().length() > 32) {
\r
190 //Fortify scan fixes - Privacy Violation
\r
191 throw new InvalidObjectException("password field is too long (" + fid.getPassword() + ")");
\r
193 this.authorization.getEndpointIDS().add(fid);
\r
195 if (this.authorization.getEndpointIDS().isEmpty()) {
\r
196 throw new InvalidObjectException("need to specify at least one endpoint_id");
\r
198 endPointIds = jauth.getJSONArray("endpoint_addrs");
\r
199 for (int i = 0; i < endPointIds.length(); i++) {
\r
200 String addr = endPointIds.getString(i);
\r
201 if (!JSONUtilities.validIPAddrOrSubnet(addr)) {
\r
202 throw new InvalidObjectException("bad IP addr or subnet mask: " + addr);
\r
204 this.authorization.getEndpointAddrs().add(addr);
\r
207 this.publisher = jo.optString("publisher", "");
\r
208 this.deleted = jo.optBoolean(DEL, false);
\r
209 this.suspended = jo.optBoolean("suspend", false);
\r
210 JSONObject jol = jo.optJSONObject("links");
\r
211 this.links = (jol == null) ? (new FeedLinks()) : (new FeedLinks(jol));
\r
212 } catch (InvalidObjectException e) {
\r
214 } catch (Exception e) {
\r
215 intlogger.warn("Invalid JSON: " + e.getMessage(), e);
\r
216 throw new InvalidObjectException("Invalid JSON: " + e.getMessage());
\r
221 * Check if a feed ID is valid.
\r
223 * @param id the Feed ID
\r
224 * @return true if it is valid
\r
226 @SuppressWarnings("resource")
\r
227 public static boolean isFeedValid(int id) {
\r
231 Connection conn = db.getConnection();
\r
232 try (PreparedStatement stmt = conn.prepareStatement("select COUNT(*) from FEEDS where FEEDID = ?")) {
\r
233 stmt.setInt(1, id);
\r
234 try (ResultSet rs = stmt.executeQuery()) {
\r
236 count = rs.getInt(1);
\r
241 } catch (SQLException e) {
\r
242 intlogger.warn("PROV0024 Feed.isFeedValid: " + e.getMessage(), e);
\r
248 * Get a specific feed from the DB, based upon its ID.
\r
250 * @param id the Feed ID
\r
251 * @return the Feed object, or null if it does not exist
\r
253 public static Feed getFeedById(int id) {
\r
254 String sql = "select * from FEEDS where FEEDID = " + id;
\r
255 return getFeedBySQL(sql);
\r
259 * Get a specific feed from the DB, based upon its name and version.
\r
261 * @param name the name of the Feed
\r
262 * @param version the version of the Feed
\r
263 * @return the Feed object, or null if it does not exist
\r
265 public static Feed getFeedByNameVersion(String name, String version) {
\r
266 name = name.replaceAll("'", "''");
\r
267 version = version.replaceAll("'", "''");
\r
268 String sql = "select * from FEEDS where NAME = '" + name + "' and VERSION ='" + version + "'";
\r
269 return getFeedBySQL(sql);
\r
273 * Return a count of the number of active feeds in the DB.
\r
275 * @return the count
\r
277 public static int countActiveFeeds() {
\r
281 @SuppressWarnings("resource") Connection conn = db.getConnection();
\r
282 try (Statement stmt = conn.createStatement()) {
\r
283 try (ResultSet rs = stmt.executeQuery("select count(*) from FEEDS where DELETED = 0")) {
\r
285 count = rs.getInt(1);
\r
290 } catch (SQLException e) {
\r
291 intlogger.warn("PROV0025 Feed.countActiveFeeds: " + e.getMessage(), e);
\r
297 * Method to get max feed id.
\r
298 * @return int max feed id
\r
300 public static int getMaxFeedID() {
\r
304 @SuppressWarnings("resource")
\r
305 Connection conn = db.getConnection();
\r
306 try (Statement stmt = conn.createStatement()) {
\r
307 try (ResultSet rs = stmt.executeQuery("select MAX(feedid) from FEEDS")) {
\r
309 max = rs.getInt(1);
\r
314 } catch (SQLException e) {
\r
315 intlogger.warn("PROV0026 Feed.getMaxFeedID: " + e.getMessage(), e);
\r
322 * @return Collection of feeds
\r
324 public static Collection<Feed> getAllFeeds() {
\r
325 Map<Integer, Feed> map = new HashMap<>();
\r
328 @SuppressWarnings("resource")
\r
329 Connection conn = db.getConnection();
\r
330 try (Statement stmt = conn.createStatement()) {
\r
331 try (ResultSet rs = stmt.executeQuery("select * from FEEDS")) {
\r
332 while (rs.next()) {
\r
333 Feed feed = new Feed(rs);
\r
334 map.put(feed.getFeedid(), feed);
\r
338 String sql = "select * from FEED_ENDPOINT_IDS";
\r
339 try (ResultSet rs = stmt.executeQuery(sql)) {
\r
340 while (rs.next()) {
\r
341 int id = rs.getInt(FEED_ID_SQL);
\r
342 Feed feed = map.get(id);
\r
343 if (feed != null) {
\r
344 FeedEndpointID epi = new FeedEndpointID(rs);
\r
345 Collection<FeedEndpointID> ecoll = feed.getAuthorization().getEndpointIDS();
\r
351 sql = "select * from FEED_ENDPOINT_ADDRS";
\r
352 try (ResultSet rs = stmt.executeQuery(sql)) {
\r
353 while (rs.next()) {
\r
354 int id = rs.getInt(FEED_ID_SQL);
\r
355 Feed feed = map.get(id);
\r
356 if (feed != null) {
\r
357 Collection<String> acoll = feed.getAuthorization().getEndpointAddrs();
\r
358 acoll.add(rs.getString("ADDR"));
\r
364 } catch (SQLException e) {
\r
365 intlogger.warn("PROV0027 Feed.getAllFeeds: " + e.getMessage(), e);
\r
367 return map.values();
\r
371 * Get Feed URL list.
\r
372 * @param name of Feed
\r
373 * @param val of feed
\r
374 * @return List of feed names
\r
376 public static List<String> getFilteredFeedUrlList(final String name, final String val) {
\r
377 List<String> list = new ArrayList<>();
\r
378 String sql = "select SELF_LINK from FEEDS where DELETED = 0";
\r
379 if (name.equals("name")) {
\r
380 sql += " and NAME = ?";
\r
381 } else if (name.equals("publ")) {
\r
382 sql += " and PUBLISHER = ?";
\r
383 } else if (name.equals("subs")) {
\r
384 sql = "select distinct FEEDS.SELF_LINK from FEEDS, SUBSCRIPTIONS "
\r
385 + "where DELETED = 0 "
\r
386 + "and FEEDS.FEEDID = SUBSCRIPTIONS.FEEDID "
\r
387 + "and SUBSCRIPTIONS.SUBSCRIBER = ?";
\r
391 @SuppressWarnings("resource")
\r
392 Connection conn = db.getConnection();
\r
393 try (PreparedStatement ps = conn.prepareStatement(sql)) {
\r
394 if (sql.indexOf('?') >= 0) {
\r
395 ps.setString(1, val);
\r
397 try (ResultSet rs = ps.executeQuery()) {
\r
398 while (rs.next()) {
\r
399 String str = rs.getString(1);
\r
400 list.add(str.trim());
\r
405 } catch (SQLException e) {
\r
406 intlogger.warn("PROV0028 Feed.getFilteredFeedUrlList: " + e.getMessage(), e);
\r
411 @SuppressWarnings("resource")
\r
412 private static Feed getFeedBySQL(String sql) {
\r
416 Connection conn = db.getConnection();
\r
417 try (Statement stmt = conn.createStatement()) {
\r
418 try (ResultSet rs = stmt.executeQuery(sql)) {
\r
420 feed = new Feed(rs);
\r
423 if (feed != null) {
\r
424 sql = "select * from FEED_ENDPOINT_IDS where FEEDID = " + feed.feedid;
\r
425 try (ResultSet rs = stmt.executeQuery(sql)) {
\r
426 Collection<FeedEndpointID> ecoll = feed.getAuthorization().getEndpointIDS();
\r
427 while (rs.next()) {
\r
428 FeedEndpointID epi = new FeedEndpointID(rs);
\r
432 sql = "select * from FEED_ENDPOINT_ADDRS where FEEDID = " + feed.feedid;
\r
433 try (ResultSet rs = stmt.executeQuery(sql)) {
\r
434 Collection<String> acoll = feed.getAuthorization().getEndpointAddrs();
\r
435 while (rs.next()) {
\r
436 acoll.add(rs.getString("ADDR"));
\r
442 } catch (SQLException e) {
\r
443 intlogger.warn("PROV0029 Feed.getFeedBySQL: " + e.getMessage(), e);
\r
450 public int getFeedid() {
\r
455 * Set feedid with FeedLinks.
\r
456 * @param feedid Feedid to set to
\r
458 public void setFeedid(int feedid) {
\r
459 this.feedid = feedid;
\r
461 // Create link URLs
\r
462 FeedLinks fl = getLinks();
\r
463 fl.setSelf(URLUtilities.generateFeedURL(feedid));
\r
464 fl.setPublish(URLUtilities.generatePublishURL(feedid));
\r
465 fl.setSubscribe(URLUtilities.generateSubscribeURL(feedid));
\r
466 fl.setLog(URLUtilities.generateFeedLogURL(feedid));
\r
469 public String getAafInstance() {
\r
470 return aafInstance;
\r
473 public void setAafInstance(String aafInstance) {
\r
474 this.aafInstance = aafInstance;
\r
477 //new getter setters for groups- Rally:US708115 - 1610
\r
478 public int getGroupid() {
\r
482 public void setGroupid(int groupid) {
\r
483 this.groupid = groupid;
\r
486 public String getName() {
\r
490 public void setName(String name) {
\r
494 public String getVersion() {
\r
498 public void setVersion(String version) {
\r
499 this.version = version;
\r
502 public String getDescription() {
\r
503 return description;
\r
506 public void setDescription(String description) {
\r
507 this.description = description;
\r
510 // New field is added - Groups feature Rally:US708102 - 1610
\r
511 public String getBusinessDescription() {
\r
512 return businessDescription;
\r
515 public void setBusinessDescription(String businessDescription) {
\r
516 this.businessDescription = businessDescription;
\r
519 public FeedAuthorization getAuthorization() {
\r
520 return authorization;
\r
523 public void setAuthorization(FeedAuthorization authorization) {
\r
524 this.authorization = authorization;
\r
527 public String getPublisher() {
\r
533 * @param publisher Publisher name
\r
535 public void setPublisher(String publisher) {
\r
536 if (publisher != null) {
\r
537 if (publisher.length() > 8) {
\r
538 publisher = publisher.substring(0, 8);
\r
540 this.publisher = publisher;
\r
544 public FeedLinks getLinks() {
\r
548 public void setLinks(FeedLinks links) {
\r
549 this.links = links;
\r
552 public boolean isDeleted() {
\r
556 public void setDeleted(boolean deleted) {
\r
557 this.deleted = deleted;
\r
560 public boolean isSuspended() {
\r
564 public void setSuspended(boolean suspended) {
\r
565 this.suspended = suspended;
\r
569 public JSONObject asJSONObject() {
\r
570 JSONObject jo = new JSONObject();
\r
571 jo.put(FEED_ID, feedid);
\r
572 //New field is added - Groups feature Rally:US708115 - 1610
\r
573 jo.put("groupid", groupid);
\r
574 jo.put("name", name);
\r
575 jo.put("version", version);
\r
576 jo.put("description", description);
\r
577 // New field is added - Groups feature Rally:US708102 - 1610
\r
578 jo.put("business_description", businessDescription);
\r
579 jo.put("authorization", authorization.asJSONObject());
\r
580 jo.put("publisher", publisher);
\r
581 jo.put("links", links.asJSONObject());
\r
582 jo.put(DEL, deleted);
\r
583 jo.put("suspend", suspended);
\r
584 jo.put(LAST_MOD, lastMod.getTime());
\r
585 jo.put(CREATED_DATE, createdDate.getTime());
\r
586 jo.put("aaf_instance", aafInstance);
\r
591 * Method to hide some attributes.
\r
592 * @param hidepasswords true/false
\r
593 * @return JSONObject
\r
595 public JSONObject asJSONObject(boolean hidepasswords) {
\r
596 JSONObject jo = asJSONObject();
\r
597 if (hidepasswords) {
\r
598 jo.remove(FEED_ID); // we no longer hide passwords, however we do hide these
\r
600 jo.remove(LAST_MOD);
\r
601 jo.remove(CREATED_DATE);
\r
607 * Method to limit JSONObject.
\r
608 * @return JSONObject
\r
610 public JSONObject asLimitedJSONObject() {
\r
611 JSONObject jo = asJSONObject();
\r
613 jo.remove(FEED_ID);
\r
614 jo.remove(LAST_MOD);
\r
615 jo.remove(CREATED_DATE);
\r
622 public boolean doDelete(Connection conn) {
\r
624 PreparedStatement ps = null;
\r
626 String sql = "delete from FEEDS where FEEDID = ?";
\r
627 ps = conn.prepareStatement(sql);
\r
628 ps.setInt(1, feedid);
\r
630 } catch (SQLException e) {
\r
632 intlogger.error("PROV0007 doDelete: " + e.getMessage(), e);
\r
638 } catch (SQLException e) {
\r
639 intlogger.error(SQLEXCEPTION + e.getMessage(), e);
\r
646 public synchronized boolean doInsert(Connection conn) {
\r
649 if (feedid == -1) {
\r
650 setFeedid(nextFeedID++);
\r
652 // In case we insert a feed from synchronization
\r
653 if (feedid > nextFeedID) {
\r
654 nextFeedID = feedid + 1;
\r
657 // Create FEED_ENDPOINT_IDS rows
\r
658 FeedAuthorization auth = getAuthorization();
\r
659 String sql = "insert into FEED_ENDPOINT_IDS values (?, ?, ?)";
\r
660 try (PreparedStatement ps2 = conn.prepareStatement(sql)) {
\r
661 for (FeedEndpointID fid : auth.getEndpointIDS()) {
\r
662 ps2.setInt(1, feedid);
\r
663 ps2.setString(2, fid.getId());
\r
664 ps2.setString(3, fid.getPassword());
\r
665 ps2.executeUpdate();
\r
669 // Create FEED_ENDPOINT_ADDRS rows
\r
670 sql = "insert into FEED_ENDPOINT_ADDRS values (?, ?)";
\r
671 try (PreparedStatement ps2 = conn.prepareStatement(sql)) {
\r
672 for (String t : auth.getEndpointAddrs()) {
\r
673 ps2.setInt(1, feedid);
\r
674 ps2.setString(2, t);
\r
675 ps2.executeUpdate();
\r
679 // Finally, create the FEEDS row
\r
680 sql = "insert into FEEDS (FEEDID, NAME, VERSION, DESCRIPTION, AUTH_CLASS, PUBLISHER, SELF_LINK, "
\r
681 + "PUBLISH_LINK, SUBSCRIBE_LINK, LOG_LINK, DELETED, SUSPENDED,"
\r
682 + "BUSINESS_DESCRIPTION, GROUPID, AAF_INSTANCE) "
\r
683 + "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
\r
684 try (PreparedStatement ps2 = conn.prepareStatement(sql)) {
\r
685 ps2.setInt(1, feedid);
\r
686 ps2.setString(2, getName());
\r
687 ps2.setString(3, getVersion());
\r
688 ps2.setString(4, getDescription());
\r
689 ps2.setString(5, getAuthorization().getClassification());
\r
690 ps2.setString(6, getPublisher());
\r
691 ps2.setString(7, getLinks().getSelf());
\r
692 ps2.setString(8, getLinks().getPublish());
\r
693 ps2.setString(9, getLinks().getSubscribe());
\r
694 ps2.setString(10, getLinks().getLog());
\r
695 ps2.setBoolean(11, isDeleted());
\r
696 ps2.setBoolean(12, isSuspended());
\r
697 ps2.setString(13, getBusinessDescription());
\r
698 ps2.setInt(14, groupid);
\r
699 ps2.setString(15, getAafInstance());
\r
700 ps2.executeUpdate();
\r
702 } catch (SQLException e) {
\r
704 intlogger.error("PROV0005 doInsert: " + e.getMessage(), e);
\r
710 public boolean doUpdate(Connection conn) {
\r
712 Feed oldobj = getFeedById(feedid);
\r
713 PreparedStatement ps = null;
\r
715 Set<FeedEndpointID> newset = getAuthorization().getEndpointIDS();
\r
716 Set<FeedEndpointID> oldset = oldobj.getAuthorization().getEndpointIDS();
\r
718 // Insert new FEED_ENDPOINT_IDS rows
\r
719 String sql = "insert into FEED_ENDPOINT_IDS values (?, ?, ?)";
\r
720 ps = conn.prepareStatement(sql);
\r
721 for (FeedEndpointID fid : newset) {
\r
722 if (!oldset.contains(fid)) {
\r
723 ps.setInt(1, feedid);
\r
724 ps.setString(2, fid.getId());
\r
725 ps.setString(3, fid.getPassword());
\r
726 ps.executeUpdate();
\r
731 // Delete old FEED_ENDPOINT_IDS rows
\r
732 sql = "delete from FEED_ENDPOINT_IDS where FEEDID = ? AND USERID = ? AND PASSWORD = ?";
\r
733 ps = conn.prepareStatement(sql);
\r
734 for (FeedEndpointID fid : oldset) {
\r
735 if (!newset.contains(fid)) {
\r
736 ps.setInt(1, feedid);
\r
737 ps.setString(2, fid.getId());
\r
738 ps.setString(3, fid.getPassword());
\r
739 ps.executeUpdate();
\r
744 // Insert new FEED_ENDPOINT_ADDRS rows
\r
745 Set<String> newset2 = getAuthorization().getEndpointAddrs();
\r
746 Set<String> oldset2 = oldobj.getAuthorization().getEndpointAddrs();
\r
747 sql = "insert into FEED_ENDPOINT_ADDRS values (?, ?)";
\r
748 ps = conn.prepareStatement(sql);
\r
749 for (String t : newset2) {
\r
750 if (!oldset2.contains(t)) {
\r
751 ps.setInt(1, feedid);
\r
752 ps.setString(2, t);
\r
753 ps.executeUpdate();
\r
758 // Delete old FEED_ENDPOINT_ADDRS rows
\r
759 sql = "delete from FEED_ENDPOINT_ADDRS where FEEDID = ? AND ADDR = ?";
\r
760 ps = conn.prepareStatement(sql);
\r
761 for (String t : oldset2) {
\r
762 if (!newset2.contains(t)) {
\r
763 ps.setInt(1, feedid);
\r
764 ps.setString(2, t);
\r
765 ps.executeUpdate();
\r
770 // Finally, update the FEEDS row
\r
771 sql = "update FEEDS set DESCRIPTION = ?, AUTH_CLASS = ?, DELETED = ?, SUSPENDED = ?, "
\r
772 + "BUSINESS_DESCRIPTION=?, GROUPID=? where FEEDID = ?";
\r
773 ps = conn.prepareStatement(sql);
\r
774 ps.setString(1, getDescription());
\r
775 ps.setString(2, getAuthorization().getClassification());
\r
776 ps.setInt(3, deleted ? 1 : 0);
\r
777 ps.setInt(4, suspended ? 1 : 0);
\r
778 ps.setString(5, getBusinessDescription());
\r
779 ps.setInt(6, groupid);
\r
780 ps.setInt(7, feedid);
\r
781 ps.executeUpdate();
\r
783 } catch (SQLException e) {
\r
785 intlogger.warn("PROV0006 doUpdate: " + e.getMessage(), e);
\r
791 } catch (SQLException e) {
\r
792 intlogger.error(SQLEXCEPTION + e.getMessage(), e);
\r
800 * Change Ownership of FEED - 1610
\r
802 public boolean changeOwnerShip() {
\r
804 PreparedStatement ps = null;
\r
808 @SuppressWarnings("resource")
\r
809 Connection conn = db.getConnection();
\r
810 String sql = "update FEEDS set PUBLISHER = ? where FEEDID = ?";
\r
811 ps = conn.prepareStatement(sql);
\r
812 ps.setString(1, this.publisher);
\r
813 ps.setInt(2, feedid);
\r
816 } catch (SQLException e) {
\r
818 intlogger.warn("PROV0008 changeOwnerShip: " + e.getMessage(), e);
\r
824 } catch (SQLException e) {
\r
825 intlogger.error(SQLEXCEPTION + e.getMessage(), e);
\r
833 public String getKey() {
\r
834 return "" + getFeedid();
\r
838 public boolean equals(Object obj) {
\r
839 if (!(obj instanceof Feed)) {
\r
842 Feed of = (Feed) obj;
\r
843 if (feedid != of.feedid) {
\r
846 if (groupid != of.groupid) {
\r
847 //New field is added - Groups feature Rally:US708115 - 1610
\r
850 if (!name.equals(of.name)) {
\r
853 if (!version.equals(of.version)) {
\r
856 if (!description.equals(of.description)) {
\r
859 if (!businessDescription.equals(of.businessDescription)) {
\r
860 // New field is added - Groups feature Rally:US708102 - 1610
\r
863 if (!publisher.equals(of.publisher)) {
\r
866 if (!authorization.equals(of.authorization)) {
\r
869 if (!links.equals(of.links)) {
\r
872 if (deleted != of.deleted) {
\r
875 if (suspended != of.suspended) {
\r
878 if (!aafInstance.equals(of.aafInstance)) {
\r
885 public String toString() {
\r
886 return "FEED: feedid=" + feedid + ", name=" + name + ", version=" + version;
\r
890 public int hashCode() {
\r
891 return super.hashCode();
\r