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
82 this("", "", "", "");
\r
87 * @param name feed name
\r
88 * @param version feed version
\r
89 * @param desc feed description
\r
90 * @param businessDescription feed business description
\r
92 public Feed(String name, String version, String desc, String businessDescription) {
\r
94 this.groupid = -1; //New field is added - Groups feature Rally:US708115 - 1610
\r
96 this.version = version;
\r
97 this.description = desc;
\r
98 this.businessDescription = businessDescription; // New field is added - Groups feature Rally:US708102 - 1610
\r
99 this.authorization = new FeedAuthorization();
\r
100 this.publisher = "";
\r
101 this.links = new FeedLinks();
\r
102 this.deleted = false;
\r
103 this.suspended = false;
\r
104 this.lastMod = new Date();
\r
105 this.createdDate = new Date();
\r
109 * Feed Constructor from ResultSet.
\r
110 * @param rs ResultSet
\r
111 * @throws SQLException in case of SQL statement error
\r
113 public Feed(ResultSet rs) throws SQLException {
\r
114 this.feedid = rs.getInt(FEED_ID_SQL);
\r
115 //New field is added - Groups feature Rally:US708115 - 1610
\r
116 this.groupid = rs.getInt("GROUPID");
\r
117 this.name = rs.getString("NAME");
\r
118 this.version = rs.getString("VERSION");
\r
119 this.description = rs.getString("DESCRIPTION");
\r
120 // New field is added - Groups feature Rally:US708102 - 1610
\r
121 this.businessDescription = rs.getString("BUSINESS_DESCRIPTION");
\r
122 this.authorization = new FeedAuthorization();
\r
123 this.authorization.setClassification(rs.getString("AUTH_CLASS"));
\r
124 this.publisher = rs.getString("PUBLISHER");
\r
125 this.links = new FeedLinks();
\r
126 this.links.setSelf(rs.getString("SELF_LINK"));
\r
127 this.links.setPublish(rs.getString("PUBLISH_LINK"));
\r
128 this.links.setSubscribe(rs.getString("SUBSCRIBE_LINK"));
\r
129 this.links.setLog(rs.getString("LOG_LINK"));
\r
130 this.deleted = rs.getBoolean("DELETED");
\r
131 this.suspended = rs.getBoolean("SUSPENDED");
\r
132 this.lastMod = rs.getDate("LAST_MOD");
\r
133 this.createdDate = rs.getTimestamp("CREATED_DATE");
\r
137 * Feed constructor from JSONObject.
\r
138 * @param jo JSONObject
\r
139 * @throws InvalidObjectException in case of JSON error
\r
141 public Feed(JSONObject jo) throws InvalidObjectException {
\r
142 this("", "", "", "");
\r
144 // The JSONObject is assumed to contain a vnd.dmaap-dr.feed representation
\r
145 this.feedid = jo.optInt(FEED_ID, -1);
\r
146 this.groupid = jo.optInt("groupid");
\r
147 this.name = jo.getString("name");
\r
148 if (name.length() > 255) {
\r
149 throw new InvalidObjectException("name field is too long");
\r
152 this.version = jo.getString("version");
\r
153 } catch (JSONException e) {
\r
154 intlogger.warn("PROV0023 Feed.Feed: " + e.getMessage(), e);
\r
155 this.version = null;
\r
157 if (version != null && version.length() > 20) {
\r
158 throw new InvalidObjectException("version field is too long");
\r
160 this.description = jo.optString("description");
\r
161 this.businessDescription = jo.optString("business_description");
\r
162 if (description.length() > 1000) {
\r
163 throw new InvalidObjectException("technical description field is too long");
\r
165 if (businessDescription.length() > 1000) {
\r
166 throw new InvalidObjectException("business description field is too long");
\r
168 this.authorization = new FeedAuthorization();
\r
169 JSONObject jauth = jo.getJSONObject("authorization");
\r
170 this.authorization.setClassification(jauth.getString("classification"));
\r
171 if (this.authorization.getClassification().length() > 32) {
\r
172 throw new InvalidObjectException("classification field is too long");
\r
174 JSONArray endPointIds = jauth.getJSONArray("endpoint_ids");
\r
175 for (int i = 0; i < endPointIds.length(); i++) {
\r
176 JSONObject id = endPointIds.getJSONObject(i);
\r
177 FeedEndpointID fid = new FeedEndpointID(id.getString("id"), id.getString("password"));
\r
178 if (fid.getId().length() > 60) {
\r
179 throw new InvalidObjectException("id field is too long (" + fid.getId() + ")");
\r
181 if (fid.getPassword().length() > 100) {
\r
182 //Fortify scan fixes - Privacy Violation
\r
183 throw new InvalidObjectException("password field is too long (" + fid.getPassword() + ")");
\r
185 this.authorization.getEndpointIDS().add(fid);
\r
187 if (this.authorization.getEndpointIDS().isEmpty()) {
\r
188 throw new InvalidObjectException("need to specify at least one endpoint_id");
\r
190 endPointIds = jauth.getJSONArray("endpoint_addrs");
\r
191 for (int i = 0; i < endPointIds.length(); i++) {
\r
192 String addr = endPointIds.getString(i);
\r
193 if (!JSONUtilities.validIPAddrOrSubnet(addr)) {
\r
194 throw new InvalidObjectException("bad IP addr or subnet mask: " + addr);
\r
196 this.authorization.getEndpointAddrs().add(addr);
\r
199 this.publisher = jo.optString("publisher", "");
\r
200 this.deleted = jo.optBoolean(DEL, false);
\r
201 this.suspended = jo.optBoolean("suspend", false);
\r
202 JSONObject jol = jo.optJSONObject("links");
\r
203 this.links = (jol == null) ? (new FeedLinks()) : (new FeedLinks(jol));
\r
204 } catch (InvalidObjectException e) {
\r
206 } catch (Exception e) {
\r
207 intlogger.warn("Invalid JSON: " + e.getMessage(), e);
\r
208 throw new InvalidObjectException("Invalid JSON: " + e.getMessage());
\r
213 * Check if a feed ID is valid.
\r
215 * @param id the Feed ID
\r
216 * @return true if it is valid
\r
218 @SuppressWarnings("resource")
\r
219 static boolean isFeedValid(int id) {
\r
221 try (Connection conn = ProvDbUtils.getInstance().getConnection();
\r
222 PreparedStatement ps = conn.prepareStatement(
\r
223 "select COUNT(*) from FEEDS where FEEDID = ?")) {
\r
225 try (ResultSet rs = ps.executeQuery()) {
\r
227 count = rs.getInt(1);
\r
230 } catch (SQLException e) {
\r
231 intlogger.warn("PROV0024 Feed.isFeedValid: " + e.getMessage(), e);
\r
237 * Get a specific feed from the DB, based upon its ID.
\r
239 * @param id the Feed ID
\r
240 * @return the Feed object, or null if it does not exist
\r
242 public static Feed getFeedById(int id) {
\r
243 String sql = "select * from FEEDS where FEEDID = " + id;
\r
244 return getFeedBySQL(sql);
\r
248 * Get a specific feed from the DB, based upon its name and version.
\r
250 * @param name the name of the Feed
\r
251 * @param version the version of the Feed
\r
252 * @return the Feed object, or null if it does not exist
\r
254 public static Feed getFeedByNameVersion(String name, String version) {
\r
255 name = name.replaceAll("'", "''");
\r
256 version = version.replaceAll("'", "''");
\r
257 String sql = "select * from FEEDS where NAME = '" + name + "' and VERSION ='" + version + "'";
\r
258 return getFeedBySQL(sql);
\r
262 * Return a count of the number of active feeds in the DB.
\r
264 * @return the count
\r
266 public static int countActiveFeeds() {
\r
268 try (Connection conn = ProvDbUtils.getInstance().getConnection();
\r
269 PreparedStatement ps = conn.prepareStatement(
\r
270 "select count(*) from FEEDS where DELETED = 0")) {
\r
271 try (ResultSet rs = ps.executeQuery()) {
\r
273 count = rs.getInt(1);
\r
276 } catch (SQLException e) {
\r
277 intlogger.warn("PROV0025 Feed.countActiveFeeds: " + e.getMessage(), e);
\r
283 * Method to get max feed id.
\r
284 * @return int max feed id
\r
286 public static int getMaxFeedID() {
\r
288 try (Connection conn = ProvDbUtils.getInstance().getConnection();
\r
289 PreparedStatement ps = conn.prepareStatement(
\r
290 "select MAX(feedid) from FEEDS")) {
\r
291 try (ResultSet rs = ps.executeQuery()) {
\r
293 max = rs.getInt(1);
\r
296 } catch (SQLException e) {
\r
297 intlogger.warn("PROV0026 Feed.getMaxFeedID: " + e.getMessage(), e);
\r
304 * @return Collection of feeds
\r
306 public static Collection<Feed> getAllFeeds() {
\r
307 Map<Integer, Feed> map = new HashMap<>();
\r
308 try (Connection conn = ProvDbUtils.getInstance().getConnection()) {
\r
309 try (PreparedStatement ps = conn.prepareStatement("select * from FEEDS");
\r
310 ResultSet rs = ps.executeQuery()) {
\r
311 while (rs.next()) {
\r
312 Feed feed = new Feed(rs);
\r
313 map.put(feed.getFeedid(), feed);
\r
316 try (PreparedStatement ps = conn.prepareStatement("select * from FEED_ENDPOINT_IDS");
\r
317 ResultSet rs = ps.executeQuery()) {
\r
318 while (rs.next()) {
\r
319 int id = rs.getInt(FEED_ID_SQL);
\r
320 Feed feed = map.get(id);
\r
321 if (feed != null) {
\r
322 FeedEndpointID epi = new FeedEndpointID(rs);
\r
323 Collection<FeedEndpointID> ecoll = feed.getAuthorization().getEndpointIDS();
\r
328 try (PreparedStatement ps = conn.prepareStatement("select * from FEED_ENDPOINT_ADDRS");
\r
329 ResultSet rs = ps.executeQuery()) {
\r
330 while (rs.next()) {
\r
331 int id = rs.getInt(FEED_ID_SQL);
\r
332 Feed feed = map.get(id);
\r
333 if (feed != null) {
\r
334 Collection<String> acoll = feed.getAuthorization().getEndpointAddrs();
\r
335 acoll.add(rs.getString("ADDR"));
\r
339 } catch (SQLException e) {
\r
340 intlogger.warn("PROV0027 Feed.getAllFeeds: " + e.getMessage(), e);
\r
342 return map.values();
\r
346 * Get Feed URL list.
\r
347 * @param name of Feed
\r
348 * @param val of feed
\r
349 * @return List of feed names
\r
351 public static List<String> getFilteredFeedUrlList(final String name, final String val) {
\r
352 List<String> list = new ArrayList<>();
\r
353 String sql = "select SELF_LINK from FEEDS where DELETED = 0";
\r
354 if (name.equals("name")) {
\r
355 sql += " and NAME = ?";
\r
356 } else if (name.equals("publ")) {
\r
357 sql += " and PUBLISHER = ?";
\r
358 } else if (name.equals("subs")) {
\r
359 sql = "select distinct FEEDS.SELF_LINK from FEEDS, SUBSCRIPTIONS "
\r
360 + "where DELETED = 0 "
\r
361 + "and FEEDS.FEEDID = SUBSCRIPTIONS.FEEDID "
\r
362 + "and SUBSCRIPTIONS.SUBSCRIBER = ?";
\r
364 try (Connection conn = ProvDbUtils.getInstance().getConnection();
\r
365 PreparedStatement ps = conn.prepareStatement(sql)) {
\r
366 if (sql.indexOf('?') >= 0) {
\r
367 ps.setString(1, val);
\r
369 try (ResultSet rs = ps.executeQuery()) {
\r
370 while (rs.next()) {
\r
371 String str = rs.getString(1);
\r
372 list.add(str.trim());
\r
375 } catch (SQLException e) {
\r
376 intlogger.warn("PROV0028 Feed.getFilteredFeedUrlList: " + e.getMessage(), e);
\r
381 @SuppressWarnings("resource")
\r
382 private static Feed getFeedBySQL(String sql) {
\r
384 try (Connection conn = ProvDbUtils.getInstance().getConnection()) {
\r
385 try (Statement stmt = conn.createStatement()) {
\r
386 try (ResultSet rs = stmt.executeQuery(sql)) {
\r
388 feed = new Feed(rs);
\r
391 if (feed != null) {
\r
392 sql = "select * from FEED_ENDPOINT_IDS where FEEDID = " + feed.feedid;
\r
393 try (ResultSet rs = stmt.executeQuery(sql)) {
\r
394 Collection<FeedEndpointID> ecoll = feed.getAuthorization().getEndpointIDS();
\r
395 while (rs.next()) {
\r
396 FeedEndpointID epi = new FeedEndpointID(rs);
\r
400 sql = "select * from FEED_ENDPOINT_ADDRS where FEEDID = " + feed.feedid;
\r
401 try (ResultSet rs = stmt.executeQuery(sql)) {
\r
402 Collection<String> acoll = feed.getAuthorization().getEndpointAddrs();
\r
403 while (rs.next()) {
\r
404 acoll.add(rs.getString("ADDR"));
\r
409 } catch (SQLException e) {
\r
410 intlogger.warn("PROV0029 Feed.getFeedBySQL: " + e.getMessage(), e);
\r
417 public int getFeedid() {
\r
422 * Set feedid with FeedLinks.
\r
423 * @param feedid Feedid to set to
\r
425 public void setFeedid(int feedid) {
\r
426 this.feedid = feedid;
\r
428 // Create link URLs
\r
429 FeedLinks fl = getLinks();
\r
430 fl.setSelf(URLUtilities.generateFeedURL(feedid));
\r
431 fl.setPublish(URLUtilities.generatePublishURL(feedid));
\r
432 fl.setSubscribe(URLUtilities.generateSubscribeURL(feedid));
\r
433 fl.setLog(URLUtilities.generateFeedLogURL(feedid));
\r
436 //new getter setters for groups- Rally:US708115 - 1610
\r
437 public int getGroupid() {
\r
441 public void setGroupid(int groupid) {
\r
442 this.groupid = groupid;
\r
445 public String getName() {
\r
449 public void setName(String name) {
\r
453 public String getVersion() {
\r
457 public void setVersion(String version) {
\r
458 this.version = version;
\r
461 public String getDescription() {
\r
462 return description;
\r
465 public void setDescription(String description) {
\r
466 this.description = description;
\r
469 // New field is added - Groups feature Rally:US708102 - 1610
\r
470 String getBusinessDescription() {
\r
471 return businessDescription;
\r
474 void setBusinessDescription(String businessDescription) {
\r
475 this.businessDescription = businessDescription;
\r
478 public FeedAuthorization getAuthorization() {
\r
479 return authorization;
\r
482 public void setAuthorization(FeedAuthorization authorization) {
\r
483 this.authorization = authorization;
\r
486 public String getPublisher() {
\r
492 * @param publisher Publisher name
\r
494 public void setPublisher(String publisher) {
\r
495 if (publisher != null) {
\r
496 if (publisher.length() > 8) {
\r
497 publisher = publisher.substring(0, 8);
\r
499 this.publisher = publisher;
\r
503 public FeedLinks getLinks() {
\r
507 void setLinks(FeedLinks links) {
\r
508 this.links = links;
\r
511 public boolean isDeleted() {
\r
515 public void setDeleted(boolean deleted) {
\r
516 this.deleted = deleted;
\r
519 boolean isSuspended() {
\r
523 void setSuspended(boolean suspended) {
\r
524 this.suspended = suspended;
\r
528 public JSONObject asJSONObject() {
\r
529 JSONObject jo = new JSONObject();
\r
530 jo.put(FEED_ID, feedid);
\r
531 //New field is added - Groups feature Rally:US708115 - 1610
\r
532 jo.put("groupid", groupid);
\r
533 jo.put("name", name);
\r
534 jo.put("version", version);
\r
535 jo.put("description", description);
\r
536 // New field is added - Groups feature Rally:US708102 - 1610
\r
537 jo.put("business_description", businessDescription);
\r
538 jo.put("authorization", authorization.asJSONObject());
\r
539 jo.put("publisher", publisher);
\r
540 jo.put("links", links.asJSONObject());
\r
541 jo.put(DEL, deleted);
\r
542 jo.put("suspend", suspended);
\r
543 jo.put(LAST_MOD, lastMod.getTime());
\r
544 jo.put(CREATED_DATE, createdDate.getTime());
\r
549 * Method to hide some attributes.
\r
550 * @param hidepasswords true/false
\r
551 * @return JSONObject
\r
553 public JSONObject asJSONObject(boolean hidepasswords) {
\r
554 JSONObject jo = asJSONObject();
\r
555 if (hidepasswords) {
\r
556 jo.remove(FEED_ID); // we no longer hide passwords, however we do hide these
\r
558 jo.remove(LAST_MOD);
\r
559 jo.remove(CREATED_DATE);
\r
565 * Method to limit JSONObject.
\r
566 * @return JSONObject
\r
568 public JSONObject asLimitedJSONObject() {
\r
569 JSONObject jo = asJSONObject();
\r
571 jo.remove(FEED_ID);
\r
572 jo.remove(LAST_MOD);
\r
573 jo.remove(CREATED_DATE);
\r
580 public boolean doDelete(Connection conn) {
\r
582 try (PreparedStatement ps = conn.prepareStatement("delete from FEEDS where FEEDID = ?")) {
\r
583 ps.setInt(1, feedid);
\r
585 } catch (SQLException e) {
\r
587 intlogger.error("PROV0007 doDelete: " + e.getMessage(), e);
\r
593 public synchronized boolean doInsert(Connection conn) {
\r
596 if (feedid == -1) {
\r
597 setFeedid(nextFeedID++);
\r
599 // In case we insert a feed from synchronization
\r
600 if (feedid > nextFeedID) {
\r
601 nextFeedID = feedid + 1;
\r
603 // Create FEED_ENDPOINT_IDS rows
\r
604 FeedAuthorization auth = getAuthorization();
\r
605 try (PreparedStatement ps = conn.prepareStatement("insert into FEED_ENDPOINT_IDS values (?, ?, ?)")) {
\r
606 for (FeedEndpointID fid : auth.getEndpointIDS()) {
\r
607 ps.setInt(1, feedid);
\r
608 ps.setString(2, fid.getId());
\r
609 ps.setString(3, fid.getPassword());
\r
610 ps.executeUpdate();
\r
613 // Create FEED_ENDPOINT_ADDRS rows
\r
614 try (PreparedStatement ps = conn.prepareStatement("insert into FEED_ENDPOINT_ADDRS values (?, ?)")) {
\r
615 for (String t : auth.getEndpointAddrs()) {
\r
616 ps.setInt(1, feedid);
\r
617 ps.setString(2, t);
\r
618 ps.executeUpdate();
\r
621 // Finally, create the FEEDS row
\r
622 try (PreparedStatement ps = conn.prepareStatement(
\r
623 "insert into FEEDS (FEEDID, NAME, VERSION, DESCRIPTION, AUTH_CLASS, PUBLISHER, SELF_LINK, "
\r
624 + "PUBLISH_LINK, SUBSCRIBE_LINK, LOG_LINK, DELETED, SUSPENDED,"
\r
625 + "BUSINESS_DESCRIPTION, GROUPID) "
\r
626 + "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) {
\r
627 ps.setInt(1, feedid);
\r
628 ps.setString(2, getName());
\r
629 ps.setString(3, getVersion());
\r
630 ps.setString(4, getDescription());
\r
631 ps.setString(5, getAuthorization().getClassification());
\r
632 ps.setString(6, getPublisher());
\r
633 ps.setString(7, getLinks().getSelf());
\r
634 ps.setString(8, getLinks().getPublish());
\r
635 ps.setString(9, getLinks().getSubscribe());
\r
636 ps.setString(10, getLinks().getLog());
\r
637 ps.setBoolean(11, isDeleted());
\r
638 ps.setBoolean(12, isSuspended());
\r
639 ps.setString(13, getBusinessDescription());
\r
640 ps.setInt(14, groupid);
\r
641 ps.executeUpdate();
\r
643 } catch (SQLException e) {
\r
645 intlogger.error("PROV0005 doInsert: " + e.getMessage(), e);
\r
651 public boolean doUpdate(Connection conn) {
\r
654 Feed oldobj = getFeedById(feedid);
\r
655 Set<FeedEndpointID> newset = getAuthorization().getEndpointIDS();
\r
656 Set<FeedEndpointID> oldset = oldobj.getAuthorization().getEndpointIDS();
\r
657 try (PreparedStatement ps = conn.prepareStatement("insert into FEED_ENDPOINT_IDS values (?, ?, ?)")) {
\r
658 // Insert new FEED_ENDPOINT_IDS rows
\r
659 for (FeedEndpointID fid : newset) {
\r
660 if (!oldset.contains(fid)) {
\r
661 ps.setInt(1, feedid);
\r
662 ps.setString(2, fid.getId());
\r
663 ps.setString(3, fid.getPassword());
\r
664 ps.executeUpdate();
\r
668 // Delete old FEED_ENDPOINT_IDS rows
\r
669 try (PreparedStatement ps = conn.prepareStatement(
\r
670 "delete from FEED_ENDPOINT_IDS where FEEDID = ? AND USERID = ? AND PASSWORD = ?")) {
\r
671 for (FeedEndpointID fid : oldset) {
\r
672 if (!newset.contains(fid)) {
\r
673 ps.setInt(1, feedid);
\r
674 ps.setString(2, fid.getId());
\r
675 ps.setString(3, fid.getPassword());
\r
676 ps.executeUpdate();
\r
680 Set<String> newset2 = getAuthorization().getEndpointAddrs();
\r
681 Set<String> oldset2 = oldobj.getAuthorization().getEndpointAddrs();
\r
682 // Insert new FEED_ENDPOINT_ADDRS rows
\r
683 try (PreparedStatement ps = conn.prepareStatement("insert into FEED_ENDPOINT_ADDRS values (?, ?)")) {
\r
684 for (String t : newset2) {
\r
685 if (!oldset2.contains(t)) {
\r
686 ps.setInt(1, feedid);
\r
687 ps.setString(2, t);
\r
688 ps.executeUpdate();
\r
692 // Delete old FEED_ENDPOINT_ADDRS rows
\r
693 try (PreparedStatement ps = conn.prepareStatement(
\r
694 "delete from FEED_ENDPOINT_ADDRS where FEEDID = ? AND ADDR = ?")) {
\r
695 for (String t : oldset2) {
\r
696 if (!newset2.contains(t)) {
\r
697 ps.setInt(1, feedid);
\r
698 ps.setString(2, t);
\r
699 ps.executeUpdate();
\r
703 try (PreparedStatement ps = conn.prepareStatement(
\r
704 "update FEEDS set DESCRIPTION = ?, AUTH_CLASS = ?, DELETED = ?, SUSPENDED = ?, "
\r
705 + "BUSINESS_DESCRIPTION=?, GROUPID=? where FEEDID = ?")) {
\r
706 // Finally, update the FEEDS row
\r
707 ps.setString(1, getDescription());
\r
708 ps.setString(2, getAuthorization().getClassification());
\r
709 ps.setInt(3, deleted ? 1 : 0);
\r
710 ps.setInt(4, suspended ? 1 : 0);
\r
711 ps.setString(5, getBusinessDescription());
\r
712 ps.setInt(6, groupid);
\r
713 ps.setInt(7, feedid);
\r
714 ps.executeUpdate();
\r
716 } catch (SQLException e) {
\r
718 intlogger.warn("PROV0006 doUpdate: " + e.getMessage(), e);
\r
725 * Change Ownership of FEED - 1610
\r
727 public boolean changeOwnerShip() {
\r
729 try (Connection conn = ProvDbUtils.getInstance().getConnection();
\r
730 PreparedStatement ps = conn.prepareStatement(
\r
731 "update FEEDS set PUBLISHER = ? where FEEDID = ?")) {
\r
732 ps.setString(1, this.publisher);
\r
733 ps.setInt(2, feedid);
\r
735 } catch (SQLException e) {
\r
737 intlogger.warn("PROV0008 changeOwnerShip: " + e.getMessage(), e);
\r
744 public String getKey() {
\r
745 return "" + getFeedid();
\r
749 public boolean equals(Object obj) {
\r
750 if (!(obj instanceof Feed)) {
\r
753 Feed of = (Feed) obj;
\r
754 if (feedid != of.feedid) {
\r
757 if (groupid != of.groupid) {
\r
758 //New field is added - Groups feature Rally:US708115 - 1610
\r
761 if (!name.equals(of.name)) {
\r
764 if (!version.equals(of.version)) {
\r
767 if (!description.equals(of.description)) {
\r
770 if (!businessDescription.equals(of.businessDescription)) {
\r
771 // New field is added - Groups feature Rally:US708102 - 1610
\r
774 if (!publisher.equals(of.publisher)) {
\r
777 if (!authorization.equals(of.authorization)) {
\r
780 if (!links.equals(of.links)) {
\r
783 if (deleted != of.deleted) {
\r
786 if (suspended != of.suspended) {
\r
793 public String toString() {
\r
794 return "FEED: feedid=" + feedid + ", name=" + name + ", version=" + version;
\r
798 public int hashCode() {
\r
799 return super.hashCode();
\r