diff options
author | Jim Hahn <jrh3@att.com> | 2021-05-06 09:52:08 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2021-05-06 09:55:29 -0400 |
commit | f0e4980a5ab90b5256bc7330a1b0448c54dcd475 (patch) | |
tree | 349e5fda92592065d9afd34d75eb2adc145ab927 /main | |
parent | b64fcd93b2a5c11ffac61c9a09d52f1de18c05ff (diff) |
Fix sonars in policy-api
Fixed sonars:
- use "var" instead of actual type name
Issue-ID: POLICY-3285
Change-Id: I349e57f7abe84138f5aa3478e22652a593b59845
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'main')
8 files changed, 38 insertions, 39 deletions
diff --git a/main/src/main/java/org/onap/policy/api/main/parameters/ApiParameterHandler.java b/main/src/main/java/org/onap/policy/api/main/parameters/ApiParameterHandler.java index 813dd75e..019a0125 100644 --- a/main/src/main/java/org/onap/policy/api/main/parameters/ApiParameterHandler.java +++ b/main/src/main/java/org/onap/policy/api/main/parameters/ApiParameterHandler.java @@ -23,7 +23,6 @@ package org.onap.policy.api.main.parameters; -import com.google.gson.Gson; import com.google.gson.GsonBuilder; import java.io.FileReader; import org.onap.policy.api.main.exception.PolicyApiException; @@ -53,7 +52,7 @@ public class ApiParameterHandler { // Read the parameters try { // Read the parameters from JSON using Gson - final Gson gson = new GsonBuilder().create(); + final var gson = new GsonBuilder().create(); apiParameterGroup = gson.fromJson(new FileReader(arguments.getFullConfigurationFilePath()), ApiParameterGroup.class); } catch (final Exception e) { diff --git a/main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java b/main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java index e23604b0..5e845089 100644 --- a/main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java +++ b/main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java @@ -3,7 +3,7 @@ * ONAP Policy API
* ================================================================================
* Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2020 Nordix Foundation.
* Modifications Copyright (C) 2020 Bell Canada.
* ================================================================================
@@ -237,7 +237,7 @@ public class ApiRestController extends CommonRestController { public Response
getAllPolicyTypes(@HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
- try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
+ try (var policyTypeProvider = new PolicyTypeProvider()) {
ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchPolicyTypes(null, null);
updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.GET);
return makeOkResponse(requestId, serviceTemplate);
@@ -285,7 +285,7 @@ public class ApiRestController extends CommonRestController { @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
@HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
- try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
+ try (var policyTypeProvider = new PolicyTypeProvider()) {
ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchPolicyTypes(policyTypeId, null);
updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.GET);
return makeOkResponse(requestId, serviceTemplate);
@@ -334,7 +334,7 @@ public class ApiRestController extends CommonRestController { @PathParam("versionId") @ApiParam(value = "Version of policy type", required = true) String versionId,
@HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
- try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
+ try (var policyTypeProvider = new PolicyTypeProvider()) {
ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchPolicyTypes(policyTypeId, versionId);
updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.GET);
return makeOkResponse(requestId, serviceTemplate);
@@ -381,7 +381,7 @@ public class ApiRestController extends CommonRestController { @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,
@HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
- try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
+ try (var policyTypeProvider = new PolicyTypeProvider()) {
ToscaServiceTemplate serviceTemplate = policyTypeProvider.fetchLatestPolicyTypes(policyTypeId);
updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.GET);
return makeOkResponse(requestId, serviceTemplate);
@@ -433,7 +433,7 @@ public class ApiRestController extends CommonRestController { NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, "/policytypes", toJson(body));
}
- try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
+ try (var policyTypeProvider = new PolicyTypeProvider()) {
ToscaServiceTemplate serviceTemplate = policyTypeProvider.createPolicyType(body);
updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.POST);
return makeOkResponse(requestId, serviceTemplate);
@@ -486,7 +486,7 @@ public class ApiRestController extends CommonRestController { @PathParam("versionId") @ApiParam(value = "Version of policy type", required = true) String versionId,
@HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
- try (PolicyTypeProvider policyTypeProvider = new PolicyTypeProvider()) {
+ try (var policyTypeProvider = new PolicyTypeProvider()) {
ToscaServiceTemplate serviceTemplate = policyTypeProvider.deletePolicyType(policyTypeId, versionId);
updateApiStatisticsCounter(Target.POLICY_TYPE, Result.SUCCESS, HttpMethod.DELETE);
return makeOkResponse(requestId, serviceTemplate);
@@ -545,7 +545,7 @@ public class ApiRestController extends CommonRestController { + " REFERENCED for fully referenced policies") PolicyFetchMode mode
) {
- try (PolicyProvider policyProvider = new PolicyProvider()) {
+ try (var policyProvider = new PolicyProvider()) {
ToscaServiceTemplate serviceTemplate =
policyProvider.fetchPolicies(policyTypeId, policyTypeVersion, null, null, mode);
updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);
@@ -604,7 +604,7 @@ public class ApiRestController extends CommonRestController { @QueryParam("mode") @DefaultValue("bare") @ApiParam("Fetch mode for policies, BARE for bare policies (default),"
+ " REFERENCED for fully referenced policies") PolicyFetchMode mode
) {
- try (PolicyProvider policyProvider = new PolicyProvider()) {
+ try (var policyProvider = new PolicyProvider()) {
ToscaServiceTemplate serviceTemplate =
policyProvider.fetchPolicies(policyTypeId, policyTypeVersion, policyId, null, mode);
updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);
@@ -666,7 +666,7 @@ public class ApiRestController extends CommonRestController { @QueryParam("mode") @DefaultValue("bare") @ApiParam("Fetch mode for policies, BARE for bare policies (default),"
+ " REFERENCED for fully referenced policies") PolicyFetchMode mode
) {
- try (PolicyProvider policyProvider = new PolicyProvider()) {
+ try (var policyProvider = new PolicyProvider()) {
ToscaServiceTemplate serviceTemplate =
policyProvider.fetchPolicies(policyTypeId, policyTypeVersion, policyId, policyVersion, mode);
updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);
@@ -722,7 +722,7 @@ public class ApiRestController extends CommonRestController { @QueryParam("mode") @ApiParam("Fetch mode for policies, TERSE for bare policies (default), "
+ "REFERENCED for fully referenced policies") PolicyFetchMode mode) {
- try (PolicyProvider policyProvider = new PolicyProvider()) {
+ try (var policyProvider = new PolicyProvider()) {
ToscaServiceTemplate serviceTemplate =
policyProvider.fetchLatestPolicies(policyTypeId, policyTypeVersion, policyId, mode);
updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);
@@ -784,7 +784,7 @@ public class ApiRestController extends CommonRestController { "/policytypes/" + policyTypeId + "/versions/" + policyTypeVersion + "/policies", toJson(body));
}
- try (PolicyProvider policyProvider = new PolicyProvider()) {
+ try (var policyProvider = new PolicyProvider()) {
ToscaServiceTemplate serviceTemplate = policyProvider.createPolicy(policyTypeId, policyTypeVersion, body);
updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.POST);
return makeOkResponse(requestId, serviceTemplate);
@@ -840,7 +840,7 @@ public class ApiRestController extends CommonRestController { @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
@HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
- try (PolicyProvider policyProvider = new PolicyProvider()) {
+ try (var policyProvider = new PolicyProvider()) {
ToscaServiceTemplate serviceTemplate =
policyProvider.deletePolicy(policyTypeId, policyTypeVersion, policyId, policyVersion);
updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.DELETE);
@@ -893,7 +893,7 @@ public class ApiRestController extends CommonRestController { @QueryParam("mode") @DefaultValue("bare") @ApiParam("Fetch mode for policies, BARE for bare policies (default),"
+ " REFERENCED for fully referenced policies") PolicyFetchMode mode
) {
- try (PolicyProvider policyProvider = new PolicyProvider()) {
+ try (var policyProvider = new PolicyProvider()) {
ToscaServiceTemplate serviceTemplate =
policyProvider.fetchPolicies(null, null, null, null, mode);
updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);
@@ -954,7 +954,7 @@ public class ApiRestController extends CommonRestController { @QueryParam("mode") @DefaultValue("bare") @ApiParam("Fetch mode for policies, BARE for bare policies (default),"
+ " REFERENCED for fully referenced policies") PolicyFetchMode mode
) {
- try (PolicyProvider policyProvider = new PolicyProvider()) {
+ try (var policyProvider = new PolicyProvider()) {
ToscaServiceTemplate serviceTemplate =
policyProvider.fetchPolicies(null, null, policyId, policyVersion, mode);
updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);
@@ -1009,7 +1009,7 @@ public class ApiRestController extends CommonRestController { NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, "/policies", toJson(body));
}
- try (PolicyProvider policyProvider = new PolicyProvider()) {
+ try (var policyProvider = new PolicyProvider()) {
ToscaServiceTemplate serviceTemplate = policyProvider.createPolicies(body);
updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.POST);
return makeOkResponse(requestId, serviceTemplate);
@@ -1060,7 +1060,7 @@ public class ApiRestController extends CommonRestController { @PathParam("policyVersion") @ApiParam(value = "Version of policy", required = true) String policyVersion,
@HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
- try (PolicyProvider policyProvider = new PolicyProvider()) {
+ try (var policyProvider = new PolicyProvider()) {
ToscaServiceTemplate serviceTemplate =
policyProvider.deletePolicy(null, null, policyId, policyVersion);
updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.DELETE);
@@ -1199,4 +1199,4 @@ public class ApiRestController extends CommonRestController { }
}
}
-}
\ No newline at end of file +}
diff --git a/main/src/main/java/org/onap/policy/api/main/rest/PolicyFetchMode.java b/main/src/main/java/org/onap/policy/api/main/rest/PolicyFetchMode.java index 99678b84..7e201b63 100644 --- a/main/src/main/java/org/onap/policy/api/main/rest/PolicyFetchMode.java +++ b/main/src/main/java/org/onap/policy/api/main/rest/PolicyFetchMode.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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,7 +32,6 @@ public enum PolicyFetchMode { * @return the enum value of the string */ public static PolicyFetchMode fromString(final String modeString) { - String modeStringUpper = modeString.toUpperCase(); - return valueOf(modeStringUpper); + return valueOf(modeString.toUpperCase()); } } diff --git a/main/src/main/java/org/onap/policy/api/main/rest/provider/CommonModelProvider.java b/main/src/main/java/org/onap/policy/api/main/rest/provider/CommonModelProvider.java index cb20c04c..b0825ea0 100644 --- a/main/src/main/java/org/onap/policy/api/main/rest/provider/CommonModelProvider.java +++ b/main/src/main/java/org/onap/policy/api/main/rest/provider/CommonModelProvider.java @@ -2,7 +2,7 @@ * ============LICENSE_START=======================================================
* ONAP Policy API
* ================================================================================
- * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019-2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -132,7 +132,7 @@ public class CommonModelProvider implements AutoCloseable { List<ToscaConceptIdentifier> policyTypes = new ArrayList<>();
policyTypes.add(new ToscaConceptIdentifier(policyType.getName(), policyType.getVersion()));
- PdpGroupFilter pdpGroupFilter = PdpGroupFilter.builder().policyTypeList(policyTypes).groupState(PdpState.ACTIVE)
+ var pdpGroupFilter = PdpGroupFilter.builder().policyTypeList(policyTypes).groupState(PdpState.ACTIVE)
.pdpState(PdpState.ACTIVE).build();
return modelsProvider.getFilteredPdpGroups(pdpGroupFilter);
}
@@ -158,7 +158,7 @@ public class CommonModelProvider implements AutoCloseable { Map<Pair<String, String>, T> deployedPolicyMap = new HashMap<>();
for (PdpGroup pdpGroup : pdpGroups) {
List<ToscaConceptIdentifier> policyIdentifiers = extractPolicyIdentifiers(policyId, pdpGroup, policyType);
- T deployedPolicies = getDeployedPolicies(policyIdentifiers, policyType, getter, consumer, data);
+ var deployedPolicies = getDeployedPolicies(policyIdentifiers, policyType, getter, consumer, data);
deployedPolicyMap.put(Pair.of(pdpGroup.getName(), pdpGroup.getVersion()), deployedPolicies);
}
return deployedPolicyMap;
@@ -210,7 +210,7 @@ public class CommonModelProvider implements AutoCloseable { BiFunctionWithEx<String, String, R> getter, BiConsumer<T, R> consumer, T data) throws PfModelException {
for (ToscaConceptIdentifier policyIdentifier : policyIdentifiers) {
- R result = getter.apply(policyIdentifier.getName(),
+ var result = getter.apply(policyIdentifier.getName(),
getTrimedVersionForLegacyType(policyIdentifier.getVersion(), policyType));
consumer.accept(data, result);
}
diff --git a/main/src/main/java/org/onap/policy/api/main/rest/provider/HealthCheckProvider.java b/main/src/main/java/org/onap/policy/api/main/rest/provider/HealthCheckProvider.java index a8edaa12..f4019d9a 100644 --- a/main/src/main/java/org/onap/policy/api/main/rest/provider/HealthCheckProvider.java +++ b/main/src/main/java/org/onap/policy/api/main/rest/provider/HealthCheckProvider.java @@ -3,7 +3,7 @@ * ONAP Policy API * ================================================================================ * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved. - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -45,7 +45,7 @@ public class HealthCheckProvider { * @return Report containing health check status */ public HealthCheckReport performHealthCheck() { - final HealthCheckReport report = new HealthCheckReport(); + final var report = new HealthCheckReport(); report.setName(NAME); report.setUrl(URL); report.setHealthy(ApiActivator.isAlive()); diff --git a/main/src/main/java/org/onap/policy/api/main/rest/provider/StatisticsProvider.java b/main/src/main/java/org/onap/policy/api/main/rest/provider/StatisticsProvider.java index 3a842227..dadc630e 100644 --- a/main/src/main/java/org/onap/policy/api/main/rest/provider/StatisticsProvider.java +++ b/main/src/main/java/org/onap/policy/api/main/rest/provider/StatisticsProvider.java @@ -3,7 +3,7 @@ * ============LICENSE_START======================================================= * ONAP Policy API * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019, 2021 AT&T Intellectual Property. 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,7 +40,7 @@ public class StatisticsProvider { * @return Report containing API statistics */ public StatisticsReport fetchCurrentStatistics() { - final StatisticsReport report = new StatisticsReport(); + final var report = new StatisticsReport(); report.setCode(ApiActivator.isAlive() ? 200 : 500); report.setTotalApiCallCount(ApiStatisticsManager.getTotalApiCallCount()); report.setApiCallSuccessCount(ApiStatisticsManager.getApiCallSuccessCount()); diff --git a/main/src/main/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializer.java b/main/src/main/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializer.java index d30b0120..76ffd9ff 100644 --- a/main/src/main/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializer.java +++ b/main/src/main/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializer.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP Policy API * ================================================================================ - * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019-2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -69,7 +69,7 @@ public class ApiDatabaseInitializer { */ public void initializeApiDatabase(final ApiParameterGroup apiParameterGroup) throws PolicyApiException { - try (PolicyModelsProvider databaseProvider = + try (var databaseProvider = factory.createPolicyModelsProvider(apiParameterGroup.getDatabaseProviderParameters())) { if (alreadyExists(databaseProvider)) { @@ -77,7 +77,7 @@ public class ApiDatabaseInitializer { return; } - ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate(); + var serviceTemplate = new ToscaServiceTemplate(); serviceTemplate.setDataTypes(new LinkedHashMap<>()); serviceTemplate.setPolicyTypes(new LinkedHashMap<>()); serviceTemplate.setToscaDefinitionsVersion("tosca_simple_yaml_1_1_0"); @@ -111,7 +111,7 @@ public class ApiDatabaseInitializer { throws PolicyApiException, CoderException, PfModelException { for (String entity : entities) { - String entityAsStringYaml = ResourceUtils.getResourceAsString(entity); + var entityAsStringYaml = ResourceUtils.getResourceAsString(entity); if (entityAsStringYaml == null) { LOGGER.warn("Preloading entity cannot be found: {}", entity); continue; @@ -131,7 +131,7 @@ public class ApiDatabaseInitializer { } // Consolidate policies - ToscaTopologyTemplate topologyTemplate = singleEntity.getToscaTopologyTemplate(); + var topologyTemplate = singleEntity.getToscaTopologyTemplate(); if (topologyTemplate != null && topologyTemplate.getPolicies() != null) { serviceTemplate.setToscaTopologyTemplate(new ToscaTopologyTemplate()); serviceTemplate.getToscaTopologyTemplate().setPolicies(new LinkedList<>()); diff --git a/main/src/main/java/org/onap/policy/api/main/startstop/Main.java b/main/src/main/java/org/onap/policy/api/main/startstop/Main.java index 36734f30..76de0173 100644 --- a/main/src/main/java/org/onap/policy/api/main/startstop/Main.java +++ b/main/src/main/java/org/onap/policy/api/main/startstop/Main.java @@ -3,7 +3,7 @@ * ONAP Policy API * ================================================================================ * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved. - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2020 Bell Canada. All rights reserved. * Modifications Copyright (C) 2021 Nordix Foundation. * ================================================================================ @@ -55,11 +55,11 @@ public class Main { * @param args the command line arguments */ public Main(final String[] args) { - final String argumentString = Arrays.toString(args); + final var argumentString = Arrays.toString(args); LOGGER.info("Starting policy api service with arguments - {}", argumentString); // Check the arguments - final ApiCommandLineArguments arguments = new ApiCommandLineArguments(); + final var arguments = new ApiCommandLineArguments(); try { // The arguments return a string if there is a message to print and we should exit final String argumentMessage = arguments.parse(args); @@ -88,7 +88,7 @@ public class Main { // Add a shutdown hook to shut everything down in an orderly manner Runtime.getRuntime().addShutdownHook(new PolicyApiShutdownHookClass()); - String successMsg = String.format(MessageConstants.START_SUCCESS_MSG, MessageConstants.POLICY_API); + var successMsg = String.format(MessageConstants.START_SUCCESS_MSG, MessageConstants.POLICY_API); LOGGER.info(successMsg); } |