X-Git-Url: https://gerrit.onap.org/r/gitweb?p=dmaap%2Fdatarouter.git;a=blobdiff_plain;f=datarouter-prov%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdatarouter%2Fprovisioning%2Fbeans%2FFeed.java;h=1cfd0f6bc892341008f9d3a4a0010d037c4d4c8e;hp=f18734243fbc3f413e2028bec350fd4292feaea5;hb=534c164c124950a2019acf71d253ac96be12c78c;hpb=85b8739b9f1ebdf9731b134ac2b2796c0e2e5178 diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Feed.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Feed.java index f1873424..1cfd0f6b 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Feed.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Feed.java @@ -24,8 +24,10 @@ package org.onap.dmaap.datarouter.provisioning.beans; -import org.apache.log4j.Logger; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import org.json.JSONArray; +import org.json.JSONException; import org.json.JSONObject; import org.onap.dmaap.datarouter.provisioning.utils.DB; import org.onap.dmaap.datarouter.provisioning.utils.JSONUtilities; @@ -33,8 +35,8 @@ import org.onap.dmaap.datarouter.provisioning.utils.URLUtilities; import java.io.InvalidObjectException; import java.sql.*; -import java.util.*; import java.util.Date; +import java.util.*; /** * The representation of a Feed. Feeds can be retrieved from the DB, or stored/updated in the DB. @@ -43,8 +45,9 @@ import java.util.Date; * @version $Id: Feed.java,v 1.13 2013/10/28 18:06:52 eby Exp $ */ public class Feed extends Syncable { - private static Logger intlogger = Logger.getLogger("org.onap.dmaap.datarouter.provisioning.internal"); + private static EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog"); private static int next_feedid = getMaxFeedID() + 1; + private static final String SQLEXCEPTION = "SQLException: "; private int feedid; private int groupid; //New field is added - Groups feature Rally:US708115 - 1610 @@ -59,6 +62,7 @@ public class Feed extends Syncable { private boolean suspended; private Date last_mod; private Date created_date; + private String aaf_instance; /** * Check if a feed ID is valid. @@ -82,7 +86,7 @@ public class Feed extends Syncable { } db.release(conn); } catch (SQLException e) { - intlogger.error("SQLException " + e.getMessage()); + intlogger.warn("PROV0024 Feed.isFeedValid: " + e.getMessage(), e); } return count != 0; } @@ -132,8 +136,7 @@ public class Feed extends Syncable { } db.release(conn); } catch (SQLException e) { - intlogger.info("countActiveFeeds: " + e.getMessage()); - intlogger.error("SQLException " + e.getMessage()); + intlogger.warn("PROV0025 Feed.countActiveFeeds: " + e.getMessage(), e); } return count; } @@ -153,8 +156,7 @@ public class Feed extends Syncable { } db.release(conn); } catch (SQLException e) { - intlogger.info("getMaxFeedID: " + e.getMessage()); - intlogger.error("SQLException " + e.getMessage()); + intlogger.warn("PROV0026 Feed.getMaxFeedID: " + e.getMessage(), e); } return max; } @@ -200,7 +202,7 @@ public class Feed extends Syncable { } db.release(conn); } catch (SQLException e) { - intlogger.error("SQLException " + e.getMessage()); + intlogger.warn("PROV0027 Feed.getAllFeeds: " + e.getMessage(), e); } return map.values(); } @@ -234,7 +236,7 @@ public class Feed extends Syncable { } db.release(conn); } catch (SQLException e) { - intlogger.error("SQLException " + e.getMessage()); + intlogger.warn("PROV0028 Feed.getFilteredFeedUrlList: " + e.getMessage(), e); } return list; } @@ -271,7 +273,7 @@ public class Feed extends Syncable { } db.release(conn); } catch (SQLException e) { - intlogger.error("SQLException " + e.getMessage()); + intlogger.warn("PROV0029 Feed.getFeedBySQL: " + e.getMessage(), e); } return feed; } @@ -294,6 +296,7 @@ public class Feed extends Syncable { this.suspended = false; this.last_mod = new Date(); this.created_date = new Date(); + this.aaf_instance = ""; } public Feed(ResultSet rs) throws SQLException { @@ -315,48 +318,58 @@ public class Feed extends Syncable { this.suspended = rs.getBoolean("SUSPENDED"); this.last_mod = rs.getDate("LAST_MOD"); this.created_date = rs.getTimestamp("CREATED_DATE"); + this.aaf_instance = rs.getString("AAF_INSTANCE"); } public Feed(JSONObject jo) throws InvalidObjectException { this("", "", "", ""); try { - // The JSONObject is assumed to contain a vnd.att-dr.feed representation + // The JSONObject is assumed to contain a vnd.dmaap-dr.feed representation this.feedid = jo.optInt("feedid", -1); - this.groupid = jo.optInt("groupid"); //New field is added - Groups feature Rally:US708115 - 1610 + this.groupid = jo.optInt("groupid"); this.name = jo.getString("name"); + this.aaf_instance = jo.optString("aaf_instance", "legacy"); + if(!(aaf_instance.equalsIgnoreCase("legacy"))){ + if (aaf_instance.length() > 255){ + throw new InvalidObjectException("aaf_instance field is too long"); + } + } if (name.length() > 255) throw new InvalidObjectException("name field is too long"); - this.version = jo.getString("version"); - if (version.length() > 20) + try { + this.version = jo.getString("version"); + } catch (JSONException e) { + intlogger.warn("PROV0023 Feed.Feed: " + e.getMessage(), e); + this.version = null; + } + if(version != null && version.length() > 20) throw new InvalidObjectException("version field is too long"); this.description = jo.optString("description"); - this.business_description = jo.optString("business_description"); // New field is added - Groups feature Rally:US708102 - 1610 + this.business_description = jo.optString("business_description"); if (description.length() > 1000) throw new InvalidObjectException("technical description field is too long"); - - if (business_description.length() > 1000) // New field is added - Groups feature Rally:US708102 - 1610 + if (business_description.length() > 1000) throw new InvalidObjectException("business description field is too long"); - this.authorization = new FeedAuthorization(); JSONObject jauth = jo.getJSONObject("authorization"); this.authorization.setClassification(jauth.getString("classification")); if (this.authorization.getClassification().length() > 32) throw new InvalidObjectException("classification field is too long"); - JSONArray ja = jauth.getJSONArray("endpoint_ids"); - for (int i = 0; i < ja.length(); i++) { - JSONObject id = ja.getJSONObject(i); + JSONArray endPointIds = jauth.getJSONArray("endpoint_ids"); + for (int i = 0; i < endPointIds.length(); i++) { + JSONObject id = endPointIds.getJSONObject(i); FeedEndpointID fid = new FeedEndpointID(id.getString("id"), id.getString("password")); - if (fid.getId().length() > 20) + if (fid.getId().length() > 60) throw new InvalidObjectException("id field is too long (" + fid.getId() + ")"); if (fid.getPassword().length() > 32) - throw new InvalidObjectException("password field is too long (" + fid.getPassword() + ")"); + throw new InvalidObjectException("password field is too long ("+ fid.getPassword()+")"); //Fortify scan fixes - Privacy Violation this.authorization.getEndpoint_ids().add(fid); } if (this.authorization.getEndpoint_ids().size() < 1) throw new InvalidObjectException("need to specify at least one endpoint_id"); - ja = jauth.getJSONArray("endpoint_addrs"); - for (int i = 0; i < ja.length(); i++) { - String addr = ja.getString(i); + endPointIds = jauth.getJSONArray("endpoint_addrs"); + for (int i = 0; i < endPointIds.length(); i++) { + String addr = endPointIds.getString(i); if (!JSONUtilities.validIPAddrOrSubnet(addr)) throw new InvalidObjectException("bad IP addr or subnet mask: " + addr); this.authorization.getEndpoint_addrs().add(addr); @@ -370,7 +383,8 @@ public class Feed extends Syncable { } catch (InvalidObjectException e) { throw e; } catch (Exception e) { - throw new InvalidObjectException("invalid JSON: " + e.getMessage()); + intlogger.warn("Invalid JSON: " + e.getMessage(), e); + throw new InvalidObjectException("Invalid JSON: " + e.getMessage()); } } @@ -389,6 +403,14 @@ public class Feed extends Syncable { fl.setLog(URLUtilities.generateFeedLogURL(feedid)); } + public String getAafInstance() { + return aaf_instance; + } + + public void setAaf_instance(String aaf_instance) { + this.aaf_instance = aaf_instance; + } + //new getter setters for groups- Rally:US708115 - 1610 public int getGroupid() { return groupid; @@ -475,14 +497,6 @@ public class Feed extends Syncable { this.suspended = suspended; } - public Date getLast_mod() { - return last_mod; - } - - public Date getCreated_date() { - return created_date; - } - @Override public JSONObject asJSONObject() { JSONObject jo = new JSONObject(); @@ -499,6 +513,7 @@ public class Feed extends Syncable { jo.put("suspend", suspended); jo.put("last_mod", last_mod.getTime()); jo.put("created_date", created_date.getTime()); + jo.put("aaf_instance", aaf_instance); return jo; } @@ -533,15 +548,14 @@ public class Feed extends Syncable { ps.execute(); } catch (SQLException e) { rv = false; - intlogger.warn("PROV0007 doDelete: " + e.getMessage()); - intlogger.error("SQLException " + e.getMessage()); + intlogger.error("PROV0007 doDelete: " + e.getMessage(), e); } finally { try { if(ps!=null) { ps.close(); } } catch (SQLException e) { - intlogger.error("SQLException " + e.getMessage()); + intlogger.error(SQLEXCEPTION + e.getMessage(), e); } } return rv; @@ -581,7 +595,7 @@ public class Feed extends Syncable { } // Finally, create the FEEDS row - 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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?, ?)"; + 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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; try(PreparedStatement ps2 = c.prepareStatement(sql)) { ps2.setInt(1, feedid); ps2.setString(2, getName()); @@ -595,14 +609,14 @@ public class Feed extends Syncable { ps2.setString(10, getLinks().getLog()); ps2.setBoolean(11, isDeleted()); ps2.setBoolean(12, isSuspended()); - ps2.setString(13, getBusiness_description()); // New field is added - Groups feature Rally:US708102 - 1610 - ps2.setInt(14, groupid); //New field is added - Groups feature Rally:US708115 - 1610 + ps2.setString(13, getBusiness_description()); + ps2.setInt(14, groupid); + ps2.setString(15, getAafInstance()); ps2.executeUpdate(); } } catch (SQLException e) { rv = false; - intlogger.warn("PROV0005 doInsert: " + e.getMessage()); - intlogger.error("SQLException " + e.getMessage()); + intlogger.error("PROV0005 doInsert: " + e.getMessage(), e); } return rv; } @@ -675,20 +689,20 @@ public class Feed extends Syncable { ps.setString(2, getAuthorization().getClassification()); ps.setInt(3, deleted ? 1 : 0); ps.setInt(4, suspended ? 1 : 0); - ps.setString(5, getBusiness_description()); // New field is added - Groups feature Rally:US708102 - 1610 - ps.setInt(6, groupid); //New field is added - Groups feature Rally:US708115 - 1610 + ps.setString(5, getBusiness_description()); + ps.setInt(6, groupid); ps.setInt(7, feedid); ps.executeUpdate(); ps.close(); } catch (SQLException e) { rv = false; - intlogger.warn("PROV0006 doUpdate: " + e.getMessage()); + intlogger.warn("PROV0006 doUpdate: " + e.getMessage(), e); } finally { try { if (ps != null) ps.close(); } catch (SQLException e) { - intlogger.error("SQLException " + e.getMessage()); + intlogger.error(SQLEXCEPTION + e.getMessage(), e); } } return rv; @@ -714,14 +728,14 @@ public class Feed extends Syncable { ps.close(); } catch (SQLException e) { rv = false; - intlogger.warn("PROV0006 doUpdate: " + e.getMessage()); + intlogger.warn("PROV0008 changeOwnerShip: " + e.getMessage(), e); } finally { try { if(ps!=null) { ps.close(); } } catch (SQLException e) { - intlogger.error("SQLException " + e.getMessage()); + intlogger.error(SQLEXCEPTION + e.getMessage(), e); } } return rv; @@ -760,6 +774,8 @@ public class Feed extends Syncable { return false; if (suspended != of.suspended) return false; + if (!aaf_instance.equals(of.aaf_instance)) + return false; return true; } @@ -770,6 +786,6 @@ public class Feed extends Syncable { @Override public int hashCode() { - return Objects.hash(feedid, groupid, name, version, description, business_description, authorization, publisher, links, deleted, suspended, last_mod, created_date); + return super.hashCode(); } -} +} \ No newline at end of file