Code style cleanup for prov authz and beans
[dmaap/datarouter.git] / datarouter-prov / src / main / java / org / onap / dmaap / datarouter / provisioning / beans / Subscription.java
index c12d83d..95f0a70 100644 (file)
@@ -23,6 +23,8 @@
 \r
 package org.onap.dmaap.datarouter.provisioning.beans;\r
 \r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\r
 import java.io.InvalidObjectException;\r
 import java.sql.Connection;\r
 import java.sql.PreparedStatement;\r
@@ -34,9 +36,6 @@ import java.util.Collection;
 import java.util.Date;\r
 import java.util.List;\r
 import java.util.Properties;\r
-\r
-import com.att.eelf.configuration.EELFLogger;\r
-import com.att.eelf.configuration.EELFManager;\r
 import org.json.JSONObject;\r
 import org.onap.dmaap.datarouter.provisioning.utils.DB;\r
 import org.onap.dmaap.datarouter.provisioning.utils.URLUtilities;\r
@@ -48,6 +47,7 @@ import org.onap.dmaap.datarouter.provisioning.utils.URLUtilities;
  * @author Robert Eby\r
  * @version $Id: Subscription.java,v 1.9 2013/10/28 18:06:53 eby Exp $\r
  */\r
+\r
 public class Subscription extends Syncable {\r
 \r
     private static final String SQLEXCEPTION = "SQLException: ";\r
@@ -75,22 +75,34 @@ public class Subscription extends Syncable {
     private String aafInstance;\r
     private boolean decompress;\r
 \r
+    /**\r
+     * Get specific subscription.\r
+     * @param sub subscription object\r
+     * @return subscription\r
+     */\r
     public static Subscription getSubscriptionMatching(Subscription sub) {\r
         SubDelivery deli = sub.getDelivery();\r
         String sql = String.format(\r
-                "select * from SUBSCRIPTIONS where FEEDID = %d and DELIVERY_URL = \"%s\" and DELIVERY_USER = \"%s\" and DELIVERY_PASSWORD = \"%s\" and DELIVERY_USE100 = %d and METADATA_ONLY = %d and FOLLOW_REDIRECTS = %d",\r
+                "select * from SUBSCRIPTIONS where FEEDID = %d and DELIVERY_URL = \"%s\" and DELIVERY_USER = \"%s\" "\r
+                        + "and DELIVERY_PASSWORD = \"%s\" and DELIVERY_USE100 = %d and METADATA_ONLY = %d "\r
+                        + "and FOLLOW_REDIRECTS = %d",\r
                 sub.getFeedid(),\r
                 deli.getUrl(),\r
                 deli.getUser(),\r
                 deli.getPassword(),\r
                 deli.isUse100() ? 1 : 0,\r
                 sub.isMetadataOnly() ? 1 : 0,\r
-                sub.isFollowRedirect() ? 1 :0\r
+                sub.isFollowRedirect() ? 1 : 0\r
         );\r
         List<Subscription> list = getSubscriptionsForSQL(sql);\r
         return !list.isEmpty() ? list.get(0) : null;\r
     }\r
 \r
+    /**\r
+     * Get subscription by id.\r
+     * @param id subscription id string\r
+     * @return subscription\r
+     */\r
     public static Subscription getSubscriptionById(int id) {\r
         String sql = "select * from SUBSCRIPTIONS where SUBID = " + id;\r
         List<Subscription> list = getSubscriptionsForSQL(sql);\r
@@ -101,6 +113,11 @@ public class Subscription extends Syncable {
         return getSubscriptionsForSQL("select * from SUBSCRIPTIONS");\r
     }\r
 \r
+    /**\r
+     * Get subscriptions from SQL.\r
+     * @param sql SQL statement\r
+     * @return List of subscriptions\r
+     */\r
     private static List<Subscription> getSubscriptionsForSQL(String sql) {\r
         List<Subscription> list = new ArrayList<>();\r
         try {\r
@@ -122,6 +139,10 @@ public class Subscription extends Syncable {
         return list;\r
     }\r
 \r
+    /**\r
+     * Get max subid.\r
+     * @return subid int\r
+     */\r
     public static int getMaxSubID() {\r
         int max = 0;\r
         try {\r
@@ -142,6 +163,11 @@ public class Subscription extends Syncable {
         return max;\r
     }\r
 \r
+    /**\r
+     * Get subscription URL list.\r
+     * @param feedid feedid int\r
+     * @return collection of subscription URL\r
+     */\r
     public static Collection<String> getSubscriptionUrlList(int feedid) {\r
         List<String> list = new ArrayList<>();\r
         String sql = "select SUBID from SUBSCRIPTIONS where FEEDID = ?";\r
@@ -195,6 +221,12 @@ public class Subscription extends Syncable {
         this("", "", "");\r
     }\r
 \r
+    /**\r
+     * Subscription constructor.\r
+     * @param url url string\r
+     * @param user user string\r
+     * @param password password string\r
+     */\r
     public Subscription(String url, String user, String password) {\r
         this.subid = -1;\r
         this.feedid = -1;\r
@@ -212,6 +244,11 @@ public class Subscription extends Syncable {
         this.decompress = false;\r
     }\r
 \r
+    /**\r
+     * Subscription constructor.\r
+     * @param rs resultset from SQL\r
+     * @throws SQLException in case of SQL error\r
+     */\r
     public Subscription(ResultSet rs) throws SQLException {\r
         this.subid = rs.getInt(SUBID_COL);\r
         this.feedid = rs.getInt("FEEDID");\r
@@ -220,7 +257,8 @@ public class Subscription extends Syncable {
         this.metadataOnly = rs.getBoolean("METADATA_ONLY");\r
         this.followRedirect = rs.getBoolean("FOLLOW_REDIRECTS");\r
         this.subscriber = rs.getString("SUBSCRIBER");\r
-        this.links = new SubLinks(rs.getString("SELF_LINK"), URLUtilities.generateFeedURL(feedid), rs.getString("LOG_LINK"));\r
+        this.links = new SubLinks(rs.getString("SELF_LINK"), URLUtilities.generateFeedURL(feedid),\r
+                rs.getString("LOG_LINK"));\r
         this.suspended = rs.getBoolean("SUSPENDED");\r
         this.lastMod = rs.getDate("LAST_MOD");\r
         this.createdDate = rs.getDate("CREATED_DATE");\r
@@ -229,6 +267,11 @@ public class Subscription extends Syncable {
         this.decompress  = rs.getBoolean("DECOMPRESS");\r
     }\r
 \r
+    /**\r
+     * Subscription constructor.\r
+     * @param jo JSONObject\r
+     * @throws InvalidObjectException in case of object error\r
+     */\r
     public Subscription(JSONObject jo) throws InvalidObjectException {\r
         this("", "", "");\r
         try {\r
@@ -237,19 +280,18 @@ public class Subscription extends Syncable {
             this.feedid = jo.optInt(FEEDID_KEY, -1);\r
             this.groupid = jo.optInt(GROUPID_KEY, -1); //New field is added - Groups feature Rally:US708115 - 1610\r
             this.aafInstance = jo.optString("aaf_instance", "legacy");\r
-            if(!(aafInstance.equalsIgnoreCase("legacy"))){\r
-                if (aafInstance.length() > 255)\r
-                    throw new InvalidObjectException("aaf_instance field is too long");\r
+            if (!(aafInstance.equalsIgnoreCase("legacy")) && aafInstance.length() > 255) {\r
+                throw new InvalidObjectException("aaf_instance field is too long");\r
             }\r
             JSONObject jdeli = jo.getJSONObject("delivery");\r
             String url = jdeli.getString("url");\r
             String user = jdeli.getString("user");\r
-            String password = jdeli.getString("password");\r
-            boolean use100 = jdeli.getBoolean("use100");\r
+            final String password = jdeli.getString("password");\r
+            final boolean use100 = jdeli.getBoolean("use100");\r
 \r
             //Data Router Subscriber HTTPS Relaxation feature USERSTORYID:US674047.\r
-            Properties p = (new DB()).getProperties();\r
-            if (!url.startsWith("https://") && isHttpsRelaxationFalseAndHasSyncKey(jo, p)) {\r
+            Properties prop = (new DB()).getProperties();\r
+            if (!url.startsWith("https://") && isHttpsRelaxationFalseAndHasSyncKey(jo, prop)) {\r
                 throw new InvalidObjectException("delivery URL is not HTTPS");\r
             }\r
 \r
@@ -279,8 +321,8 @@ public class Subscription extends Syncable {
         }\r
     }\r
 \r
-    private boolean isHttpsRelaxationFalseAndHasSyncKey(JSONObject jo, Properties p) {\r
-        return p.get("org.onap.dmaap.datarouter.provserver.https.relaxation").toString().equals("false") && !jo\r
+    private boolean isHttpsRelaxationFalseAndHasSyncKey(JSONObject jo, Properties prop) {\r
+        return prop.get("org.onap.dmaap.datarouter.provserver.https.relaxation").toString().equals("false") && !jo\r
                 .has("sync");\r
     }\r
 \r
@@ -288,6 +330,10 @@ public class Subscription extends Syncable {
         return subid;\r
     }\r
 \r
+    /**\r
+     * Subid setter.\r
+     * @param subid subid string\r
+     */\r
     public void setSubid(int subid) {\r
         this.subid = subid;\r
 \r
@@ -301,6 +347,10 @@ public class Subscription extends Syncable {
         return feedid;\r
     }\r
 \r
+    /**\r
+     * feedid setter.\r
+     * @param feedid feedid string\r
+     */\r
     public void setFeedid(int feedid) {\r
         this.feedid = feedid;\r
 \r
@@ -308,6 +358,7 @@ public class Subscription extends Syncable {
         SubLinks sl = getLinks();\r
         sl.setFeed(URLUtilities.generateFeedURL(feedid));\r
     }\r
+\r
     public String getAafInstance() {\r
         return aafInstance;\r
     }\r
@@ -344,6 +395,7 @@ public class Subscription extends Syncable {
     private boolean isFollowRedirect() {\r
         return followRedirect;\r
     }\r
+\r
     public void setFollowRedirect(boolean followRedirect) {\r
         this.followRedirect = followRedirect;\r
     }\r
@@ -368,6 +420,10 @@ public class Subscription extends Syncable {
         return subscriber;\r
     }\r
 \r
+    /**\r
+     * Subscriber setter.\r
+     * @param subscriber subscriber string\r
+     */\r
     public void setSubscriber(String subscriber) {\r
         if (subscriber != null) {\r
             if (subscriber.length() > 8) {\r
@@ -413,14 +469,11 @@ public class Subscription extends Syncable {
         return jo;\r
     }\r
 \r
-    public JSONObject asLimitedJSONObject() {\r
-        JSONObject jo = asJSONObject();\r
-        jo.remove(SUBID_KEY);\r
-        jo.remove(FEEDID_KEY);\r
-        jo.remove(LAST_MOD_KEY);\r
-        return jo;\r
-    }\r
-\r
+    /**\r
+     * Method to hide attributes.\r
+     * @param hidepasswords true/false\r
+     * @return JSONObject\r
+     */\r
     public JSONObject asJSONObject(boolean hidepasswords) {\r
         JSONObject jo = asJSONObject();\r
         if (hidepasswords) {\r
@@ -432,8 +485,21 @@ public class Subscription extends Syncable {
         return jo;\r
     }\r
 \r
+    /**\r
+     * Method to remove some attributes from JSON.\r
+     * @ JSONObject\r
+     */\r
+    public JSONObject asLimitedJSONObject() {\r
+        JSONObject jo = asJSONObject();\r
+        jo.remove(SUBID_KEY);\r
+        jo.remove(FEEDID_KEY);\r
+        jo.remove(LAST_MOD_KEY);\r
+        return jo;\r
+    }\r
+\r
+\r
     @Override\r
-    public boolean doInsert(Connection c) {\r
+    public boolean doInsert(Connection conn) {\r
         boolean rv = true;\r
         PreparedStatement ps = null;\r
         try {\r
@@ -447,8 +513,11 @@ public class Subscription extends Syncable {
             }\r
 \r
             // Create the SUBSCRIPTIONS row\r
-            String sql = "insert into SUBSCRIPTIONS (SUBID, FEEDID, DELIVERY_URL, DELIVERY_USER, DELIVERY_PASSWORD, DELIVERY_USE100, METADATA_ONLY, SUBSCRIBER, SUSPENDED, GROUPID, PRIVILEGED_SUBSCRIBER, FOLLOW_REDIRECTS, DECOMPRESS, AAF_INSTANCE) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";\r
-            ps = c.prepareStatement(sql, new String[]{SUBID_COL});\r
+            String sql = "insert into SUBSCRIPTIONS (SUBID, FEEDID, DELIVERY_URL, DELIVERY_USER, DELIVERY_PASSWORD, "\r
+                                 + "DELIVERY_USE100, METADATA_ONLY, SUBSCRIBER, SUSPENDED, GROUPID, "\r
+                                 + "PRIVILEGED_SUBSCRIBER, FOLLOW_REDIRECTS, DECOMPRESS, AAF_INSTANCE) "\r
+                                 + "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";\r
+            ps = conn.prepareStatement(sql, new String[]{SUBID_COL});\r
             ps.setInt(1, subid);\r
             ps.setInt(2, feedid);\r
             ps.setString(3, getDelivery().getUrl());\r
@@ -467,7 +536,7 @@ public class Subscription extends Syncable {
             ps.close();\r
             // Update the row to set the URLs\r
             sql = "update SUBSCRIPTIONS set SELF_LINK = ?, LOG_LINK = ? where SUBID = ?";\r
-            ps = c.prepareStatement(sql);\r
+            ps = conn.prepareStatement(sql);\r
             ps.setString(1, getLinks().getSelf());\r
             ps.setString(2, getLinks().getLog());\r
             ps.setInt(3, subid);\r
@@ -489,12 +558,15 @@ public class Subscription extends Syncable {
     }\r
 \r
     @Override\r
-    public boolean doUpdate(Connection c) {\r
+    public boolean doUpdate(Connection conn) {\r
         boolean rv = true;\r
         PreparedStatement ps = null;\r
         try {\r
-            String sql = "update SUBSCRIPTIONS set DELIVERY_URL = ?, DELIVERY_USER = ?, DELIVERY_PASSWORD = ?, DELIVERY_USE100 = ?, METADATA_ONLY = ?, SUSPENDED = ?, GROUPID = ?, PRIVILEGED_SUBSCRIBER = ?, FOLLOW_REDIRECTS = ?, DECOMPRESS = ? where SUBID = ?";\r
-            ps = c.prepareStatement(sql);\r
+            String sql = "update SUBSCRIPTIONS set DELIVERY_URL = ?, DELIVERY_USER = ?, DELIVERY_PASSWORD = ?, "\r
+                                 + "DELIVERY_USE100 = ?, METADATA_ONLY = ?, " + "SUSPENDED = ?, GROUPID = ?, "\r
+                                 + "PRIVILEGED_SUBSCRIBER = ?, "\r
+                                 + "FOLLOW_REDIRECTS = ?, DECOMPRESS = ? where SUBID = ?";\r
+            ps = conn.prepareStatement(sql);\r
             ps.setString(1, delivery.getUrl());\r
             ps.setString(2, delivery.getUser());\r
             ps.setString(3, delivery.getPassword());\r
@@ -524,7 +596,7 @@ public class Subscription extends Syncable {
 \r
 \r
     /**\r
-     * Rally US708115 Change Ownership of Subscription - 1610\r
+     * Rally US708115 Change Ownership of Subscription - 1610.\r
      */\r
     public boolean changeOwnerShip() {\r
         boolean rv = true;\r
@@ -533,9 +605,9 @@ public class Subscription extends Syncable {
 \r
             DB db = new DB();\r
             @SuppressWarnings("resource")\r
-            Connection c = db.getConnection();\r
+            Connection conn = db.getConnection();\r
             String sql = "update SUBSCRIPTIONS set SUBSCRIBER = ? where SUBID = ?";\r
-            ps = c.prepareStatement(sql);\r
+            ps = conn.prepareStatement(sql);\r
             ps.setString(1, this.subscriber);\r
             ps.setInt(2, subid);\r
             ps.execute();\r
@@ -557,12 +629,12 @@ public class Subscription extends Syncable {
 \r
 \r
     @Override\r
-    public boolean doDelete(Connection c) {\r
+    public boolean doDelete(Connection conn) {\r
         boolean rv = true;\r
         PreparedStatement ps = null;\r
         try {\r
             String sql = "delete from SUBSCRIPTIONS where SUBID = ?";\r
-            ps = c.prepareStatement(sql);\r
+            ps = conn.prepareStatement(sql);\r
             ps.setInt(1, subid);\r
             ps.execute();\r
         } catch (SQLException e) {\r
@@ -597,8 +669,8 @@ public class Subscription extends Syncable {
         if (feedid != os.feedid) {\r
             return false;\r
         }\r
-        if (groupid != os.groupid) //New field is added - Groups feature Rally:US708115 - 1610\r
-        {\r
+        if (groupid != os.groupid) {\r
+            //New field is added - Groups feature Rally:US708115 - 1610\r
             return false;\r
         }\r
         if (!delivery.equals(os.delivery)) {\r