update link to upper-constraints.txt
[dmaap/datarouter.git] / datarouter-prov / src / main / java / org / onap / dmaap / datarouter / provisioning / beans / Subscription.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 package org.onap.dmaap.datarouter.provisioning.beans;\r
25 \r
26 import com.att.eelf.configuration.EELFLogger;\r
27 import com.att.eelf.configuration.EELFManager;\r
28 import java.io.InvalidObjectException;\r
29 import java.sql.Connection;\r
30 import java.sql.PreparedStatement;\r
31 import java.sql.ResultSet;\r
32 import java.sql.SQLException;\r
33 import java.util.ArrayList;\r
34 import java.util.Collection;\r
35 import java.util.Date;\r
36 import java.util.List;\r
37 import java.util.Properties;\r
38 import org.json.JSONObject;\r
39 import org.onap.dmaap.datarouter.provisioning.ProvRunner;\r
40 import org.onap.dmaap.datarouter.provisioning.utils.ProvDbUtils;\r
41 import org.onap.dmaap.datarouter.provisioning.utils.URLUtilities;\r
42 \r
43 \r
44 /**\r
45  * The representation of a Subscription.  Subscriptions can be retrieved from the DB, or stored/updated in the DB.\r
46  *\r
47  * @author Robert Eby\r
48  * @version $Id: Subscription.java,v 1.9 2013/10/28 18:06:53 eby Exp $\r
49  */\r
50 \r
51 public class Subscription extends Syncable {\r
52 \r
53     private static final String SQLEXCEPTION = "SQLException: ";\r
54     private static final String SUBID_KEY = "subid";\r
55     private static final String SUBID_COL = "SUBID";\r
56     private static final String FEEDID_KEY = "feedid";\r
57     private static final String GROUPID_KEY = "groupid";\r
58     private static final String LAST_MOD_KEY = "last_mod";\r
59     private static final String CREATED_DATE = "created_date";\r
60     private static EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");\r
61     private static int nextSubid = getMaxSubID() + 1;\r
62 \r
63     private int subid;\r
64     private int feedid;\r
65     private int groupid; //New field is added - Groups feature Rally:US708115 - 1610\r
66     private SubDelivery delivery;\r
67     private boolean followRedirect;\r
68     private boolean metadataOnly;\r
69     private String subscriber;\r
70     private SubLinks links;\r
71     private boolean suspended;\r
72     private Date lastMod;\r
73     private Date createdDate;\r
74     private boolean privilegedSubscriber;\r
75     private boolean decompress;\r
76 \r
77     public Subscription() {\r
78         this("", "", "");\r
79     }\r
80 \r
81     /**\r
82      * Subscription constructor.\r
83      * @param url url string\r
84      * @param user user string\r
85      * @param password password string\r
86      */\r
87     public Subscription(String url, String user, String password) {\r
88         this.subid = -1;\r
89         this.feedid = -1;\r
90         this.groupid = -1; //New field is added - Groups feature Rally:US708115 - 1610\r
91         this.delivery = new SubDelivery(url, user, password, false);\r
92         this.metadataOnly = false;\r
93         this.followRedirect = false;\r
94         this.subscriber = "";\r
95         this.links = new SubLinks();\r
96         this.suspended = false;\r
97         this.lastMod = new Date();\r
98         this.createdDate = new Date();\r
99         this.privilegedSubscriber = false;\r
100         this.decompress = false;\r
101     }\r
102 \r
103     /**\r
104      * Subscription constructor.\r
105      * @param rs resultset from SQL\r
106      * @throws SQLException in case of SQL error\r
107      */\r
108     public Subscription(ResultSet rs) throws SQLException {\r
109         this.subid = rs.getInt(SUBID_COL);\r
110         this.feedid = rs.getInt("FEEDID");\r
111         this.groupid = rs.getInt("GROUPID"); //New field is added - Groups feature Rally:US708115 - 1610\r
112         this.delivery = new SubDelivery(rs);\r
113         this.metadataOnly = rs.getBoolean("METADATA_ONLY");\r
114         this.followRedirect = rs.getBoolean("FOLLOW_REDIRECTS");\r
115         this.subscriber = rs.getString("SUBSCRIBER");\r
116         this.links = new SubLinks(rs.getString("SELF_LINK"), URLUtilities.generateFeedURL(feedid),\r
117             rs.getString("LOG_LINK"));\r
118         this.suspended = rs.getBoolean("SUSPENDED");\r
119         this.lastMod = rs.getDate("LAST_MOD");\r
120         this.createdDate = rs.getDate("CREATED_DATE");\r
121         this.privilegedSubscriber = rs.getBoolean("PRIVILEGED_SUBSCRIBER");\r
122         this.decompress  = rs.getBoolean("DECOMPRESS");\r
123     }\r
124 \r
125     /**\r
126      * Subscription constructor.\r
127      * @param jo JSONObject\r
128      * @throws InvalidObjectException in case of object error\r
129      */\r
130     public Subscription(JSONObject jo) throws InvalidObjectException {\r
131         this("", "", "");\r
132         try {\r
133             // The JSONObject is assumed to contain a vnd.dmaap-dr.subscription representation\r
134             this.subid = jo.optInt(SUBID_KEY, -1);\r
135             this.feedid = jo.optInt(FEEDID_KEY, -1);\r
136             this.groupid = jo.optInt(GROUPID_KEY, -1); //New field is added - Groups feature Rally:US708115 - 1610\r
137             JSONObject jdeli = jo.getJSONObject("delivery");\r
138             String url = jdeli.getString("url");\r
139             String user = jdeli.getString("user");\r
140             final String password = jdeli.getString("password");\r
141             final boolean use100 = jdeli.getBoolean("use100");\r
142 \r
143             //Data Router Subscriber HTTPS Relaxation feature USERSTORYID:US674047.\r
144             Properties prop = ProvRunner.getProvProperties();\r
145             if (!url.startsWith("https://") && isHttpsRelaxationFalseAndHasSyncKey(jo, prop)) {\r
146                 throw new InvalidObjectException("delivery URL is not HTTPS");\r
147             }\r
148 \r
149             if (url.length() > 256) {\r
150                 throw new InvalidObjectException("delivery url field is too long");\r
151             }\r
152             if (user.length() > 60) {\r
153                 throw new InvalidObjectException("delivery user field is too long");\r
154             }\r
155             if (password.length() > 32) {\r
156                 throw new InvalidObjectException("delivery password field is too long");\r
157             }\r
158             this.delivery = new SubDelivery(url, user, password, use100);\r
159             this.metadataOnly = jo.getBoolean("metadataOnly");\r
160             this.followRedirect = jo.optBoolean("follow_redirect", false);\r
161             this.suspended = jo.optBoolean("suspend", false);\r
162             this.privilegedSubscriber = jo.optBoolean("privilegedSubscriber", false);\r
163             this.decompress = jo.optBoolean("decompress", false);\r
164             this.subscriber = jo.optString("subscriber", "");\r
165             JSONObject jol = jo.optJSONObject("links");\r
166             this.links = (jol == null) ? (new SubLinks()) : (new SubLinks(jol));\r
167         } catch (InvalidObjectException e) {\r
168             throw e;\r
169         } catch (Exception e) {\r
170             intlogger.warn("Invalid JSON: " + e.getMessage(), e);\r
171             throw new InvalidObjectException("Invalid JSON: " + e.getMessage());\r
172         }\r
173     }\r
174 \r
175     /**\r
176      * Get specific subscription.\r
177      * @param sub subscription object\r
178      * @return subscription\r
179      */\r
180     public static Subscription getSubscriptionMatching(Subscription sub) {\r
181         SubDelivery deli = sub.getDelivery();\r
182         String sql = String.format(\r
183             "select * from SUBSCRIPTIONS where FEEDID = %d and DELIVERY_URL = \"%s\" and DELIVERY_USER = \"%s\" "\r
184                 + "and DELIVERY_PASSWORD = \"%s\" and DELIVERY_USE100 = %d and METADATA_ONLY = %d "\r
185                 + "and FOLLOW_REDIRECTS = %d",\r
186             sub.getFeedid(),\r
187             deli.getUrl(),\r
188             deli.getUser(),\r
189             deli.getPassword(),\r
190             deli.isUse100() ? 1 : 0,\r
191             sub.isMetadataOnly() ? 1 : 0,\r
192             sub.isFollowRedirect() ? 1 : 0\r
193         );\r
194         List<Subscription> list = getSubscriptionsForSQL(sql);\r
195         return !list.isEmpty() ? list.get(0) : null;\r
196     }\r
197 \r
198     /**\r
199      * Get subscription by id.\r
200      * @param id subscription id string\r
201      * @return subscription\r
202      */\r
203     public static Subscription getSubscriptionById(int id) {\r
204         String sql = "select * from SUBSCRIPTIONS where SUBID = " + id;\r
205         List<Subscription> list = getSubscriptionsForSQL(sql);\r
206         return !list.isEmpty() ? list.get(0) : null;\r
207     }\r
208 \r
209     public static Collection<Subscription> getAllSubscriptions() {\r
210         return getSubscriptionsForSQL("select * from SUBSCRIPTIONS");\r
211     }\r
212 \r
213     /**\r
214      * Get subscriptions from SQL.\r
215      * @param sql SQL statement\r
216      * @return List of subscriptions\r
217      */\r
218     private static List<Subscription> getSubscriptionsForSQL(String sql) {\r
219         List<Subscription> list = new ArrayList<>();\r
220         try (Connection conn = ProvDbUtils.getInstance().getConnection();\r
221             PreparedStatement ps = conn.prepareStatement(sql);\r
222             ResultSet rs = ps.executeQuery()) {\r
223             while (rs.next()) {\r
224                 Subscription sub = new Subscription(rs);\r
225                 list.add(sub);\r
226             }\r
227         } catch (SQLException e) {\r
228             intlogger.error("PROV0001 getSubscriptionsForSQL: " + e.toString(), e);\r
229         }\r
230         return list;\r
231     }\r
232 \r
233     /**\r
234      * Get max subid.\r
235      * @return subid int\r
236      */\r
237     public static int getMaxSubID() {\r
238         int max = 0;\r
239         try (Connection conn = ProvDbUtils.getInstance().getConnection();\r
240             PreparedStatement ps = conn.prepareStatement("select MAX(subid) from SUBSCRIPTIONS");\r
241             ResultSet rs = ps.executeQuery()) {\r
242             if (rs.next()) {\r
243                 max = rs.getInt(1);\r
244             }\r
245         } catch (SQLException e) {\r
246             intlogger.info("getMaxSubID: " + e.getMessage(), e);\r
247         }\r
248         return max;\r
249     }\r
250 \r
251     /**\r
252      * Get subscription URL list.\r
253      * @param feedid feedid int\r
254      * @return collection of subscription URL\r
255      */\r
256     public static Collection<String> getSubscriptionUrlList(int feedid) {\r
257         List<String> list = new ArrayList<>();\r
258         try (Connection conn = ProvDbUtils.getInstance().getConnection();\r
259             PreparedStatement stmt = conn.prepareStatement("select SUBID from SUBSCRIPTIONS where FEEDID = ?")) {\r
260             stmt.setString(1, String.valueOf(feedid));\r
261             try (ResultSet rs = stmt.executeQuery()) {\r
262                 while (rs.next()) {\r
263                     int subid = rs.getInt(SUBID_COL);\r
264                     list.add(URLUtilities.generateSubscriptionURL(subid));\r
265                 }\r
266             }\r
267         } catch (SQLException e) {\r
268             intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
269         }\r
270         return list;\r
271     }\r
272 \r
273     /**\r
274      * Return a count of the number of active subscriptions in the DB.\r
275      *\r
276      * @return the count\r
277      */\r
278     public static int countActiveSubscriptions() {\r
279         int count = 0;\r
280         try (Connection conn = ProvDbUtils.getInstance().getConnection();\r
281             PreparedStatement ps = conn.prepareStatement("select count(*) from SUBSCRIPTIONS");\r
282             ResultSet rs = ps.executeQuery()) {\r
283             if (rs.next()) {\r
284                 count = rs.getInt(1);\r
285             }\r
286         } catch (SQLException e) {\r
287             intlogger.warn("PROV0008 countActiveSubscriptions: " + e.getMessage(), e);\r
288         }\r
289         return count;\r
290     }\r
291 \r
292     private boolean isHttpsRelaxationFalseAndHasSyncKey(JSONObject jo, Properties prop) {\r
293         return prop.get("org.onap.dmaap.datarouter.provserver.https.relaxation").toString().equals("false") && !jo\r
294             .has("sync");\r
295     }\r
296 \r
297     public int getSubid() {\r
298         return subid;\r
299     }\r
300 \r
301     /**\r
302      * Subid setter.\r
303      * @param subid subid string\r
304      */\r
305     public void setSubid(int subid) {\r
306         this.subid = subid;\r
307 \r
308         // Create link URLs\r
309         SubLinks sl = getLinks();\r
310         sl.setSelf(URLUtilities.generateSubscriptionURL(subid));\r
311         sl.setLog(URLUtilities.generateSubLogURL(subid));\r
312     }\r
313 \r
314     public int getFeedid() {\r
315         return feedid;\r
316     }\r
317 \r
318     /**\r
319      * feedid setter.\r
320      * @param feedid feedid string\r
321      */\r
322     public void setFeedid(int feedid) {\r
323         this.feedid = feedid;\r
324 \r
325         // Create link URLs\r
326         SubLinks sl = getLinks();\r
327         sl.setFeed(URLUtilities.generateFeedURL(feedid));\r
328     }\r
329 \r
330     //New getter setters for Groups feature Rally:US708115 - 1610\r
331     public int getGroupid() {\r
332         return groupid;\r
333     }\r
334 \r
335     public void setGroupid(int groupid) {\r
336         this.groupid = groupid;\r
337     }\r
338 \r
339     public SubDelivery getDelivery() {\r
340         return delivery;\r
341     }\r
342 \r
343     public void setDelivery(SubDelivery delivery) {\r
344         this.delivery = delivery;\r
345     }\r
346 \r
347     public boolean isMetadataOnly() {\r
348         return metadataOnly;\r
349     }\r
350 \r
351     public void setMetadataOnly(boolean metadataOnly) {\r
352         this.metadataOnly = metadataOnly;\r
353     }\r
354 \r
355     private boolean isFollowRedirect() {\r
356         return followRedirect;\r
357     }\r
358 \r
359     public void setFollowRedirect(boolean followRedirect) {\r
360         this.followRedirect = followRedirect;\r
361     }\r
362 \r
363     boolean isSuspended() {\r
364         return suspended;\r
365     }\r
366 \r
367     public void setSuspended(boolean suspended) {\r
368         this.suspended = suspended;\r
369     }\r
370 \r
371     public boolean isPrivilegedSubscriber() {\r
372         return privilegedSubscriber;\r
373     }\r
374 \r
375     public void setPrivilegedSubscriber(boolean privilegedSubscriber) {\r
376         this.privilegedSubscriber = privilegedSubscriber;\r
377     }\r
378 \r
379     public String getSubscriber() {\r
380         return subscriber;\r
381     }\r
382 \r
383     /**\r
384      * Subscriber setter.\r
385      * @param subscriber subscriber string\r
386      */\r
387     public void setSubscriber(String subscriber) {\r
388         if (subscriber != null) {\r
389             if (subscriber.length() > 8) {\r
390                 subscriber = subscriber.substring(0, 8);\r
391             }\r
392             this.subscriber = subscriber;\r
393         }\r
394     }\r
395 \r
396     public SubLinks getLinks() {\r
397         return links;\r
398     }\r
399 \r
400     void setLinks(SubLinks links) {\r
401         this.links = links;\r
402     }\r
403 \r
404     public boolean isDecompress() {\r
405         return decompress;\r
406     }\r
407 \r
408     public void setDecompress(boolean decompress) {\r
409         this.decompress = decompress;\r
410     }\r
411 \r
412     @Override\r
413     public JSONObject asJSONObject() {\r
414         JSONObject jo = new JSONObject();\r
415         jo.put(SUBID_KEY, subid);\r
416         jo.put(FEEDID_KEY, feedid);\r
417         jo.put(GROUPID_KEY, groupid); //New field is added - Groups feature Rally:US708115 - 1610\r
418         jo.put("delivery", delivery.asJSONObject());\r
419         jo.put("metadataOnly", metadataOnly);\r
420         jo.put("follow_redirect", followRedirect);\r
421         jo.put("subscriber", subscriber);\r
422         jo.put("links", links.asJSONObject());\r
423         jo.put("suspend", suspended);\r
424         jo.put(LAST_MOD_KEY, lastMod.getTime());\r
425         jo.put(CREATED_DATE, createdDate.getTime());\r
426         jo.put("privilegedSubscriber", privilegedSubscriber);\r
427         jo.put("decompress", decompress);\r
428         return jo;\r
429     }\r
430 \r
431     /**\r
432      * Method to hide attributes.\r
433      * @param hidepasswords true/false\r
434      * @return JSONObject\r
435      */\r
436     public JSONObject asJSONObject(boolean hidepasswords) {\r
437         JSONObject jo = asJSONObject();\r
438         if (hidepasswords) {\r
439             jo.remove(SUBID_KEY);    // we no longer hide passwords, however we do hide these\r
440             jo.remove(FEEDID_KEY);\r
441             jo.remove(LAST_MOD_KEY);\r
442             jo.remove(CREATED_DATE);\r
443         }\r
444         return jo;\r
445     }\r
446 \r
447     /**\r
448      * Method to remove some attributes from JSON.\r
449      * @ JSONObject\r
450      */\r
451     public JSONObject asLimitedJSONObject() {\r
452         JSONObject jo = asJSONObject();\r
453         jo.remove(SUBID_KEY);\r
454         jo.remove(FEEDID_KEY);\r
455         jo.remove(LAST_MOD_KEY);\r
456         return jo;\r
457     }\r
458 \r
459 \r
460     @Override\r
461     public boolean doInsert(Connection conn) {\r
462         boolean rv = true;\r
463         PreparedStatement ps = null;\r
464         try {\r
465             if (subid == -1) {\r
466                 // No feed ID assigned yet, so assign the next available one\r
467                 setSubid(nextSubid++);\r
468             }\r
469             // In case we insert a feed from synchronization\r
470             if (subid > nextSubid) {\r
471                 nextSubid = subid + 1;\r
472             }\r
473 \r
474             // Create the SUBSCRIPTIONS row\r
475             String sql = "insert into SUBSCRIPTIONS (SUBID, FEEDID, DELIVERY_URL, DELIVERY_USER, DELIVERY_PASSWORD, "\r
476                 + "DELIVERY_USE100, METADATA_ONLY, SUBSCRIBER, SUSPENDED, GROUPID, "\r
477                 + "PRIVILEGED_SUBSCRIBER, FOLLOW_REDIRECTS, DECOMPRESS) "\r
478                 + "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";\r
479             ps = conn.prepareStatement(sql, new String[]{SUBID_COL});\r
480             ps.setInt(1, subid);\r
481             ps.setInt(2, feedid);\r
482             ps.setString(3, getDelivery().getUrl());\r
483             ps.setString(4, getDelivery().getUser());\r
484             ps.setString(5, getDelivery().getPassword());\r
485             ps.setInt(6, getDelivery().isUse100() ? 1 : 0);\r
486             ps.setInt(7, isMetadataOnly() ? 1 : 0);\r
487             ps.setString(8, getSubscriber());\r
488             ps.setBoolean(9, isSuspended());\r
489             ps.setInt(10, groupid); //New field is added - Groups feature Rally:US708115 - 1610\r
490             ps.setBoolean(11, isPrivilegedSubscriber());\r
491             ps.setInt(12, isFollowRedirect() ? 1 : 0);\r
492             ps.setBoolean(13, isDecompress());\r
493             ps.execute();\r
494             ps.close();\r
495             // Update the row to set the URLs\r
496             sql = "update SUBSCRIPTIONS set SELF_LINK = ?, LOG_LINK = ? where SUBID = ?";\r
497             ps = conn.prepareStatement(sql);\r
498             ps.setString(1, getLinks().getSelf());\r
499             ps.setString(2, getLinks().getLog());\r
500             ps.setInt(3, subid);\r
501             ps.execute();\r
502             ps.close();\r
503         } catch (SQLException e) {\r
504             rv = false;\r
505             intlogger.warn("PROV0005 doInsert: " + e.getMessage(), e);\r
506         } finally {\r
507             try {\r
508                 if (ps != null) {\r
509                     ps.close();\r
510                 }\r
511             } catch (SQLException e) {\r
512                 intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
513             }\r
514         }\r
515         return rv;\r
516     }\r
517 \r
518     @Override\r
519     public boolean doUpdate(Connection conn) {\r
520         boolean rv = true;\r
521         try (PreparedStatement ps = conn.prepareStatement(\r
522             "update SUBSCRIPTIONS set DELIVERY_URL = ?, DELIVERY_USER = ?, DELIVERY_PASSWORD = ?, "\r
523             + "DELIVERY_USE100 = ?, METADATA_ONLY = ?, SUSPENDED = ?, GROUPID = ?, PRIVILEGED_SUBSCRIBER = ?, "\r
524             + "FOLLOW_REDIRECTS = ?, DECOMPRESS = ? where SUBID = ?")) {\r
525             ps.setString(1, delivery.getUrl());\r
526             ps.setString(2, delivery.getUser());\r
527             ps.setString(3, delivery.getPassword());\r
528             ps.setInt(4, delivery.isUse100() ? 1 : 0);\r
529             ps.setInt(5, isMetadataOnly() ? 1 : 0);\r
530             ps.setInt(6, suspended ? 1 : 0);\r
531             ps.setInt(7, groupid); //New field is added - Groups feature Rally:US708115 - 1610\r
532             ps.setInt(8, privilegedSubscriber ? 1 : 0);\r
533             ps.setInt(9, isFollowRedirect() ? 1 : 0);\r
534             ps.setInt(10, isDecompress() ? 1 : 0);\r
535             ps.setInt(11, subid);\r
536             ps.executeUpdate();\r
537         } catch (SQLException e) {\r
538             rv = false;\r
539             intlogger.warn("PROV0006 doUpdate: " + e.getMessage(), e);\r
540         }\r
541         return rv;\r
542     }\r
543 \r
544 \r
545     /**\r
546      * Rally US708115 Change Ownership of Subscription - 1610.\r
547      */\r
548     public boolean changeOwnerShip() {\r
549         boolean rv = true;\r
550         try (Connection conn = ProvDbUtils.getInstance().getConnection();\r
551             PreparedStatement ps = conn.prepareStatement(\r
552                 "update SUBSCRIPTIONS set SUBSCRIBER = ? where SUBID = ?")) {\r
553             ps.setString(1, this.subscriber);\r
554             ps.setInt(2, subid);\r
555             ps.execute();\r
556         } catch (SQLException e) {\r
557             rv = false;\r
558             intlogger.warn("PROV0006 doUpdate: " + e.getMessage(), e);\r
559         }\r
560         return rv;\r
561     }\r
562 \r
563 \r
564     @Override\r
565     public boolean doDelete(Connection conn) {\r
566         boolean rv = true;\r
567         try (PreparedStatement ps = conn.prepareStatement("delete from SUBSCRIPTIONS where SUBID = ?")) {\r
568             ps.setInt(1, subid);\r
569             ps.execute();\r
570         } catch (SQLException e) {\r
571             rv = false;\r
572             intlogger.warn("PROV0007 doDelete: " + e.getMessage(), e);\r
573         }\r
574         return rv;\r
575     }\r
576 \r
577     @Override\r
578     public String getKey() {\r
579         return "" + getSubid();\r
580     }\r
581 \r
582     @Override\r
583     public boolean equals(Object obj) {\r
584         if (!(obj instanceof Subscription)) {\r
585             return false;\r
586         }\r
587         Subscription os = (Subscription) obj;\r
588         if (subid != os.subid) {\r
589             return false;\r
590         }\r
591         if (feedid != os.feedid) {\r
592             return false;\r
593         }\r
594         if (groupid != os.groupid) {\r
595             //New field is added - Groups feature Rally:US708115 - 1610\r
596             return false;\r
597         }\r
598         if (!delivery.equals(os.delivery)) {\r
599             return false;\r
600         }\r
601         if (metadataOnly != os.metadataOnly) {\r
602             return false;\r
603         }\r
604         if (followRedirect != os.followRedirect) {\r
605             return false;\r
606         }\r
607         if (!subscriber.equals(os.subscriber)) {\r
608             return false;\r
609         }\r
610         if (!links.equals(os.links)) {\r
611             return false;\r
612         }\r
613         if (suspended != os.suspended) {\r
614             return false;\r
615         }\r
616         return true;\r
617     }\r
618 \r
619     @Override\r
620     public int hashCode() {\r
621         return super.hashCode();\r
622     }\r
623 \r
624     @Override\r
625     public String toString() {\r
626         return "SUB: subid=" + subid + ", feedid=" + feedid;\r
627     }\r
628 }\r