From d897c0fba26ce6eeba41dbfc93e2da93f6125bd8 Mon Sep 17 00:00:00 2001 From: Bharat saraswal Date: Fri, 22 Sep 2017 19:58:54 +0530 Subject: Resolved below sonar issues. removed redundant code. changed nested if condition to switch case. added method for resuablity of string builder. rename variable to follow camelCase. removed tab char and changed them with spaces. Issue-ID:SO-98 Change-Id: If4cf02dede7903ed8b35e4e6879b8691d4f3c48d Signed-off-by: Bharat saraswal --- .../openstack/keystone/utils/KeystoneUtils.java | 52 +++++++++++++--------- 1 file changed, 32 insertions(+), 20 deletions(-) (limited to 'keystone-client/src/main/java/com/woorea/openstack/keystone/utils/KeystoneUtils.java') diff --git a/keystone-client/src/main/java/com/woorea/openstack/keystone/utils/KeystoneUtils.java b/keystone-client/src/main/java/com/woorea/openstack/keystone/utils/KeystoneUtils.java index 8269597..b41c092 100644 --- a/keystone-client/src/main/java/com/woorea/openstack/keystone/utils/KeystoneUtils.java +++ b/keystone-client/src/main/java/com/woorea/openstack/keystone/utils/KeystoneUtils.java @@ -1,28 +1,40 @@ package com.woorea.openstack.keystone.utils; -import java.util.List; - import com.woorea.openstack.keystone.model.Access.Service; +import java.util.List; public class KeystoneUtils { - public static String findEndpointURL(List serviceCatalog, String type, String region, String facing) { - for(Service service : serviceCatalog) { - if(type.equals(service.getType())) { - for(Service.Endpoint endpoint : service.getEndpoints()) { - if(region == null || region.equals(endpoint.getRegion())) { - if(endpoint.getPublicURL() != null && facing.equals("public")) { - return endpoint.getPublicURL(); - } else if(endpoint.getInternalURL() != null && facing.equals("internal")) { - return endpoint.getInternalURL(); - } else if(endpoint.getAdminURL() != null && facing.equals("admin")) { - return endpoint.getAdminURL(); - } - } - } - } - } - throw new RuntimeException("endpoint url not found"); - } + private KeystoneUtils() { + } + + public static String findEndpointURL(List serviceCatalog, String type, String region, String facing) { + for (Service service : serviceCatalog) { + if (type.equals(service.getType())) { + for (Service.Endpoint endpoint : service.getEndpoints()) { + String url = handleServiceEndPoints(endpoint, region, facing); + if (url != null) { + return url; + } + } + } + } + throw new RuntimeException("endpoint url not found"); + } + private static String handleServiceEndPoints(Service.Endpoint endpoint, String region, String facing) { + if (region == null || region.equals(endpoint.getRegion())) { + switch (facing) { + case "public": + return endpoint.getPublicURL(); + case "internal": + return endpoint.getInternalURL(); + case "admin": + return endpoint.getAdminURL(); + default: + return null; + } + } + return null; + } } -- cgit 1.2.3-korg