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.JSONUtilities;
\r
46 import org.onap.dmaap.datarouter.provisioning.utils.ProvDbUtils;
\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 FEED_ID_SQL = "FEEDID";
\r
62 private static final String FEED_ID = "feedid";
\r
63 private static final String DEL = "deleted";
\r
64 private static final String LAST_MOD = "last_mod";
\r
65 private static final String CREATED_DATE = "created_date";
\r
68 private int groupid; //New field is added - Groups feature Rally:US708115 - 1610
\r
69 private String name;
\r
70 private String version;
\r
71 private String description;
\r
72 private String businessDescription; // New field is added - Groups feature Rally:US708102 - 1610
\r
73 private FeedAuthorization authorization;
\r
74 private String publisher;
\r
75 private FeedLinks links;
\r
76 private boolean deleted;
\r
77 private boolean suspended;
\r
78 private Date lastMod;
\r
79 private Date createdDate;
\r
80 private String aafInstance;
\r
83 this("", "", "", "");
\r
88 * @param name feed name
\r
89 * @param version feed version
\r
90 * @param desc feed description
\r
91 * @param businessDescription feed business description
\r
93 public Feed(String name, String version, String desc, String businessDescription) {
\r
95 this.groupid = -1; //New field is added - Groups feature Rally:US708115 - 1610
\r
97 this.version = version;
\r
98 this.description = desc;
\r
99 this.businessDescription = businessDescription; // New field is added - Groups feature Rally:US708102 - 1610
\r
100 this.authorization = new FeedAuthorization();
\r
101 this.publisher = "";
\r
102 this.links = new FeedLinks();
\r
103 this.deleted = false;
\r
104 this.suspended = false;
\r
105 this.lastMod = new Date();
\r
106 this.createdDate = new Date();
\r
107 this.aafInstance = "";
\r
111 * Feed Constructor from ResultSet.
\r
112 * @param rs ResultSet
\r
113 * @throws SQLException in case of SQL statement error
\r
115 public Feed(ResultSet rs) throws SQLException {
\r
116 this.feedid = rs.getInt(FEED_ID_SQL);
\r
117 //New field is added - Groups feature Rally:US708115 - 1610
\r
118 this.groupid = rs.getInt("GROUPID");
\r
119 this.name = rs.getString("NAME");
\r
120 this.version = rs.getString("VERSION");
\r
121 this.description = rs.getString("DESCRIPTION");
\r
122 // New field is added - Groups feature Rally:US708102 - 1610
\r
123 this.businessDescription = rs.getString("BUSINESS_DESCRIPTION");
\r
124 this.authorization = new FeedAuthorization();
\r
125 this.authorization.setClassification(rs.getString("AUTH_CLASS"));
\r
126 this.publisher = rs.getString("PUBLISHER");
\r
127 this.links = new FeedLinks();
\r
128 this.links.setSelf(rs.getString("SELF_LINK"));
\r
129 this.links.setPublish(rs.getString("PUBLISH_LINK"));
\r
130 this.links.setSubscribe(rs.getString("SUBSCRIBE_LINK"));
\r
131 this.links.setLog(rs.getString("LOG_LINK"));
\r
132 this.deleted = rs.getBoolean("DELETED");
\r
133 this.suspended = rs.getBoolean("SUSPENDED");
\r
134 this.lastMod = rs.getDate("LAST_MOD");
\r
135 this.createdDate = rs.getTimestamp("CREATED_DATE");
\r
136 this.aafInstance = rs.getString("AAF_INSTANCE");
\r
140 * Feed constructor from JSONObject.
\r
141 * @param jo JSONObject
\r
142 * @throws InvalidObjectException in case of JSON error
\r
144 public Feed(JSONObject jo) throws InvalidObjectException {
\r
145 this("", "", "", "");
\r
147 // The JSONObject is assumed to contain a vnd.dmaap-dr.feed representation
\r
148 this.feedid = jo.optInt(FEED_ID, -1);
\r
149 this.groupid = jo.optInt("groupid");
\r
150 this.name = jo.getString("name");
\r
151 this.aafInstance = jo.optString("aaf_instance", "legacy");
\r
152 if (!("legacy".equalsIgnoreCase(aafInstance)) && aafInstance.length() > 255) {
\r
153 throw new InvalidObjectException("aaf_instance field is too long");
\r
155 if (name.length() > 255) {
\r
156 throw new InvalidObjectException("name field is too long");
\r
159 this.version = jo.getString("version");
\r
160 } catch (JSONException e) {
\r
161 intlogger.warn("PROV0023 Feed.Feed: " + e.getMessage(), e);
\r
162 this.version = null;
\r
164 if (version != null && version.length() > 20) {
\r
165 throw new InvalidObjectException("version field is too long");
\r
167 this.description = jo.optString("description");
\r
168 this.businessDescription = jo.optString("business_description");
\r
169 if (description.length() > 1000) {
\r
170 throw new InvalidObjectException("technical description field is too long");
\r
172 if (businessDescription.length() > 1000) {
\r
173 throw new InvalidObjectException("business description field is too long");
\r
175 this.authorization = new FeedAuthorization();
\r
176 JSONObject jauth = jo.getJSONObject("authorization");
\r
177 this.authorization.setClassification(jauth.getString("classification"));
\r
178 if (this.authorization.getClassification().length() > 32) {
\r
179 throw new InvalidObjectException("classification field is too long");
\r
181 JSONArray endPointIds = jauth.getJSONArray("endpoint_ids");
\r
182 for (int i = 0; i < endPointIds.length(); i++) {
\r
183 JSONObject id = endPointIds.getJSONObject(i);
\r
184 FeedEndpointID fid = new FeedEndpointID(id.getString("id"), id.getString("password"));
\r
185 if (fid.getId().length() > 60) {
\r
186 throw new InvalidObjectException("id field is too long (" + fid.getId() + ")");
\r
188 if (fid.getPassword().length() > 100) {
\r
189 //Fortify scan fixes - Privacy Violation
\r
190 throw new InvalidObjectException("password field is too long (" + fid.getPassword() + ")");
\r
192 this.authorization.getEndpointIDS().add(fid);
\r
194 if (this.authorization.getEndpointIDS().isEmpty()) {
\r
195 throw new InvalidObjectException("need to specify at least one endpoint_id");
\r
197 endPointIds = jauth.getJSONArray("endpoint_addrs");
\r
198 for (int i = 0; i < endPointIds.length(); i++) {
\r
199 String addr = endPointIds.getString(i);
\r
200 if (!JSONUtilities.validIPAddrOrSubnet(addr)) {
\r
201 throw new InvalidObjectException("bad IP addr or subnet mask: " + addr);
\r
203 this.authorization.getEndpointAddrs().add(addr);
\r
206 this.publisher = jo.optString("publisher", "");
\r
207 this.deleted = jo.optBoolean(DEL, false);
\r
208 this.suspended = jo.optBoolean("suspend", false);
\r
209 JSONObject jol = jo.optJSONObject("links");
\r
210 this.links = (jol == null) ? (new FeedLinks()) : (new FeedLinks(jol));
\r
211 } catch (InvalidObjectException e) {
\r
213 } catch (Exception e) {
\r
214 intlogger.warn("Invalid JSON: " + e.getMessage(), e);
\r
215 throw new InvalidObjectException("Invalid JSON: " + e.getMessage());
\r
220 * Check if a feed ID is valid.
\r
222 * @param id the Feed ID
\r
223 * @return true if it is valid
\r
225 @SuppressWarnings("resource")
\r
226 static boolean isFeedValid(int id) {
\r
228 try (Connection conn = ProvDbUtils.getInstance().getConnection();
\r
229 PreparedStatement ps = conn.prepareStatement(
\r
230 "select COUNT(*) from FEEDS where FEEDID = ?")) {
\r
232 try (ResultSet rs = ps.executeQuery()) {
\r
234 count = rs.getInt(1);
\r
237 } catch (SQLException e) {
\r
238 intlogger.warn("PROV0024 Feed.isFeedValid: " + e.getMessage(), e);
\r
244 * Get a specific feed from the DB, based upon its ID.
\r
246 * @param id the Feed ID
\r
247 * @return the Feed object, or null if it does not exist
\r
249 public static Feed getFeedById(int id) {
\r
250 String sql = "select * from FEEDS where FEEDID = " + id;
\r
251 return getFeedBySQL(sql);
\r
255 * Get a specific feed from the DB, based upon its name and version.
\r
257 * @param name the name of the Feed
\r
258 * @param version the version of the Feed
\r
259 * @return the Feed object, or null if it does not exist
\r
261 public static Feed getFeedByNameVersion(String name, String version) {
\r
262 name = name.replaceAll("'", "''");
\r
263 version = version.replaceAll("'", "''");
\r
264 String sql = "select * from FEEDS where NAME = '" + name + "' and VERSION ='" + version + "'";
\r
265 return getFeedBySQL(sql);
\r
269 * Return a count of the number of active feeds in the DB.
\r
271 * @return the count
\r
273 public static int countActiveFeeds() {
\r
275 try (Connection conn = ProvDbUtils.getInstance().getConnection();
\r
276 PreparedStatement ps = conn.prepareStatement(
\r
277 "select count(*) from FEEDS where DELETED = 0")) {
\r
278 try (ResultSet rs = ps.executeQuery()) {
\r
280 count = rs.getInt(1);
\r
283 } catch (SQLException e) {
\r
284 intlogger.warn("PROV0025 Feed.countActiveFeeds: " + e.getMessage(), e);
\r
290 * Method to get max feed id.
\r
291 * @return int max feed id
\r
293 public static int getMaxFeedID() {
\r
295 try (Connection conn = ProvDbUtils.getInstance().getConnection();
\r
296 PreparedStatement ps = conn.prepareStatement(
\r
297 "select MAX(feedid) from FEEDS")) {
\r
298 try (ResultSet rs = ps.executeQuery()) {
\r
300 max = rs.getInt(1);
\r
303 } catch (SQLException e) {
\r
304 intlogger.warn("PROV0026 Feed.getMaxFeedID: " + e.getMessage(), e);
\r
311 * @return Collection of feeds
\r
313 public static Collection<Feed> getAllFeeds() {
\r
314 Map<Integer, Feed> map = new HashMap<>();
\r
315 try (Connection conn = ProvDbUtils.getInstance().getConnection()) {
\r
316 try (PreparedStatement ps = conn.prepareStatement("select * from FEEDS");
\r
317 ResultSet rs = ps.executeQuery()) {
\r
318 while (rs.next()) {
\r
319 Feed feed = new Feed(rs);
\r
320 map.put(feed.getFeedid(), feed);
\r
323 try (PreparedStatement ps = conn.prepareStatement("select * from FEED_ENDPOINT_IDS");
\r
324 ResultSet rs = ps.executeQuery()) {
\r
325 while (rs.next()) {
\r
326 int id = rs.getInt(FEED_ID_SQL);
\r
327 Feed feed = map.get(id);
\r
328 if (feed != null) {
\r
329 FeedEndpointID epi = new FeedEndpointID(rs);
\r
330 Collection<FeedEndpointID> ecoll = feed.getAuthorization().getEndpointIDS();
\r
335 try (PreparedStatement ps = conn.prepareStatement("select * from FEED_ENDPOINT_ADDRS");
\r
336 ResultSet rs = ps.executeQuery()) {
\r
337 while (rs.next()) {
\r
338 int id = rs.getInt(FEED_ID_SQL);
\r
339 Feed feed = map.get(id);
\r
340 if (feed != null) {
\r
341 Collection<String> acoll = feed.getAuthorization().getEndpointAddrs();
\r
342 acoll.add(rs.getString("ADDR"));
\r
346 } catch (SQLException e) {
\r
347 intlogger.warn("PROV0027 Feed.getAllFeeds: " + e.getMessage(), e);
\r
349 return map.values();
\r
353 * Get Feed URL list.
\r
354 * @param name of Feed
\r
355 * @param val of feed
\r
356 * @return List of feed names
\r
358 public static List<String> getFilteredFeedUrlList(final String name, final String val) {
\r
359 List<String> list = new ArrayList<>();
\r
360 String sql = "select SELF_LINK from FEEDS where DELETED = 0";
\r
361 if (name.equals("name")) {
\r
362 sql += " and NAME = ?";
\r
363 } else if (name.equals("publ")) {
\r
364 sql += " and PUBLISHER = ?";
\r
365 } else if (name.equals("subs")) {
\r
366 sql = "select distinct FEEDS.SELF_LINK from FEEDS, SUBSCRIPTIONS "
\r
367 + "where DELETED = 0 "
\r
368 + "and FEEDS.FEEDID = SUBSCRIPTIONS.FEEDID "
\r
369 + "and SUBSCRIPTIONS.SUBSCRIBER = ?";
\r
371 try (Connection conn = ProvDbUtils.getInstance().getConnection();
\r
372 PreparedStatement ps = conn.prepareStatement(sql)) {
\r
373 if (sql.indexOf('?') >= 0) {
\r
374 ps.setString(1, val);
\r
376 try (ResultSet rs = ps.executeQuery()) {
\r
377 while (rs.next()) {
\r
378 String str = rs.getString(1);
\r
379 list.add(str.trim());
\r
382 } catch (SQLException e) {
\r
383 intlogger.warn("PROV0028 Feed.getFilteredFeedUrlList: " + e.getMessage(), e);
\r
388 @SuppressWarnings("resource")
\r
389 private static Feed getFeedBySQL(String sql) {
\r
391 try (Connection conn = ProvDbUtils.getInstance().getConnection()) {
\r
392 try (Statement stmt = conn.createStatement()) {
\r
393 try (ResultSet rs = stmt.executeQuery(sql)) {
\r
395 feed = new Feed(rs);
\r
398 if (feed != null) {
\r
399 sql = "select * from FEED_ENDPOINT_IDS where FEEDID = " + feed.feedid;
\r
400 try (ResultSet rs = stmt.executeQuery(sql)) {
\r
401 Collection<FeedEndpointID> ecoll = feed.getAuthorization().getEndpointIDS();
\r
402 while (rs.next()) {
\r
403 FeedEndpointID epi = new FeedEndpointID(rs);
\r
407 sql = "select * from FEED_ENDPOINT_ADDRS where FEEDID = " + feed.feedid;
\r
408 try (ResultSet rs = stmt.executeQuery(sql)) {
\r
409 Collection<String> acoll = feed.getAuthorization().getEndpointAddrs();
\r
410 while (rs.next()) {
\r
411 acoll.add(rs.getString("ADDR"));
\r
416 } catch (SQLException e) {
\r
417 intlogger.warn("PROV0029 Feed.getFeedBySQL: " + e.getMessage(), e);
\r
424 public int getFeedid() {
\r
429 * Set feedid with FeedLinks.
\r
430 * @param feedid Feedid to set to
\r
432 public void setFeedid(int feedid) {
\r
433 this.feedid = feedid;
\r
435 // Create link URLs
\r
436 FeedLinks fl = getLinks();
\r
437 fl.setSelf(URLUtilities.generateFeedURL(feedid));
\r
438 fl.setPublish(URLUtilities.generatePublishURL(feedid));
\r
439 fl.setSubscribe(URLUtilities.generateSubscribeURL(feedid));
\r
440 fl.setLog(URLUtilities.generateFeedLogURL(feedid));
\r
443 public String getAafInstance() {
\r
444 return aafInstance;
\r
447 //new getter setters for groups- Rally:US708115 - 1610
\r
448 public int getGroupid() {
\r
452 public void setGroupid(int groupid) {
\r
453 this.groupid = groupid;
\r
456 public String getName() {
\r
460 public void setName(String name) {
\r
464 public String getVersion() {
\r
468 public void setVersion(String version) {
\r
469 this.version = version;
\r
472 public String getDescription() {
\r
473 return description;
\r
476 public void setDescription(String description) {
\r
477 this.description = description;
\r
480 // New field is added - Groups feature Rally:US708102 - 1610
\r
481 String getBusinessDescription() {
\r
482 return businessDescription;
\r
485 void setBusinessDescription(String businessDescription) {
\r
486 this.businessDescription = businessDescription;
\r
489 public FeedAuthorization getAuthorization() {
\r
490 return authorization;
\r
493 public void setAuthorization(FeedAuthorization authorization) {
\r
494 this.authorization = authorization;
\r
497 public String getPublisher() {
\r
503 * @param publisher Publisher name
\r
505 public void setPublisher(String publisher) {
\r
506 if (publisher != null) {
\r
507 if (publisher.length() > 8) {
\r
508 publisher = publisher.substring(0, 8);
\r
510 this.publisher = publisher;
\r
514 public FeedLinks getLinks() {
\r
518 void setLinks(FeedLinks links) {
\r
519 this.links = links;
\r
522 public boolean isDeleted() {
\r
526 public void setDeleted(boolean deleted) {
\r
527 this.deleted = deleted;
\r
530 boolean isSuspended() {
\r
534 void setSuspended(boolean suspended) {
\r
535 this.suspended = suspended;
\r
539 public JSONObject asJSONObject() {
\r
540 JSONObject jo = new JSONObject();
\r
541 jo.put(FEED_ID, feedid);
\r
542 //New field is added - Groups feature Rally:US708115 - 1610
\r
543 jo.put("groupid", groupid);
\r
544 jo.put("name", name);
\r
545 jo.put("version", version);
\r
546 jo.put("description", description);
\r
547 // New field is added - Groups feature Rally:US708102 - 1610
\r
548 jo.put("business_description", businessDescription);
\r
549 jo.put("authorization", authorization.asJSONObject());
\r
550 jo.put("publisher", publisher);
\r
551 jo.put("links", links.asJSONObject());
\r
552 jo.put(DEL, deleted);
\r
553 jo.put("suspend", suspended);
\r
554 jo.put(LAST_MOD, lastMod.getTime());
\r
555 jo.put(CREATED_DATE, createdDate.getTime());
\r
556 jo.put("aaf_instance", aafInstance);
\r
561 * Method to hide some attributes.
\r
562 * @param hidepasswords true/false
\r
563 * @return JSONObject
\r
565 public JSONObject asJSONObject(boolean hidepasswords) {
\r
566 JSONObject jo = asJSONObject();
\r
567 if (hidepasswords) {
\r
568 jo.remove(FEED_ID); // we no longer hide passwords, however we do hide these
\r
570 jo.remove(LAST_MOD);
\r
571 jo.remove(CREATED_DATE);
\r
577 * Method to limit JSONObject.
\r
578 * @return JSONObject
\r
580 public JSONObject asLimitedJSONObject() {
\r
581 JSONObject jo = asJSONObject();
\r
583 jo.remove(FEED_ID);
\r
584 jo.remove(LAST_MOD);
\r
585 jo.remove(CREATED_DATE);
\r
592 public boolean doDelete(Connection conn) {
\r
594 try (PreparedStatement ps = conn.prepareStatement("delete from FEEDS where FEEDID = ?")) {
\r
595 ps.setInt(1, feedid);
\r
597 } catch (SQLException e) {
\r
599 intlogger.error("PROV0007 doDelete: " + e.getMessage(), e);
\r
605 public synchronized boolean doInsert(Connection conn) {
\r
608 if (feedid == -1) {
\r
609 setFeedid(nextFeedID++);
\r
611 // In case we insert a feed from synchronization
\r
612 if (feedid > nextFeedID) {
\r
613 nextFeedID = feedid + 1;
\r
615 // Create FEED_ENDPOINT_IDS rows
\r
616 FeedAuthorization auth = getAuthorization();
\r
617 try (PreparedStatement ps = conn.prepareStatement("insert into FEED_ENDPOINT_IDS values (?, ?, ?)")) {
\r
618 for (FeedEndpointID fid : auth.getEndpointIDS()) {
\r
619 ps.setInt(1, feedid);
\r
620 ps.setString(2, fid.getId());
\r
621 ps.setString(3, fid.getPassword());
\r
622 ps.executeUpdate();
\r
625 // Create FEED_ENDPOINT_ADDRS rows
\r
626 try (PreparedStatement ps = conn.prepareStatement("insert into FEED_ENDPOINT_ADDRS values (?, ?)")) {
\r
627 for (String t : auth.getEndpointAddrs()) {
\r
628 ps.setInt(1, feedid);
\r
629 ps.setString(2, t);
\r
630 ps.executeUpdate();
\r
633 // Finally, create the FEEDS row
\r
634 try (PreparedStatement ps = conn.prepareStatement(
\r
635 "insert into FEEDS (FEEDID, NAME, VERSION, DESCRIPTION, AUTH_CLASS, PUBLISHER, SELF_LINK, "
\r
636 + "PUBLISH_LINK, SUBSCRIBE_LINK, LOG_LINK, DELETED, SUSPENDED,"
\r
637 + "BUSINESS_DESCRIPTION, GROUPID, AAF_INSTANCE) "
\r
638 + "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) {
\r
639 ps.setInt(1, feedid);
\r
640 ps.setString(2, getName());
\r
641 ps.setString(3, getVersion());
\r
642 ps.setString(4, getDescription());
\r
643 ps.setString(5, getAuthorization().getClassification());
\r
644 ps.setString(6, getPublisher());
\r
645 ps.setString(7, getLinks().getSelf());
\r
646 ps.setString(8, getLinks().getPublish());
\r
647 ps.setString(9, getLinks().getSubscribe());
\r
648 ps.setString(10, getLinks().getLog());
\r
649 ps.setBoolean(11, isDeleted());
\r
650 ps.setBoolean(12, isSuspended());
\r
651 ps.setString(13, getBusinessDescription());
\r
652 ps.setInt(14, groupid);
\r
653 ps.setString(15, getAafInstance());
\r
654 ps.executeUpdate();
\r
656 } catch (SQLException e) {
\r
658 intlogger.error("PROV0005 doInsert: " + e.getMessage(), e);
\r
664 public boolean doUpdate(Connection conn) {
\r
667 Feed oldobj = getFeedById(feedid);
\r
668 Set<FeedEndpointID> newset = getAuthorization().getEndpointIDS();
\r
669 Set<FeedEndpointID> oldset = oldobj.getAuthorization().getEndpointIDS();
\r
670 try (PreparedStatement ps = conn.prepareStatement("insert into FEED_ENDPOINT_IDS values (?, ?, ?)")) {
\r
671 // Insert new FEED_ENDPOINT_IDS rows
\r
672 for (FeedEndpointID fid : newset) {
\r
673 if (!oldset.contains(fid)) {
\r
674 ps.setInt(1, feedid);
\r
675 ps.setString(2, fid.getId());
\r
676 ps.setString(3, fid.getPassword());
\r
677 ps.executeUpdate();
\r
681 // Delete old FEED_ENDPOINT_IDS rows
\r
682 try (PreparedStatement ps = conn.prepareStatement(
\r
683 "delete from FEED_ENDPOINT_IDS where FEEDID = ? AND USERID = ? AND PASSWORD = ?")) {
\r
684 for (FeedEndpointID fid : oldset) {
\r
685 if (!newset.contains(fid)) {
\r
686 ps.setInt(1, feedid);
\r
687 ps.setString(2, fid.getId());
\r
688 ps.setString(3, fid.getPassword());
\r
689 ps.executeUpdate();
\r
693 Set<String> newset2 = getAuthorization().getEndpointAddrs();
\r
694 Set<String> oldset2 = oldobj.getAuthorization().getEndpointAddrs();
\r
695 // Insert new FEED_ENDPOINT_ADDRS rows
\r
696 try (PreparedStatement ps = conn.prepareStatement("insert into FEED_ENDPOINT_ADDRS values (?, ?)")) {
\r
697 for (String t : newset2) {
\r
698 if (!oldset2.contains(t)) {
\r
699 ps.setInt(1, feedid);
\r
700 ps.setString(2, t);
\r
701 ps.executeUpdate();
\r
705 // Delete old FEED_ENDPOINT_ADDRS rows
\r
706 try (PreparedStatement ps = conn.prepareStatement(
\r
707 "delete from FEED_ENDPOINT_ADDRS where FEEDID = ? AND ADDR = ?")) {
\r
708 for (String t : oldset2) {
\r
709 if (!newset2.contains(t)) {
\r
710 ps.setInt(1, feedid);
\r
711 ps.setString(2, t);
\r
712 ps.executeUpdate();
\r
716 try (PreparedStatement ps = conn.prepareStatement(
\r
717 "update FEEDS set DESCRIPTION = ?, AUTH_CLASS = ?, DELETED = ?, SUSPENDED = ?, "
\r
718 + "BUSINESS_DESCRIPTION=?, GROUPID=? where FEEDID = ?")) {
\r
719 // Finally, update the FEEDS row
\r
720 ps.setString(1, getDescription());
\r
721 ps.setString(2, getAuthorization().getClassification());
\r
722 ps.setInt(3, deleted ? 1 : 0);
\r
723 ps.setInt(4, suspended ? 1 : 0);
\r
724 ps.setString(5, getBusinessDescription());
\r
725 ps.setInt(6, groupid);
\r
726 ps.setInt(7, feedid);
\r
727 ps.executeUpdate();
\r
729 } catch (SQLException e) {
\r
731 intlogger.warn("PROV0006 doUpdate: " + e.getMessage(), e);
\r
738 * Change Ownership of FEED - 1610
\r
740 public boolean changeOwnerShip() {
\r
742 try (Connection conn = ProvDbUtils.getInstance().getConnection();
\r
743 PreparedStatement ps = conn.prepareStatement(
\r
744 "update FEEDS set PUBLISHER = ? where FEEDID = ?")) {
\r
745 ps.setString(1, this.publisher);
\r
746 ps.setInt(2, feedid);
\r
748 } catch (SQLException e) {
\r
750 intlogger.warn("PROV0008 changeOwnerShip: " + e.getMessage(), e);
\r
757 public String getKey() {
\r
758 return "" + getFeedid();
\r
762 public boolean equals(Object obj) {
\r
763 if (!(obj instanceof Feed)) {
\r
766 Feed of = (Feed) obj;
\r
767 if (feedid != of.feedid) {
\r
770 if (groupid != of.groupid) {
\r
771 //New field is added - Groups feature Rally:US708115 - 1610
\r
774 if (!name.equals(of.name)) {
\r
777 if (!version.equals(of.version)) {
\r
780 if (!description.equals(of.description)) {
\r
783 if (!businessDescription.equals(of.businessDescription)) {
\r
784 // New field is added - Groups feature Rally:US708102 - 1610
\r
787 if (!publisher.equals(of.publisher)) {
\r
790 if (!authorization.equals(of.authorization)) {
\r
793 if (!links.equals(of.links)) {
\r
796 if (deleted != of.deleted) {
\r
799 if (suspended != of.suspended) {
\r
802 if (!aafInstance.equals(of.aafInstance)) {
\r
809 public String toString() {
\r
810 return "FEED: feedid=" + feedid + ", name=" + name + ", version=" + version;
\r
814 public int hashCode() {
\r
815 return super.hashCode();
\r