diff options
author | Magnusen, Drew (dm741q) <dm741q@att.com> | 2017-11-30 13:38:37 -0600 |
---|---|---|
committer | Magnusen, Drew (dm741q) <dm741q@att.com> | 2017-12-07 10:20:18 -0600 |
commit | 1810e5979594f4dd3a5bfa2297ca75da37d6b7fc (patch) | |
tree | bf70760a1319176c21c7ce9bcfe877d5c86334fc /policy-endpoints/src/main/java/org/onap | |
parent | 7a8d505b684cc568d0f50179ff2c3a4e4880f65d (diff) |
Multiple small changes to reduce technical debt.
Made multiple changes across several classes to reduce technical debt in
policy-endpoints project.
Issue-ID: POLICY-462
Change-Id: I0338b9e98dd5a39492f3880c2e3a5d35b3957811
Signed-off-by: Magnusen, Drew (dm741q) <dm741q@att.com>
Diffstat (limited to 'policy-endpoints/src/main/java/org/onap')
9 files changed, 42 insertions, 38 deletions
diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/TopicEndpoint.java b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/TopicEndpoint.java index 09ee9a4e..fc7db6f7 100644 --- a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/TopicEndpoint.java +++ b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/TopicEndpoint.java @@ -570,7 +570,6 @@ class ProxyTopicEndpointManager implements TopicEndpoint { return this.getUebTopicSource(topicName); case DMAAP: return this.getDmaapTopicSource(topicName); - case REST: default: throw new UnsupportedOperationException("Unsupported " + commType.name()); } @@ -596,7 +595,6 @@ class ProxyTopicEndpointManager implements TopicEndpoint { return this.getDmaapTopicSink(topicName); case NOOP: return this.getNoopTopicSink(topicName); - case REST: default: throw new UnsupportedOperationException("Unsupported " + commType.name()); } diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/NoopTopicSinkFactory.java b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/NoopTopicSinkFactory.java index 53315391..1958da06 100644 --- a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/NoopTopicSinkFactory.java +++ b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/NoopTopicSinkFactory.java @@ -115,7 +115,7 @@ class IndexedNoopTopicSinkFactory implements NoopTopicSinkFactory { final List<String> sinkTopicList = new ArrayList<>(Arrays.asList(sinkTopics.split("\\s*,\\s*"))); - final List<NoopTopicSink> newSinks = new ArrayList<NoopTopicSink>(); + final List<NoopTopicSink> newSinks = new ArrayList<>(); synchronized (this) { for (final String topic : sinkTopicList) { if (this.noopTopicSinks.containsKey(topic)) { @@ -148,12 +148,14 @@ class IndexedNoopTopicSinkFactory implements NoopTopicSinkFactory { @Override public NoopTopicSink build(List<String> servers, String topic, boolean managed) { - if (servers == null) { - servers = new ArrayList<>(); + + List<String> noopSinkServers = servers; + if (noopSinkServers == null) { + noopSinkServers = new ArrayList<>(); } - if (servers.isEmpty()) { - servers.add("noop"); + if (noopSinkServers.isEmpty()) { + noopSinkServers.add("noop"); } if (topic == null || topic.isEmpty()) { @@ -165,7 +167,7 @@ class IndexedNoopTopicSinkFactory implements NoopTopicSinkFactory { return this.noopTopicSinks.get(topic); } - final NoopTopicSink sink = new NoopTopicSink(servers, topic); + final NoopTopicSink sink = new NoopTopicSink(noopSinkServers, topic); if (managed) this.noopTopicSinks.put(topic, sink); diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/UebTopicSinkFactory.java b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/UebTopicSinkFactory.java index 2a20c317..fc4229c3 100644 --- a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/UebTopicSinkFactory.java +++ b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/UebTopicSinkFactory.java @@ -125,7 +125,7 @@ class IndexedUebTopicSinkFactory implements UebTopicSinkFactory { * UEB Topic Name Index */ protected HashMap<String, UebTopicSink> uebTopicSinks = - new HashMap<String, UebTopicSink>(); + new HashMap<>(); @Override public UebTopicSink build(List<String> servers, diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/UebTopicSourceFactory.java b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/UebTopicSourceFactory.java index 6f3bd350..d2aa6710 100644 --- a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/UebTopicSourceFactory.java +++ b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/UebTopicSourceFactory.java @@ -207,7 +207,7 @@ class IndexedUebTopicSourceFactory implements UebTopicSourceFactory { String readTopics = properties.getProperty(PolicyProperties.PROPERTY_UEB_SOURCE_TOPICS); if (readTopics == null || readTopics.isEmpty()) { logger.info("{}: no topic for UEB Source", this); - return new ArrayList<UebTopicSource>(); + return new ArrayList<>(); } List<String> readTopicList = new ArrayList<>(Arrays.asList(readTopics.split("\\s*,\\s*"))); diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusConsumer.java b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusConsumer.java index 8171c35d..06503304 100644 --- a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusConsumer.java +++ b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusConsumer.java @@ -237,7 +237,7 @@ public interface BusConsumer { logger.debug("DMaaP consumer received {} : {}" + response.getResponseCode(), response.getResponseMessage()); - if (response.getResponseCode() == null || !response.getResponseCode().equals("200")) { + if (response.getResponseCode() == null || !"200".equals(response.getResponseCode())) { logger.error("DMaaP consumer received: {} : {}", response.getResponseCode(), response.getResponseMessage()); @@ -450,8 +450,8 @@ public interface BusConsumer { props.setProperty("contenttype", "application/json"); if (additionalProps != null) { - for (final String key : additionalProps.keySet()) - props.put(key, additionalProps.get(key)); + for (Map.Entry<String, String> entry : additionalProps.entrySet()) + props.put(entry.getKey(), entry.getValue()); } MRClientFactory.prop = props; diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusPublisher.java b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusPublisher.java index 10bc8325..df2088c1 100644 --- a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusPublisher.java +++ b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusPublisher.java @@ -302,8 +302,6 @@ public interface BusPublisher { /** * MR based Publisher */ - protected MRSimplerBatchPublisher publisher; - public DmaapAafPublisherWrapper(List<String> servers, String topic, String aafLogin, String aafPassword, boolean useHttps) { diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/http/client/internal/JerseyClient.java b/policy-endpoints/src/main/java/org/onap/policy/drools/http/client/internal/JerseyClient.java index 5dd97363..9b18cae0 100644 --- a/policy-endpoints/src/main/java/org/onap/policy/drools/http/client/internal/JerseyClient.java +++ b/policy-endpoints/src/main/java/org/onap/policy/drools/http/client/internal/JerseyClient.java @@ -91,7 +91,7 @@ public class JerseyClient implements HttpClient { this.password = password; this.selfSignedCerts = selfSignedCerts; - StringBuffer tmpBaseUrl = new StringBuffer(); + StringBuilder tmpBaseUrl = new StringBuilder(); if (this.https) { tmpBaseUrl.append("https://"); ClientBuilder clientBuilder; @@ -195,6 +195,7 @@ public class JerseyClient implements HttpClient { return hostname; } + @Override public int getPort() { return port; } diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/internal/JettyJerseyServer.java b/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/internal/JettyJerseyServer.java index 8d66807d..f882c927 100644 --- a/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/internal/JettyJerseyServer.java +++ b/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/internal/JettyJerseyServer.java @@ -93,7 +93,7 @@ public class JettyJerseyServer extends JettyServletServer { /** * Container for servlets */ - protected HashMap<String, ServletHolder> servlets = new HashMap<String, ServletHolder>(); + protected HashMap<String, ServletHolder> servlets = new HashMap<>(); /** * Swagger ID @@ -171,14 +171,14 @@ public class JettyJerseyServer extends JettyServletServer { @Override public synchronized void addServletPackage(String servletPath, String restPackage) { - + String servPath = servletPath; if (restPackage == null || restPackage.isEmpty()) throw new IllegalArgumentException("No discoverable REST package provided"); - if (servletPath == null || servletPath.isEmpty()) - servletPath = "/*"; + if (servPath == null || servPath.isEmpty()) + servPath = "/*"; - ServletHolder jerseyServlet = this.getServlet(servletPath); + ServletHolder jerseyServlet = this.getServlet(servPath); String initClasses = jerseyServlet.getInitParameter(JERSEY_INIT_CLASSNAMES_PARAM_NAME); diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/internal/JettyServletServer.java b/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/internal/JettyServletServer.java index e0a46173..08c62445 100644 --- a/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/internal/JettyServletServer.java +++ b/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/internal/JettyServletServer.java @@ -111,37 +111,40 @@ public abstract class JettyServletServer implements HttpServletServer, Runnable * @throws IllegalArgumentException if invalid parameters are passed in */ public JettyServletServer(String name, String host, int port, String contextPath) { - - if (name == null || name.isEmpty()) - name = "http-" + port; + String srvName = name; + String srvHost = host; + String ctxtPath = contextPath; + + if (srvName == null || srvName.isEmpty()) + srvName = "http-" + port; if (port <= 0 && port >= 65535) throw new IllegalArgumentException("Invalid Port provided: " + port); - if (host == null || host.isEmpty()) - host = "localhost"; + if (srvHost == null || srvHost.isEmpty()) + srvHost = "localhost"; - if (contextPath == null || contextPath.isEmpty()) - contextPath = "/"; + if (ctxtPath == null || ctxtPath.isEmpty()) + ctxtPath = "/"; - this.name = name; + this.name = srvName; - this.host = host; + this.host = srvHost; this.port = port; - this.contextPath = contextPath; + this.contextPath = ctxtPath; this.context = new ServletContextHandler(ServletContextHandler.SESSIONS); - this.context.setContextPath(contextPath); + this.context.setContextPath(ctxtPath); this.jettyServer = new Server(); this.jettyServer.setRequestLog(new Slf4jRequestLog()); this.connector = new ServerConnector(this.jettyServer); - this.connector.setName(name); + this.connector.setName(srvName); this.connector.setReuseAddress(true); this.connector.setPort(port); - this.connector.setHost(host); + this.connector.setHost(srvHost); this.jettyServer.addConnector(this.connector); this.jettyServer.setHandler(context); @@ -149,11 +152,13 @@ public abstract class JettyServletServer implements HttpServletServer, Runnable @Override public void setBasicAuthentication(String user, String password, String servletPath) { - if (user == null || user.isEmpty() || password == null || password.isEmpty()) + String srvltPath = servletPath; + + if (user == null || user.isEmpty() || password == null || password.isEmpty()) throw new IllegalArgumentException("Missing user and/or password"); - if (servletPath == null || servletPath.isEmpty()) - servletPath = "/*"; + if (srvltPath == null || srvltPath.isEmpty()) + srvltPath = "/*"; HashLoginService hashLoginService = new HashLoginService(); hashLoginService.putUser(user, @@ -168,7 +173,7 @@ public abstract class JettyServletServer implements HttpServletServer, Runnable ConstraintMapping constraintMapping = new ConstraintMapping(); constraintMapping.setConstraint(constraint); - constraintMapping.setPathSpec(servletPath); + constraintMapping.setPathSpec(srvltPath); ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler(); securityHandler.setAuthenticator(new BasicAuthenticator()); |