DMAAP-1195 [DR] Remove DR code smells
[dmaap/datarouter.git] / datarouter-prov / src / main / java / org / onap / dmaap / datarouter / provisioning / beans / Feed.java
index 4a14da2..76b9e4b 100644 (file)
@@ -57,8 +57,13 @@ import org.onap.dmaap.datarouter.provisioning.utils.URLUtilities;
 public class Feed extends Syncable {\r
 \r
     private static EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");\r
-    private static int next_feedid = getMaxFeedID() + 1;\r
+    private static int nextFeedID = getMaxFeedID() + 1;\r
     private static final String SQLEXCEPTION = "SQLException: ";\r
+    private static final String FEEDID = "FEEDID";\r
+    private static final String feedIDStr = "feedid";\r
+    private static final String deletedStr = "deleted";\r
+    private static final String lastModStr = "last_mod";\r
+    private static final String createdDateStr ="created_date";\r
 \r
     private int feedid;\r
     private int groupid; //New field is added - Groups feature Rally:US708115 - 1610\r
@@ -75,6 +80,143 @@ public class Feed extends Syncable {
     private Date createdDate;\r
     private String aafInstance;\r
 \r
+    public Feed() {\r
+        this("", "", "", "");\r
+    }\r
+\r
+    /**\r
+     * Feed constructor.\r
+     * @param name feed name\r
+     * @param version feed version\r
+     * @param desc feed description\r
+     * @param businessDescription feed business description\r
+     */\r
+    public Feed(String name, String version, String desc, String businessDescription) {\r
+        this.feedid = -1;\r
+        this.groupid = -1; //New field is added - Groups feature Rally:US708115 - 1610\r
+        this.name = name;\r
+        this.version = version;\r
+        this.description = desc;\r
+        this.businessDescription = businessDescription; // New field is added - Groups feature Rally:US708102 - 1610\r
+        this.authorization = new FeedAuthorization();\r
+        this.publisher = "";\r
+        this.links = new FeedLinks();\r
+        this.deleted = false;\r
+        this.suspended = false;\r
+        this.lastMod = new Date();\r
+        this.createdDate = new Date();\r
+        this.aafInstance = "";\r
+    }\r
+\r
+    /**\r
+     * Feed Constructor from ResultSet.\r
+     * @param rs ResultSet\r
+     * @throws SQLException in case of SQL statement error\r
+     */\r
+    public Feed(ResultSet rs) throws SQLException {\r
+        this.feedid = rs.getInt(FEEDID);\r
+        //New field is added - Groups feature Rally:US708115 - 1610\r
+        this.groupid = rs.getInt("GROUPID");\r
+        this.name = rs.getString("NAME");\r
+        this.version = rs.getString("VERSION");\r
+        this.description = rs.getString("DESCRIPTION");\r
+        // New field is added - Groups feature Rally:US708102 - 1610\r
+        this.businessDescription = rs.getString("BUSINESS_DESCRIPTION");\r
+        this.authorization = new FeedAuthorization();\r
+        this.authorization.setClassification(rs.getString("AUTH_CLASS"));\r
+        this.publisher = rs.getString("PUBLISHER");\r
+        this.links = new FeedLinks();\r
+        this.links.setSelf(rs.getString("SELF_LINK"));\r
+        this.links.setPublish(rs.getString("PUBLISH_LINK"));\r
+        this.links.setSubscribe(rs.getString("SUBSCRIBE_LINK"));\r
+        this.links.setLog(rs.getString("LOG_LINK"));\r
+        this.deleted = rs.getBoolean("DELETED");\r
+        this.suspended = rs.getBoolean("SUSPENDED");\r
+        this.lastMod = rs.getDate("LAST_MOD");\r
+        this.createdDate = rs.getTimestamp("CREATED_DATE");\r
+        this.aafInstance = rs.getString("AAF_INSTANCE");\r
+    }\r
+\r
+    /**\r
+     * Feed constructor from JSONObject.\r
+     * @param jo JSONObject\r
+     * @throws InvalidObjectException in case of JSON error\r
+     */\r
+    public Feed(JSONObject jo) throws InvalidObjectException {\r
+        this("", "", "", "");\r
+        try {\r
+            // The JSONObject is assumed to contain a vnd.dmaap-dr.feed representation\r
+            this.feedid = jo.optInt(feedIDStr, -1);\r
+            this.groupid = jo.optInt("groupid");\r
+            this.name = jo.getString("name");\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
+            if (name.length() > 255) {\r
+                throw new InvalidObjectException("name field is too long");\r
+            }\r
+            try {\r
+                this.version = jo.getString("version");\r
+            } catch (JSONException e) {\r
+                intlogger.warn("PROV0023 Feed.Feed: " + e.getMessage(), e);\r
+                this.version = null;\r
+            }\r
+            if (version != null && version.length() > 20) {\r
+                throw new InvalidObjectException("version field is too long");\r
+            }\r
+            this.description = jo.optString("description");\r
+            this.businessDescription = jo.optString("business_description");\r
+            if (description.length() > 1000) {\r
+                throw new InvalidObjectException("technical description field is too long");\r
+            }\r
+            if (businessDescription.length() > 1000) {\r
+                throw new InvalidObjectException("business description field is too long");\r
+            }\r
+            this.authorization = new FeedAuthorization();\r
+            JSONObject jauth = jo.getJSONObject("authorization");\r
+            this.authorization.setClassification(jauth.getString("classification"));\r
+            if (this.authorization.getClassification().length() > 32) {\r
+                throw new InvalidObjectException("classification field is too long");\r
+            }\r
+            JSONArray endPointIds = jauth.getJSONArray("endpoint_ids");\r
+            for (int i = 0; i < endPointIds.length(); i++) {\r
+                JSONObject id = endPointIds.getJSONObject(i);\r
+                FeedEndpointID fid = new FeedEndpointID(id.getString("id"), id.getString("password"));\r
+                if (fid.getId().length() > 60) {\r
+                    throw new InvalidObjectException("id field is too long (" + fid.getId() + ")");\r
+                }\r
+                if (fid.getPassword().length() > 32) {\r
+                    //Fortify scan fixes - Privacy Violation\r
+                    throw new InvalidObjectException("password field is too long (" + fid.getPassword() + ")");\r
+                }\r
+                this.authorization.getEndpointIDS().add(fid);\r
+            }\r
+            if (this.authorization.getEndpointIDS().isEmpty()) {\r
+                throw new InvalidObjectException("need to specify at least one endpoint_id");\r
+            }\r
+            endPointIds = jauth.getJSONArray("endpoint_addrs");\r
+            for (int i = 0; i < endPointIds.length(); i++) {\r
+                String addr = endPointIds.getString(i);\r
+                if (!JSONUtilities.validIPAddrOrSubnet(addr)) {\r
+                    throw new InvalidObjectException("bad IP addr or subnet mask: " + addr);\r
+                }\r
+                this.authorization.getEndpointAddrs().add(addr);\r
+            }\r
+\r
+            this.publisher = jo.optString("publisher", "");\r
+            this.deleted = jo.optBoolean(deletedStr, false);\r
+            this.suspended = jo.optBoolean("suspend", false);\r
+            JSONObject jol = jo.optJSONObject("links");\r
+            this.links = (jol == null) ? (new FeedLinks()) : (new FeedLinks(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
      * Check if a feed ID is valid.\r
      *\r
@@ -196,7 +338,7 @@ public class Feed extends Syncable {
                 String sql = "select * from FEED_ENDPOINT_IDS";\r
                 try (ResultSet rs = stmt.executeQuery(sql)) {\r
                     while (rs.next()) {\r
-                        int id = rs.getInt("FEEDID");\r
+                        int id = rs.getInt(FEEDID);\r
                         Feed feed = map.get(id);\r
                         if (feed != null) {\r
                             FeedEndpointID epi = new FeedEndpointID(rs);\r
@@ -209,7 +351,7 @@ public class Feed extends Syncable {
                 sql = "select * from FEED_ENDPOINT_ADDRS";\r
                 try (ResultSet rs = stmt.executeQuery(sql)) {\r
                     while (rs.next()) {\r
-                        int id = rs.getInt("FEEDID");\r
+                        int id = rs.getInt(FEEDID);\r
                         Feed feed = map.get(id);\r
                         if (feed != null) {\r
                             Collection<String> acoll = feed.getAuthorization().getEndpointAddrs();\r
@@ -303,142 +445,7 @@ public class Feed extends Syncable {
         return feed;\r
     }\r
 \r
-    public Feed() {\r
-        this("", "", "", "");\r
-    }\r
-\r
-    /**\r
-     * Feed constructor.\r
-     * @param name feed name\r
-     * @param version feed version\r
-     * @param desc feed description\r
-     * @param businessDescription feed business description\r
-     */\r
-    public Feed(String name, String version, String desc, String businessDescription) {\r
-        this.feedid = -1;\r
-        this.groupid = -1; //New field is added - Groups feature Rally:US708115 - 1610\r
-        this.name = name;\r
-        this.version = version;\r
-        this.description = desc;\r
-        this.businessDescription = businessDescription; // New field is added - Groups feature Rally:US708102 - 1610\r
-        this.authorization = new FeedAuthorization();\r
-        this.publisher = "";\r
-        this.links = new FeedLinks();\r
-        this.deleted = false;\r
-        this.suspended = false;\r
-        this.lastMod = new Date();\r
-        this.createdDate = new Date();\r
-        this.aafInstance = "";\r
-    }\r
 \r
-    /**\r
-     * Feed Constructor from ResultSet.\r
-     * @param rs ResultSet\r
-     * @throws SQLException in case of SQL statement error\r
-     */\r
-    public Feed(ResultSet rs) throws SQLException {\r
-        this.feedid = rs.getInt("FEEDID");\r
-        //New field is added - Groups feature Rally:US708115 - 1610\r
-        this.groupid = rs.getInt("GROUPID");\r
-        this.name = rs.getString("NAME");\r
-        this.version = rs.getString("VERSION");\r
-        this.description = rs.getString("DESCRIPTION");\r
-        // New field is added - Groups feature Rally:US708102 - 1610\r
-        this.businessDescription = rs.getString("BUSINESS_DESCRIPTION");\r
-        this.authorization = new FeedAuthorization();\r
-        this.authorization.setClassification(rs.getString("AUTH_CLASS"));\r
-        this.publisher = rs.getString("PUBLISHER");\r
-        this.links = new FeedLinks();\r
-        this.links.setSelf(rs.getString("SELF_LINK"));\r
-        this.links.setPublish(rs.getString("PUBLISH_LINK"));\r
-        this.links.setSubscribe(rs.getString("SUBSCRIBE_LINK"));\r
-        this.links.setLog(rs.getString("LOG_LINK"));\r
-        this.deleted = rs.getBoolean("DELETED");\r
-        this.suspended = rs.getBoolean("SUSPENDED");\r
-        this.lastMod = rs.getDate("LAST_MOD");\r
-        this.createdDate = rs.getTimestamp("CREATED_DATE");\r
-        this.aafInstance = rs.getString("AAF_INSTANCE");\r
-    }\r
-\r
-    /**\r
-     * Feed constructor from JSONObject.\r
-     * @param jo JSONObject\r
-     * @throws InvalidObjectException in case of JSON error\r
-     */\r
-    public Feed(JSONObject jo) throws InvalidObjectException {\r
-        this("", "", "", "");\r
-        try {\r
-            // The JSONObject is assumed to contain a vnd.dmaap-dr.feed representation\r
-            this.feedid = jo.optInt("feedid", -1);\r
-            this.groupid = jo.optInt("groupid");\r
-            this.name = jo.getString("name");\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
-            if (name.length() > 255) {\r
-                throw new InvalidObjectException("name field is too long");\r
-            }\r
-            try {\r
-                this.version = jo.getString("version");\r
-            } catch (JSONException e) {\r
-                intlogger.warn("PROV0023 Feed.Feed: " + e.getMessage(), e);\r
-                this.version = null;\r
-            }\r
-            if (version != null && version.length() > 20) {\r
-                throw new InvalidObjectException("version field is too long");\r
-            }\r
-            this.description = jo.optString("description");\r
-            this.businessDescription = jo.optString("business_description");\r
-            if (description.length() > 1000) {\r
-                throw new InvalidObjectException("technical description field is too long");\r
-            }\r
-            if (businessDescription.length() > 1000) {\r
-                throw new InvalidObjectException("business description field is too long");\r
-            }\r
-            this.authorization = new FeedAuthorization();\r
-            JSONObject jauth = jo.getJSONObject("authorization");\r
-            this.authorization.setClassification(jauth.getString("classification"));\r
-            if (this.authorization.getClassification().length() > 32) {\r
-                throw new InvalidObjectException("classification field is too long");\r
-            }\r
-            JSONArray endPointIds = jauth.getJSONArray("endpoint_ids");\r
-            for (int i = 0; i < endPointIds.length(); i++) {\r
-                JSONObject id = endPointIds.getJSONObject(i);\r
-                FeedEndpointID fid = new FeedEndpointID(id.getString("id"), id.getString("password"));\r
-                if (fid.getId().length() > 60) {\r
-                    throw new InvalidObjectException("id field is too long (" + fid.getId() + ")");\r
-                }\r
-                if (fid.getPassword().length() > 32) {\r
-                    //Fortify scan fixes - Privacy Violation\r
-                    throw new InvalidObjectException("password field is too long (" + fid.getPassword() + ")");\r
-                }\r
-                this.authorization.getEndpointIDS().add(fid);\r
-            }\r
-            if (this.authorization.getEndpointIDS().isEmpty()) {\r
-                throw new InvalidObjectException("need to specify at least one endpoint_id");\r
-            }\r
-            endPointIds = jauth.getJSONArray("endpoint_addrs");\r
-            for (int i = 0; i < endPointIds.length(); i++) {\r
-                String addr = endPointIds.getString(i);\r
-                if (!JSONUtilities.validIPAddrOrSubnet(addr)) {\r
-                    throw new InvalidObjectException("bad IP addr or subnet mask: " + addr);\r
-                }\r
-                this.authorization.getEndpointAddrs().add(addr);\r
-            }\r
-\r
-            this.publisher = jo.optString("publisher", "");\r
-            this.deleted = jo.optBoolean("deleted", false);\r
-            this.suspended = jo.optBoolean("suspend", false);\r
-            JSONObject jol = jo.optJSONObject("links");\r
-            this.links = (jol == null) ? (new FeedLinks()) : (new FeedLinks(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
     public int getFeedid() {\r
         return feedid;\r
@@ -463,7 +470,7 @@ public class Feed extends Syncable {
         return aafInstance;\r
     }\r
 \r
-    public void setAaf_instance(String aafInstance) {\r
+    public void setAafInstance(String aafInstance) {\r
         this.aafInstance = aafInstance;\r
     }\r
 \r
@@ -501,11 +508,11 @@ public class Feed extends Syncable {
     }\r
 \r
     // New field is added - Groups feature Rally:US708102 - 1610\r
-    public String getBusiness_description() {\r
+    public String getBusinessDescription() {\r
         return businessDescription;\r
     }\r
 \r
-    public void setBusiness_description(String businessDescription) {\r
+    public void setBusinessDescription(String businessDescription) {\r
         this.businessDescription = businessDescription;\r
     }\r
 \r
@@ -561,7 +568,7 @@ public class Feed extends Syncable {
     @Override\r
     public JSONObject asJSONObject() {\r
         JSONObject jo = new JSONObject();\r
-        jo.put("feedid", feedid);\r
+        jo.put(feedIDStr, feedid);\r
         //New field is added - Groups feature Rally:US708115 - 1610\r
         jo.put("groupid", groupid);\r
         jo.put("name", name);\r
@@ -572,10 +579,10 @@ public class Feed extends Syncable {
         jo.put("authorization", authorization.asJSONObject());\r
         jo.put("publisher", publisher);\r
         jo.put("links", links.asJSONObject());\r
-        jo.put("deleted", deleted);\r
+        jo.put(deletedStr, deleted);\r
         jo.put("suspend", suspended);\r
-        jo.put("last_mod", lastMod.getTime());\r
-        jo.put("created_date", createdDate.getTime());\r
+        jo.put(lastModStr, lastMod.getTime());\r
+        jo.put(createdDateStr, createdDate.getTime());\r
         jo.put("aaf_instance", aafInstance);\r
         return jo;\r
     }\r
@@ -588,10 +595,10 @@ public class Feed extends Syncable {
     public JSONObject asJSONObject(boolean hidepasswords) {\r
         JSONObject jo = asJSONObject();\r
         if (hidepasswords) {\r
-            jo.remove("feedid");    // we no longer hide passwords, however we do hide these\r
-            jo.remove("deleted");\r
-            jo.remove("last_mod");\r
-            jo.remove("created_date");\r
+            jo.remove(feedIDStr);    // we no longer hide passwords, however we do hide these\r
+            jo.remove(deletedStr);\r
+            jo.remove(lastModStr);\r
+            jo.remove(createdDateStr);\r
         }\r
         return jo;\r
     }\r
@@ -602,10 +609,10 @@ public class Feed extends Syncable {
      */\r
     public JSONObject asLimitedJSONObject() {\r
         JSONObject jo = asJSONObject();\r
-        jo.remove("deleted");\r
-        jo.remove("feedid");\r
-        jo.remove("last_mod");\r
-        jo.remove("created_date");\r
+        jo.remove(deletedStr);\r
+        jo.remove(feedIDStr);\r
+        jo.remove(lastModStr);\r
+        jo.remove(createdDateStr);\r
         return jo;\r
     }\r
 \r
@@ -640,11 +647,11 @@ public class Feed extends Syncable {
         boolean rv = true;\r
         try {\r
             if (feedid == -1) {\r
-                setFeedid(next_feedid++);\r
+                setFeedid(nextFeedID++);\r
             }\r
             // In case we insert a feed from synchronization\r
-            if (feedid > next_feedid) {\r
-                next_feedid = feedid + 1;\r
+            if (feedid > nextFeedID) {\r
+                nextFeedID = feedid + 1;\r
             }\r
 \r
             // Create FEED_ENDPOINT_IDS rows\r
@@ -687,7 +694,7 @@ public class Feed extends Syncable {
                 ps2.setString(10, getLinks().getLog());\r
                 ps2.setBoolean(11, isDeleted());\r
                 ps2.setBoolean(12, isSuspended());\r
-                ps2.setString(13, getBusiness_description());\r
+                ps2.setString(13, getBusinessDescription());\r
                 ps2.setInt(14, groupid);\r
                 ps2.setString(15, getAafInstance());\r
                 ps2.executeUpdate();\r
@@ -768,7 +775,7 @@ public class Feed extends Syncable {
             ps.setString(2, getAuthorization().getClassification());\r
             ps.setInt(3, deleted ? 1 : 0);\r
             ps.setInt(4, suspended ? 1 : 0);\r
-            ps.setString(5, getBusiness_description());\r
+            ps.setString(5, getBusinessDescription());\r
             ps.setInt(6, groupid);\r
             ps.setInt(7, feedid);\r
             ps.executeUpdate();\r