2 * ================================================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ================================================================================
20 package org.openecomp.portalsdk.analytics.model.definition;
22 import java.io.Serializable;
23 import java.sql.Connection;
24 import java.util.Calendar;
25 import java.util.Collections;
26 import java.util.Iterator;
27 import java.util.List;
28 import java.util.StringTokenizer;
29 import java.util.Vector;
30 import java.util.regex.Matcher;
31 import java.util.regex.Pattern;
33 import javax.servlet.http.HttpServletRequest;
34 import javax.xml.bind.JAXBException;
35 import javax.xml.datatype.DatatypeConfigurationException;
36 import javax.xml.datatype.DatatypeFactory;
37 //import javax.xml.transform.stream.*;
39 import org.openecomp.portalsdk.analytics.controller.WizardSequence;
40 import org.openecomp.portalsdk.analytics.controller.WizardSequenceCrossTab;
41 import org.openecomp.portalsdk.analytics.controller.WizardSequenceDashboard;
42 import org.openecomp.portalsdk.analytics.controller.WizardSequenceLinear;
43 import org.openecomp.portalsdk.analytics.controller.WizardSequenceSQLBasedCrossTab;
44 import org.openecomp.portalsdk.analytics.controller.WizardSequenceSQLBasedHive;
45 import org.openecomp.portalsdk.analytics.controller.WizardSequenceSQLBasedLinear;
46 import org.openecomp.portalsdk.analytics.controller.WizardSequenceSQLBasedLinearDatamining;
47 import org.openecomp.portalsdk.analytics.error.RaptorException;
48 import org.openecomp.portalsdk.analytics.model.DataCache;
49 import org.openecomp.portalsdk.analytics.model.ReportLoader;
50 import org.openecomp.portalsdk.analytics.model.base.OrderBySeqComparator;
51 import org.openecomp.portalsdk.analytics.model.base.OrderSeqComparator;
52 import org.openecomp.portalsdk.analytics.model.base.ReportWrapper;
53 import org.openecomp.portalsdk.analytics.model.runtime.FormField;
54 import org.openecomp.portalsdk.analytics.system.AppUtils;
55 import org.openecomp.portalsdk.analytics.system.DbUtils;
56 import org.openecomp.portalsdk.analytics.system.Globals;
57 import org.openecomp.portalsdk.analytics.util.AppConstants;
58 import org.openecomp.portalsdk.analytics.util.DataSet;
59 import org.openecomp.portalsdk.analytics.util.Utils;
60 import org.openecomp.portalsdk.analytics.xmlobj.ChartAdditionalOptions;
61 import org.openecomp.portalsdk.analytics.xmlobj.ChartDrillOptions;
62 import org.openecomp.portalsdk.analytics.xmlobj.ColFilterType;
63 import org.openecomp.portalsdk.analytics.xmlobj.CustomReportType;
64 import org.openecomp.portalsdk.analytics.xmlobj.DataColumnList;
65 import org.openecomp.portalsdk.analytics.xmlobj.DataColumnType;
66 import org.openecomp.portalsdk.analytics.xmlobj.DataSourceType;
67 import org.openecomp.portalsdk.analytics.xmlobj.DataminingOptions;
68 import org.openecomp.portalsdk.analytics.xmlobj.FormFieldList;
69 import org.openecomp.portalsdk.analytics.xmlobj.FormFieldType;
70 import org.openecomp.portalsdk.analytics.xmlobj.FormatList;
71 import org.openecomp.portalsdk.analytics.xmlobj.FormatType;
72 import org.openecomp.portalsdk.analytics.xmlobj.JavascriptItemType;
73 import org.openecomp.portalsdk.analytics.xmlobj.ObjectFactory;
74 import org.openecomp.portalsdk.analytics.xmlobj.PredefinedValueList;
75 import org.openecomp.portalsdk.analytics.xmlobj.SemaphoreType;
76 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
79 * This class is part of <B><I>RAPTOR (Rapid Application Programming Tool for OLAP Reporting)</I></B><BR/>
82 * --------------------------------------------------------------------------------------------------<BR/>
83 * <B>ReportDefinition.java</B> - This involves in creating and modifying RAPTOR reports.
84 * --------------------------------------------------------------------------------------------------<BR/>
87 * <U>Change Log</U><BR/><BR/>
89 * 18-Aug-2009 : Version 8.5.1 (Sundar);<UL><LI> request Object is passed to prevent caching user/roles - Datamining/Hosting. </LI></UL>
90 * 27-Jul-2009 : Version 8.4 (Sundar); <UL><LI>userIsAuthorizedToSeeLog is checked for Admin User instead of Super User.</LI></UL>
91 * 22-Jun-2009 : Version 8.4 (Sundar); <UL><LI>A new type ChartAdditionalOptions is introduced in RAPTOR XSD.
92 * For this type a create procedure is added to this class.</LI></UL>
96 public class ReportDefinition extends ReportWrapper implements Serializable {
98 static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ReportDefinition.class);
101 private ReportSchedule reportSchedule = null;
103 private WizardSequence wizardSequence = null;
106 private boolean reportUpdateLogged = false; // Used to avoid multiple
107 // entries in the report log
108 // when persisting report on
111 private ReportDefinition(CustomReportType crType, String reportID, String ownerID,
112 String createID, String createDate, String updateID, String updateDate,
113 String menuID, boolean menuApproved, HttpServletRequest request) throws RaptorException {
114 super(crType, reportID, ownerID, createID, createDate, updateID, updateDate, menuID,
116 if(reportID.equals("-1"))
117 reportSchedule = new ReportSchedule(getReportID(), getOwnerID(), false, request);
119 reportSchedule = new ReportSchedule(getReportID(), getOwnerID(), true, request);
120 generateWizardSequence(null);
121 } // ReportDefinition
123 public ReportDefinition(ReportWrapper rw, HttpServletRequest request)throws RaptorException {
126 reportSchedule = new ReportSchedule(reportID, rw.getOwnerID(),false, request);
127 generateWizardSequence(null);
128 } // ReportDefinition
130 private void setReportID(String reportID) {
131 this.reportID = reportID;
132 reportSchedule.setReportID(reportID);
133 reportSchedule.setScheduleUserID(getOwnerID());
136 public ReportSchedule getReportSchedule() {
137 return reportSchedule;
140 public static ReportDefinition unmarshal(String reportXML, String reportID, HttpServletRequest request)
141 throws RaptorException {
142 ReportDefinition rn = null;
143 CustomReportType crType = ReportWrapper.unmarshalCR(reportXML);
144 //Log.write("Report [" + reportID + "]: XML unmarshalled", 4);
145 logger.debug(EELFLoggerDelegate.debugLogger, ("[DEBUG MESSAGE FROM RAPTOR] Report [" + reportID + "]: XML unmarshalled"));
147 rn = new ReportDefinition(crType, reportID, null, null, null, null, null, null, false, request);
151 public static ReportDefinition createBlank(HttpServletRequest request) throws RaptorException {
152 String curTime = Utils.getCurrentDateTime();
153 String userID = AppUtils.getUserID(request);
154 ReportDefinition rd = new ReportDefinition(ReportWrapper.createBlankCR(userID), "-1",
155 userID, userID, curTime, userID, curTime, "", false, request);
157 // Necessary initialization
160 } // ReportDefinition
162 public void setAsCopy(HttpServletRequest request) throws RaptorException {
163 verifySQLBasedReportAccess(request);
165 replaceCustomReportWithClone();
168 setReportName("Copy: " + getReportName());
171 public WizardSequence getWizardSequence() {
172 return wizardSequence;
173 } // getWizardSequence
175 public void generateWizardSequence(HttpServletRequest request) throws RaptorException {
176 boolean userIsAuthorizedToSeeLog = false;
177 String userId = null;
179 userId = AppUtils.getUserID(request);
181 userIsAuthorizedToSeeLog = AppUtils.isAdminUser(request)
182 || AppUtils.isAdminUser(request);
183 //System.out.println("******** Report Type "+getReportType() + " userIsAuthorizedToSeeLog " + userIsAuthorizedToSeeLog);
185 if (getReportType().equals(AppConstants.RT_LINEAR)){
186 if (getReportDefType().equals(AppConstants.RD_SQL_BASED))
187 wizardSequence = new WizardSequenceSQLBasedLinear(userIsAuthorizedToSeeLog);
188 else if (getReportDefType().equals(AppConstants.RD_SQL_BASED_DATAMIN))
189 wizardSequence = new WizardSequenceSQLBasedLinearDatamining(userIsAuthorizedToSeeLog);
191 wizardSequence = new WizardSequenceLinear(userIsAuthorizedToSeeLog);
192 } else if (getReportType().equals(AppConstants.RT_CROSSTAB)) {
193 if (getReportDefType().equals(AppConstants.RD_SQL_BASED))
194 wizardSequence = new WizardSequenceSQLBasedCrossTab(userIsAuthorizedToSeeLog);
196 wizardSequence = new WizardSequenceCrossTab(userIsAuthorizedToSeeLog);
197 } else if (getReportType().equals(AppConstants.RT_DASHBOARD)) {
198 wizardSequence = new WizardSequenceDashboard(userIsAuthorizedToSeeLog);
199 } else if (getReportType().equals(AppConstants.RT_HIVE)) {
200 wizardSequence = new WizardSequenceSQLBasedHive(userIsAuthorizedToSeeLog);
202 wizardSequence = new WizardSequence();
203 } // generateWizardSequence
205 private boolean canPersistDashboard() {
206 //System.out.println(" getDashBoardReports().getReportsList().size() " + getDashBoardReports().getReportsList().size());
207 /* Commented for New DashBoard
208 if (getDashBoardReports()!=null && getDashBoardReports().getReportsList()!=null && getDashBoardReports().getReportsList().size() > 0) {
209 for (Iterator iter = getDashBoardReports().getReportsList().iterator(); iter.hasNext();) {
210 Reports report = (Reports)iter.next();
212 if(Integer.parseInt(report.getReportId())>0) return true;
213 } catch (NumberFormatException ex) {}
219 return nvl(getDashboardLayoutHTML()).length() > 0;
220 } //canPersistDashboard
222 private boolean canPersistLinearReport() {
223 System.out.println("&&&&&&&&&&&&&&&&&&&&&& canPersistLinearReport");
224 boolean visibleColExist = false;
226 if (getDataSourceList().getDataSource().size() > 0) {
227 for (Iterator iter = getAllColumns().iterator(); iter.hasNext();) {
228 DataColumnType dct = (DataColumnType) iter.next();
230 if (dct.isVisible()) {
231 visibleColExist = true;
237 System.out.println("&&&&&&&&&&&&&&&&&&&&&& visibleColExist " + visibleColExist);
238 return visibleColExist;
239 } // canPersistLinearReport
241 private boolean canPersistCrossTabReport() {
242 boolean rowColExist = false;
243 boolean colColExist = false;
244 boolean valColExist = false;
246 if (getDataSourceList().getDataSource().size() > 0) {
247 for (Iterator iter = getAllColumns().iterator(); iter.hasNext();) {
248 DataColumnType dct = (DataColumnType) iter.next();
250 if (nvl(dct.getCrossTabValue()).equals(AppConstants.CV_ROW))
252 if (nvl(dct.getCrossTabValue()).equals(AppConstants.CV_COLUMN))
254 if (nvl(dct.getCrossTabValue()).equals(AppConstants.CV_VALUE))
259 return rowColExist && colColExist && valColExist;
260 } // canPersistCrossTabReport
262 private boolean canPersistReport() {
263 return getReportType().equals(AppConstants.RT_CROSSTAB) ? canPersistCrossTabReport()
264 : (getReportType().equals(AppConstants.RT_LINEAR)? canPersistLinearReport():((getReportType().equals(AppConstants.RT_HIVE)? canPersistLinearReport():canPersistDashboard())));
265 } // canPersistReport
267 public void persistReport(HttpServletRequest request) throws RaptorException {
268 if (!canPersistReport()) {
269 System.out.println("&&&&&&&&&&&&&&&&&&&&&& In !canPersistReport ReportType: " + getReportType());
272 System.out.println("&&&&&&&&&&&&&&&&&&&&&& Not In !canPersistReport");
275 Connection connection = null;
277 String userID = AppUtils.getUserID(request);
278 String reportXML = marshal();
279 logger.debug(EELFLoggerDelegate.debugLogger, ("Ocurring during Schedule "));
280 System.out.println("&&&&&&&&&&&&&&&&&&&&&& Report ID " + reportID);
281 if (nvl(reportID, "-1").equals("-1")) {
282 connection = DbUtils.startTransaction();
285 if (nvl(Globals.getAdhocReportSequence()).length()> 0 && nvl(Globals.getAdhocUserRoldId()).length() > 0 && AppUtils.isUserInRole(request, Globals.getAdhocUserRoldId()) && !AppUtils.isAdminUser(request)) {
286 //sql = "SELECT "+ Globals.getAdhocReportSequence() + ".nextval FROM dual";
287 sql = Globals.getPersistReportAdhoc();
288 sql = sql.replace("[Globals.getAdhocReportSequence()]", Globals.getAdhocReportSequence());
291 //sql = "SELECT seq_cr_report.nextval FROM dual";
292 sql = Globals.getNewReportData();
294 DataSet ds = DbUtils.executeQuery(connection,sql);
295 setReportID(ds.getString(0, 0));
297 reportSecurity.reportCreate(reportID, userID, isPublic());
298 ReportLoader.createCustomReportRec(connection, this, reportXML);
299 ReportLoader.createReportLogEntry(connection, reportID, userID,
300 AppConstants.RLA_CREATE, "", "");
301 reportUpdateLogged = true;
302 logger.debug(EELFLoggerDelegate.debugLogger, ("[DEBUG MESSAGE FROM RAPTOR] DB insert report " + reportID + " succesfull"));
305 verifySQLBasedReportAccess(request);
306 reportSecurity.reportUpdate(request);
307 connection = DbUtils.startTransaction();
308 ReportLoader.updateCustomReportRec(connection, this, reportXML);
309 if (!reportUpdateLogged) {
310 ReportLoader.createReportLogEntry(connection, reportID, userID,
311 AppConstants.RLA_UPDATE,"","");
312 reportUpdateLogged = true;
314 logger.debug(EELFLoggerDelegate.debugLogger, ("[DEBUG MESSAGE FROM RAPTOR] DB update report " + reportID + " succesfull"));
317 getReportSchedule().persistScheduleData(connection, request);
319 DbUtils.commitTransaction(connection);
320 } catch (RaptorException e) {
322 DbUtils.rollbackTransaction(connection);
325 DbUtils.clearConnection(connection);
329 public String getCrossTabDisplayValue(String crossTabValue) {
330 return nvl(crossTabValue).equals(AppConstants.CV_ROW) ? "Row headings" : (nvl(
331 crossTabValue).equals(AppConstants.CV_COLUMN) ? "Column headings" : (nvl(
332 crossTabValue).equals(AppConstants.CV_VALUE) ? "Report values" : "Invisible/Filter"));
333 } // getCrossTabDisplayValue
335 public String getCrossTabDisplayValue(DataColumnType dct) {
336 return getCrossTabDisplayValue(dct.getCrossTabValue());
337 } // getCrossTabDisplayValue
339 public String getColumnLabel(DataColumnType dct) throws Exception {
340 String tableName = getTableById(dct.getTableId()).getTableName();
341 Vector dbColumns = null;
342 dbColumns = DataCache.getReportTableDbColumns(tableName, cr.getDbInfo());
343 if (dbColumns != null)
344 for (int i = 0; i < dbColumns.size(); i++) {
345 DBColumnInfo dbCol = (DBColumnInfo) dbColumns.get(i);
346 if (dct.getDbColName().equals(dbCol.getColName()))
347 return dbCol.getLabel();
351 } // getCrossTabDisplayValue
353 public String getFilterLabel(ColFilterType cft) {
354 StringBuffer fLabel = new StringBuffer();
356 fLabel.append(cft.getExpression());
358 if (cft.getArgType() != null)
359 if (cft.getArgType().equals(AppConstants.AT_FORMULA)) {
360 fLabel.append("[" + cft.getArgValue() + "]");
361 } else if (cft.getArgType().equals(AppConstants.AT_VALUE)) {
362 fLabel.append(cft.getArgValue());
363 } else if (cft.getArgType().equals(AppConstants.AT_LIST)) {
364 fLabel.append("(" + cft.getArgValue() + ")");
365 } else if (cft.getArgType().equals(AppConstants.AT_COLUMN)) {
366 DataColumnType dctFilter = getColumnById(cft.getArgValue());
367 fLabel.append("[" + dctFilter.getDisplayName() + "]");
368 } else if (cft.getArgType().equals(AppConstants.AT_FORM)) {
369 fLabel.append("[Form Field]");
372 return fLabel.toString();
375 public Vector getReportUsers(HttpServletRequest request) throws RaptorException {
376 return reportSecurity.getReportUsers(request);
379 public Vector getReportRoles(HttpServletRequest request) throws RaptorException {
380 return reportSecurity.getReportRoles(request);
383 /** ************************************************************************************************* */
385 public void clearAllDrillDowns() {
386 List reportCols = getAllColumns();
387 for (int i = 0; i < reportCols.size(); i++) {
388 DataColumnType dct = (DataColumnType) reportCols.get(i);
389 dct.setDrillDownURL(null);
390 dct.setDrillDownParams(null);
391 dct.setDrillDownType(null);
393 } // clearAllDrillDowns
395 public void setOuterJoin(DataSourceType curTable, String joinType) {
396 String refDefinition = nvl(curTable.getRefDefinition());
397 int outerJoinIdx = refDefinition.indexOf(" (+)");
398 if (outerJoinIdx >= 0)
399 // Clear existing outer join
400 if (outerJoinIdx == (refDefinition.length() - 4))
401 refDefinition = refDefinition.substring(0, outerJoinIdx);
403 refDefinition = refDefinition.substring(0, outerJoinIdx)
404 + refDefinition.substring(outerJoinIdx + 4);
406 int equalSignIdx = refDefinition.indexOf("=");
407 if (equalSignIdx < 0)
408 // Ref. definition not present
411 if (refDefinition.indexOf(curTable.getTableId()) < equalSignIdx) {
412 // Cur. table is on the left side
413 if (nvl(joinType).equals(AppConstants.OJ_CURRENT))
414 refDefinition = refDefinition.substring(0, equalSignIdx) + " (+)"
415 + refDefinition.substring(equalSignIdx);
416 else if (nvl(joinType).equals(AppConstants.OJ_JOINED))
417 refDefinition = refDefinition + " (+)";
419 // Joined table is on the left side
420 if (nvl(joinType).equals(AppConstants.OJ_CURRENT))
421 refDefinition = refDefinition + " (+)";
422 else if (nvl(joinType).equals(AppConstants.OJ_JOINED))
423 refDefinition = refDefinition.substring(0, equalSignIdx) + " (+)"
424 + refDefinition.substring(equalSignIdx);
427 curTable.setRefDefinition(refDefinition);
430 public void addDataSourceType(ObjectFactory objFactory, String tableId, String tableName,
431 String tablePK, String displayName, String refTableId, String refDefinition,
432 String comment) throws RaptorException {
433 DataSourceType dst = objFactory.createDataSourceType();
435 dst.setTableId(tableId);
436 dst.setTableName(tableName);
437 dst.setTablePK(tablePK);
438 dst.setDisplayName(displayName);
439 if (nvl(refTableId).length() > 0)
440 dst.setRefTableId(refTableId);
441 if (nvl(refDefinition).length() > 0)
442 dst.setRefDefinition(refDefinition);
443 if (nvl(comment).length() > 0)
444 dst.setComment(comment);
446 DataColumnList dataColumnList = objFactory.createDataColumnList();
447 dst.setDataColumnList(dataColumnList);
449 getDataSourceList().getDataSource().add(dst);
452 } // addDataSourceType
454 public void deleteDataSourceType(String tableId) {
455 super.deleteDataSourceType(tableId);
456 } // deleteDataSourceType
458 public String getUniqueColumnId(String colName) {
461 int colIdN = getAllColumns().size() + 1;
463 colId = colName.substring(0, 2).toLowerCase() + (colIdN++);
464 } while (getColumnById(colId) != null);
467 } // getUniqueColumnId
469 public DataColumnType addDataColumnType(ObjectFactory objFactory, String colId,
470 String tableId, // Table to which the new column belongs
471 String dbColName, String crossTabValue, String colName, String displayName,
472 int displayWidth, String displayAlignment, int orderSeq, boolean visible,
473 boolean calculated, String colType, String colFormat, boolean groupBreak,
474 int orderBySeq, String orderByAscDesc, String displayTotal, String colOnChart,
475 int chartSeq, String drillDownType, String drillDownURL, String drillDownParams,
476 String semaphoreId, String comment) throws RaptorException {
477 DataColumnType dct = null;
478 dct = objFactory.createDataColumnType();
481 dct.setTableId(tableId);
482 dct.setDbColName(dbColName);
483 if (nvl(crossTabValue).length() > 0)
484 dct.setCrossTabValue(crossTabValue);
485 dct.setColName(colName);
486 dct.setDisplayName(displayName);
487 if (displayWidth > 0)
488 dct.setDisplayWidth(displayWidth);
489 if (nvl(displayAlignment).length() > 0)
490 dct.setDisplayAlignment(displayAlignment);
492 dct.setOrderSeq(orderSeq);
494 dct.setOrderSeq(getAllColumns().size() + 1);
495 dct.setVisible(visible);
496 dct.setCalculated(calculated);
497 // dct.setColType(colType);
498 if (nvl(colFormat).length() > 0)
499 dct.setColFormat(colFormat);
500 dct.setGroupBreak(groupBreak);
502 dct.setOrderBySeq(orderBySeq);
503 if (nvl(orderByAscDesc).length() > 0)
504 dct.setOrderByAscDesc(orderByAscDesc);
505 if (nvl(displayTotal).length() > 0)
506 dct.setDisplayTotal(displayTotal);
507 if (nvl(colOnChart).length() > 0)
508 dct.setColOnChart(colOnChart);
510 dct.setChartSeq(chartSeq);
511 if (nvl(drillDownType).length() > 0)
512 dct.setDrillDownType(drillDownType);
513 if (nvl(drillDownURL).length() > 0)
514 dct.setDrillDownURL(drillDownURL);
515 if (nvl(drillDownParams).length() > 0)
516 dct.setDrillDownParams(drillDownParams);
517 if (nvl(semaphoreId).length() > 0)
518 dct.setSemaphoreId(semaphoreId);
519 if (nvl(comment).length() > 0)
520 dct.setComment(comment);
522 dct.setDbColType(colType);
523 adjustColumnType(dct);
525 // ColFilterList colFilterList = objFactory.createColFilterList();
526 // dct.setColFilterList(colFilterList);
528 getTableById(tableId).getDataColumnList().getDataColumn().add(dct);
533 } // addDataColumnType
535 public void deleteDataColumnType(String colId) {
536 int colOrder = getColumnById(colId).getOrderSeq();
538 List dcList = getColumnTableById(colId).getDataColumnList().getDataColumn();
539 for (Iterator iterC = dcList.iterator(); iterC.hasNext();) {
540 DataColumnType dct = (DataColumnType) iterC.next();
542 if (dct.getColId().equals(colId) && dct.getOrderSeq() == colOrder)
544 else if (dct.getOrderSeq() > colOrder)
545 dct.setOrderSeq(dct.getOrderSeq() - 1);
548 if (getFormFieldList() != null)
549 for (Iterator iter = getFormFieldList().getFormField().iterator(); iter.hasNext();) {
550 FormFieldType fft = (FormFieldType) iter.next();
551 if (nvl(fft.getColId()).equals(colId)) {
553 fft.setFieldType(FormField.FFT_TEXT);
554 if (nvl(fft.getDefaultValue()).equals(AppConstants.FILTER_MAX_VALUE)
555 || nvl(fft.getDefaultValue())
556 .equals(AppConstants.FILTER_MIN_VALUE))
557 fft.setDefaultValue("");
562 resetColumnOrderValues();
563 } // deleteDataColumnType
565 public void shiftColumnOrderUp(String colId) {
566 List reportCols = getAllColumns();
567 for (int i = 0; i < reportCols.size(); i++) {
568 DataColumnType dct = (DataColumnType) reportCols.get(i);
570 if (dct.getColId().equals(colId) && (i > 0)) {
571 DataColumnType dctUp = (DataColumnType) reportCols.get(i - 1);
572 dctUp.setOrderSeq(dctUp.getOrderSeq() + 1);
573 dct.setOrderSeq(dct.getOrderSeq() - 1);
578 Collections.sort(reportCols, new OrderSeqComparator());
580 resetColumnOrderValues();
581 } // shiftColumnOrderUp
583 public void shiftColumnOrderDown(String colId) {
584 List reportCols = getAllColumns();
585 for (int i = 0; i < reportCols.size(); i++) {
586 DataColumnType dct = (DataColumnType) reportCols.get(i);
588 if (dct.getColId().equals(colId) && (i < reportCols.size() - 1)) {
589 DataColumnType dctDown = (DataColumnType) reportCols.get(i + 1);
590 dctDown.setOrderSeq(dctDown.getOrderSeq() - 1);
591 dct.setOrderSeq(dct.getOrderSeq() + 1);
596 Collections.sort(reportCols, new OrderSeqComparator());
598 resetColumnOrderValues();
599 } // shiftColumnOrderDown
601 public void resetColumnOrderValues() {
602 List reportCols = getAllColumns();
605 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
606 DataColumnType dct = (DataColumnType) iter.next();
607 dct.setOrderSeq(++colOrder);
610 Collections.sort(reportCols, new OrderSeqComparator());
611 } // resetColumnOrderValues
613 public void addColFilterType(ObjectFactory objFactory, String colId, // Column
620 String joinCondition, String openBrackets, String expression, String argType,
621 String argValue, String closeBrackets, String comment) throws RaptorException {
622 ColFilterType cft = objFactory.createColFilterType();
625 cft.setJoinCondition(nvl(joinCondition, "AND"));
626 if (nvl(openBrackets).length() > 0)
627 cft.setOpenBrackets(openBrackets);
628 cft.setExpression(expression);
629 if (nvl(argType).length() > 0)
630 cft.setArgType(argType);
631 if (nvl(argValue).length() > 0)
632 cft.setArgValue(argValue);
633 if (nvl(closeBrackets).length() > 0)
634 cft.setCloseBrackets(closeBrackets);
635 if (nvl(comment).length() > 0)
636 cft.setComment(comment);
638 DataColumnType dct = getColumnById(colId);
640 if (dct.getColFilterList() == null)
641 dct.setColFilterList(objFactory.createColFilterList());
643 cft.setFilterSeq(dct.getColFilterList().getColFilter().size());
644 dct.getColFilterList().getColFilter().add(cft);
648 } // addColFilterType
650 public void removeColumnFilter(String colId, int filterPos) {
651 DataColumnType dct = getColumnById(colId);
653 if (dct.getColFilterList() != null)
655 dct.getColFilterList().getColFilter().remove(filterPos);
656 } catch (IndexOutOfBoundsException e) {
660 } // removeColumnFilter
662 public void addColumnSort(String colId, String ascDesc) {
663 addColumnSort(colId, ascDesc, -1);
666 public void addColumnSort(String colId, String ascDesc, int sortOrder) {
667 if (sortOrder <= 0) {
669 List reportCols = getAllColumns();
670 for (Iterator iter = reportCols.iterator(); iter.hasNext();)
671 if (((DataColumnType) iter.next()).getOrderBySeq() > 0)
675 DataColumnType dct = getColumnById(colId);
676 dct.setOrderBySeq(sortOrder);
677 dct.setOrderByAscDesc(ascDesc);
682 public void removeColumnSort(String colId) {
683 DataColumnType dct = getColumnById(colId);
684 int sortOrder = dct.getOrderBySeq();
686 dct.setOrderBySeq(0);
687 dct.setOrderByAscDesc(null);
690 List reportCols = getAllColumns();
691 for (Iterator iter = reportCols.iterator(); iter.hasNext();) {
692 DataColumnType dct2 = (DataColumnType) iter.next();
694 if (dct2.getOrderBySeq() > sortOrder)
695 dct2.setOrderBySeq(dct2.getOrderBySeq() - 1);
700 } // removeColumnSort
702 public void shiftColumnSortUp(String colId) {
703 List reportCols = getAllColumns();
704 Collections.sort(reportCols, new OrderBySeqComparator());
706 for (int i = 0; i < reportCols.size(); i++) {
707 DataColumnType dct = (DataColumnType) reportCols.get(i);
709 if (dct.getColId().equals(colId) && (dct.getOrderBySeq() > 0)) {
710 DataColumnType dctUp = (DataColumnType) reportCols.get(i - 1);
711 if (dctUp.getOrderBySeq() > 0)
712 dctUp.setOrderBySeq(dctUp.getOrderBySeq() + 1);
713 dct.setOrderBySeq(dct.getOrderBySeq() - 1);
718 Collections.sort(reportCols, new OrderSeqComparator());
720 } // shiftColumnSortUp
722 public void shiftColumnSortDown(String colId) {
723 List reportCols = getAllColumns();
724 Collections.sort(reportCols, new OrderBySeqComparator());
726 for (int i = 0; i < reportCols.size(); i++) {
727 DataColumnType dct = (DataColumnType) reportCols.get(i);
729 if (dct.getColId().equals(colId) && (dct.getOrderBySeq() > 0)) {
730 DataColumnType dctDown = (DataColumnType) reportCols.get(i + 1);
731 if (dctDown.getOrderBySeq() > 0)
732 dctDown.setOrderBySeq(dctDown.getOrderBySeq() - 1);
733 dct.setOrderBySeq(dct.getOrderBySeq() + 1);
738 Collections.sort(reportCols, new OrderSeqComparator());
740 } // shiftColumnSortDown
742 /** ************************************************************************************************* */
744 public String generateNewSemaphoreId() {
745 if (getSemaphoreList() == null)
748 String semaphoreId = null;
749 boolean idExists = true;
750 for (int i = 1; idExists; i++) {
751 semaphoreId = "sem" + i;
753 for (Iterator iter = getSemaphoreList().getSemaphore().iterator(); iter.hasNext();)
754 if (semaphoreId.equals(((SemaphoreType) iter.next()).getSemaphoreId())) {
761 } // generateNewSemaphoreId
763 public SemaphoreType addSemaphore(ObjectFactory objFactory, SemaphoreType semaphoreType)
764 throws RaptorException {
765 SemaphoreType sem = null;
767 if (getSemaphoreList() == null)
768 setSemaphoreList(objFactory.createSemaphoreList());
770 String semaphoreName = null;
771 boolean nameExists = true;
772 for (int i = 1; nameExists; i++) {
773 semaphoreName = semaphoreType.getSemaphoreName() + ((i > 1) ? (" v" + i) : "");
775 for (Iterator iter2 = getSemaphoreList().getSemaphore().iterator(); iter2
777 if (semaphoreName.equals(((SemaphoreType) iter2.next()).getSemaphoreName())) {
783 sem = cloneSemaphoreType(objFactory, semaphoreType);
784 getSemaphoreList().getSemaphore().add(sem);
786 sem.setSemaphoreId(generateNewSemaphoreId());
787 sem.setSemaphoreName(semaphoreName);
788 } catch (JAXBException ex) {
789 throw new RaptorException(ex.getMessage(), ex.getCause());
795 public SemaphoreType addSemaphoreType(ObjectFactory objFactory, String semaphoreName,
796 String semaphoreType, String comment) throws RaptorException {
797 SemaphoreType sem = null;
798 if (getSemaphoreList() == null)
799 setSemaphoreList(objFactory.createSemaphoreList());
801 sem = objFactory.createSemaphoreType();
802 getSemaphoreList().getSemaphore().add(sem);
804 sem.setSemaphoreId(generateNewSemaphoreId());
805 sem.setSemaphoreName(semaphoreName);
806 sem.setSemaphoreType(nvl(semaphoreType));
807 if (nvl(comment).length() > 0)
808 sem.setComment(comment);
810 FormatList formatList = objFactory.createFormatList();
811 sem.setFormatList(formatList);
813 } // addSemaphoreType
816 public String getNextIdForJavaScriptElement (ObjectFactory objFactory, String fieldId) throws RaptorException {
818 JavascriptItemType jit = null;
820 if (getJavascriptList() == null) {
821 setJavascriptList(objFactory.createJavascriptList());
822 return fieldId + "|1";
824 if(getJavascriptList().getJavascriptItem().iterator().hasNext()) {
825 for (Iterator iter = getJavascriptList().getJavascriptItem().iterator(); iter.hasNext();) {
826 jit = (JavascriptItemType) iter.next();
827 logger.debug(EELFLoggerDelegate.debugLogger, ("^^^^^JAVASCRIPTITEMTYPE " + jit.getFieldId() + " " + fieldId + " " + id));
828 if(nvl(jit.getFieldId()).length()>0 && jit.getFieldId().equals(fieldId)) {
832 return fieldId + "|"+incr;
834 return fieldId + "|1";
841 public JavascriptItemType addJavascriptType(ObjectFactory objFactory, String id) throws RaptorException {
842 JavascriptItemType javascriptItemType = null;
843 int flag = 0; // checking whether id existing in the list
844 if (getJavascriptList() == null) {
845 setJavascriptList(objFactory.createJavascriptList());
846 javascriptItemType = objFactory.createJavascriptItemType();
847 getJavascriptList().getJavascriptItem().add(javascriptItemType);
848 return javascriptItemType;
851 for (Iterator iter = getJavascriptList().getJavascriptItem().iterator(); iter.hasNext();) {
852 javascriptItemType = (JavascriptItemType)iter.next();
853 if(javascriptItemType.getId().equals(id) && !id.startsWith("-1")) {
858 if(flag == 1) return javascriptItemType;
860 javascriptItemType = objFactory.createJavascriptItemType();
861 getJavascriptList().getJavascriptItem().add(javascriptItemType);
862 return javascriptItemType;
866 } // addSemaphoreType
868 public boolean deleteJavascriptType(String id) throws RaptorException {
869 JavascriptItemType javascriptType = null;
870 if (getJavascriptList() == null)
872 for (Iterator iter = getJavascriptList().getJavascriptItem().iterator(); iter.hasNext();) {
873 javascriptType = (JavascriptItemType)iter.next();
874 if(javascriptType.getId().equals(id)) {
880 } // addSemaphoreType
882 public static FormatType addEmptyFormatType(ObjectFactory objFactory,
883 SemaphoreType semaphore) throws RaptorException {
884 FormatType fmt = null;
885 fmt = objFactory.createFormatType();
886 semaphore.getFormatList().getFormat().add(fmt);
888 String formatId = null;
889 boolean idExists = true;
890 for (int i = 1; idExists; i++) {
891 formatId = semaphore.getSemaphoreId() + "_fmt" + i;
893 for (Iterator iter = semaphore.getFormatList().getFormat().iterator(); iter
895 if (formatId.equals(((FormatType) iter.next()).getFormatId())) {
900 fmt.setFormatId(formatId);
902 } // addEmptyFormatType
904 public static void deleteFormatType(SemaphoreType semaphore, String formatId) {
905 for (Iterator iter = semaphore.getFormatList().getFormat().iterator(); iter.hasNext();)
906 if (formatId.equals(((FormatType) iter.next()).getFormatId())) {
910 } // deleteFormatType
912 public FormFieldType addFormFieldType(ObjectFactory objFactory, String fieldName,
913 String colId, String fieldType, String validationType, String mandatory,
914 String defaultValue, String fieldSQL, String comment, Calendar rangeStartDate, Calendar rangeEndDate,
915 String rangeStartDateSQL, String rangeEndDateSQL) throws RaptorException {
916 FormFieldType fft = null;
917 fft = objFactory.createFormFieldType();
919 fft.setFieldName(fieldName);
921 fft.setFieldType(fieldType);
922 fft.setValidationType(validationType);
923 fft.setMandatory(nvl(mandatory, "N"));
924 fft.setDefaultValue(nvl(defaultValue));
925 fft.setOrderBySeq((getFormFieldList() == null) ? 1 : getFormFieldList().getFormField()
927 fft.setFieldSQL(fieldSQL);
928 //fft.setRangeStartDate(rangeStartDate);
929 //fft.setRangeEndDate(rangeEndDate);
932 fft.setRangeStartDate(DatatypeFactory.newInstance()
933 .newXMLGregorianCalendar(rangeStartDate.YEAR, rangeStartDate.MONTH, rangeStartDate.DAY_OF_WEEK, rangeStartDate.HOUR, rangeStartDate.MINUTE, rangeStartDate.SECOND, rangeStartDate.MILLISECOND, rangeStartDate.ZONE_OFFSET));
934 fft.setRangeStartDate(DatatypeFactory.newInstance()
935 .newXMLGregorianCalendar(rangeEndDate.YEAR, rangeEndDate.MONTH, rangeEndDate.DAY_OF_WEEK, rangeEndDate.HOUR, rangeEndDate.MINUTE, rangeEndDate.SECOND, rangeEndDate.MILLISECOND, rangeEndDate.ZONE_OFFSET));
936 /*currField.setRangeEndDate(DatatypeFactory.newInstance()
937 .newXMLGregorianCalendar(end));*/
938 } catch (DatatypeConfigurationException ex) {
942 fft.setRangeStartDateSQL(rangeStartDateSQL);
943 fft.setRangeEndDateSQL(rangeEndDateSQL);
944 if (nvl(comment).length() > 0)
945 fft.setComment(comment);
947 String fieldId = null;
948 boolean idExists = true;
949 for (int i = 1; idExists; i++) {
952 if (getFormFieldList() != null)
953 for (Iterator iter = getFormFieldList().getFormField().iterator(); iter
955 if (fieldId.equals(((FormFieldType) iter.next()).getFieldId())) {
960 fft.setFieldId(fieldId);
962 if (getFormFieldList() == null) {
963 FormFieldList formFieldList = objFactory.createFormFieldList();
964 setFormFieldList(formFieldList);
967 getFormFieldList().getFormField().add(fft);
969 } // addFormFieldType
971 //addCustomizedTextForParameters
972 public void addCustomizedTextForParameters(String comment) throws RaptorException {
973 getFormFieldList().setComment(comment);
976 public FormFieldType addFormFieldBlank(ObjectFactory objFactory) throws RaptorException {
977 FormFieldType fft = null;
978 fft = objFactory.createFormFieldType();
980 fft.setFieldName("BLANK");
982 fft.setFieldType(FormField.FFT_BLANK);
983 fft.setOrderBySeq((getFormFieldList() == null) ? 1 : getFormFieldList().getFormField()
985 String fieldId = null;
986 boolean idExists = true;
987 for (int i = 1; idExists; i++) {
990 if (getFormFieldList() != null)
991 for (Iterator iter = getFormFieldList().getFormField().iterator(); iter
993 if (fieldId.equals(((FormFieldType) iter.next()).getFieldId())) {
998 fft.setFieldId(fieldId);
1000 if (getFormFieldList() == null) {
1001 FormFieldList formFieldList = objFactory.createFormFieldList();
1002 setFormFieldList(formFieldList);
1005 getFormFieldList().getFormField().add(fft);
1007 } // addFormFieldBlank
1009 public void replaceFormFieldReferences(String fieldName, String replaceWith) {
1010 if (fieldName.equals(replaceWith))
1013 for (Iterator iter = getAllColumns().iterator(); iter.hasNext();) {
1014 DataColumnType dct = (DataColumnType) iter.next();
1016 if (dct.isCalculated() && dct.getColName().indexOf(fieldName) >= 0)
1017 dct.setColName(Utils.replaceInString(dct.getColName(), fieldName, nvl(
1018 replaceWith, "NULL")));
1020 if (dct.getColFilterList() != null)
1021 for (Iterator iter2 = dct.getColFilterList().getColFilter().iterator(); iter2
1023 ColFilterType cft = (ColFilterType) iter2.next();
1025 if (nvl(cft.getArgType()).equals(AppConstants.AT_FORM)
1026 && nvl(cft.getArgValue()).equals(fieldName))
1027 cft.setArgValue(replaceWith);
1030 } // replaceFormFieldReferences
1032 public void deleteFormField(String fieldId) {
1033 String fieldDisplayName = null;
1035 int orderBySeq = Integer.MAX_VALUE;
1036 if (getFormFieldList() != null)
1037 for (Iterator iter = getFormFieldList().getFormField().iterator(); iter.hasNext();) {
1038 FormFieldType fft = (FormFieldType) iter.next();
1040 if (fieldId.equals(fft.getFieldId())) {
1041 //orderBySeq = fft.getOrderBySeq();
1042 fieldDisplayName = getFormFieldDisplayName(fft);
1044 } else if (fft.getOrderBySeq()!=null && (fft.getOrderBySeq().intValue() > orderBySeq))
1045 fft.setOrderBySeq(fft.getOrderBySeq() - 1);
1048 if (fieldDisplayName != null)
1049 replaceFormFieldReferences(fieldDisplayName, "");
1050 } // deleteFormField
1052 public void shiftFormFieldUp(String fieldId) {
1053 if (getFormFieldList() == null)
1056 for (int i = 0; i < getFormFieldList().getFormField().size(); i++) {
1057 FormFieldType fft = (FormFieldType) getFormFieldList().getFormField().get(i);
1059 if (fft.getFieldId().equals(fieldId) && (i > 0)) {
1060 FormFieldType prevFft = (FormFieldType) getFormFieldList().getFormField().get(
1062 prevFft.setOrderBySeq(prevFft.getOrderBySeq() + 1);
1063 fft.setOrderBySeq((fft.getOrderBySeq() == null)?0:fft.getOrderBySeq() - 1);
1065 getFormFieldList().getFormField().remove(i);
1066 getFormFieldList().getFormField().add(i - 1, fft);
1070 } // shiftFormFieldUp
1072 public void shiftFormFieldDown(String fieldId) {
1073 if (getFormFieldList() == null)
1076 for (int i = 0; i < getFormFieldList().getFormField().size(); i++) {
1077 FormFieldType fft = (FormFieldType) getFormFieldList().getFormField().get(i);
1079 if (fft.getFieldId().equals(fieldId)
1080 && (i < getFormFieldList().getFormField().size() - 1)) {
1081 FormFieldType nextFft = (FormFieldType) getFormFieldList().getFormField().get(
1083 nextFft.setOrderBySeq((nextFft.getOrderBySeq() == null)?0:nextFft.getOrderBySeq() - 1);
1084 fft.setOrderBySeq((fft.getOrderBySeq() == null)?0:fft.getOrderBySeq() + 1);
1086 getFormFieldList().getFormField().remove(i + 1);
1087 getFormFieldList().getFormField().add(i, nextFft);
1091 } // shiftFormFieldDown
1093 public static void addFormFieldPredefinedValue(ObjectFactory objFactory,
1094 FormFieldType formField, String predefinedValue) throws RaptorException {
1095 if (formField.getPredefinedValueList() == null) {
1096 PredefinedValueList predefinedValueList = objFactory.createPredefinedValueList();
1097 formField.setPredefinedValueList(predefinedValueList);
1100 if (predefinedValue.length() > 0) {
1101 formField.getPredefinedValueList().getPredefinedValue().add(predefinedValue);
1102 Collections.sort(formField.getPredefinedValueList().getPredefinedValue());
1104 } // addFormFieldPredefinedValue
1106 public static void deleteFormFieldPredefinedValue(FormFieldType formField,
1107 String predefinedValue) {
1108 if (formField != null && formField.getPredefinedValueList() != null
1109 && predefinedValue.length() > 0)
1110 for (Iterator iter = formField.getPredefinedValueList().getPredefinedValue()
1111 .iterator(); iter.hasNext();)
1112 if (predefinedValue.equals((String) iter.next())) {
1116 } // deleteFormFieldPredefinedValue
1118 /** ************************************************************************************************* */
1120 private int curSQLParsePos = 0;
1122 private String getNextSQLParseToken(String sql, boolean updateParsePos) {
1123 int braketCount = 0;
1124 boolean isInsideQuote = false;
1125 StringBuffer nextToken = new StringBuffer();
1126 for (int idxNext = curSQLParsePos; idxNext < sql.length(); idxNext++) {
1127 char ch = sql.charAt(idxNext);
1129 if (Character.isWhitespace(ch) || ch == ',') {
1131 nextToken.append(ch);
1133 if (nextToken.length() == 0)
1135 else if (braketCount == 0 && (!isInsideQuote)) {
1137 curSQLParsePos = idxNext + ((ch == ',') ? 1 : 0);
1139 } else if (ch != ',' && nextToken.charAt(nextToken.length() - 1) != ' ')
1140 nextToken.append(' ');
1142 nextToken.append(ch);
1144 if (ch == '(' || ch == '[')
1146 else if (ch == ')' || ch == ']')
1148 else if (ch == '\''/* ||ch=='\"' */)
1149 isInsideQuote = (!isInsideQuote);
1153 return nextToken.toString();
1154 } // getNextSQLParseToken
1156 private boolean isParseSQLColID(String token) {
1157 if (nvl(token).length() == 0)
1160 for (int i = 0; i < token.length(); i++) {
1161 char ch = token.charAt(i);
1163 if (i == 0 && ch == '_')
1166 if (!(Character.isLetterOrDigit(ch) || ch == '_'))
1171 } // isParseSQLColID
1173 private DataColumnType getParseSQLDataColumn(String sqlExpression, String colId,
1174 StringBuffer parsedSQL, Vector updatedReportCols, boolean isCYMBALScript) throws RaptorException {
1175 DataColumnType dct = null;
1177 if (colId != null) {
1178 if (!isParseSQLColID(colId))
1179 throw new org.openecomp.portalsdk.analytics.error.ValidationException(
1182 + "] must either be a valid column id consisting only of letters, numbers, and underscores, or there must be a comma in front of it.");
1184 dct = getColumnById(colId);
1186 // Getting unique column id
1189 for (int i = 0; (i < sqlExpression.length()) && (colIdN < 2); i++)
1190 if (Character.isLetter(sqlExpression.charAt(i))) {
1191 colId += sqlExpression.toLowerCase().charAt(i);
1195 colIdN = getAllColumns().size() + updatedReportCols.size();
1196 for (boolean idAlreadyUsed = true; idAlreadyUsed; colIdN++) {
1197 String newColId = colId + colIdN;
1198 idAlreadyUsed = false;
1200 for (Iterator iter = getAllColumns().iterator(); iter.hasNext();)
1201 if (newColId.equals(((DataColumnType) iter.next()).getColId())) {
1202 idAlreadyUsed = true;
1207 for (Iterator iter = updatedReportCols.iterator(); iter.hasNext();)
1208 if (newColId.equals(((DataColumnType) iter.next()).getColId())) {
1209 idAlreadyUsed = true;
1214 colId += (colIdN - 1);
1218 dct = (new ObjectFactory()).createDataColumnType();
1219 dct.setColId(colId);
1220 dct.setDisplayWidth(10);
1221 dct.setDisplayAlignment("Left");
1222 dct.setVisible(true);
1223 dct.setGroupBreak(false); // ???
1224 if(!isCYMBALScript) {
1225 boolean isValidIdentifier = Character.isLetterOrDigit(sqlExpression.charAt(0));
1226 for (int i = 0; i < sqlExpression.length(); i++)
1227 if (!(Character.isLetterOrDigit(sqlExpression.charAt(i))
1228 || (sqlExpression.charAt(i) == '_') || (sqlExpression.charAt(i) == '$'))) {
1229 isValidIdentifier = false;
1233 if (isValidIdentifier) {
1234 dct.setDisplayName(sqlExpression);
1236 dct.setDisplayName(colId);
1238 } else dct.setDisplayName(colId);
1241 sqlExpression = sqlExpression.replaceAll(", '", ",'");
1242 dct.setDbColName(sqlExpression);
1243 dct.setColName(sqlExpression);
1244 dct.setCalculated(true);
1245 dct.setColType(AppConstants.CT_CHAR);
1246 dct.setDbColType(AppConstants.CT_CHAR);
1247 adjustColumnType(dct); // ???
1248 if(!isCYMBALScript) {
1249 if (parsedSQL.toString().equals("SELECT ")
1250 || parsedSQL.toString().equals("SELECT DISTINCT "))
1251 parsedSQL.append("\n\t");
1253 parsedSQL.append(", \n\t");
1254 parsedSQL.append(sqlExpression);
1255 parsedSQL.append(" ");
1256 parsedSQL.append(colId);
1260 } // getParseSQLDataColumn
1262 public void parseReportSQL(String sql) throws RaptorException {
1263 StringBuffer parsedSQL = new StringBuffer();
1265 Vector updatedReportCols = new Vector();
1268 int lastParsePos = curSQLParsePos;
1269 String lastToken = null;
1270 String nextToken = getNextSQLParseToken(sql, true);
1272 String dbInfo = getDBInfo();
1273 boolean isCYMBALScript = false;
1274 if (!isNull(dbInfo) && (!dbInfo.equals(AppConstants.DB_LOCAL))) {
1276 org.openecomp.portalsdk.analytics.util.RemDbInfo remDbInfo = new org.openecomp.portalsdk.analytics.util.RemDbInfo();
1277 String dbType = remDbInfo.getDBType(dbInfo);
1278 if (dbType.equals("DAYTONA") && !(nextToken.toUpperCase().equals("SELECT"))) {
1279 isCYMBALScript = true;
1281 } catch (Exception ex) {
1282 throw new RaptorException(ex);
1285 if ( isCYMBALScript == false ) {
1286 while (nextToken.length() > 0) {
1287 if (parsedSQL.length() == 0) {
1288 if (nextToken.toUpperCase().equals("SELECT"))
1289 parsedSQL.append("SELECT ");
1291 throw new org.openecomp.portalsdk.analytics.error.ValidationException(
1292 "The SQL must start with the SELECT keyword.");
1293 } else if (nextToken.toUpperCase().equals("DISTINCT")
1294 && parsedSQL.toString().equals("SELECT ")) {
1295 parsedSQL.append("DISTINCT ");
1296 } else if (nextToken.equals("*")
1297 && (parsedSQL.toString().equals("SELECT ") || parsedSQL.toString().equals(
1298 "SELECT DISTINCT "))) {
1299 throw new org.openecomp.portalsdk.analytics.error.ValidationException(
1300 "You cannot use \"SELECT *\". Please specify select columns/expressions.");
1301 } else if (nextToken.toUpperCase().equals("FROM")) {
1302 if (lastToken != null) {
1303 updatedReportCols.add(getParseSQLDataColumn(lastToken, null, parsedSQL,
1304 updatedReportCols, false));
1308 parsedSQL.append(" \n");
1309 while (lastParsePos < sql.length()
1310 && Character.isWhitespace(sql.charAt(lastParsePos)))
1312 parsedSQL.append(sql.substring(lastParsePos));
1315 if (nextToken.charAt(nextToken.length() - 1) == ',') {
1316 // The token ends with ,
1317 nextToken = nextToken.substring(0, nextToken.length() - 1);
1319 if (nextToken.length() == 0) {
1320 if (lastToken != null) {
1321 updatedReportCols.add(getParseSQLDataColumn(lastToken, null,
1322 parsedSQL, updatedReportCols, false));
1324 } // else just comma => ignore it
1326 if (lastToken != null) {
1327 updatedReportCols.add(getParseSQLDataColumn(lastToken, nextToken,
1328 parsedSQL, updatedReportCols, false));
1331 updatedReportCols.add(getParseSQLDataColumn(nextToken, null,
1332 parsedSQL, updatedReportCols, false));
1335 // The token doesn't end with ,
1336 if (lastToken == null)
1337 lastToken = nextToken;
1339 String token = getNextSQLParseToken(sql, false);
1340 if (!token.toUpperCase().equals("FROM"))
1341 throw new org.openecomp.portalsdk.analytics.error.ValidationException(
1342 "|FROM keyword or a comma expected after [" + nextToken
1345 updatedReportCols.add(getParseSQLDataColumn(lastToken, nextToken,
1346 parsedSQL, updatedReportCols, false));
1352 lastParsePos = curSQLParsePos;
1353 nextToken = getNextSQLParseToken(sql, true);
1355 } else { // if CYMBAL Script
1358 Matcher matcher = null;
1359 String extracted = null;
1360 nextToken = getNextCYMBALSQLParseToken(sql,true);
1361 while (nextToken.length() > 0) {
1362 if (lastToken == null) lastToken = nextToken;
1364 if( lastToken.toUpperCase().startsWith("DO DISPLAY")) {
1365 re = Pattern.compile("each(.*)\\[.(.*?)\\]"); //\\[(.*?)\\]
1366 matcher = re.matcher(nextToken);
1367 if (matcher.find()) {
1368 extracted = matcher.group();
1369 re = Pattern.compile("\\[(.*?)\\]");
1370 matcher = re.matcher(nextToken);
1371 if(matcher.find()) {
1372 extracted = matcher.group();
1373 extracted = extracted.substring(1,extracted.length()-1);
1374 StringTokenizer sToken = new StringTokenizer(extracted, ",");
1375 while(sToken.hasMoreTokens()) {
1376 String str1 = sToken.nextToken().trim().substring(1);
1377 updatedReportCols.add(getParseSQLDataColumn("", str1,
1378 new StringBuffer(""), updatedReportCols, true));
1385 lastToken = nextToken;
1386 nextToken = getNextCYMBALSQLParseToken(sql, true);
1390 if (updatedReportCols.size() == 0)
1391 throw new org.openecomp.portalsdk.analytics.error.ValidationException(
1392 "The SQL statement must have at least one column in the SELECT clause.");
1393 if (getDataSourceList().getDataSource().size() == 0)
1394 addDataSourceType(new ObjectFactory(), "du0", "DUAL", "", "DUAL", null, null, null);
1395 DataSourceType dst = (DataSourceType) getDataSourceList().getDataSource().get(0);
1396 dst.getDataColumnList().getDataColumn().clear();
1398 for (int i = 0; i < updatedReportCols.size(); i++) {
1399 DataColumnType dct = (DataColumnType) updatedReportCols.get(i);
1400 dct.setTableId(dst.getTableId());
1401 dct.setOrderSeq(i + 1);
1402 dst.getDataColumnList().getDataColumn().add(dct);
1404 setReportSQL(parsedSQL.toString());
1408 private String getNextCYMBALSQLParseToken(String sql, boolean updateParsePos) {
1409 int braketCount = 0;
1410 boolean isInsideQuote = false;
1411 StringBuffer nextToken = new StringBuffer();
1412 for (int idxNext = curSQLParsePos; idxNext < sql.length(); idxNext++) {
1413 char ch = sql.charAt(idxNext);
1416 nextToken.append(ch);
1418 curSQLParsePos = idxNext;
1421 curSQLParsePos = idxNext+1;
1426 return nextToken.toString();
1427 } // getNextSQLParseToken
1429 public void addChartAdditionalOptions(ObjectFactory objFactory) throws RaptorException {
1430 ChartAdditionalOptions chartOptions = objFactory.createChartAdditionalOptions();
1431 cr.setChartAdditionalOptions(chartOptions);
1434 public void addChartDrillOptions(ObjectFactory objFactory) throws RaptorException {
1435 ChartDrillOptions chartOptions = objFactory.createChartDrillOptions();
1436 cr.setChartDrillOptions(chartOptions);
1439 public void addDataminingOptions(ObjectFactory objFactory) throws RaptorException {
1440 DataminingOptions dataminingOptions = objFactory.createDataminingOptions();
1441 cr.setDataminingOptions(dataminingOptions);
1443 /*public void addChartAdditionalOptions(ObjectFactory objFactory, String chartType, String chartMultiplePieOrder, String chartMultiplePieLabelDisplay,
1444 String chartOrientation, String secondaryChartRenderer, String chartDisplay, String legendPosition,
1445 String labelAngle) throws RaptorException {
1447 ChartAdditionalOptions chartOptions = objFactory.createChartAdditionalOptions();
1449 if (nvl(chartMultiplePieOrder).length() > 0)
1450 chartOptions.setChartMultiplePieOrder(chartMultiplePieOrder);
1451 if (nvl(chartMultiplePieLabelDisplay).length() > 0)
1452 chartOptions.setChartMultiplePieLabelDisplay(chartMultiplePieLabelDisplay);
1453 if (nvl(chartOrientation).length() > 0)
1454 chartOptions.setChartOrientation(chartOrientation);
1455 if (nvl(secondaryChartRenderer).length() > 0)
1456 chartOptions.setSecondaryChartRenderer(secondaryChartRenderer);
1457 if (nvl(chartDisplay).length() > 0)
1458 chartOptions.setChartDisplay(chartDisplay);
1459 if (nvl(legendPosition).length() > 0)
1460 chartOptions.setLegendPosition(legendPosition);
1461 if (nvl(labelAngle).length() > 0)
1462 chartOptions.setLabelAngle(labelAngle);
1464 cr.setChartAdditionalOptions(chartOptions);
1465 } catch (JAXBException ex) {
1466 throw new RaptorException(ex.getMessage(), ex.getCause());
1468 } // addChartAdditionalOptions*/
1471 } // ReportDefinition