DMAAP-1195 [DR] Remove DR code smells
[dmaap/datarouter.git] / datarouter-prov / src / main / java / org / onap / dmaap / datarouter / provisioning / beans / Subscription.java
index 95f0a70..749980e 100644 (file)
@@ -75,6 +75,110 @@ public class Subscription extends Syncable {
     private String aafInstance;\r
     private boolean decompress;\r
 \r
+    public Subscription() {\r
+        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
+        this.groupid = -1; //New field is added - Groups feature Rally:US708115 - 1610\r
+        this.delivery = new SubDelivery(url, user, password, false);\r
+        this.metadataOnly = false;\r
+        this.followRedirect = false;\r
+        this.subscriber = "";\r
+        this.links = new SubLinks();\r
+        this.suspended = false;\r
+        this.lastMod = new Date();\r
+        this.createdDate = new Date();\r
+        this.privilegedSubscriber = false;\r
+        this.aafInstance = "";\r
+        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
+        this.groupid = rs.getInt("GROUPID"); //New field is added - Groups feature Rally:US708115 - 1610\r
+        this.delivery = new SubDelivery(rs);\r
+        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),\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
+        this.privilegedSubscriber = rs.getBoolean("PRIVILEGED_SUBSCRIBER");\r
+        this.aafInstance = rs.getString("AAF_INSTANCE");\r
+        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
+            // The JSONObject is assumed to contain a vnd.dmaap-dr.subscription representation\r
+            this.subid = jo.optInt(SUBID_KEY, -1);\r
+            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")) && 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
+            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 prop = (new DB()).getProperties();\r
+            if (!url.startsWith("https://") && isHttpsRelaxationFalseAndHasSyncKey(jo, prop)) {\r
+                throw new InvalidObjectException("delivery URL is not HTTPS");\r
+            }\r
+\r
+            if (url.length() > 256) {\r
+                throw new InvalidObjectException("delivery url field is too long");\r
+            }\r
+            if (user.length() > 60) {\r
+                throw new InvalidObjectException("delivery user field is too long");\r
+            }\r
+            if (password.length() > 32) {\r
+                throw new InvalidObjectException("delivery password field is too long");\r
+            }\r
+            this.delivery = new SubDelivery(url, user, password, use100);\r
+            this.metadataOnly = jo.getBoolean("metadataOnly");\r
+            this.followRedirect = jo.optBoolean("follow_redirect", false);\r
+            this.suspended = jo.optBoolean("suspend", false);\r
+            this.privilegedSubscriber = jo.optBoolean("privilegedSubscriber", false);\r
+            this.decompress = jo.optBoolean("decompress", false);\r
+            this.subscriber = jo.optString("subscriber", "");\r
+            JSONObject jol = jo.optJSONObject("links");\r
+            this.links = (jol == null) ? (new SubLinks()) : (new SubLinks(jol));\r
+        } catch (InvalidObjectException e) {\r
+            throw e;\r
+        } catch (Exception e) {\r
+            intlogger.warn("Invalid JSON: " + e.getMessage(), e);\r
+            throw new InvalidObjectException("Invalid JSON: " + e.getMessage());\r
+        }\r
+    }\r
+\r
     /**\r
      * Get specific subscription.\r
      * @param sub subscription object\r
@@ -217,110 +321,6 @@ public class Subscription extends Syncable {
         return count;\r
     }\r
 \r
-    public Subscription() {\r
-        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
-        this.groupid = -1; //New field is added - Groups feature Rally:US708115 - 1610\r
-        this.delivery = new SubDelivery(url, user, password, false);\r
-        this.metadataOnly = false;\r
-        this.followRedirect = false;\r
-        this.subscriber = "";\r
-        this.links = new SubLinks();\r
-        this.suspended = false;\r
-        this.lastMod = new Date();\r
-        this.createdDate = new Date();\r
-        this.privilegedSubscriber = false;\r
-        this.aafInstance = "";\r
-        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
-        this.groupid = rs.getInt("GROUPID"); //New field is added - Groups feature Rally:US708115 - 1610\r
-        this.delivery = new SubDelivery(rs);\r
-        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),\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
-        this.privilegedSubscriber = rs.getBoolean("PRIVILEGED_SUBSCRIBER");\r
-        this.aafInstance = rs.getString("AAF_INSTANCE");\r
-        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
-            // The JSONObject is assumed to contain a vnd.dmaap-dr.subscription representation\r
-            this.subid = jo.optInt(SUBID_KEY, -1);\r
-            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")) && 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
-            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 prop = (new DB()).getProperties();\r
-            if (!url.startsWith("https://") && isHttpsRelaxationFalseAndHasSyncKey(jo, prop)) {\r
-                throw new InvalidObjectException("delivery URL is not HTTPS");\r
-            }\r
-\r
-            if (url.length() > 256) {\r
-                throw new InvalidObjectException("delivery url field is too long");\r
-            }\r
-            if (user.length() > 60) {\r
-                throw new InvalidObjectException("delivery user field is too long");\r
-            }\r
-            if (password.length() > 32) {\r
-                throw new InvalidObjectException("delivery password field is too long");\r
-            }\r
-            this.delivery = new SubDelivery(url, user, password, use100);\r
-            this.metadataOnly = jo.getBoolean("metadataOnly");\r
-            this.followRedirect = jo.optBoolean("follow_redirect", false);\r
-            this.suspended = jo.optBoolean("suspend", false);\r
-            this.privilegedSubscriber = jo.optBoolean("privilegedSubscriber", false);\r
-            this.decompress = jo.optBoolean("decompress", false);\r
-            this.subscriber = jo.optString("subscriber", "");\r
-            JSONObject jol = jo.optJSONObject("links");\r
-            this.links = (jol == null) ? (new SubLinks()) : (new SubLinks(jol));\r
-        } catch (InvalidObjectException e) {\r
-            throw e;\r
-        } catch (Exception e) {\r
-            intlogger.warn("Invalid JSON: " + e.getMessage(), e);\r
-            throw new InvalidObjectException("Invalid JSON: " + e.getMessage());\r
-        }\r
-    }\r
-\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