From d05277df22ddde79458cd853f98e7ab3a4d98913 Mon Sep 17 00:00:00 2001 From: Parshad Patel Date: Wed, 25 Jul 2018 16:45:20 +0900 Subject: Fix sonar issues Fix try-with-resources and NPE issue Issue-ID: SDC-1529 Change-Id: Ia1071608528493e0a1a2985c458998d1197a8c0b Signed-off-by: Parshad Patel --- .../sdc/asdctool/impl/GraphMLDataAnalyzer.java | 25 +++++++-------- .../openecomp/sdc/asdctool/main/RemoveUtils.java | 37 +++++++++------------- 2 files changed, 27 insertions(+), 35 deletions(-) (limited to 'asdctool/src') diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/GraphMLDataAnalyzer.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/GraphMLDataAnalyzer.java index 863f920b47..e533c31082 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/GraphMLDataAnalyzer.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/GraphMLDataAnalyzer.java @@ -53,30 +53,31 @@ public class GraphMLDataAnalyzer { try { String mlFileLocation = args[0]; result = _analyzeGraphMLData(mlFileLocation); - System.out.println("Analyzed ML file=" + mlFileLocation + ", XLS result=" + result); + log.info("Analyzed ML file=" + mlFileLocation + ", XLS result=" + result); } catch (Exception e) { - log.info("analyze GraphML Data failed - {}" , e); + log.error("analyze GraphML Data failed - {}" , e); return null; } return result; } private String _analyzeGraphMLData(String mlFileLocation) throws Exception { - // Parse ML file SAXBuilder builder = new SAXBuilder(); File xmlFile = new File(mlFileLocation); Document document = (Document) builder.build(xmlFile); - + // XLS data file name String outputFile = mlFileLocation.replace(".graphml", ".xls"); Workbook wb = new HSSFWorkbook(); - FileOutputStream fileOut = new FileOutputStream(outputFile); - writeComponents(wb, document); - writeComponentInstances(wb, document); - wb.write(fileOut); - fileOut.close(); - return outputFile; + try(FileOutputStream fileOut = new FileOutputStream(outputFile)){ + writeComponents(wb, document); + writeComponentInstances(wb, document); + wb.write(fileOut); + }catch(Exception e){ + log.error("analyze GraphML Data failed - {}" , e); + } + return outputFile; } private void writeComponents(Workbook wb, Document document) { @@ -132,13 +133,11 @@ public class GraphMLDataAnalyzer { IteratorIterable dataNodes = edge.getDescendants(filter); for (Element data : dataNodes) { String attributeValue = data.getAttributeValue("key"); - switch (attributeValue) { - case "labelE": + if( attributeValue.equals("labelE")) { String edgeLabel = data.getText(); if (edgeLabel.equals("REQUIREMENT") || edgeLabel.equals("CAPABILITY")) { componentsHavingReqOrCap.add(edge.getAttributeValue("source")); } - break; } } } diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/RemoveUtils.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/RemoveUtils.java index 5546300740..4bc21b38ca 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/RemoveUtils.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/RemoveUtils.java @@ -31,31 +31,24 @@ public class RemoveUtils { if (args == null || args.length < 1) { removeUsage(); - } - - String operation = args[0]; - - switch (operation.toLowerCase()) { - - case "remove-products": - - boolean isValid = verifyParamsLength(args, 5); - if (false == isValid) { + }else { + String operation = args[0]; + if(operation.equalsIgnoreCase("remove-products")) { + boolean isValid = verifyParamsLength(args, 5); + if (!isValid) { + removeUsage(); + System.exit(1); + } + ProductLogic productLogic = new ProductLogic(); + boolean result = productLogic.deleteAllProducts(args[1], args[2], args[3], args[4]); + + if (!result) { + System.exit(2); + } + }else { removeUsage(); - System.exit(1); } - - ProductLogic productLogic = new ProductLogic(); - boolean result = productLogic.deleteAllProducts(args[1], args[2], args[3], args[4]); - - if (result == false) { - System.exit(2); - } - break; - default: - removeUsage(); } - } private static void removeUsage() { -- cgit 1.2.3-korg