Multiple small changes to reduce technical debt. 81/25281/2
authorMagnusen, Drew (dm741q) <dm741q@att.com>
Thu, 30 Nov 2017 19:38:37 +0000 (13:38 -0600)
committerMagnusen, Drew (dm741q) <dm741q@att.com>
Thu, 7 Dec 2017 16:20:18 +0000 (10:20 -0600)
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>
policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/TopicEndpoint.java
policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/NoopTopicSinkFactory.java
policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/UebTopicSinkFactory.java
policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/UebTopicSourceFactory.java
policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusConsumer.java
policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusPublisher.java
policy-endpoints/src/main/java/org/onap/policy/drools/http/client/internal/JerseyClient.java
policy-endpoints/src/main/java/org/onap/policy/drools/http/server/internal/JettyJerseyServer.java
policy-endpoints/src/main/java/org/onap/policy/drools/http/server/internal/JettyServletServer.java

index 09ee9a4..fc7db6f 100644 (file)
@@ -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());
     }
index 5331539..1958da0 100644 (file)
@@ -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);
index 2a20c31..fc4229c 100644 (file)
@@ -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, 
index 6f3bd35..d2aa671 100644 (file)
@@ -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*")));             
                
index 8171c35..0650330 100644 (file)
@@ -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;
index 10bc832..df2088c 100644 (file)
@@ -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) {
index 5dd9736..9b18cae 100644 (file)
@@ -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;
        }
index 8d66807..f882c92 100644 (file)
@@ -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);
index e0a4617..08c6244 100644 (file)
@@ -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());