From 8ebd052e0b1066c432f5dba6ef69599eaf5ec27e Mon Sep 17 00:00:00 2001 From: egernug Date: Thu, 25 Jul 2019 16:18:31 +0000 Subject: Removing clumsy code smells and adding missing JettyFilter test Change-Id: I1679f4a5656ab9d34ad247d3edc7eb39821cf769 Issue-ID: DMAAP-1195 Signed-off-by: egernug --- .../onap/dmaap/datarouter/provisioning/FeedServlet.java | 4 +--- .../datarouter/provisioning/beans/DeliveryRecord.java | 8 +++----- .../dmaap/datarouter/provisioning/beans/ExpiryRecord.java | 8 +++----- .../org/onap/dmaap/datarouter/provisioning/beans/Feed.java | 10 ++++------ .../datarouter/provisioning/beans/FeedAuthorization.java | 4 ++-- .../dmaap/datarouter/provisioning/beans/FeedLinks.java | 2 +- .../onap/dmaap/datarouter/provisioning/beans/Group.java | 8 ++++---- .../dmaap/datarouter/provisioning/beans/PublishRecord.java | 9 +++------ .../onap/dmaap/datarouter/provisioning/beans/SubLinks.java | 2 +- .../dmaap/datarouter/provisioning/beans/Subscription.java | 3 +-- .../dmaap/datarouter/provisioning/utils/RLEBitSet.java | 8 ++++---- .../datarouter/provisioning/utils/ThrottleFilter.java | 14 ++++++-------- 12 files changed, 33 insertions(+), 47 deletions(-) (limited to 'datarouter-prov/src/main/java/org') diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/FeedServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/FeedServlet.java index e1938cd8..de90fdee 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/FeedServlet.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/FeedServlet.java @@ -338,15 +338,13 @@ public class FeedServlet extends ProxyServlet { return; } // US DSCDR-19 for DCAE if version is not null, version can't be changed - if ((oldFeed.getVersion() != null) && (feed.getVersion() != null)) { - if (!oldFeed.getVersion().equals(feed.getVersion())) { + if ((oldFeed.getVersion() != null) && (feed.getVersion() != null) && !oldFeed.getVersion().equals(feed.getVersion())) { message = "The version of the feed may not be updated."; elr.setMessage(message); elr.setResult(HttpServletResponse.SC_BAD_REQUEST); eventlogger.error(elr.toString()); sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger); return; - } } /* diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/DeliveryRecord.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/DeliveryRecord.java index 929c6f90..07fe7372 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/DeliveryRecord.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/DeliveryRecord.java @@ -101,7 +101,7 @@ public class DeliveryRecord extends BaseLogRecord { public LOGJSONObject reOrderObject(LOGJSONObject jo) { - LinkedHashMap logrecordObj = new LinkedHashMap(); + LinkedHashMap logrecordObj = new LinkedHashMap<>(); logrecordObj.put("statusCode", jo.get("statusCode")); logrecordObj.put("deliveryId", jo.get("deliveryId")); @@ -116,8 +116,7 @@ public class DeliveryRecord extends BaseLogRecord { logrecordObj.put("contentLength", jo.get("contentLength")); - LOGJSONObject newjo = new LOGJSONObject(logrecordObj); - return newjo; + return new LOGJSONObject(logrecordObj); } @Override @@ -127,8 +126,7 @@ public class DeliveryRecord extends BaseLogRecord { jo.put("deliveryId", user); jo.put("statusCode", result); - LOGJSONObject newjo = this.reOrderObject(jo); - return newjo; + return this.reOrderObject(jo); } @Override diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/ExpiryRecord.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/ExpiryRecord.java index 9e6987a5..8e841e68 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/ExpiryRecord.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/ExpiryRecord.java @@ -100,7 +100,7 @@ public class ExpiryRecord extends BaseLogRecord { } public LOGJSONObject reOrderObject(LOGJSONObject jo) { - LinkedHashMap logrecordObj = new LinkedHashMap(); + LinkedHashMap logrecordObj = new LinkedHashMap<>(); logrecordObj.put("expiryReason", jo.get("expiryReason")); logrecordObj.put("publishId", jo.get("publishId")); @@ -112,8 +112,7 @@ public class ExpiryRecord extends BaseLogRecord { logrecordObj.put("date", jo.get("date")); logrecordObj.put("contentLength", jo.get("contentLength")); - LOGJSONObject newjo = new LOGJSONObject(logrecordObj); - return newjo; + return new LOGJSONObject(logrecordObj); } @Override @@ -123,8 +122,7 @@ public class ExpiryRecord extends BaseLogRecord { jo.put("expiryReason", reason); jo.put("attempts", attempts); - LOGJSONObject newjo = this.reOrderObject(jo); - return newjo; + return this.reOrderObject(jo); } @Override 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 1cfd0f6b..3462e234 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 @@ -162,7 +162,7 @@ public class Feed extends Syncable { } public static Collection getAllFeeds() { - Map map = new HashMap(); + Map map = new HashMap<>(); try { DB db = new DB(); @SuppressWarnings("resource") @@ -208,7 +208,7 @@ public class Feed extends Syncable { } public static List getFilteredFeedUrlList(final String name, final String val) { - List list = new ArrayList(); + List list = new ArrayList<>(); String sql = "select SELF_LINK from FEEDS where DELETED = 0"; if (name.equals("name")) { sql += " and NAME = ?"; @@ -329,10 +329,8 @@ public class Feed extends Syncable { 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){ + if(!(aaf_instance.equalsIgnoreCase("legacy")) && 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"); @@ -365,7 +363,7 @@ public class Feed extends Syncable { 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) + if (this.authorization.getEndpoint_ids().isEmpty()) throw new InvalidObjectException("need to specify at least one endpoint_id"); endPointIds = jauth.getJSONArray("endpoint_addrs"); for (int i = 0; i < endPointIds.length(); i++) { diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/FeedAuthorization.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/FeedAuthorization.java index a7213e09..4d901633 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/FeedAuthorization.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/FeedAuthorization.java @@ -44,8 +44,8 @@ public class FeedAuthorization implements JSONable { public FeedAuthorization() { this.classification = ""; - this.endpoint_ids = new HashSet(); - this.endpoint_addrs = new HashSet(); + this.endpoint_ids = new HashSet<>(); + this.endpoint_addrs = new HashSet<>(); } public String getClassification() { diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/FeedLinks.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/FeedLinks.java index 77726bb4..0e885e5f 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/FeedLinks.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/FeedLinks.java @@ -45,7 +45,7 @@ public class FeedLinks implements JSONable { self = publish = subscribe = log = null; } - public FeedLinks(JSONObject jo) throws InvalidObjectException { + public FeedLinks(JSONObject jo) { this(); self = jo.getString("self"); publish = jo.getString("publish"); diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Group.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Group.java index 4d6b0ee2..d05e3e6b 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Group.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Group.java @@ -121,7 +121,7 @@ public class Group extends Syncable { gup.getName() ); List list = getGroupsForSQL(sql); - return list.size() > 0 ? list.get(0) : null; + return !list.isEmpty() ? list.get(0) : null; } public static Group getGroupMatching(Group gup, int groupid) { @@ -131,19 +131,19 @@ public class Group extends Syncable { gup.getGroupid() ); List list = getGroupsForSQL(sql); - return list.size() > 0 ? list.get(0) : null; + return !list.isEmpty() ? list.get(0) : null; } public static Group getGroupById(int id) { String sql = "select * from GROUPS where GROUPID = " + id; List list = getGroupsForSQL(sql); - return list.size() > 0 ? list.get(0) : null; + return !list.isEmpty() ? list.get(0) : null; } static Group getGroupByAuthId(String id) { String sql = "select * from GROUPS where AUTHID = '" + id + "'"; List list = getGroupsForSQL(sql); - return list.size() > 0 ? list.get(0) : null; + return !list.isEmpty() ? list.get(0) : null; } public static Collection getAllgroups() { diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/PublishRecord.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/PublishRecord.java index 5e16bac8..72ad8af0 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/PublishRecord.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/PublishRecord.java @@ -109,7 +109,7 @@ public class PublishRecord extends BaseLogRecord { public LOGJSONObject reOrderObject(LOGJSONObject jo) { - LinkedHashMap logrecordObj = new LinkedHashMap(); + LinkedHashMap logrecordObj = new LinkedHashMap<>(); logrecordObj.put("statusCode", jo.get("statusCode")); @@ -124,8 +124,7 @@ public class PublishRecord extends BaseLogRecord { logrecordObj.put("contentLength", jo.get("contentLength")); logrecordObj.put("fileName", jo.get("fileName")); - LOGJSONObject newjo = new LOGJSONObject(logrecordObj); - return newjo; + return new LOGJSONObject(logrecordObj); } @Override @@ -140,9 +139,7 @@ public class PublishRecord extends BaseLogRecord { jo.put("statusCode", status); jo.put("fileName", fileName); - LOGJSONObject newjo = this.reOrderObject(jo); - - return newjo; + return this.reOrderObject(jo); } @Override diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/SubLinks.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/SubLinks.java index d3f82e6e..e8ef8393 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/SubLinks.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/SubLinks.java @@ -44,7 +44,7 @@ public class SubLinks implements JSONable { self = feed = log = null; } - public SubLinks(JSONObject jo) throws InvalidObjectException { + public SubLinks(JSONObject jo) { this(); self = jo.getString("self"); feed = jo.getString("feed"); diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Subscription.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Subscription.java index 1cb1f2bb..0b07a5d9 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Subscription.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Subscription.java @@ -236,8 +236,7 @@ public class Subscription extends Syncable { this.feedid = jo.optInt(FEEDID_KEY, -1); this.groupid = jo.optInt(GROUPID_KEY, -1); //New field is added - Groups feature Rally:US708115 - 1610 this.aafInstance = jo.optString("aaf_instance", "legacy"); - if(!(aafInstance.equalsIgnoreCase("legacy"))){ - if (aafInstance.length() > 255) + if(!(aafInstance.equalsIgnoreCase("legacy")) && aafInstance.length() > 255) { throw new InvalidObjectException("aaf_instance field is too long"); } JSONObject jdeli = jo.getJSONObject("delivery"); diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/RLEBitSet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/RLEBitSet.java index bc1919f7..7914c81d 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/RLEBitSet.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/RLEBitSet.java @@ -144,7 +144,7 @@ public class RLEBitSet { * Creates a new bit set. All bits are initially false. */ public RLEBitSet() { - bitsets = new TreeSet(); + bitsets = new TreeSet<>(); } /** @@ -153,7 +153,7 @@ public class RLEBitSet { * @param s the initialization String */ public RLEBitSet(String s) { - bitsets = new TreeSet(); + bitsets = new TreeSet<>(); set(s); } @@ -196,7 +196,7 @@ public class RLEBitSet { * @throws NumberFormatException - if a number is incorrectly formatted * @throws IndexOutOfBoundsException - if an index is negative */ - public void set(String s) throws NumberFormatException { + public void set(String s) { s = s.trim(); if (!s.isEmpty()) { for (String s2 : s.split("[, \n]+")) { @@ -280,7 +280,7 @@ public class RLEBitSet { public void clear(long from, long to) { checkRange(from, to); RLE newbits = new RLE(from, to - from); - List newranges = new ArrayList(); + List newranges = new ArrayList<>(); synchronized (bitsets) { for (RLE bs : bitsets) { if (bs.intersects(newbits)) { diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/ThrottleFilter.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/ThrottleFilter.java index 5c1fd560..b0fd4f40 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/ThrottleFilter.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/ThrottleFilter.java @@ -103,7 +103,7 @@ public class ThrottleFilter extends TimerTask implements Filter { private static int action = ACTION_DROP; // action to take (throttle or drop) private static EELFLogger logger = EELFManager.getInstance().getLogger("InternalLog"); - private static Map map = new HashMap(); + private static Map map = new HashMap<>(); private static final Timer rolex = new Timer(); @Override @@ -214,13 +214,13 @@ public class ThrottleFilter extends TimerTask implements Filter { } } - private Map> suspended_requests = new HashMap>(); + private Map> suspended_requests = new HashMap<>(); private void register(String id, Continuation continuation) { synchronized (suspended_requests) { List list = suspended_requests.get(id); if (list == null) { - list = new ArrayList(); + list = new ArrayList<>(); suspended_requests.put(id, list); } list.add(continuation); @@ -258,13 +258,12 @@ public class ThrottleFilter extends TimerTask implements Filter { cnt = new Counter(); map.put(key, cnt); } - int n = cnt.getRequestRate(); - return n; + return cnt.getRequestRate(); } } public class Counter { - private List times = new Vector(); // a record of request times + private List times = new Vector<>(); // a record of request times public int prune() { try { @@ -302,8 +301,7 @@ public class ThrottleFilter extends TimerTask implements Filter { if (ix < 0 || ix == path.length() - 1) return -2; try { - int feedid = Integer.parseInt(path.substring(0, ix)); - return feedid; + return Integer.parseInt(path.substring(0, ix)); } catch (NumberFormatException e) { return -1; } -- cgit 1.2.3-korg