Fixed chart Issue- Throwing error on the screen 64/112264/1
authorSudarshan Kumar <sudarshan.kumar@att.com>
Tue, 8 Sep 2020 09:04:24 +0000 (14:34 +0530)
committerSudarshan Kumar <sudarshan.kumar@att.com>
Tue, 8 Sep 2020 09:05:45 +0000 (14:35 +0530)
Fixed chart Issue- Throwing error on the screen while running older
report

Issue-ID: PORTAL-1000
Change-Id: I569cd01cea830d16b32c34b516e399d9207b21cc
Signed-off-by: Sudarshan Kumar <sudarshan.kumar@att.com>
ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/runtime/ChartD3Helper.java
ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/runtime/ChartJSONHelper.java

index a63ce95..6367c3e 100644 (file)
@@ -155,12 +155,12 @@ public class ChartD3Helper {
                try {
                        precision = Integer.parseInt(chartOptionsMap.get("precision"));
                } catch (NumberFormatException ex) {
-      logger.debug(EELFLoggerDelegate.debugLogger, ex.getMessage());
+                       logger.debug(EELFLoggerDelegate.debugLogger, ex.getMessage());
                }
                
-      final Long user_id = new Long((long) UserUtils.getUserId(request));
+               final Long user_id = new Long((long) UserUtils.getUserId(request));
 
-      String chartType = reportRuntime.getChartType();
+               String chartType = reportRuntime.getChartType();
            List l = reportRuntime.getAllColumns();
 
            String chartLeftAxisLabel = reportRuntime.getFormFieldFilled(nvl(reportRuntime.getChartLeftAxisLabel()));
@@ -175,12 +175,21 @@ public class ChartD3Helper {
            String legendColumnName = (reportRuntime.getChartLegendColumn()!=null)?reportRuntime.getChartLegendColumn().getDisplayName():"Legend Column";
                boolean displayChart = (nvl(chartType).length()>0)&&reportRuntime.getDisplayChart();
 
-    StringBuilder wholeScript = new StringBuilder("");
+               StringBuilder wholeScript = new StringBuilder("");
                
                String title = reportRuntime.getReportTitle();
                
-               title = parseTitle(title, formValues);
+               //Assigning reportName as title in case of title is blank or null
+               if(title == null || "".equalsIgnoreCase(title)) {
+                       title = reportRuntime.getReportName();
+               }
                
+               if(title != null) {
+                       title = parseTitle(title, formValues);
+               }else {
+                       logger.debug(EELFLoggerDelegate.debugLogger, "Report Title is NULL.");
+               }
+                               
                String chartScriptsPath = (isEmbedded?AppUtils.getChartScriptsPath(""):AppUtils.getChartScriptsPath());
                
                if(displayChart) {
@@ -2822,7 +2831,20 @@ public class ChartD3Helper {
                        }
                }
                try(BufferedWriter out = new BufferedWriter(new FileWriter("test.txt"))) {
-                       out.write(wholeScript.toString());
+                       if(wholeScript !=null && wholeScript.length() > 0) {
+                               out.write(wholeScript.toString());
+                       }else {
+                               wholeScript = new StringBuilder("");
+                               wholeScript.append("<!DOCTYPE html>\n");
+                               wholeScript.append("<html>\n");
+                               wholeScript.append(" <head>\n");
+                               wholeScript.append("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />\n");
+                               wholeScript.append("</head>\n");
+                               wholeScript.append("<body> \n");
+                               wholeScript.append("<div style=\"margin-top:135px;\"><h2>No Chart has been configured. Kindly go to Chart Wizard and configure your Chart.</h2></div>");
+                               wholeScript.append("</body></html> \n");
+                               out.write(wholeScript.toString());
+                       }                       
                } catch (IOException e) { 
                        e.printStackTrace();
                        System.out.println("Exception ");
index 088409e..934db0a 100644 (file)
@@ -359,7 +359,17 @@ public class ChartJSONHelper {
                
                String title = reportRuntime.getReportTitle();
                
-               title = parseTitle(title, formValues);
+               //Assigning reportName as title in case of title is blank or null
+               if(title == null || "".equalsIgnoreCase(title)) {
+                       title = reportRuntime.getReportName();
+               }
+               
+               if(title != null) {
+                       title = parseTitle(title, formValues);
+               }else {
+                       logger.debug(EELFLoggerDelegate.debugLogger, "Report Title is NULL.");
+               }
+               
                ObjectMapper mapper = new ObjectMapper();
                ChartJSON chartJSON = new ChartJSON();
                String sql = "";