From a84ef3cb2133fde745c50d7a23290505e4f4659a Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Thu, 2 Sep 2021 09:57:16 -0400 Subject: Fix eclipse warnings in clamp Fixed some of these warnings, just in policy-clamp-runtime: - equals() with wrong argument type in junit - remove unneeded "SuppressWarning" - unused fields - deprecated classes/methods Fixed some sonars, too: - use isEqualByComparingTo() - method complexity: used eclipse to auto-extract methods Fixed checkstyle issues: - indentation level Did not address all deprecation issues (e.g., SSLSocketFactory). Issue-ID: POLICY-3200 Change-Id: Ibd92e5326854002dc0ca2d7b3b777699cafb5e98 Signed-off-by: Jim Hahn --- .../clamp/clds/client/DcaeInventoryServices.java | 1 - .../clamp/clds/config/CamelConfiguration.java | 4 - .../config/sdc/SdcControllersConfiguration.java | 6 +- .../update/execution/ToscaMetadataExecutor.java | 5 - .../update/parser/ToscaConverterToJsonSchema.java | 163 +++++++++++---------- .../update/templates/JsonTemplateManager.java | 19 ++- .../org/onap/policy/clamp/loop/CsarInstaller.java | 4 - .../clamp/policy/pdpgroup/PdpGroupPayload.java | 12 +- ...caConverterWithDictionarySupportItTestCase.java | 4 - .../policy/clamp/clds/util/LoggingUtilsTest.java | 4 +- .../clamp/loop/ExternalComponentStateTest.java | 3 +- 11 files changed, 108 insertions(+), 117 deletions(-) (limited to 'runtime') diff --git a/runtime/src/main/java/org/onap/policy/clamp/clds/client/DcaeInventoryServices.java b/runtime/src/main/java/org/onap/policy/clamp/clds/client/DcaeInventoryServices.java index 524733115..387ea8c1f 100644 --- a/runtime/src/main/java/org/onap/policy/clamp/clds/client/DcaeInventoryServices.java +++ b/runtime/src/main/java/org/onap/policy/clamp/clds/client/DcaeInventoryServices.java @@ -28,7 +28,6 @@ import java.io.IOException; import java.util.Date; import org.apache.camel.CamelContext; import org.apache.camel.Exchange; -import org.apache.camel.ProducerTemplate; import org.apache.camel.builder.ExchangeBuilder; import org.json.simple.JSONArray; import org.json.simple.JSONObject; diff --git a/runtime/src/main/java/org/onap/policy/clamp/clds/config/CamelConfiguration.java b/runtime/src/main/java/org/onap/policy/clamp/clds/config/CamelConfiguration.java index 0880e9b74..b1141ea49 100644 --- a/runtime/src/main/java/org/onap/policy/clamp/clds/config/CamelConfiguration.java +++ b/runtime/src/main/java/org/onap/policy/clamp/clds/config/CamelConfiguration.java @@ -91,10 +91,6 @@ public class CamelConfiguration extends RouteBuilder { @Value("${clamp.config.keyFile:#{null}}") private String keyFile; - - @Autowired - private ClampProperties clampProperties; - private void configureDefaultSslProperties() { if (trustStore != null) { System.setProperty("javax.net.ssl.trustStore", Thread.currentThread().getContextClassLoader() diff --git a/runtime/src/main/java/org/onap/policy/clamp/clds/config/sdc/SdcControllersConfiguration.java b/runtime/src/main/java/org/onap/policy/clamp/clds/config/sdc/SdcControllersConfiguration.java index 71986f6fb..f871df70e 100644 --- a/runtime/src/main/java/org/onap/policy/clamp/clds/config/sdc/SdcControllersConfiguration.java +++ b/runtime/src/main/java/org/onap/policy/clamp/clds/config/sdc/SdcControllersConfiguration.java @@ -88,9 +88,9 @@ public class SdcControllersConfiguration { Map result = new HashMap<>(); if (jsonRootNode.get(CONTROLLER_SUBTREE_KEY) != null) { jsonRootNode.get(CONTROLLER_SUBTREE_KEY).getAsJsonObject().entrySet().forEach( - entry -> result.put(entry.getKey(), - new SdcSingleControllerConfiguration(entry.getValue().getAsJsonObject(), entry.getKey(), - keyFile))); + entry -> result.put(entry.getKey(), + new SdcSingleControllerConfiguration(entry.getValue().getAsJsonObject(), entry.getKey(), + keyFile))); } else { throw new SdcParametersException( CONTROLLER_SUBTREE_KEY + " key not found in the file: " + sdcControllerFile); diff --git a/runtime/src/main/java/org/onap/policy/clamp/clds/tosca/update/execution/ToscaMetadataExecutor.java b/runtime/src/main/java/org/onap/policy/clamp/clds/tosca/update/execution/ToscaMetadataExecutor.java index 2d193355e..4a4155446 100644 --- a/runtime/src/main/java/org/onap/policy/clamp/clds/tosca/update/execution/ToscaMetadataExecutor.java +++ b/runtime/src/main/java/org/onap/policy/clamp/clds/tosca/update/execution/ToscaMetadataExecutor.java @@ -29,10 +29,8 @@ import java.util.Map; import javax.annotation.PostConstruct; import org.onap.policy.clamp.clds.tosca.update.execution.cds.ToscaMetadataCdsProcess; import org.onap.policy.clamp.loop.service.Service; -import org.onap.policy.clamp.tosca.DictionaryService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** @@ -44,9 +42,6 @@ public class ToscaMetadataExecutor { private static final Logger logger = LoggerFactory.getLogger(ToscaMetadataExecutor.class); - @Autowired - private DictionaryService dictionaryService; - private Map mapOfProcesses = new HashMap<>(); /** diff --git a/runtime/src/main/java/org/onap/policy/clamp/clds/tosca/update/parser/ToscaConverterToJsonSchema.java b/runtime/src/main/java/org/onap/policy/clamp/clds/tosca/update/parser/ToscaConverterToJsonSchema.java index 1d5ed26e0..9fe199af2 100644 --- a/runtime/src/main/java/org/onap/policy/clamp/clds/tosca/update/parser/ToscaConverterToJsonSchema.java +++ b/runtime/src/main/java/org/onap/policy/clamp/clds/tosca/update/parser/ToscaConverterToJsonSchema.java @@ -27,7 +27,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedHashMap; +import java.util.Map; import java.util.Map.Entry; import org.onap.policy.clamp.clds.tosca.update.elements.ToscaElement; import org.onap.policy.clamp.clds.tosca.update.elements.ToscaElementProperty; @@ -59,8 +59,8 @@ public class ToscaConverterToJsonSchema { private static final String TITLE = "title"; private static final String TYPE = "type"; - private LinkedHashMap components; - private LinkedHashMap templates; + private Map components; + private Map templates; private ToscaMetadataParser metadataParser; @@ -74,8 +74,8 @@ public class ToscaConverterToJsonSchema { * @param metadataParser The metadata parser to use for metadata section * @param serviceModel The service model for clamp enrichment */ - public ToscaConverterToJsonSchema(LinkedHashMap toscaElementsMap, - LinkedHashMap jsonSchemaTemplates, ToscaMetadataParser metadataParser, + public ToscaConverterToJsonSchema(Map toscaElementsMap, + Map jsonSchemaTemplates, ToscaMetadataParser metadataParser, Service serviceModel) { this.components = toscaElementsMap; this.templates = jsonSchemaTemplates; @@ -204,43 +204,7 @@ public class ToscaConverterToJsonSchema { for (String propertyField : toscaElementProperty.getItems().keySet()) { switch (propertyField) { case TYPE: - if (currentPropertyJsonTemplate.hasFields(propertyField)) { - String fieldtype = (String) toscaElementProperty.getItems().get(propertyField); - switch (fieldtype.toLowerCase()) { - case LIST: - propertiesInJson.addProperty(TYPE, ARRAY); - break; - case MAP: - propertiesInJson.addProperty(TYPE, OBJECT); - break; - case "scalar-unit.time": - case "scalar-unit.frequency": - case "scalar-unit.size": - propertiesInJson.addProperty(TYPE, "string"); - break; - case "timestamp": - propertiesInJson.addProperty(TYPE, "string"); - propertiesInJson.addProperty(FORMAT, "date-time"); - break; - case "float": - propertiesInJson.addProperty(TYPE, "number"); - break; - case "range": - propertiesInJson.addProperty(TYPE, "integer"); - if (!checkConstraintPresence(toscaElementProperty, "greater_than") - && currentPropertyJsonTemplate.hasFields("exclusiveMinimum")) { - propertiesInJson.addProperty("exclusiveMinimum", false); - } - if (!checkConstraintPresence(toscaElementProperty, "less_than") - && currentPropertyJsonTemplate.hasFields("exclusiveMaximum")) { - propertiesInJson.addProperty("exclusiveMaximum", false); - } - break; - default: - propertiesInJson.addProperty(TYPE, currentPropertyJsonTemplate.getName()); - break; - } - } + parseType(toscaElementProperty, propertyField, propertiesInJson, currentPropertyJsonTemplate); break; case METADATA: if (metadataParser != null) { @@ -254,37 +218,7 @@ public class ToscaConverterToJsonSchema { currentPropertyJsonTemplate); break; case ENTRY_SCHEMA: - // Here, a way to check if entry is a component (datatype) or a simple string - if (getToscaElement(this.extractSpecificFieldFromMap(toscaElementProperty, ENTRY_SCHEMA)) != null) { - String nameComponent = this.extractSpecificFieldFromMap(toscaElementProperty, ENTRY_SCHEMA); - var child = new ToscaConverterToJsonSchema(components, templates, metadataParser, serviceModel); - var propertiesContainer = new JsonObject(); - - if (((String) toscaElementProperty.getItems().get(TYPE)).equals(MAP)) { - JsonObject componentAsProperty = child.getJsonSchemaOfToscaElement(nameComponent); - propertiesContainer.add(nameComponent, componentAsProperty); - if (currentPropertyJsonTemplate.hasFields(PROPERTIES)) { - propertiesInJson.add(PROPERTIES, propertiesContainer); - } - } else { - JsonObject componentAsItem = child.getJsonSchemaOfToscaElement(nameComponent); - if (currentPropertyJsonTemplate.hasFields(PROPERTIES)) { - propertiesInJson.add("items", componentAsItem); - propertiesInJson.addProperty(FORMAT, "tabs-top"); - } - } - } else if (toscaElementProperty.getItems().get(TYPE).equals(LIST)) { - // Native cases - var itemContainer = new JsonObject(); - String valueInEntrySchema = - this.extractSpecificFieldFromMap(toscaElementProperty, ENTRY_SCHEMA); - itemContainer.addProperty(TYPE, valueInEntrySchema); - propertiesInJson.add("items", itemContainer); - propertiesInJson.addProperty(FORMAT, "tabs-top"); - } - - // MAP Case, for now nothing - + parseEntrySchema(toscaElementProperty, propertiesInJson, currentPropertyJsonTemplate); break; default: // Each classical field : type, description, default.. @@ -298,6 +232,81 @@ public class ToscaConverterToJsonSchema { return propertiesInJson; } + private void parseType(ToscaElementProperty toscaElementProperty, String propertyField, JsonObject propertiesInJson, + JsonTemplate currentPropertyJsonTemplate) { + if (currentPropertyJsonTemplate.hasFields(propertyField)) { + String fieldtype = (String) toscaElementProperty.getItems().get(propertyField); + switch (fieldtype.toLowerCase()) { + case LIST: + propertiesInJson.addProperty(TYPE, ARRAY); + break; + case MAP: + propertiesInJson.addProperty(TYPE, OBJECT); + break; + case "scalar-unit.time": + case "scalar-unit.frequency": + case "scalar-unit.size": + propertiesInJson.addProperty(TYPE, "string"); + break; + case "timestamp": + propertiesInJson.addProperty(TYPE, "string"); + propertiesInJson.addProperty(FORMAT, "date-time"); + break; + case "float": + propertiesInJson.addProperty(TYPE, "number"); + break; + case "range": + propertiesInJson.addProperty(TYPE, "integer"); + if (!checkConstraintPresence(toscaElementProperty, "greater_than") + && currentPropertyJsonTemplate.hasFields("exclusiveMinimum")) { + propertiesInJson.addProperty("exclusiveMinimum", false); + } + if (!checkConstraintPresence(toscaElementProperty, "less_than") + && currentPropertyJsonTemplate.hasFields("exclusiveMaximum")) { + propertiesInJson.addProperty("exclusiveMaximum", false); + } + break; + default: + propertiesInJson.addProperty(TYPE, currentPropertyJsonTemplate.getName()); + break; + } + } + } + + private void parseEntrySchema(ToscaElementProperty toscaElementProperty, JsonObject propertiesInJson, + JsonTemplate currentPropertyJsonTemplate) { + // Here, a way to check if entry is a component (datatype) or a simple string + if (getToscaElement(this.extractSpecificFieldFromMap(toscaElementProperty, ENTRY_SCHEMA)) != null) { + String nameComponent = this.extractSpecificFieldFromMap(toscaElementProperty, ENTRY_SCHEMA); + var child = new ToscaConverterToJsonSchema(components, templates, metadataParser, serviceModel); + var propertiesContainer = new JsonObject(); + + if (((String) toscaElementProperty.getItems().get(TYPE)).equals(MAP)) { + JsonObject componentAsProperty = child.getJsonSchemaOfToscaElement(nameComponent); + propertiesContainer.add(nameComponent, componentAsProperty); + if (currentPropertyJsonTemplate.hasFields(PROPERTIES)) { + propertiesInJson.add(PROPERTIES, propertiesContainer); + } + } else { + JsonObject componentAsItem = child.getJsonSchemaOfToscaElement(nameComponent); + if (currentPropertyJsonTemplate.hasFields(PROPERTIES)) { + propertiesInJson.add("items", componentAsItem); + propertiesInJson.addProperty(FORMAT, "tabs-top"); + } + } + } else if (toscaElementProperty.getItems().get(TYPE).equals(LIST)) { + // Native cases + var itemContainer = new JsonObject(); + String valueInEntrySchema = + this.extractSpecificFieldFromMap(toscaElementProperty, ENTRY_SCHEMA); + itemContainer.addProperty(TYPE, valueInEntrySchema); + propertiesInJson.add("items", itemContainer); + propertiesInJson.addProperty(FORMAT, "tabs-top"); + } + + // MAP Case, for now nothing + } + /** * Look for a matching Component for the name parameter, in the components list. * @@ -326,8 +335,8 @@ public class ToscaConverterToJsonSchema { */ @SuppressWarnings("unchecked") public String extractSpecificFieldFromMap(ToscaElementProperty toscaElementProperty, String fieldName) { - LinkedHashMap entrySchemaFields = - (LinkedHashMap) toscaElementProperty.getItems().get(fieldName); + Map entrySchemaFields = + (Map) toscaElementProperty.getItems().get(fieldName); return entrySchemaFields.get(TYPE); } @@ -344,8 +353,8 @@ public class ToscaConverterToJsonSchema { @SuppressWarnings("unchecked") ArrayList constraints = (ArrayList) toscaElementProperty.getItems().get(CONSTRAINTS); for (Object constraint : constraints) { - if (constraint instanceof LinkedHashMap - && ((LinkedHashMap) constraint).containsKey(nameConstraint)) { + if (constraint instanceof Map + && ((Map) constraint).containsKey(nameConstraint)) { presentConstraint = true; } } diff --git a/runtime/src/main/java/org/onap/policy/clamp/clds/tosca/update/templates/JsonTemplateManager.java b/runtime/src/main/java/org/onap/policy/clamp/clds/tosca/update/templates/JsonTemplateManager.java index af7f8cc54..f9b274e26 100644 --- a/runtime/src/main/java/org/onap/policy/clamp/clds/tosca/update/templates/JsonTemplateManager.java +++ b/runtime/src/main/java/org/onap/policy/clamp/clds/tosca/update/templates/JsonTemplateManager.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP CLAMP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights + * Copyright (C) 2020, 2021 AT&T Intellectual Property. All rights * reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -38,8 +38,8 @@ import org.onap.policy.clamp.clds.util.JsonUtils; import org.onap.policy.clamp.loop.service.Service; public class JsonTemplateManager { - private LinkedHashMap jsonSchemaTemplates; - private LinkedHashMap toscaElements; + private Map jsonSchemaTemplates; + private Map toscaElements; /** * Constructor. @@ -58,19 +58,19 @@ public class JsonTemplateManager { } // GETTERS & SETTERS - public LinkedHashMap getToscaElements() { + public Map getToscaElements() { return toscaElements; } - public void setToscaElements(LinkedHashMap toscaElements) { + public void setToscaElements(Map toscaElements) { this.toscaElements = toscaElements; } - public LinkedHashMap getJsonSchemaTemplates() { + public Map getJsonSchemaTemplates() { return jsonSchemaTemplates; } - public void setJsonSchemaTemplates(LinkedHashMap jsonSchemaTemplates) { + public void setJsonSchemaTemplates(Map jsonSchemaTemplates) { this.jsonSchemaTemplates = jsonSchemaTemplates; } @@ -157,10 +157,9 @@ public class JsonTemplateManager { * @param jsonTemplates The template properties as String * @return a map */ - @SuppressWarnings("unused") - private LinkedHashMap initializeTemplates(String jsonTemplates) { + private Map initializeTemplates(String jsonTemplates) { - LinkedHashMap generatedTemplates = new LinkedHashMap<>(); + Map generatedTemplates = new LinkedHashMap<>(); JsonObject templates = JsonUtils.GSON.fromJson(jsonTemplates, JsonObject.class); for (Map.Entry templateAsJson : templates.entrySet()) { diff --git a/runtime/src/main/java/org/onap/policy/clamp/loop/CsarInstaller.java b/runtime/src/main/java/org/onap/policy/clamp/loop/CsarInstaller.java index aefe4556d..1542d9736 100644 --- a/runtime/src/main/java/org/onap/policy/clamp/loop/CsarInstaller.java +++ b/runtime/src/main/java/org/onap/policy/clamp/loop/CsarInstaller.java @@ -43,7 +43,6 @@ import org.onap.policy.clamp.loop.service.Service; import org.onap.policy.clamp.loop.template.LoopElementModel; import org.onap.policy.clamp.loop.template.LoopTemplate; import org.onap.policy.clamp.loop.template.LoopTemplatesRepository; -import org.onap.policy.clamp.loop.template.PolicyModelsRepository; import org.onap.policy.clamp.policy.PolicyEngineServices; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -62,9 +61,6 @@ public class CsarInstaller { private static final Logger logger = LoggerFactory.getLogger(CsarInstaller.class); - @Autowired - private PolicyModelsRepository policyModelsRepository; - @Autowired private LoopTemplatesRepository loopTemplatesRepository; diff --git a/runtime/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupPayload.java b/runtime/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupPayload.java index bbf33d54c..a161860ad 100644 --- a/runtime/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupPayload.java +++ b/runtime/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupPayload.java @@ -119,12 +119,12 @@ public class PdpGroupPayload { this.deploymentGroups.getGroups().stream().filter(group -> group.getName().equals(pdpGroup)).findFirst() .ifPresentOrElse(group -> group.getDeploymentSubgroups().add(newSubGroup), - () -> { - var newGroup = new DeploymentGroup(); - newGroup.setName(pdpGroup); - newGroup.setDeploymentSubgroups(new ArrayList<>(Arrays.asList(newSubGroup))); - this.deploymentGroups.getGroups().add(newGroup); - }); + () -> { + var newGroup = new DeploymentGroup(); + newGroup.setName(pdpGroup); + newGroup.setDeploymentSubgroups(new ArrayList<>(Arrays.asList(newSubGroup))); + this.deploymentGroups.getGroups().add(newGroup); + }); } /** diff --git a/runtime/src/test/java/org/onap/policy/clamp/clds/tosca/update/ToscaConverterWithDictionarySupportItTestCase.java b/runtime/src/test/java/org/onap/policy/clamp/clds/tosca/update/ToscaConverterWithDictionarySupportItTestCase.java index 1d78d6ce1..165fd3fd6 100644 --- a/runtime/src/test/java/org/onap/policy/clamp/clds/tosca/update/ToscaConverterWithDictionarySupportItTestCase.java +++ b/runtime/src/test/java/org/onap/policy/clamp/clds/tosca/update/ToscaConverterWithDictionarySupportItTestCase.java @@ -29,7 +29,6 @@ import javax.transaction.Transactional; import org.junit.Test; import org.junit.runner.RunWith; import org.onap.policy.clamp.clds.Application; -import org.onap.policy.clamp.clds.tosca.update.execution.ToscaMetadataExecutor; import org.onap.policy.clamp.clds.tosca.update.parser.metadata.ToscaMetadataParserWithDictionarySupport; import org.onap.policy.clamp.clds.tosca.update.templates.JsonTemplateManager; import org.onap.policy.clamp.clds.util.JsonUtils; @@ -55,9 +54,6 @@ public class ToscaConverterWithDictionarySupportItTestCase { @Autowired private ToscaMetadataParserWithDictionarySupport toscaMetadataParserWithDictionarySupport; - @Autowired - private ToscaMetadataExecutor toscaMetadataExecutor; - /** * This Test validates Tosca yaml with metadata tag that contains policy_model_type and acronym * parameters which defines the Tosca Policy name and its short name. diff --git a/runtime/src/test/java/org/onap/policy/clamp/clds/util/LoggingUtilsTest.java b/runtime/src/test/java/org/onap/policy/clamp/clds/util/LoggingUtilsTest.java index f3ca978e7..57837eff4 100644 --- a/runtime/src/test/java/org/onap/policy/clamp/clds/util/LoggingUtilsTest.java +++ b/runtime/src/test/java/org/onap/policy/clamp/clds/util/LoggingUtilsTest.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * ONAP CLAMP * Copyright (C) 2019 Samsung. All rights reserved. +* 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. @@ -22,7 +23,6 @@ package org.onap.policy.clamp.clds.util; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; @@ -38,7 +38,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.MDC; diff --git a/runtime/src/test/java/org/onap/policy/clamp/loop/ExternalComponentStateTest.java b/runtime/src/test/java/org/onap/policy/clamp/loop/ExternalComponentStateTest.java index 567cad69d..de8ec4a48 100644 --- a/runtime/src/test/java/org/onap/policy/clamp/loop/ExternalComponentStateTest.java +++ b/runtime/src/test/java/org/onap/policy/clamp/loop/ExternalComponentStateTest.java @@ -40,6 +40,7 @@ public class ExternalComponentStateTest { } @Test + @SuppressWarnings("unlikely-arg-type") public void equalsTest() { assertThat(state.equals(null)).isFalse(); @@ -68,7 +69,7 @@ public class ExternalComponentStateTest { public void compareToTest() { ExternalComponentState state2 = new ExternalComponentState("NOT_SENT", "The policies defined have NOT yet been created on the policy engine", 90); - assertThat(state.compareTo(state2)).isEqualTo(0); + assertThat(state).isEqualByComparingTo(state2); ExternalComponentState state3 = new ExternalComponentState("SENT", "The policies defined have NOT yet been created on the policy engine", 50); -- cgit 1.2.3-korg