DR AAF CADI integration
[dmaap/datarouter.git] / datarouter-prov / src / main / java / org / onap / dmaap / datarouter / provisioning / beans / Feed.java
index a2076b0..502dbbd 100644 (file)
 \r
 package org.onap.dmaap.datarouter.provisioning.beans;\r
 \r
+import org.apache.log4j.Level;\r
 import org.apache.log4j.Logger;\r
 import org.json.JSONArray;\r
+import org.json.JSONException;\r
 import org.json.JSONObject;\r
 import org.onap.dmaap.datarouter.provisioning.utils.DB;\r
 import org.onap.dmaap.datarouter.provisioning.utils.JSONUtilities;\r
+import org.onap.dmaap.datarouter.provisioning.utils.PasswordProcessor;\r
 import org.onap.dmaap.datarouter.provisioning.utils.URLUtilities;\r
 \r
 import java.io.InvalidObjectException;\r
+import java.security.GeneralSecurityException;\r
 import java.sql.*;\r
-import java.util.*;\r
 import java.util.Date;\r
+import java.util.*;\r
 \r
 /**\r
  * The representation of a Feed.  Feeds can be retrieved from the DB, or stored/updated in the DB.\r
@@ -59,6 +63,7 @@ public class Feed extends Syncable {
     private boolean suspended;\r
     private Date last_mod;\r
     private Date created_date;\r
+    private String aaf_instance;\r
 \r
     /**\r
      * Check if a feed ID is valid.\r
@@ -82,7 +87,7 @@ public class Feed extends Syncable {
             }\r
             db.release(conn);\r
         } catch (SQLException e) {\r
-            intlogger.error("SQLException " + e.getMessage());\r
+            intlogger.log(Level.WARN, "PROV0024 Feed.isFeedValid: ", e);\r
         }\r
         return count != 0;\r
     }\r
@@ -132,8 +137,8 @@ public class Feed extends Syncable {
             }\r
             db.release(conn);\r
         } catch (SQLException e) {\r
-            intlogger.info("countActiveFeeds: " + e.getMessage());\r
-            intlogger.error("SQLException " + e.getMessage());\r
+            intlogger.info("PROV0025 Feed.countActiveFeeds: " + e.getMessage());\r
+            intlogger.log(Level.WARN, "PROV0025 Feed.countActiveFeeds: ", e);\r
         }\r
         return count;\r
     }\r
@@ -153,8 +158,8 @@ public class Feed extends Syncable {
             }\r
             db.release(conn);\r
         } catch (SQLException e) {\r
-            intlogger.info("getMaxFeedID: " + e.getMessage());\r
-            intlogger.error("SQLException " + e.getMessage());\r
+            intlogger.info("PROV0026 Feed.getMaxFeedID: "+e.getMessage());\r
+            intlogger.log(Level.WARN, "PROV0026 Feed.getMaxFeedID: ", e);\r
         }\r
         return max;\r
     }\r
@@ -200,7 +205,7 @@ public class Feed extends Syncable {
             }\r
             db.release(conn);\r
         } catch (SQLException e) {\r
-            intlogger.error("SQLException " + e.getMessage());\r
+            intlogger.log(Level.WARN, "PROV0027 Feed.getAllFeeds: ", e);\r
         }\r
         return map.values();\r
     }\r
@@ -234,7 +239,7 @@ public class Feed extends Syncable {
             }\r
             db.release(conn);\r
         } catch (SQLException e) {\r
-            intlogger.error("SQLException " + e.getMessage());\r
+            intlogger.log(Level.WARN, "PROV0028 Feed.getFilteredFeedUrlList: ", e);\r
         }\r
         return list;\r
     }\r
@@ -271,7 +276,7 @@ public class Feed extends Syncable {
             }\r
             db.release(conn);\r
         } catch (SQLException e) {\r
-            intlogger.error("SQLException " + e.getMessage());\r
+            intlogger.log(Level.WARN, "PROV0029 Feed.getFeedBySQL: ", e);\r
         }\r
         return feed;\r
     }\r
@@ -294,6 +299,7 @@ public class Feed extends Syncable {
         this.suspended = false;\r
         this.last_mod = new Date();\r
         this.created_date = new Date();\r
+        this.aaf_instance = "";\r
     }\r
 \r
     public Feed(ResultSet rs) throws SQLException {\r
@@ -315,6 +321,7 @@ public class Feed extends Syncable {
         this.suspended = rs.getBoolean("SUSPENDED");\r
         this.last_mod = rs.getDate("LAST_MOD");\r
         this.created_date = rs.getTimestamp("CREATED_DATE");\r
+        this.aaf_instance = rs.getString("AAF_INSTANCE");\r
     }\r
 \r
     public Feed(JSONObject jo) throws InvalidObjectException {\r
@@ -322,41 +329,49 @@ public class Feed extends Syncable {
         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"); //New field is added - Groups feature Rally:US708115 - 1610\r
+            this.groupid = jo.optInt("groupid");\r
             this.name = jo.getString("name");\r
+            this.aaf_instance = jo.optString("aaf_instance", "legacy");\r
+            if(!(aaf_instance.equalsIgnoreCase("legacy"))){\r
+                if (aaf_instance.length() > 255){\r
+                    throw new InvalidObjectException("aaf_instance field is too long");\r
+                }\r
+            }\r
             if (name.length() > 255)\r
                 throw new InvalidObjectException("name field is too long");\r
-            this.version = jo.getString("version");\r
-            if (version.length() > 20)\r
+            try {\r
+                this.version = jo.getString("version");\r
+            } catch (JSONException e) {\r
+                this.version = null;\r
+            }\r
+            if(version != null && version.length() > 20)\r
                 throw new InvalidObjectException("version field is too long");\r
             this.description = jo.optString("description");\r
-            this.business_description = jo.optString("business_description"); // New field is added - Groups feature Rally:US708102 - 1610\r
+            this.business_description = jo.optString("business_description");\r
             if (description.length() > 1000)\r
                 throw new InvalidObjectException("technical description field is too long");\r
-\r
-            if (business_description.length() > 1000) // New field is added - Groups feature Rally:US708102 - 1610\r
+            if (business_description.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
-            JSONArray ja = jauth.getJSONArray("endpoint_ids");\r
-            for (int i = 0; i < ja.length(); i++) {\r
-                JSONObject id = ja.getJSONObject(i);\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() > 20)\r
+                if (fid.getId().length() > 60)\r
                     throw new InvalidObjectException("id field is too long (" + fid.getId() + ")");\r
                 if (fid.getPassword().length() > 32)\r
-                    throw new InvalidObjectException("password field is too long (" + fid.getPassword() + ")");\r
+                    throw new InvalidObjectException("password field is too long ("+ fid.getPassword()+")");  //Fortify scan fixes - Privacy Violation\r
                 this.authorization.getEndpoint_ids().add(fid);\r
             }\r
             if (this.authorization.getEndpoint_ids().size() < 1)\r
                 throw new InvalidObjectException("need to specify at least one endpoint_id");\r
-            ja = jauth.getJSONArray("endpoint_addrs");\r
-            for (int i = 0; i < ja.length(); i++) {\r
-                String addr = ja.getString(i);\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
                 this.authorization.getEndpoint_addrs().add(addr);\r
@@ -368,8 +383,10 @@ public class Feed extends Syncable {
             JSONObject jol = jo.optJSONObject("links");\r
             this.links = (jol == null) ? (new FeedLinks()) : (new FeedLinks(jol));\r
         } catch (InvalidObjectException e) {\r
+            intlogger.log(Level.WARN, "PROV0030 Feed.Feed: ", e);\r
             throw e;\r
         } catch (Exception e) {\r
+            intlogger.error("PROV0031 Feed.Feed: invalid JSON: "+e);\r
             throw new InvalidObjectException("invalid JSON: " + e.getMessage());\r
         }\r
     }\r
@@ -389,6 +406,14 @@ public class Feed extends Syncable {
         fl.setLog(URLUtilities.generateFeedLogURL(feedid));\r
     }\r
 \r
+    public String getAafInstance() {\r
+        return aaf_instance;\r
+    }\r
+\r
+    public void setAaf_instance(String aaf_instance) {\r
+        this.aaf_instance = aaf_instance;\r
+    }\r
+\r
     //new getter setters for groups- Rally:US708115 - 1610\r
     public int getGroupid() {\r
         return groupid;\r
@@ -499,6 +524,7 @@ public class Feed extends Syncable {
         jo.put("suspend", suspended);\r
         jo.put("last_mod", last_mod.getTime());\r
         jo.put("created_date", created_date.getTime());\r
+        jo.put("aaf_instance", aaf_instance);\r
         return jo;\r
     }\r
 \r
@@ -581,7 +607,7 @@ public class Feed extends Syncable {
             }\r
 \r
             // Finally, create the FEEDS row\r
-            sql = "insert into FEEDS (FEEDID, NAME, VERSION, DESCRIPTION, AUTH_CLASS, PUBLISHER, SELF_LINK, PUBLISH_LINK, SUBSCRIBE_LINK, LOG_LINK, DELETED, SUSPENDED,BUSINESS_DESCRIPTION, GROUPID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?, ?)";\r
+            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
             try(PreparedStatement ps2 = c.prepareStatement(sql)) {\r
                 ps2.setInt(1, feedid);\r
                 ps2.setString(2, getName());\r
@@ -595,8 +621,9 @@ 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()); // New field is added - Groups feature Rally:US708102 - 1610\r
-                ps2.setInt(14, groupid); //New field is added - Groups feature Rally:US708115 - 1610\r
+                ps2.setString(13, getBusiness_description());\r
+                ps2.setInt(14, groupid);\r
+                ps2.setString(15, getAafInstance());\r
                 ps2.executeUpdate();\r
             }\r
         } catch (SQLException e) {\r
@@ -675,8 +702,8 @@ 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()); // New field is added - Groups feature Rally:US708102 - 1610\r
-            ps.setInt(6, groupid); //New field is added - Groups feature Rally:US708115 - 1610\r
+            ps.setString(5, getBusiness_description());\r
+            ps.setInt(6, groupid);\r
             ps.setInt(7, feedid);\r
             ps.executeUpdate();\r
             ps.close();\r
@@ -760,6 +787,8 @@ public class Feed extends Syncable {
             return false;\r
         if (suspended != of.suspended)\r
             return false;\r
+        if (!aaf_instance.equals(of.aaf_instance))\r
+            return false;\r
         return true;\r
     }\r
 \r
@@ -770,6 +799,6 @@ public class Feed extends Syncable {
 \r
     @Override\r
     public int hashCode() {\r
-        return Objects.hash(feedid, groupid, name, version, description, business_description, authorization, publisher, links, deleted, suspended, last_mod, created_date);\r
+        return super.hashCode();\r
     }\r
-}\r
+}
\ No newline at end of file