Improve tests/issues found in Sonar report - A1 Oslo/NewDelhi/Montreal/London- Part4 31/138831/2
authorraviteja.karumuri <raviteja.karumuri@est.tech>
Wed, 14 Aug 2024 10:49:49 +0000 (11:49 +0100)
committerRAVITEJA KARUMURI <raviteja.karumuri@est.tech>
Wed, 28 Aug 2024 14:46:29 +0000 (14:46 +0000)
Issue-ID: CCSDK-4037
Change-Id: I272c4bd112ac866896d36cb1c8efc9881efacf26
Signed-off-by: Raviteja Karumuri <raviteja.karumuri@est.tech>
a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/Application.java
a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientFactory.java
a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParser.java
a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationController.java
a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyController.java
a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/RicRepositoryController.java
a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ServiceController.java
a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/StatusController.java

index 6f45864..e1403b1 100644 (file)
@@ -2,7 +2,8 @@
  * ========================LICENSE_START=================================
  * ONAP : ccsdk oran
  * ======================================================================
- * Copyright (C) 2019-2020 Nordix Foundation. All rights reserved.
+ * Copyright (C) 2019-2023 Nordix Foundation. All rights reserved.
+ * Copyright (C) 2024 OpenInfra Foundation Europe. 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.
@@ -22,10 +23,10 @@ package org.onap.ccsdk.oran.a1policymanagementservice;
 
 import java.lang.invoke.MethodHandles;
 
+import lombok.RequiredArgsConstructor;
 import org.onap.ccsdk.oran.a1policymanagementservice.tasks.RefreshConfigTask;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.CommandLineRunner;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -34,10 +35,10 @@ import org.springframework.context.ConfigurableApplicationContext;
 import org.springframework.context.annotation.Bean;
 
 @SpringBootApplication
+@RequiredArgsConstructor
 public class Application {
 
-    @Autowired
-    private RefreshConfigTask configRefresh;
+    private final RefreshConfigTask configRefresh;
 
     private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
index 5f57314..9877ce5 100644 (file)
@@ -3,6 +3,7 @@
  * ONAP : ccsdk oran
  * ======================================================================
  * Copyright (C) 2020-2023 Nordix Foundation. All rights reserved.
+ * Copyright (C) 2024 OpenInfra Foundation Europe. 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.
@@ -31,9 +32,9 @@ import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.ServiceException
 import org.onap.ccsdk.oran.a1policymanagementservice.repository.Ric;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-
 import reactor.core.publisher.Mono;
 
+
 /**
  * Factory for A1 clients that supports four different protocol versions of the
  * A1 api.
@@ -42,12 +43,9 @@ public class A1ClientFactory {
 
     private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
-    private final ApplicationConfig appConfig;
-
     private final AsyncRestClientFactory restClientFactory;
 
     public A1ClientFactory(ApplicationConfig appConfig, SecurityContext securityContext) {
-        this.appConfig = appConfig;
         this.restClientFactory = new AsyncRestClientFactory(appConfig.getWebClientConfig(), securityContext);
     }
 
index 45305f8..e3036bb 100644 (file)
@@ -2,7 +2,8 @@
  * ========================LICENSE_START=================================
  * ONAP : ccsdk oran
  * ======================================================================
- * Copyright (C) 2019-2020 Nordix Foundation. All rights reserved.
+ * Copyright (C) 2019-2023 Nordix Foundation. All rights reserved.
+ * Copyright (C) 2024 OpenInfra Foundation Europe. 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.
@@ -84,7 +85,7 @@ public class ApplicationConfigParser {
         Map<String, ControllerConfig> controllerConfigs = parseControllerConfigs(pmsConfigJson);
         List<RicConfig> ricConfigs = parseRics(pmsConfigJson, controllerConfigs);
 
-        checkConfigurationConsistency(ricConfigs, controllerConfigs);
+        checkConfigurationConsistency(ricConfigs);
 
         return ConfigParserResult.builder() //
                 .ricConfigs(ricConfigs) //
@@ -123,8 +124,7 @@ public class ApplicationConfigParser {
         return CharStreams.toString(new InputStreamReader(in, StandardCharsets.UTF_8));
     }
 
-    private void checkConfigurationConsistency(List<RicConfig> ricConfigs,
-            Map<String, ControllerConfig> controllerConfigs) throws ServiceException {
+    private void checkConfigurationConsistency(List<RicConfig> ricConfigs) throws ServiceException {
         Set<String> ricUrls = new HashSet<>();
         Set<String> ricNames = new HashSet<>();
         for (RicConfig ric : ricConfigs) {
@@ -218,8 +218,4 @@ public class ApplicationConfigParser {
     private JsonArray getAsJsonArray(JsonObject obj, String memberName) throws ServiceException {
         return get(obj, memberName).getAsJsonArray();
     }
-
-    private static String getAsString(JsonObject obj, String memberName) throws ServiceException {
-        return get(obj, memberName).getAsString();
-    }
 }
index 0d0919d..2a0177f 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ========================LICENSE_START=================================
  * Copyright (C) 2020-2023 Nordix Foundation. All rights reserved.
+ * Copyright (C) 2024 OpenInfra Foundation Europe. 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.
@@ -33,13 +34,13 @@ import io.swagger.v3.oas.annotations.tags.Tag;
 import java.io.IOException;
 import java.util.Optional;
 
+import lombok.RequiredArgsConstructor;
 import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
 import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfigParser;
 import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ConfigurationFile;
 import org.onap.ccsdk.oran.a1policymanagementservice.controllers.VoidResponse;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.MediaType;
 import org.springframework.http.ResponseEntity;
@@ -48,7 +49,8 @@ import org.springframework.web.bind.annotation.PutMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RestController;
 
-@RestController("ConfigurationControllerV2")
+@RestController("configurationControllerV2")
+@RequiredArgsConstructor
 @Tag( //
         name = ConfigurationController.API_NAME, //
         description = ConfigurationController.API_DESCRIPTION //
@@ -62,12 +64,6 @@ public class ConfigurationController {
     private final ConfigurationFile configurationFile;
     private final ApplicationConfig applicationConfig;
 
-    ConfigurationController(@Autowired ConfigurationFile configurationFile,
-            @Autowired ApplicationConfig applicationConfig) {
-        this.configurationFile = configurationFile;
-        this.applicationConfig = applicationConfig;
-    }
-
     private static Gson gson = new GsonBuilder() //
             .create(); //
 
index 64905f4..6f624d0 100644 (file)
@@ -2,7 +2,8 @@
  * ========================LICENSE_START=================================
  * ONAP : ccsdk oran
  * ======================================================================
- * Copyright (C) 2019-2020 Nordix Foundation. All rights reserved.
+ * Copyright (C) 2019-2023 Nordix Foundation. All rights reserved.
+ * Copyright (C) 2024 OpenInfra Foundation Europe. 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.
@@ -40,6 +41,7 @@ import java.util.Map;
 
 import lombok.Getter;
 
+import lombok.RequiredArgsConstructor;
 import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1ClientFactory;
 import org.onap.ccsdk.oran.a1policymanagementservice.controllers.VoidResponse;
 import org.onap.ccsdk.oran.a1policymanagementservice.controllers.authorization.AuthorizationCheck;
@@ -58,7 +60,6 @@ import org.onap.ccsdk.oran.a1policymanagementservice.repository.Service;
 import org.onap.ccsdk.oran.a1policymanagementservice.repository.Services;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.MediaType;
 import org.springframework.http.ResponseEntity;
@@ -76,7 +77,8 @@ import org.springframework.web.reactive.function.client.WebClientResponseExcepti
 import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
 
-@RestController("PolicyControllerV2")
+@RestController("policyControllerV2")
+@RequiredArgsConstructor
 @Tag(//
         name = PolicyController.API_NAME, //
         description = PolicyController.API_DESCRIPTION //
@@ -98,23 +100,15 @@ public class PolicyController {
         }
     }
 
-    @Autowired
-    private Rics rics;
-    @Autowired
-    private PolicyTypes policyTypes;
-    @Autowired
-    private Policies policies;
-    @Autowired
-    private A1ClientFactory a1ClientFactory;
-    @Autowired
-    private Services services;
-
-    @Autowired
-    private AuthorizationCheck authorization;
+    private final Rics rics;
+    private final PolicyTypes policyTypes;
+    private final Policies policies;
+    private final A1ClientFactory a1ClientFactory;
+    private final Services services;
+    private final AuthorizationCheck authorization;
 
     private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-    private static Gson gson = new GsonBuilder() //
-            .create(); //
+    private static final Gson gson = new GsonBuilder().create();
 
     @GetMapping(path = Consts.V2_API_ROOT + "/policy-types/{policytype_id:.+}") //
     @Operation(summary = "Returns a policy type definition") //
@@ -268,7 +262,7 @@ public class PolicyController {
                 .lastModified(Instant.now()) //
                 .isTransient(policyInfo.isTransient) //
                 .statusNotificationUri(policyInfo.statusNotificationUri == null ? "" : policyInfo.statusNotificationUri) //
-                .build();
+                                .build();
 
         return authorization.doAccessControl(headers, policy, AccessType.WRITE) //
                 .flatMap(x -> ric.getLock().lock(LockType.SHARED, "putPolicy")) //
@@ -293,17 +287,13 @@ public class PolicyController {
     }
 
     private Mono<ResponseEntity<Object>> handleException(Throwable throwable) {
-        if (throwable instanceof WebClientResponseException) {
-            WebClientResponseException e = (WebClientResponseException) throwable;
+        if (throwable instanceof WebClientResponseException e) {
             return ErrorResponse.createMono(e.getResponseBodyAsString(), e.getStatusCode());
-        } else if (throwable instanceof WebClientException) {
-            WebClientException e = (WebClientException) throwable;
+        } else if (throwable instanceof WebClientException e) {
             return ErrorResponse.createMono(e.getMessage(), HttpStatus.BAD_GATEWAY);
-        } else if (throwable instanceof RejectionException) {
-            RejectionException e = (RejectionException) throwable;
+        } else if (throwable instanceof RejectionException e) {
             return ErrorResponse.createMono(e.getMessage(), e.getStatus());
-        } else if (throwable instanceof ServiceException) {
-            ServiceException e = (ServiceException) throwable;
+        } else if (throwable instanceof ServiceException e) {
             return ErrorResponse.createMono(e.getMessage(), e.getHttpStatus());
         } else {
             return ErrorResponse.createMono(throwable.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
@@ -479,12 +469,12 @@ public class PolicyController {
         policyInfo.isTransient = p.isTransient();
         if (!p.getStatusNotificationUri().isEmpty()) {
             policyInfo.statusNotificationUri = p.getStatusNotificationUri();
-        }
+            }
         if (!policyInfo.validate()) {
             logger.error("BUG, all mandatory fields must be set");
         }
 
-        return policyInfo;
+            return policyInfo;
     }
 
     private String policiesToJson(Collection<Policy> policies) {
@@ -516,5 +506,4 @@ public class PolicyController {
         }
         return gson.toJson(new PolicyIdList(v));
     }
-
 }
index 9e2644a..85cbb82 100644 (file)
@@ -2,7 +2,8 @@
  * ========================LICENSE_START=================================
  * ONAP : ccsdk oran
  * ======================================================================
- * Copyright (C) 2019-2020 Nordix Foundation. All rights reserved.
+ * Copyright (C) 2019-2023 Nordix Foundation. All rights reserved.
+ * Copyright (C) 2024 OpenInfra Foundation Europe. 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.
@@ -34,12 +35,13 @@ import io.swagger.v3.oas.annotations.tags.Tag;
 import java.util.ArrayList;
 import java.util.List;
 
+import lombok.RequiredArgsConstructor;
+
 import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.EntityNotFoundException;
 import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.InvalidRequestException;
 import org.onap.ccsdk.oran.a1policymanagementservice.repository.PolicyTypes;
 import org.onap.ccsdk.oran.a1policymanagementservice.repository.Ric;
 import org.onap.ccsdk.oran.a1policymanagementservice.repository.Rics;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.MediaType;
 import org.springframework.http.ResponseEntity;
@@ -47,7 +49,9 @@ import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
-@RestController("RicRepositoryControllerV2")
+
+@RestController("ricRepositoryControllerV2")
+@RequiredArgsConstructor
 @Tag( //
         name = RicRepositoryController.API_NAME, //
         description = RicRepositoryController.API_DESCRIPTION //
@@ -57,14 +61,10 @@ public class RicRepositoryController {
     public static final String API_NAME = "NearRT-RIC Repository";
     public static final String API_DESCRIPTION = "";
 
-    @Autowired
-    private Rics rics;
-
-    @Autowired
-    PolicyTypes types;
+    private final Rics rics;
+    private final PolicyTypes types;
 
-    private static Gson gson = new GsonBuilder() //
-            .create(); //
+    private static final Gson gson = new GsonBuilder().create();
 
     private static final String GET_RIC_BRIEF = "Returns info for one Near-RT RIC";
     private static final String GET_RIC_DETAILS =
index 84c8cb3..c596fa1 100644 (file)
@@ -2,7 +2,8 @@
  * ========================LICENSE_START=================================
  * ONAP : ccsdk oran
  * ======================================================================
- * Copyright (C) 2019-2020 Nordix Foundation. All rights reserved.
+ * Copyright (C) 2019-2023 Nordix Foundation. All rights reserved.
+ * Copyright (C) 2024 OpenInfra Foundation Europe. 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.
@@ -39,6 +40,8 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Map;
 
+import lombok.RequiredArgsConstructor;
+
 import org.onap.ccsdk.oran.a1policymanagementservice.controllers.VoidResponse;
 import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.ServiceException;
 import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policies;
@@ -47,7 +50,6 @@ import org.onap.ccsdk.oran.a1policymanagementservice.repository.Service;
 import org.onap.ccsdk.oran.a1policymanagementservice.repository.Services;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.MediaType;
 import org.springframework.http.ResponseEntity;
@@ -60,7 +62,8 @@ import org.springframework.web.bind.annotation.RequestHeader;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
-@RestController("ServiceControllerV2")
+@RestController("serviceControllerV2")
+@RequiredArgsConstructor
 @Tag( //
         name = ServiceController.API_NAME, //
         description = ServiceController.API_DESCRIPTION //
@@ -68,23 +71,16 @@ import org.springframework.web.bind.annotation.RestController;
 )
 public class ServiceController {
 
+    private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
     public static final String API_NAME = "Service Registry and Supervision";
     public static final String API_DESCRIPTION = "";
 
     private final Services services;
     private final Policies policies;
+    private final PolicyController policyController;
 
-    private static Gson gson = new GsonBuilder().create();
-
-    private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
-    @Autowired
-    private PolicyController policyController;
-
-    ServiceController(Services services, Policies policies) {
-        this.services = services;
-        this.policies = policies;
-    }
+    private static final Gson gson = new GsonBuilder().create();
 
     private static final String GET_SERVICE_DETAILS =
             "Either information about a registered service with given identity or all registered services are returned.";
@@ -153,14 +149,14 @@ public class ServiceController {
 
     public ResponseEntity<Object> putService(//
             @RequestBody ServiceRegistrationInfo registrationInfo) {
-        try {
+            try {
             validateRegistrationInfo(registrationInfo);
             final boolean isCreate = this.services.get(registrationInfo.serviceId) == null;
             this.services.put(toService(registrationInfo));
             return new ResponseEntity<>(isCreate ? HttpStatus.CREATED : HttpStatus.OK);
-        } catch (Exception e) {
+            } catch (Exception e) {
             return ErrorResponse.create(e, HttpStatus.BAD_REQUEST);
-        }
+            }
     }
 
     @DeleteMapping(Consts.V2_API_ROOT + "/services/{service_id:.+}")
@@ -180,7 +176,8 @@ public class ServiceController {
             removePolicies(service, headers);
             return new ResponseEntity<>(HttpStatus.NO_CONTENT);
         } catch (ServiceException e) {
-            logger.warn("Exception caught during service deletion while deleting service {}: {}", serviceId, e.getMessage());
+            logger.warn("Exception caught during service deletion while deleting service {}: {}", serviceId,
+                    e.getMessage());
             return ErrorResponse.create(e, HttpStatus.NOT_FOUND);
         }
     }
@@ -198,7 +195,7 @@ public class ServiceController {
     public ResponseEntity<Object> keepAliveService(//
             @PathVariable(Consts.SERVICE_ID_PARAM) String serviceId) {
         try {
-            services.getService(serviceId).keepAlive();
+        services.getService(serviceId).keepAlive();
             return new ResponseEntity<>(HttpStatus.OK);
         } catch (ServiceException e) {
             return ErrorResponse.create(e, HttpStatus.NOT_FOUND);
index 5773179..6217a81 100644 (file)
@@ -2,7 +2,8 @@
  * ========================LICENSE_START=================================
  * ONAP : ccsdk oran
  * ======================================================================
- * Copyright (C) 2019-2020 Nordix Foundation. All rights reserved.
+ * Copyright (C) 2019-2023 Nordix Foundation. All rights reserved.
+ * Copyright (C) 2024 OpenInfra Foundation Europe. 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.
@@ -35,7 +36,7 @@ import org.springframework.web.bind.annotation.RestController;
 
 import reactor.core.publisher.Mono;
 
-@RestController("StatusControllerV2")
+@RestController("statusControllerV2")
 @Tag( //
         name = StatusController.API_NAME, //
         description = StatusController.API_DESCRIPTION //
@@ -79,4 +80,4 @@ public class StatusController {
         return Mono.just(new ResponseEntity<>("success", HttpStatus.OK));
     }
 
-}
+}
\ No newline at end of file