summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/model/base/ReportWrapper.java
blob: 27ad62f9af2aa1f653c655c1bcc1bdc24d1e76d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
/*
 * ============LICENSE_START==========================================
 * ONAP Portal SDK
 * ===================================================================
 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
 * ===================================================================
 *
 * Unless otherwise specified, all software contained herein is licensed
 * under the Apache License, Version 2.0 (the "License");
 * you may not use this software except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *             http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * 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.
 *
 * Unless otherwise specified, all documentation contained herein is licensed
 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
 * you may not use this documentation except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *             https://creativecommons.org/licenses/by/4.0/
 *
 * Unless required by applicable law or agreed to in writing, documentation
 * 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============================================
 *
 *
 */
package org.onap.portalsdk.analytics.model.base;

import java.io.Serializable;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;
import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletRequest;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.transform.stream.StreamResult;

import org.onap.portalsdk.analytics.error.RaptorException;
import org.onap.portalsdk.analytics.error.RaptorRuntimeException;
import org.onap.portalsdk.analytics.error.UserDefinedException;
import org.onap.portalsdk.analytics.model.DataCache;
import org.onap.portalsdk.analytics.model.ReportLoader;
import org.onap.portalsdk.analytics.model.definition.TableSource;
import org.onap.portalsdk.analytics.model.runtime.FormField;
import org.onap.portalsdk.analytics.model.runtime.ReportParamValues;
import org.onap.portalsdk.analytics.model.runtime.ReportRuntime;
import org.onap.portalsdk.analytics.system.AppUtils;
import org.onap.portalsdk.analytics.system.ConnectionUtils;
import org.onap.portalsdk.analytics.system.DbUtils;
import org.onap.portalsdk.analytics.system.Globals;
import org.onap.portalsdk.analytics.util.AppConstants;
import org.onap.portalsdk.analytics.util.CachingUtils;
import org.onap.portalsdk.analytics.util.DataSet;
import org.onap.portalsdk.analytics.util.RemDbInfo;
import org.onap.portalsdk.analytics.util.SQLCorrector;
import org.onap.portalsdk.analytics.util.Utils;
import org.onap.portalsdk.analytics.xmlobj.ChartAdditionalOptions;
import org.onap.portalsdk.analytics.xmlobj.ChartDrillFormfield;
import org.onap.portalsdk.analytics.xmlobj.ChartDrillOptions;
import org.onap.portalsdk.analytics.xmlobj.ColFilterList;
import org.onap.portalsdk.analytics.xmlobj.ColFilterType;
import org.onap.portalsdk.analytics.xmlobj.CustomReportType;
import org.onap.portalsdk.analytics.xmlobj.DashboardEditorList;
import org.onap.portalsdk.analytics.xmlobj.DashboardReports;
import org.onap.portalsdk.analytics.xmlobj.DashboardReportsNew;
import org.onap.portalsdk.analytics.xmlobj.DataColumnList;
import org.onap.portalsdk.analytics.xmlobj.DataColumnType;
import org.onap.portalsdk.analytics.xmlobj.DataSourceList;
import org.onap.portalsdk.analytics.xmlobj.DataSourceType;
import org.onap.portalsdk.analytics.xmlobj.DataminingOptions;
import org.onap.portalsdk.analytics.xmlobj.FormFieldList;
import org.onap.portalsdk.analytics.xmlobj.FormFieldType;
import org.onap.portalsdk.analytics.xmlobj.FormatList;
import org.onap.portalsdk.analytics.xmlobj.FormatType;
import org.onap.portalsdk.analytics.xmlobj.JavascriptItemType;
import org.onap.portalsdk.analytics.xmlobj.JavascriptList;
import org.onap.portalsdk.analytics.xmlobj.Marker;
import org.onap.portalsdk.analytics.xmlobj.ObjectFactory;
import org.onap.portalsdk.analytics.xmlobj.PDFAdditionalOptions;
import org.onap.portalsdk.analytics.xmlobj.PredefinedValueList;
import org.onap.portalsdk.analytics.xmlobj.ReportMap;
import org.onap.portalsdk.analytics.xmlobj.Reports;
import org.onap.portalsdk.analytics.xmlobj.SemaphoreList;
import org.onap.portalsdk.analytics.xmlobj.SemaphoreType;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.portalsdk.core.util.SecurityCodecUtil;
import org.owasp.esapi.ESAPI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**<HR/>
 * This class is part of <B><I>RAPTOR (Rapid Application Programming Tool for OLAP Reporting)</I></B><BR/>
 * <HR/>
 *
 * --------------------------------------------------------------------------------------------------<BR/>
 * <B>ReportWrapper.java</B> - This is the base class for the RAPTOR. This involves in creating,<BR/>
 * modifying, running RAPTOR reports.<BR/>
 * --------------------------------------------------------------------------------------------------<BR/>
 *
 *
 * <U>Change Log</U><BR/><BR/>
 *
 * 31-Aug-2009 : Version 8.5.1 (Sundar);<UL><LI> All the elements in the meta xml is copied to the target reports. </LI></UL>
 * 18-Aug-2009 : Version 8.5.1 (Sundar);<UL><LI> request Object is passed to prevent caching user/roles - Datamining/Hosting. </LI></UL>
 * 27-Jul-2009 : Version 8.4 (Sundar); <UL><LI> verifySQLBasedReportAccess method checks for Admin user instead of super user. </LI></UL>
 * 09-Jul-2009 : Version 8.4 (Sundar); <UL><LI> Bug due to parsing and removing formfields from "and" is bulletproofed to the right "and" to which the formfield is associated. </LI></UL>
 * 08-Jul-2009 : Version 8.4 (Sundar); <UL><LI> Bug due to parsing and removing formfields when there is no parameter for Daytona specific database is resolved. </LI></UL>
 * 29-Jun-2009 : Version 8.4 (Sundar); <UL><LI> isLastSeriesALineChart() and setLastSeriesALineChart(String value) method have been added for the Bar Chart enhancements. </LI></UL>
 * 23-Jun-2009 : Version 8.4 (Sundar); <UL><LI> check for cr.getChartAdditionalOptions() for null value is added.</LI></UL>
 * 22-Jun-2009 : Version 8.4 (Sundar); <UL><LI> Wrapper functions to call JAXB were added. These Wrapper
 * functions are related to the Pareto chart, Time Difference Chart, Multiple Pie Chart and generic Chart Options.</LI></UL>
 *
 */

@Component
public class ReportWrapper extends org.onap.portalsdk.analytics.RaptorObject implements Serializable{

    private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ReportWrapper.class);

	protected static RemDbInfo remDbInfo;

	@SuppressWarnings("static-access")
	@Autowired
    public void setRemDbInfo(RemDbInfo remDbInfo) {
		this.remDbInfo = remDbInfo;
	}

    protected CustomReportType cr = null;

    protected Vector allColumns = null;

    protected Vector allVisibleColumns = null;

    protected Vector allFilters = null;

    protected String generatedSQL = null;

    protected String generatedChartSQL = null;

	protected String wholeSQL = null;


    protected String reportID = null;

    protected String menuID = "";

    protected boolean menuApproved = false;

    protected String reportDefType = "";

    protected ReportSecurity reportSecurity = null;

    protected String reportSQLWithRowNum = null;

    protected String reportSQLOnlyFirstPart = null;

    public ReportWrapper() {
        super();
    }
	
    private ReportWrapper(CustomReportType cr, String reportID, ReportSecurity reportSecurity) {
        super();

        if (reportID == null)
            reportID = "-1";

        this.cr = cr;
        this.reportID = reportID;

        this.reportSecurity = reportSecurity;
	}

    public ReportWrapper(ReportWrapper rw) {
		this(rw.getCustomReport(), 
                rw.getReportID(), rw.reportSecurity);

        this.menuID = rw.getMenuID();
        this.menuApproved = rw.isMenuApproved();

        this.reportDefType = rw.getReportDefType();
	}
    public ReportWrapper(CustomReportType cr, String reportID, String ownerID, String createID,
            String createDate, String updateID, String updateDate, String menuID,
            boolean menuApproved) throws RaptorException {
        this(cr, reportID, null);

        if (ownerID == null && !"-1".equals(reportID)) {
            try {

                String rSql = Globals.getReportWrapperFormat();
                rSql = rSql.replace("[Globals.getTimeFormat()]", Globals.getTimeFormat());
                rSql = rSql.replace("[reportID]", reportID);

                DataSet ds = DbUtils
                        .executeQuery(rSql);

                ownerID = ds.getString(0, 0);
                createID = ds.getString(0, 1);
                createDate = ds.getString(0, 2);
                updateID = ds.getString(0, 3);
                updateDate = ds.getString(0, 4);
                menuID = nvl(ds.getString(0, 5));
                menuApproved = nvl(ds.getString(0, 6)).equals("Y");
            } catch (Exception e) {
                String eMsg = "ReportWrapper.ReportWrapper: Unable to load report record details. Exception: ";
                logger.error(EELFLoggerDelegate.debugLogger, ("[EXCEPTION ENCOUNTERED IN RAPTOR] " + eMsg), e);
                throw new RaptorRuntimeException(eMsg);
            }
        }
        this.menuID = nvl(menuID);
        this.menuApproved = menuApproved;

        if (!"-1".equals(reportID)) {
            updateReportDefType();
        }

        reportSecurity = new ReportSecurity(reportID, ownerID, createID, createDate, updateID,
                updateDate, cr.isPublic());
    } // ReportWrapper

    public CustomReportType getCustomReport() {
        return cr;
    }

    public String getReportID() {
        return reportID;
    }

    public String getMenuID() {
        return menuID;
    }

    public boolean checkMenuIDSelected(String chkMenuID) {
        return ("|" + menuID + "|").indexOf("|" + chkMenuID + "|") >= 0;
    }

    public boolean isMenuApproved() {
        return menuApproved;
    }

    public String getReportDefType() {
        return reportDefType;
    }

    public void setMenuID(String menuID) {
        this.menuID = menuID;
    }

    public void setMenuApproved(boolean menuApproved) {
        this.menuApproved = menuApproved;
    }

    public void setReportDefType(String reportDefType) {
        this.reportDefType = reportDefType;
    }

    public void updateReportDefType() {
        this.reportDefType = (nvl(cr.getReportSQL()).length() > 0)
                ? ((cr.getDataminingOptions() != null && nvl(cr.getDataminingOptions().getClassifier()).length() > 0)
                        ? AppConstants.RD_SQL_BASED_DATAMIN
                        : AppConstants.RD_SQL_BASED)
                : AppConstants.RD_VISUAL;
    }

    public String getJavascriptElement() {
        return cr.getJavascriptElement();
    }

    public int getPageSize() {
        return cr.getPageSize() == null ? 50 : cr.getPageSize();
    }

    public int getMaxRowsInExcelDownload() {
        return cr.getMaxRowsInExcelDownload() == null ? 500 : cr.getMaxRowsInExcelDownload();
    }

    public boolean isDisplayFolderTree() {
        return cr.isDisplayFolderTree() != null ? cr.isDisplayFolderTree().booleanValue() : false;
    }

    public boolean isHideFormFieldAfterRun() {
        return cr.isHideFormFieldAfterRun() != null ? cr.isHideFormFieldAfterRun().booleanValue() : false;
    }

    public void setHideFormFieldAfterRun(boolean hideFormFieldAfterRun) {
        cr.setHideFormFieldAfterRun(hideFormFieldAfterRun);
    }

    public boolean isReportInNewWindow() {
        return cr.isReportInNewWindow() != null ? cr.isReportInNewWindow().booleanValue() : false;
    }

    public String getReportType() {
        return cr.getReportType();
    }

    public String getReportName() {
        return cr.getReportName();
    }

    public String getDBInfo() {
        return cr.getDbInfo();
    }

    public String getDBType() {
        return cr.getDbType();
    }

    public boolean isDrillDownURLInPopupPresent() {
        return cr.isDrillURLInPoPUpPresent() != null ? cr.isDrillURLInPoPUpPresent().booleanValue() : false;
    }

    public void setDrillDownURLInPopupPresent(boolean value) {
        cr.setDrillURLInPoPUpPresent(value);
    }

    public String getReportDescr() {
        return cr.getReportDescr();
    }

    public String getChartType() {
        return cr.getChartType();
    }

    public boolean displayChartTitle() {
        return cr.isShowChartTitle();
    }

    public void setShowChartTitle(boolean showTitle) {
        cr.setShowChartTitle(showTitle);
    }

    public String getChartTypeFixed() {
        return cr.getChartTypeFixed();
    }

    public boolean isChartTypeFixed() {
        return nvl(cr.getChartTypeFixed()).length() > 0 ? "Y".equals(cr.getChartTypeFixed())
                : (!Globals.getAllowRuntimeChartSel());
    }

    public String getChartLeftAxisLabel() {
        return cr.getChartLeftAxisLabel();
    }

    public String getChartRightAxisLabel() {
        return cr.getChartRightAxisLabel();
    }

    public String getChartWidth() {
        return cr.getChartWidth();
    }

    public int getChartWidthAsInt() {
        return getIntValue(cr.getChartWidth(), Globals.getDefaultChartWidth());
    }

    public String getChartHeight() {
        return cr.getChartHeight() == null ? "500" : cr.getChartHeight();
    }


    public boolean displayPieOrderinRunPage() {
        String s = "";
        s = (cr.getChartAdditionalOptions() != null) ? cr.getChartAdditionalOptions().getChartMultiplePieOrder() : "";
        if (nvl(s).indexOf("|") != -1) {
            s = s.substring(s.indexOf("|") + 1);
            return getFlagInBoolean(s);
        } else
            return false;
    }

    public boolean isMultiplePieOrderByRow() {
        String s = "";
        s = (cr.getChartAdditionalOptions() != null) ? cr.getChartAdditionalOptions().getChartMultiplePieOrder() : "";
        if (nvl(s).indexOf("|") != -1)
            s = s.substring(0, s.indexOf("|"));
        return (nvl(s).length() > 0) ? ("row".equals(s) ? true : false) : true;
    }

    public boolean isMultiplePieOrderByColumn() {
        String s = "";
        s = (cr.getChartAdditionalOptions() != null) ? cr.getChartAdditionalOptions().getChartMultiplePieOrder() : "";
        if (nvl(s).indexOf("|") != -1)
            s = s.substring(0, s.indexOf("|"));
        return (nvl(s).length() > 0) && ("column".equals(s)) ? true : false;
    }

    public boolean displayPieLabelDisplayinRunPage() {
        String s = "";
        s = (cr.getChartAdditionalOptions() != null) ? cr.getChartAdditionalOptions().getChartMultiplePieLabelDisplay()
                : "";
        if (nvl(s).indexOf("|") != -1) {
            s = s.substring(s.indexOf("|") + 1);
            return getFlagInBoolean(s);
        } else
            return false;
    }

    public String getMultiplePieLabelDisplay() {
        String s = "";
        s = (cr.getChartAdditionalOptions() != null) ? cr.getChartAdditionalOptions().getChartMultiplePieLabelDisplay()
                : "";
        if (nvl(s).indexOf("|") != -1)
            s = s.substring(0, s.indexOf("|"));
        return s;
    }

    public boolean displayChartDisplayinRunPage() {
        String s = "";
        s = (cr.getChartAdditionalOptions() != null) ? cr.getChartAdditionalOptions().getChartDisplay() : "";
        if (nvl(s).indexOf("|") != -1) {
            s = s.substring(s.indexOf("|") + 1);
            return getFlagInBoolean(s);
        } else
            return false;
    }

    public boolean isChartDisplayIn3D() {
        String s = "";
        s = (cr.getChartAdditionalOptions() != null) ? cr.getChartAdditionalOptions().getChartDisplay() : "";
        if (nvl(s).length() <= 0)
            return true;
        if (nvl(s).indexOf("|") != -1)
            s = s.substring(0, s.indexOf("|"));
        return (nvl(s).length() > 0) && ("3D".equals(s)) ? true : false;
    }

    public boolean displayChartOrientationInRunPage() {
        String s = "";
        s = (cr.getChartAdditionalOptions() != null) ? cr.getChartAdditionalOptions().getChartOrientation() : "";
        if (nvl(s).indexOf("|") != -1) {
            s = s.substring(s.indexOf("|") + 1);
            return getFlagInBoolean(s);
        } else
            return false;

    }

    public String getLinearRegression() {
        String s = "";
        s = nvl((cr.getChartAdditionalOptions() != null) ? cr.getChartAdditionalOptions().getLinearRegression() : "Y");
        return s;
    }

    public void setLinearRegression(String linear) {
        cr.getChartAdditionalOptions().setLinearRegression(linear);
    }

    public String getLinearRegressionColor() {
        return (cr.getChartAdditionalOptions() != null) ? cr.getChartAdditionalOptions().getLinearRegressionColor()
                : "";
    }

    public String getCustomizedRegressionPoint() {
        return (cr.getChartAdditionalOptions() != null) ? cr.getChartAdditionalOptions().getMaxRegression() : "";
    }

    public void setCustomizedRegressionPoint(String d) {
        cr.getChartAdditionalOptions().setMaxRegression(d);
    }

    public void setLinearRegressionColor(String color) {
        cr.getChartAdditionalOptions().setLinearRegressionColor(color);
    }

    public String getExponentialRegressionColor() {
        return (cr.getChartAdditionalOptions() != null) ? cr.getChartAdditionalOptions().getExponentialRegressionColor()
                : "";
    }

    public void setExponentialRegressionColor(String color) {
        cr.getChartAdditionalOptions().setExponentialRegressionColor(color);
    }

    public void setRangeAxisUpperLimit(String d) {
        if (cr.getChartAdditionalOptions() != null)
            cr.getChartAdditionalOptions().setRangeAxisUpperLimit(d);
    }

    public void setRangeAxisLowerLimit(String d) {
        if (cr.getChartAdditionalOptions() != null)
            cr.getChartAdditionalOptions().setRangeAxisLowerLimit(d);
    }

    public String getRangeAxisUpperLimit() {
        return (cr.getChartAdditionalOptions() != null) ? cr.getChartAdditionalOptions().getRangeAxisUpperLimit() : "";
    }

    public String getRangeAxisLowerLimit() {
        return (cr.getChartAdditionalOptions() != null) ? cr.getChartAdditionalOptions().getRangeAxisLowerLimit() : "";
    }

    public boolean isChartAnimate() {
        return (cr.getChartAdditionalOptions() != null)
                ? (cr.getChartAdditionalOptions().isAnimate() != null ? cr.getChartAdditionalOptions().isAnimate()
                        : false)
                : false;
    }

    public boolean isAnimateAnimatedChart() {
        return (cr.getChartAdditionalOptions() != null)
                ? (cr.getChartAdditionalOptions().isAnimateAnimatedChart() != null
                        ? cr.getChartAdditionalOptions().isAnimateAnimatedChart()
                        : false)
                : true;
    }

    public void setAnimateAnimatedChart(boolean animate) {
        cr.getChartAdditionalOptions().setAnimateAnimatedChart(animate);
    }

    public void setChartStacked(boolean stacked) {
        cr.getChartAdditionalOptions().setStacked(stacked);
    }

    public boolean isChartStacked() {
        return (cr.getChartAdditionalOptions() != null)
                ? (cr.getChartAdditionalOptions().isStacked() != null ? cr.getChartAdditionalOptions().isStacked()
                        : true)
                : false;
    }

    public void setBarControls(boolean barControls) {
        cr.getChartAdditionalOptions().setBarControls(barControls);
    }

    public boolean displayBarControls() {
        return (cr.getChartAdditionalOptions() != null) ? (cr.getChartAdditionalOptions().isBarControls() != null
                ? cr.getChartAdditionalOptions().isBarControls()
                : false) : false;
    }

    public void setXAxisDateType(boolean dateType) {
        cr.getChartAdditionalOptions().setXAxisDateType(dateType);
    }

    public boolean isXAxisDateType() {
        return (cr.getChartAdditionalOptions() != null) ? (cr.getChartAdditionalOptions().isXAxisDateType() != null
                ? cr.getChartAdditionalOptions().isXAxisDateType()
                : false) : false;
    }

    public void setLessXaxisTickers(boolean lessTickers) {
        cr.getChartAdditionalOptions().setLessXaxisTickers(lessTickers);
    }

    public boolean isLessXaxisTickers() {
        return (cr.getChartAdditionalOptions() != null) ? (cr.getChartAdditionalOptions().isLessXaxisTickers() != null
                ? cr.getChartAdditionalOptions().isLessXaxisTickers()
                : false) : false;
    }

    public void setTimeAxis(boolean timeAxis) {
        cr.getChartAdditionalOptions().setTimeAxis(timeAxis);
    }

    public boolean isTimeAxis() {
        return (cr.getChartAdditionalOptions() != null)
                ? (cr.getChartAdditionalOptions().isTimeAxis() != null ? cr.getChartAdditionalOptions().isTimeAxis()
                        : true)
                : true;
    }

    public void setLogScale(boolean logScale) {
        cr.getChartAdditionalOptions().setLogScale(logScale);
    }

    public boolean isLogScale() {
        return (cr.getChartAdditionalOptions() != null)
                ? (cr.getChartAdditionalOptions().isLogScale() != null ? cr.getChartAdditionalOptions().isLogScale()
                        : false)
                : false;
    }

    public void setMultiSeries(boolean multiSeries) {
        cr.getChartAdditionalOptions().setMultiSeries(multiSeries);
        cr.setChartMultiSeries(multiSeries ? "Y" : "N");
    }

    public boolean isMultiSeries() {
        if ("Y".equals(AppUtils.nvl(cr.getChartMultiSeries())))
            cr.getChartAdditionalOptions().setMultiSeries(true);
        return (cr.getChartAdditionalOptions() != null) ? (cr.getChartAdditionalOptions().isMultiSeries() != null
                ? cr.getChartAdditionalOptions().isMultiSeries()
                : false) : false;
    }

    public void setTimeSeriesRender(String timeSeriesRenderer) {
        cr.getChartAdditionalOptions().setTimeSeriesRender(timeSeriesRenderer);
    }

    public String getTimeSeriesRender() {
        return (cr.getChartAdditionalOptions() != null) ? cr.getChartAdditionalOptions().getTimeSeriesRender() : "line";
    }

    public void setShowXAxisLabel(boolean showXaxisLabel) {
        cr.getChartAdditionalOptions().setShowXAxisLabel(showXaxisLabel);
    }

    public boolean isShowXaxisLabel() {
        return (cr.getChartAdditionalOptions() != null) ? (cr.getChartAdditionalOptions().isShowXAxisLabel() != null
                ? cr.getChartAdditionalOptions().isShowXAxisLabel()
                : false) : false;
    }

    public void setAddXAxisTickers(boolean addXAxisTickers) {
        cr.getChartAdditionalOptions().setAddXAxisTickers(addXAxisTickers);
    }

    public boolean isAddXAxisTickers() {
        return (cr.getChartAdditionalOptions() != null) ? (cr.getChartAdditionalOptions().isAddXAxisTickers() != null
                ? cr.getChartAdditionalOptions().isAddXAxisTickers()
                : false) : true;
    }

    public void setZoomIn(Integer zoomIn) {
        cr.getChartAdditionalOptions().setZoomIn(zoomIn);
    }

    public Integer getZoomIn() {
        return (cr.getChartAdditionalOptions() != null)
                ? (cr.getChartAdditionalOptions().getZoomIn() != null ? cr.getChartAdditionalOptions().getZoomIn()
                        : new Integer("25"))
                : new Integer("25");
    }

    public void setTimeAxisType(String timeAxisType) {
        cr.getChartAdditionalOptions().setTimeAxisType(timeAxisType);
    }

    public String getTimeAxisType() {
        return (cr.getChartAdditionalOptions() != null) ? (cr.getChartAdditionalOptions().getTimeAxisType() != null
                ? cr.getChartAdditionalOptions().getTimeAxisType()
                : "hourly") : "hourly";
    }

    public void setTopMargin(Integer topMargin) {
        cr.getChartAdditionalOptions().setTopMargin(topMargin);
    }

    public Integer getTopMargin() {
        return (cr.getChartAdditionalOptions() != null) ? cr.getChartAdditionalOptions().getTopMargin()
                : new Integer("30");
    }

    public void setBottomMargin(Integer bottomMargin) {
        cr.getChartAdditionalOptions().setBottomMargin(bottomMargin);
    }

    public Integer getBottomMargin() {
        return (cr.getChartAdditionalOptions() != null) ? cr.getChartAdditionalOptions().getBottomMargin()
                : new Integer("50");
    }

    public void setRightMargin(Integer rightMargin) {
        cr.getChartAdditionalOptions().setRightMargin(rightMargin);
    }

    public Integer getRightMargin() {
        return (cr.getChartAdditionalOptions() != null) ? cr.getChartAdditionalOptions().getRightMargin()
                : new Integer("60");
    }

    public void setLeftMargin(Integer leftMargin) {
        cr.getChartAdditionalOptions().setLeftMargin(leftMargin);
    }

    public Integer getLeftMargin() {
        return (cr.getChartAdditionalOptions() != null) ? cr.getChartAdditionalOptions().getLeftMargin()
                : new Integer("100");
    }

    public boolean isVerticalOrientation() {
        String s = "";
        s = (cr.getChartAdditionalOptions() != null) ? cr.getChartAdditionalOptions().getChartOrientation() : "";
        if (nvl(s).length() <= 0)
            return true;
        if (nvl(s).indexOf("|") != -1)
            s = s.substring(0, s.indexOf("|"));
        return (nvl(s).length() > 0) && ("vertical".equals(s)) ? true : false;
    }

    public boolean isHorizontalOrientation() {
        String s = "";
        s = (cr.getChartAdditionalOptions() != null) ? cr.getChartAdditionalOptions().getChartOrientation() : "";
        if (nvl(s).indexOf("|") != -1)
            s = s.substring(0, s.indexOf("|"));
        return (nvl(s).length() > 0) && ("horizontal".equals(s)) ? true : false;
    }

    public boolean displaySecondaryChartRendererInRunPage() {
        String s = "";
        s = (cr.getChartAdditionalOptions() != null) ? cr.getChartAdditionalOptions().getSecondaryChartRenderer() : "";
        if (nvl(s).indexOf("|") != -1) {
            s = s.substring(s.indexOf("|") + 1);
            return getFlagInBoolean(s);
        } else
            return false;

    }

    public String getSecondaryChartRenderer() {
        String s = "";
        s = (cr.getChartAdditionalOptions() != null) ? cr.getChartAdditionalOptions().getSecondaryChartRenderer() : "";
        if (nvl(s).indexOf("|") != -1)
            s = s.substring(0, s.indexOf("|"));
        return s;
    }

    public String getOverlayItemValueOnStackBar() {
        String s = "";
        s = (cr.getChartAdditionalOptions() != null) ? cr.getChartAdditionalOptions().getOverlayItemValueOnStackBar()
                : "N";
        return s;
    }

    public boolean displayIntervalInputInRunPage() {
        String s = "";
        s = (cr.getChartAdditionalOptions() != null) ? cr.getChartAdditionalOptions().getIntervalFromdate() : "";
        if (nvl(s).indexOf("|") != -1) {
            s = s.substring(s.indexOf("|") + 1);
            return getFlagInBoolean(s);
        } else
            return false;
    }

    public boolean showLegendDisplayOptionsInRunPage() {
        String s = "";
        s = (cr.getChartAdditionalOptions() != null) ? cr.getChartAdditionalOptions().getHidechartLegend() : "";
        if (nvl(s).indexOf("|") != -1) {
            s = s.substring(s.indexOf("|") + 1);
            return getFlagInBoolean(s);
        } else
            return false;
    }

    public String getIntervalFromdate() {
        String s = "";
        s = (cr.getChartAdditionalOptions() != null) ? cr.getChartAdditionalOptions().getIntervalFromdate() : "";
        if (nvl(s).indexOf("|") != -1)
            s = s.substring(0, s.indexOf("|"));
        return nvl(s, "");
    }

    public String getIntervalTodate() {
        String s = "";
        s = (cr.getChartAdditionalOptions() != null) ? cr.getChartAdditionalOptions().getIntervalTodate() : "";
        if (nvl(s).indexOf("|") != -1)
            s = s.substring(0, s.indexOf("|"));
        return nvl(s, "");
    }

    public String getIntervalLabel() {
        return cr.getChartAdditionalOptions() != null ? nvl(cr.getChartAdditionalOptions().getIntervalLabel()) : "";
    }

    public String getLegendPosition() {
        String s = "";
        s = (cr.getChartAdditionalOptions() != null) ? cr.getChartAdditionalOptions().getLegendPosition() : "";
        return nvl(s, "bottom");
    }

    public String getLegendLabelAngle() {
        String s = "";
        s = (cr.getChartAdditionalOptions() != null) ? cr.getChartAdditionalOptions().getLabelAngle() : "";
        return nvl(s, "UP90");
    }

    public String getMaxLabelsInDomainAxis() {
        String s = "";
        s = (cr.getChartAdditionalOptions() != null) ? cr.getChartAdditionalOptions().getMaxLabelsInDomainAxis() : "";
        return nvl(s, "99");
    }

    public boolean isLastSeriesALineChart() {
        String s = "";
        s = nvl((cr.getChartAdditionalOptions() != null) ? cr.getChartAdditionalOptions().getLastSeriesALineChart()
                : "");
        return s.equals("Y");
    }

    public boolean isLastSeriesABarChart() {
        String s = "";
        s = nvl((cr.getChartAdditionalOptions() != null) ? cr.getChartAdditionalOptions().getLastSeriesABarChart()
                : "");
        return s.equals("Y");
    }

    public void setChartLegendDisplay(String value) {
        cr.getChartAdditionalOptions().setHidechartLegend(value);
    }

    public boolean hideChartLegend() {
        String s = "";
        s = nvl((cr.getChartAdditionalOptions() != null) ? cr.getChartAdditionalOptions().getHidechartLegend() : "N");
        if (nvl(s).length() <= 0)
            s = "N";
        if (nvl(s).indexOf("|") != -1)
            s = s.substring(0, s.indexOf("|"));
        return s.equals("Y");
    }

    public void setChartToolTips(String value) {
        cr.getChartAdditionalOptions().setHideToolTips(value);
    }

    public void setDomainAxisValuesAsString(String value) {
        cr.getChartAdditionalOptions().setKeepDomainAxisValueAsString(value);
    }

    public boolean hideChartToolTips() {
        boolean s = true;
        s = (cr.getChartAdditionalOptions() != null)
                ? (cr.getChartAdditionalOptions().getHideToolTips() != null
                        ? ("Y".equals(cr.getChartAdditionalOptions().getHideToolTips()) ? true : false)
                        : (Globals.hideToolTipsGlobally() ? true : false))
                : (Globals.hideToolTipsGlobally() ? true : false);
        return s;
    }

    public boolean keepDomainAxisValueInChartAsString() {
        boolean s = true;
        s = (cr.getChartAdditionalOptions() != null)
                ? (cr.getChartAdditionalOptions().getKeepDomainAxisValueAsString() != null
                        ? ("Y".equals(cr.getChartAdditionalOptions().getKeepDomainAxisValueAsString()) ? true : false)
                        : false)
                : false;
        return s;
    }

    public int getChartHeightAsInt() {
        return getIntValue(cr.getChartHeight(), Globals.getDefaultChartHeight());
    }

    public boolean isPublic() {
        return cr.isPublic();
    }

    public boolean isDashboardType() throws RaptorException {
        return cr.isDashboardType() != null ? cr.isDashboardType().booleanValue() : false;
    }


    public String getReportSQL() {
        return cr.getReportSQL();
    }

    public String getReportTitle() {
        return cr.getReportTitle();
    }

    public String getReportSubTitle() {
        return cr.getReportSubTitle();
    }

    public String getReportHeader() {
        return cr.getReportHeader();
    }

    public String getReportFooter() {
        return cr.getReportFooter();
    }

    public String getNumDashCols() {
        return cr.getNumDashCols();
    }

    public int getNumDashColsAsInt() {
        return getIntValue(cr.getNumDashCols(), 1);
    }

    public String getNumFormCols() {
        return cr.getNumFormCols();
    }

    public int getNumFormColsAsInt() {
        return getIntValue(cr.getNumFormCols(), 5);
    }

    public String getDisplayOptions() {
        return cr.getDisplayOptions();
    }



    public int getJumpTo() {
        return cr.getJumpTo() == null ? 1 : cr.getJumpTo();
    }

    public void setJumpTo(int value) {
        cr.setJumpTo(value);
    }

    public int getSearchPageSize() {
        return cr.getSearchPageSize() == null ? 20 : cr.getSearchPageSize();
    }

    public void setSearchPageSize(int value) {
        cr.setSearchPageSize(value);
    }

    public boolean isToggleLayout() {
        if (cr.isToggleLayout() != null)
            return cr.isToggleLayout();

        else
            return Globals.displayRuntimeOptionsAsDefault();

    }

    public void setToggleLayout(boolean value) {
        cr.setToggleLayout(value);
    }

    public boolean isShowPageSize() {
        if (cr.isShowPageSize() != null)
            return cr.isShowPageSize();

        else
            return Globals.displayRuntimeOptionsAsDefault();

    }

    public void setShowPageSize(boolean value) {
        cr.setShowPageSize(value);
    }

    public boolean isShowNavPos() {
        if (cr.isShowNavPos() != null)
            return cr.isShowNavPos();

        else
            return Globals.displayRuntimeOptionsAsDefault();

    }

    public void setShowNavPos(boolean value) {
        cr.setShowNavPos(value);
    }

    public boolean isShowGotoOption() {
        if (cr.isShowGotoOption() != null)
            return cr.isShowGotoOption();

        else
            return Globals.displayRuntimeOptionsAsDefault();

    }

    public void setShowGotoOption(boolean value) {
        cr.setShowGotoOption(value);
    }

    public boolean isPageNav() {

        if (cr.isPageNav() != null)
            return cr.isPageNav();

        else
            return Globals.displayRuntimeOptionsAsDefault();

    }

    public void setPageNav(boolean value) {
        cr.setPageNav(value);
    }

    public String getNavPosition() {
        if (cr.getNavPosition() != null)
            return cr.getNavPosition();

        else
            return "top";
		
    }

    public void setNavPosition(String value) {
        cr.setNavPosition(value);
    }

    public String getDashboardEditor() {
        return getDashBoardReportsNew().getDashboardEditor();
    }

    public void setDashboardEditor(String value) {
        getDashBoardReportsNew().setDashboardEditor(value);
    }

    public DashboardEditorList getDashboardEditorList() {
        return getDashBoardReportsNew().getDashboardEditorList();
    }

    public void setDashboardEditorList(DashboardEditorList value) {
        getDashBoardReportsNew().setDashboardEditorList(value);
    }

    public PDFAdditionalOptions getPDFAdditionalOptions() {
        try {
            if (cr.getPdfAdditionalOptions() == null)
                addPDFAdditionalOptions(new ObjectFactory());
        } catch (RaptorException ex) {
            logger.error(EELFLoggerDelegate.debugLogger, "Exception occured in getPDFAdditionalOptions ", ex);
        }
        return cr.getPdfAdditionalOptions();
    }

    public String getPDFFont() {
        return getPDFAdditionalOptions().getPDFFont() != null ? getPDFAdditionalOptions().getPDFFont()
                : Globals.getDataFontFamily();
    }

    public void setPDFFont(String value) {
        getPDFAdditionalOptions().setPDFFont(value);
    }

    public int getPDFFontSize() {
        return getPDFAdditionalOptions().getPDFFontSize() == null ? 9 : getPDFAdditionalOptions().getPDFFontSize();
    }

    public void setPDFFontSize(int value) {
        getPDFAdditionalOptions().setPDFFontSize(value);
    }

    public String getPDFOrientation() {
        return getPDFAdditionalOptions().getPDFOrientation() != null ? "portrait" : "landscape";
    }

    public void setPDFOrientation(String value) {
        getPDFAdditionalOptions().setPDFOrientation(value);
    }

    public String getPDFLogo1() {
        return getPDFAdditionalOptions().getPDFLogo1();
    }

    public void setPDFLogo1(String value) {
        getPDFAdditionalOptions().setPDFLogo1(value);
    }

    public String getPDFLogo2() {
        return getPDFAdditionalOptions().getPDFLogo2();
    }

    public void setPDFLogo2(String value) {
        getPDFAdditionalOptions().setPDFLogo2(value);
    }

    public int getPDFLogo1Size() {
        return getPDFAdditionalOptions().getPDFLogo1Size() == null ? 0 : getPDFAdditionalOptions().getPDFLogo1Size();
    }

    public void setPDFLogo1Size(int value) {
        getPDFAdditionalOptions().setPDFLogo1Size(value);
    }

    public int getPDFLogo2Size() {
        return getPDFAdditionalOptions().getPDFLogo2Size() == null ? 0 : getPDFAdditionalOptions().getPDFLogo2Size();
    }

    public void setPDFLogo2Size(int value) {
        getPDFAdditionalOptions().setPDFLogo2Size(value);
    }

    public boolean isPDFCoverPage() {

        if (getPDFAdditionalOptions().isPDFCoverPage() != null)
            return getPDFAdditionalOptions().isPDFCoverPage();

        else
            return true;

    }

    public void setPDFCoverPage(boolean value) {
        getPDFAdditionalOptions().setPDFCoverPage(value);
    }

    public String getPDFFooter1() {
        return getPDFAdditionalOptions().getPDFFooter1();
    }

    public void setPDFFooter1(String value) {
        getPDFAdditionalOptions().setPDFFooter1(value);
    }

    public String getPDFFooter2() {
        return getPDFAdditionalOptions().getPDFFooter2();
    }

    public void setPDFFooter2(String value) {
        getPDFAdditionalOptions().setPDFFooter2(value);
    }


    public String getDataContainerHeight() {
        return cr.getDataContainerHeight();
    }

    public String getDataContainerWidth() {
        return cr.getDataContainerWidth();
    }

    public boolean isAllowSchedule() {
        String allowSchedule = getAllowSchedule();
        return (allowSchedule != null) ? allowSchedule.startsWith("Y") : false;
    }

    public String getAllowSchedule() {
        return cr.getAllowSchedule();
    }



    public boolean isMultiGroupColumn() {
        String multiGroupColumn = getMultiGroupColumn();
        return (multiGroupColumn != null) ? multiGroupColumn.startsWith("Y") : false;
    }

    public String getMultiGroupColumn() {
        return cr.getMultiGroupColumn();
    }

    public void setMultiGroupColumn(String value) {
        cr.setMultiGroupColumn(value);
    }

    private int getColumnGroupLevel(String colId) throws RaptorException {
        DataColumnType dc = getColumnById(colId);
        return (dc == null) ? 0 : dc.getLevel();
	} 

    public int getMaxGroupLevel() {
        List reportCols = getAllColumns();
        int maxLevel = 0;
        for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
            DataColumnType dc = (DataColumnType) iter.next();
            if (dc.getLevel() != null) {
                if (maxLevel < dc.getLevel())
                    maxLevel = dc.getLevel();
            }
		} 
        return maxLevel;
	}

    private int getColumnGroupStart(String colId) throws RaptorException {
        DataColumnType dc = getColumnById(colId);
        return (dc == null) ? 0 : dc.getStart();
	}

    private int getColumnGroupColSpan(String colId) throws RaptorException {
        DataColumnType dc = getColumnById(colId);
        return (dc == null) ? 0 : dc.getColspan();
	}

    public void setTopDown(String value) {
        cr.setTopDown(value);
    }

    public boolean isTopDown() {
        String topDown = getTopDownOption();
        return (topDown != null) ? topDown.startsWith("Y") : false;
    }

    public String getTopDownOption() {
        return cr.getTopDown();
    }

    public void setSizedByContent(String value) {
        cr.setSizedByContent(value);
    }

    public boolean isSizedByContent() {
        String sizedByContent = getSizedByContentOption();
        return (sizedByContent != null) ? sizedByContent.startsWith("Y") : false;
    }

    public String getSizedByContentOption() {
        return cr.getSizedByContent();
    }

    public String getDashboardOptions() {
        return cr.getDashboardOptions();
    }

    public boolean isDashboardOptionHideChart() {
        return nvl(getDashboardOptions()).length() > 0 && (getDashboardOptions().charAt(0) == 'Y');
    }

    public boolean isDashboardOptionHideData() {
        return nvl(getDashboardOptions()).length() > 0 && (getDashboardOptions().charAt(1) == 'Y');
    }

    public boolean isDashboardOptionHideBtns() {
        return nvl(getDashboardOptions()).length() > 0 && (getDashboardOptions().charAt(2) == 'Y');
    }

    public boolean isDisplayOptionHideForm() {
        return nvl(getDisplayOptions()).length() > 0 && (getDisplayOptions().charAt(0) == 'Y');
    }

    public boolean isDisplayOptionHideChart() {
        return nvl(getDisplayOptions()).length() > 1 && (getDisplayOptions().charAt(1) == 'Y');
    }

    public boolean isDisplayOptionHideData() {
        return nvl(getDisplayOptions()).length() > 2 && (getDisplayOptions().charAt(2) == 'Y');
    }

    public boolean isDisplayOptionHideBtns() {
        return nvl(getDisplayOptions()).length() > 3 && (getDisplayOptions().charAt(3) == 'Y');
    }

    public boolean isDisplayOptionHideMap() {
        return nvl(getDisplayOptions()).length() > 4 && (getDisplayOptions().charAt(4) == 'Y');
    }

    public boolean isDisplayOptionHideExcelIcons() {
        return nvl(getDisplayOptions()).length() > 5 && (getDisplayOptions().charAt(5) == 'Y');
    }

    public boolean isDisplayOptionHidePDFIcons() {
        return nvl(getDisplayOptions()).length() > 6 && (getDisplayOptions().charAt(6) == 'Y');
    }

    public String getComment() {
        return cr.getComment();
    }

    public DataSourceList getDataSourceList() {
        return cr.getDataSourceList();
    }

    public ChartAdditionalOptions getChartAdditionalOptions() {
        return cr.getChartAdditionalOptions();
    }

    public ChartDrillOptions getChartDrillOptions() {
        return cr.getChartDrillOptions();
    }

    public DataminingOptions getDataminingOptions() {
        return cr.getDataminingOptions();
    }

    public DashboardReports getDashBoardReports() {
        return cr.getDashBoardReports();
    }

    public DashboardReportsNew getDashBoardReportsNew() {
        try {
            if (cr.getDashBoardReportsNew() == null)
                addDashboardReportsNew(new ObjectFactory());
        } catch (RaptorException ex) {
            logger.error(EELFLoggerDelegate.debugLogger, "Exception occured in getDashBoardReportsNew ", ex);
        }
        return cr.getDashBoardReportsNew();
    }

    public String getDashboardLayoutHTML() {
        return cr.getDashboardLayoutHTML();
    }

	public String getDashboardLayoutJSON() {
		return cr.getDashboardLayoutJSON();
	}
	
    public FormFieldList getFormFieldList() {
        return cr.getFormFieldList();
    }

    public JavascriptList getJavascriptList() {
        return cr.getJavascriptList();
    }

    public SemaphoreList getSemaphoreList() {
        return cr.getSemaphoreList();
    }

    public void setPageSize(int value) {
        cr.setPageSize(value);
    }

    public void setAllowSchedule(String value) {
        cr.setAllowSchedule(value);
    }

    public void setMaxRowsInExcelDownload(int value) {
        cr.setMaxRowsInExcelDownload(value);
    }

    public void setReportInNewWindow(boolean value) {
        cr.setReportInNewWindow(value);
    }

    public void setDisplayFolderTree(boolean value) {
        cr.setDisplayFolderTree(value);
    }

    public void setReportType(String value) {
        cr.setReportType(value);
    }

    public void setReportName(String value) {
        cr.setReportName(value);
    }

    public void setDBInfo(String value) {
            cr.setDbInfo(value);
    }

    public void setDBType(String value) {
            cr.setDbType(value);
    }

    public void setReportDescr(String value) {
        cr.setReportDescr(value);
    }

    public void setChartType(String value) {
        cr.setChartType(value);
    }

    public void setChartMultiplePieOrder(String value) {
        cr.getChartAdditionalOptions().setChartMultiplePieOrder(value);
    }

    public void setChartMultiplePieLabelDisplay(String value) {
        cr.getChartAdditionalOptions().setChartMultiplePieLabelDisplay(value);
    }

    public void setChartOrientation(String value) {
        cr.getChartAdditionalOptions().setChartOrientation(value);
    }

    public void setSecondaryChartRenderer(String value) {
        cr.getChartAdditionalOptions().setSecondaryChartRenderer(value);
    }

    public void setOverlayItemValueOnStackBar(String value) {
        cr.getChartAdditionalOptions().setOverlayItemValueOnStackBar(value);
    }

    public void setIntervalFromdate(String value) {
        cr.getChartAdditionalOptions().setIntervalFromdate(value);
    }

    public void setIntervalLabel(String value) {
        cr.getChartAdditionalOptions().setIntervalLabel(value);
    }

    public void setIntervalTodate(String value) {
        cr.getChartAdditionalOptions().setIntervalTodate(value);
    }

    public void setLegendPosition(String value) {
        cr.getChartAdditionalOptions().setLegendPosition(value);
    }

    public void setLegendLabelAngle(String value) {
        cr.getChartAdditionalOptions().setLabelAngle(value);
    }

    public void setMaxLabelsInDomainAxis(String value) {
        if (nvl(value).length() <= 0)
            value = "99";
        cr.getChartAdditionalOptions().setMaxLabelsInDomainAxis(value);
    }

    public void setLastSeriesALineChart(String value) {
        cr.getChartAdditionalOptions().setLastSeriesALineChart(value);
    }

    public void setLastSeriesABarChart(String value) {
        cr.getChartAdditionalOptions().setLastSeriesABarChart(value);
    }

    public void setChartDisplay(String value) {
        cr.getChartAdditionalOptions().setChartDisplay(value);
    }

    public void setChartAnimate(boolean animate) {
        if (cr.getChartAdditionalOptions() != null)
            cr.getChartAdditionalOptions().setAnimate(animate);
        else {
            try {
                if (getChartAdditionalOptions() == null)
                    addChartAdditionalOptions(new ObjectFactory());
            } catch (RaptorException ex) {
                logger.error(EELFLoggerDelegate.debugLogger, "Exception occured in setChartAnimate ", ex);
            }
            if (cr.getChartAdditionalOptions() != null)
                cr.getChartAdditionalOptions().setAnimate(animate);

        }

    }

    public void addChartAdditionalOptions(ObjectFactory objFactory) throws RaptorException {
        ChartAdditionalOptions chartOptions = objFactory.createChartAdditionalOptions();
        cr.setChartAdditionalOptions(chartOptions);
    }

    public void addDashboardReportsNew(ObjectFactory objFactory) throws RaptorException {
        DashboardReportsNew dashboardReports = objFactory.createDashboardReportsNew();
        cr.setDashBoardReportsNew(dashboardReports);
    }

    public void addPDFAdditionalOptions(ObjectFactory objFactory) throws RaptorException {
        PDFAdditionalOptions pdfOptions = objFactory.createPDFAdditionalOptions();
        cr.setPdfAdditionalOptions(pdfOptions);
    }

    public void setChartTypeFixed(String value) {
        cr.setChartTypeFixed(value);
    }

    public void setChartLeftAxisLabel(String value) {
        cr.setChartLeftAxisLabel(value);
    }

    public void setChartRightAxisLabel(String value) {
        cr.setChartRightAxisLabel(value);
    }

    public void setChartWidth(String value) {
        cr.setChartWidth(value);
    }

    public void setChartHeight(String value) {
        cr.setChartHeight(value);
    }

    public void setChartMultiSeries(String value) {
        cr.setChartMultiSeries(value);
    }

    public void setPublic(boolean value) {
        cr.setPublic(value);
        if (reportSecurity != null)
            reportSecurity.setPublic(value);
    }

    public void setReportSQL(String value) {
        cr.setReportSQL(value);
    }

    public void setReportTitle(String value) {
        cr.setReportTitle(value);
    }

    public void setReportSubTitle(String value) {
        cr.setReportSubTitle(value);
    }

    public void setReportHeader(String value) {
        cr.setReportHeader(value);
    }

    public void setReportFooter(String value) {
        cr.setReportFooter(value);
    }

    public void setNumFormCols(String value) {
        cr.setNumFormCols(value);
    }

    public void setNumDashCols(String value) {
        cr.setNumDashCols(value);
    }

    public void setDisplayOptions(String value) {
        cr.setDisplayOptions(value);
    }

    public void setDataContainerHeight(String value) {
        cr.setDataContainerHeight(value);
    }

    public void setDataContainerWidth(String value) {
        cr.setDataContainerWidth(value);
    }

    public void setDashboardOptions(String value) {
        cr.setDashboardOptions(value);
    }

    public void setComment(String value) {
        cr.setComment(value);
    }

    public void setDashboardType(boolean dashboardType) {
        cr.setDashboardType(dashboardType);
    }

    public void setDashboardLayoutHTML(String html) {
        cr.setDashboardLayoutHTML(html);
    }

    public void setDataSourceList(DataSourceList value) {
        cr.setDataSourceList(value);
    }

    public void setFormFieldList(FormFieldList value) {
        cr.setFormFieldList(value);
    }

    public void setDashBoardReports(DashboardReports value) {
        cr.setDashBoardReports(value);
    }

    public void setSemaphoreList(SemaphoreList value) {
        cr.setSemaphoreList(value);
    }

    public void setJavascriptList(JavascriptList value) {
        cr.setJavascriptList(value);
    }

    public void setJavascriptElement(String javascriptElement) {
        cr.setJavascriptElement(javascriptElement);
    }

    public void checkUserReadAccess(HttpServletRequest request) throws RaptorException {
        reportSecurity.checkUserReadAccess(request, null);
    }

    public void checkUserReadAccess(HttpServletRequest request, String userID) throws RaptorException {
        reportSecurity.checkUserReadAccess(request, userID);
    }

    public void checkUserWriteAccess(HttpServletRequest request) throws RaptorException {
        reportSecurity.checkUserWriteAccess(request);
        verifySQLBasedReportAccess(request);
    }

    public String getOwnerID() {
        return reportSecurity.getOwnerID();
    }

    public String getCreateID() {
        return reportSecurity.getCreateID();
    }

    public String getCreateDate() {
        return reportSecurity.getCreateDate();
    }

    public String getUpdateID() {
        return reportSecurity.getUpdateID();
    }

    public String getUpdateDate() {
        return reportSecurity.getUpdateDate();
    }

    public ReportSecurity getReportSecurity() {
        return reportSecurity;
    }

    /**** Report Maps - Start ****/
    public ReportMap getReportMap() {
        return cr.getReportMap();
    }

    public void setReportMap(ReportMap reportMap) {
        cr.setReportMap(reportMap);
    }

    /**** Report Maps - End ****/

    /**** Report Chart Drilldown - Start ****/
    public ChartDrillOptions getReportChartDrillOptions() {
        return cr.getChartDrillOptions();
    }

    public void setReportChartDrillOptions(ChartDrillOptions chartDrillOptions) {
        cr.setChartDrillOptions(chartDrillOptions);
    }



    public String getFormHelpText() {
        String formHelpText = nvl(getComment());

        if (formHelpText.indexOf('|') >= 0)
            formHelpText = formHelpText.substring(formHelpText.lastIndexOf('|') + 1);

        return formHelpText;
	} 

    public void setFormHelpText(String formHelpText) {
        String comment = nvl(getComment());

        if (comment.indexOf('|') >= 0)
            comment = comment.substring(0, comment.lastIndexOf('|'));
        if (comment.length() > 0)
            comment += '|';

        setComment(comment + formHelpText);
	}

    public boolean isRuntimeColSortDisabled() {
        String comment = nvl(getComment());

        if (comment.indexOf('|') < 0)
            return false;

        return "Y".equals(comment.substring(0, comment.indexOf('|')));
	} 
    public void setRuntimeColSortDisabled(boolean value) {
        String comment = nvl(getComment());

        if (comment.indexOf('|') >= 0)
            comment = comment.substring(comment.indexOf('|') + 1);

        setComment((value ? "Y" : "N") + "|" + comment);
	}

    /**
     * *************************************************************************************************
     */

    protected void verifySQLBasedReportAccess(HttpServletRequest request) throws RaptorException {
        String userID = AppUtils.getUserID(request);
        if (getReportDefType().equals(AppConstants.RD_SQL_BASED)
                && (!Globals.getAllowSQLBasedReports()) && (!AppUtils.isAdminUser(request)))
            throw new org.onap.portalsdk.analytics.error.UserAccessException(reportID, "[" + userID + "] "
                    + AppUtils.getUserName(request), AppConstants.UA_WRITE);
	} 

    /**
     * *************************************************************************************************
     */

    private String getColumnNameById(String colId) throws RaptorException {
        DataColumnType dc = getColumnById(colId);
        return (dc == null) ? "NULL" : dc.getColName();
	} 
    private boolean isViewAction(String value) throws RaptorException {
        try {
            Vector viewActions = org.onap.portalsdk.analytics.model.DataCache.getDataViewActions();

            for (int i = 0; i < viewActions.size(); i++)
                if (value.equals(AppUtils.getBaseActionURL() + ((String) viewActions.get(i))))
                    return true;
        } catch (Exception e) {
            logger.error(EELFLoggerDelegate.debugLogger, "Exception occured in isViewAction ", e);
            throw new RaptorRuntimeException("ReportWrapper.isViewAction Exception: "
                    + e.getMessage());
        }

        return false;
	}

    public String getSelectExpr(DataColumnType dct) {
        return getSelectExpr(dct, dct.getColName() /* colName */);
	} 



    private String getSelectExpr(DataColumnType dct, String colName) {
        String colType = dct.getColType();
        if (colType.equals(AppConstants.CT_NUMBER)) {
            return colName;
        } else if (colType.equals(AppConstants.CT_CHAR)
                || ((nvl(dct.getColFormat()).length() == 0) && (!colType
                        .equals(AppConstants.CT_DATE))))
            return colName;

        else
            return "TO_CHAR(" + colName + ", '"
                    + nvl(dct.getColFormat(), AppConstants.DEFAULT_DATE_FORMAT) + "')";
	} 
	


    public DataSourceType getTableById(String tableId) {
        for (Iterator iter = getDataSourceList().getDataSource().iterator(); iter.hasNext();) {
            DataSourceType ds = (DataSourceType) iter.next();
            if (ds.getTableId().equals(tableId))
                return ds;
		}
        return null;
	} 

    public DataSourceType getTableByDBName(String tableName) {
        for (Iterator iter = getDataSourceList().getDataSource().iterator(); iter.hasNext();) {
            DataSourceType ds = (DataSourceType) iter.next();
            if (ds.getTableName().equals(tableName))
                return ds;
		} 

        return null;
	}

    public DataSourceType getColumnTableById(String colId) {
        return getTableById(getColumnById(colId).getTableId());
	}

    public DataColumnType getColumnById(String colId) {
        List reportCols = getAllColumns();
        for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
            DataColumnType dc = (DataColumnType) iter.next();
            if (dc.getColId().equalsIgnoreCase(colId)) {
                return dc;
            }
		} 

        return null;
	} 

    public DataColumnType getChartLegendColumn() {
        List reportCols = getAllColumns();
        for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
            DataColumnType dc = (DataColumnType) iter.next();
            if (nvl(dc.getColOnChart()).equals(AppConstants.GC_LEGEND))
                return dc;
		} 
        return null;
	} 

    public List getChartValueColumnsList(int filter, HashMap formValues) { /*
                                                                            * filter; all=0;create without new chart =1;
                                                                            * createNewChart=2
                                                                            */
        List reportCols = getAllColumns();

        ArrayList chartValueCols = new ArrayList();
        int flag = 0;
        for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
            flag = 0;
            DataColumnType dc = (DataColumnType) iter.next();
            flag = getDependsOnFormFieldFlag(dc, formValues);

            if ((dc.getChartSeq() != null && dc.getChartSeq() > 0) && flag == 0) {
                if (!AppUtils.nvl(dc.getColOnChart()).equals(AppConstants.GC_LEGEND)) {
                    if (nvl(dc.getChartGroup()).length() <= 0) {
                        if (filter == 2
                                && (dc.isCreateInNewChart() != null && dc.isCreateInNewChart().booleanValue())) {
                            chartValueCols.add(dc);
                        } else if (filter == 1
                                && (dc.isCreateInNewChart() == null || !dc.isCreateInNewChart().booleanValue())) {
                            chartValueCols.add(dc);
                        } else if (filter == 0)
                            chartValueCols.add(dc);
                    } else
                        chartValueCols.add(dc);
                }
            }

		} 
        Collections.sort(chartValueCols, new ChartSeqComparator());
        return chartValueCols;
    } 

    /** Check whether chart has series (Category) columns **/
    public boolean hasSeriesColumn() {
        List reportCols = getAllColumns();

        for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
            DataColumnType dc = (DataColumnType) iter.next();
            if (dc.isChartSeries() != null && dc.isChartSeries().booleanValue())
                return true;
		} 
        return false;
	}

    public List getChartDisplayNamesList(int filter, HashMap formValues) { 
        List reportCols = getAllColumns();
        ArrayList chartValueColNames = new ArrayList();
        int flag = 0;
        for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
            flag = 0;
            DataColumnType dc = (DataColumnType) iter.next();
            // if(filter == 2 || filter == 1) {
            flag = getDependsOnFormFieldFlag(dc, formValues);

            if ((dc.getChartSeq() != null && dc.getChartSeq() > 0) && flag == 0) {
                if (nvl(dc.getChartGroup()).length() <= 0) {
                    if (filter == 2 && (dc.isCreateInNewChart() != null && dc.isCreateInNewChart().booleanValue())) {
                        chartValueColNames.add(dc.getDisplayName());
                    } else if (filter == 1
                            && (dc.isCreateInNewChart() == null || !dc.isCreateInNewChart().booleanValue())) {
                        chartValueColNames.add(dc.getDisplayName());
                    } else if (filter == 0)
                        chartValueColNames.add(dc.getDisplayName());
                } else if (filter == 0)
                    chartValueColNames.add(dc.getDisplayName());
            }


        }
        return chartValueColNames;
	} 

    public List getChartColumnColorsList(int filter, HashMap formValues) { 
        List reportCols = getAllColumns();
        ArrayList chartValueColColors = new ArrayList();
        int flag = 0;
        for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
            flag = 0;
            DataColumnType dc = (DataColumnType) iter.next();
            flag = getDependsOnFormFieldFlag(dc, formValues);

            if ((dc.getChartSeq() != null && dc.getChartSeq() > 0) && flag == 0) {
                if (nvl(dc.getChartGroup()).length() <= 0) {
                    if (filter == 2 && (dc.isCreateInNewChart() != null && dc.isCreateInNewChart().booleanValue())) {
                        chartValueColColors.add(dc.getChartColor());
                    } else if (filter == 1
                            && (dc.isCreateInNewChart() == null || !dc.isCreateInNewChart().booleanValue())) {
                        chartValueColColors.add(dc.getChartColor());
                    } else if (filter == 0)
                        chartValueColColors.add(dc.getChartColor());
                } else if (filter == 0)
                    chartValueColColors.add(dc.getChartColor());
            }
        }
        return chartValueColColors;
	} 

    public List getChartValueColumnAxisList(int filter, HashMap formValues) { 
        List reportCols = getAllColumns();
        ArrayList chartValueColAxis = new ArrayList();
        int flag = 0;
        for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
            flag = 0;
            DataColumnType dc = (DataColumnType) iter.next();
            flag = getDependsOnFormFieldFlag(dc, formValues);

            if ((dc.getChartSeq() != null && dc.getChartSeq() > 0) && flag == 0) {
                if (nvl(dc.getChartGroup()).length() <= 0) {
                    if (filter == 2 && (dc.isCreateInNewChart() != null && dc.isCreateInNewChart().booleanValue())) {
                        chartValueColAxis.add(nvl(dc.getColOnChart(), "0"));
                    } else if (filter == 1
                            && (dc.isCreateInNewChart() == null || !dc.isCreateInNewChart().booleanValue())) {
                        chartValueColAxis.add(nvl(dc.getColOnChart(), "0"));
                    } else if (filter == 0)
                        chartValueColAxis.add(nvl(dc.getColOnChart(), "0"));
                } else if (filter == 0)
                    chartValueColAxis.add(nvl(dc.getColOnChart(), "0"));
            }
        }
        return chartValueColAxis;
	}


    public List getChartValueNewChartList() {
        ArrayList chartValueNewChartAxis = new ArrayList();
        for (Iterator iter = getChartValueColumnsList(2, null).iterator(); iter.hasNext();)
            chartValueNewChartAxis.add(new Boolean(((DataColumnType) iter.next()).isCreateInNewChart()));
        return chartValueNewChartAxis;
	}

    public List getAllChartGroups() {
        ArrayList chartGroups = new ArrayList();
        String chartGroupName = "";
        List reportCols = getAllColumns();
        Set groupSet = new TreeSet();
        for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
            DataColumnType dc = (DataColumnType) iter.next();
            if (dc.getChartSeq() != null && dc.getChartSeq() > 0) {
                chartGroupName = dc.getChartGroup();
                if (nvl(chartGroupName).length() > 0)
                    groupSet.add(chartGroupName);
            }
        }
        List l = new ArrayList(groupSet);
        return l;
	} 

    public HashMap getAllChartYAxis(ReportParamValues reportParamValues) {
        String chartYAxis = "";
        List reportCols = getAllColumns();
        HashMap hashMap = new HashMap();
        FormFieldList formFieldList = getFormFieldList();
        for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
            DataColumnType dc = (DataColumnType) iter.next();
            if (dc.getChartSeq() != null && dc.getChartSeq() > 0) {
                chartYAxis = dc.getYAxis();
                if (formFieldList != null && reportParamValues != null) {
                    for (Iterator iter1 = getFormFieldList().getFormField().iterator(); iter1.hasNext();) {
                        FormFieldType fft = (FormFieldType) iter1.next();
                        String fieldDisplay = getFormFieldDisplayName(fft);
                        String fieldId = "";
                        if (fft != null)
                            fieldId = fft.getFieldId();
                        if (fft != null && !fft.getFieldType().equals(FormField.FFT_BLANK)
                                && !fft.getFieldType().equals(FormField.FFT_LIST_MULTI)
                                && !fft.getFieldType().equals(FormField.FFT_TEXTAREA)) {
                            String paramValue = Utils.oracleSafe(nvl(reportParamValues.getParamValue(fieldId)));
                            chartYAxis = Utils.replaceInString(chartYAxis, fieldDisplay, nvl(
                                    paramValue, ""));
                        }
                    }
                }
                if (nvl(dc.getChartGroup()).length() > 0)
                    hashMap.put(dc.getChartGroup(), chartYAxis);
            }
        }
        return hashMap;
	}

    public List getChartGroupColumnAxisList(String chartGroupName, HashMap formValues) { /*
                                                                                          * filter; all=0;create without
                                                                                          * new chart =1;
                                                                                          * createNewChart=2
                                                                                          */
        List reportCols = getAllColumns();
        ArrayList chartGroupColAxis = new ArrayList();
        String chartGroup = chartGroupName.substring(0, chartGroupName.lastIndexOf("|"));
        int flag = 0;
        for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
            DataColumnType dc = (DataColumnType) iter.next();
            flag = getDependsOnFormFieldFlag(dc, formValues);

            if ((dc.getChartSeq() != null && dc.getChartSeq() > 0) && flag == 0) {
                if (nvl(dc.getChartGroup()).indexOf("|") > 0
                        && (nvl(dc.getChartGroup().substring(0, dc.getChartGroup().lastIndexOf("|")))
                                .equals(chartGroup))) {
                    chartGroupColAxis.add(dc);
                }
            }
        }
        Collections.sort(chartGroupColAxis, new ChartSeqComparator());
        return chartGroupColAxis;
	} 

    public List getChartGroupValueColumnAxisList(String chartGroupName, HashMap formValues) {
        List reportCols = getAllColumns();
        String index = chartGroupName.substring(chartGroupName.lastIndexOf("|") + 1);
        String chartGroup = chartGroupName.substring(0, chartGroupName.lastIndexOf("|"));
        ArrayList chartGroupValueColAxis = new ArrayList();
        int flag = 0;

        for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
            flag = 0;
            DataColumnType dc = (DataColumnType) iter.next();
            flag = getDependsOnFormFieldFlag(dc, formValues);

            if ((dc.getChartSeq() != null && dc.getChartSeq() > 0) && flag == 0) {
                if (nvl(dc.getChartGroup()).indexOf("|") > 0
                        && (nvl(dc.getChartGroup().substring(0, dc.getChartGroup().lastIndexOf("|")))
                                .equals(chartGroup))) {
                    chartGroupValueColAxis.add(dc);
                }
            }
        }
        return chartGroupValueColAxis;
	} 

    public List getChartGroupDisplayNamesList(String chartGroupName, HashMap formValues) {
        List reportCols = getAllColumns();
        ArrayList chartGroupValueColNames = new ArrayList();
        String chartGroup = chartGroupName.substring(0, chartGroupName.lastIndexOf("|"));
        int flag = 0;

        for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
            flag = 0;
            DataColumnType dc = (DataColumnType) iter.next();
            flag = getDependsOnFormFieldFlag(dc, formValues);

            if ((dc.getChartSeq() != null && dc.getChartSeq() > 0) && flag == 0) {
                if (nvl(dc.getChartGroup()).indexOf("|") > 0
                        && (nvl(dc.getChartGroup().substring(0, dc.getChartGroup().lastIndexOf("|")))
                                .equals(chartGroup))) {
                    chartGroupValueColNames.add(dc.getDisplayName());
                }
            }
        }
        return chartGroupValueColNames;
	} 


    public List getChartGroupColumnColorsList(String chartGroupName, HashMap formValues) {
        List reportCols = getAllColumns();
        ArrayList chartValueColColors = new ArrayList();
        String chartGroup = chartGroupName.substring(0, chartGroupName.lastIndexOf("|"));
        int flag = 0;
        for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
            flag = 0;
            DataColumnType dc = (DataColumnType) iter.next();
            flag = getDependsOnFormFieldFlag(dc, formValues);

            if ((dc.getChartSeq() != null && dc.getChartSeq() > 0) && flag == 0) {
                if (nvl(dc.getChartGroup()).indexOf("|") > 0
                        && (nvl(dc.getChartGroup().substring(0, dc.getChartGroup().lastIndexOf("|")))
                                .equals(chartGroup))) {
                    chartValueColColors.add(dc.getChartColor());
                }
            }
        }
        return chartValueColColors;
	}

    public List getCrossTabRowColumns() {
        List reportCols = getAllColumns();
        Vector v = new Vector(reportCols.size());

        for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
            DataColumnType dc = (DataColumnType) iter.next();
            if (nvl(dc.getCrossTabValue()).equals(AppConstants.CV_ROW))
                v.add(dc);
		} 

        return v;
	} 

    public List getCrossTabColColumns() {
        List reportCols = getAllColumns();
        Vector v = new Vector(reportCols.size());

        for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
            DataColumnType dc = (DataColumnType) iter.next();
            if (nvl(dc.getCrossTabValue()).equals(AppConstants.CV_COLUMN))
                v.add(dc);
		} 

        return v;
	} 

    public String getCrossTabDisplayTotal(String rowColPos) {
        DataColumnType dct = getCrossTabValueColumn();
        if (dct == null)
            return "";

        String displayTotal = nvl(dct.getDisplayTotal());
        if (displayTotal.indexOf('|') >= 0) {
            String displayColTotal = displayTotal.substring(0, displayTotal.indexOf('|'));
            String displayRowTotal = displayTotal.substring(displayTotal.indexOf('|') + 1);

            if (rowColPos.equals(AppConstants.CV_COLUMN))
                displayTotal = displayColTotal;
            else if (rowColPos.equals(AppConstants.CV_ROW))
                displayTotal = displayRowTotal;
            else if (displayColTotal.equals(displayRowTotal))
                displayTotal = displayColTotal;
		}

        return displayTotal;
	} 

    public DataColumnType getCrossTabValueColumn() {
        List reportCols = getAllColumns();
        for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
            DataColumnType dc = (DataColumnType) iter.next();
            if (nvl(dc.getCrossTabValue()).equals(AppConstants.CV_VALUE))
                return dc;
		} 

        return null;
	} 

	public int getCrossTabValueColumnIndex() { 
        List reportCols = getAllColumns();

        int idx = 0;
        for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
            DataColumnType dc = (DataColumnType) iter.next();
            if (nvl(dc.getCrossTabValue()).equals(AppConstants.CV_VALUE))
                break;
            if (dc.isVisible())
                idx++;
		} 

        return idx;
	} 

    public ColFilterType getFilterById(String colId, int filterIndex) {
        DataColumnType dc = getColumnById(colId);
        try {
            return dc.getColFilterList().getColFilter().get(filterIndex);
        } catch (Exception e) {
            logger.error(EELFLoggerDelegate.debugLogger, "Exception occured in getFilterById ", e);
            return null;
        }
	}

    public boolean needFormInput() {
        List reportCols = getAllColumns();
        for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
            DataColumnType dct = (DataColumnType) iter.next();

            if (dct.getColFilterList() != null) {
                List fList = dct.getColFilterList().getColFilter();
                for (Iterator iterF = fList.iterator(); iterF.hasNext();) {
                    ColFilterType cft = (ColFilterType) iterF.next();

                    if (nvl(cft.getArgType()).equals(AppConstants.AT_FORM))
                        return true;
				}
			} 
		} 

        return false;
	}

    public int getNumSortColumns() {
        int numSortCols = 0;
        for (Iterator iter = getAllColumns().iterator(); iter.hasNext();) {
            DataColumnType dct = (DataColumnType) iter.next();
            if (dct.getOrderBySeq() != null && dct.getOrderBySeq() > 0)
                numSortCols++;
		} 

        return numSortCols;
	} 

    public SemaphoreType getSemaphoreById(String semaphoreId) {
        if (getSemaphoreList() != null && semaphoreId != null)
            for (Iterator iter = getSemaphoreList().getSemaphore().iterator(); iter.hasNext();) {
                SemaphoreType sem = (SemaphoreType) iter.next();
                if (sem.getSemaphoreId().equals(semaphoreId))
                    return sem;
			}

        return null;
	} 

    public void deleteSemaphore(SemaphoreType semaphore) {
        if (getSemaphoreList() != null) {
            if (getSemaphoreList().getSemaphore() != null)
                getSemaphoreList().getSemaphore().remove((SemaphoreType) semaphore);
        }
	} 

    public void setSemaphore(SemaphoreType sem) {
        if (getSemaphoreList() != null) {
            getSemaphoreList().getSemaphore().add(sem);
        }

	} 

    public static FormatType getSemaphoreFormatById(SemaphoreType semaphore, String formatId) {
        if (semaphore != null)
            for (Iterator iter = semaphore.getFormatList().getFormat().iterator(); iter
                    .hasNext();) {
                FormatType fmt = (FormatType) iter.next();
                if (fmt.getFormatId().equals(formatId))
                    return fmt;
			} 

        return null;
	} 

    public FormFieldType getFormFieldById(String fieldId) {
        if (getFormFieldList() != null && fieldId != null)
            for (Iterator iter = getFormFieldList().getFormField().iterator(); iter.hasNext();) {
                FormFieldType fft = (FormFieldType) iter.next();
                if (fft.getFieldId().equals(fieldId))
                    return fft;
			} 

        return null;
	} 

    public FormFieldType getFormFieldByDisplayValue(String fieldDisplay) {
        if (getFormFieldList() != null && fieldDisplay != null)
            for (Iterator iter = getFormFieldList().getFormField().iterator(); iter.hasNext();) {
                FormFieldType fft = (FormFieldType) iter.next();
                if (fieldDisplay.equals(getFormFieldDisplayName(fft)))
                    return fft;
			} 

        return null;
	}
    public String getFormFieldDisplayName(FormFieldType fft) {
        return "[" + fft.getFieldName() + "]";
	}


    public void resetCache(boolean sqlOnly) {
        generatedSQL = null;
        if (!sqlOnly) {
            allColumns = null;
            allFilters = null;
        }
	} 

    public String getOuterJoinType(DataSourceType curTable) {
        String refDefinition = nvl(curTable.getRefDefinition());
        int outerJoinIdx = refDefinition.indexOf(" (+)");
        if (outerJoinIdx < 0)
            return "";

        int equalSignIdx = refDefinition.indexOf("=");
        if (refDefinition.indexOf(curTable.getTableId()) < equalSignIdx)
            return (outerJoinIdx < equalSignIdx) ? AppConstants.OJ_CURRENT
                    : AppConstants.OJ_JOINED;
        else
            return (outerJoinIdx < equalSignIdx) ? AppConstants.OJ_JOINED
                    : AppConstants.OJ_CURRENT;
	} 

    public String getFormFieldName(ColFilterType filter) {
        FormFieldType fft = null;
        if (filter.getArgType().equals(AppConstants.AT_FORM))
            fft = getFormFieldByDisplayValue(filter.getArgValue());

        return (fft != null) ? fft.getFieldId()
                : filter.getColId() + "_f"
                        + filter.getFilterSeq();
	} 

    public String getFormFieldDisplayName(DataColumnType column, ColFilterType filter) {
        FormFieldType fft = null;
        if (filter.getArgType().equals(AppConstants.AT_FORM))
            fft = getFormFieldByDisplayValue(filter.getArgValue());

        return (fft != null) ? fft.getFieldName()
                : column.getDisplayName() + "&nbsp;"
                        + filter.getExpression();
	}

    public Calendar getFormFieldRangeStart(ColFilterType filter) {
        FormFieldType fft = null;
        if (filter.getArgType().equals(AppConstants.AT_FORM))
            fft = getFormFieldByDisplayValue(filter.getArgValue());

        return (fft != null) ? fft.getRangeStartDate().toGregorianCalendar() : null;
	} 

    public Calendar getFormFieldRangeEnd(ColFilterType filter) {
        FormFieldType fft = null;
        if (filter.getArgType().equals(AppConstants.AT_FORM))
            fft = getFormFieldByDisplayValue(filter.getArgValue());
        return (fft != null) ? fft.getRangeEndDate().toGregorianCalendar() : null;
	} 

    public String getFormFieldRangeStartSQL(ColFilterType filter) {
        FormFieldType fft = null;
        if (filter.getArgType().equals(AppConstants.AT_FORM))
            fft = getFormFieldByDisplayValue(filter.getArgValue());

        return (fft != null) ? fft.getRangeStartDateSQL() : null;
	} 

    public String getFormFieldRangeEndSQL(ColFilterType filter) {
        FormFieldType fft = null;
        if (filter.getArgType().equals(AppConstants.AT_FORM))
            fft = getFormFieldByDisplayValue(filter.getArgValue());
        return (fft != null) ? fft.getRangeEndDateSQL() : null;
	}

    public String getUniqueTableId(String tableName) {
        String tableIdPrefix = tableName.startsWith("MSA_") ? tableName.substring(4, 6)
                : tableName.substring(0, 2);
        String tableId = "";

        int tableIdN = getDataSourceList().getDataSource().size() + 1;
        do {
            tableId = tableIdPrefix.toLowerCase() + (tableIdN++);
        } while (getTableById(tableId) != null);

        return tableId;
	} 

    protected void deleteDataSourceType(String tableId) {
        List dsList = getDataSourceList().getDataSource();
        for (Iterator iter = dsList.iterator(); iter.hasNext();) {
            DataSourceType dst = (DataSourceType) iter.next();
            if (dst.getTableId().equals(tableId))
                iter.remove();
            else if (nvl(dst.getRefTableId()).equals(tableId)) {
                dst.setRefTableId(null);
                dst.setRefDefinition(null);
            }
		} 

        resetCache(false);
	}

    public static void adjustColumnType(DataColumnType dct) {
        dct.setColType(dct.getDbColType());

        if (dct.isCalculated())
            if (dct.getColName().startsWith("SUM(") || dct.getColName().startsWith("COUNT(")
                    || dct.getColName().startsWith("AVG(")
                    || dct.getColName().startsWith("STDDEV(")
                    || dct.getColName().startsWith("VARIANCE("))
                dct.setColType(AppConstants.CT_NUMBER);
            else if (dct.getColName().startsWith("DECODE(") || dct.getColName().startsWith("coalesce("))
                dct.setColType(AppConstants.CT_CHAR);
	} 
    public static boolean getColumnNoParseDateFlag(DataColumnType dct) {
        return (nvls(dct.getComment()).indexOf(AppConstants.CF_NO_PARSE_DATE) >= 0);
	}

    public static void setColumnNoParseDateFlag(DataColumnType dct, boolean noParseDateFlag) {
        dct.setComment(noParseDateFlag ? AppConstants.CF_NO_PARSE_DATE : null);
	} 


    public static String getSQLBasedFFTColTableName(String fftColId) {
        return fftColId.substring(0, fftColId.indexOf('.'));
	} 

    public static String getSQLBasedFFTColColumnName(String fftColId) {
        fftColId = (fftColId.indexOf('|') < 0) ? fftColId
                : fftColId.substring(0, fftColId
                        .indexOf('|'));
        return fftColId.substring(fftColId.indexOf('.') + 1);
	} 
    public static String getSQLBasedFFTColDisplayFormat(String fftColId) {
        return (fftColId.indexOf('|') < 0) ? ""
                : fftColId
                        .substring(fftColId.indexOf('|') + 1);
	} 


    public List<DataColumnType> getAllColumns() {
        if (cr == null)
            throw new NullPointerException("CustomReport not initialized");

        if (allColumns == null) {
            allColumns = new Vector();

            List dsList = getDataSourceList().getDataSource();
            for (Iterator iter = dsList.iterator(); iter.hasNext();) {
                DataSourceType ds = (DataSourceType) iter.next();
                List dcList = ds.getDataColumnList().getDataColumn();
                for (Iterator iterC = dcList.iterator(); iterC.hasNext();) {
                    DataColumnType dc = (DataColumnType) iterC.next();

                    allColumns.add(dc);
				} 
			} 

            Collections.sort(allColumns, new OrderSeqComparator());
		} 

        return allColumns;
	}

    public List getOnlyVisibleColumns() {
        if (cr == null)
            throw new NullPointerException("CustomReport not initialized");

        if (allVisibleColumns == null) {
            allVisibleColumns = new Vector();

            List dsList = getDataSourceList().getDataSource();
            for (Iterator iter = dsList.iterator(); iter.hasNext();) {
                DataSourceType ds = (DataSourceType) iter.next();
                List dcList = ds.getDataColumnList().getDataColumn();
                for (Iterator iterC = dcList.iterator(); iterC.hasNext();) {
                    DataColumnType dc = (DataColumnType) iterC.next();
                    if (dc.isVisible())
                        allVisibleColumns.add(dc);
				} 
			} 

            Collections.sort(allVisibleColumns, new OrderSeqComparator());
		} 

        return allVisibleColumns;
	} 
    public int getVisibleColumnCount() {
        if (cr == null)
            throw new NullPointerException("CustomReport not initialized");
        int colCount = 0;
        List dsList = getDataSourceList().getDataSource();
        for (Iterator iter = dsList.iterator(); iter.hasNext();) {
            DataSourceType ds = (DataSourceType) iter.next();
            List dcList = ds.getDataColumnList().getDataColumn();
            for (Iterator iterC = dcList.iterator(); iterC.hasNext();) {
                DataColumnType dc = (DataColumnType) iterC.next();
                if (dc.isVisible())
                    colCount++;
				} 
			} 

        return colCount;
    }

    public List getAllFilters() {
        if (cr == null)
            throw new NullPointerException("CustomReport not initialized");

        allFilters = new Vector();

        List reportCols = getAllColumns();
        for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
            DataColumnType dct = (DataColumnType) iter.next();

            if (dct.getColFilterList() != null) {
                List colFilters = dct.getColFilterList().getColFilter();

                for (Iterator iterF = colFilters.iterator(); iterF.hasNext();) {
                    ColFilterType cft = (ColFilterType) iterF.next();

                    allFilters.add(cft);
				} 
			} 
		} 
        return allFilters;
	}

    private String formatValue(String value, DataColumnType dc, boolean useDefaultDateFormat) throws RaptorException {
        return formatValue(value, dc, useDefaultDateFormat, getColumnTableById(dc.getColId()), null);
	}

    private String formatValue(String value, DataColumnType dc, boolean useDefaultDateFormat,
            DataSourceType ds, FormFieldType fft) throws RaptorException {
        String fmtValue = null;

        if (nvl(value).length() == 0)
            fmtValue = "";
        else if (value.equals(AppConstants.FILTER_MAX_VALUE)
                || value.equals(AppConstants.FILTER_MIN_VALUE))
            fmtValue = "(SELECT "
                    + (value.equals(AppConstants.FILTER_MAX_VALUE) ? "MAX" : "MIN") + "("
                    + dc.getColName() + ") FROM " + ds.getTableName() + ")";
        else if (dc.getColType().equals(AppConstants.CT_NUMBER)) {
            try {
                double vD = Double.parseDouble(value);
                fmtValue = value;
            } catch (NumberFormatException ex) {
                throw new UserDefinedException(
                        "Expected number, Given String for the form field \"" + fft.getFieldName() + "\"");
            }
        } else if (dc.getColType().equals(AppConstants.CT_DATE)) {
            if (fft != null && (fft.getValidationType().equals(FormField.VT_TIMESTAMP_HR)
                    || fft.getValidationType().equals(FormField.VT_TIMESTAMP_MIN)
                    || fft.getValidationType().equals(FormField.VT_TIMESTAMP_SEC))) {
                fmtValue = "TO_DATE('"
                        + value
                        + "', '"
                        + (useDefaultDateFormat ? AppConstants.DEFAULT_DATE_FORMAT
                                : nvl(dc
							.getColFormat(), AppConstants.DEFAULT_DATE_FORMAT));
                fmtValue = fmtValue + " HH24";
                if (fft.getValidationType().equals(FormField.VT_TIMESTAMP_MIN)
                        || fft.getValidationType().equals(FormField.VT_TIMESTAMP_SEC))
                    fmtValue = fmtValue + ":MI";
                if (fft.getValidationType().equals(FormField.VT_TIMESTAMP_SEC))
                    fmtValue = fmtValue + " HH24:MI:SS";
            } else {
                fmtValue = "TO_DATE('"
                        + value
                        + "', '"
                        + (useDefaultDateFormat ? AppConstants.DEFAULT_DATE_FORMAT
                                : nvl(dc
                                        .getColFormat(), AppConstants.DEFAULT_DATE_FORMAT))
                        + "')";
                if (Globals.getMonthFormatUseLastDay())
                    if (!useDefaultDateFormat)
                        if ("MM/YYYY".equals(nvl(dc.getColFormat(), AppConstants.DEFAULT_DATE_FORMAT))
                                || "MONTH, YYYY"
                                        .equals(nvl(dc.getColFormat(), AppConstants.DEFAULT_DATE_FORMAT)))
                            fmtValue = "ADD_MONTHS(" + fmtValue + ", 1)-1";
            }
        } else {
            fmtValue = value;
            if (!fmtValue.startsWith("'"))
                fmtValue = "'" + fmtValue + "'";
        }

        return fmtValue;
	}

    private String formatListValue(String listValue, DataColumnType dc,
            boolean useDefaultDateFormat, boolean useOnlyPipeDelimiter) throws RaptorException {
        return formatListValue("", listValue, dc, useDefaultDateFormat, useOnlyPipeDelimiter,
                getColumnTableById(dc.getColId()), null);
	} 

    public String formatListValue(String fieldDisplay, String listValue, DataColumnType dc,
            boolean useDefaultDateFormat, boolean useOnlyPipeDelimiter, DataSourceType ds,
            String listBaseSQL) throws RaptorException {
        StringBuffer fmtValue = new StringBuffer("");
        StringTokenizer st = new StringTokenizer(listValue, useOnlyPipeDelimiter ? "|"
                : ",\n\r\f");

        while (st.hasMoreTokens()) {
            if (fmtValue.length() > 0)
                fmtValue.append(", ");

            if (dc == null) {
                String value = st.nextToken().trim();
                if (value.startsWith("'"))
                    fmtValue.append(value);
                else
                    fmtValue.append("'" + value + "'");
            } else
                fmtValue.append(formatValue(st.nextToken().trim(), dc, useDefaultDateFormat,
                        ds, null));

		}

        if (fmtValue.length() == 0) {
            if (nvl(fieldDisplay).length() > 0) {
                fmtValue.append("");
            } else {
                fmtValue.append("(");
                fmtValue.append(nvl(listBaseSQL, "NULL"));
                fmtValue.append(")");
            }
        } else if (fmtValue.charAt(0) != '(') {
            fmtValue.insert(0, '(');
            fmtValue.append(')');
        }

        return fmtValue.toString();
	} 

    private String getColumnSelectStr(DataColumnType dc, ReportParamValues paramValues) {
        String colName = dc.isCalculated() ? dc.getColName()
                : ((nvl(dc.getTableId()).length() > 0) ? (dc.getTableId() + "." + dc
                        .getColName()) : dc.getColName());
        String paramValue = null;
        if (dc.isCalculated())
            if (getFormFieldList() != null)
                for (Iterator iter2 = getFormFieldList().getFormField().iterator(); iter2
                        .hasNext();) {
                    FormFieldType fft = (FormFieldType) iter2.next();
                    String fieldId = fft.getFieldId();
                    String fieldDisplay = getFormFieldDisplayName(fft);
                    if (!paramValues.isParameterMultiValue(fieldId)) {
                        paramValue = paramValues.getParamValue(fieldId);
                        if (paramValue != null && paramValue.length() > 0) {
                            colName = Utils.replaceInString(colName, fieldDisplay, Utils
                                    .oracleSafe(nvl(paramValue, "NULL")));
                        } else {
                            colName = Utils.replaceInString(colName, "'" + fieldDisplay + "'", nvl(
                                    paramValue, "NULL"));
                            colName = Utils.replaceInString(colName, fieldDisplay, nvl(
                                    paramValue, "NULL"));
                        }
                    }
				}

        return colName;
	} 

    private void addExtraIdSelect(StringBuffer selectExtraIdCl, String drillDownParams,
            boolean includeSelectExpr) {
		drillDownParams = drillDownParams.substring(10, drillDownParams.length() - 1); 

        selectExtraIdCl.append(", ");
        if (includeSelectExpr) {
            selectExtraIdCl.append(drillDownParams);
            selectExtraIdCl.append(" ");
        } // if
		selectExtraIdCl.append(drillDownParams.replace('.', '_')); 
	} 

    private void addExtraDateSelect(StringBuffer selectExtraDateCl, String drillDownParams,
            ReportParamValues paramValues, boolean includeSelectExpr) {
        String colId = "";
        while (drillDownParams.indexOf('[') >= 0) {
            int startIdx = drillDownParams.indexOf('[');
            int endIdx = drillDownParams.indexOf(']');

            if (startIdx <= endIdx) {
				colId = drillDownParams.substring(startIdx + 1, endIdx); 
            } else {
                drillDownParams = drillDownParams.substring(endIdx + 1);
                continue;
            }
																		

            DataColumnType column = getColumnById(colId);
            if (column != null)
                if (column.getColType().equals(AppConstants.CT_DATE))
                    if (!nvl(column.getColFormat(), AppConstants.DEFAULT_DATE_FORMAT).equals(
                            AppConstants.DEFAULT_DATE_FORMAT))
                        if (selectExtraDateCl.toString().indexOf(
                                " " + colId + AppConstants.DD_COL_EXTENSION) < 0) {
                            selectExtraDateCl.append(", ");
                            if (includeSelectExpr) {
                                selectExtraDateCl.append("TO_CHAR("
                                        + getColumnSelectStr(column, paramValues) + ", '"
                                        + AppConstants.DEFAULT_DATE_FORMAT + "')");
                                selectExtraDateCl.append(" ");
							} 
							selectExtraDateCl.append(colId + AppConstants.DD_COL_EXTENSION);
						} 

            drillDownParams = drillDownParams.substring(endIdx + 1);
		} 
	} 


    public String generateSQL(String userId, HttpServletRequest request) throws RaptorException {
        return generateSQL(new ReportParamValues(), userId, request);
	} 
    public String generateSQL(ReportParamValues paramValues, String userId, HttpServletRequest request)
            throws RaptorException {
        return generateSQL(paramValues, null, AppConstants.SO_ASC, userId, request);
	} 

    public String generateSQL(ReportParamValues paramValues, String overrideSortByColId,
            String overrideSortByAscDesc, String userId, HttpServletRequest request) throws RaptorException {
        if (cr == null)
            throw new NullPointerException("CustomReport not initialized");
        if (nvl(getWholeSQL()).length() > 0)
            return getWholeSQL();
        if (paramValues.size() > 0)
            resetCache(true);
          
        if (generatedSQL == null) {
            if (getReportDefType().equals(AppConstants.RD_SQL_BASED)
                    || getReportDefType().equals(AppConstants.RD_SQL_BASED_DATAMIN)) {
                generatedSQL = generateSQLSQLBased(paramValues, overrideSortByColId,
                        overrideSortByAscDesc, userId, request);
                generatedChartSQL = generateSQLSQLBased(paramValues, null,
                        AppConstants.SO_ASC, userId, request);
            } else if (getReportDefType().equals(AppConstants.RD_VISUAL)
                    && !getReportType().equals(AppConstants.RT_CROSSTAB)) {
                generatedSQL = generateSQLVisual(paramValues, overrideSortByColId,
                        overrideSortByAscDesc, userId, request);
                generatedChartSQL = generateSQLVisual(paramValues, null,
                        AppConstants.SO_ASC, userId, request);
            } else {
                generatedSQL = generateSQLCrossTabVisual(paramValues, overrideSortByColId,
                        overrideSortByAscDesc, userId, request);
            }

            generatedSQL = replaceNewLine(generatedSQL, "" + '\n', " " + '\n' + " ");
            if (nvl(generatedChartSQL).trim().length() > 0)
                generatedChartSQL = replaceNewLine(generatedChartSQL, "" + '\n', " " + '\n' + " ");
		} 

        return generatedSQL;
	} 

    public String generateSQLSQLBased(ReportParamValues paramValues,
            String overrideSortByColId, String overrideSortByAscDesc, String userId, HttpServletRequest request)
            throws RaptorException {
        String sql = getReportSQL();
        DataSet ds = null;
        String[] reqParameters = Globals.getRequestParams().split(",");
        String[] sessionParameters = Globals.getSessionParams().split(",");
        String[] scheduleSessionParameters = Globals.getSessionParamsForScheduling().split(",");
        javax.servlet.http.HttpSession session = request.getSession();
        String dbType = "";
        String dbInfo = getDBInfo();
        int fieldCount = 0;
        Pattern re1 = null;
        Matcher matcher = null;
        int index = 0;
        int posFormField = 0;
        int posAnd = 0;
        if (!isNull(dbInfo) && (!dbInfo.equals(AppConstants.DB_LOCAL))) {
            try {
                dbType = remDbInfo.getDBType(dbInfo);
            } catch (Exception ex) {
                throw new RaptorException(ex);
            }
        }

        sql = sql + " ";
        sql = Pattern.compile("(^[\r\n]*|([\\s]))[Ss][Ee][Ll][Ee][Cc][Tt]([\r\n]*|[\\s]*)", Pattern.DOTALL).matcher(sql)
                .replaceAll(" SELECT ");
        sql = Pattern.compile("(^[\r\n]*|([\\s]))[Ww][Hh][Ee][Rr][Ee]([\r\n]*|[\\s]*)", Pattern.DOTALL).matcher(sql)
                .replaceAll(" WHERE ");
        sql = Pattern.compile("(^[\r\n]*|([\\s]))[Ww][Hh][Ee][Nn]([\r\n]*|[\\s]*)", Pattern.DOTALL).matcher(sql)
                .replaceAll(" WHEN ");
        sql = Pattern.compile("(^[\r\n]*|([\\s]))[Aa][Nn][Dd]([\r\n]*|[\\s]*)", Pattern.DOTALL).matcher(sql)
                .replaceAll(" AND ");

        if (getFormFieldList() != null) {
            for (Iterator iter = getFormFieldList().getFormField().iterator(); iter.hasNext();) {

                FormFieldType fft = (FormFieldType) iter.next();
                String fieldId = fft.getFieldId();
                String fieldDisplay = getFormFieldDisplayName(fft);
                if (!fft.getFieldType().equals(FormField.FFT_BLANK)) {
                    if (paramValues.isParameterMultiValue(fieldId)) {
                        String replaceValue = formatListValue(fieldDisplay, Utils
                                .oracleSafe(nvl(paramValues.getParamValue(fieldId))), null, false,
                                true, null, paramValues.getParamBaseSQL(fieldId));
                        if (replaceValue.length() > 0) {
                            sql = Utils.replaceInString(sql, fieldDisplay, replaceValue);
                        } else {
                            fieldCount++;
                            if (fieldCount == 1) {
                            }
                            while (sql.indexOf(fieldDisplay) > 0) {
                                re1 = Pattern.compile(
                                        "(^[\r\n]|[\\s])AND(.*?[^\r\n]*)" + "\\[" + fft.getFieldName() + "\\](.*?)\\s",
                                        Pattern.DOTALL);
                                posFormField = sql.indexOf(fieldDisplay);
                                int posSelectField = sql.lastIndexOf("SELECT ", posFormField);
                                int andField = 0;
                                int whereField = 0;
								int	whenField = 0;
                                andField = sql.lastIndexOf(" AND ", posFormField);
                                whereField = sql.indexOf(" WHERE", posSelectField);
                                whenField = sql.indexOf(" WHEN", posSelectField);

                                if (posFormField > whereField)
                                    andField = sql.lastIndexOf(" AND ", posFormField);
                                if (posFormField > andField && (andField > whereField || andField > whenField))
                                    posAnd = andField;
                                else
                                    posAnd = 0;
                                matcher = re1.matcher(sql);

                                if (posAnd > 0 && matcher.find(posAnd - 1)) {
           						
                                    matcher = re1.matcher(sql);
                                    index = sql != null ? sql.lastIndexOf("[" + fft.getFieldName() + "]") : -1;

                                    if (andField > 0)
                                        index = andField;
                                    else
                                        index = whereField;
                                    if (index >= 0 && matcher.find(index - 1)) {
                                        sql = sql.replace(matcher.group(), " ");
                                    }
                                } else {

                                    re1 = Pattern.compile(
                                            "(^[\r\n]|[\\s])WHERE(.*?[^\r\n]*)\\[" + fft.getFieldName() + "\\](.*?)\\s",
                                            Pattern.DOTALL);
                                    matcher = re1.matcher(sql);
                                    if (whereField != -1) {
                                        if (matcher.find(whereField - 1)) {
                                            matcher = re1.matcher(sql);
                                            index = sql != null ? sql.lastIndexOf("[" + fft.getFieldName() + "]") : -1;
                                            if (index >= 0 && matcher.find(index - 30)) {
                                                sql = sql.replace(matcher.group(), " WHERE 1=1 ");
                                            }
                                        } 
                                    } else {
                                        sql = Utils.replaceInString(sql, fieldDisplay, replaceValue);
                                    }

                                }
                            }
                        }

                    } else {
                        String paramValue = "";
                        if (paramValues.isParameterTextAreaValueAndModified(fieldId)) {
                            String value = "";
                            value = nvl(paramValues
                                    .getParamValue(fieldId));
                            paramValue = value;
                        } else
                            paramValue = Utils.oracleSafe(nvl(paramValues
                                    .getParamValue(fieldId)));

                        if (paramValue != null && paramValue.length() > 0) {
                            if (paramValue.toLowerCase().trim().startsWith("select ")) {
                                paramValue = Utils.replaceInString(paramValue, "[LOGGED_USERID]", userId);
                                paramValue = Utils.replaceInString(paramValue, "[USERID]", userId);
                                paramValue = Utils.replaceInString(paramValue, "[USER_ID]", userId);

                                paramValue = Utils.replaceInString(paramValue, "''", "'");
                                ds = ConnectionUtils.getDataSet(paramValue, dbInfo);
                                if (ds.getRowCount() > 0)
                                    paramValue = ds.getString(0, 0);
                            }
                            if (fft != null && (fft.getValidationType() != null
                                    && (fft.getValidationType().equals(FormField.VT_TIMESTAMP_HR)
                                            || fft.getValidationType().equals(FormField.VT_TIMESTAMP_MIN)
                                            || fft.getValidationType().equals(FormField.VT_TIMESTAMP_SEC)
                                            || fft.getValidationType().equals(FormField.VT_DATE)))) {
                                if (fft.getValidationType().equals(FormField.VT_TIMESTAMP_HR)) {
                                    sql = Utils.replaceInString(sql, fieldDisplay, nvl(
                                            paramValue)
                                            + ((nvl(paramValues
                                                    .getParamValue(fieldId + "_Hr")).length() > 0)
                                                            ? " " + addZero(Utils.oracleSafe(nvl(paramValues
                                                                    .getParamValue(fieldId + "_Hr"))))
                                                            : ""));
                                } else if (fft.getValidationType().equals(FormField.VT_TIMESTAMP_MIN)) {
			                            sql = Utils.replaceInString(sql, fieldDisplay, nvl(
                                            paramValue)
                                            + ((nvl(paramValues
                                                    .getParamValue(fieldId + "_Hr")).length() > 0)
                                                            ? " " + addZero(Utils.oracleSafe(nvl(paramValues
                                                                    .getParamValue(fieldId + "_Hr"))))
                                                            : "")
                                            + ((nvl(paramValues
                                                    .getParamValue(fieldId + "_Min")).length() > 0)
                                                            ? ":" + addZero(Utils.oracleSafe(nvl(paramValues
                                                                    .getParamValue(fieldId + "_Min"))))
                                                            : ""));
                                } else if (fft.getValidationType().equals(FormField.VT_TIMESTAMP_SEC)) {
                                    sql = Utils.replaceInString(sql, fieldDisplay, nvl(
                                            paramValue)
                                            + ((nvl(paramValues
                                                    .getParamValue(fieldId + "_Hr")).length() > 0)
                                                            ? " " + addZero(Utils.oracleSafe(nvl(paramValues
                                                                    .getParamValue(fieldId + "_Hr"))))
                                                            : "")
                                            + ((nvl(paramValues
                                                    .getParamValue(fieldId + "_Min")).length() > 0)
                                                            ? ":" + addZero(Utils.oracleSafe(nvl(paramValues
                                                                    .getParamValue(fieldId + "_Min"))))
                                                            : "")
                                            + ((nvl(paramValues
                                                    .getParamValue(fieldId + "_Sec")).length() > 0)
                                                            ? ":" + addZero(Utils.oracleSafe(nvl(paramValues
                                                                    .getParamValue(fieldId + "_Sec"))))
                                                            : ""));
                                } else {
                                    sql = Utils.replaceInString(sql, fieldDisplay, nvl(
                                            paramValue, "NULL"));
                                }

                            } else {
                                if (paramValue != null && paramValue.length() > 0) {
                                    if (sql.indexOf("'" + fieldDisplay + "'") != -1
                                            || sql.indexOf("'" + fieldDisplay) != -1
                                            || sql.indexOf(fieldDisplay + "'") != -1
                                            || sql.indexOf("'%" + fieldDisplay + "%'") != -1
                                            || sql.indexOf("'%" + fieldDisplay) != -1
                                            || sql.indexOf(fieldDisplay + "%'") != -1
                                            || sql.indexOf("'_" + fieldDisplay + "_'") != -1
                                            || sql.indexOf("'_" + fieldDisplay) != -1
                                            || sql.indexOf(fieldDisplay + "_'") != -1
                                            || sql.indexOf("'%_" + fieldDisplay + "_%'") != -1
                                            || sql.indexOf("^" + fieldDisplay + "^") != -1
                                            || sql.indexOf("'%_" + fieldDisplay) != -1
                                            || sql.indexOf(fieldDisplay + "_%'") != -1) {
                                        sql = Utils.replaceInString(sql, fieldDisplay, nvl(
                                                paramValue, "NULL"));
                                    } else {
                                        if (sql.indexOf(fieldDisplay) != -1) {
                                            if (nvl(paramValue).length() > 0) {
                                                try {
                                                    double vD = Double.parseDouble(paramValue);
                                                    sql = Utils.replaceInString(sql, fieldDisplay, nvl(
                                                            paramValue, "NULL"));

                                                } catch (NumberFormatException ex) {
                                                    if (sql.trim().toUpperCase()
                                                            .startsWith("SELECT")) {
                                                        sql = Utils.replaceInString(sql, fieldDisplay, nvl(
                                                                paramValue, "NULL"));
                                                    } else
                                                        throw new UserDefinedException(
                                                                "Expected number, Given String for the form field \""
                                                                        + fieldDisplay + "\"");
                                                }
                                              
                                            } else
                                                sql = Utils.replaceInString(sql, fieldDisplay, nvl(
                                                        paramValue, "NULL"));

                                        }
                                    }
                                } else {
                                    if ("DAYTONA".equals(dbType) && sql.trim().toUpperCase().startsWith("SELECT")) {
                                        sql = sql + " ";
                                        re1 = Pattern.compile("(^[\r\n]|[\\s]|[^0-9a-zA-Z])AND(.*?[^\r\n]*)" + "\\["
                                                + fft.getFieldName() + "\\](.*?)\\s", Pattern.DOTALL);
                                        posFormField = sql.indexOf(fieldDisplay);
                                        posAnd = sql.lastIndexOf(" AND ", posFormField);
                                        if (posAnd < 0)
                                            posAnd = 0;
                                        else if (posAnd > 2)
                                            posAnd = posAnd - 2;
                                        matcher = re1.matcher(sql);
                                        if (matcher.find(posAnd)) {
                                            sql = sql.replace(matcher.group(), "");
                                        }
                                    } else {
                                        sql = Utils.replaceInString(sql, "'" + fieldDisplay + "'", nvl(
                                                paramValue, "NULL"));
                                        sql = Utils.replaceInString(sql, fieldDisplay, nvl(
                                                paramValue, "NULL"));
                                    }
                                }
                            }

                        }

                        if ("DAYTONA".equals(dbType) && sql.trim().toUpperCase().startsWith("SELECT")) {
                            sql = sql + " ";
                            re1 = Pattern.compile("(^[\r\n]|[\\s]|[^0-9a-zA-Z])AND(.*?[^\r\n]*)" + "\\["
                                    + fft.getFieldName() + "\\](.*?)\\s", Pattern.DOTALL); // +[\'\\)|\'|\\s]
                            posFormField = sql.indexOf(fieldDisplay);
                            posAnd = sql.lastIndexOf(" AND ", posFormField);
                            if (posAnd < 0)
                                posAnd = 0;
                            else if (posAnd > 2)
                                posAnd = posAnd - 2;
                            matcher = re1.matcher(sql);
                            if (matcher.find(posAnd)) {
                                sql = sql.replace(matcher.group(), " ");
                            }
                        } else {
                            if (fft.isGroupFormField() != null && fft.isGroupFormField().booleanValue()) {
                                sql = Pattern.compile("[[\\s*][,]]\\[" + fft.getFieldName() + "\\](.*?)[,]",
                                        Pattern.MULTILINE).matcher(sql).replaceAll(" ");
                                sql = Pattern
                                        .compile("(,.+?)[\\s*]\\[" + fft.getFieldName() + "\\][\\s]", Pattern.MULTILINE)
                                        .matcher(sql).replaceAll(" ");
           				} else {
                                sql = Utils.replaceInString(sql, "'" + fieldDisplay + "'", nvl(
                                        paramValue, "NULL"));
                                sql = Utils.replaceInString(sql, fieldDisplay, nvl(
                                        paramValue, "NULL"));
                            }
                        }

				} 
				}
			} 
            if (request != null) {
                for (int i = 0; i < reqParameters.length; i++) {
                    if (!reqParameters[i].startsWith("ff")) {
                        if (nvl(request.getParameter(reqParameters[i].toUpperCase())).length() > 0)
                            sql = Utils.replaceInString(sql, "[" + reqParameters[i].toUpperCase() + "]",
                                    ESAPI.encoder().encodeForSQL(SecurityCodecUtil.getCodec(),
                                            request.getParameter(reqParameters[i].toUpperCase())));
                    } else
                        sql = Utils.replaceInString(sql, "[" + reqParameters[i].toUpperCase() + "]", ESAPI.encoder()
                                .encodeForSQL(SecurityCodecUtil.getCodec(), request.getParameter(reqParameters[i])));
                }

                for (int i = 0; i < scheduleSessionParameters.length; i++) {
                    if (nvl(request.getParameter(scheduleSessionParameters[i])).trim().length() > 0)
                        sql = Utils.replaceInString(sql, "[" + scheduleSessionParameters[i].toUpperCase() + "]",
                                ESAPI.encoder().encodeForSQL(SecurityCodecUtil.getCodec(),
                                        request.getParameter(scheduleSessionParameters[i])));
                }
            }
            if (session != null) {
                for (int i = 0; i < sessionParameters.length; i++) {
                    sql = Utils.replaceInString(sql, "[" + sessionParameters[i].toUpperCase() + "]",
                            (String) session.getAttribute(sessionParameters[i]));
                    
                }
            }
        } else {
            sql = Utils.replaceInString(sql, "[LOGGED_USERID]", userId);
            sql = Utils.replaceInString(sql, "[USERID]", userId);
            sql = Utils.replaceInString(sql, "[USER_ID]", userId);
            if (request != null) {
                for (int i = 0; i < reqParameters.length; i++) {
                    sql = Utils.replaceInString(sql, "[" + reqParameters[i].toUpperCase() + "]", ESAPI.encoder()
                            .encodeForSQL(SecurityCodecUtil.getCodec(), request.getParameter(reqParameters[i])));
                }
            }
            if (session != null) {
                for (int i = 0; i < sessionParameters.length; i++) {
                    sql = Utils.replaceInString(sql, "[" + sessionParameters[i].toUpperCase() + "]",
                            (String) session.getAttribute(sessionParameters[i]));
                }
            }
        }
        sql = Utils.replaceInString(sql, "[LOGGED_USERID]",
                ESAPI.encoder().encodeForSQL(SecurityCodecUtil.getCodec(), userId));
        sql = Utils.replaceInString(sql, "[USERID]",
                ESAPI.encoder().encodeForSQL(SecurityCodecUtil.getCodec(), userId));
        sql = Utils.replaceInString(sql, "[USER_ID]",
                ESAPI.encoder().encodeForSQL(SecurityCodecUtil.getCodec(), userId));

        int closeBracketPos = 0;
        if (nvl(overrideSortByColId).length() > 0) {
            if (sql.lastIndexOf(")") != -1)
                closeBracketPos = sql.lastIndexOf(")");
            int idxOrderBy = (closeBracketPos > 0) ? sql.toUpperCase().indexOf("ORDER BY", closeBracketPos)
                    : sql.toUpperCase().lastIndexOf("ORDER BY");
            DataColumnType dct = getColumnById(overrideSortByColId + "_sort");
            if (dct != null && dct.getColName().length() > 0) {
                overrideSortByColId = overrideSortByColId + "_sort";
            }
            if (idxOrderBy < 0)
                sql += " ORDER BY " + overrideSortByColId + " " + overrideSortByAscDesc;
            else {
                int braketCount = 0;
                int idxOrderByClauseEnd = 0;
                for (idxOrderByClauseEnd = idxOrderBy; idxOrderByClauseEnd < sql.length(); idxOrderByClauseEnd++) {
                    char ch = sql.charAt(idxOrderByClauseEnd);

                    if (ch == '(')
                        braketCount++;
                    else if (ch == ')') {
                        if (braketCount == 0)
                            break;
                        braketCount--;
                    }
				}

                sql = sql.substring(0, idxOrderBy) + " ORDER BY " + overrideSortByColId + " "
                        + overrideSortByAscDesc + sql.substring(idxOrderByClauseEnd);
			}
		} 
        sql = Pattern.compile("([\n][\\s]*)", Pattern.DOTALL).matcher(sql).replaceAll(" ");
        return sql;
	} 

    public String generateSQLVisual(ReportParamValues paramValues, String overrideSortByColId,
            String overrideSortByAscDesc, String userId, HttpServletRequest request) throws RaptorException {
        StringBuffer selectCl = new StringBuffer();
        StringBuffer fromCl = new StringBuffer();
        StringBuffer whereCl = new StringBuffer();
        StringBuffer groupByCl = new StringBuffer();
        StringBuffer havingCl = new StringBuffer();
        StringBuffer orderByCl = new StringBuffer();
        StringBuffer selectExtraIdCl = new StringBuffer();
        StringBuffer selectExtraDateCl = new StringBuffer();

        int whereClBracketCount = 0;
        int havingClBracketCount = 0;
        int whereClCarryoverBrackets = 0;
        int havingClCarryoverBrackets = 0;

        List dsList = getDataSourceList().getDataSource();
        for (Iterator iter = dsList.iterator(); iter.hasNext();) {
            DataSourceType ds = (DataSourceType) iter.next();

            if (fromCl.length() > 0)
                fromCl.append(", ");
            fromCl.append(ds.getTableName());
            fromCl.append(" ");
            fromCl.append(ds.getTableId());

            if (nvl(ds.getRefTableId()).length() > 0) {
                if (whereCl.length() > 0)
                    whereCl.append(" AND ");
                whereCl.append(ds.getRefDefinition());
			}
            TableSource tableSource = null;
            String dBInfo = this.cr.getDbInfo();
            Vector userRoles = AppUtils.getUserRoles(request);
            tableSource = DataCache.getTableSource(ds.getTableName(), dBInfo, userRoles, userId, request);
            if (userId != null && (!AppUtils.isSuperUser(request))
                    && (!AppUtils.isAdminUser(request)) && tableSource != null
                    && nvl(tableSource.getFilterSql()).length() > 0) {
                if (whereCl.length() > 0)
                    whereCl.append(" AND ");
                whereCl.append(Utils.replaceInString(Utils.replaceInString(tableSource
                        .getFilterSql(), "[" + ds.getTableName() + "]", ds.getTableId()),
                        "[USER_ID]", userId));
			}
		}

        List reportCols = getAllColumns();

        boolean isGroupStmt = false;
        for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
            DataColumnType dc = (DataColumnType) iter.next();
            if (dc.isGroupBreak()) {
                isGroupStmt = true;
                break;
			} 
		}


        for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
            DataColumnType dc = (DataColumnType) iter.next();
            String colName = getColumnSelectStr(dc, paramValues);

            if (selectCl.length() > 0)
                selectCl.append(", ");
            selectCl.append(getSelectExpr(dc, colName));
            selectCl.append(" ");
            selectCl.append(dc.getColId());
            if (nvl(dc.getDrillDownURL()).length() > 0)
                if (isViewAction(dc.getDrillDownURL()))
                    addExtraIdSelect(selectExtraIdCl, nvl(dc.getDrillDownParams()), true);
                else
                    addExtraDateSelect(selectExtraDateCl, nvl(dc.getDrillDownParams()),
                            paramValues, true);
            if (dc.isGroupBreak()) {
                if (groupByCl.length() > 0)
                    groupByCl.append(", ");
                groupByCl.append(colName);
			} 
            boolean isHavingCl = isGroupStmt && (!dc.isGroupBreak());
            StringBuffer filterCl = isHavingCl ? havingCl : whereCl;

            if (dc.getColFilterList() != null) {
                int fNo = 0;
                List fList = dc.getColFilterList().getColFilter();
                for (Iterator iterF = fList.iterator(); iterF.hasNext(); fNo++) {
                    ColFilterType cf = (ColFilterType) iterF.next();

                    StringBuffer curFilter = new StringBuffer();
                    if (filterCl.length() > 0)
                        curFilter.append(" " + cf.getJoinCondition() + " ");
                    if ((isHavingCl ? havingClCarryoverBrackets : whereClCarryoverBrackets) > 0)
                        for (int b = 0; b < (isHavingCl ? havingClCarryoverBrackets
                                : whereClCarryoverBrackets); b++)
                            filterCl.append('(');
                    curFilter.append(nvl(cf.getOpenBrackets()));
                    curFilter.append(colName + " ");
                    curFilter.append(cf.getExpression() + " ");

                    boolean applyFilter = true;
                    if ((nvl(cf.getArgValue()).length() > 0)
                            || (nvl(cf.getArgType()).equals(AppConstants.AT_FORM)))
                        if (nvl(cf.getArgType()).equals(AppConstants.AT_FORMULA))
                            curFilter.append(cf.getArgValue());
                        else if (nvl(cf.getArgType()).equals(AppConstants.AT_VALUE))
                            curFilter.append(formatValue(cf.getArgValue(), dc, false));
                        else if (nvl(cf.getArgType()).equals(AppConstants.AT_LIST))
                            curFilter.append(formatListValue(cf.getArgValue(), dc, false,
                                    false));
                        else if (nvl(cf.getArgType()).equals(AppConstants.AT_COLUMN))
                            curFilter.append(getColumnNameById(cf.getArgValue()));
                        else if (nvl(cf.getArgType()).equals(AppConstants.AT_FORM)) {
                            String fieldName = getFormFieldName(cf);
                            String fieldValue = Utils.oracleSafe(paramValues
                                    .getParamValue(fieldName));
                            boolean isMultiValue = paramValues
                                    .isParameterMultiValue(fieldName);
                            boolean usePipeDelimiterOnly = false;

                            FormFieldType fft = getFormFieldByDisplayValue(cf.getArgValue());
                            if (fft == null)
                                fieldValue = nvl(fieldValue, Utils
                                        .oracleSafe(cf.getArgValue()));
                            else
                                usePipeDelimiterOnly = fft.getFieldType().equals(
                                        FormField.FFT_CHECK_BOX)
                                        || fft.getFieldType().equals(FormField.FFT_LIST_MULTI);
                            if (fft != null) {
                                String fieldId = fft.getFieldId();
                                if (fft.getValidationType().equals(FormField.VT_TIMESTAMP_HR)
                                        || fft.getValidationType().equals(FormField.VT_TIMESTAMP_MIN)
                                        || fft.getValidationType().equals(FormField.VT_TIMESTAMP_SEC)) {
                                    fieldValue = nvl(
                                            fieldValue + " " + addZero(Utils.oracleSafe(nvl(paramValues
                                                    .getParamValue(fieldId + "_Hr")))));
                                    if (fft.getValidationType().equals(FormField.VT_TIMESTAMP_MIN)
                                            || fft.getValidationType().equals(FormField.VT_TIMESTAMP_SEC)) {
                                        fieldValue = fieldValue + (nvl(paramValues
                                                .getParamValue(fieldId + "_Min")).length() > 0
                                                        ? ":" + addZero(Utils.oracleSafe(nvl(paramValues
                                                                .getParamValue(fieldId + "_Min"))))
                                                        : "");
                                    }
                                    if (fft.getValidationType().equals(FormField.VT_TIMESTAMP_SEC)) {
                                        fieldValue = fieldValue + (nvl(paramValues
                                                .getParamValue(fieldId + "_Sec")).length() > 0
                                                        ? ":" + addZero(Utils.oracleSafe(nvl(paramValues
                                                                .getParamValue(fieldId + "_Sec"))))
                                                        : "");
                                    }
                                }
                            }

                            // End
                            if (nvl(fieldValue).length() == 0) {
                                // Does not append filter with missing form
                                // field argument
                                applyFilter = false;
                            } else if (isMultiValue || "IN".equals(nvl(cf.getExpression()))
                                    || "NOT IN".equals(nvl(cf.getExpression()))) {
                                curFilter.append(formatListValue(fieldValue, dc, true,
                                        usePipeDelimiterOnly));
                            } else {
                                curFilter.append(formatValue(fieldValue, dc, true, getColumnTableById(dc.getColId()), fft));
                            }
                        } // else
                    curFilter.append(nvl(cf.getCloseBrackets()));

                    if (applyFilter) {
                        filterCl.append(curFilter.toString());

                        if (isHavingCl) {
                            havingClBracketCount += (nvl(cf.getOpenBrackets()).length() - nvl(
                                    cf.getCloseBrackets()).length());
                            havingClCarryoverBrackets = 0;
                        } else {
                            whereClBracketCount += (nvl(cf.getOpenBrackets()).length() - nvl(
                                    cf.getCloseBrackets()).length());
                            whereClCarryoverBrackets = 0;
                        }
                    } else if (nvl(cf.getOpenBrackets()).length() != nvl(cf.getCloseBrackets())
                            .length())
                        if (nvl(cf.getOpenBrackets()).length() > nvl(cf.getCloseBrackets())
                                .length()) {
                            if (isHavingCl)
                                havingClCarryoverBrackets += (nvl(cf.getOpenBrackets())
                                        .length() - nvl(cf.getCloseBrackets()).length());
                            else
                                whereClCarryoverBrackets += (nvl(cf.getOpenBrackets())
                                        .length() - nvl(cf.getCloseBrackets()).length());

                            if (isHavingCl)
                                havingClBracketCount += (nvl(cf.getOpenBrackets()).length() - nvl(
                                        cf.getCloseBrackets()).length());
                            else
                                whereClBracketCount += (nvl(cf.getOpenBrackets()).length() - nvl(
                                        cf.getCloseBrackets()).length());
                        } else {
						
                            if (filterCl.length() > 0) {
                                for (int b = 0; b < nvl(cf.getCloseBrackets()).length()
                                        - nvl(cf.getOpenBrackets()).length(); b++)
                                    filterCl.append(')');

                                if (isHavingCl)
                                    havingClBracketCount += (nvl(cf.getOpenBrackets())
                                            .length() - nvl(cf.getCloseBrackets()).length());
                                else
                                    whereClBracketCount += (nvl(cf.getOpenBrackets()).length() - nvl(
                                            cf.getCloseBrackets()).length());
							} 
						} 
				} 
			} 
		}

        DataColumnType overrideSortByCol = null;
        if (overrideSortByColId != null)
            overrideSortByCol = getColumnById(overrideSortByColId);

        if (overrideSortByCol != null) {
            orderByCl.append(getColumnSelectStr(overrideSortByCol, paramValues));
            orderByCl.append(" ");
            orderByCl.append(nvl(overrideSortByAscDesc, AppConstants.SO_ASC));
        } else if (getReportType().equals(AppConstants.RT_CROSSTAB)) {

        } else {
            Collections.sort(reportCols, new OrderBySeqComparator());
            for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
                DataColumnType dc = (DataColumnType) iter.next();

                if (dc.getOrderBySeq() > 0) {
                    if (orderByCl.length() > 0)
                        orderByCl.append(", ");
                    orderByCl.append(getColumnSelectStr(dc, paramValues));
                    orderByCl.append(" ");
                    orderByCl.append(dc.getOrderByAscDesc());
				} 
			} 
            Collections.sort(reportCols, new OrderSeqComparator());
		} 

        StringBuffer sql = new StringBuffer();
        sql.append(Globals.getGenerateSqlVisualSelect());
        sql.append((selectCl.length() == 0) ? Globals.getGenerateSqlVisualCount() : selectCl.toString());
        if (groupByCl.length() == 0)
            sql.append(selectExtraIdCl.toString());
        sql.append(selectExtraDateCl.toString());
        sql.append((fromCl.length() == 0) ? Globals.getGenerateSqlVisualDual() : "FROM " + fromCl.toString());
        if (whereCl.length() > 0) {
            if (whereClBracketCount > 0) {
                for (int b = 0; b < whereClBracketCount; b++)
                    whereCl.append(')');
            } else if (whereClBracketCount < 0) {
                for (int b = 0; b < Math.abs(whereClBracketCount); b++)
                    whereCl.insert(0, '(');
			}

            sql.append(" WHERE ");
            sql.append(whereCl.toString());
		}
        if (groupByCl.length() > 0) {
            sql.append(" GROUP BY ");
            sql.append(groupByCl.toString());

            if (havingCl.length() > 0) {
                if (havingClBracketCount > 0) {
                    for (int b = 0; b < havingClBracketCount; b++)
                        havingCl.append(')');
                } else if (havingClBracketCount < 0) {
                    for (int b = 0; b < Math.abs(havingClBracketCount); b++)
                        havingCl.insert(0, '(');
				}

                sql.append(" HAVING ");
                sql.append(havingCl.toString());
            }
        }
        if (orderByCl.length() > 0) {
            sql.append(" ORDER BY ");
            sql.append(orderByCl.toString());
        }
        return sql.toString();
	} 

    public String generateSQLCrossTabVisual(ReportParamValues paramValues, String overrideSortByColId,
            String overrideSortByAscDesc, String userId, HttpServletRequest request) throws RaptorException {
        StringBuffer selectCl = new StringBuffer();
        StringBuffer fromCl = new StringBuffer();
        StringBuffer whereCl = new StringBuffer();
        StringBuffer groupByCl = new StringBuffer();
        StringBuffer havingCl = new StringBuffer();
        StringBuffer orderByCl = new StringBuffer();
        StringBuffer selectExtraIdCl = new StringBuffer();
        StringBuffer selectExtraDateCl = new StringBuffer();

        int whereClBracketCount = 0;
        int havingClBracketCount = 0;
        int whereClCarryoverBrackets = 0;
        int havingClCarryoverBrackets = 0;

        List dsList = getDataSourceList().getDataSource();
        for (Iterator iter = dsList.iterator(); iter.hasNext();) {
            DataSourceType ds = (DataSourceType) iter.next();

            if (fromCl.length() > 0)
                fromCl.append(", ");
            fromCl.append(ds.getTableName());
            fromCl.append(" ");
            fromCl.append(ds.getTableId());

            if (nvl(ds.getRefTableId()).length() > 0) {
                if (whereCl.length() > 0)
                    whereCl.append(" AND ");
                whereCl.append(ds.getRefDefinition());
            } 
            TableSource tableSource = null;
            String dBInfo = this.cr.getDbInfo();
            Vector userRoles = AppUtils.getUserRoles(request);
            tableSource = DataCache.getTableSource(ds.getTableName(), dBInfo, userRoles, userId, request);
            if (userId != null && (!AppUtils.isSuperUser(request))
                    && (!AppUtils.isAdminUser(request)) && tableSource != null
                    && nvl(tableSource.getFilterSql()).length() > 0) {
                if (whereCl.length() > 0)
                    whereCl.append(" AND ");
                whereCl.append(Utils.replaceInString(Utils.replaceInString(tableSource
                        .getFilterSql(), "[" + ds.getTableName() + "]", ds.getTableId()),
                        "[USER_ID]", userId));
            }
        } 

        List reportCols = getAllColumns();

        boolean isGroupStmt = false;
        for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
            DataColumnType dc = (DataColumnType) iter.next();
            if (dc.isGroupBreak()) {
                isGroupStmt = true;
                break;
            } 
        } 

        for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
            DataColumnType dc = (DataColumnType) iter.next();
            String colName = getColumnSelectStr(dc, paramValues);

            
            if (dc.isVisible()) {
                if (selectCl.length() > 0)
                    selectCl.append(", ");
                selectCl.append(getSelectExpr(dc, colName));
                selectCl.append(" ");
                selectCl.append(dc.getColId());
             } 


            if (nvl(dc.getDrillDownURL()).length() > 0)
                if (isViewAction(dc.getDrillDownURL()))
                    addExtraIdSelect(selectExtraIdCl, nvl(dc.getDrillDownParams()), true);
                else
                    addExtraDateSelect(selectExtraDateCl, nvl(dc.getDrillDownParams()),
                            paramValues, true);

            if (dc.isGroupBreak()) {
                if (groupByCl.length() > 0)
                    groupByCl.append(", ");
                groupByCl.append(colName);
            } 
            boolean isHavingCl = isGroupStmt && dc.isVisible() && (!dc.isGroupBreak());
            StringBuffer filterCl =
                    isGroupStmt ? (dc.isVisible() ? (dc.isGroupBreak() ? whereCl : havingCl) : whereCl) : whereCl;
            if (dc.getColFilterList() != null) {
                int fNo = 0;
                List fList = dc.getColFilterList().getColFilter();
                for (Iterator iterF = fList.iterator(); iterF.hasNext(); fNo++) {
                    ColFilterType cf = (ColFilterType) iterF.next();

                    StringBuffer curFilter = new StringBuffer();
                    if (filterCl.length() > 0)
                        curFilter.append(" " + cf.getJoinCondition() + " ");
                    if ((isHavingCl ? havingClCarryoverBrackets : whereClCarryoverBrackets) > 0)
                        for (int b = 0; b < (isHavingCl ? havingClCarryoverBrackets
                                : whereClCarryoverBrackets); b++)
                            filterCl.append('(');
                    curFilter.append(nvl(cf.getOpenBrackets()));
                    curFilter.append(colName + " ");
                    curFilter.append(cf.getExpression() + " ");

                    boolean applyFilter = true;
                    if ((nvl(cf.getArgValue()).length() > 0)
                            || (nvl(cf.getArgType()).equals(AppConstants.AT_FORM)))
                        if (nvl(cf.getArgType()).equals(AppConstants.AT_FORMULA))
                            curFilter.append(cf.getArgValue());
                        else if (nvl(cf.getArgType()).equals(AppConstants.AT_VALUE))
                            curFilter.append(formatValue(cf.getArgValue(), dc, false));
                        else if (nvl(cf.getArgType()).equals(AppConstants.AT_LIST))
                            curFilter.append(formatListValue(cf.getArgValue(), dc, false,
                                    false));
                        else if (nvl(cf.getArgType()).equals(AppConstants.AT_COLUMN))
                            curFilter.append(getColumnNameById(cf.getArgValue()));
                        else if (nvl(cf.getArgType()).equals(AppConstants.AT_FORM)) {
                            String fieldName = getFormFieldName(cf);
                            String fieldValue = Utils.oracleSafe(paramValues
                                    .getParamValue(fieldName));
                            boolean isMultiValue = paramValues
                                    .isParameterMultiValue(fieldName);
                            boolean usePipeDelimiterOnly = false;

                            FormFieldType fft = getFormFieldByDisplayValue(cf.getArgValue());
                            if (fft == null)
                                fieldValue = nvl(fieldValue, Utils
                                        .oracleSafe(cf.getArgValue()));
                            else
                                usePipeDelimiterOnly = fft.getFieldType().equals(
                                        FormField.FFT_CHECK_BOX)
                                        || fft.getFieldType().equals(FormField.FFT_LIST_MULTI);

                            if (nvl(fieldValue).length() == 0)
                                applyFilter = false;
                            else if (isMultiValue || "IN".equals(nvl(cf.getExpression()))
                                    || "NOT IN".equals(nvl(cf.getExpression())))
                                curFilter.append(formatListValue(fieldValue, dc, true,
                                        usePipeDelimiterOnly));
                            else
                                curFilter.append(formatValue(fieldValue, dc, true));
                        } 
                    curFilter.append(nvl(cf.getCloseBrackets()));

                    if (applyFilter) {
                        filterCl.append(curFilter.toString());

                        if (isHavingCl) {
                            havingClBracketCount += (nvl(cf.getOpenBrackets()).length() - nvl(
                                    cf.getCloseBrackets()).length());
                            havingClCarryoverBrackets = 0;
                        } else {
                            whereClBracketCount += (nvl(cf.getOpenBrackets()).length() - nvl(
                                    cf.getCloseBrackets()).length());
                            whereClCarryoverBrackets = 0;
                        }
                    } else if (nvl(cf.getOpenBrackets()).length() != nvl(cf.getCloseBrackets())
                            .length())
                        if (nvl(cf.getOpenBrackets()).length() > nvl(cf.getCloseBrackets())
                                .length()) {
                            if (isHavingCl)
                                havingClCarryoverBrackets += (nvl(cf.getOpenBrackets())
                                        .length() - nvl(cf.getCloseBrackets()).length());
                            else
                                whereClCarryoverBrackets += (nvl(cf.getOpenBrackets())
                                        .length() - nvl(cf.getCloseBrackets()).length());

                            if (isHavingCl)
                                havingClBracketCount += (nvl(cf.getOpenBrackets()).length() - nvl(
                                        cf.getCloseBrackets()).length());
                            else
                                whereClBracketCount += (nvl(cf.getOpenBrackets()).length() - nvl(
                                        cf.getCloseBrackets()).length());
                        } else {
                            if (filterCl.length() > 0) {
                                for (int b = 0; b < nvl(cf.getCloseBrackets()).length()
                                        - nvl(cf.getOpenBrackets()).length(); b++)
                                    filterCl.append(')');

                                if (isHavingCl)
                                    havingClBracketCount += (nvl(cf.getOpenBrackets())
                                            .length() - nvl(cf.getCloseBrackets()).length());
                                else
                                    whereClBracketCount += (nvl(cf.getOpenBrackets()).length() - nvl(
                                            cf.getCloseBrackets()).length());
                            } 
                        } 
                }
            } 
        } 

        DataColumnType overrideSortByCol = null;
        if (overrideSortByColId != null)
            overrideSortByCol = getColumnById(overrideSortByColId);

        if (overrideSortByCol != null) {
            orderByCl.append(getColumnSelectStr(overrideSortByCol, paramValues));
            orderByCl.append(" ");
            orderByCl.append(nvl(overrideSortByAscDesc, AppConstants.SO_ASC));
        } else if (getReportType().equals(AppConstants.RT_CROSSTAB)) {
        } else {
            Collections.sort(reportCols, new OrderBySeqComparator());
            for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
                DataColumnType dc = (DataColumnType) iter.next();

                if (dc.getOrderBySeq() > 0) {
                    if (orderByCl.length() > 0)
                        orderByCl.append(", ");
                    orderByCl.append(getColumnSelectStr(dc, paramValues));
                    orderByCl.append(" ");
                    orderByCl.append(dc.getOrderByAscDesc());
                } 
            } 
            Collections.sort(reportCols, new OrderSeqComparator());
        } 


        StringBuffer sql = new StringBuffer();
        sql.append(Globals.getGenerateSqlVisualSelect());
        sql.append((selectCl.length() == 0) ? Globals.getGenerateSqlVisualCount() : selectCl.toString());
        if (groupByCl.length() == 0)
            sql.append(selectExtraIdCl.toString());
        sql.append(selectExtraDateCl.toString());
        sql.append((fromCl.length() == 0) ? Globals.getGenerateSqlVisualDual() : "FROM " + fromCl.toString());
        if (whereCl.length() > 0) {
            if (whereClBracketCount > 0) {
                for (int b = 0; b < whereClBracketCount; b++)
                    whereCl.append(')');
            } else if (whereClBracketCount < 0) {
                for (int b = 0; b < Math.abs(whereClBracketCount); b++)
                    whereCl.insert(0, '(');
            } 

            sql.append(" WHERE ");
            sql.append(whereCl.toString());
        } 
        if (groupByCl.length() > 0) {
            sql.append(" GROUP BY ");
            sql.append(groupByCl.toString());

            if (havingCl.length() > 0) {
                if (havingClBracketCount > 0) {
                    for (int b = 0; b < havingClBracketCount; b++)
                        havingCl.append(')');
                } else if (havingClBracketCount < 0) {
                    for (int b = 0; b < Math.abs(havingClBracketCount); b++)
                        havingCl.insert(0, '(');
                } 
                sql.append(" HAVING ");
                sql.append(havingCl.toString());
            }
        }
        if (orderByCl.length() > 0) {
            sql.append(" ORDER BY ");
            sql.append(orderByCl.toString());
        }

        logger.debug(EELFLoggerDelegate.debugLogger, "Created SQL statement: {}", sql);

        return sql.toString();
    } 

    public String generatePagedSQL(int pageNo, String userId, HttpServletRequest request,
            boolean getColumnNamesFromReportSQL, ReportParamValues paramValues) throws RaptorException {
        int counter = 0;
        if (!Globals.isMySQL())
            counter = 1;
        return generateSubsetSQL(pageNo * getPageSize() + counter, ((pageNo + 1) * getPageSize())
                + ((pageNo == 0) ? 1 : 0), userId, request, getColumnNamesFromReportSQL, paramValues);
	} 

    public String generateSubsetSQL(int startRow, int endRow, String userId, HttpServletRequest request,
            boolean getColumnNamesFromReportSQL, ReportParamValues paramValues) throws RaptorException {
        String dbInfo = getDBInfo();
        String dbType = "";
		String partSql = "";
		String reportSQL = getWholeSQL();
		if (!CachingUtils.isReportSqlExists(request.getSession().getId()+reportSQL)) {
        if (!isNull(dbInfo) && (!dbInfo.equals(AppConstants.DB_LOCAL))) {
            try {
                dbType = remDbInfo.getDBType(dbInfo);
            } catch (Exception ex) {
                throw new RaptorException(ex);
            }
        }
        List reportCols = getAllColumns();
        String wholeSQL_OrderBy = getWholeSQL();
        reportSQL = reportSQL.replace(";", "");
        setWholeSQL(reportSQL);
        if (nvl(reportSQL).length() > 0)
            reportSQL = generateSQL(userId, request);
        if (nvl(reportSQL).toUpperCase().indexOf("ORDER BY ") < 0) {
            StringBuffer sortBy = null;

            if (nvl(reportSQL).toUpperCase().indexOf("GROUP BY ") < 0)
                if (getDataSourceList().getDataSource().size() > 0) {
						DataSourceType dst = (DataSourceType) getDataSourceList().getDataSource().get(0);
                    String tId = dst.getTableId();
                    String tPK = dst.getTablePK();
                    if (nvl(tPK).length() > 0) {
                        sortBy = new StringBuffer();
                        StringTokenizer st = new StringTokenizer(tPK, ", ");
                        while (st.hasMoreTokens()) {
                            if (sortBy.length() > 0)
                                sortBy.append(",");
                            sortBy.append(tId);
                            sortBy.append(".");
                            sortBy.append(st.nextToken());
                    }
						}
					} 
            if (nvl(reportSQL).trim().toUpperCase().startsWith("SELECT")) {

            }
        }
        StringBuffer colNames = new StringBuffer();
        StringBuffer colExtraIdNames = new StringBuffer();
        StringBuffer colExtraDateNames = new StringBuffer();

        if (getColumnNamesFromReportSQL) {
				String getColumnDef = "SELECT * FROM ( "+reportSQL+ ") derivedtable WHERE 1 > 2 ";
				DataSet ds = ConnectionUtils.getDataSet(getColumnDef, dbInfo);
            List reportCols1 = getAllColumns();
            reportCols = new Vector();
            outer: for (Iterator iter = reportCols1.iterator(); iter.hasNext();) {
                DataColumnType dct = (DataColumnType) iter.next();
                for (int k = 0; k < ds.getColumnCount(); k++) {
                    if (dct.getColId().toUpperCase().trim().equals(ds.getColumnName(k).trim())) {
                        reportCols.add(dct);
                        continue outer;
                    }
                }
            }

            if (getFormFieldList() != null) {
                String paramValue = "";
                for (Iterator iter = getFormFieldList().getFormField().iterator(); iter.hasNext();) {
                    FormFieldType fft = (FormFieldType) iter.next();
                    if (fft.isGroupFormField() != null && fft.isGroupFormField().booleanValue()) {
                        paramValue = Utils.oracleSafe(nvl(paramValues
                                .getParamValue(fft.getFieldId())));
                        outer: for (Iterator iter1 = reportCols1.iterator(); iter1.hasNext();) {
                            DataColumnType dct = (DataColumnType) iter1.next();
                            if (("[" + fft.getFieldName() + "]").equals(dct.getColName().trim())) {
                                dct.setDisplayName(paramValue);
                                continue outer;
                            }
                        }

                    }
                }
            }

        }

        for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
            DataColumnType dc = (DataColumnType) iter.next();
            if (colNames.length() > 0)
                colNames.append(", ");
            colNames.append(dc.getColId());
            if (nvl(dc.getDrillDownURL()).length() > 0)
                if (isViewAction(dc.getDrillDownURL()))
                    addExtraIdSelect(colExtraIdNames, nvl(dc.getDrillDownParams()), false);
                else
						addExtraDateSelect(colExtraDateNames, nvl(dc.getDrillDownParams()), null, false);
			}

        if (reportSQL.toUpperCase().indexOf("GROUP BY ") < 0)
            colNames.append(colExtraIdNames.toString());

        if ("DAYTONA".equals(dbType) && reportSQL.trim().toUpperCase().startsWith("SELECT")) {
            if (endRow == -1)
					endRow = (getMaxRowsInExcelDownload() > 0) ? getMaxRowsInExcelDownload()
							: Globals.getDownloadLimit();
            reportSQL = reportSQL + " LIMIT TO " + (startRow == 0 ? startRow + 1 : startRow) + "->" + endRow;
            return reportSQL;
        } else if ("DAYTONA".equals(dbType)) {
            return reportSQL;
        }


        String rSQL = Globals.getGenerateSubsetSql();
        rSQL = rSQL.replace("[colNames.toString()]", colNames.toString());
        rSQL = rSQL.replace("[reportSQL]", reportSQL);

        reportSQL = rSQL;

        reportSQLOnlyFirstPart = Globals.getReportSqlOnlyFirstPart();
        reportSQLOnlyFirstPart = reportSQLOnlyFirstPart.replace("[colNames.toString()]", colNames.toString());

        reportSQLWithRowNum = reportSQL;

        String parta = Globals.getReportSqlOnlySecondPartA();
        String partb = Globals.getReportSqlOnlySecondPartB();

        if (!AppUtils.isNotEmpty(getDBType())) {
            setDBType(Globals.getDBType());
        }

        int closeBracketPos = 0;
        if (wholeSQL_OrderBy.lastIndexOf(")") != -1)
            closeBracketPos = wholeSQL_OrderBy.lastIndexOf(")");
        int idxOrderBy = (closeBracketPos > 0) ? wholeSQL_OrderBy.toUpperCase().indexOf("ORDER BY", closeBracketPos)
                : wholeSQL_OrderBy.toUpperCase().lastIndexOf("ORDER BY");
        String orderbyclause = "";
        if (idxOrderBy < 0) {
            orderbyclause = " ORDER BY 1 ";
            partSql += " " + orderbyclause + " ";
        } else {
            orderbyclause = wholeSQL_OrderBy.substring(idxOrderBy);
            partSql += " " + orderbyclause + " ";
        }

			CachingUtils.putPageSql(request.getSession().getId()+getWholeSQL(), partSql);
			CachingUtils.putReportSql(request.getSession().getId()+getWholeSQL(), reportSQL);
		}else {
			if (!AppUtils.isNotEmpty(getDBType())) {
				setDBType(Globals.getDBType());
			}
		}
		if(startRow >= 0 && CachingUtils.isReportSqlExists(request.getSession().getId()+getWholeSQL()) ) {
			partSql = CachingUtils.getPageSql(request.getSession().getId()+getWholeSQL());
			reportSQL = CachingUtils.getReportSql(request.getSession().getId()+getWholeSQL());
			}
		
        if (getDBType().equals(AppConstants.MYSQL)) {
            partSql = partSql + " LIMIT " + String.valueOf(startRow) + " , " + String.valueOf(endRow);
        } else if (getDBType().equals(AppConstants.ORACLE)) {
            partSql = "where rnum >= " + String.valueOf(startRow) + " and rnum <= "
                    + ( Integer.parseInt(String.valueOf(endRow)));
        } else if (getDBType().equals(AppConstants.POSTGRESQL)) {
            partSql = partSql + " LIMIT " + String.valueOf(endRow) + " , " + String.valueOf(startRow);
        }

         
        reportSQL += partSql;

        return reportSQL;

	} 

    public String generateChartSQL(ReportParamValues paramValues, String userId, HttpServletRequest request)
            throws RaptorException {
        List reportCols = getAllColumns();
        List chartValueCols = getChartValueColumnsList(AppConstants.CHART_ALL_COLUMNS, null); 
        String reportSQL = generateSQL(userId, request);
        logger.debug(EELFLoggerDelegate.debugLogger, ("SQL " + reportSQL));
        String legendCol = "1 a";
        StringBuffer groupCol = new StringBuffer();
        StringBuffer seriesCol = new StringBuffer();
        StringBuffer valueCols = new StringBuffer();

        for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
            DataColumnType dc = (DataColumnType) iter.next();
            String colName = getColumnSelectStr(dc, paramValues);
            if (nvl(dc.getColOnChart()).equals(AppConstants.GC_LEGEND))
                legendCol = getSelectExpr(dc, colName) + " " + dc.getColId();
            if ((!nvl(dc.getColOnChart()).equals(AppConstants.GC_LEGEND))
                    && (dc.getChartSeq() == null || dc.getChartSeq() <= 0) && dc.isGroupBreak()) {
                groupCol.append(", ");
                groupCol.append(colName + " " + dc.getColId());
            }
		} 
        for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
            DataColumnType dc = (DataColumnType) iter.next();
            if (dc.isChartSeries() != null && dc.isChartSeries().booleanValue()) {
                seriesCol.append(", " + getSelectExpr(dc, getColumnSelectStr(dc, paramValues)) + " " + dc.getColId());
            }
        }


        for (Iterator iter = chartValueCols.iterator(); iter.hasNext();) {
            DataColumnType dc = (DataColumnType) iter.next();
            String colName = getColumnSelectStr(dc, paramValues);
            seriesCol.append("," + formatChartColumn(colName) + " " + dc.getColId());
		} 

        for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
            DataColumnType dc = (DataColumnType) iter.next();
            String colName = getColumnSelectStr(dc, paramValues);
            if (colName.equals(AppConstants.RI_CHART_TOTAL_COL))
                seriesCol.append(", " + AppConstants.RI_CHART_TOTAL_COL + " " + AppConstants.RI_CHART_TOTAL_COL);
            if (colName.equals(AppConstants.RI_CHART_COLOR))
                seriesCol.append(", " + AppConstants.RI_CHART_COLOR + " " + AppConstants.RI_CHART_COLOR);
            if (colName.equals(AppConstants.RI_CHART_MARKER_START))
                seriesCol.append(", " + AppConstants.RI_CHART_MARKER_START + " " + AppConstants.RI_CHART_MARKER_START);
            if (colName.equals(AppConstants.RI_CHART_MARKER_END))
                seriesCol.append(", " + AppConstants.RI_CHART_MARKER_END + " " + AppConstants.RI_CHART_MARKER_END);
            if (colName.equals(AppConstants.RI_CHART_MARKER_TEXT_LEFT))
                seriesCol.append(
                        ", " + AppConstants.RI_CHART_MARKER_TEXT_LEFT + " " + AppConstants.RI_CHART_MARKER_TEXT_LEFT);
            if (colName.equals(AppConstants.RI_CHART_MARKER_TEXT_RIGHT))
                seriesCol.append(
                        ", " + AppConstants.RI_CHART_MARKER_TEXT_RIGHT + " " + AppConstants.RI_CHART_MARKER_TEXT_RIGHT);
            if (colName.equals(AppConstants.RI_ANOMALY_TEXT))
                seriesCol.append(", " + AppConstants.RI_ANOMALY_TEXT + " " + AppConstants.RI_ANOMALY_TEXT);
        }


        String final_sql = "";
        reportSQL = Utils.replaceInString(reportSQL, " from ", " FROM ");
        reportSQL = Utils.replaceInString(reportSQL, " select ", " SELECT ");
        reportSQL = Utils.replaceInString(reportSQL, " union ", " UNION ");
        int pos = 0;
        int pos_first_select = 0;
        int pos_dup_select = 0;
        int pos_prev_select = 0;
        int pos_last_select = 0;
        if (reportSQL.indexOf("FROM", pos) != -1) {
            pos = reportSQL.indexOf("FROM", pos);
            pos_dup_select = reportSQL.lastIndexOf("SELECT", pos);
            pos_first_select = reportSQL.indexOf("SELECT");
            logger.debug(EELFLoggerDelegate.debugLogger, ("pos_select " + pos_first_select + " " + pos_dup_select));
            if (pos_dup_select > pos_first_select) {
                logger.debug(EELFLoggerDelegate.debugLogger, ("********pos_dup_select ********" + pos_dup_select));
                pos_prev_select = pos_first_select;
                pos_last_select = pos_dup_select;
                while (pos_last_select > pos_prev_select) {
                    logger.debug(EELFLoggerDelegate.debugLogger,
                            ("pos_last , pos_prev " + pos_last_select + " " + pos_prev_select));
                    pos = reportSQL.indexOf("FROM", pos + 2);
                    pos_prev_select = pos_last_select;
                    pos_last_select = reportSQL.lastIndexOf("SELECT", pos);
                    logger.debug(EELFLoggerDelegate.debugLogger, ("in WHILE LOOP LAST " + pos_last_select));
                }
            }

        }
        final_sql += " " + reportSQL.substring(pos);
        logger.debug(EELFLoggerDelegate.debugLogger, ("Final SQL " + final_sql));
        String sql = "SELECT " + legendCol + ", " + legendCol + "_1" + seriesCol.toString()
                + nvl(valueCols.toString(), ", 1")
                + groupCol.toString()
                + final_sql;
        logger.debug(EELFLoggerDelegate.debugLogger, ("Final sql in generateChartSQL " + sql));

        return sql;
	} 

    private String formatChartColumn(String colName) {

        logger.debug(EELFLoggerDelegate.debugLogger, ("Format Chart Column Input colName" + colName));
        colName = colName.trim();
        colName = Utils.replaceInString(colName, "TO_CHAR", "to_char");
        colName = Utils.replaceInString(colName, "to_number", "TO_NUMBER");
        colName = colName.replaceAll(",[\\s]*\\(", ",(");
        StringBuffer colNameBuf = new StringBuffer(colName);
        int pos = 0;
		int	posFormatStart = 0;
		int	posFormatEnd = 0;
        String format = "";
        if (colNameBuf.indexOf("999") == -1 && colNameBuf.indexOf("990") == -1) {
            logger.debug(EELFLoggerDelegate.debugLogger, (" return colName " + colNameBuf.toString()));
            return colNameBuf.toString();
        }
        while (colNameBuf.indexOf("to_char") != -1) {
            if (colNameBuf.indexOf("999") != -1 || colNameBuf.indexOf("990") != -1) {
                pos = colNameBuf.indexOf("to_char");
                colNameBuf.insert(pos, " TO_NUMBER ( CR_RAPTOR.SAFE_TO_NUMBER (");
                pos = colNameBuf.indexOf("to_char");
                colNameBuf.replace(pos, pos + 7, "TO_CHAR");
                logger.debug(EELFLoggerDelegate.debugLogger, ("After adding to_number " + colNameBuf.toString()));
                posFormatStart = colNameBuf.indexOf(",'", pos) + 1;
                posFormatEnd = colNameBuf.indexOf(")", posFormatStart);
                logger.debug(EELFLoggerDelegate.debugLogger, (posFormatStart + " " + posFormatEnd + " " + pos));
                format = colNameBuf.substring(posFormatStart, posFormatEnd);
                colNameBuf.insert(posFormatEnd + 1, " ," + format + ") , " + format + ")");
                logger.debug(EELFLoggerDelegate.debugLogger, ("colNameBuf " + colNameBuf.toString()));
            }
        }
        logger.debug(EELFLoggerDelegate.debugLogger, (" return colName " + colNameBuf.toString()));
        return colNameBuf.toString();
    }

    public String generateTotalSQLLinear(ReportParamValues paramValues, String userId, HttpServletRequest request)
            throws RaptorException {
        List reportCols = getAllColumns();
        String reportSQL = generateSQL(userId, request);

        StringBuffer sbSelect = new StringBuffer();
        StringBuffer sbTotal = new StringBuffer();
        StringBuffer colNames = new StringBuffer();
        for (Iterator iter = reportCols.iterator(); iter.hasNext();) {

            DataColumnType dc = (DataColumnType) iter.next();
            if (colNames.length() > 0)
                colNames.append(", ");
            colNames.append(dc.getColId());
        }
        for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
            DataColumnType dct = (DataColumnType) iter.next();

            String colName = getColumnSelectStr(dct, paramValues);

            sbSelect.append((sbSelect.length() == 0) ? "SELECT " : ", ");

            sbSelect.append(colName);
            sbSelect.append(" ");
            sbSelect.append(dct.getColId());

            sbTotal.append((sbTotal.length() == 0) ? "SELECT " : ", ");
            if (nvl(dct.getDisplayTotal()).length() > 0) {
                String displayTotal = dct.getDisplayTotal();
                StringBuffer sb = new StringBuffer();
                for (int i = 0; i < displayTotal.length(); i++) {
                    char ch = displayTotal.charAt(i);
                    if (ch == '+' || ch == '-')
                        sb.append(dct.getColId() + ")");
                    sb.append(ch);
				} 
                sb.append(dct.getColId() + ")");
                sbTotal.append(getSelectExpr(dct, sb.toString()));
            } else
                sbTotal.append("NULL");
            sbTotal.append(" total_");
            sbTotal.append(dct.getColId());
		} 

        logger.debug(EELFLoggerDelegate.debugLogger, ("REPORTWRAPPER " + reportSQL));
        int pos = 0;
        int pos_first_select = 0;
        int pos_dup_select = 0;
        int pos_prev_select = 0;
        int pos_last_select = 0;
        reportSQL = replaceNewLine(reportSQL, " from ", " FROM ");
        reportSQL = replaceNewLine(reportSQL, "from ", " FROM ");
        reportSQL = replaceNewLine(reportSQL, "FROM ", " FROM ");

        reportSQL = " " + reportSQL;
        reportSQL = replaceNewLine(reportSQL, "select ", " SELECT ");
        reportSQL = replaceNewLine(reportSQL, "SELECT ", " SELECT ");
        if (reportSQL.indexOf("FROM", pos) != -1) {
            pos = reportSQL.indexOf("FROM", pos);
            pos_dup_select = reportSQL.lastIndexOf("SELECT", pos);
            pos_first_select = reportSQL.indexOf("SELECT");
            logger.debug(EELFLoggerDelegate.debugLogger, ("pos_select " + pos_first_select + " " + pos_dup_select));
            if (pos_dup_select > pos_first_select) {
                logger.debug(EELFLoggerDelegate.debugLogger, ("********pos_dup_select ********" + pos_dup_select));
                pos_prev_select = pos_first_select;
                pos_last_select = pos_dup_select;
                while (pos_last_select > pos_prev_select) {
                    logger.debug(EELFLoggerDelegate.debugLogger,
                            ("pos_last , pos_prev " + pos_last_select + " " + pos_prev_select));
                    pos = reportSQL.indexOf("FROM", pos + 2);
                    pos_prev_select = pos_last_select;
                    pos_last_select = reportSQL.lastIndexOf("SELECT", pos);
                    logger.debug(EELFLoggerDelegate.debugLogger, ("in WHILE LOOP LAST " + pos_last_select));
                }
            }

        }

        logger.debug(EELFLoggerDelegate.debugLogger, (" *************** " + pos + " " + reportSQL));
        sbSelect.append(" " + reportSQL.substring(pos));
        logger.debug(EELFLoggerDelegate.debugLogger, (" **************** " + sbSelect.toString()));
        sbTotal.append(" FROM (");
        sbTotal.append(sbSelect.toString());
        sbTotal.append(") totalSQL");

        String dbType = "";
        String dbInfo = getDBInfo();
        if (!isNull(dbInfo) && (!dbInfo.equals(AppConstants.DB_LOCAL))) {
            try {
                dbType = remDbInfo.getDBType(dbInfo);
            } catch (Exception ex) {
                throw new RaptorException(ex);
            }
        }
        if ("DAYTONA".equals(dbType)) {
            sbTotal.append("(" + colNames + ")");
        }
        String sql = sbTotal.toString();
        sql = Utils.replaceInString(sql, " from ", " FROM ");
        sql = Utils.replaceInString(sql, "select ", "SELECT ");
        logger.debug(EELFLoggerDelegate.debugLogger, ("Before SQL Corrector " + sql));
        String corrected_SQL = new SQLCorrector().fixSQL(new StringBuffer(sql));
        logger.debug(EELFLoggerDelegate.debugLogger, ("************"));
        logger.debug(EELFLoggerDelegate.debugLogger, ("Corrected SQL " + corrected_SQL));
        return corrected_SQL;
	} 

    public String generateTotalSQLCrossTab(String sql, String rowColPos,
            String userId, HttpServletRequest request, ReportParamValues paramValues) throws RaptorException {
        List reportCols = getAllColumns();
        String reportSQL = sql;

        StringBuffer sbSelect = new StringBuffer();
        StringBuffer sbGroup = new StringBuffer();
        StringBuffer sbTotal = new StringBuffer();
        StringBuffer colNames = new StringBuffer();
        for (Iterator iter = reportCols.iterator(); iter.hasNext();) {

            DataColumnType dc = (DataColumnType) iter.next();
            if (colNames.length() > 0)
                colNames.append(", ");
            colNames.append(dc.getColId());
        }
        for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
            DataColumnType dct = (DataColumnType) iter.next();

            if (!dct.isVisible())
                continue;

            String colName = getColumnSelectStr(dct, paramValues);
            String colExpr = getSelectExpr(dct, colName);

            sbSelect.append((sbSelect.length() == 0) ? "SELECT " : ", ");

            if (nvl(dct.getCrossTabValue()).equals(rowColPos)) {
                sbSelect.append(dct.getColId());
                sbGroup.append((sbGroup.length() == 0) ? " GROUP BY " : ", ");
                sbGroup.append(dct.getColId());

                sbTotal.append((sbTotal.length() == 0) ? "SELECT " : ", ");
                sbTotal.append(dct.getColId());
            } else if (nvl(dct.getCrossTabValue()).equals(AppConstants.CV_VALUE)) {
				
                sbSelect.append(dct.getColId());

                String displayTotal = getCrossTabDisplayTotal(rowColPos);
                if (displayTotal.length() > 0) {
					
                    StringBuffer sb = new StringBuffer();
                    for (int i = 0; i < displayTotal.length(); i++) {
                        char ch = displayTotal.charAt(i);
                        if (ch == '+' || ch == '-')
                            sb.append(dct.getColId() + ")");
                        sb.append(ch);
					} 
                    sb.append(dct.getColId() + ")");

                    displayTotal = sb.toString();
                } else
                    displayTotal = "COUNT(*)";

                sbTotal.append((sbTotal.length() == 0) ? "SELECT " : ", ");
                sbTotal.append(getSelectExpr(dct, displayTotal));
                sbTotal.append(" total_");
                sbTotal.append(dct.getColId());
            } else {
				
                sbSelect.append(dct.getColId());
			} 

            sbSelect.append(" ");
            sbSelect.append(dct.getColId());
		} 

        sbSelect.append(reportSQL.substring(reportSQL.toUpperCase().indexOf(" FROM ")));

        sbTotal.append(" FROM (");
        sbTotal.append(sbSelect.toString());
        sbTotal.append(") totalSQL");
        sbTotal.append(sbGroup.toString());
        String dbType = "";
        String dbInfo = getDBInfo();
        if (!isNull(dbInfo) && (!dbInfo.equals(AppConstants.DB_LOCAL))) {
            try {
                dbType = remDbInfo.getDBType(dbInfo);
            } catch (Exception ex) {
                throw new RaptorException(ex);
            }
        }
        if ("DAYTONA".equals(dbType)) {
            sbTotal.append("(" + colNames + ")");
        }

        sql = "";
        if (getReportDefType().equals(AppConstants.RD_SQL_BASED)) {
            sql = Utils.replaceInString(sbTotal.toString(), " from ", " FROM ");
            sql = Utils.replaceInString(sql, "select ", "SELECT ");
            return new SQLCorrector().fixSQL(new StringBuffer(sql));
        }

        return sbTotal.toString();

	} 

    public String generateTotalSQLCrossTab(ReportParamValues paramValues, String rowColPos,
            String userId, HttpServletRequest request) throws RaptorException {
        List reportCols = getAllColumns();
        String reportSQL = generateSQL(userId, request);

        StringBuffer sbSelect = new StringBuffer();
        StringBuffer sbGroup = new StringBuffer();
        StringBuffer sbTotal = new StringBuffer();
        StringBuffer colNames = new StringBuffer();
        for (Iterator iter = reportCols.iterator(); iter.hasNext();) {

            DataColumnType dc = (DataColumnType) iter.next();
            if (colNames.length() > 0)
                colNames.append(", ");
            colNames.append(dc.getColId());
        }
        for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
            DataColumnType dct = (DataColumnType) iter.next();

            if (!dct.isVisible())
                continue;

            String colName = getColumnSelectStr(dct, paramValues);
            String colExpr = getSelectExpr(dct, colName);

            sbSelect.append((sbSelect.length() == 0) ? "SELECT " : ", ");

            if (nvl(dct.getCrossTabValue()).equals(rowColPos)) {
                sbSelect.append(colExpr);

                sbGroup.append((sbGroup.length() == 0) ? " GROUP BY " : ", ");
                sbGroup.append(dct.getColId());

                sbTotal.append((sbTotal.length() == 0) ? "SELECT " : ", ");
                sbTotal.append(dct.getColId());
            } else if (nvl(dct.getCrossTabValue()).equals(AppConstants.CV_VALUE)) {
                sbSelect.append(colName);

                String displayTotal = getCrossTabDisplayTotal(rowColPos);
                if (displayTotal.length() > 0) {
                    StringBuffer sb = new StringBuffer();
                    for (int i = 0; i < displayTotal.length(); i++) {
                        char ch = displayTotal.charAt(i);
                        if (ch == '+' || ch == '-')
                            sb.append(dct.getColId() + ")");
                        sb.append(ch);
					} 
                    sb.append(dct.getColId() + ")");

                    displayTotal = sb.toString();
                } else
                    displayTotal = "COUNT(*)";

                sbTotal.append((sbTotal.length() == 0) ? "SELECT " : ", ");
                sbTotal.append(getSelectExpr(dct, displayTotal));
                sbTotal.append(" total_");
                sbTotal.append(dct.getColId());
            } else {
                sbSelect.append(colExpr);
			}

            sbSelect.append(" ");
            sbSelect.append(dct.getColId());
		}

        sbSelect.append(reportSQL.substring(reportSQL.toUpperCase().indexOf(" FROM ")));

        sbTotal.append(" FROM (");
        sbTotal.append(sbSelect.toString());
        sbTotal.append(") totalSQL");
        sbTotal.append(sbGroup.toString());
        String dbType = "";
        String dbInfo = getDBInfo();
        if (!isNull(dbInfo) && (!dbInfo.equals(AppConstants.DB_LOCAL))) {
            try {
                dbType = remDbInfo.getDBType(dbInfo);
            } catch (Exception ex) {
                throw new RaptorException(ex);
            }
        }
        if ("DAYTONA".equals(dbType)) {
            sbTotal.append("(" + colNames + ")");
        }

        String sql = "";
        if (getReportDefType().equals(AppConstants.RD_SQL_BASED)) {
            sql = Utils.replaceInString(sbTotal.toString(), " from ", " FROM ");
            sql = Utils.replaceInString(sql, "select ", "SELECT ");
            return new SQLCorrector().fixSQL(new StringBuffer(sql));
        }

        return sbTotal.toString();

	} 

    public String generateDistinctValuesSQL(ReportParamValues paramValues, DataColumnType dct,
            String userId, HttpServletRequest request) throws RaptorException {
        DataSourceType dst = getColumnTableById(dct.getColId());
        String colName = getColumnSelectStr(dct, paramValues);
        String colExpr = getSelectExpr(dct, colName);
        ReportRuntime rr = (ReportRuntime) request.getSession().getAttribute(AppConstants.SI_REPORT_RUNTIME);
        StringBuffer sb = new StringBuffer();
        sb.append("SELECT DISTINCT ");
        if (getReportDefType().equals(AppConstants.RD_SQL_BASED)) {
            sb.append(dct.getColId());
            sb.append(" FROM (");
            sb.append(rr.getWholeSQL());
            sb.append(") " + (Globals.isPostgreSQL() || Globals.isMySQL() ? " AS " : "") + " report_sql ORDER BY 1");
        } else {
            sb.append(colExpr);
            sb.append(" ");
            sb.append(dct.getColId());
            if (!colExpr.equals(colName)) {
                sb.append(", ");
                sb.append(colName);
			} 
            sb.append(" FROM ");
            sb.append(dst.getTableName());
            sb.append(" ");
            sb.append(dst.getTableId());
            sb.append(" ORDER BY ");
            sb.append(colName);
            if (dct.getColType().equals(AppConstants.CT_DATE))
                sb.append(" DESC");
		} 

        return sb.toString();
	} 

    public DataSourceType getTableWithoutColumns() {
        List dsList = getDataSourceList().getDataSource();
        for (Iterator iter = dsList.iterator(); iter.hasNext();) {
            DataSourceType ds = (DataSourceType) iter.next();

            if (ds.getDataColumnList().getDataColumn().isEmpty())
                return ds;
		} 

        return null;
	} 

    public CustomReportType cloneCustomReportClearTables() throws RaptorException {
        ReportWrapper nrw = new ReportWrapper(cloneCustomReport(), reportID, getOwnerID(),
                getCreateID(), getCreateDate(), getUpdateID(), getUpdateDate(), getMenuID(),
                isMenuApproved());

        DataSourceType ndst = null;
        while ((ndst = nrw.getTableWithoutColumns()) != null)
            nrw.deleteDataSourceType(ndst.getTableId());

        return nrw.getCustomReport();
	} 

    public String marshal() throws RaptorException {
        StringWriter sw = new StringWriter();
        ObjectFactory objFactory = new ObjectFactory();

        try {
            JAXBContext jc = JAXBContext.newInstance("org.onap.portalsdk.analytics.xmlobj");
            Marshaller m = jc.createMarshaller();
            m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
            m.marshal(
                    (getTableWithoutColumns() == null) ? objFactory.createCustomReport(cr)
                            : objFactory.createCustomReport(cloneCustomReportClearTables()),
                    new StreamResult(sw));
        } catch (JAXBException ex) {
            logger.error(EELFLoggerDelegate.debugLogger, "Exception occured in marshal ", ex);
            throw new RaptorException(ex.getMessage(), ex.getCause());
        }
        return sw.toString();
	}

    public static CustomReportType unmarshalCR(String reportXML) throws RaptorException {
        try {
            JAXBContext jc = JAXBContext.newInstance("org.onap.portalsdk.analytics.xmlobj");
            Unmarshaller u = jc.createUnmarshaller();
            javax.xml.bind.JAXBElement<CustomReportType> doc =
                    (javax.xml.bind.JAXBElement<CustomReportType>) u.unmarshal(new java.io.StringReader(
                            reportXML));
            return doc.getValue();
        } catch (JAXBException ex) {
            logger.error(EELFLoggerDelegate.debugLogger, "Exception occured in unmarshalCR ", ex);
            throw new RaptorException(ex.getMessage(), ex.getCause());
        }


	} 

    protected static CustomReportType createBlankCR() throws RaptorException {
        return createBlankCR("N/A");
	}
    protected static CustomReportType createBlankCR(String createID) throws RaptorException {
        ObjectFactory objFactory = new ObjectFactory();
        CustomReportType cr = objFactory.createCustomReportType();
        try {
            cr.setReportName("");
            cr.setReportDescr("");
            cr.setChartType("");
            cr.setPublic(false);
            cr.setCreateId(createID);
            cr.setCreateDate(DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar()));
            cr.setReportType("");
            cr.setPageSize(50);

            DataSourceList dataSourceList = objFactory.createDataSourceList();
            cr.setDataSourceList(dataSourceList);
        } catch (DatatypeConfigurationException ex) {
            logger.error(EELFLoggerDelegate.debugLogger, "Exception occured in createBlankCR ", ex);
            throw new RaptorException(ex.getMessage(), ex.getCause());
        }
        return cr;
	} 

    protected void replaceCustomReportWithClone() throws RaptorException {
        try {
            CustomReportType clone = cloneCustomReport();
            this.cr = clone;
        } catch (Exception e) {
            logger.debug(EELFLoggerDelegate.debugLogger,
                    ("[SYSTEM ERROR] ReportWrapper.replaceCustomReportWithClone generated exception for report ["
                            + reportID + "]. Exception: "),
                    e);
            throw new RaptorException(
                    "[SYSTEM ERROR] ReportWrapper.replaceCustomReportWithClone generated exception for report ["
                            + reportID + "]. Exception: " + e.getMessage(),
                    e.getCause());
        }
	}

    public FormatType cloneFormatType(ObjectFactory objFactory, FormatType ft)
            throws JAXBException {
        FormatType nft = objFactory.createFormatType();

        nft.setLessThanValue(ft.getLessThanValue());
        nft.setExpression(ft.getExpression());
        nft.setBold(ft.isBold());
        nft.setItalic(ft.isItalic());
        nft.setUnderline(ft.isUnderline());
        if (nvl(ft.getBgColor()).length() > 0)
            nft.setBgColor(ft.getBgColor());
        if (nvl(ft.getFontColor()).length() > 0)
            nft.setFontColor(ft.getFontColor());
        if (nvl(ft.getFontFace()).length() > 0)
            nft.setFontFace(ft.getFontFace());
        if (nvl(ft.getFontSize()).length() > 0)
            nft.setFontSize(ft.getFontSize());
        if (nvl(ft.getAlignment()).length() > 0)
            nft.setAlignment(ft.getAlignment());
        if (nvl(ft.getComment()).length() > 0)
            nft.setComment(ft.getComment());

        nft.setFormatId(ft.getFormatId());

        return nft;
	} 

    public SemaphoreType cloneSemaphoreType(ObjectFactory objFactory, SemaphoreType st)
            throws JAXBException {
        SemaphoreType nst = objFactory.createSemaphoreType();

        nst.setSemaphoreName(st.getSemaphoreName());
        nst.setSemaphoreType(st.getSemaphoreType());
        nst.setSemaphoreId(st.getSemaphoreId());
        if (nvl(st.getComment()).length() > 0)
            nst.setComment(st.getComment());

        if (st.getFormatList() != null) {
            FormatList formatList = objFactory.createFormatList();
            nst.setFormatList(formatList);

            for (Iterator iter = st.getFormatList().getFormat().iterator(); iter.hasNext();)
                formatList.getFormat().add(
                        cloneFormatType(objFactory, (FormatType) iter.next()));
        } // if

        return nst;
	}

    public Reports cloneDashboardType(ObjectFactory objFactory, Reports rpt)
            throws JAXBException {
        Reports nrpt = objFactory.createReports();

        nrpt.setReportId(rpt.getReportId());
        nrpt.setBgcolor(rpt.getBgcolor());
        return nrpt;
		} 

    public Marker cloneMarkerType(ObjectFactory objFactory, Marker marker)
            throws JAXBException {
        Marker nMarker = objFactory.createMarker();
        nMarker.setAddressColumn(marker.getAddressColumn());
        nMarker.setDataColumn(marker.getDataColumn());
        nMarker.setDataHeader(marker.getDataHeader());
        nMarker.setMarkerColor(marker.getMarkerColor());
        return nMarker;
		}

    public ChartDrillFormfield cloneChartDrillFormfield(ObjectFactory objFactory,
            ChartDrillFormfield chartDrillFormfield)
            throws JAXBException {
        ChartDrillFormfield nChartDrillFormfield = objFactory.createChartDrillFormfield();
        nChartDrillFormfield.setFormfield(chartDrillFormfield.getFormfield());
        return nChartDrillFormfield;
		} 

    public boolean isChartDrillDownContainsName(String name) {
        for (Iterator iter = getChartDrillOptions().getTargetFormfield().iterator(); iter
                .hasNext();) {
            org.onap.portalsdk.analytics.xmlobj.ChartDrillFormfield cdf =
                    (org.onap.portalsdk.analytics.xmlobj.ChartDrillFormfield) iter.next();
            if (cdf.getFormfield().equals(name)) {
                return true;
            }
        }
        return false;
    }

    public FormFieldType cloneFormFieldType(ObjectFactory objFactory, FormFieldType fft)
            throws JAXBException {
        FormFieldType nfft = objFactory.createFormFieldType();

        nfft.setColId(fft.getColId());
        nfft.setFieldName(fft.getFieldName());
        nfft.setFieldType(fft.getFieldType());
        if (nvl(fft.getVisible()).length() > 0)
            nfft.setVisible(fft.getVisible());
		if (nvl(fft.getValidationType()).length() > 0 || (fft.getValidationType() != null && fft.getValidationType().isEmpty()))
            nfft.setValidationType(fft.getValidationType());
        if (nvl(fft.getMandatory()).length() > 0)
            nfft.setMandatory(fft.getMandatory());
		if (nvl(fft.getDefaultValue()).length() > 0 || (fft.getDefaultValue() != null && fft.getDefaultValue().isEmpty()))
            nfft.setDefaultValue(fft.getDefaultValue());
        nfft.setOrderBySeq(fft.getOrderBySeq());
		if (nvl(fft.getFieldSQL()).length() > 0  || (fft.getFieldSQL()  != null && fft.getFieldSQL().isEmpty()))
            nfft.setFieldSQL(fft.getFieldSQL());
		if (nvl(fft.getFieldDefaultSQL()).length() > 0 || (fft.getFieldDefaultSQL()  != null && fft.getFieldDefaultSQL().isEmpty()))
            nfft.setFieldDefaultSQL(fft.getFieldDefaultSQL());
        if (fft.getRangeStartDate() != null)
            nfft.setRangeStartDate(fft.getRangeStartDate());
        if (fft.getRangeEndDate() != null)
            nfft.setRangeEndDate(fft.getRangeEndDate());
        if (fft.getRangeStartDateSQL() != null)
            nfft.setRangeStartDateSQL(fft.getRangeStartDateSQL());
        if (fft.getRangeEndDateSQL() != null)
            nfft.setRangeEndDateSQL(fft.getRangeEndDateSQL());

        if (nvl(fft.getComment()).length() > 0)
            nfft.setComment(fft.getComment());

        if (fft.getPredefinedValueList() != null) {
            PredefinedValueList predefinedValueList = objFactory.createPredefinedValueList();
            nfft.setPredefinedValueList(predefinedValueList);

            for (Iterator iter = fft.getPredefinedValueList().getPredefinedValue().iterator(); iter
                    .hasNext();)
                predefinedValueList.getPredefinedValue().add(new String((String) iter.next()));
		}
        if (nvl(fft.getDependsOn()).length() > 0)
            nfft.setDependsOn(fft.getDependsOn());

        nfft.setGroupFormField(
                (fft.isGroupFormField() != null && fft.isGroupFormField().booleanValue()) ? true : false);
        if (nvl(fft.getMultiSelectListSize()).length() > 0)
            nfft.setMultiSelectListSize(fft.getMultiSelectListSize());

        nfft.setFieldId(fft.getFieldId());
        return nfft;
	} 

    public JavascriptItemType cloneJavascriptType(ObjectFactory objFactory, JavascriptItemType jit)
            throws JAXBException {
        JavascriptItemType njit = objFactory.createJavascriptItemType();

        njit.setId(jit.getId());
        njit.setFieldId(jit.getFieldId());
        njit.setCallText(jit.getCallText());
        return njit;
	} 

    public ColFilterType cloneColFilterType(ObjectFactory objFactory, ColFilterType cft)
            throws JAXBException {
        ColFilterType ncft = objFactory.createColFilterType();

        ncft.setColId(cft.getColId());
        ncft.setFilterSeq(cft.getFilterSeq());
        ncft.setJoinCondition(cft.getJoinCondition());
        if (nvl(cft.getOpenBrackets()).length() > 0)
            ncft.setOpenBrackets(cft.getOpenBrackets());
        ncft.setExpression(cft.getExpression());
        if (nvl(cft.getArgType()).length() > 0)
            ncft.setArgType(cft.getArgType());
        if (nvl(cft.getArgValue()).length() > 0)
            ncft.setArgValue(cft.getArgValue());
        if (nvl(cft.getCloseBrackets()).length() > 0)
            ncft.setCloseBrackets(cft.getCloseBrackets());
        if (nvl(cft.getComment()).length() > 0)
            ncft.setComment(cft.getComment());

        return ncft;
	} 

    public DataColumnType cloneDataColumnType(ObjectFactory objFactory, DataColumnType dct)
            throws JAXBException {
        DataColumnType ndct = objFactory.createDataColumnType();

        ndct.setTableId(dct.getTableId());
        ndct.setDbColName(dct.getDbColName());
        if (nvl(dct.getCrossTabValue()).length() > 0)
            ndct.setCrossTabValue(dct.getCrossTabValue());
        ndct.setColName(dct.getColName());
        ndct.setDisplayName(dct.getDisplayName());
        if (dct.getDisplayWidth() > 0)
            ndct.setDisplayWidth(dct.getDisplayWidth());
        if (nvl(dct.getDisplayWidthInPxls()).length() > 0)
            ndct.setDisplayWidthInPxls(dct.getDisplayWidthInPxls());
        if (nvl(dct.getDisplayAlignment()).length() > 0)
            ndct.setDisplayAlignment(dct.getDisplayAlignment());
        if (nvl(dct.getDisplayHeaderAlignment()).length() > 0)
            ndct.setDisplayHeaderAlignment(dct.getDisplayHeaderAlignment());
        ndct.setOrderSeq(dct.getOrderSeq());
        ndct.setVisible(dct.isVisible());
        ndct.setCalculated(dct.isCalculated());
        ndct.setColType(dct.getColType());
        if (dct.getColType().equals(AppConstants.CT_HYPERLINK)) {
            ndct.setHyperlinkURL(dct.getHyperlinkURL());
            ndct.setHyperlinkType(dct.getHyperlinkType());
            if ("IMAGE".equals(dct.getHyperlinkType())) {
                ndct.setActionImg(dct.getActionImg());
            }
        }

        if (dct.getIndentation() != null) {
            ndct.setIndentation(dct.getIndentation());
        }

        if (nvl(dct.getColFormat()).length() > 0)
            ndct.setColFormat(dct.getColFormat());
        ndct.setGroupBreak(dct.isGroupBreak());
        ndct.setNowrap(dct.getNowrap());
        if (nvl(dct.getYAxis()).length() > 0)
            ndct.setYAxis(dct.getYAxis());
        if (dct.getOrderBySeq() != null && dct.getOrderBySeq() > 0)
            ndct.setOrderBySeq(dct.getOrderBySeq());
        if (nvl(dct.getOrderByAscDesc()).length() > 0)
            ndct.setOrderByAscDesc(dct.getOrderByAscDesc());
        if (nvl(dct.getDisplayTotal()).length() > 0)
            ndct.setDisplayTotal(dct.getDisplayTotal());
        if (nvl(dct.getColOnChart()).length() > 0)
            ndct.setColOnChart(dct.getColOnChart());
        if (dct.getChartSeq() != null)
            ndct.setChartSeq(dct.getChartSeq());
        if (nvl(dct.getChartColor()).length() > 0)
            ndct.setChartColor(dct.getChartColor());
        if (nvl(dct.getChartLineType()).length() > 0)
            ndct.setChartLineType(dct.getChartLineType());
        ndct.setChartSeries((dct.isChartSeries() != null && dct.isChartSeries().booleanValue()) ? true : false);
        ndct.setIsRangeAxisFilled(
                (dct.isIsRangeAxisFilled() != null && dct.isIsRangeAxisFilled().booleanValue()) ? true : false);

        if (dct.isCreateInNewChart() != null)
            ndct.setCreateInNewChart(dct.isCreateInNewChart());
        if (nvl(dct.getDrillDownType()).length() > 0)
            ndct.setDrillDownType(dct.getDrillDownType());
        ndct.setDrillinPoPUp(dct.isDrillinPoPUp() != null ? dct.isDrillinPoPUp() : false);
        if (nvl(dct.getDrillDownURL()).length() > 0)
            ndct.setDrillDownURL(dct.getDrillDownURL());
        if (nvl(dct.getDrillDownParams()).length() > 0)
            ndct.setDrillDownParams(dct.getDrillDownParams());
        if (nvl(dct.getComment()).length() > 0)
            ndct.setComment(dct.getComment());
        if (nvl(dct.getDependsOnFormField()).length() > 0)
            ndct.setDependsOnFormField(dct.getDependsOnFormField());
        if (dct.getColFilterList() != null) {
            ColFilterList colFilterList = objFactory.createColFilterList();
            ndct.setColFilterList(colFilterList);

            for (Iterator iter = dct.getColFilterList().getColFilter().iterator(); iter
                    .hasNext();)
                colFilterList.getColFilter().add(
                        cloneColFilterType(objFactory, (ColFilterType) iter.next()));
		}

        if (nvl(dct.getSemaphoreId()).length() > 0)
            ndct.setSemaphoreId(dct.getSemaphoreId());
        if (nvl(dct.getDbColType()).length() > 0)
            ndct.setDbColType(dct.getDbColType());
        else {
            ndct.setDbColType(dct.getColType());
            adjustColumnType(ndct);
        }
        if (nvl(dct.getChartGroup()).length() > 0)
            ndct.setChartGroup(dct.getChartGroup());

        if (nvl(dct.getYAxis()).length() > 0)
            ndct.setYAxis(dct.getYAxis());

        if (nvl(dct.getDependsOnFormField()).length() > 0)
            ndct.setDependsOnFormField(dct.getDependsOnFormField());

        if (nvl(dct.getNowrap()).length() > 0)
            ndct.setNowrap(dct.getNowrap());

        if (dct.getIndentation() != null) {
            ndct.setIndentation(dct.getIndentation());
        }

        ndct.setEnhancedPagination(
                (dct.isEnhancedPagination() != null && dct.isEnhancedPagination().booleanValue()) ? true : false);
        if (nvl(dct.getDataMiningCol()).length() > 0)
            ndct.setDataMiningCol(dct.getDataMiningCol());

        ndct.setColId(dct.getColId());

        return ndct;
	} 

    public DataSourceType cloneDataSourceType(ObjectFactory objFactory, DataSourceType dst)
            throws JAXBException {
        DataSourceType ndst = objFactory.createDataSourceType();

        ndst.setTableName(dst.getTableName());
        ndst.setTablePK(dst.getTablePK());
        ndst.setDisplayName(dst.getDisplayName());
        if (nvl(dst.getRefTableId()).length() > 0)
            ndst.setRefTableId(dst.getRefTableId());
        if (nvl(dst.getRefDefinition()).length() > 0)
            ndst.setRefDefinition(dst.getRefDefinition());
        if (nvl(dst.getComment()).length() > 0)
            ndst.setComment(dst.getComment());
        DataColumnList dataColumnList = objFactory.createDataColumnList();
        ndst.setDataColumnList(dataColumnList);

        for (Iterator iter = dst.getDataColumnList().getDataColumn().iterator(); iter
                .hasNext();)
            dataColumnList.getDataColumn().add(
                    cloneDataColumnType(objFactory, (DataColumnType) iter.next()));
        ndst.setTableId(dst.getTableId());

        return ndst;
	} 

    public CustomReportType cloneCustomReport() throws RaptorException {
        ObjectFactory objFactory = new ObjectFactory();
        CustomReportType ncr = objFactory.createCustomReportType();
        try {
            ncr.setReportName(cr.getReportName());
            ncr.setReportDescr(cr.getReportDescr());
            if (nvl(cr.getNumDashCols()).length() > 0)
                ncr.setNumDashCols(cr.getNumDashCols());
            if (nvl(cr.getDashboardLayoutHTML()).length() > 0)
                ncr.setDashboardLayoutHTML(cr.getDashboardLayoutHTML());
			if (nvl(cr.getDashboardLayoutJSON()).length() > 0)
				ncr.setDashboardLayoutJSON(cr.getDashboardLayoutJSON());			
            if (nvl(cr.getDbInfo()).length() > 0)
                ncr.setDbInfo(cr.getDbInfo());
            ncr.setChartType(cr.getChartType());
            if (nvl(cr.getChartTypeFixed()).length() > 0)
                ncr.setChartTypeFixed(cr.getChartTypeFixed());
            if (nvl(cr.getChartMultiSeries()).length() > 0)
                ncr.setChartMultiSeries(cr.getChartMultiSeries());
            if (nvl(cr.getChartLeftAxisLabel()).length() > 0)
                ncr.setChartLeftAxisLabel(cr.getChartLeftAxisLabel());
            if (nvl(cr.getChartRightAxisLabel()).length() > 0)
                ncr.setChartRightAxisLabel(cr.getChartRightAxisLabel());
            if (nvl(cr.getChartWidth()).length() > 0)
                ncr.setChartWidth(cr.getChartWidth());
            if (nvl(cr.getChartHeight()).length() > 0)
                ncr.setChartHeight(cr.getChartHeight());
            ncr.setShowChartTitle(cr.isShowChartTitle());
            ncr.setPublic(cr.isPublic());
            ncr.setHideFormFieldAfterRun(cr.isHideFormFieldAfterRun());
            ncr.setCreateId(cr.getCreateId());
            ncr.setCreateDate(cr.getCreateDate());
            if (nvl(cr.getReportSQL()).length() > 0)
                ncr.setReportSQL(cr.getReportSQL());
            if (nvl(cr.getReportTitle()).length() > 0)
                ncr.setReportTitle(cr.getReportTitle());
            if (nvl(cr.getReportSubTitle()).length() > 0)
                ncr.setReportSubTitle(cr.getReportSubTitle());
            if (nvl(cr.getReportHeader()).length() > 0)
                ncr.setReportHeader(cr.getReportHeader());
            if (cr.getFrozenColumns() != null)
                ncr.setFrozenColumns(cr.getFrozenColumns());
            if (nvl(cr.getPdfImgLogo()).length() > 0)
                ncr.setPdfImgLogo(cr.getPdfImgLogo());
            if (nvl(cr.getEmptyMessage()).length() > 0)
                ncr.setEmptyMessage(cr.getEmptyMessage());
            if (nvl(cr.getWidthNoColumn()).length() > 0)
                ncr.setWidthNoColumn(cr.getWidthNoColumn());
            if (nvl(cr.getDataGridAlign()).length() > 0)
                ncr.setDataGridAlign(cr.getDataGridAlign());
                ncr.setReportFooter(cr.getReportFooter());
                ncr.setNumFormCols(cr.getNumFormCols());
                ncr.setDisplayOptions(cr.getDisplayOptions());
                ncr.setDataContainerHeight(cr.getDataContainerHeight());
                ncr.setDataContainerWidth(cr.getDataContainerWidth());
                ncr.setAllowSchedule(cr.getAllowSchedule());
                ncr.setTopDown(cr.getTopDown());
                ncr.setSizedByContent(cr.getSizedByContent());
                ncr.setComment(cr.getComment());
                ncr.setDashboardOptions(cr.getDashboardOptions());
                ncr.setDashboardType(cr.isDashboardType());
                ncr.setReportInNewWindow(cr.isReportInNewWindow());
            ncr.setDisplayFolderTree(cr.isDisplayFolderTree());
            if (cr.getDashBoardReports() == null) {
                if (cr.getMaxRowsInExcelDownload() != null && cr.getMaxRowsInExcelDownload() > 0)
                    ncr.setMaxRowsInExcelDownload(cr.getMaxRowsInExcelDownload());
            }

            if (nvl(cr.getJavascriptElement()).length() > 0)
                ncr.setJavascriptElement(cr.getJavascriptElement());
            if (nvl(cr.getFolderId()).length() > 0)
                ncr.setFolderId(cr.getFolderId());
            ncr.setDrillURLInPoPUpPresent(
                    (cr.isDrillURLInPoPUpPresent() != null && cr.isDrillURLInPoPUpPresent().booleanValue()) ? true
                            : false);
                ncr.setIsOneTimeScheduleAllowed(cr.getIsOneTimeScheduleAllowed());
                ncr.setIsHourlyScheduleAllowed(cr.getIsHourlyScheduleAllowed());
                ncr.setIsDailyScheduleAllowed(cr.getIsDailyScheduleAllowed());
                ncr.setIsDailyMFScheduleAllowed(cr.getIsDailyMFScheduleAllowed());
                ncr.setIsWeeklyScheduleAllowed(cr.getIsWeeklyScheduleAllowed());
                ncr.setIsMonthlyScheduleAllowed(cr.getIsMonthlyScheduleAllowed());

            ncr.setPageSize(cr.getPageSize());
            ncr.setReportType(cr.getReportType());
			ncr.setFormFieldGroupsJSON(cr.getFormFieldGroupsJSON());
            DataSourceList dataSourceList = objFactory.createDataSourceList();
            ncr.setDataSourceList(dataSourceList);

            for (Iterator iter = cr.getDataSourceList().getDataSource().iterator(); iter.hasNext();) {
                dataSourceList.getDataSource().add(
                        cloneDataSourceType(objFactory, (DataSourceType) iter.next()));
            }

            if (cr.getFormFieldList() != null) {
                FormFieldList formFieldList = objFactory.createFormFieldList();
                ncr.setFormFieldList(formFieldList);
                ncr.getFormFieldList().setComment(formFieldList.getComment());

                for (Iterator iter = cr.getFormFieldList().getFormField().iterator(); iter
                        .hasNext();)
                    formFieldList.getFormField().add(
                            cloneFormFieldType(objFactory, (FormFieldType) iter.next()));
                formFieldList.setComment(cr.getFormFieldList().getComment());
			} 

            if (cr.getJavascriptList() != null) {
                JavascriptList javascriptList = objFactory.createJavascriptList();
                ncr.setJavascriptList(javascriptList);

                for (Iterator iter = cr.getJavascriptList().getJavascriptItem().iterator(); iter
                        .hasNext();)
                    javascriptList.getJavascriptItem().add(
                            cloneJavascriptType(objFactory, (JavascriptItemType) iter.next()));
			}

            if (cr.getSemaphoreList() != null) {
                SemaphoreList semaphoreList = objFactory.createSemaphoreList();
                ncr.setSemaphoreList(semaphoreList);

                for (Iterator iter = cr.getSemaphoreList().getSemaphore().iterator(); iter
                        .hasNext();) {
                    semaphoreList.getSemaphore().add(
                            cloneSemaphoreType(objFactory, (SemaphoreType) iter.next()));
                }
			} 

            if (nvl(cr.getDashboardOptions()).length() > 0)
                ncr.setDashboardOptions(cr.getDashboardOptions());
            if (cr.isDashboardType() != null)
                ncr.setDashboardType(cr.isDashboardType());
            if (cr.isReportInNewWindow() != null)
                ncr.setReportInNewWindow(cr.isReportInNewWindow());
            ncr.setDisplayFolderTree(cr.isDisplayFolderTree());
            if (cr.getDashBoardReports() == null) {
                if (cr.getMaxRowsInExcelDownload() != null && cr.getMaxRowsInExcelDownload() > 0)
                    ncr.setMaxRowsInExcelDownload(cr.getMaxRowsInExcelDownload());
            }

            if (cr.getDashBoardReports() != null) {
                DashboardReports dashboardReports = objFactory.createDashboardReports();
                ncr.setDashBoardReports(dashboardReports);

                for (Iterator iter = cr.getDashBoardReports().getReportsList().iterator(); iter
                        .hasNext();) {
                    dashboardReports.getReportsList().add(
                            cloneDashboardType(objFactory, (Reports) iter.next()));
                }
			} 

            if (cr.getChartAdditionalOptions() != null) {
                ChartAdditionalOptions chartAdditionalOptions = objFactory.createChartAdditionalOptions();
                if (nvl(cr.getChartAdditionalOptions().getChartMultiplePieOrder()).length() > 0)
                    chartAdditionalOptions
                            .setChartMultiplePieOrder(cr.getChartAdditionalOptions().getChartMultiplePieOrder());
                if (nvl(cr.getChartAdditionalOptions().getChartMultiplePieLabelDisplay()).length() > 0)
                    chartAdditionalOptions.setChartMultiplePieLabelDisplay(
                            cr.getChartAdditionalOptions().getChartMultiplePieLabelDisplay());

                if (nvl(cr.getChartAdditionalOptions().getChartOrientation()).length() > 0)
                    chartAdditionalOptions.setChartOrientation(cr.getChartAdditionalOptions().getChartOrientation());
                if (nvl(cr.getChartAdditionalOptions().getSecondaryChartRenderer()).length() > 0)
                    chartAdditionalOptions
                            .setSecondaryChartRenderer(cr.getChartAdditionalOptions().getSecondaryChartRenderer());

                if (nvl(cr.getChartAdditionalOptions().getChartDisplay()).length() > 0)
                    chartAdditionalOptions.setChartDisplay(cr.getChartAdditionalOptions().getChartDisplay());
                if (nvl(cr.getChartAdditionalOptions().getHideToolTips()).length() > 0)
                    chartAdditionalOptions.setHideToolTips(cr.getChartAdditionalOptions().getHideToolTips());
                if (nvl(cr.getChartAdditionalOptions().getHidechartLegend()).length() > 0)
                    chartAdditionalOptions.setHidechartLegend(cr.getChartAdditionalOptions().getHidechartLegend());
                if (nvl(cr.getChartAdditionalOptions().getLegendPosition()).length() > 0)
                    chartAdditionalOptions.setLegendPosition(cr.getChartAdditionalOptions().getLegendPosition());
                if (nvl(cr.getChartAdditionalOptions().getLabelAngle()).length() > 0)
                    chartAdditionalOptions.setLabelAngle(cr.getChartAdditionalOptions().getLabelAngle());

                if (nvl(cr.getChartAdditionalOptions().getIntervalFromdate()).length() > 0)
                    chartAdditionalOptions.setIntervalFromdate(cr.getChartAdditionalOptions().getIntervalFromdate());
                if (nvl(cr.getChartAdditionalOptions().getIntervalTodate()).length() > 0)
                    chartAdditionalOptions.setIntervalTodate(cr.getChartAdditionalOptions().getIntervalTodate());
                if (nvl(cr.getChartAdditionalOptions().getIntervalLabel()).length() > 0)
                    chartAdditionalOptions.setIntervalLabel(cr.getChartAdditionalOptions().getIntervalLabel());

                if (nvl(cr.getChartAdditionalOptions().getLastSeriesALineChart()).length() > 0)
                    chartAdditionalOptions
                            .setLastSeriesALineChart(cr.getChartAdditionalOptions().getLastSeriesALineChart());
                if (nvl(cr.getChartAdditionalOptions().getLastSeriesABarChart()).length() > 0)
                    chartAdditionalOptions
                            .setLastSeriesABarChart(cr.getChartAdditionalOptions().getLastSeriesABarChart());

                if (nvl(cr.getChartAdditionalOptions().getMaxLabelsInDomainAxis()).length() > 0)
                    chartAdditionalOptions
                            .setMaxLabelsInDomainAxis(cr.getChartAdditionalOptions().getMaxLabelsInDomainAxis());
                if (nvl(cr.getChartAdditionalOptions().getLinearRegression()).length() > 0)
                    chartAdditionalOptions.setLinearRegression(cr.getChartAdditionalOptions().getLinearRegression());
                if (nvl(cr.getChartAdditionalOptions().getLinearRegressionColor()).length() > 0)
                    chartAdditionalOptions
                            .setLinearRegressionColor(cr.getChartAdditionalOptions().getLinearRegressionColor());
                if (nvl(cr.getChartAdditionalOptions().getExponentialRegressionColor()).length() > 0)
                    chartAdditionalOptions.setExponentialRegressionColor(
                            cr.getChartAdditionalOptions().getExponentialRegressionColor());
                if (nvl(cr.getChartAdditionalOptions().getMaxRegression()).length() > 0)
                    chartAdditionalOptions.setMaxRegression(cr.getChartAdditionalOptions().getMaxRegression());
                if (nvl(cr.getChartAdditionalOptions().getRangeAxisUpperLimit()).length() > 0)
                    chartAdditionalOptions
                            .setRangeAxisUpperLimit(cr.getChartAdditionalOptions().getRangeAxisUpperLimit());
                if (nvl(cr.getChartAdditionalOptions().getRangeAxisLowerLimit()).length() > 0)
                    chartAdditionalOptions
                            .setRangeAxisLowerLimit(cr.getChartAdditionalOptions().getRangeAxisLowerLimit());
                if (nvl(cr.getChartAdditionalOptions().getOverlayItemValueOnStackBar()).length() > 0)
                    chartAdditionalOptions.setOverlayItemValueOnStackBar(
                            cr.getChartAdditionalOptions().getOverlayItemValueOnStackBar());
                chartAdditionalOptions.setAnimate((cr.getChartAdditionalOptions().isAnimate() != null
                        && cr.getChartAdditionalOptions().isAnimate().booleanValue()) ? true : false);

                if (nvl(cr.getChartAdditionalOptions().getKeepDomainAxisValueAsString()).length() > 0)
                    chartAdditionalOptions.setKeepDomainAxisValueAsString(
                            cr.getChartAdditionalOptions().getKeepDomainAxisValueAsString());

                // Animate
                chartAdditionalOptions
                        .setAnimateAnimatedChart((cr.getChartAdditionalOptions().isAnimateAnimatedChart() != null
                                && cr.getChartAdditionalOptions().isAnimateAnimatedChart().booleanValue()) ? true
                                        : false);
                chartAdditionalOptions.setStacked((cr.getChartAdditionalOptions().isStacked() != null
                        && cr.getChartAdditionalOptions().isStacked().booleanValue()) ? true : false);
                chartAdditionalOptions.setBarControls((cr.getChartAdditionalOptions().isBarControls() != null
                        && cr.getChartAdditionalOptions().isBarControls().booleanValue()) ? true : false);
                chartAdditionalOptions.setXAxisDateType((cr.getChartAdditionalOptions().isXAxisDateType() != null
                        && cr.getChartAdditionalOptions().isXAxisDateType().booleanValue()) ? true : false);
                chartAdditionalOptions.setLessXaxisTickers((cr.getChartAdditionalOptions().isLessXaxisTickers() != null
                        && cr.getChartAdditionalOptions().isLessXaxisTickers().booleanValue()) ? true : false);
                chartAdditionalOptions.setTimeAxis((cr.getChartAdditionalOptions().isTimeAxis() != null
                        && cr.getChartAdditionalOptions().isTimeAxis().booleanValue()) ? true : false);

                if (nvl(cr.getChartAdditionalOptions().getTimeSeriesRender()).length() > 0)
                    chartAdditionalOptions.setTimeSeriesRender(cr.getChartAdditionalOptions().getTimeSeriesRender());

                chartAdditionalOptions.setMultiSeries((cr.getChartAdditionalOptions().isMultiSeries() != null
                        && cr.getChartAdditionalOptions().isMultiSeries().booleanValue()) ? true : false);

                chartAdditionalOptions.setTopMargin(cr.getChartAdditionalOptions().getTopMargin() != null
                        ? cr.getChartAdditionalOptions().getTopMargin()
                        : new Integer(30));
                chartAdditionalOptions.setBottomMargin(cr.getChartAdditionalOptions().getBottomMargin() != null
                        ? cr.getChartAdditionalOptions().getBottomMargin()
                        : new Integer(50));
                chartAdditionalOptions.setLeftMargin(cr.getChartAdditionalOptions().getLeftMargin() != null
                        ? cr.getChartAdditionalOptions().getLeftMargin()
                        : new Integer(100));
                chartAdditionalOptions.setRightMargin(cr.getChartAdditionalOptions().getRightMargin() != null
                        ? cr.getChartAdditionalOptions().getRightMargin()
                        : new Integer(60));

                ncr.setChartAdditionalOptions(chartAdditionalOptions);
			} 

            if (nvl(cr.getJavascriptElement()).length() > 0)
                ncr.setJavascriptElement(cr.getJavascriptElement());
            if (nvl(cr.getFolderId()).length() > 0)
                ncr.setFolderId(cr.getFolderId());

            if (cr.getChartDrillOptions() != null) {
                ChartDrillOptions chartDrillOptions = objFactory.createChartDrillOptions();

                if (nvl(cr.getChartDrillOptions().getDrillReportId()).length() > 0)
                    chartDrillOptions.setDrillReportId(cr.getChartDrillOptions().getDrillReportId());

                for (Iterator iter = cr.getChartDrillOptions().getTargetFormfield().iterator(); iter
                        .hasNext();) {
                    chartDrillOptions.getTargetFormfield().add(
                            cloneChartDrillFormfield(objFactory, (ChartDrillFormfield) iter.next()));

                }

                if (nvl(cr.getChartDrillOptions().getDrillXAxisFormField()).length() > 0)
                    chartDrillOptions.setDrillXAxisFormField(cr.getChartDrillOptions().getDrillXAxisFormField());
                if (nvl(cr.getChartDrillOptions().getDrillYAxisFormField()).length() > 0)
                    chartDrillOptions.setDrillYAxisFormField(cr.getChartDrillOptions().getDrillYAxisFormField());
                if (nvl(cr.getChartDrillOptions().getDrillSeriesFormField()).length() > 0)
                    chartDrillOptions.setDrillSeriesFormField(cr.getChartDrillOptions().getDrillSeriesFormField());

                ncr.setChartDrillOptions(chartDrillOptions);
            }
                ncr.setIsOneTimeScheduleAllowed(cr.getIsOneTimeScheduleAllowed());
                ncr.setIsHourlyScheduleAllowed(cr.getIsHourlyScheduleAllowed());
                ncr.setIsDailyScheduleAllowed(cr.getIsDailyScheduleAllowed());
                ncr.setIsDailyMFScheduleAllowed(cr.getIsDailyMFScheduleAllowed());
                ncr.setIsWeeklyScheduleAllowed(cr.getIsWeeklyScheduleAllowed());
                ncr.setIsMonthlyScheduleAllowed(cr.getIsMonthlyScheduleAllowed());

            ncr.setPageSize(cr.getPageSize());
            ncr.setReportType(cr.getReportType());

            if (cr.getReportMap() != null) {
                ReportMap repMap = objFactory.createReportMap();
                if (nvl(cr.getReportMap().getMarkerColor()).length() > 0)
                    repMap.setMarkerColor(cr.getReportMap().getMarkerColor());
                if (nvl(cr.getReportMap().getUseDefaultSize()).length() > 0)
                    repMap.setUseDefaultSize(cr.getReportMap().getUseDefaultSize());
                if (nvl(cr.getReportMap().getHeight()).length() > 0)
                    repMap.setHeight(cr.getReportMap().getHeight());
                if (nvl(cr.getReportMap().getWidth()).length() > 0)
                    repMap.setWidth(cr.getReportMap().getWidth());
                if (nvl(cr.getReportMap().getIsMapAllowedYN()).length() > 0)
                    repMap.setIsMapAllowedYN(cr.getReportMap().getIsMapAllowedYN());
                if (nvl(cr.getReportMap().getAddAddressInDataYN()).length() > 0)
                    repMap.setAddAddressInDataYN(cr.getReportMap().getAddAddressInDataYN());
                if (nvl(cr.getReportMap().getAddressColumn()).length() > 0)
                    repMap.setAddressColumn(cr.getReportMap().getAddressColumn());
                if (nvl(cr.getReportMap().getDataColumn()).length() > 0)
                    repMap.setDataColumn(cr.getReportMap().getDataColumn());
                if (nvl(cr.getReportMap().getDefaultMapType()).length() > 0)
                    repMap.setDefaultMapType(cr.getReportMap().getDefaultMapType());
                if (nvl(cr.getReportMap().getLatColumn()).length() > 0)
                    repMap.setLatColumn(cr.getReportMap().getLatColumn());
                if (nvl(cr.getReportMap().getLongColumn()).length() > 0)
                    repMap.setLongColumn(cr.getReportMap().getLongColumn());
                if (nvl(cr.getReportMap().getColorColumn()).length() > 0)
                    repMap.setColorColumn(cr.getReportMap().getColorColumn());
                if (nvl(cr.getReportMap().getLegendColumn()).length() > 0)
                    repMap.setLegendColumn(cr.getReportMap().getLegendColumn());

                for (Iterator iter = cr.getReportMap().getMarkers().iterator(); iter
                        .hasNext();) {
                    repMap.getMarkers().add(
                            cloneMarkerType(objFactory, (Marker) iter.next()));

                }

                ncr.setReportMap(repMap);
            }

		} catch (JAXBException ex) { 
            logger.error(EELFLoggerDelegate.debugLogger, "Exception occured in cloneCustomReport ", ex);
            throw new RaptorException(ex.getMessage(), ex.getCause());
        }

        return ncr;
	} 



    private int getIntValue(String value, int defaultValue) {
        int iValue = defaultValue;
        try {
            iValue = Integer.parseInt(value);
        } catch (Exception e) {
            logger.error(EELFLoggerDelegate.debugLogger, "Exception occured in getIntValue ", e);
        }

        return iValue;
	} 

    public static String replaceNewLine(String strSource, String strFind, String chrReplace) {
        StringBuffer sbfTemp = new StringBuffer();

        try {
            int intIndex = strSource.indexOf(strFind, 0);
            if (intIndex >= 0) {
                int intStart = 0;

                int intTotalSize = strSource.length();

                while (intStart < intTotalSize &&
                        ((intIndex = strSource.indexOf(strFind, intStart)) >= 0)) {
                    if (intIndex == intStart) {
                        sbfTemp.append(chrReplace);
                    } else {
                        sbfTemp.append(strSource.substring(intStart, intIndex));
                        sbfTemp.append(chrReplace);
                    }
                    intStart = intIndex + strFind.length();
                }
                sbfTemp.append(strSource.substring(intStart));
            } else {
                sbfTemp.append(strSource);
            }
        } catch (Exception expGeneral) {
            logger.error(EELFLoggerDelegate.debugLogger, "Exception occured in replaceNewLine ", expGeneral);
            sbfTemp = new StringBuffer(strSource);
        }

        return sbfTemp.toString();
    }


    public String getFolderId() {
        return nvl(cr.getFolderId()).length() > 0 ? cr.getFolderId() : "NULL";
    }

    public void setFolderId(String folderId) {
        cr.setFolderId(folderId);
    }

    public String addZero(String num) {
        int numInt = 0;
        try {
            numInt = Integer.parseInt(num);
        } catch (NumberFormatException ex) {
            numInt = 0;
        }
        if (numInt < 10)
            return "0" + numInt;
        else
            return "" + numInt;
    }

    public String getIsDailyMFScheduleAllowed() {
        return cr.getIsDailyMFScheduleAllowed();
    }

    public void setIsDailyMFScheduleAllowed(String isDailyMFScheduleAllowed) {
        cr.setIsDailyMFScheduleAllowed(isDailyMFScheduleAllowed);
    }

    public String getIsDailyScheduleAllowed() {
        return cr.getIsDailyScheduleAllowed();
    }

    public void setIsDailyScheduleAllowed(String isDailyScheduleAllowed) {
        cr.setIsDailyScheduleAllowed(isDailyScheduleAllowed);
    }

    public String getIsHourlyScheduleAllowed() {
        return cr.getIsHourlyScheduleAllowed();
    }

    public void setIsHourlyScheduleAllowed(String isHourlyScheduleAllowed) {
        cr.setIsHourlyScheduleAllowed(isHourlyScheduleAllowed);
    }

    public String getIsMonthlyScheduleAllowed() {
        return cr.getIsMonthlyScheduleAllowed();
    }

    public void setIsMonthlyScheduleAllowed(String isMonthlyScheduleAllowed) {
        cr.setIsMonthlyScheduleAllowed(isMonthlyScheduleAllowed);
    }

    public String getIsOneTimeScheduleAllowed() {
        return cr.getIsOneTimeScheduleAllowed();
    }

    public void setIsOneTimeScheduleAllowed(String isOneTimeScheduleAllowed) {
        cr.setIsOneTimeScheduleAllowed(isOneTimeScheduleAllowed);
    }

    public String getIsWeeklyScheduleAllowed() {
        return cr.getIsWeeklyScheduleAllowed();
    }

    public void setIsWeeklyScheduleAllowed(String isWeeklyScheduleAllowed) {
        cr.setIsWeeklyScheduleAllowed(isWeeklyScheduleAllowed);

    }

    public static boolean isNull(String a) {
        if ((a == null) || (a.length() == 0) || "null".equalsIgnoreCase(a))
            return true;
        else
            return false;
    }

    public int getDependsOnFormFieldFlag(DataColumnType dc, HashMap formValues) {
        int flag = 0;
        String fieldValue = "";
        if (nvl(dc.getDependsOnFormField()).length() > 0 && nvl(dc.getDependsOnFormField()).indexOf("[") != -1) {
            if (formValues != null) {
                Set set = formValues.entrySet();
                String value = "";
                for (Iterator iter1 = set.iterator(); iter1.hasNext();) {
                    Map.Entry entry = (Entry) iter1.next();
                    value = (String) entry.getValue();
                    if (dc.getDependsOnFormField().equals("[" + entry.getKey() + "]")) {
                        fieldValue = nvl(value);

                        if (fieldValue.length() > 0 && !"NULL".equals(fieldValue)) {
                            flag = 0;
                        } else {
                            flag = 1;
                        }

                    }
                }
            }
        }

        return flag;
    }

    public String getClassifier() {
        return (cr.getDataminingOptions() != null ? cr.getDataminingOptions().getClassifier() : "");
    }

    public void setClassifier(String classifier) {
        cr.getDataminingOptions().setClassifier(classifier);
    }

    public int getForecastingPeriod() {
        return (cr.getDataminingOptions() != null
                ? new Integer(cr.getDataminingOptions().getForecastingUnits()).intValue()
                : -1);
    }

    public void setForecastingPeriod(String period) {
        cr.getDataminingOptions().setForecastingUnits(period);
    }

    public String getForecastingTimeFormat() {
        return (cr.getDataminingOptions() != null ? cr.getDataminingOptions().getTimeformat() : "");
    }

    public void setForecastingTimeFormat(String format) {
        cr.getDataminingOptions().setTimeformat(format);
    }

    /**
     * Get Number of Columns to Frozen in Data Grid
     */

    public int getFrozenColumns() {
        return cr.getFrozenColumns() == null ? 0 : cr.getFrozenColumns();
    }

    public String getFrozenColumnId() {
        int noOfColumns = cr.getFrozenColumns() == null ? 0 : cr.getFrozenColumns();
        if (noOfColumns != 0) {
            List reportCols = getOnlyVisibleColumns();
            int colIdx = 0;
            for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
                ++colIdx;
                DataColumnType dc = (DataColumnType) iter.next();
                if (colIdx == noOfColumns) {

                    return dc.getColId();
                } else
                    continue;
            } // for
            return "";
        } else
            return "";

    }

    /**
     * Set Number of Columns to Frozen in Data Grid
     */

    public void setFrozenColumns(int frozenColumns) {
        cr.setFrozenColumns(frozenColumns);
    }

    /**
     * @return the reportSQLWithRowNum for ZK Support
     */
    public String getReportSQLWithRowNum() {
        return reportSQLWithRowNum;
    }

    /**
     * @param reportSQLWithRowNum the reportSQLWithRowNum to set for ZK Support
     */
    public void setReportSQLWithRowNum(String reportSQLWithRowNum) {
        this.reportSQLWithRowNum = reportSQLWithRowNum;
    }

    public void setReportSQLOnlyFirstPart(String reportSQLOnlyFirstPart) {
        this.reportSQLOnlyFirstPart = reportSQLOnlyFirstPart;
    }

    public String getReportSQLOnlyFirstPart() {
        return this.reportSQLOnlyFirstPart;
    }

    public String getTemplateFile() throws RaptorException {
        return ReportLoader.getTemplateFile(getReportID());
    }

    public String getPdfImg() {
        return cr.getPdfImgLogo();
    }

    public String getEmptyMessage() {
        String emptyMessage = cr.getEmptyMessage();
        if (nvl(emptyMessage).length() <= 0)
            emptyMessage = Globals.getReportEmptyMessage();
        return emptyMessage;
    }

    public void setPdfImg(String img_loc) {
        cr.setPdfImgLogo(img_loc);
    }

    public void setEmptyMessage(String emptyMessage) {
        cr.setEmptyMessage(emptyMessage);
    }

    public void setDrillReportIdForChart(String reportId) {
        cr.getChartDrillOptions().setDrillReportId(reportId);
    }

    public String getDrillReportIdForChart() {
        return (cr.getChartDrillOptions() != null) ? cr.getChartDrillOptions().getDrillReportId() : "";
    }

    public void setDrillXAxisFormField(String formField) {
        cr.getChartDrillOptions().setDrillXAxisFormField(formField);
    }

    public String getDrillXAxisFormField() {
        return (cr.getChartDrillOptions() != null) ? cr.getChartDrillOptions().getDrillXAxisFormField() : "";
    }

    public void setDrillYAxisFormField(String formField) {
        cr.getChartDrillOptions().setDrillYAxisFormField(formField);
    }

    public String getDrillYAxisFormField() {
        return (cr.getChartDrillOptions() != null) ? cr.getChartDrillOptions().getDrillYAxisFormField() : "";
    }

    public void setDrillSeriesFormField(String formField) {
        cr.getChartDrillOptions().setDrillSeriesFormField(formField);
    }

    public String getDrillSeriesFormField() {
        return (cr.getChartDrillOptions() != null) ? cr.getChartDrillOptions().getDrillSeriesFormField() : "";
    }

    public boolean isEnhancedPaginationNeeded() {
        List reportCols = getAllColumns();

        for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
            DataColumnType dc = (DataColumnType) iter.next();
            if (dc.isEnhancedPagination() != null && dc.isEnhancedPagination().booleanValue())
                return true;
		} 
        return false;
    }

    public DataColumnType getColumnWhichNeedEnhancedPagination() {
        List reportCols = getAllColumns();

        for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
            DataColumnType dc = (DataColumnType) iter.next();
            if (dc.isEnhancedPagination() != null && dc.isEnhancedPagination().booleanValue())
                return dc;
		} 
        return null;
    }

    public void setDataGridAlign(String align) {
        cr.setDataGridAlign(align);
    }

    public String getDataGridAlign() {
        return (cr.getDataGridAlign() != null) ? cr.getDataGridAlign() : "left";
    }

    public void setWidthNoColumn(String width) {
        cr.setWidthNoColumn(width);
    }

    public String getWidthNoColumn() {
        return (cr.getWidthNoColumn() != null) ? cr.getWidthNoColumn() : "30px";
    }

    public void setWholeSQL(String sql) {
        wholeSQL = sql;
    }

    public String getWholeSQL() {
        return wholeSQL;
    }

}