Removing unused code
[dmaap/datarouter.git] / datarouter-prov / src / main / java / org / onap / dmaap / datarouter / provisioning / beans / Feed.java
1 /*******************************************************************************\r
2  * ============LICENSE_START==================================================\r
3  * * org.onap.dmaap\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
10  * *\r
11  *  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * *\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
19  * *\r
20  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
21  * *\r
22  ******************************************************************************/\r
23 \r
24 \r
25 package org.onap.dmaap.datarouter.provisioning.beans;\r
26 \r
27 import com.att.eelf.configuration.EELFLogger;\r
28 import com.att.eelf.configuration.EELFManager;\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.URLUtilities;\r
35 \r
36 import java.io.InvalidObjectException;\r
37 import java.sql.*;\r
38 import java.util.Date;\r
39 import java.util.*;\r
40 \r
41 /**\r
42  * The representation of a Feed.  Feeds can be retrieved from the DB, or stored/updated in the DB.\r
43  *\r
44  * @author Robert Eby\r
45  * @version $Id: Feed.java,v 1.13 2013/10/28 18:06:52 eby Exp $\r
46  */\r
47 public class Feed extends Syncable {\r
48     private static EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");\r
49     private static int next_feedid = getMaxFeedID() + 1;\r
50     private static final String SQLEXCEPTION = "SQLException: ";\r
51 \r
52     private int feedid;\r
53     private int groupid; //New field is added - Groups feature Rally:US708115 - 1610\r
54     private String name;\r
55     private String version;\r
56     private String description;\r
57     private String business_description; // New field is added - Groups feature Rally:US708102 - 1610\r
58     private FeedAuthorization authorization;\r
59     private String publisher;\r
60     private FeedLinks links;\r
61     private boolean deleted;\r
62     private boolean suspended;\r
63     private Date last_mod;\r
64     private Date created_date;\r
65     private String aaf_instance;\r
66 \r
67     /**\r
68      * Check if a feed ID is valid.\r
69      *\r
70      * @param id the Feed ID\r
71      * @return true if it is valid\r
72      */\r
73     @SuppressWarnings("resource")\r
74     public static boolean isFeedValid(int id) {\r
75         int count = 0;\r
76         try {\r
77             DB db = new DB();\r
78             Connection conn = db.getConnection();\r
79             try(PreparedStatement stmt = conn.prepareStatement("select COUNT(*) from FEEDS where FEEDID = ?")) {\r
80                 stmt.setInt(1, id);\r
81                 try(ResultSet rs = stmt.executeQuery()) {\r
82                     if (rs.next()) {\r
83                         count = rs.getInt(1);\r
84                     }\r
85                 }\r
86             }\r
87             db.release(conn);\r
88         } catch (SQLException e) {\r
89             intlogger.warn("PROV0024 Feed.isFeedValid: " + e.getMessage(), e);\r
90         }\r
91         return count != 0;\r
92     }\r
93 \r
94     /**\r
95      * Get a specific feed from the DB, based upon its ID.\r
96      *\r
97      * @param id the Feed ID\r
98      * @return the Feed object, or null if it does not exist\r
99      */\r
100     public static Feed getFeedById(int id) {\r
101         String sql = "select * from FEEDS where FEEDID = " + id;\r
102         return getFeedBySQL(sql);\r
103     }\r
104 \r
105     /**\r
106      * Get a specific feed from the DB, based upon its name and version.\r
107      *\r
108      * @param name    the name of the Feed\r
109      * @param version the version of the Feed\r
110      * @return the Feed object, or null if it does not exist\r
111      */\r
112     public static Feed getFeedByNameVersion(String name, String version) {\r
113         name = name.replaceAll("'", "''");\r
114         version = version.replaceAll("'", "''");\r
115         String sql = "select * from FEEDS where NAME = '" + name + "' and VERSION ='" + version + "'";\r
116         return getFeedBySQL(sql);\r
117     }\r
118 \r
119     /**\r
120      * Return a count of the number of active feeds in the DB.\r
121      *\r
122      * @return the count\r
123      */\r
124     public static int countActiveFeeds() {\r
125         int count = 0;\r
126         try {\r
127             DB db = new DB();\r
128             @SuppressWarnings("resource")\r
129             Connection conn = db.getConnection();\r
130             try(Statement stmt = conn.createStatement()) {\r
131                 try (ResultSet rs = stmt.executeQuery("select count(*) from FEEDS where DELETED = 0")) {\r
132                     if (rs.next()) {\r
133                         count = rs.getInt(1);\r
134                     }\r
135                 }\r
136             }\r
137             db.release(conn);\r
138         } catch (SQLException e) {\r
139             intlogger.warn("PROV0025 Feed.countActiveFeeds: " + e.getMessage(), e);\r
140         }\r
141         return count;\r
142     }\r
143 \r
144     public static int getMaxFeedID() {\r
145         int max = 0;\r
146         try {\r
147             DB db = new DB();\r
148             @SuppressWarnings("resource")\r
149             Connection conn = db.getConnection();\r
150             try(Statement stmt = conn.createStatement()) {\r
151                 try (ResultSet rs = stmt.executeQuery("select MAX(feedid) from FEEDS")) {\r
152                     if (rs.next()) {\r
153                         max = rs.getInt(1);\r
154                     }\r
155                 }\r
156             }\r
157             db.release(conn);\r
158         } catch (SQLException e) {\r
159             intlogger.warn("PROV0026 Feed.getMaxFeedID: " + e.getMessage(), e);\r
160         }\r
161         return max;\r
162     }\r
163 \r
164     public static Collection<Feed> getAllFeeds() {\r
165         Map<Integer, Feed> map = new HashMap<Integer, Feed>();\r
166         try {\r
167             DB db = new DB();\r
168             @SuppressWarnings("resource")\r
169             Connection conn = db.getConnection();\r
170             try(Statement stmt = conn.createStatement()) {\r
171                 try(ResultSet rs = stmt.executeQuery("select * from FEEDS")) {\r
172                     while (rs.next()) {\r
173                         Feed feed = new Feed(rs);\r
174                         map.put(feed.getFeedid(), feed);\r
175                     }\r
176                 }\r
177 \r
178                 String sql = "select * from FEED_ENDPOINT_IDS";\r
179                 try(ResultSet rs = stmt.executeQuery(sql)){\r
180                     while (rs.next()) {\r
181                         int id = rs.getInt("FEEDID");\r
182                         Feed feed = map.get(id);\r
183                         if (feed != null) {\r
184                             FeedEndpointID epi = new FeedEndpointID(rs);\r
185                             Collection<FeedEndpointID> ecoll = feed.getAuthorization().getEndpoint_ids();\r
186                             ecoll.add(epi);\r
187                         }\r
188                     }\r
189                 }\r
190 \r
191                 sql = "select * from FEED_ENDPOINT_ADDRS";\r
192                 try(ResultSet rs = stmt.executeQuery(sql)) {\r
193                     while (rs.next()) {\r
194                         int id = rs.getInt("FEEDID");\r
195                         Feed feed = map.get(id);\r
196                         if (feed != null) {\r
197                             Collection<String> acoll = feed.getAuthorization().getEndpoint_addrs();\r
198                             acoll.add(rs.getString("ADDR"));\r
199                         }\r
200                     }\r
201                 }\r
202             }\r
203             db.release(conn);\r
204         } catch (SQLException e) {\r
205             intlogger.warn("PROV0027 Feed.getAllFeeds: " + e.getMessage(), e);\r
206         }\r
207         return map.values();\r
208     }\r
209 \r
210     public static List<String> getFilteredFeedUrlList(final String name, final String val) {\r
211         List<String> list = new ArrayList<String>();\r
212         String sql = "select SELF_LINK from FEEDS where DELETED = 0";\r
213         if (name.equals("name")) {\r
214             sql += " and NAME = ?";\r
215         } else if (name.equals("publ")) {\r
216             sql += " and PUBLISHER = ?";\r
217         } else if (name.equals("subs")) {\r
218             sql = "select distinct FEEDS.SELF_LINK from FEEDS, SUBSCRIPTIONS " +\r
219                     "where DELETED = 0 " +\r
220                     "and FEEDS.FEEDID = SUBSCRIPTIONS.FEEDID " +\r
221                     "and SUBSCRIPTIONS.SUBSCRIBER = ?";\r
222         }\r
223         try {\r
224             DB db = new DB();\r
225             @SuppressWarnings("resource")\r
226             Connection conn = db.getConnection();\r
227             try(PreparedStatement ps = conn.prepareStatement(sql)) {\r
228                 if (sql.indexOf('?') >= 0)\r
229                     ps.setString(1, val);\r
230                 try(ResultSet rs = ps.executeQuery()) {\r
231                     while (rs.next()) {\r
232                         String t = rs.getString(1);\r
233                         list.add(t.trim());\r
234                     }\r
235                 }\r
236             }\r
237             db.release(conn);\r
238         } catch (SQLException e) {\r
239             intlogger.warn("PROV0028 Feed.getFilteredFeedUrlList: " + e.getMessage(), e);\r
240         }\r
241         return list;\r
242     }\r
243 \r
244     @SuppressWarnings("resource")\r
245     private static Feed getFeedBySQL(String sql) {\r
246         Feed feed = null;\r
247         try {\r
248             DB db = new DB();\r
249             Connection conn = db.getConnection();\r
250             try (Statement stmt = conn.createStatement()) {\r
251                 try (ResultSet rs = stmt.executeQuery(sql)) {\r
252                     if (rs.next()) {\r
253                         feed = new Feed(rs);\r
254                     }\r
255                 }\r
256                 if (feed != null) {\r
257                     sql = "select * from FEED_ENDPOINT_IDS where FEEDID = " + feed.feedid;\r
258                     try (ResultSet rs = stmt.executeQuery(sql)) {\r
259                         Collection<FeedEndpointID> ecoll = feed.getAuthorization().getEndpoint_ids();\r
260                         while (rs.next()) {\r
261                             FeedEndpointID epi = new FeedEndpointID(rs);\r
262                             ecoll.add(epi);\r
263                         }\r
264                     }\r
265                     sql = "select * from FEED_ENDPOINT_ADDRS where FEEDID = " + feed.feedid;\r
266                     try (ResultSet rs = stmt.executeQuery(sql)) {\r
267                         Collection<String> acoll = feed.getAuthorization().getEndpoint_addrs();\r
268                         while (rs.next()) {\r
269                             acoll.add(rs.getString("ADDR"));\r
270                         }\r
271                     }\r
272                 }\r
273             }\r
274             db.release(conn);\r
275         } catch (SQLException e) {\r
276             intlogger.warn("PROV0029 Feed.getFeedBySQL: " + e.getMessage(), e);\r
277         }\r
278         return feed;\r
279     }\r
280 \r
281     public Feed() {\r
282         this("", "", "", "");\r
283     }\r
284 \r
285     public Feed(String name, String version, String desc, String business_description) {\r
286         this.feedid = -1;\r
287         this.groupid = -1; //New field is added - Groups feature Rally:US708115 - 1610\r
288         this.name = name;\r
289         this.version = version;\r
290         this.description = desc;\r
291         this.business_description = business_description; // New field is added - Groups feature Rally:US708102 - 1610\r
292         this.authorization = new FeedAuthorization();\r
293         this.publisher = "";\r
294         this.links = new FeedLinks();\r
295         this.deleted = false;\r
296         this.suspended = false;\r
297         this.last_mod = new Date();\r
298         this.created_date = new Date();\r
299         this.aaf_instance = "";\r
300     }\r
301 \r
302     public Feed(ResultSet rs) throws SQLException {\r
303         this.feedid = rs.getInt("FEEDID");\r
304         this.groupid = rs.getInt("GROUPID"); //New field is added - Groups feature Rally:US708115 - 1610\r
305         this.name = rs.getString("NAME");\r
306         this.version = rs.getString("VERSION");\r
307         this.description = rs.getString("DESCRIPTION");\r
308         this.business_description = rs.getString("BUSINESS_DESCRIPTION"); // New field is added - Groups feature Rally:US708102 - 1610\r
309         this.authorization = new FeedAuthorization();\r
310         this.authorization.setClassification(rs.getString("AUTH_CLASS"));\r
311         this.publisher = rs.getString("PUBLISHER");\r
312         this.links = new FeedLinks();\r
313         this.links.setSelf(rs.getString("SELF_LINK"));\r
314         this.links.setPublish(rs.getString("PUBLISH_LINK"));\r
315         this.links.setSubscribe(rs.getString("SUBSCRIBE_LINK"));\r
316         this.links.setLog(rs.getString("LOG_LINK"));\r
317         this.deleted = rs.getBoolean("DELETED");\r
318         this.suspended = rs.getBoolean("SUSPENDED");\r
319         this.last_mod = rs.getDate("LAST_MOD");\r
320         this.created_date = rs.getTimestamp("CREATED_DATE");\r
321         this.aaf_instance = rs.getString("AAF_INSTANCE");\r
322     }\r
323 \r
324     public Feed(JSONObject jo) throws InvalidObjectException {\r
325         this("", "", "", "");\r
326         try {\r
327             // The JSONObject is assumed to contain a vnd.dmaap-dr.feed representation\r
328             this.feedid = jo.optInt("feedid", -1);\r
329             this.groupid = jo.optInt("groupid");\r
330             this.name = jo.getString("name");\r
331             this.aaf_instance = jo.optString("aaf_instance", "legacy");\r
332             if(!(aaf_instance.equalsIgnoreCase("legacy"))){\r
333                 if (aaf_instance.length() > 255){\r
334                     throw new InvalidObjectException("aaf_instance field is too long");\r
335                 }\r
336             }\r
337             if (name.length() > 255)\r
338                 throw new InvalidObjectException("name field is too long");\r
339             try {\r
340                 this.version = jo.getString("version");\r
341             } catch (JSONException e) {\r
342                 intlogger.warn("PROV0023 Feed.Feed: " + e.getMessage(), e);\r
343                 this.version = null;\r
344             }\r
345             if(version != null && version.length() > 20)\r
346                 throw new InvalidObjectException("version field is too long");\r
347             this.description = jo.optString("description");\r
348             this.business_description = jo.optString("business_description");\r
349             if (description.length() > 1000)\r
350                 throw new InvalidObjectException("technical description field is too long");\r
351             if (business_description.length() > 1000)\r
352                 throw new InvalidObjectException("business description field is too long");\r
353             this.authorization = new FeedAuthorization();\r
354             JSONObject jauth = jo.getJSONObject("authorization");\r
355             this.authorization.setClassification(jauth.getString("classification"));\r
356             if (this.authorization.getClassification().length() > 32)\r
357                 throw new InvalidObjectException("classification field is too long");\r
358             JSONArray endPointIds = jauth.getJSONArray("endpoint_ids");\r
359             for (int i = 0; i < endPointIds.length(); i++) {\r
360                 JSONObject id = endPointIds.getJSONObject(i);\r
361                 FeedEndpointID fid = new FeedEndpointID(id.getString("id"), id.getString("password"));\r
362                 if (fid.getId().length() > 60)\r
363                     throw new InvalidObjectException("id field is too long (" + fid.getId() + ")");\r
364                 if (fid.getPassword().length() > 32)\r
365                     throw new InvalidObjectException("password field is too long ("+ fid.getPassword()+")");  //Fortify scan fixes - Privacy Violation\r
366                 this.authorization.getEndpoint_ids().add(fid);\r
367             }\r
368             if (this.authorization.getEndpoint_ids().size() < 1)\r
369                 throw new InvalidObjectException("need to specify at least one endpoint_id");\r
370             endPointIds = jauth.getJSONArray("endpoint_addrs");\r
371             for (int i = 0; i < endPointIds.length(); i++) {\r
372                 String addr = endPointIds.getString(i);\r
373                 if (!JSONUtilities.validIPAddrOrSubnet(addr))\r
374                     throw new InvalidObjectException("bad IP addr or subnet mask: " + addr);\r
375                 this.authorization.getEndpoint_addrs().add(addr);\r
376             }\r
377 \r
378             this.publisher = jo.optString("publisher", "");\r
379             this.deleted = jo.optBoolean("deleted", false);\r
380             this.suspended = jo.optBoolean("suspend", false);\r
381             JSONObject jol = jo.optJSONObject("links");\r
382             this.links = (jol == null) ? (new FeedLinks()) : (new FeedLinks(jol));\r
383         } catch (InvalidObjectException e) {\r
384             throw e;\r
385         } catch (Exception e) {\r
386             intlogger.warn("Invalid JSON: " + e.getMessage(), e);\r
387             throw new InvalidObjectException("Invalid JSON: " + e.getMessage());\r
388         }\r
389     }\r
390 \r
391     public int getFeedid() {\r
392         return feedid;\r
393     }\r
394 \r
395     public void setFeedid(int feedid) {\r
396         this.feedid = feedid;\r
397 \r
398         // Create link URLs\r
399         FeedLinks fl = getLinks();\r
400         fl.setSelf(URLUtilities.generateFeedURL(feedid));\r
401         fl.setPublish(URLUtilities.generatePublishURL(feedid));\r
402         fl.setSubscribe(URLUtilities.generateSubscribeURL(feedid));\r
403         fl.setLog(URLUtilities.generateFeedLogURL(feedid));\r
404     }\r
405 \r
406     public String getAafInstance() {\r
407         return aaf_instance;\r
408     }\r
409 \r
410     public void setAaf_instance(String aaf_instance) {\r
411         this.aaf_instance = aaf_instance;\r
412     }\r
413 \r
414     //new getter setters for groups- Rally:US708115 - 1610\r
415     public int getGroupid() {\r
416         return groupid;\r
417     }\r
418 \r
419     public void setGroupid(int groupid) {\r
420         this.groupid = groupid;\r
421     }\r
422 \r
423     public String getName() {\r
424         return name;\r
425     }\r
426 \r
427     public void setName(String name) {\r
428         this.name = name;\r
429     }\r
430 \r
431     public String getVersion() {\r
432         return version;\r
433     }\r
434 \r
435     public void setVersion(String version) {\r
436         this.version = version;\r
437     }\r
438 \r
439     public String getDescription() {\r
440         return description;\r
441     }\r
442 \r
443     public void setDescription(String description) {\r
444         this.description = description;\r
445     }\r
446 \r
447     // New field is added - Groups feature Rally:US708102 - 1610\r
448     public String getBusiness_description() {\r
449         return business_description;\r
450     }\r
451 \r
452     public void setBusiness_description(String business_description) {\r
453         this.business_description = business_description;\r
454     }\r
455 \r
456     public FeedAuthorization getAuthorization() {\r
457         return authorization;\r
458     }\r
459 \r
460     public void setAuthorization(FeedAuthorization authorization) {\r
461         this.authorization = authorization;\r
462     }\r
463 \r
464     public String getPublisher() {\r
465         return publisher;\r
466     }\r
467 \r
468     public void setPublisher(String publisher) {\r
469         if (publisher != null) {\r
470             if (publisher.length() > 8)\r
471                 publisher = publisher.substring(0, 8);\r
472             this.publisher = publisher;\r
473         }\r
474     }\r
475 \r
476     public FeedLinks getLinks() {\r
477         return links;\r
478     }\r
479 \r
480     public void setLinks(FeedLinks links) {\r
481         this.links = links;\r
482     }\r
483 \r
484     public boolean isDeleted() {\r
485         return deleted;\r
486     }\r
487 \r
488     public void setDeleted(boolean deleted) {\r
489         this.deleted = deleted;\r
490     }\r
491 \r
492     public boolean isSuspended() {\r
493         return suspended;\r
494     }\r
495 \r
496     public void setSuspended(boolean suspended) {\r
497         this.suspended = suspended;\r
498     }\r
499 \r
500     @Override\r
501     public JSONObject asJSONObject() {\r
502         JSONObject jo = new JSONObject();\r
503         jo.put("feedid", feedid);\r
504         jo.put("groupid", groupid); //New field is added - Groups feature Rally:US708115 - 1610\r
505         jo.put("name", name);\r
506         jo.put("version", version);\r
507         jo.put("description", description);\r
508         jo.put("business_description", business_description); // New field is added - Groups feature Rally:US708102 - 1610\r
509         jo.put("authorization", authorization.asJSONObject());\r
510         jo.put("publisher", publisher);\r
511         jo.put("links", links.asJSONObject());\r
512         jo.put("deleted", deleted);\r
513         jo.put("suspend", suspended);\r
514         jo.put("last_mod", last_mod.getTime());\r
515         jo.put("created_date", created_date.getTime());\r
516         jo.put("aaf_instance", aaf_instance);\r
517         return jo;\r
518     }\r
519 \r
520     public JSONObject asLimitedJSONObject() {\r
521         JSONObject jo = asJSONObject();\r
522         jo.remove("deleted");\r
523         jo.remove("feedid");\r
524         jo.remove("last_mod");\r
525         jo.remove("created_date");\r
526         return jo;\r
527     }\r
528 \r
529     public JSONObject asJSONObject(boolean hidepasswords) {\r
530         JSONObject jo = asJSONObject();\r
531         if (hidepasswords) {\r
532             jo.remove("feedid");    // we no longer hide passwords, however we do hide these\r
533             jo.remove("deleted");\r
534             jo.remove("last_mod");\r
535             jo.remove("created_date");\r
536         }\r
537         return jo;\r
538     }\r
539 \r
540     @Override\r
541     public boolean doDelete(Connection c) {\r
542         boolean rv = true;\r
543         PreparedStatement ps = null;\r
544         try {\r
545             String sql = "delete from FEEDS where FEEDID = ?";\r
546             ps = c.prepareStatement(sql);\r
547             ps.setInt(1, feedid);\r
548             ps.execute();\r
549         } catch (SQLException e) {\r
550             rv = false;\r
551             intlogger.error("PROV0007 doDelete: " + e.getMessage(), e);\r
552         } finally {\r
553             try {\r
554                 if(ps!=null) {\r
555                     ps.close();\r
556                 }\r
557             } catch (SQLException e) {\r
558                 intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
559             }\r
560         }\r
561         return rv;\r
562     }\r
563 \r
564     @Override\r
565     public synchronized boolean doInsert(Connection c) {\r
566         boolean rv = true;\r
567         try {\r
568             if (feedid == -1) {\r
569                 setFeedid(next_feedid++);\r
570             }\r
571             // In case we insert a feed from synchronization\r
572             if (feedid > next_feedid)\r
573                 next_feedid = feedid + 1;\r
574 \r
575             // Create FEED_ENDPOINT_IDS rows\r
576             FeedAuthorization auth = getAuthorization();\r
577             String sql = "insert into FEED_ENDPOINT_IDS values (?, ?, ?)";\r
578             try(PreparedStatement ps2 = c.prepareStatement(sql)) {\r
579                 for (FeedEndpointID fid : auth.getEndpoint_ids()) {\r
580                     ps2.setInt(1, feedid);\r
581                     ps2.setString(2, fid.getId());\r
582                     ps2.setString(3, fid.getPassword());\r
583                     ps2.executeUpdate();\r
584                 }\r
585             }\r
586 \r
587             // Create FEED_ENDPOINT_ADDRS rows\r
588             sql = "insert into FEED_ENDPOINT_ADDRS values (?, ?)";\r
589             try(PreparedStatement ps2 = c.prepareStatement(sql)) {\r
590                 for (String t : auth.getEndpoint_addrs()) {\r
591                     ps2.setInt(1, feedid);\r
592                     ps2.setString(2, t);\r
593                     ps2.executeUpdate();\r
594                 }\r
595             }\r
596 \r
597             // Finally, create the FEEDS row\r
598             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
599             try(PreparedStatement ps2 = c.prepareStatement(sql)) {\r
600                 ps2.setInt(1, feedid);\r
601                 ps2.setString(2, getName());\r
602                 ps2.setString(3, getVersion());\r
603                 ps2.setString(4, getDescription());\r
604                 ps2.setString(5, getAuthorization().getClassification());\r
605                 ps2.setString(6, getPublisher());\r
606                 ps2.setString(7, getLinks().getSelf());\r
607                 ps2.setString(8, getLinks().getPublish());\r
608                 ps2.setString(9, getLinks().getSubscribe());\r
609                 ps2.setString(10, getLinks().getLog());\r
610                 ps2.setBoolean(11, isDeleted());\r
611                 ps2.setBoolean(12, isSuspended());\r
612                 ps2.setString(13, getBusiness_description());\r
613                 ps2.setInt(14, groupid);\r
614                 ps2.setString(15, getAafInstance());\r
615                 ps2.executeUpdate();\r
616             }\r
617         } catch (SQLException e) {\r
618             rv = false;\r
619             intlogger.error("PROV0005 doInsert: " + e.getMessage(), e);\r
620         }\r
621         return rv;\r
622     }\r
623 \r
624     @Override\r
625     public boolean doUpdate(Connection c) {\r
626         boolean rv = true;\r
627         Feed oldobj = getFeedById(feedid);\r
628         PreparedStatement ps = null;\r
629         try {\r
630             Set<FeedEndpointID> newset = getAuthorization().getEndpoint_ids();\r
631             Set<FeedEndpointID> oldset = oldobj.getAuthorization().getEndpoint_ids();\r
632 \r
633             // Insert new FEED_ENDPOINT_IDS rows\r
634             String sql = "insert into FEED_ENDPOINT_IDS values (?, ?, ?)";\r
635             ps = c.prepareStatement(sql);\r
636             for (FeedEndpointID fid : newset) {\r
637                 if (!oldset.contains(fid)) {\r
638                     ps.setInt(1, feedid);\r
639                     ps.setString(2, fid.getId());\r
640                     ps.setString(3, fid.getPassword());\r
641                     ps.executeUpdate();\r
642                 }\r
643             }\r
644             ps.close();\r
645 \r
646             // Delete old FEED_ENDPOINT_IDS rows\r
647             sql = "delete from FEED_ENDPOINT_IDS where FEEDID = ? AND USERID = ? AND PASSWORD = ?";\r
648             ps = c.prepareStatement(sql);\r
649             for (FeedEndpointID fid : oldset) {\r
650                 if (!newset.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
655                 }\r
656             }\r
657             ps.close();\r
658 \r
659             // Insert new FEED_ENDPOINT_ADDRS rows\r
660             Set<String> newset2 = getAuthorization().getEndpoint_addrs();\r
661             Set<String> oldset2 = oldobj.getAuthorization().getEndpoint_addrs();\r
662             sql = "insert into FEED_ENDPOINT_ADDRS values (?, ?)";\r
663             ps = c.prepareStatement(sql);\r
664             for (String t : newset2) {\r
665                 if (!oldset2.contains(t)) {\r
666                     ps.setInt(1, feedid);\r
667                     ps.setString(2, t);\r
668                     ps.executeUpdate();\r
669                 }\r
670             }\r
671             ps.close();\r
672 \r
673             // Delete old FEED_ENDPOINT_ADDRS rows\r
674             sql = "delete from FEED_ENDPOINT_ADDRS where FEEDID = ? AND ADDR = ?";\r
675             ps = c.prepareStatement(sql);\r
676             for (String t : oldset2) {\r
677                 if (!newset2.contains(t)) {\r
678                     ps.setInt(1, feedid);\r
679                     ps.setString(2, t);\r
680                     ps.executeUpdate();\r
681                 }\r
682             }\r
683             ps.close();\r
684 \r
685             // Finally, update the FEEDS row\r
686             sql = "update FEEDS set DESCRIPTION = ?, AUTH_CLASS = ?, DELETED = ?, SUSPENDED = ?, BUSINESS_DESCRIPTION=?, GROUPID=? where FEEDID = ?";\r
687             ps = c.prepareStatement(sql);\r
688             ps.setString(1, getDescription());\r
689             ps.setString(2, getAuthorization().getClassification());\r
690             ps.setInt(3, deleted ? 1 : 0);\r
691             ps.setInt(4, suspended ? 1 : 0);\r
692             ps.setString(5, getBusiness_description());\r
693             ps.setInt(6, groupid);\r
694             ps.setInt(7, feedid);\r
695             ps.executeUpdate();\r
696             ps.close();\r
697         } catch (SQLException e) {\r
698             rv = false;\r
699             intlogger.warn("PROV0006 doUpdate: " + e.getMessage(), e);\r
700         } finally {\r
701             try {\r
702                 if (ps != null)\r
703                     ps.close();\r
704             } catch (SQLException e) {\r
705                 intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
706             }\r
707         }\r
708         return rv;\r
709     }\r
710 \r
711     /**\r
712      * Rally US708115\r
713      * Change Ownership of FEED - 1610\r
714      */\r
715     public boolean changeOwnerShip() {\r
716         boolean rv = true;\r
717         PreparedStatement ps = null;\r
718         try {\r
719 \r
720             DB db = new DB();\r
721             @SuppressWarnings("resource")\r
722             Connection c = db.getConnection();\r
723             String sql = "update FEEDS set PUBLISHER = ? where FEEDID = ?";\r
724             ps = c.prepareStatement(sql);\r
725             ps.setString(1, this.publisher);\r
726             ps.setInt(2, feedid);\r
727             ps.execute();\r
728             ps.close();\r
729         } catch (SQLException e) {\r
730             rv = false;\r
731             intlogger.warn("PROV0008 changeOwnerShip: " + e.getMessage(), e);\r
732         } finally {\r
733             try {\r
734                 if(ps!=null) {\r
735                     ps.close();\r
736                 }\r
737             } catch (SQLException e) {\r
738                 intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
739             }\r
740         }\r
741         return rv;\r
742     }\r
743 \r
744 \r
745     @Override\r
746     public String getKey() {\r
747         return "" + getFeedid();\r
748     }\r
749 \r
750     @Override\r
751     public boolean equals(Object obj) {\r
752         if (!(obj instanceof Feed))\r
753             return false;\r
754         Feed of = (Feed) obj;\r
755         if (feedid != of.feedid)\r
756             return false;\r
757         if (groupid != of.groupid) //New field is added - Groups feature Rally:US708115 - 1610\r
758             return false;\r
759         if (!name.equals(of.name))\r
760             return false;\r
761         if (!version.equals(of.version))\r
762             return false;\r
763         if (!description.equals(of.description))\r
764             return false;\r
765         if (!business_description.equals(of.business_description)) // New field is added - Groups feature Rally:US708102 - 1610\r
766             return false;\r
767         if (!publisher.equals(of.publisher))\r
768             return false;\r
769         if (!authorization.equals(of.authorization))\r
770             return false;\r
771         if (!links.equals(of.links))\r
772             return false;\r
773         if (deleted != of.deleted)\r
774             return false;\r
775         if (suspended != of.suspended)\r
776             return false;\r
777         if (!aaf_instance.equals(of.aaf_instance))\r
778             return false;\r
779         return true;\r
780     }\r
781 \r
782     @Override\r
783     public String toString() {\r
784         return "FEED: feedid=" + feedid + ", name=" + name + ", version=" + version;\r
785     }\r
786 \r
787     @Override\r
788     public int hashCode() {\r
789         return super.hashCode();\r
790     }\r
791 }