Fix outstanding Sonar issues 75/78775/1
authormark.j.leonard <mark.j.leonard@gmail.com>
Tue, 19 Feb 2019 19:09:00 +0000 (19:09 +0000)
committermark.j.leonard <mark.j.leonard@gmail.com>
Tue, 19 Feb 2019 19:09:00 +0000 (19:09 +0000)
Change-Id: I9699ee13321f136b4460d5c85d49ab13378f52b4
Issue-ID: AAI-2121
Signed-off-by: mark.j.leonard <mark.j.leonard@gmail.com>
License.txt
src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java
src/main/java/org/onap/aai/babel/xml/generator/api/AaiArtifactGenerator.java
src/main/java/org/onap/aai/babel/xml/generator/model/Resource.java
src/test/java/org/onap/aai/babel/csar/extractor/YamlExtractorTest.java
src/test/java/org/onap/aai/babel/logging/TestApplicationLogger.java
src/test/java/org/onap/aai/babel/xml/generator/model/TestModel.java

index 6d771b3..5ce31aa 100644 (file)
@@ -1,8 +1,8 @@
 ============LICENSE_START=======================================================
 org.onap.aai
 ================================================================================
-Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
-Copyright © 2017-2018 European Software Marketing Ltd.
+Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved.
+Copyright © 2017-2019 European Software Marketing Ltd.
 ================================================================================
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
@@ -15,4 +15,4 @@ distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-============LICENSE_END=========================================================
\ No newline at end of file
+============LICENSE_END=========================================================
index 50c6edf..3fb77be 100644 (file)
@@ -85,7 +85,7 @@ public class ArtifactGeneratorToscaParser {
      * Constructs using csarHelper
      *
      * @param csarHelper
-     *            The csar helper
+     *     The csar helper
      */
     public ArtifactGeneratorToscaParser(ISdcCsarHelper csarHelper) {
         this.csarHelper = csarHelper;
@@ -95,7 +95,7 @@ public class ArtifactGeneratorToscaParser {
      * Get or create the artifact description.
      *
      * @param model
-     *            the artifact model
+     *     the artifact model
      * @return the artifact model's description
      */
     public static String getArtifactDescription(Model model) {
@@ -136,9 +136,9 @@ public class ArtifactGeneratorToscaParser {
      * Initialises the group filtering and TOSCA mapping configuration.
      * 
      * @param configLocation
-     *            the pathname to the JSON config file
+     *     the pathname to the JSON config file
      * @throws FileNotFoundException
-     *             if the file cannot be opened for reading
+     *     if the file cannot be opened for reading
      */
     public static void initToscaMappingsConfiguration(String configLocation) throws FileNotFoundException {
         log.debug("Getting TOSCA Mappings Configuration");
@@ -181,9 +181,9 @@ public class ArtifactGeneratorToscaParser {
      * duplicate keys then the TOSCA Property value takes precedence.
      *
      * @param stringProps
-     *            initial Map of String property values (e.g. from the TOSCA YAML metadata section)
+     *     initial Map of String property values (e.g. from the TOSCA YAML metadata section)
      * @param toscaProps
-     *            Map of TOSCA Property Type Object values to merge in (or overwrite)
+     *     Map of TOSCA Property Type Object values to merge in (or overwrite)
      * @return a Map of the property values converted to String
      */
     public Map<String, String> mergeProperties(Map<String, String> stringProps, Map<String, Property> toscaProps) {
@@ -253,13 +253,12 @@ public class ArtifactGeneratorToscaParser {
             String metaDataType = Optional.ofNullable(metadata).map(m -> m.getValue("type")).orElse(nodeTypeName);
             Resource model = Model.getModelFor(nodeTypeName, metaDataType);
 
-            if (metadata != null && hasAllottedResource(metadata.getAllProperties())) {
-                if (model.getWidgetType() == Type.VSERVER) {
-                    model = new Resource(Type.ALLOTTED_RESOURCE, false);
-                    Map<String, Object> props = new HashMap<>();
-                    props.put("providingService", true);
-                    model.setProperties(props);
-                }
+            if (metadata != null && hasAllottedResource(metadata.getAllProperties())
+                    && model.getWidgetType() == Type.VSERVER) {
+                model = new Resource(Type.ALLOTTED_RESOURCE, false);
+                Map<String, Object> props = new HashMap<>();
+                props.put("providingService", true);
+                model.setProperties(props);
             }
 
             foundProvidingService |= processModel(resourceModel, metadata, model, resourceNodeTemplate.getProperties());
@@ -276,13 +275,13 @@ public class ArtifactGeneratorToscaParser {
      * Create an Instance Group Model and populate it with the supplied data.
      *
      * @param resourceModel
-     *            the Resource node template Model
+     *     the Resource node template Model
      * @param memberNodes
-     *            the Resources and Widgets belonging to the Group
+     *     the Resources and Widgets belonging to the Group
      * @param metaProperties
-     *            the metadata of the Group
+     *     the metadata of the Group
      * @param properties
-     *            the properties of the Group
+     *     the properties of the Group
      * @return the Instance Group and Member resource models
      */
     private List<Resource> processInstanceGroup(Model resourceModel, ArrayList<NodeTemplate> memberNodes,
@@ -385,7 +384,7 @@ public class ArtifactGeneratorToscaParser {
      * Create a Map of property name against String property value from the input Map
      *
      * @param inputMap
-     *            The input Map
+     *     The input Map
      * @return Map of property name against String property value
      */
     private Map<String, String> populateStringProperties(Map<String, Property> inputMap) {
@@ -398,13 +397,13 @@ public class ArtifactGeneratorToscaParser {
      * is ProvidingService then return true, otherwise return false.
      *
      * @param resourceModel
-     *            parent Resource
+     *     parent Resource
      * @param metaData
-     *            for populating the Resource IDs
+     *     for populating the Resource IDs
      * @param resourceNode
-     *            any Model (will be ignored if not a Resource)
+     *     any Model (will be ignored if not a Resource)
      * @param nodeProperties
-     *            the node properties
+     *     the node properties
      * @return whether or not a ProvidingService was processed
      */
     private boolean processModel(Model resourceModel, Metadata metaData, Resource resourceNode,
index 19b3d80..57e8a67 100644 (file)
@@ -112,7 +112,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
      *
      * @param serviceVersion
      * @param csarHelper
-     *            interface to the TOSCA parser
+     *     interface to the TOSCA parser
      * @return the generated Artifacts (containing XML models)
      */
     private GenerationData generateAllArtifacts(final String serviceVersion, ISdcCsarHelper csarHelper) {
@@ -229,10 +229,9 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
 
         if (model != null) {
             Metadata metadata = nodeTemplate.getMetaData();
-            if (metadata != null && parser.hasAllottedResource(metadata.getAllProperties())) {
-                if (model.getWidgetType() == Type.VF) {
-                    model = new Resource(Type.ALLOTTED_RESOURCE, true);
-                }
+            if (metadata != null && parser.hasAllottedResource(metadata.getAllProperties())
+                    && model.getWidgetType() == Type.VF) {
+                model = new Resource(Type.ALLOTTED_RESOURCE, true);
             }
         }
 
@@ -242,6 +241,11 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
     private void generateResourceModel(ISdcCsarHelper csarHelper, List<Resource> resources,
             ArtifactGeneratorToscaParser parser, NodeTemplate nodeTemplate) {
         Resource resourceModel = getModelFor(parser, nodeTemplate);
+        if (resourceModel == null) {
+            log.info(ApplicationMsgs.DISTRIBUTION_EVENT, "Could not generate resource model");
+            return;
+        }
+
         Map<String, String> serviceMetadata = nodeTemplate.getMetaData().getAllProperties();
         resourceModel.populateModelIdentificationInformation(serviceMetadata);
 
@@ -296,7 +300,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
      * Method to generate the artifact name for an AAI model.
      *
      * @param model
-     *            AAI artifact model
+     *     AAI artifact model
      * @return Model artifact name
      */
     private String getArtifactName(Model model) {
@@ -320,9 +324,9 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
      * Create Resource artifact model from the AAI xml model string.
      *
      * @param resourceModel
-     *            Model of the resource artifact
+     *     Model of the resource artifact
      * @param aaiResourceModel
-     *            AAI model as string
+     *     AAI model as string
      * @return Generated {@link Artifact} model for the resource
      */
     private Artifact getResourceArtifact(Model resourceModel, String aaiResourceModel) {
@@ -352,9 +356,9 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
      * Create Service artifact model from the AAI XML model.
      *
      * @param serviceModel
-     *            Model of the service artifact
+     *     Model of the service artifact
      * @param aaiServiceModel
-     *            AAI model as string
+     *     AAI model as string
      * @return Generated {@link Artifact} model for the service
      */
     private Artifact getServiceArtifact(Service serviceModel, String aaiServiceModel) {
index d6a9405..d655ca6 100644 (file)
@@ -57,14 +57,17 @@ public class Resource extends Model {
         return false;
     }
 
+    @Override
     public boolean getDeleteFlag() {
         return deleteFlag;
     }
 
+    @Override
     public String getWidgetInvariantId() {
         return Widget.getWidget(getWidgetType()).getWidgetId();
     }
 
+    @Override
     public String getWidgetId() {
         return Widget.getWidget(getWidgetType()).getId();
     }
@@ -100,7 +103,7 @@ public class Resource extends Model {
      * Adds a Widget.
      *
      * @param widget
-     *            the widget
+     *     the widget
      * @return the boolean
      */
     @Override
index abe6f4d..5bb7763 100644 (file)
@@ -132,10 +132,14 @@ public class YamlExtractorTest {
     /**
      * Call the extractor with the specified arguments and assert that an exception is thrown.
      *
-     * @param archive the compressed archive in the form of a byte array, expected to contain one or more YAML files
-     * @param name the name of the archive
-     * @param version the version of the archive
-     * @param expectedErrorMessage the text of the InvalidArchiveException thrown by the extractor
+     * @param archive
+     *            the compressed archive in the form of a byte array, expected to contain one or more YAML files
+     * @param name
+     *            the name of the archive
+     * @param version
+     *            the version of the archive
+     * @param expectedErrorMessage
+     *            the text of the InvalidArchiveException thrown by the extractor
      */
     private void invalidArgumentsTest(byte[] archive, String name, String version, String expectedErrorMessage) {
         try {
index 2719315..02df4e8 100644 (file)
@@ -55,14 +55,15 @@ public class TestApplicationLogger {
      * Check that each message can be logged and that (by implication of successful logging) there is a corresponding
      * resource (message format).
      *
-     * @throws IOException if the log files cannot be read
+     * @throws IOException
+     *             if the log files cannot be read
      */
     @Test
     public void logAllMessages() throws IOException {
         Logger logger = LogHelper.INSTANCE;
         LogReader errorReader = new LogReader(LogHelper.getLogDirectory(), "error");
         LogReader debugReader = new LogReader(LogHelper.getLogDirectory(), "debug");
-        String[] args = { "1", "2", "3", "4" };
+        String[] args = {"1", "2", "3", "4"};
         for (ApplicationMsgs msg : Arrays.asList(ApplicationMsgs.values())) {
             if (msg.name().endsWith("ERROR")) {
                 logger.error(msg, args);
@@ -90,7 +91,8 @@ public class TestApplicationLogger {
      * Check that each message can be logged and that (by implication of successful logging) there is a corresponding
      * resource (message format).
      *
-     * @throws IOException if the log file cannot be read
+     * @throws IOException
+     *             if the log file cannot be read
      */
     @Test
     public void logDebugMessages() throws IOException {
@@ -103,7 +105,8 @@ public class TestApplicationLogger {
     /**
      * Check logAudit with HTTP headers.
      *
-     * @throws IOException if the log file cannot be read
+     * @throws IOException
+     *             if the log file cannot be read
      */
     @Test
     public void logAuditMessage() throws IOException {
@@ -135,7 +138,8 @@ public class TestApplicationLogger {
     /**
      * Check logAudit with no HTTP headers.
      *
-     * @throws IOException if the log file cannot be read
+     * @throws IOException
+     *             if the log file cannot be read
      */
     @Test
     public void logAuditMessageWithoutHeaders() throws IOException {
@@ -152,7 +156,8 @@ public class TestApplicationLogger {
     /**
      * Check logMetrics.
      *
-     * @throws IOException if the log file cannot be read
+     * @throws IOException
+     *             if the log file cannot be read
      */
     @Test
     public void logMetricsMessage() throws IOException {
@@ -207,13 +212,15 @@ public class TestApplicationLogger {
     /**
      * Call a logger method which is expected to throw an UnsupportedOperationException.
      *
-     * @param logMethod the logger method to invoke
-     * @param dummyMsg any Application Message enumeration value
+     * @param logMethod
+     *            the logger method to invoke
+     * @param dummyMsg
+     *            any Application Message enumeration value
      */
     private void callUnsupportedOperationMethod(TriConsumer<Enum<?>, LogFields, String[]> logMethod,
             ApplicationMsgs dummyMsg) {
         try {
-            logMethod.accept(dummyMsg, new LogFields(), new String[] { "" });
+            logMethod.accept(dummyMsg, new LogFields(), new String[] {""});
             org.junit.Assert.fail("method should have thrown execption"); // NOSONAR as code not reached
         } catch (UnsupportedOperationException e) {
             // Expected to reach here
@@ -223,10 +230,14 @@ public class TestApplicationLogger {
     /**
      * Assert that a log message was logged to the expected log file at the expected severity.
      *
-     * @param msg the Application Message enumeration value
-     * @param reader the log reader for the message
-     * @param severity log level
-     * @throws IOException if the log file cannot be read
+     * @param msg
+     *            the Application Message enumeration value
+     * @param reader
+     *            the log reader for the message
+     * @param severity
+     *            log level
+     * @throws IOException
+     *             if the log file cannot be read
      */
     private void validateLoggedMessage(ApplicationMsgs msg, LogReader reader, String severity) throws IOException {
         String str = reader.getNewLines();
index 8d1a045..92b548a 100644 (file)
@@ -58,7 +58,7 @@ public class TestModel {
      * from the Artifact Generator properties.
      *
      * @throws IOException
-     *     if the Artifact Generator properties file is not loaded
+     *             if the Artifact Generator properties file is not loaded
      */
     @Before
     public void setup() throws IOException {
@@ -68,9 +68,10 @@ public class TestModel {
         String configLocation = System.getProperty(ArtifactGeneratorToscaParser.PROPERTY_TOSCA_MAPPING_FILE);
         if (configLocation == null) {
             throw new IllegalArgumentException(
-                    String.format(ArtifactGeneratorToscaParser.GENERATOR_AAI_CONFIGLOCATION_NOT_FOUND, ArtifactGeneratorToscaParser.PROPERTY_TOSCA_MAPPING_FILE));
+                    String.format(ArtifactGeneratorToscaParser.GENERATOR_AAI_CONFIGLOCATION_NOT_FOUND,
+                            ArtifactGeneratorToscaParser.PROPERTY_TOSCA_MAPPING_FILE));
         }
-        
+
         ArtifactGeneratorToscaParser.initToscaMappingsConfiguration(configLocation);
         utils.loadWidgetToUuidMappings();
 
@@ -129,9 +130,9 @@ public class TestModel {
      * Assert that the TOSCA type String is mapped to the expected Widget Type.
      * 
      * @param toscaType
-     *     the TOSCA type or prefix
+     *            the TOSCA type or prefix
      * @param widgetType
-     *     the type of Widget expected from the mappings
+     *            the type of Widget expected from the mappings
      */
     private void assertMapping(String toscaType, Type widgetType) {
         assertThat(Model.getModelFor(toscaType).getWidgetType(), is(widgetType));
@@ -141,11 +142,11 @@ public class TestModel {
      * Assert that the TOSCA metadata type is mapped to the expected Widget Type.
      * 
      * @param toscaType
-     *     the name (or name prefix) of the TOSCA type
+     *            the name (or name prefix) of the TOSCA type
      * @param metadataType
-     *     the type specified in the TOSCA metadata
+     *            the type specified in the TOSCA metadata
      * @param widgetType
-     *     the type of Widget expected from the mappings
+     *            the type of Widget expected from the mappings
      */
     private void assertMapping(String toscaType, String metadataType, Type widgetType) {
         assertThat(Model.getModelFor(toscaType, metadataType).getWidgetType(), is(widgetType));