\r
package org.onap.dmaap.datarouter.provisioning.beans;\r
\r
-import org.apache.log4j.Logger;\r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\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
\r
import java.io.InvalidObjectException;\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
* @version $Id: Feed.java,v 1.13 2013/10/28 18:06:52 eby Exp $\r
*/\r
public class Feed extends Syncable {\r
- private static Logger intlogger = Logger.getLogger("org.onap.dmaap.datarouter.provisioning.internal");\r
+ private static EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");\r
private static int next_feedid = getMaxFeedID() + 1;\r
+ private static final String SQLEXCEPTION = "SQLException: ";\r
\r
private int feedid;\r
private int groupid; //New field is added - Groups feature Rally:US708115 - 1610\r
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
try {\r
DB db = new DB();\r
Connection conn = db.getConnection();\r
- try(Statement stmt = conn.createStatement()) {\r
- try(ResultSet rs = stmt.executeQuery("select COUNT(*) from FEEDS where FEEDID = " + id)) {\r
+ try(PreparedStatement stmt = conn.prepareStatement("select COUNT(*) from FEEDS where FEEDID = ?")) {\r
+ stmt.setInt(1, id);\r
+ try(ResultSet rs = stmt.executeQuery()) {\r
if (rs.next()) {\r
count = rs.getInt(1);\r
}\r
}\r
db.release(conn);\r
} catch (SQLException e) {\r
- e.printStackTrace();\r
+ intlogger.warn("PROV0024 Feed.isFeedValid: " + e.getMessage(), e);\r
}\r
return count != 0;\r
}\r
}\r
db.release(conn);\r
} catch (SQLException e) {\r
- intlogger.info("countActiveFeeds: " + e.getMessage());\r
- e.printStackTrace();\r
+ intlogger.warn("PROV0025 Feed.countActiveFeeds: " + e.getMessage(), e);\r
}\r
return count;\r
}\r
}\r
db.release(conn);\r
} catch (SQLException e) {\r
- intlogger.info("getMaxFeedID: " + e.getMessage());\r
- e.printStackTrace();\r
+ intlogger.warn("PROV0026 Feed.getMaxFeedID: " + e.getMessage(), e);\r
}\r
return max;\r
}\r
\r
public static Collection<Feed> getAllFeeds() {\r
- Map<Integer, Feed> map = new HashMap<Integer, Feed>();\r
+ Map<Integer, Feed> map = new HashMap<>();\r
try {\r
DB db = new DB();\r
@SuppressWarnings("resource")\r
}\r
db.release(conn);\r
} catch (SQLException e) {\r
- e.printStackTrace();\r
+ intlogger.warn("PROV0027 Feed.getAllFeeds: " + e.getMessage(), e);\r
}\r
return map.values();\r
}\r
\r
public static List<String> getFilteredFeedUrlList(final String name, final String val) {\r
- List<String> list = new ArrayList<String>();\r
+ List<String> list = new ArrayList<>();\r
String sql = "select SELF_LINK from FEEDS where DELETED = 0";\r
if (name.equals("name")) {\r
sql += " and NAME = ?";\r
}\r
db.release(conn);\r
} catch (SQLException e) {\r
- e.printStackTrace();\r
+ intlogger.warn("PROV0028 Feed.getFilteredFeedUrlList: " + e.getMessage(), e);\r
}\r
return list;\r
}\r
}\r
db.release(conn);\r
} catch (SQLException e) {\r
- e.printStackTrace();\r
+ intlogger.warn("PROV0029 Feed.getFeedBySQL: " + e.getMessage(), e);\r
}\r
return feed;\r
}\r
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
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
this("", "", "", "");\r
try {\r
- // The JSONObject is assumed to contain a vnd.att-dr.feed representation\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")) && aaf_instance.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
- this.version = jo.getString("version");\r
- if (version.length() > 20)\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
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
+ if (this.authorization.getEndpoint_ids().isEmpty())\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
} catch (InvalidObjectException e) {\r
throw e;\r
} catch (Exception e) {\r
- throw new InvalidObjectException("invalid JSON: " + e.getMessage());\r
+ intlogger.warn("Invalid JSON: " + e.getMessage(), e);\r
+ throw new InvalidObjectException("Invalid JSON: " + e.getMessage());\r
}\r
}\r
\r
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
this.suspended = suspended;\r
}\r
\r
- public Date getLast_mod() {\r
- return last_mod;\r
- }\r
-\r
- public Date getCreated_date() {\r
- return created_date;\r
- }\r
-\r
@Override\r
public JSONObject asJSONObject() {\r
JSONObject jo = new JSONObject();\r
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
ps.execute();\r
} catch (SQLException e) {\r
rv = false;\r
- intlogger.warn("PROV0007 doDelete: " + e.getMessage());\r
- e.printStackTrace();\r
+ intlogger.error("PROV0007 doDelete: " + e.getMessage(), e);\r
} finally {\r
try {\r
if(ps!=null) {\r
ps.close();\r
}\r
} catch (SQLException e) {\r
- e.printStackTrace();\r
+ intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
}\r
}\r
return rv;\r
}\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
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
rv = false;\r
- intlogger.warn("PROV0005 doInsert: " + e.getMessage());\r
- e.printStackTrace();\r
+ intlogger.error("PROV0005 doInsert: " + e.getMessage(), e);\r
}\r
return rv;\r
}\r
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
} catch (SQLException e) {\r
rv = false;\r
- intlogger.warn("PROV0006 doUpdate: " + e.getMessage());\r
- e.printStackTrace();\r
+ intlogger.warn("PROV0006 doUpdate: " + e.getMessage(), e);\r
} finally {\r
try {\r
if (ps != null)\r
ps.close();\r
} catch (SQLException e) {\r
- e.printStackTrace();\r
+ intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
}\r
}\r
return rv;\r
ps.close();\r
} catch (SQLException e) {\r
rv = false;\r
- intlogger.warn("PROV0006 doUpdate: " + e.getMessage());\r
- e.printStackTrace();\r
+ intlogger.warn("PROV0008 changeOwnerShip: " + e.getMessage(), e);\r
} finally {\r
try {\r
if(ps!=null) {\r
ps.close();\r
}\r
} catch (SQLException e) {\r
- e.printStackTrace();\r
+ intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
}\r
}\r
return rv;\r
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
\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