Fix sonar issues
[portal.git] / ecomp-portal-BE-common / src / main / java / org / onap / portalapp / portal / controller / WebAnalyticsExtAppController.java
index f1192f9..41273ec 100644 (file)
@@ -55,7 +55,7 @@ import org.onap.portalapp.portal.logging.aop.EPAuditLog;
 import org.onap.portalapp.portal.logging.aop.EPEELFLoggerAdvice;
 import org.onap.portalapp.portal.logging.logic.EPLogUtil;
 import org.onap.portalapp.portal.service.AppsCacheService;
-import org.onap.portalapp.portal.service.ConsulHealthService;
+import org.onap.portalapp.portal.service.WidgetMService;
 import org.onap.portalapp.portal.transport.Analytics;
 import org.onap.portalapp.portal.utils.EPCommonSystemProperties;
 import org.onap.portalapp.portal.utils.EcompPortalUtils;
@@ -89,22 +89,24 @@ import org.springframework.web.client.AsyncRestTemplate;
 @EPAuditLog
 @NoArgsConstructor
 public class WebAnalyticsExtAppController extends EPRestrictedRESTfulBaseController {
-       private ConsulHealthService consulHealthService;
+       private WidgetMService widgetMService;
        private AppsCacheService appCacheService;
 
        private static final String MACHINE_LEARNING_SERVICE_CTX = "/ml_api";
        private static final String REGISTER_ACTION = MACHINE_LEARNING_SERVICE_CTX + "/" + "registerAction";
        private static final String CONSUL_ML_SERVICE_ID = "machine-learning";
        private static final String APP_KEY = "uebkey";
+       private static final String ERROR_MSG = " Error retrieving Application to capture app name for analytics; Proceeding with empty app name";
        private final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(WebAnalyticsExtAppController.class);
        private final AsyncRestTemplate restTemplate = new AsyncRestTemplate();
        private final SuccessCallback<ResponseEntity<String>> successCallback = arg -> logger.info(EELFLoggerDelegate.debugLogger, arg.getBody());
        private final FailureCallback failureCallback = arg -> logger.error(EELFLoggerDelegate.errorLogger, "storeAuxAnalytics failed", arg);
 
+
        @Autowired
-       public WebAnalyticsExtAppController(AppsCacheService appCacheService, ConsulHealthService consulHealthService) {
+       public WebAnalyticsExtAppController(AppsCacheService appCacheService, WidgetMService consulHealthService) {
                this.appCacheService = appCacheService;
-               this.consulHealthService = consulHealthService;
+               this.widgetMService = consulHealthService;
        }
 
        /**
@@ -124,13 +126,13 @@ public class WebAnalyticsExtAppController extends EPRestrictedRESTfulBaseControl
                try {
                        app = getApp(request);
                } catch (Exception e) {
-                       logger.error(EELFLoggerDelegate.errorLogger,
-                                       " Error retrieving Application to capture app name for analytics; Proceeding with empty app name");
+            logger.error(EELFLoggerDelegate.errorLogger,
+                    ERROR_MSG, e);
                }
                if (app != null) {
                        String restEndPoint = app.getAppRestEndpoint();
-                       if(restEndPoint.contains("/api")) {
-                               version = restEndPoint.substring(restEndPoint.indexOf("/api")+4);
+                       if(restEndPoint.indexOf("/api")!=-1) {
+                               version = restEndPoint.substring(restEndPoint.indexOf("api"));
                        }
                }
                String endPoint = "/storeAnalytics";
@@ -168,19 +170,19 @@ public class WebAnalyticsExtAppController extends EPRestrictedRESTfulBaseControl
                try {
                        MDC.put(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP, EPEELFLoggerAdvice.getCurrentDateTimeUTC());
                        String appName = "";
-                       try {
-                               appName = getAppName(request, appName);
-                       } catch (Exception e) {
-                               logger.error(EELFLoggerDelegate.errorLogger,
-                                               " Error retrieving Application to capture app name for analytics; Proceeding with empty app name");
-                       }
-
-                       try {
-                               storeAuxAnalytics(analyticsMap, appName);
-                       } catch (Exception e) {
-                               logger.error(EELFLoggerDelegate.errorLogger,
-                                               " Error retrieving Application to capture app name for analytics; Proceeding with empty app name");
-                       }
+            try {
+                appName = getAppName(request, appName);
+            } catch (Exception e) {
+                logger.error(EELFLoggerDelegate.errorLogger,
+                        ERROR_MSG, e);
+            }
+
+            try {
+                storeAuxAnalytics(analyticsMap, appName);
+            } catch (Exception e) {
+                logger.error(EELFLoggerDelegate.errorLogger,
+                        ERROR_MSG, e);
+            }
 
                        MDC.put(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP, EPEELFLoggerAdvice.getCurrentDateTimeUTC());
 
@@ -216,7 +218,7 @@ public class WebAnalyticsExtAppController extends EPRestrictedRESTfulBaseControl
        private EPApp getApp(HttpServletRequest request) {
                String appKeyValue = request.getHeader(APP_KEY);
                EPApp appRecord = null;
-               if (appKeyValue == null || appKeyValue.equals("")) {
+               if (appKeyValue == null || "".equals(appKeyValue)) {
                        logger.error(EELFLoggerDelegate.errorLogger, " App Key unavailable; Proceeding with null app name");
                } else {
                         appRecord = appCacheService.getAppFromUeb(appKeyValue);
@@ -242,7 +244,7 @@ public class WebAnalyticsExtAppController extends EPRestrictedRESTfulBaseControl
                // send it!
                ListenableFuture<ResponseEntity<String>> out = restTemplate.exchange(
                                EcompPortalUtils.widgetMsProtocol() + "://"
-                                               + consulHealthService.getServiceLocation(CONSUL_ML_SERVICE_ID,
+                                               + widgetMService.getServiceLocation(CONSUL_ML_SERVICE_ID,
                                                                SystemProperties.getProperty("microservices.m-learn.local.port"))
                                                + REGISTER_ACTION,
                                HttpMethod.POST, entity, String.class);