Removing clumsy code smells and adding missing JettyFilter test
Change-Id: I1679f4a5656ab9d34ad247d3edc7eb39821cf769
Issue-ID: DMAAP-1195
Signed-off-by: egernug <gerard.nugent@est.tech>
diff --git a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/LogbackFilterTest.java b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/LogbackFilterTest.java
index 4a5d07a..c18528e 100644
--- a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/LogbackFilterTest.java
+++ b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/LogbackFilterTest.java
@@ -83,7 +83,17 @@
}
@Test
- public void Given_Event_with_invalid_jetty_string_and_valid_logger_then_jetty_Filter_DENY() {
+ public void Given_Event_with_invalid_jetty_string_and_valid_logger_then_jetty_Filter_ACCEPT() {
+ final JettyFilter filter = new JettyFilter();
+ filter.start();
+ final LoggingEvent event = new LoggingEvent();
+ event.setMessage("org.invalid.jetty");
+ event.setLoggerName("org.eclipse.jetty");
+ assertEquals(FilterReply.ACCEPT, filter.decide(event));
+ }
+
+ @Test
+ public void Given_Event_with_invalid_jetty_string_and_invalid_logger_then_jetty_Filter_DENY() {
final JettyFilter filter = new JettyFilter();
filter.start();
final LoggingEvent event = new LoggingEvent();
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 e1938cd..de90fde 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 @@
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 929c6f9..07fe737 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 LOGJSONObject reOrderObject(LOGJSONObject jo) {
- LinkedHashMap<String, Object> logrecordObj = new LinkedHashMap<String, Object>();
+ LinkedHashMap<String, Object> logrecordObj = new LinkedHashMap<>();
logrecordObj.put("statusCode", jo.get("statusCode"));
logrecordObj.put("deliveryId", jo.get("deliveryId"));
@@ -116,8 +116,7 @@
logrecordObj.put("contentLength", jo.get("contentLength"));
- LOGJSONObject newjo = new LOGJSONObject(logrecordObj);
- return newjo;
+ return new LOGJSONObject(logrecordObj);
}
@Override
@@ -127,8 +126,7 @@
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 9e6987a..8e841e6 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 LOGJSONObject reOrderObject(LOGJSONObject jo) {
- LinkedHashMap<String, Object> logrecordObj = new LinkedHashMap<String, Object>();
+ LinkedHashMap<String, Object> logrecordObj = new LinkedHashMap<>();
logrecordObj.put("expiryReason", jo.get("expiryReason"));
logrecordObj.put("publishId", jo.get("publishId"));
@@ -112,8 +112,7 @@
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 @@
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 1cfd0f6..3462e23 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 static Collection<Feed> getAllFeeds() {
- Map<Integer, Feed> map = new HashMap<Integer, Feed>();
+ Map<Integer, Feed> map = new HashMap<>();
try {
DB db = new DB();
@SuppressWarnings("resource")
@@ -208,7 +208,7 @@
}
public static List<String> getFilteredFeedUrlList(final String name, final String val) {
- List<String> list = new ArrayList<String>();
+ List<String> list = new ArrayList<>();
String sql = "select SELF_LINK from FEEDS where DELETED = 0";
if (name.equals("name")) {
sql += " and NAME = ?";
@@ -329,10 +329,8 @@
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 @@
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 a7213e0..4d90163 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 FeedAuthorization() {
this.classification = "";
- this.endpoint_ids = new HashSet<FeedEndpointID>();
- this.endpoint_addrs = new HashSet<String>();
+ 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 77726bb..0e885e5 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 @@
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 4d6b0ee..d05e3e6 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 @@
gup.getName()
);
List<Group> 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 @@
gup.getGroupid()
);
List<Group> 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<Group> 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<Group> list = getGroupsForSQL(sql);
- return list.size() > 0 ? list.get(0) : null;
+ return !list.isEmpty() ? list.get(0) : null;
}
public static Collection<Group> 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 5e16bac..72ad8af 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 LOGJSONObject reOrderObject(LOGJSONObject jo) {
- LinkedHashMap<String, Object> logrecordObj = new LinkedHashMap<String, Object>();
+ LinkedHashMap<String, Object> logrecordObj = new LinkedHashMap<>();
logrecordObj.put("statusCode", jo.get("statusCode"));
@@ -124,8 +124,7 @@
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 @@
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 d3f82e6..e8ef839 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 @@
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 1cb1f2b..0b07a5d 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 @@
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 bc1919f..7914c81 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 @@
* Creates a new bit set. All bits are initially <code>false</code>.
*/
public RLEBitSet() {
- bitsets = new TreeSet<RLE>();
+ bitsets = new TreeSet<>();
}
/**
@@ -153,7 +153,7 @@
* @param s the initialization String
*/
public RLEBitSet(String s) {
- bitsets = new TreeSet<RLE>();
+ bitsets = new TreeSet<>();
set(s);
}
@@ -196,7 +196,7 @@
* @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 void clear(long from, long to) {
checkRange(from, to);
RLE newbits = new RLE(from, to - from);
- List<RLE> newranges = new ArrayList<RLE>();
+ List<RLE> 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 5c1fd56..b0fd4f4 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 @@
private static int action = ACTION_DROP; // action to take (throttle or drop)
private static EELFLogger logger = EELFManager.getInstance().getLogger("InternalLog");
- private static Map<String, Counter> map = new HashMap<String, Counter>();
+ private static Map<String, Counter> map = new HashMap<>();
private static final Timer rolex = new Timer();
@Override
@@ -214,13 +214,13 @@
}
}
- private Map<String, List<Continuation>> suspended_requests = new HashMap<String, List<Continuation>>();
+ private Map<String, List<Continuation>> suspended_requests = new HashMap<>();
private void register(String id, Continuation continuation) {
synchronized (suspended_requests) {
List<Continuation> list = suspended_requests.get(id);
if (list == null) {
- list = new ArrayList<Continuation>();
+ list = new ArrayList<>();
suspended_requests.put(id, list);
}
list.add(continuation);
@@ -258,13 +258,12 @@
cnt = new Counter();
map.put(key, cnt);
}
- int n = cnt.getRequestRate();
- return n;
+ return cnt.getRequestRate();
}
}
public class Counter {
- private List<Long> times = new Vector<Long>(); // a record of request times
+ private List<Long> times = new Vector<>(); // a record of request times
public int prune() {
try {
@@ -302,8 +301,7 @@
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;
}