diff options
author | burdziak <olaf.burdziakowski@nokia.com> | 2019-04-19 15:27:13 +0200 |
---|---|---|
committer | burdziak <olaf.burdziakowski@nokia.com> | 2019-04-19 15:27:13 +0200 |
commit | c31795a7437b0dbcf26effe7f121a4cdae7bf753 (patch) | |
tree | e50ae8b36422397ec9391ac6d13a1d14ea5ce163 /ecomp-sdk | |
parent | b3ced8c4eb98a152076b3f0a05ba601bce7f8d2a (diff) |
Fix sonar issues (part) in ChartD3Helper
Change-Id: I742c940914026b759e8240f2b23e90e2b89e2c44
Issue-ID: PORTAL-523
Signed-off-by: burdziak <olaf.burdziakowski@nokia.com>
Diffstat (limited to 'ecomp-sdk')
2 files changed, 85 insertions, 336 deletions
diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/runtime/ChartD3Helper.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/runtime/ChartD3Helper.java index 4839f115..721d46ab 100644 --- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/runtime/ChartD3Helper.java +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/runtime/ChartD3Helper.java @@ -63,10 +63,8 @@ import java.util.regex.Pattern; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; -import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.time.DateUtils; import org.onap.portalsdk.analytics.error.RaptorException; -import org.onap.portalsdk.analytics.model.ReportHandler; import org.onap.portalsdk.analytics.model.base.ChartSeqComparator; import org.onap.portalsdk.analytics.system.AppUtils; import org.onap.portalsdk.analytics.system.ConnectionUtils; @@ -75,7 +73,6 @@ import org.onap.portalsdk.analytics.util.AppConstants; import org.onap.portalsdk.analytics.util.DataSet; import org.onap.portalsdk.analytics.util.HtmlStripper; import org.onap.portalsdk.analytics.util.Utils; -import org.onap.portalsdk.analytics.view.ReportData; import org.onap.portalsdk.analytics.xmlobj.DataColumnType; import org.onap.portalsdk.analytics.xmlobj.FormFieldType; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; @@ -88,16 +85,27 @@ public class ChartD3Helper { private ReportRuntime reportRuntime; private String chartType; - public static final long HOUR = 3600*1000; - public static final long DAY = 3600*1000*24; - public static final long MONTH = 3600*1000*24*31; - public static final long YEAR = 3600*1000*24*365; - + public static final long HOUR = 3600l*1000l; + public static final long DAY = 3600l*1000l*24l; + public static final long MONTH = 3600l*1000l*24l*31l; + public static final long YEAR = 3600l*1000l*24l*365l; + + private static final String REPORT_ID = "Report ID : "; + private static final String QUERY = "QUERY - "; public ChartD3Helper() { } + public ChartD3Helper(ReportRuntime rr) { + this.reportRuntime = rr; + } + + private void printDebugLogSeparatorLine() + { + logger.debug(EELFLoggerDelegate.debugLogger, ("********************************************************************************")); + } + /** * @return the chartType */ @@ -111,153 +119,9 @@ public class ChartD3Helper { public void setChartType(String chartType) { this.chartType = chartType; } - - public ChartD3Helper(ReportRuntime rr) { - this.reportRuntime = rr; - } - -// public String createVisualization(String reportID, HttpServletRequest request) throws RaptorException { -// //From annotations chart -// clearReportRuntimeBackup(request); -// -// //HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes()).getRequest(); -// final Long user_id = new Long((long) UserUtils.getUserId(request)); -// //String action = request.getParameter(AppConstants.RI_ACTION); -// //String reportID = AppUtils.getRequestValue(request, AppConstants.RI_REPORT_ID); -// -// ReportHandler rh = new ReportHandler(); -// ReportData reportData = null; -// HashMap<String, String> chartOptionsMap = new HashMap<String, String>(); -// try { -// if(reportID !=null) { -// reportRuntime = rh.loadReportRuntime(request, reportID, true, 1); -// setChartType(reportRuntime.getChartType()); -// reportData = reportRuntime.loadReportData(0, user_id.toString(), 10000,request, false); -// } -// -// -// -// String rotateLabelsStr = ""; -// rotateLabelsStr = AppUtils.nvl(reportRuntime.getLegendLabelAngle()); -// if(rotateLabelsStr.toLowerCase().equals("standard")) { -// rotateLabelsStr = "0"; -// } else if (rotateLabelsStr.toLowerCase().equals("up45")) { -// rotateLabelsStr = "45"; -// } else if (rotateLabelsStr.toLowerCase().equals("down45")) { -// rotateLabelsStr = "-45"; -// } else if (rotateLabelsStr.toLowerCase().equals("up90")) { -// rotateLabelsStr = "90"; -// } else if (rotateLabelsStr.toLowerCase().equals("down90")) { -// rotateLabelsStr = "-90"; -// } else -// rotateLabelsStr = "0"; -// -// String width = (AppUtils.getRequestNvlValue(request, "width").length()>0?AppUtils.getRequestNvlValue(request, "width"):(AppUtils.nvl(reportRuntime.getChartWidth()).length()>0?reportRuntime.getChartWidth():"700")); -// String height = (AppUtils.getRequestNvlValue(request, "height").length()>0?AppUtils.getRequestNvlValue(request, "height"):(AppUtils.nvl(reportRuntime.getChartHeight()).length()>0?reportRuntime.getChartHeight():"300")); -// String animationStr = (AppUtils.getRequestNvlValue(request, "animation").length()>0?AppUtils.getRequestNvlValue(request, "animation"):new Boolean(reportRuntime.isAnimateAnimatedChart()).toString()); -// -// String rotateLabels = (AppUtils.getRequestNvlValue(request, "rotateLabels").length()>0?AppUtils.getRequestNvlValue(request, "rotateLabels"):(rotateLabelsStr.length()>0?rotateLabelsStr:"0")); -// String staggerLabelsStr = (AppUtils.getRequestNvlValue(request, "staggerLabels").length()>0?AppUtils.getRequestNvlValue(request, "staggerLabels"):"false"); -// String showMaxMinStr = (AppUtils.getRequestNvlValue(request, "showMaxMin").length()>0?AppUtils.getRequestNvlValue(request, "showMaxMin"):"false"); -// String showControlsStr = (AppUtils.getRequestNvlValue(request, "showControls").length()>0?AppUtils.getRequestNvlValue(request, "showControls"):new Boolean(reportRuntime.displayBarControls()).toString()); -// String showLegendStr = (AppUtils.getRequestNvlValue(request, "showLegend").length()>0?AppUtils.getRequestNvlValue(request, "showLegend"):new Boolean(!new Boolean(reportRuntime.hideChartLegend())).toString()); -// String topMarginStr = AppUtils.getRequestNvlValue(request, "topMargin"); -// String topMargin = (AppUtils.nvl(topMarginStr).length()<=0)?(reportRuntime.getTopMargin()!=null?reportRuntime.getTopMargin().toString():"30"):topMarginStr; -// String bottomMarginStr = AppUtils.getRequestNvlValue(request, "bottomMargin"); -// String bottomMargin = (AppUtils.nvl(bottomMarginStr).length()<=0)?(reportRuntime.getBottomMargin()!=null?reportRuntime.getBottomMargin().toString():"50"):bottomMarginStr; -// String leftMarginStr = AppUtils.getRequestNvlValue(request, "leftMargin"); -// String leftMargin = (AppUtils.nvl(leftMarginStr).length()<=0)?(reportRuntime.getLeftMargin()!=null?reportRuntime.getLeftMargin().toString():"100"):leftMarginStr; -// String rightMarginStr = AppUtils.getRequestNvlValue(request, "rightMargin"); -// String rightMargin = (AppUtils.nvl(rightMarginStr).length()<=0)?(reportRuntime.getRightMargin()!=null?reportRuntime.getRightMargin().toString():"160"):rightMarginStr; -// String showTitleStr = (AppUtils.getRequestNvlValue(request, "showTitle").length()>0?AppUtils.getRequestNvlValue(request, "showTitle"):new Boolean(reportRuntime.displayChartTitle()).toString()); -// String subType = AppUtils.getRequestNvlValue(request, "subType").length()>0?AppUtils.getRequestNvlValue(request, "subType"):(AppUtils.nvl(reportRuntime.getTimeSeriesRender()).equals("area")?reportRuntime.getTimeSeriesRender():""); -// String stackedStr = AppUtils.getRequestNvlValue(request, "stacked").length()>0?AppUtils.getRequestNvlValue(request, "stacked"):new Boolean(reportRuntime.isChartStacked()).toString(); -// String horizontalBar = AppUtils.getRequestNvlValue(request, "horizontalBar").length()>0?AppUtils.getRequestNvlValue(request, "horizontalBar"):new Boolean(reportRuntime.isHorizontalOrientation()).toString(); -// String barRealTimeAxis = AppUtils.getRequestNvlValue(request, "barRealTimeAxis"); -// String barReduceXAxisLabels = AppUtils.getRequestNvlValue(request, "barReduceXAxisLabels").length()>0?AppUtils.getRequestNvlValue(request, "barReduceXAxisLabels"):new Boolean(reportRuntime.isLessXaxisTickers()).toString();; -// String timeAxis = AppUtils.getRequestNvlValue(request, "timeAxis").length()>0?AppUtils.getRequestNvlValue(request, "timeAxis"):new Boolean(reportRuntime.isTimeAxis()).toString(); -// String logScale = AppUtils.getRequestNvlValue(request, "logScale").length()>0?AppUtils.getRequestNvlValue(request, "logScale"):new Boolean(reportRuntime.isLogScale()).toString(); -// String precision = AppUtils.getRequestNvlValue(request, "precision").length()>0?AppUtils.getRequestNvlValue(request, "precision"):"2"; -// -// -// chartOptionsMap.put("width", width); -// chartOptionsMap.put("height", height); -// chartOptionsMap.put("animation", animationStr); -// chartOptionsMap.put("rotateLabels", rotateLabels); -// chartOptionsMap.put("staggerLabels", staggerLabelsStr); -// chartOptionsMap.put("showMaxMin", showMaxMinStr); -// chartOptionsMap.put("showControls", showControlsStr); -// chartOptionsMap.put("showLegend", showLegendStr); -// chartOptionsMap.put("topMargin", topMargin); -// chartOptionsMap.put("bottomMargin", bottomMargin); -// chartOptionsMap.put("leftMargin", leftMargin); -// chartOptionsMap.put("rightMargin", rightMargin); -// chartOptionsMap.put("showTitle", showTitleStr); -// chartOptionsMap.put("subType", subType); -// chartOptionsMap.put("stacked", stackedStr); -// chartOptionsMap.put("horizontalBar", horizontalBar); -// chartOptionsMap.put("timeAxis", timeAxis); -// chartOptionsMap.put("barRealTimeAxis", barRealTimeAxis); -// chartOptionsMap.put("barReduceXAxisLabels", barReduceXAxisLabels); -// -// chartOptionsMap.put("logScale", logScale); -// chartOptionsMap.put("precision", precision); -// -// -// } catch (RaptorException ex) { -// ex.printStackTrace(); -// } -// return createVisualization(reportRuntime, chartOptionsMap, request); -// } - -// public String createVisualization(ReportRuntime reportRuntime, HttpServletRequest request) throws RaptorException { -// -// String rotateLabelsStr = ""; -// rotateLabelsStr = AppUtils.nvl(reportRuntime.getLegendLabelAngle()); -// if(rotateLabelsStr.toLowerCase().equals("standard")) { -// rotateLabelsStr = "0"; -// } else if (rotateLabelsStr.toLowerCase().equals("up45")) { -// rotateLabelsStr = "45"; -// } else if (rotateLabelsStr.toLowerCase().equals("down45")) { -// rotateLabelsStr = "-45"; -// } else if (rotateLabelsStr.toLowerCase().equals("up90")) { -// rotateLabelsStr = "90"; -// } else if (rotateLabelsStr.toLowerCase().equals("down90")) { -// rotateLabelsStr = "-90"; -// } else -// rotateLabelsStr = "0"; -// -// HashMap<String,String> chartOptionsMap = new HashMap<String, String>(); -// chartOptionsMap.put("width", reportRuntime.getChartWidth()); -// chartOptionsMap.put("height", reportRuntime.getChartHeight()); -// chartOptionsMap.put("animation", new Boolean(reportRuntime.isAnimateAnimatedChart()).toString()); -// chartOptionsMap.put("rotateLabels", rotateLabelsStr); -// chartOptionsMap.put("staggerLabels", "false"); -// chartOptionsMap.put("showMaxMin", "false"); -// chartOptionsMap.put("showControls", new Boolean(reportRuntime.displayBarControls()).toString()); -// chartOptionsMap.put("showLegend", new Boolean(!reportRuntime.hideChartLegend()).toString()); -// chartOptionsMap.put("topMargin", reportRuntime.getTopMargin()!=null?reportRuntime.getTopMargin().toString():"30"); -// chartOptionsMap.put("bottomMargin", reportRuntime.getBottomMargin()!=null?reportRuntime.getBottomMargin().toString():"50"); -// chartOptionsMap.put("leftMargin", reportRuntime.getLeftMargin()!=null?reportRuntime.getLeftMargin().toString():"100"); -// chartOptionsMap.put("rightMargin", reportRuntime.getRightMargin()!=null?reportRuntime.getRightMargin().toString():"160"); -// chartOptionsMap.put("showTitle", new Boolean(reportRuntime.displayChartTitle()).toString()); -// chartOptionsMap.put("subType", (AppUtils.nvl(reportRuntime.getTimeSeriesRender()).equals("area")?reportRuntime.getTimeSeriesRender():"")); -// chartOptionsMap.put("stacked", new Boolean(reportRuntime.isChartStacked()).toString()); -// chartOptionsMap.put("horizontalBar", new Boolean(reportRuntime.isHorizontalOrientation()).toString()); -// chartOptionsMap.put("timeAxis", new Boolean(reportRuntime.isTimeAxis()).toString()); -// chartOptionsMap.put("barReduceXAxisLabels", new Boolean(reportRuntime.isLessXaxisTickers()).toString()); -// -// chartOptionsMap.put("logScale", new Boolean(reportRuntime.isLogScale()).toString()); -// chartOptionsMap.put("precision", "2"); -// -// -// -// return createVisualization(reportRuntime, chartOptionsMap, request); -// } - public String createVisualization(ReportRuntime reportRuntime, HashMap<String,String> chartOptionsMap, HttpServletRequest request) throws RaptorException { - - //String width, String height, boolean animation, String rotateLabels, boolean staggerLabels, boolean showMaxMin, boolean showLegend, boolean showControls, String topMargin, String bottomMargin, boolean showTitle, String subType + public String createVisualization(ReportRuntime reportRuntime, Map<String,String> chartOptionsMap, + HttpServletRequest request) { boolean isEmbedded = false; if(request.getParameter("embedded")!=null) { @@ -291,18 +155,14 @@ public class ChartD3Helper { try { precision = Integer.parseInt(chartOptionsMap.get("precision")); } catch (NumberFormatException ex) { - + 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)); - HttpSession session = null; - session = request.getSession(); - String chartType = reportRuntime.getChartType(); + String chartType = reportRuntime.getChartType(); List l = reportRuntime.getAllColumns(); - List lGroups = reportRuntime.getAllChartGroups(); - HashMap mapYAxis = reportRuntime.getAllChartYAxis(reportRuntime.getReportParamValues()); - //ReportParamValues reportParamValues = reportRuntime.getReportParamValues(); + String chartLeftAxisLabel = reportRuntime.getFormFieldFilled(nvl(reportRuntime.getChartLeftAxisLabel())); String chartRightAxisLabel = reportRuntime.getFormFieldFilled(nvl(reportRuntime.getChartRightAxisLabel())); @@ -314,9 +174,8 @@ public class ChartD3Helper { String legendColumnName = (reportRuntime.getChartLegendColumn()!=null)?reportRuntime.getChartLegendColumn().getDisplayName():"Legend Column"; boolean displayChart = (nvl(chartType).length()>0)&&reportRuntime.getDisplayChart(); - HashMap additionalChartOptionsMap = new HashMap(); - StringBuffer wholeScript = new StringBuffer(""); + StringBuilder wholeScript = new StringBuilder(""); String title = reportRuntime.getReportTitle(); @@ -328,16 +187,16 @@ public class ChartD3Helper { DataSet ds = null; try { if (!(chartType.equals(AppConstants.GT_HIERARCHICAL) || chartType.equals(AppConstants.GT_HIERARCHICAL_SUNBURST) || chartType.equals(AppConstants.GT_ANNOTATION_CHART))) { - ds = (DataSet) loadChartData(new Long(user_id).toString(), request); + ds = loadChartData(Long.toString(user_id), request); } else if(chartType.equals(AppConstants.GT_ANNOTATION_CHART)) { String reportSQL = reportRuntime.getWholeSQL(); String dbInfo = reportRuntime.getDBInfo(); ds = ConnectionUtils.getDataSet(reportSQL, dbInfo); if(ds.getRowCount()<=0) { - logger.debug(EELFLoggerDelegate.debugLogger, ("********************************************************************************")); - logger.debug(EELFLoggerDelegate.debugLogger, (chartType.toUpperCase()+" - " + "Report ID : " + reportRuntime.getReportID() + " DATA IS EMPTY")); - logger.debug(EELFLoggerDelegate.debugLogger, ("QUERY - " + reportSQL)); - logger.debug(EELFLoggerDelegate.debugLogger, ("********************************************************************************")); + printDebugLogSeparatorLine(); + logger.debug(EELFLoggerDelegate.debugLogger, (chartType.toUpperCase()+" - " + REPORT_ID + reportRuntime.getReportID() + " DATA IS EMPTY")); + logger.debug(EELFLoggerDelegate.debugLogger, (QUERY + reportSQL)); + printDebugLogSeparatorLine(); } } else if(chartType.equals(AppConstants.GT_HIERARCHICAL)||chartType.equals(AppConstants.GT_HIERARCHICAL_SUNBURST)) { String reportSQL = reportRuntime.getWholeSQL(); @@ -345,16 +204,14 @@ public class ChartD3Helper { ds = ConnectionUtils.getDataSet(reportSQL, dbInfo); } } catch (RaptorException ex) { - //throw new RaptorException("Error while loading chart data", ex); - logger.error(EELFLoggerDelegate.debugLogger, ("********************************************************************************")); - logger.error(EELFLoggerDelegate.debugLogger, (chartType.toUpperCase()+" - " + "Report ID : " + reportRuntime.getReportID() + " ERROR THROWN FOR GIVEN QUERY ")); - logger.error(EELFLoggerDelegate.debugLogger, ("QUERY - " + reportRuntime.getWholeSQL())); + printDebugLogSeparatorLine(); + logger.error(EELFLoggerDelegate.debugLogger, (chartType.toUpperCase()+" - " + REPORT_ID + reportRuntime.getReportID() + " ERROR THROWN FOR GIVEN QUERY ")); + logger.error(EELFLoggerDelegate.debugLogger, (QUERY + reportRuntime.getWholeSQL())); logger.error(EELFLoggerDelegate.debugLogger, ("ERROR STACK TRACE" + ex.getMessage())); - logger.error(EELFLoggerDelegate.debugLogger, ("********************************************************************************")); + printDebugLogSeparatorLine(); } if(ds==null) { - //displayChart = false; if(chartType.equals(AppConstants.GT_ANNOTATION_CHART)) ds = new DataSet(); else @@ -370,11 +227,10 @@ public class ChartD3Helper { boolean hasCustomizedChartColor = false; int flag = 0; flag = hasCategoryAxis?1:0; - Object uniqueElements [] = null; + Object[] uniqueElements = null; ArrayList uniqueElementsList = new ArrayList(); - Object uniqueXAxisElements[] = null; - ArrayList ts = new ArrayList(); - //Set<String> ts1 = new HashSet(); + Object[] uniqueXAxisElements = null; + ArrayList ts = new ArrayList(); ArrayList<String> ts1 = new ArrayList(); HashMap<String, String> columnMap = new HashMap(); String uniqueXAxisStr = ""; @@ -388,10 +244,10 @@ public class ChartD3Helper { uniqueXAxisElements = ts1.toArray(); if(flag == 1) { - StringBuffer catStr = new StringBuffer(""); + StringBuilder catStr; String color=""; for (int i = 0; i < ds.getRowCount(); i++) { - catStr = new StringBuffer(""); + catStr = new StringBuilder(""); catStr.append(ds.getString(i, 2)); try { if(ds.getString(i, "chart_color")!=null) { @@ -400,7 +256,7 @@ public class ChartD3Helper { catStr.append("|"+color); } } catch (ArrayIndexOutOfBoundsException ex) { - //System.out.println("No Chart Color"); + logger.debug(EELFLoggerDelegate.debugLogger, ex.getMessage()); } if(catStr.length()>0) { @@ -540,12 +396,9 @@ public class ChartD3Helper { for (int i = 0; i < uniqueElements.length; i++) { if(multipleSeries && (nvl(chartRightAxisLabel).length() > 0)) - dataSeriesMap.put((String) uniqueElements[i], new HashMap<String, String>()); - //dataSeries.add(new StringBuffer(" { \"type\":\"bar\", \"key\": \""+ uniqueElements[i] +"\", \"yAxis\": \""+(i+1)+"\", \"values\": [")); + dataSeriesMap.put((String) uniqueElements[i], new HashMap<String, String>()); else - dataSeriesMap.put((String) uniqueElements[i], new HashMap<String, String>()); - - //dataSeries.add(new StringBuffer(" { \"type\":\"bar\", \"key\": \""+ uniqueElements[i] +"\", \"yAxis\": \""+(1)+"\", \"values\": [")); + dataSeriesMap.put((String) uniqueElements[i], new HashMap<String, String>()); } String dateStr = null; @@ -606,15 +459,6 @@ public class ChartD3Helper { break; } } - /*for(int f=0; f<uniqueElementsList.size() && f < pos; f++) - { - StringBuffer strBuf = ((StringBuffer)dataSeries.get(j)); - if(strBuf.indexOf((String)uniqueElementsList.get(f)) < 0 ) { - dataSeriesStrMap.put((String)uniqueElementsList.get(f), value); - //((StringBuffer) dataSeries.get(j)).append ("{ \"x\":\"" + (String)uniqueElementsList.get(f) + "\" , \"y\": null },"); - } - }*/ - //} dateStrList.add("'"+dateStr+"'"); //uniqueElement = (String)uniqueElements[j]; @@ -633,45 +477,36 @@ public class ChartD3Helper { //flagNull = 1; } /* For Non-date type value enclose with double quotes */ - // ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":\"" + dateStr + "\" , \"y\":" + (flagNull==0?(YAXISDOUBLENUM>0?YAXISDOUBLENUM:YAXISNUM):null) +"}, "); + if(logScale) { - // ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":\"" + dateStr + "\" , \"y\":" + (flagNull==0?(YAXISDOUBLENUM>0?new Double(Math.log10(YAXISDOUBLENUM)).toString():(YAXISNUM>0?new Double(Math.log10(new Integer(YAXISNUM).doubleValue())).toString():null)):null) +"}, "); + valueDataSeries = "{ \"x\":\"" + dateStr + "\" , \"y\":" + (flagNull == 0 ? (YAXISDOUBLENUM>0?new Double(Math.log10(YAXISDOUBLENUM)).toString():new Double(Math.log10(new Double(YAXISNUM>0?YAXISNUM:1).doubleValue())).toString()): null) +"}, "; dataSeriesStrMap.put(dateStr, valueDataSeries); } else { - //((StringBuffer) dataSeries.get(j)).append ("{ \"x\":\"" + dateStr + "\" , \"y\":" + (flagNull==0?(YAXISDOUBLENUM>0?YAXISDOUBLENUM:YAXISNUM):null) +"}, "); valueDataSeries = "{ \"x\":\"" + dateStr + "\" , \"y\":" + (flagNull == 0 ? (YAXISDOUBLENUM>0?YAXISDOUBLENUM:YAXISNUM): null) +"}, "; dataSeriesStrMap.put(dateStr, valueDataSeries); } dataSeriesOverAllMap.put(uniqueElements[j], dataSeriesStrMap); - - //((StringBuffer) dataSeries.get(j)).append ("{ \"x\":\"" + dateStr + "\" , \"y\":\"" + ds.getString(i, columnMap.get((String)uniqueElements[j])) +"\"}, "); + } else { if(!barRealTimeAxis) { // true - non-time if(!dateStrList.contains(new Long(date.getTime()).toString())) { dateStrList.add(new Long(date.getTime()).toString()); for (int k = 0; k < uniqueElements.length; k++) { - //((StringBuffer) dataSeries.get(k)).append ("{ \"x\":" + date.getTime() + " , \"y\":null}, "); HashMap<String, String> dataMap = dataSeriesMap.get((String) uniqueElements[k]); dataMap.put(date.getTime()+"", "null"); } } } - //if(ds.getString(i, 2).equals(uniqueElements[j])) { - /*if(!dateStrList.contains(new Long(date.getTime()).toString())) { - for (int k = 0; k < uniqueElements.length; k++) { - ((StringBuffer) dataSeries.get(k)).append ("{ \"x\":" + date.getTime() + " , \"y\":null}, "); - } - }*/ - //dateStrList.add(new Long(date.getTime()).toString()); + try { YAXISNUM = Integer.parseInt(ds.getString(i, columnMap.get(((hasCustomizedChartColor||nvl(chartRightAxisLabel).length()>0) && (uniqueElement.lastIndexOf("|") != -1)?uniqueElement.substring(0, uniqueElement.lastIndexOf("|")):uniqueElement)))); dateStrList.add(new Long(date.getTime()).toString()); - //if(MAXNUM < YAXISNUM) MAXNUM = YAXISNUM; + if(MAXDOUBLENUM < YAXISNUM) MAXDOUBLENUM = YAXISNUM; } catch (NumberFormatException ex) { try { @@ -692,9 +527,7 @@ public class ChartD3Helper { } - // ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + date.getTime() + " , \"y\":" + (flagNull==0?(YAXISDOUBLENUM>0?YAXISDOUBLENUM:YAXISNUM):null) +"}, "); - //((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + date.getTime() + " , \"y\":" + ds.getString(i, columnMap.get((String)uniqueElements[j])) +"}, "); } //} } @@ -740,15 +573,7 @@ public class ChartD3Helper { break; } } - /*for(int f=0; f<uniqueElementsList.size() && f < pos; f++) - { - StringBuffer strBuf = ((StringBuffer)dataSeries.get(j)); - if(strBuf.indexOf((String)uniqueElementsList.get(f)) < 0 ) { - dataSeriesStrMap.put((String)uniqueElementsList.get(f), value); - //((StringBuffer) dataSeries.get(j)).append ("{ \"x\":\"" + (String)uniqueElementsList.get(f) + "\" , \"y\": null },"); - } - }*/ - //} + if(ds.getString(i, 2).equals(((hasCustomizedChartColor||nvl(chartRightAxisLabel).length()>0) && (uniqueElement.lastIndexOf("|") != -1) ?uniqueElement.substring(0, uniqueElement.lastIndexOf("|")):uniqueElement))) { dateStrList.add("'"+dateStr+"'"); @@ -769,32 +594,24 @@ public class ChartD3Helper { if(logScale) { if(timeAxis) { - //((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + dateStr + " , \"y\":" + (flagNull == 0 ? (YAXISDOUBLENUM>0?new Double(Math.log10(YAXISDOUBLENUM)).toString():new Double(Math.log10(new Double(YAXISNUM>0?YAXISNUM:1).doubleValue())).toString()): null) +"}, "); valueDataSeries = "{ \"x\":" + dateStr + " , \"y\":" + (flagNull == 0 ? (YAXISDOUBLENUM>0?new Double(Math.log10(YAXISDOUBLENUM)).toString():new Double(Math.log10(new Double(YAXISNUM>0?YAXISNUM:1).doubleValue())).toString()): null) +"}, "; dataSeriesStrMap.put(dateStr, valueDataSeries); } else { - // ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":\"" + dateStr + "\" , \"y\":" + (flagNull == 0 ? (YAXISDOUBLENUM>0?new Double(Math.log10(YAXISDOUBLENUM)).toString():new Double(Math.log10(new Double(YAXISNUM>0?YAXISNUM:1).doubleValue())).toString()): null) +"}, "); valueDataSeries = "{ \"x\":\"" + dateStr + "\" , \"y\":" + (flagNull == 0 ? (YAXISDOUBLENUM>0?new Double(Math.log10(YAXISDOUBLENUM)).toString():new Double(Math.log10(new Double(YAXISNUM>0?YAXISNUM:1).doubleValue())).toString()): null) +"}, "; dataSeriesStrMap.put(dateStr, valueDataSeries); } } else { if(timeAxis) { - //((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + dateStr + " , \"y\":" + (flagNull == 0 ? (YAXISDOUBLENUM>0?YAXISDOUBLENUM:YAXISNUM): null) +"}, "); valueDataSeries = "{ \"x\":" + dateStr + " , \"y\":" + (flagNull == 0 ? (YAXISDOUBLENUM>0?YAXISDOUBLENUM:YAXISNUM): null) +"}, "; dataSeriesStrMap.put(dateStr, valueDataSeries); } else { - //((StringBuffer) dataSeries.get(j)).append ("{ \"x\":\"" + dateStr + "\" , \"y\":" + (flagNull == 0 ? (YAXISDOUBLENUM>0?YAXISDOUBLENUM:YAXISNUM): null) +"}, "); valueDataSeries = "{ \"x\":\"" + dateStr + "\" , \"y\":" + (flagNull == 0 ? (YAXISDOUBLENUM>0?YAXISDOUBLENUM:YAXISNUM): null) +"}, "; dataSeriesStrMap.put(dateStr, valueDataSeries); } } - - /*if(ds.getString(i, 2).equals(uniqueElements[j])) { - dateStrList.add("'"+dateStr+"'"); - ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":\"" + dateStr + "\" , \"y\":\"" + ds.getString(i, 3) +"\"}, "); - */ + } dataSeriesOverAllMap.put(uniqueElements[j], dataSeriesStrMap); } else { @@ -803,7 +620,6 @@ public class ChartD3Helper { if(!dateStrList.contains(new Long(date.getTime()).toString())) { dateStrList.add(new Long(date.getTime()).toString()); for (int k = 0; k < uniqueElements.length; k++) { - //((StringBuffer) dataSeries.get(k)).append ("{ \"x\":" + date.getTime() + " , \"y\":null}, "); HashMap<String, String> dataMap = dataSeriesMap.get((String) uniqueElements[k]); dataMap.put(date.getTime()+"", "null"); @@ -841,10 +657,7 @@ public class ChartD3Helper { // .println(dataMap + " " + dataSeriesMap); //} } - // ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + date.getTime() + " , \"y\":" + (flagNull == 0 ? (YAXISDOUBLENUM>0?YAXISDOUBLENUM:YAXISNUM): null) +"}, "); - - //((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + date.getTime() + " , \"y\":" + ds.getString(i, 3) +"}, "); } else if (AppUtils.nvl(ds.getString(i, 2)).length()<=0) { dateStrList.add(new Long(date.getTime()).toString()); HashMap<String, String> dataMap1 = null; @@ -874,23 +687,8 @@ public class ChartD3Helper { } } } - - StringBuffer dateStrBuf = new StringBuffer(""); - /*if(count == 1) { - Long initialDate = Long.parseLong((String)ds.getString(0, 0)); - Long endDate = Long.parseLong((String) ds.getString(ds.getRowCount(), 0)); - java.util.Date date1 = null; - - while ( initialDate <= endDate) { - //System.out.println("********** " + df.format(initialDate)); - date1 = new java.util.Date(initialDate.longValue() * 1000); - initialDate = initialDate + HOUR; - - dateStrBuf.append(initialDate+","); - sortSet.add(""+initialDate); - //DateUtils.addHours(date1, 1); - } - }*/ + + StringBuilder dateStrBuf = new StringBuilder(""); if(dateStrList.size()>0) { SortedSet<String> s = Collections.synchronizedSortedSet(dateStrList); @@ -964,7 +762,6 @@ public class ChartD3Helper { //if(strBuf.toString().indexOf((String) dateAllElements[j]) == -1) { if(!dataMap.containsKey((String) dateAllElements[j])) { dataMap.put((String) dateAllElements[j], "null"); - //((StringBuffer) dataSeries.get(i)).append ("{ \"x\":" + dateAllElements[j] + " , \"y\":null}, "); } } } @@ -980,19 +777,14 @@ public class ChartD3Helper { valueStr = dataSeriesMap.get((String)uniqueElements[i]).get(keySortedList.get(k)); if(valueStr.equals("null")) valueStr = null; - else { - //if(logScale) - //valueStr = new Double(Math.log10(new Double(valueStr).doubleValue())).toString(); - } + ((StringBuffer) dataSeries.get(i)).append ("{ \"x\":" + keySortedList.get(k) + " , \"y\":" + valueStr +"}, "); - // ((StringBuffer) dataSeries.get(i)).append ("{ \"x\":" + keySortedList.get(k) + " , \"y\":" + valueStr +"}, "); + } - - // ((StringBuffer) dataSeries.get(j)).append ("{ \"x\":" + date.getTime() + " , \"y\":" + (flagNull == 0 ? (YAXISDOUBLENUM>0?YAXISDOUBLENUM:YAXISNUM): null) +"}, "); + } for (int i = 0; i < uniqueElements.length; i++) { - StringBuffer strBuf = ((StringBuffer) dataSeries.get(i)); ((StringBuffer) dataSeries.get(i)).deleteCharAt(((StringBuffer) dataSeries.get(i)).lastIndexOf(",")); if(i < (uniqueElements.length -1) ) { ((StringBuffer) dataSeries.get(i)).append("] } , \n"); @@ -1235,44 +1027,7 @@ public class ChartD3Helper { uniqueElementsList.addAll(ts1); uniqueXAxisElements = ts1.toArray(); //test start - /* int TOTAL = 0; - int VALUE = 0; - int flagNull = 0; - String KEY = ""; - String COLOR = ""; - TreeSet<String> colorList = new TreeSet<String>(); - for (int i = 0; i < ds.getRowCount(); i++) { - VALUE = 0; - try { - VALUE = Integer.parseInt(ds.getString(i, 2)); - TOTAL = TOTAL+VALUE; - } catch (NumberFormatException ex) { - flagNull = 1; - } - KEY = ds.getString(i, 0); - try { - if(ds.getString(i, "chart_color")!=null) { - colorList.add(KEY+"|"+ds.getString(i, "chart_color")); - } - } catch (ArrayIndexOutOfBoundsException ex) { - System.out.println("No Chart Color"); - } - wholeScript.append("{ \""+ "key" +"\":\""+ KEY+"\", \""+ "y" +"\":"+VALUE+"}, \n"); - - } - StringBuffer color = new StringBuffer(""); - if(colorList.size()>0) { - SortedSet<String> s = Collections.synchronizedSortedSet(colorList); - Object[] colorElements = (Object[]) s.toArray(); - - String element = ""; - - for (int i = 0; i < colorElements.length; i++) { - element = ((String)colorElements[i]); - color.append("'"+element.substring(element.indexOf("|")+1)+"',"); - } - color.deleteCharAt(color.length()-1); - }*/ + //test end boolean hasCustomizedChartColor = false; @@ -2181,7 +1936,7 @@ public class ChartD3Helper { if(dataStrBuf.lastIndexOf(",")!= -1) dataStrBuf.deleteCharAt(dataStrBuf.lastIndexOf(",")); - wholeScript = new StringBuffer(""); + wholeScript = new StringBuilder(""); wholeScript.append("<!DOCTYPE html>\n"); wholeScript.append("<html>\n"); wholeScript.append(" <head>\n"); @@ -2424,9 +2179,9 @@ public class ChartD3Helper { //Labels here dct = null; - StringBuffer labelStrBuf = new StringBuffer(""); - StringBuffer colorsStrBuf = new StringBuffer(""); - StringBuffer visibilityStrBuf = new StringBuffer(""); + StringBuilder labelStrBuf = new StringBuilder(""); + StringBuilder colorsStrBuf = new StringBuilder(""); + StringBuilder visibilityStrBuf = new StringBuilder(""); int countChartValues = 0; for (Iterator iter = l.iterator(); iter.hasNext();) { dct = (DataColumnType) iter.next(); @@ -2706,9 +2461,9 @@ public class ChartD3Helper { //Labels here dct = null; - labelStrBuf = new StringBuffer(""); - colorsStrBuf = new StringBuffer(""); - visibilityStrBuf = new StringBuffer(""); + labelStrBuf = new StringBuilder(""); + colorsStrBuf = new StringBuilder(""); + visibilityStrBuf = new StringBuilder(""); countChartValues = 0; for (Iterator iter = l.iterator(); iter.hasNext();) { dct = (DataColumnType) iter.next(); @@ -3078,10 +2833,10 @@ public class ChartD3Helper { wholeScript.append("return data; } </script></body>\n"); } else if (chartType.equals(AppConstants.GT_HIERARCHICAL_SUNBURST)) { - - StringBuffer dataStr = new StringBuffer(""); - StringBuffer groupBuffer = new StringBuffer(""); - StringBuffer s = new StringBuffer(""); + + StringBuilder dataStr = new StringBuilder(""); + StringBuilder groupBuffer = new StringBuilder(""); + StringBuilder s = new StringBuilder(""); dataStr.append("{"); dataStr.append(" \"xxxxxx\":{\n"); String mid = ""; @@ -3127,10 +2882,10 @@ public class ChartD3Helper { System.out.println("Exception "); } } else if (chartType.equals(AppConstants.GT_HIERARCHICAL)) { - - StringBuffer dataStr = new StringBuffer(""); - StringBuffer groupBuffer = new StringBuffer(""); - StringBuffer s = new StringBuffer(""); + + StringBuilder dataStr = new StringBuilder(""); + StringBuilder groupBuffer = new StringBuilder(""); + StringBuilder s = new StringBuilder(""); dataStr.append("{"); dataStr.append(" \"groups\":["); @@ -3149,7 +2904,7 @@ public class ChartD3Helper { s.append("{ \"name\": \""+ ds.getString(i,"ei1") +"\" , \"group\":"+ ds.getString(i,"groups") +", \"level\":2 }"); if (i < (rowCount-1)) s.append(","); dataStr.append(s); - s = new StringBuffer(""); + s = new StringBuilder(""); } dataStr.append("],"); @@ -3158,7 +2913,7 @@ public class ChartD3Helper { s.append("{ \"source\": "+ ds.getString(i,"source") +" , \"target\":"+ ds.getString(i,"target") +", \"value\":2 }"); if (i < (rowCount-1)) s.append(","); dataStr.append(s); - s = new StringBuffer(""); + s = new StringBuilder(""); } dataStr.append("]}"); try { @@ -3221,10 +2976,10 @@ public class ChartD3Helper { String dbInfo = reportRuntime.getDBInfo(); DataSet ds = ConnectionUtils.getDataSet(sql, dbInfo); if(ds.getRowCount()<=0) { - logger.debug(EELFLoggerDelegate.debugLogger, ("********************************************************************************")); - logger.debug(EELFLoggerDelegate.debugLogger, (getChartType().toUpperCase()+" - " + "Report ID : " + reportRuntime.getReportID() + " DATA IS EMPTY" )); - logger.debug(EELFLoggerDelegate.debugLogger, ("QUERY - " + sql)); - logger.debug(EELFLoggerDelegate.debugLogger, ("********************************************************************************")); + printDebugLogSeparatorLine(); + logger.debug(EELFLoggerDelegate.debugLogger, (getChartType().toUpperCase()+" - " + REPORT_ID + reportRuntime.getReportID() + " DATA IS EMPTY" )); + logger.debug(EELFLoggerDelegate.debugLogger, (QUERY + sql)); + printDebugLogSeparatorLine(); } return ds; @@ -3265,11 +3020,11 @@ public class ChartD3Helper { reportSQL = reportSQL + " ORDER BY 1" ; } } - reportRuntime.setWholeSQL(reportSQL); - - logger.debug(EELFLoggerDelegate.debugLogger, (" *************************************************************************************** ")); + reportRuntime.setWholeSQL(reportSQL); + + printDebugLogSeparatorLine(); logger.debug(EELFLoggerDelegate.debugLogger, ("WHOLE_SQL" + reportSQL)); - logger.debug(EELFLoggerDelegate.debugLogger, (" *************************************************************************************** ")); + printDebugLogSeparatorLine(); if (reportRuntime.getFormFieldList() != null) { for (Iterator iter = reportRuntime.getFormFieldList().getFormField().iterator(); iter.hasNext();) { @@ -3296,9 +3051,9 @@ public class ChartD3Helper { logger.debug(EELFLoggerDelegate.debugLogger, ("SQL " + reportSQL)); String legendCol = "1 a"; // String valueCol = "1"; - StringBuffer groupCol = new StringBuffer(); - StringBuffer seriesCol = new StringBuffer(); - StringBuffer valueCols = new StringBuffer(); + StringBuilder groupCol = new StringBuilder(); + StringBuilder seriesCol = new StringBuilder(); + StringBuilder valueCols = new StringBuilder(); for (Iterator iter = reportCols.iterator(); iter.hasNext();) { DataColumnType dc = (DataColumnType) iter.next(); @@ -3502,7 +3257,7 @@ public class ChartD3Helper { colName = Utils.replaceInString(colName, "to_number", "TO_NUMBER"); //reportSQL = reportSQL.replaceAll("[\\s]*\\(", "("); colName = colName.replaceAll(",[\\s]*\\(", ",("); - StringBuffer colNameBuf = new StringBuffer(colName); + StringBuilder colNameBuf = new StringBuilder(colName); int pos = 0, posFormatStart = 0, posFormatEnd = 0; String format = ""; @@ -4057,7 +3812,7 @@ public class ChartD3Helper { if(request.getParameterValues(formField) != null && isMultiValue ) { String[] vals = request.getParameterValues(formField); - StringBuffer value = new StringBuffer(""); + StringBuilder value = new StringBuilder(""); if(!AppUtils.getRequestFlag(request, AppConstants.RI_RESET_ACTION)) { if ( isMultiValue ) { @@ -4093,7 +3848,6 @@ public class ChartD3Helper { //value = value.substring(0 , value.length()); valuesMap.put(fieldNameMap.get(formField), value.toString()); - value = new StringBuffer(""); } else if(request.getParameter(formField) != null) { if(isTextArea) { String value = ""; diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/runtime/ChartWebRuntime.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/runtime/ChartWebRuntime.java index c0f0cd96..fcb0541e 100644 --- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/runtime/ChartWebRuntime.java +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/runtime/ChartWebRuntime.java @@ -412,13 +412,8 @@ public class ChartWebRuntime implements Serializable { ChartD3Helper chartHelper = new ChartD3Helper(reportRuntime); chartHelper.setChartType(reportRuntime.getChartType()); - try { - return chartHelper.createVisualization(reportRuntime, chartOptionsMap, request); - } catch(RaptorException ex) { - ex.printStackTrace(); - } - return ""; - + + return chartHelper.createVisualization(reportRuntime, chartOptionsMap, request); } public String returnChartJSON(HashMap<String,String> chartOptionsMap, HttpServletRequest request, boolean showData) { |