Sonar fix too many method param 08/82408/1
authorArindam Mondal <arind.mondal@samsung.com>
Fri, 15 Mar 2019 09:54:33 +0000 (18:54 +0900)
committerarind.mondal <arind.mondal@samsung.com>
Fri, 15 Mar 2019 09:55:09 +0000 (18:55 +0900)
Issue-ID: DMAAP-1099
Change-Id: Id659edc743c76e8a56cbb39d0185bff5c50f36a3
Signed-off-by: Arindam Mondal <arind.mondal@samsung.com>
src/main/java/org/onap/dmaap/mr/client/impl/MRBaseClient.java
src/main/java/org/onap/dmaap/mr/client/impl/MRSimplerBatchPublisher.java
src/main/java/org/onap/dmaap/mr/client/impl/PostAuthDataObject.java [new file with mode: 0644]
src/test/java/org/onap/dmaap/mr/client/impl/MRBaseClientTest.java

index 8ed7dd8..4c6d74e 100644 (file)
@@ -160,16 +160,17 @@ public class MRBaseClient extends HttpClient implements MRClient {
                return responseData;
        }
 
-       public JSONObject postAuth(final String path, final byte[] data, final String contentType, final String authKey,
-                       final String authDate, final String username, final String password, final String protocolFlag)
+       public JSONObject postAuth(PostAuthDataObject postAuthDO)
                        throws HttpException, JSONException {
-               if ((null != username && null != password)) {
-                       WebTarget target=null;
-                       Response response=null;
-                       target = DmaapClientUtil.getTarget(path, username, password);
-                       response =DmaapClientUtil.postResponsewtCambriaAuth(target, authKey, authDate, data, contentType);
-                       return getResponseDataInJson(response);
-               } else {
+        if ((null != postAuthDO.getUsername() && null != postAuthDO.getPassword())) {
+            WebTarget target = null;
+            Response response = null;
+            target = DmaapClientUtil.getTarget(postAuthDO.getPath(), postAuthDO.getUsername(),
+                    postAuthDO.getPassword());
+            response = DmaapClientUtil.postResponsewtCambriaAuth(target, postAuthDO.getAuthKey(),
+                    postAuthDO.getAuthDate(), postAuthDO.getData(), postAuthDO.getContentType());
+            return getResponseDataInJson(response);
+        } else {
                        throw new HttpException(
                                        "Authentication Failed: Username/password/AuthKey/AuthDate parameter(s) cannot be null or empty.");
                }
index c5eb3ba..4d9ab8d 100644 (file)
@@ -352,22 +352,24 @@ public class MRSimplerBatchPublisher extends MRBaseClient implements MRBatchingP
                                return true;
                        }
 
-                       if (ProtocolTypeConstants.AUTH_KEY.getValue().equalsIgnoreCase(protocolFlag)) {
-                               getLog().info("sending " + fPending.size() + " msgs to " + httpurl + ". Oldest: "
-                                               + (nowMs - fPending.peek().timestamp) + " ms");
-                               final JSONObject result = postAuth(httpurl, baseStream.toByteArray(), contentType, authKey, authDate,
-                                               username, password, protocolFlag);
-                               // Here we are checking for error response. If HTTP status
-                               // code is not within the http success response code
-                               // then we consider this as error and return false
-                               if (result.getInt("status") < 200 || result.getInt("status") > 299) {
-                                       return false;
-                               }
-                               final String logLine = "MR reply ok (" + (Clock.now() - startMs) + " ms):" + result.toString();
-                               getLog().info(logLine);
-                               fPending.clear();
-                               return true;
-                       }
+            if (ProtocolTypeConstants.AUTH_KEY.getValue().equalsIgnoreCase(protocolFlag)) {
+                getLog().info("sending " + fPending.size() + " msgs to " + httpurl + ". Oldest: "
+                        + (nowMs - fPending.peek().timestamp) + " ms");
+                final JSONObject result =
+                        postAuth(new PostAuthDataObject().setPath(httpurl).setData(baseStream.toByteArray())
+                                .setContentType(contentType).setAuthKey(authKey).setAuthDate(authDate)
+                                .setUsername(username).setPassword(password).setProtocolFlag(protocolFlag));
+                // Here we are checking for error response. If HTTP status
+                // code is not within the http success response code
+                // then we consider this as error and return false
+                if (result.getInt("status") < 200 || result.getInt("status") > 299) {
+                    return false;
+                }
+                final String logLine = "MR reply ok (" + (Clock.now() - startMs) + " ms):" + result.toString();
+                getLog().info(logLine);
+                fPending.clear();
+                return true;
+            }
 
                        if (ProtocolTypeConstants.AAF_AUTH.getValue().equalsIgnoreCase(protocolFlag)) {
                                getLog().info("sending " + fPending.size() + " msgs to " + httpurl + ". Oldest: "
diff --git a/src/main/java/org/onap/dmaap/mr/client/impl/PostAuthDataObject.java b/src/main/java/org/onap/dmaap/mr/client/impl/PostAuthDataObject.java
new file mode 100644 (file)
index 0000000..9fa3a5f
--- /dev/null
@@ -0,0 +1,105 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Samsung Electronics Co., Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.dmaap.mr.client.impl;
+
+public class PostAuthDataObject {
+
+    private String path;
+    private byte[] data;
+    private String contentType;
+    private String authKey;
+    private String authDate;
+    private String username;
+    private String password;
+    private String protocolFlag;
+
+    public String getPath() {
+        return path;
+    }
+
+    public PostAuthDataObject setPath(String path) {
+        this.path = path;
+        return this;
+    }
+
+    public byte[] getData() {
+        return data;
+    }
+
+    public PostAuthDataObject setData(byte[] data) {
+        this.data = data;
+        return this;
+    }
+
+    public String getContentType() {
+        return contentType;
+    }
+
+    public PostAuthDataObject setContentType(String contentType) {
+        this.contentType = contentType;
+        return this;
+    }
+
+    public String getAuthKey() {
+        return authKey;
+    }
+
+    public PostAuthDataObject setAuthKey(String authKey) {
+        this.authKey = authKey;
+        return this;
+    }
+
+    public String getAuthDate() {
+        return authDate;
+    }
+
+    public PostAuthDataObject setAuthDate(String authDate) {
+        this.authDate = authDate;
+        return this;
+    }
+
+    public String getUsername() {
+        return username;
+    }
+
+    public PostAuthDataObject setUsername(String username) {
+        this.username = username;
+        return this;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    public PostAuthDataObject setPassword(String password) {
+        this.password = password;
+        return this;
+    }
+
+    public String getProtocolFlag() {
+        return protocolFlag;
+    }
+
+    public PostAuthDataObject setProtocolFlag(String protocolFlag) {
+        this.protocolFlag = protocolFlag;
+        return this;
+    }
+}
index 6279d82..38c7f8a 100644 (file)
@@ -251,8 +251,14 @@ public class MRBaseClientTest {
                                                "password", new String("{\"test\":\"test\"}").getBytes(), "application/json"))
                                .thenReturn(response);
 
-               mrBaseClient.postAuth("/path", new String("{\"test\":\"test\"}").getBytes(), "application/json", "username",
-                               "password", "username", "password", "HTTPAUTH");
+                 mrBaseClient.postAuth(new PostAuthDataObject().setPath("/path")
+                         .setData( new String("{\"test\":\"test\"}").getBytes())
+                         .setContentType("application/json")
+                         .setAuthKey("username")
+                     .setAuthDate("password")
+                     .setUsername("username") 
+                     .setPassword("password")
+                     .setProtocolFlag("HTTPAUTH"));
                assertTrue(true);
 
        }
@@ -266,9 +272,16 @@ public class MRBaseClientTest {
                                                "password", new String("{\"test\":\"test\"}").getBytes(), "application/json"))
                                .thenReturn(
                                                responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
-
-               mrBaseClient.postAuth("/path", new String("{\"test\":\"test\"}").getBytes(), "application/json", null, null,
-                               null, null, "HTTPAUTH");
+               
+               mrBaseClient.postAuth(new PostAuthDataObject().setPath("/path")
+                .setData( new String("{\"test\":\"test\"}").getBytes())
+                .setContentType("application/json")
+                .setAuthKey(null)
+                .setAuthDate(null)
+                .setUsername(null) 
+                .setPassword(null)
+                .setProtocolFlag("HTTPAUTH"));
+               
                assertTrue(true);
 
        }