diff options
author | 2019-11-12 14:44:41 +0900 | |
---|---|---|
committer | 2019-11-12 14:48:07 +0900 | |
commit | 61c4bdc5146977b79fb09457672c5a915adfe64b (patch) | |
tree | 43b7e49ffb96bc1269bf1b17969cf2024564b53d /ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/pdf | |
parent | beabe647ed84f9a5fea3e9633267e713e19f3750 (diff) |
Fix NPE & other sonar in epsdk-analytics
A "NullPointerException" could be thrown
Use a logger to log this exception
Issue-ID: PORTAL-562
Change-Id: I0ee2a761136167fd6c2e1d868ae8359eba78462f
Signed-off-by: Parshad Patel <pars.patel@samsung.com>
Diffstat (limited to 'ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/pdf')
-rw-r--r-- | ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/pdf/PdfReportHandler.java | 160 |
1 files changed, 85 insertions, 75 deletions
diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/pdf/PdfReportHandler.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/pdf/PdfReportHandler.java index 3a50a99c..b42bdf9c 100644 --- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/pdf/PdfReportHandler.java +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/pdf/PdfReportHandler.java @@ -236,8 +236,12 @@ public class PdfReportHandler extends org.onap.portalsdk.analytics.RaptorObject{ } } - } catch (DocumentException dex) {dex.printStackTrace();} - catch (RaptorException rex) {rex.printStackTrace();} + } catch (DocumentException dex) { + logger.error(EELFLoggerDelegate.errorLogger, "DocumentException in createPdfFileContent", dex); + } + catch (RaptorException rex) { + logger.error(EELFLoggerDelegate.errorLogger, "RaptorException in createPdfFileContent", rex); + } } else { //ReportRuntime rr = (ReportRuntime) request.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME); @@ -322,8 +326,7 @@ public class PdfReportHandler extends org.onap.portalsdk.analytics.RaptorObject{ } catch (DocumentException de) { - de.printStackTrace(); - //System.err.println("document: " + de.getMessage()); + logger.error(EELFLoggerDelegate.errorLogger, "DocumentException in createPdfFileContent", de); } } @@ -574,18 +577,17 @@ public class PdfReportHandler extends org.onap.portalsdk.analytics.RaptorObject{ } catch (MalformedURLException e) { isGenerateNewImage = true; - //e.printStackTrace(); + logger.error(EELFLoggerDelegate.errorLogger, "MalformedURLException in getImage", e); } catch (BadElementException e) { isGenerateNewImage = true; - //e.printStackTrace(); - + logger.error(EELFLoggerDelegate.errorLogger, "BadElementException in getImage", e); } catch (FileNotFoundException e) { isGenerateNewImage = true; - //e.printStackTrace(); + logger.error(EELFLoggerDelegate.errorLogger, "FileNotFoundException in getImage", e); } catch (IOException e) { isGenerateNewImage = true; - //e.printStackTrace(); + logger.error(EELFLoggerDelegate.errorLogger, "IOException in getImage", e); } } @@ -601,6 +603,10 @@ public class PdfReportHandler extends org.onap.portalsdk.analytics.RaptorObject{ private ArrayList generateNewImage(HttpServletRequest request, ReportRuntime rr) { ArrayList images = new ArrayList(); + final String MALFORMEDURLEXCEPTION_MSG = "MalformedURLException in generateNewImage"; + final String BADELEMENTEXCEPTION_MSG = "BadElementException in generateNewImage"; + final String FILENOTFOUNDEXCEPTION_MSG = "FileNotFoundException in generateNewImage"; + final String IOEXCEPTION_MSG = "IOException in generateNewImage"; try { //ReportRuntime rr = (ReportRuntime) request.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME); DataSet ds = null; @@ -706,20 +712,21 @@ public class PdfReportHandler extends org.onap.portalsdk.analytics.RaptorObject{ additionalChartOptionsMap, true );*/ - try { - Image image = Image.getInstance(downloadFileName); - images.add(image); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - catch (BadElementException e) { - e.printStackTrace(); - - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } + try { + Image image = Image.getInstance(downloadFileName); + images.add(image); + } catch (MalformedURLException e) { + logger.error(EELFLoggerDelegate.errorLogger, MALFORMEDURLEXCEPTION_MSG, + e); + } catch (BadElementException e) { + logger.error(EELFLoggerDelegate.errorLogger, BADELEMENTEXCEPTION_MSG, + e); + } catch (FileNotFoundException e) { + logger.error(EELFLoggerDelegate.errorLogger, FILENOTFOUNDEXCEPTION_MSG, + e); + } catch (IOException e) { + logger.error(EELFLoggerDelegate.errorLogger, IOEXCEPTION_MSG, e); + } } } else { /** first check the columns to be opened in new charts and loop around in ChartGen generate chart function - sundar**/ @@ -780,20 +787,21 @@ public class PdfReportHandler extends org.onap.portalsdk.analytics.RaptorObject{ additionalChartOptionsMap, true );*/ - try { - Image image = Image.getInstance(downloadFileName); - images.add(image); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - catch (BadElementException e) { - e.printStackTrace(); - - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } + try { + Image image = Image.getInstance(downloadFileName); + images.add(image); + } catch (MalformedURLException e) { + logger.error(EELFLoggerDelegate.errorLogger, MALFORMEDURLEXCEPTION_MSG, + e); + } catch (BadElementException e) { + logger.error(EELFLoggerDelegate.errorLogger, BADELEMENTEXCEPTION_MSG, + e); + } catch (FileNotFoundException e) { + logger.error(EELFLoggerDelegate.errorLogger, FILENOTFOUNDEXCEPTION_MSG, + e); + } catch (IOException e) { + logger.error(EELFLoggerDelegate.errorLogger, IOEXCEPTION_MSG, e); + } } if(!chartType.equals(AppConstants.GT_PIE_MULTIPLE)) { @@ -831,21 +839,22 @@ public class PdfReportHandler extends org.onap.portalsdk.analytics.RaptorObject{ additionalChartOptionsMap, true );*/ - try { - Image image = Image.getInstance(downloadFileName); - images.add(image); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - catch (BadElementException e) { - e.printStackTrace(); - - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - } + try { + Image image = Image.getInstance(downloadFileName); + images.add(image); + } catch (MalformedURLException e) { + logger.error(EELFLoggerDelegate.errorLogger, + MALFORMEDURLEXCEPTION_MSG, e); + } catch (BadElementException e) { + logger.error(EELFLoggerDelegate.errorLogger, + BADELEMENTEXCEPTION_MSG, e); + } catch (FileNotFoundException e) { + logger.error(EELFLoggerDelegate.errorLogger, + FILENOTFOUNDEXCEPTION_MSG, e); + } catch (IOException e) { + logger.error(EELFLoggerDelegate.errorLogger, IOEXCEPTION_MSG, e); + } + } } /** second rest of the columns are merged to one single chart - sundar**/ // System.out.println(" rr.getChartDisplayNamesList(AppConstants.CHART_WITHOUT_NEWCHART_COLUMNS) " + rr.getChartDisplayNamesList(AppConstants.CHART_WITHOUT_NEWCHART_COLUMNS)); @@ -884,29 +893,30 @@ public class PdfReportHandler extends org.onap.portalsdk.analytics.RaptorObject{ additionalChartOptionsMap, true );*/ - try { - Image image = Image.getInstance(downloadFileName); - images.add(image); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - catch (BadElementException e) { - e.printStackTrace(); - - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } // Stacked Chart Check - } // else no Series Column - - }// if(ds!=null) - - }catch (Exception e) { - e.printStackTrace(); - } + try { + Image image = Image.getInstance(downloadFileName); + images.add(image); + } catch (MalformedURLException e) { + logger.error(EELFLoggerDelegate.errorLogger, + MALFORMEDURLEXCEPTION_MSG, e); + } catch (BadElementException e) { + logger.error(EELFLoggerDelegate.errorLogger, + BADELEMENTEXCEPTION_MSG, e); + } catch (FileNotFoundException e) { + logger.error(EELFLoggerDelegate.errorLogger, + FILENOTFOUNDEXCEPTION_MSG, e); + } catch (IOException e) { + logger.error(EELFLoggerDelegate.errorLogger, IOEXCEPTION_MSG, e); + } + } + } // Stacked Chart Check + } // else no Series Column + + } // if(ds!=null) + + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "Exception in generateNewImage", e); + } // System.out.println("Total Images " + images.size()); return images.size()>0?images:null; |