From 6beb446925c967aca92f5513adf36c5db77c00d6 Mon Sep 17 00:00:00 2001 From: TATTAVARADA Date: Thu, 27 Apr 2017 07:53:18 -0400 Subject: [PORTAL-7] Rebase This rebasing includes common libraries and common overlays projects abstraction of components Change-Id: Ia1efa4deacdc5701e6205104ac021a6c80ed60ba Signed-off-by: st782s --- .../portalsdk/analytics/util/AppConstants.java | 667 +++++++++++++++++++++ .../portalsdk/analytics/util/DataSet.java | 177 ++++++ .../portalsdk/analytics/util/ExcelColorDef.java | 65 ++ .../portalsdk/analytics/util/HtmlStripper.java | 157 +++++ .../openecomp/portalsdk/analytics/util/Log.java | 40 ++ .../portalsdk/analytics/util/RemDbInfo.java | 93 +++ .../portalsdk/analytics/util/SQLCorrector.java | 343 +++++++++++ .../portalsdk/analytics/util/Scheduler.java | 91 +++ .../openecomp/portalsdk/analytics/util/Utils.java | 372 ++++++++++++ .../portalsdk/analytics/util/XSSFilter.java | 91 +++ .../portalsdk/analytics/util/jar/ExtractJar.java | 237 ++++++++ .../analytics/util/upgrade/SystemUpgrade.java | 127 ++++ 12 files changed, 2460 insertions(+) create mode 100644 ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/AppConstants.java create mode 100644 ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/DataSet.java create mode 100644 ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/ExcelColorDef.java create mode 100644 ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/HtmlStripper.java create mode 100644 ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/Log.java create mode 100644 ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/RemDbInfo.java create mode 100644 ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/SQLCorrector.java create mode 100644 ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/Scheduler.java create mode 100644 ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/Utils.java create mode 100644 ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/XSSFilter.java create mode 100644 ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/jar/ExtractJar.java create mode 100644 ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/upgrade/SystemUpgrade.java (limited to 'ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util') diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/AppConstants.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/AppConstants.java new file mode 100644 index 00000000..7728e99e --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/AppConstants.java @@ -0,0 +1,667 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file 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. + * ================================================================================ + */ +package org.openecomp.portalsdk.analytics.util; + +import java.awt.Color; + +import org.openecomp.portalsdk.analytics.model.base.*; + +/**
+ * This class is part of RAPTOR (Rapid Application Programming Tool for OLAP Reporting)
+ *
+ * + * --------------------------------------------------------------------------------------------------
+ * AppConstants.java - This class holds almost all shareable constants for RAPTOR. + * --------------------------------------------------------------------------------------------------
+ * + * + * Change Log

+ * + * 27-Jul-2009 : Version 8.4 (Sundar); + * 14-Jul-2009 : Version 8.4 (Sundar); + * 29-Jun-2009 : Version 8.4 (Sundar); + * 22-Jun-2009 : Version 8.4 (Sundar); + * + */ + +public class AppConstants { + // Session attribute IDs + public final static String SI_BACKUP_FOR_REP_ID = "backup_for_report_id"; + public final static String SI_DASHBOARD_REP_ID = "dashboard_report_id"; + public final static String SI_DASHBOARD_REPORTRUNTIME_MAP = "dashboardReportRuntimeMap"; + public final static String SI_DASHBOARD_REPORTDATA_MAP = "dashboardReportDataMap"; + public final static String SI_DASHBOARD_CHARTDATA_MAP = "dashboardChartDataMap"; + public final static String SI_DASHBOARD_DISPLAYTYPE_MAP = "dashboardDisplayTypeMap"; + public final static String SI_DASHBOARD_REPORTRUNTIME = "dashboardRuntime"; + public final static String EMBEDDED_REPORTRUNTIME_MAP = "embeddedReportRuntimeMap"; + public final static String EMBEDDED_REPORTDATA_MAP = "embeddedReportDataMap"; + + public final static String DRILLDOWN_INDEX = "drilldown_index"; + public final static String FORM_DRILLDOWN_INDEX = "form_drilldown_index"; + + public final static String DRILLDOWN_REPORTS_LIST = "drilldownReportsList"; + + public final static String SI_REPORT_RUN_BACKUP = "report_runtime_backup"; + + public final static String SI_REPORT_RUNTIME = "report_runtime"; + + public final static String SI_FORMFIELD_INFO = "formfield_info"; + + public final static String SI_FORMFIELD_DOWNLOAD_INFO = "formfield_download_info"; + + public final static String SI_REPORT_DEFINITION = "report_definition"; + + public final static String SI_DATA_SIZE_FOR_TEXTFIELD_POPUP = "dataSizeForPopUp"; + + public final static String SI_MAP_OBJECT = "novamap"; + + public final static String SI_MAP = "raptorMap"; + + // Added for Adhoc Scheduling + public final static String SI_REPORT_SCHEDULE = "report_schedule"; + + public final static String SI_COLUMN_LOOKUP = "column_lookup"; + + // Request attribute IDs + public final static String RI_ACTION = "r_action"; + + public final static String RI_JAVASCRIPT_ITEM_ID = "javascriptItemId"; + + // added for form field chaining in schedule tab + public final static String SCHEDULE_ACTION = "N"; + + public final static String RI_REFRESH = "refresh"; + + public final static String RI_EXCEPTION = "c_exception"; + + public final static String RI_ERROR_LIST = "c_error_list"; + + public final static String RI_REPORT_ID = "c_master"; // should be + // reportID not + // c_master + public final static String RI_DASHBOARD_ID = "c_dashboard"; + + public final static String RI_DETAIL_ID = "c_detail"; // should be + // detailID not + // c_detail + + public final static String RI_REPORT_DATA = "report_data"; + + public final static String RI_REPORT_DATA_WHOLE = "report_data_whole"; + + public final static String RI_REPORT_SQL_WHOLE = "report_sql_whole"; + + public final static String RI_CHART_DATA = "chart_data"; + + public final static String RI_CHART_FORECAST_DATA = "chart_forecast_data"; + + public final static String RI_CHART_TOTAL_COL = "chart_total"; // to show sub-totals + + public final static String RI_CHART_COLOR = "chart_color"; // to specify colors + + public final static String RI_CHART_INCLUDE = "chart_include"; // + + public final static String RI_CHART_MARKER_START = "chart_marker_start"; //marker line + + public final static String RI_CHART_MARKER_END = "chart_marker_end"; //marker line + + public final static String RI_CHART_MARKER_TEXT_LEFT = "chart_marker_text_left"; //marker line + + public final static String RI_CHART_MARKER_TEXT_RIGHT = "chart_marker_text_right"; //marker line + + public final static String RI_ANOMALY_TEXT = "anomaly_text"; //marker line + + public final static String RI_JAVASCRIPT = "javascriptElement"; + + public final static String RI_PAGE_TITLE = "title"; + + public final static String RI_PAGE_SUBTITLE = "subtitle"; + + public final static String RI_NEXT_PAGE = "r_page"; + + public final static String RI_PAGE_SIZE = "r_page_size"; + + public final static String RI_RECORD_NO = "r_record"; + + public final static String RI_NEXT_PAGE_SET = "r_page_set"; + + public final static String RI_DATA_SIZE = "r_data_size"; + + public final static String RI_SORT_ORDER = "sort_order"; + + public final static String RI_USER_REPORTS = "user_reports"; + + public final static String RI_PUBLIC_REPORTS = "public_reports"; + + public final static String RI_FAVORITE_REPORTS = "favorite_reports"; + + public final static String RI_F_REPORT_ID = "f_report_id"; + + public final static String RI_F_REPORT_NAME = "f_report_name"; + + public final static String RI_F_REPORT_CREATE_DATE = "f_report_create_date"; + + public final static String RI_F_PUBLIC = "f_public"; + + public final static String RI_F_OWNER_ID = "f_owner_id"; + + public final static String RI_SEARCH_RESULT = "search_result"; + + public final static String RI_JS_TARGET_FIELD = "js_target_field"; + + public final static String RI_FIELD_NAME = "field_name"; + + public final static String RI_COLUMN_ID = "column_id"; + + public final static String RI_ARG_TYPE = "arg_type"; + + public final static String RI_VIEW_ACTION = "view_action"; + + public final static String RI_SOURCE_PAGE = "source_page"; + + public final static String RI_GO_TO_STEP = "go_to_step"; + + public final static String RI_WIZARD_ACTION = "wizard_action"; + + public final static String RI_FORMATTED_SQL = "formatted_sql"; + + public final static String RI_DATA_SET = "data_set"; + + public final static String RI_FORM_FIELDS = "form_fields"; + + public final static String RI_DISPLAY_CONTENT = "display_content"; + + public final static String RI_SHOW_BACK_BTN = "show_back_btn"; + + public final static String RI_GO_BACK = "go_back"; + + public final static String RI_RESET_PARAMS = "reset_params"; + + public final static String RI_RESET_ACTION = "reset_action"; + + public final static String RI_VISUAL_ACTION = "v_action"; + + public final static String RI_SEARCH_STRING = "search_string"; + + public final static String RI_CONTAIN_FLAG = "contain_flag"; + + public final static String RI_TABLE_NAME = "table_name"; + + public final static String RI_DISPLAY_CHART = "display_chart"; + + public final static String RI_CHK_FIELD_SQL = "check_field_sql"; + + public final static String RI_EDIT_LINK = "edit_link"; + + public final static String RI_SCHEDULE_LINK = "schedule_link"; + + public final static String RI_LIST_CATEGORY = "raptor_list_category"; + + public final static String RI_SCHEDULE_ID = "c_schedule"; // should be + // reportID not + // c_master + public final static String RI_TEXTFIELD_POP = "forTextFieldPopUp"; // should be + + + // Visualization actions + public final static String VA_SHOW = "Show"; + + public final static String VA_HIDE = "Hide"; + + public final static String VA_SORT = "Sort"; + + public final static String HIDDEN = "Hidden"; + + // Wizard steps + public final static String WS_DEFINITION = "Definition"; + + public final static String WS_TABLES = "Tables"; + + public final static String WS_SQL = "SQL"; + + public final static String WS_COLUMNS = "Columns"; + + public final static String WS_FORM_FIELDS = "Form Fields"; + + public final static String WS_FILTERS = "Filters"; + + public final static String WS_JAVASCRIPT = "Javascript"; + + public final static String WS_SORTING = "Sorting"; + + public final static String WS_CHART = "Chart"; + + public final static String WS_USER_ACCESS = "Security"; + + public final static String WS_DATA_FORECASTING = "Forecasting"; + + public final static String WS_SCHEDULE = "Schedule"; + + public final static String WS_REPORT_LOG = "Log"; + + public final static String WS_RUN = "Run"; + + /*****for report map******/ + public final static String WS_MAP = "Map"; + + + + // Wizard sub-steps + public final static String WSS_ADD = "Add"; + + public final static String WSS_ADD_MULTI = "Add Multiple"; + + public final static String WSS_ORDER_ALL = "Re-order All"; + + public final static String WSS_EDIT = "Edit"; + + public final static String WSS_DELETE = "Delete"; + + public final static String WSS_ADD_BLANK = "Add Blank"; + + public final static String WSS_INFO_BAR = "Display parameters"; + + // Wizard actions + public final static String WA_NEXT = "Next"; + + public final static String WA_BACK = "Back"; + + public final static String WA_ADD = "Add"; + + public final static String WA_ADD_MULTI = "Add Multiple"; + + public final static String WA_ORDER_ALL = "Re-order All"; + + public final static String WA_EDIT = "Edit"; + + public final static String WA_MODIFY = "Modify"; + + public final static String WA_DELETE = "Delete"; + + public final static String WA_SAVE = "Save"; + + public final static String WA_MOVE_UP = "Move Up"; + + public final static String WA_MOVE_DOWN = "Move Down"; + + public final static String WA_ADD_USER = "Add User"; + + public final static String WA_DELETE_USER = "Delete User"; + + public final static String WA_GRANT_USER = "Grant User Access"; + + public final static String WA_REVOKE_USER = "Revoke User Access"; + + public final static String WA_ADD_ROLE = "Add Role"; + + public final static String WA_DELETE_ROLE = "Delete Role"; + + public final static String WA_GRANT_ROLE = "Grant Role Access"; + + public final static String WA_REVOKE_ROLE = "Revoke Role Access"; + + public final static String WA_VALIDATE = "Validate"; + + // File types + public final static String FT_ZIP = ".zip"; + public final static String FT_TXT = ".txt"; + public final static String FT_DAT = ".dat"; + public final static String FT_CSV = ".csv"; + public final static String FT_XLS = ".xls"; + public final static String FT_XLS_ALL = "_all.xls"; + + public final static String FT_CSV_ALL = "_all.csv"; + + + public final static String FT_XML = ".xml"; + + public final static String FT_SQL = ".sql"; + public final static String FT_COLUMNS = ".head"; + + public final static String FILE_PREFIX = "cr_"; + + // Chart types + public final static String GT_BAR_3D = "BarChart3D"; + + public final static String GT_HORIZ_BAR = "HorizontalBarChart"; + + public final static String GT_STACKED_HORIZ_BAR = "HorizontalStackedBarChart"; + + public final static String GT_STACKED_VERT_BAR = "VerticalStackedBarChart"; + + public final static String GT_STACKED_HORIZ_BAR_LINES = "HorizontalStackedBarLinesChart"; + + public final static String GT_STACKED_VERT_BAR_LINES = "VerticalStackedBarLinesChart"; + + public final static String GT_VERT_BAR = "VerticalBarChart"; + + public final static String GT_TOTAL_BAR = "TotalBarChart"; + + public final static String GT_PIE_3D = "Pie3DChart"; + + public final static String GT_PIE = "PieChart"; + + public final static String GT_PIE_MULTIPLE = "MultiplePieChart"; + + public final static String GT_TIME_SERIES = "TimeSeriesChart"; + + public final static String GT_LINE = "LineChart"; + + public final static String GT_SCATTER = "ScatterPlotChart"; + + public final static String GT_HIERARCHICAL = "HierarchicalChart"; + + public final static String GT_HIERARCHICAL_SUNBURST = "HierarchicalSunBurstChart"; + + public final static String GT_REGRESSION = "RegressionPlotChart"; + + public final static String GT_BAR_LINES = "BarLinesChart"; + + public final static String GT_MULTI_SERIES_CHART = "MultiSeriesChart"; + + public final static String GT_PARETO_CHART = "ParetoChart"; + + public final static String GT_MULTIPLE_TIMESERIES_CHART = "MultipleTimeSeriesChart"; + + public final static String GT_TIME_DIFFERENCE_CHART = "TimeDifferenceChart"; + + public final static String GT_COMPARE_PREVYEAR_CHART = "CompareToPrevYear"; + + public final static String GT_ANNOTATION_CHART = "AnnotationChart"; + + public final static String GT_FLEX_TIME_CHARTS = "FlexTimeChart"; + + // Non-standard chart types + public final static String GT_MTD_BAR = "MTDBarChart"; + + // JFree latest version only chart type + public final static String GT_METER = "MeterChart"; + + public final static String GT_STACK_BAR = "StackedBarChart"; + + public static Color GREEN_COLOR = new Color(0, 128, 0); + + // chart filter + public final static int CHART_ALL_COLUMNS = 0; + public final static int CHART_WITHOUT_NEWCHART_COLUMNS = 1; + public final static int CHART_NEWCHART_COLUMNS = 2; + + // chart colors + public static Color[] CHART_SERIES_COLORS = { Color.black, GREEN_COLOR, Color.red, + Color.blue, Color.magenta, Color.orange, Color.cyan, Color.pink, Color.yellow }; + + // Chart columns + public final static String GC_LEGEND = "LEGEND"; + + /* Datamining Constants */ + public final static String DM_DATE_ATTR = "DM_DATE_ATTR"; + public final static String DM_FORECASTING_ATTR = "DM_FORECAST_ATTR"; + public final static String DM_GAUSSIAN_CLASSIFIER = "GAUSSIAN"; + public final static String DM_SVM_CLASSIFIER = "SVM"; + + // Schedule recurrence + + public final static String SR_ONETIME = "ONE_TIME"; + public final static String SR_HOURLY = "HOURLY"; + + public final static String SR_DAILY = "DAILY"; + + public final static String SR_DAILY_MO_FR = "DAILY_MO_FR"; + + public final static String SR_WEEKLY = "WEEKLY"; + + public final static String SR_MONTHLY = "MONTHLY"; + + // User access type + public final static String UA_READ = "read"; + + public final static String UA_WRITE = "write"; + + public final static String UA_DELETE = "delete"; + + // Semaphore Type + public static final String ST_ROW = "ROW"; + + public static final String ST_CELL = "CELL"; + + // Sort Order + public static final String SO_ASC = "ASC"; + + public static final String SO_DESC = "DESC"; + + // Report Log Action + public static final String RLA_CREATE = "Report Created"; + + public static final String RLA_UPDATE = "Report Updated"; + + public static final String RLA_DELETE = "Report Deleted"; // Not used + + public static final String RLA_RUN = "Report Run"; + + public static final String RLA_EXECUTION_TIME = "Report Execution Time"; + + public static final String RLA_SCHEDULED_DOWNLOAD_EXCEL = "Scheduled and Generated in Excel"; + + public static final String RLA_SCHEDULED_DOWNLOAD_PDF = "Scheduled and Generated in PDF"; + + public static final String RLA_DOWNLOAD_EXCEL = "Generated in Excel"; + + public static final String RLA_DOWNLOAD_PAGE_EXCEL = "Generated in Excel for the current Page"; + + public static final String RLA_DOWNLOAD_EXCELX = "Generated in Excel 2007"; + + public static final String RLA_SCHEDULED_DOWNLOAD_EXCELX = "Scheduled and Generated in Excel 2007"; + + public static final String RLA_DOWNLOAD_PDF = "Generated in PDF"; + + public static final String RLA_DOWNLOAD_CSV = "Generated in CSV"; + + public static final String RLA_DOWNLOAD_TEXT = "Generated in TEXT"; + + public static final String RLA_ERROR = "Error Occurred"; + + public static final String RLA_FROM_LOG = "From Log List"; + + // Drill-down extra date columns extension + public static final String DD_COL_EXTENSION = "_dde"; + + // Column "don't attempt to parse as date" flag - currently placed in the + // comment + public static final String CF_NO_PARSE_DATE = "NO_PARSE_DATE"; + + /** + * *************** Transferred from CustomReportWrapper + * ********************* + */ + + // Default Oracle date format + public static final String DEFAULT_DATE_FORMAT = "%m/%d/%Y"; + + // Java date formats + public static final String JAVA_DATE_FORMAT_MMDDYYYY = "MM/dd/yyyy"; + + public static final String JAVA_DATE_FORMAT_MMDDYYYY_HR = "MM/dd/yyyy hh aaa" ; //01-SEP-2013 00 AM + + public static final String JAVA_DATE_FORMAT_MMYYYY = "MM/yyyy"; + + public static final String JAVA_DATE_FORMAT_DDMONYYYY = "dd-MMM-yyyy"; + + public static final String JAVA_DATE_FORMAT_DDMONYYYY_HR = "dd-MMM-yyyy hh aaa" ; //01-SEP-2013 00 AM + + public static final String JAVA_DATE_FORMAT_MONTHDDYYYY = "MMMMMMMM dd, yyyy"; + + public static final String JAVA_DATE_FORMAT_MONTHYYYY = "MMMMMMMM, yyyy"; + + // Filter predefined values + public static final String FILTER_MAX_VALUE = "[MAX_VALUE]"; // Max value + // in that + // database + // column + + public static final String FILTER_MIN_VALUE = "[MIN_VALUE]"; // Min value + // in that + // database + // column + + // Column type constants + public static final String CT_CHAR = "VARCHAR2"; + + public static final String CT_NUMBER = "NUMBER"; + + public static final String CT_DATE = "DATE"; + + public static final String CT_HYPERLINK = "HYPERLINK"; + + public static final String CT_TIMESTAMP = "TIMESTAMP"; + + // Filter argument type constants + public static final String AT_FORMULA = "FORMULA"; // Exact expression - + // can be anything as + // long as fits in the + // SQL statement + + public static final String AT_VALUE = "VALUE"; // Constant value - example + // 35 or Amsterdam or + // 11/25/2004 + + public static final String AT_LIST = "LIST"; // List of constant value - + // must include formatting - + // like 'a','b' or + // TO_DATE('11/11/2001','MM/DD/YYYY'),TO_DATE('02/11/2001','MM/DD/YYYY') + + public static final String AT_COLUMN = "COLUMN"; // Column id of one of + // the columns in the + // report + + public static final String AT_FORM = "FORM"; // To be inserted in a form + // before running the report + + // Report type constants + public static final String RT_LINEAR = "Linear"; + + public static final String RT_CROSSTAB = "Cross-Tab"; + + public static final String RT_DASHBOARD = "Dashboard"; + public static final String RT_HIVE = "Hive"; + + // Report definition type constants + public static final String RD_VISUAL = "Visual"; + + public static final String RD_SQL_BASED = "SQL-based"; + + public static final String RD_SQL_BASED_DATAMIN = "SQL-based_Datamining"; + + // Column cross-tab position + public static final String CV_ROW = "ROW"; + + public static final String CV_COLUMN = "COLUMN"; + + public static final String CV_VALUE = "VALUE"; + + // Outer join type constants + public static final String OJ_CURRENT = "CURRENT"; // cur_table (+) = + // join_table + + public static final String OJ_JOINED = "JOINED"; // cur_table = + // join_table (+) + + // JFree versions + public static final String JFV_0911 = "0.9.11"; + + public static final String JFV_LATEST = "latest"; + + // List of Available Total Functions + public static final String TOTAL_SUM_ID = "SUM("; + + public static IdNameList TOTAL_FUNCTIONS = new IdNameList(); + + public static final String DB_LOCAL = "local"; + + public static final String DB_DEV = "dev"; + + public static final String DB_PROD = "prod"; + + public static final String SHELL_SCRIPT_NAME = "dwnldflatfile.sh"; + + public static final String SCHEDULE_SHELL_SCRIPT_NAME = "dwnldflatfileschedule.sh"; + + public static final String SHELL_QUERY_DIR = "query/"; + + public static final String SHELL_SCRIPTS_DIR = "scripts/"; + + public static final String SHELL_DATA_DIR = "data/"; + + public static final int WEB_VERSION = 0; + + public static final int IPHONE_VERSION = 1; + + public static final String MYSQL = "mysql"; + public static final String ORACLE = "oracle"; + public static final String POSTGRESQL = "postgresql"; + + // COLORS to be used in Excel + public static String Aqua = "#00FFFF"; + public static String Black = "#000000"; + public static String Blue = "#0000FF"; + public static String Fuchsia = "#FF00FF"; + public static String Gray = "#808080"; + public static String Green = "#008000"; + public static String Lime = "#00FF00"; + public static String Maroon = "#800000"; + public static String Navy = "#000080"; + public static String Olive = "#808000"; + public static String Orange = "#FF9900"; + public static String Purple = "#800080"; + public static String Red = "#FF0000"; + public static String Silver = "#C0C0C0"; + public static String Teal = "#008080"; + public static String White = "#FFFFFF"; + public static String Yellow = "#FFFF00"; + // End + public static void initializeAppConstants() { + // Initialize TOTAL_FUNCTIONS + if (TOTAL_FUNCTIONS.getCount() == 0) { + TOTAL_FUNCTIONS.addValue(TOTAL_SUM_ID, "Sum"); + TOTAL_FUNCTIONS.addValue("MAX(", "Max"); + TOTAL_FUNCTIONS.addValue("MIN(", "Min"); + TOTAL_FUNCTIONS.addValue("COUNT(ALL ", "Count All"); + TOTAL_FUNCTIONS.addValue("COUNT(DISTINCT ", "Count Distinct"); + TOTAL_FUNCTIONS.addValue("AVG(ALL ", "Average All"); + TOTAL_FUNCTIONS.addValue("AVG(DISTINCT ", "Average Distinct"); + TOTAL_FUNCTIONS.addValue("VARIANCE(ALL ", "Variance All"); + TOTAL_FUNCTIONS.addValue("VARIANCE(DISTINCT ", "Variance Distinct"); + TOTAL_FUNCTIONS.addValue("STDDEV(ALL ", "Standard Deviation All"); + TOTAL_FUNCTIONS.addValue("STDDEV(DISTINCT ", "Standard Deviation Distinct"); + TOTAL_FUNCTIONS.addValue("AVG(ALL +STDDEV(ALL ", + "Average + Standard Deviation All"); + TOTAL_FUNCTIONS.addValue("AVG(ALL +2*STDDEV(ALL ", + "Average + 2 * Standard Deviation All"); + TOTAL_FUNCTIONS.addValue("AVG(ALL -STDDEV(ALL ", + "Average - Standard Deviation All"); + TOTAL_FUNCTIONS.addValue("AVG(ALL -2*STDDEV(ALL ", + "Average - 2 * Standard Deviation All"); + } // if + + // ... + } // initializeAppConstants + +} // AppConstants + diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/DataSet.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/DataSet.java new file mode 100644 index 00000000..f0740399 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/DataSet.java @@ -0,0 +1,177 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file 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. + * ================================================================================ + */ +package org.openecomp.portalsdk.analytics.util; + +import java.io.Serializable; +import java.sql.*; +import java.util.*; + +import org.openecomp.portalsdk.analytics.system.Globals; + +public class DataSet extends Vector implements Serializable { + private Vector columnNames = null; + + private Vector columnTypes = null; + + public DataSet(ResultSet rs) throws SQLException { + this(rs, Integer.MAX_VALUE); + } // DataSet + + public DataSet(ResultSet rs, int maxRowLimit) throws SQLException { + ResultSetMetaData rsmd = rs.getMetaData(); + int mb = 1024*1024; + Runtime runtime = Runtime.getRuntime(); + + int colCount = rsmd.getColumnCount(); + columnNames = new Vector(colCount); + columnTypes = new Vector(colCount); + for (int i = 1; i <= colCount; i++) { + columnNames.add(rsmd.getColumnLabel(i)); // getColumnLabel ?? + columnTypes.add(rsmd.getColumnTypeName(i)); + } // for + + while (rs.next() && size() < maxRowLimit) { +// if(runtime.freeMemory()/mb <= ((runtime.maxMemory()/mb)*(Globals.getMemoryThreshold()*2)/100) ) { +// System.out.println("freeMemory " + runtime.freeMemory()); +// System.out.println("Max Memory " + runtime.maxMemory()); +// System.out.println("If Logic " + (runtime.freeMemory()/mb <= ((runtime.maxMemory()/mb)*(Globals.getMemoryThreshold()*2)/100))); +// break; +// } + + Vector v = new Vector(colCount); + for (int i = 1; i <= colCount; i++) + v.add(rs.getString(i)); + add(v); + } // while + + if(rs!=null) + rs.close(); + } // DataSet + + public DataSet() { + columnNames = new Vector(); + columnTypes = new Vector(); + } // DataSet + + public void insertRow(int rowIdx) { + if (rowIdx > size()) + rowIdx = size(); + + Vector v = new Vector(columnNames.size()); + for (int i = 0; i < columnNames.size(); i++) + v.add(""); + add(rowIdx, v); + } // insertRow + + public void insertColumn(int colIdx, String colName) { + insertColumn(colIdx, colName, "VARCHAR2"); + } // insertColumn + + public void insertColumn(int colIdx, String colName, String colType) { + if (colIdx > columnNames.size()) + colIdx = columnNames.size(); + + columnNames.add(colIdx, colName); + columnTypes.add(colIdx, colType); + + for (int i = 0; i < size(); i++) + ((Vector) get(i)).add(colIdx, ""); + } // insertColumn + + public void setValue(int rowIdx, int colIdx, String value) { + ((Vector) get(rowIdx)).set(colIdx, value); + } // setValue + + public void setValue(int rowIdx, String colName, String value) { + ((Vector) get(rowIdx)).set(getColumnIndex(colName), value); + } // setValue + + public void setString(int rowIdx, int colIdx, String value) { + setValue(rowIdx, colIdx, value); + } // setString + + public void setString(int rowIdx, String colName, String value) { + setValue(rowIdx, colName, value); + } // setString + + public int getRowCount() { + return size(); + } // getRowCount() + + public int getColumnCount() { + return columnNames.size(); + } // getColumnCount + + public String getColumnName(int colIdx) { + return ((String) columnNames.get(colIdx)); + } // getColumnName + + public String getColumnType(int colIdx) { + return ((String) columnTypes.get(colIdx)); + } // getColumnType + + public String getColumnType(String colName) { + return getColumnType(getColumnIndex(colName)); + } // getColumnType + + public int getColumnIndex(String colName) { + for (int i = 0; i < columnNames.size(); i++) + if (colName.equalsIgnoreCase((String) columnNames.get(i))) + return i; + + return -1; + } // getColumnIndex + + public String getString(int rowIdx, int colIdx) { + return nvl((String) ((Vector) get(rowIdx)).get(colIdx)); + } // getString + + public String getString(int rowIdx, String colName) { + return getString(rowIdx, getColumnIndex(colName)); + } // getString + + public int getInt(int rowIdx, int colIdx) { + return Integer.parseInt(getString(rowIdx, colIdx)); + } // getString + + public int getInt(int rowIdx, String colName) { + return getInt(rowIdx, getColumnIndex(colName)); + } // getString + + public String getItem(int rowIdx, int colIdx) { + return getString(rowIdx, colIdx); + } // getItem + + public String getItem(int rowIdx, String colName) { + return getString(rowIdx, colName); + } // getItem + + /** *********************************************************************** */ + + private String nvl(String s) { + return (s == null) ? "" : s; + } + + private String nvl(String s, String sDefault) { + return nvl(s).equals("") ? sDefault : s; + } + +} // DataSet + diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/ExcelColorDef.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/ExcelColorDef.java new file mode 100644 index 00000000..67370d96 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/ExcelColorDef.java @@ -0,0 +1,65 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file 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. + * ================================================================================ + */ +package org.openecomp.portalsdk.analytics.util; + + +import java.util.HashMap; + +import org.apache.poi.hssf.util.HSSFColor; + +public class ExcelColorDef { + + public static HashMap colors = new HashMap(); + + public static void initializeExcelColorDef() { + colors.put("#00FFFF",new Short(HSSFColor.AQUA.index)); + colors.put("#000000",new Short(HSSFColor.BLACK.index)); + colors.put("#0000FF",new Short(HSSFColor.BLUE.index)); + colors.put("#FF00FF",new Short(HSSFColor.PINK.index)); + colors.put("#808080",new Short(HSSFColor.GREY_40_PERCENT.index)); + colors.put("#008000",new Short(HSSFColor.BRIGHT_GREEN.index)); + colors.put("#00FF00",new Short(HSSFColor.LIME.index)); + colors.put("#800000",new Short(HSSFColor.MAROON.index)); + colors.put("#000080",new Short(HSSFColor.ROYAL_BLUE.index)); + colors.put("#808000",new Short(HSSFColor.OLIVE_GREEN.index)); + colors.put("#FF9900",new Short(HSSFColor.ORANGE.index)); + colors.put("#800080",new Short(HSSFColor.VIOLET.index)); + colors.put("#FF0000",new Short(HSSFColor.RED.index)); + colors.put("#C0C0C0",new Short(HSSFColor.CORAL.index)); + colors.put("#008080",new Short(HSSFColor.TEAL.index)); + colors.put("#FFFFFF",new Short(HSSFColor.WHITE.index)); + colors.put("#FFFF00",new Short(HSSFColor.YELLOW.index)); + + } + + public static short getExcelColor( String color) { + if ((colors != null) && (colors.containsKey(color))) { + return ((Short) colors.get(color)).shortValue(); + } + + return new Short(HSSFColor.WHITE.index).shortValue(); + } + + public static void main(String[] args) { + // TODO Auto-generated method stub + + } + +} diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/HtmlStripper.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/HtmlStripper.java new file mode 100644 index 00000000..9c76c368 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/HtmlStripper.java @@ -0,0 +1,157 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file 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. + * ================================================================================ + */ +package org.openecomp.portalsdk.analytics.util; + +import java.io.*; + +import org.openecomp.portalsdk.analytics.RaptorObject; + +public class HtmlStripper extends RaptorObject// this function can be accessed publicly +{ + + String filename; + final char TXT_END_TAG = '>'; + final char TXT_START_TAG = '<'; + + public String stripSpecialCharacters (String s) { + s = nvl(s); + StringBuffer sbuf = new StringBuffer(); + int c; + int prev_char = 0; + boolean inText = true; + for (int i = 0; i < s.length(); i++) { + // while c is not last character + c = s.charAt(i); + //System.out.println("444 Character " + (char)c + " int " + c); + if ((char) c == TXT_END_TAG) { + // if char == '>' text following + // it and not HTML tag + inText = true; + } else if ((char) c == TXT_START_TAG) { + // if char == '<' tag is + // following not text + inText = false; + } /*else if ((char)c == '\n') { + System.out.println("new line " + (char)c + " int " + c); + inText = false; + }*/ /*else if ((char) c == '&') { + // if char == '&' chars following + // are not text + inText = false; + }*/ + else if (inText) { + // if text write char to "text.txt" + //System.out.println("444444 Adding " + (char)c + " int " + c); + if (c >= 32 && c <= 122) { + if(c==32 || (c>32 && c<=47) || ( c>=58 && c<=64 )) { + if (c == 45) { + prev_char = 0; + sbuf.append((char) 45); + } + else if(prev_char != 95) { + prev_char = 95; + sbuf.append((char) 95); + } + } + else { + prev_char=0; + sbuf.append((char) c); + } + } + } + } + //System.out.println("\n\nFinished processing: " + s + "\n\n"); + //System.out.println("\n\nThe processed String : " + sbuf.toString() + "\n\n"); + return sbuf.toString(); + } + + public String stripHtml(String s) { + + //System.out.println("Starting to process: " + s + "\n\n"); // prints + s = nvl(s); + StringBuffer sbuf = new StringBuffer(); + int c; + boolean inText = true; + for (int i = 0; i < s.length(); i++) { + // while c is not last character + c = s.charAt(i); + if ((char) c == TXT_END_TAG) { + // if char == '>' text following + // it and not HTML tag + inText = true; + } else if ((char) c == TXT_START_TAG) { + // if char == '<' tag is + // following not text + inText = false; + } /*else if ((char)c == '\n') { + System.out.println("new line " + (char)c + " int " + c); + inText = false; + }*/ /*else if ((char) c == '&') { + // if char == '&' chars following + // are not text + inText = false; + }*/ + else if (inText) { + // if text write char to "text.txt" + if (c >= 32 && c <= 122) { + sbuf.append((char) c); + } + } + } + //System.out.println("\n\nFinished processing: " + s + "\n\n"); + //System.out.println("\n\nThe processed String : " + sbuf.toString() + "\n\n"); + int pos = 0 ; + while(sbuf.indexOf(" ")!=-1) { + pos = sbuf.indexOf(" "); + sbuf.replace(pos, pos+6, " "); + } + + return sbuf.toString(); + } + + + public String stripCSVHtml (String s) { + String s1 = stripHtml(s); + //s1 = Utils.replaceInString(s1, "\"", "\"\""); + s1 = s1.replaceAll("\"", "\"\""); + return s1; + } + + public static void main(String[] args) { + + String st = " Import: report name hello $ # " ; + System.out.println("hello " + new HtmlStripper().stripSpecialCharacters(st)); + StringBuffer strBuf = new StringBuffer(""); + strBuf.append("\n\n"); + strBuf.append(" \n"); + strBuf.append("\n"); + strBuf.append(""); + strBuf.append(""); + strBuf.append(""); + strBuf.append(""); + strBuf.append(""); + strBuf.append(""); + strBuf.append(""); + strBuf.append(""); + strBuf.append(""); + strBuf.append("
Charge To Account ABBZ2
dateMonth 04/30/2008
Generated Date/Time 05/30/2008 06:15:16 PM GMT
Login Id: sundar
"); + new HtmlStripper().stripHtml(strBuf.toString()); + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/Log.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/Log.java new file mode 100644 index 00000000..3220eeb2 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/Log.java @@ -0,0 +1,40 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file 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. + * ================================================================================ + */ +package org.openecomp.portalsdk.analytics.util; + +public class Log { + + public Log() { + } + + public static void write(String info) { + System.out.println(info); + } // write + + public static void write(String info, int debugLevel) { + if (debugLevel <= org.openecomp.portalsdk.analytics.system.Globals.getDebugLevel()) + write(info); + } // write + + public static void writeError(String info) { + System.err.println(info); + } // writeError + +} // Log diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/RemDbInfo.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/RemDbInfo.java new file mode 100644 index 00000000..2d9bef42 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/RemDbInfo.java @@ -0,0 +1,93 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file 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. + * ================================================================================ + */ +package org.openecomp.portalsdk.analytics.util; + +import java.util.HashMap; + +import org.openecomp.portalsdk.analytics.system.DbUtils; +import org.openecomp.portalsdk.analytics.system.Globals; + +public class RemDbInfo { + private HashMap remDbMap = null; + private HashMap remDbTypeMap = null; + + public RemDbInfo() throws Exception { + if (remDbMap == null) { + load(); + } + } + + public void load() throws Exception { + remDbMap = new HashMap(); + remDbTypeMap = new HashMap(); + try { + //String query = " SELECT a.SCHEMA_ID, a.SCHEMA_DESC, DATASOURCE_TYPE, rownum id FROM SCHEMA_INFO a " + + // " where schema_id = 'local' union " + + // " SELECT a.SCHEMA_ID, a.SCHEMA_DESC, DATASOURCE_TYPE, (rownum+1) id FROM SCHEMA_INFO a " + + // " where schema_id <> 'local' order by id "; + String query = Globals.getRemoteDbSchemaSql(); + DataSet ds = null; + Globals.getDbUtils(); + ds = DbUtils.executeQuery(query); + + String prefix = "", desc = "", dbType = ""; + + if(ds.getRowCount() > 0) { + for (int i = 0; i < ds.getRowCount(); i++) { + prefix = ds.getItem(i, 0); + desc = ds.getItem(i, 1); + dbType = ds.getItem(i, 2); + + remDbMap.put(prefix, desc); + remDbTypeMap.put(prefix, dbType); + } + } else { + remDbMap.put("local", "local"); + remDbTypeMap.put("local", Globals.getDBType()); + } + } + catch (Exception e) {} + + } + + public String getDesc(String prefix) { + if ((remDbMap != null) && (remDbMap.containsKey(prefix))) { + return (String) remDbMap.get(prefix); + } + + return ""; + } + + public String getDBType(String prefix) { + if ((remDbTypeMap != null) && (remDbTypeMap.containsKey(prefix))) { + return (String) remDbTypeMap.get(prefix); + } + + return ""; + } + + public HashMap getDbHash() { + return remDbMap; + } + + public HashMap getDbTypeHash() { + return remDbTypeMap; + } +} diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/SQLCorrector.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/SQLCorrector.java new file mode 100644 index 00000000..15b4042a --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/SQLCorrector.java @@ -0,0 +1,343 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file 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. + * ================================================================================ + */ +package org.openecomp.portalsdk.analytics.util; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; + +public class SQLCorrector { + + static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(SQLCorrector.class); + + + public String fixSQL(StringBuffer sql) { + + int pos = 0; + //int pos_f_select_from = 0; + int pos_f_select_to = 0; + int pos_s_select_from = 0; + int pos_s_select_to = 0; + int pos_dup_select = 0; + int pos_dup_select1 = 0; + int pos_f_format = 0; + int pos_t_format = 0; + int pos_alias_format = 0; + int pos_alias = 0; + String format = ""; + String alias = null; + String sql2 = Utils.replaceInString(sql.toString(), "\n", " "); + sql2 = Utils.replaceInString(sql2, "\t", " "); + sql = new StringBuffer(sql2); + if (sql.indexOf("FROM", 2) != -1) { + pos = sql.indexOf("FROM", 2); + pos_f_select_to = sql.indexOf("FROM", 2); + if (sql.indexOf("SELECT", pos)!=-1) { + pos = sql.indexOf("SELECT", pos); + pos_s_select_from = pos; + pos_dup_select1 = pos; + //System.out.println(pos); + if (sql.indexOf("FROM", pos)!=-1) { + pos = sql.indexOf("FROM", pos); + pos_dup_select = sql.lastIndexOf("SELECT",pos); + while(pos_dup_select > pos_dup_select1) { + pos_dup_select1 = pos_dup_select; + pos = sql.indexOf("FROM", pos + 2); + pos_dup_select = sql.lastIndexOf("SELECT",pos); + } + pos_s_select_to = pos; + + } + } + } + + String o_sql = sql.substring(0, pos_f_select_to-1); + String i_sql = sql.substring(pos_s_select_from, pos_s_select_to-1); + o_sql = o_sql.toUpperCase(); + i_sql = i_sql.toUpperCase(); + String outer_sql = o_sql.substring(o_sql.indexOf("SELECT")+7); + String inner_sql = i_sql.substring(i_sql.indexOf("SELECT")+7); + logger.debug(EELFLoggerDelegate.debugLogger, ("|"+inner_sql+"|")); + String outer_cols[] = outer_sql.split(","); + //inner_sql = inner_sql.replaceAll(", '", ",'"); + + String inner_cols[] = inner_sql.split(", "); + inner_cols = removeExtraSpace(inner_cols); + logger.debug(EELFLoggerDelegate.debugLogger, ("*******OuterCols ********")); + printArray(outer_cols); + logger.debug(EELFLoggerDelegate.debugLogger, ("\n*******InnerCols********")); + printArray(inner_cols); + logger.debug(EELFLoggerDelegate.debugLogger, ("\n********Replacing Elements*****")); + ArrayList elements = findSum(outer_cols); + logger.debug(EELFLoggerDelegate.debugLogger, ("In Fix SQL " + elements.size())); + printArrayList(elements); + HashMap elementFormatMap = matchAndGetFormatInInnerCol(elements, inner_cols); + ArrayList outerReplacedCols = replaceOuterCols(elementFormatMap, outer_cols); + String finalSql = generateSQL(outerReplacedCols, sql.toString()); + return finalSql; + } + /** + * @param args + */ + public static void main(String[] args) { + + SQLCorrector s = new SQLCorrector(); + StringBuffer strBuf = new StringBuffer(); + strBuf.append("SELECT NULL TOTAL_BILLMONTH, NULL TOTAL_ACCOUNTNUMBER, NULL TOTAL_SECTORCODE, NULL TOTAL_BUSINESS_UNIT_CODE, NULL TOTAL_BILLINGSITEID, NULL TOTAL_SITEADDRESS, NULL TOTAL_SITECITY, NULL TOTAL_SITESTATE, NULL TOTAL_VENDORNAME, NULL TOTAL_INVOICENUMBER, NULL TOTAL_INVOICEDATE, NULL TOTAL_SERVICEDESCRIPTION, SUM(INVOICEAMOUNT) TOTAL_INVOICEAMOUNT FROM (SELECT '2006/09/16 - 2006/10/15' BillMonth, account_number AccountNumber, (select distinct sector_code FROM billing_site where business_unit_code = BU) SectorCode, BU||' - '||(select distinct business_unit_name FROM billing_site where business_unit_code = BU) Business_Unit_Code, Site_ID BillingSiteID, site_address1 SiteAddress, site_city SiteCity, site_state SiteState, Vendor_Site_Name VendorName, invoice_number InvoiceNumber, to_char(invoice_date,'YYYY/MM/DD') InvoiceDate, billing_service_description ServiceDescription, to_char(payment_amount,'9,999,999.99') InvoiceAmount"); + strBuf.append(" FROM cis_gm_passthrough "); + strBuf.append(" where "); + strBuf.append(" BU = decode(upper('ALL'), 'ALL', BU, substr('ALL', 1, 3)) "); + strBuf.append(" and BU in (SELECT distinct business_unit_code FROM billing_site where "); + strBuf.append(" sector_code = decode('ALL', 'ALL', sector_code, 'ALL') "); + strBuf.append(" and CHECK_USER_SECURITY(10, 'BUSINESS_UNIT_CODE', business_unit_code)='Y') "); + strBuf.append(" and to_char(bill_cycle_start_date, 'YYYY/MM/DD') = substr('2006/09/16 - 2006/10/15', 1, 10) "); + strBuf.append(" and to_char(bill_cycle_end_date, 'YYYY/MM/DD') = substr('2006/09/16 - 2006/10/15', 14, 10)"); + strBuf.append(" order by business_unit_code, sitecity, sitestate, invoicedate, servicedescription ) totalSQL "); + String sql = strBuf.toString(); + String fix_sql = s.fixSQL(new StringBuffer(sql.toUpperCase())); + logger.debug(EELFLoggerDelegate.debugLogger, (fix_sql)); + // TODO Auto-generated method stub + + } + + private String[] removeExtraSpace (String[] inner_cols) { + String [] fixed_cols = new String[inner_cols.length]; + for (int i = 0; i < inner_cols.length; i++) { + fixed_cols[i] = inner_cols[i].replaceAll(", '", ",'"); + } + return fixed_cols; + } + + private void printArray (String[] arr) { + logger.debug(EELFLoggerDelegate.debugLogger, ("")); + for (int i = 0; i < arr.length; i++) { + System.out.print(arr[i].trim()); + if(i 10)) { + pos_f_format = sql.lastIndexOf(",'", pos); + pos_f_format -= 1; + } + pos = pos_f_format; + if(sql.indexOf("')", pos)!= -1) { + pos_t_format = sql.indexOf("')", pos); + debugLogger.debug("pos_t - " + pos_t_format + " " + pos); + if(pos_t_format == -1 || (pos_t_format - pos > 20)) { + pos_t_format = sql.indexOf("' )", pos); + pos_t_format += 3; + } + else if (pos_t_format != -1) + pos_t_format += 2; + format = sql.substring(pos_f_format+3, pos_t_format); + //alias = sql.substring(pos_t_format+3, pos_t_format+6); + pos_alias = sql.indexOf(" ", pos_t_format); + alias = sql.substring(pos_alias+1, pos_alias+4); + } + } + } + + if(sql.indexOf(alias)!=-1) { + pos = sql.indexOf(alias); + debugLogger.debug(pos + " " + alias.length()+1 + "\n" + sql); + sql.delete(pos,pos+4); + sql.insert(pos, "TO_NUMBER("+alias+", '"+format+"')),'"+ format + "')"); + pos = sql.lastIndexOf("SUM", pos); + if(pos==-1) + pos = sql.lastIndexOf("AVG", pos); + else if (pos==-1) + pos = sql.lastIndexOf("COUNT", pos); + else if (pos == -1) + pos = sql.lastIndexOf("STDDEV", pos); + else if (pos == -1) + pos = sql.lastIndexOf("VARIANCE", pos); + sql.insert(pos, "TO_CHAR ("); + } + + } + + debugLogger.debug("Alias|" + alias + "| Format " + format); + debugLogger.debug(sql.toString()); + return sql.toString(); + } // FixSQL +*/ + + +} + + diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/Scheduler.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/Scheduler.java new file mode 100644 index 00000000..0dc6da17 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/Scheduler.java @@ -0,0 +1,91 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file 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. + * ================================================================================ + */ +package org.openecomp.portalsdk.analytics.util; + +import java.sql.SQLException; +import java.util.*; + +import org.openecomp.portalsdk.analytics.error.ReportSQLException; +import org.openecomp.portalsdk.analytics.scheduler.SendNotifications; +import org.openecomp.portalsdk.analytics.system.*; +import org.openecomp.portalsdk.analytics.util.*; + +public class Scheduler extends TimerTask { + private Timer timer = new Timer(true); + + private int timeInterval = 0; + + public Scheduler(int timeInterval) { + super(); + + this.timeInterval = timeInterval; + start(); + } // Scheduler + + public void start() { + if (timeInterval > 0) + timer.schedule(this, 0, timeInterval * 1000); + } + + public void stop() { + timer.cancel(); + } + + public void run() { + + SendNotifications sendNotifications = null; + + try { + Log.write("[Scheduler.run " + (new java.util.Date()).toString() + + "] Sending notifications...", 4); + //System.out.println("SMTP Server " + AppUtils.getSMTPServer()); + //System.out.println("System Name " + Globals.getSystemName()); + //System.out.println("DefaultEmailSender " + AppUtils.getDefaultEmailSender()); + //System.out.println("DirectAccessURL " + AppUtils.getDirectAccessURL()); + //System.out.println("timeInterval " + timeInterval); + /* + DbUtils.executeCall( + "BEGIN cr_raptor.send_notifications(" + + "'" + AppUtils.getSMTPServer() + "', " + + "'" + AppUtils.getDefaultEmailSender() + "', " + + "'" + Globals.getSystemName() + "', " + + "'" + AppUtils.getDirectAccessURL() + "', " + + timeInterval + + "); END;", false); + */ + sendNotifications = new SendNotifications(); + sendNotifications.send_notification(AppUtils.getSMTPServer(), AppUtils.getSMTPServer(), Globals.getSystemName() , + AppUtils.getDirectAccessURL(), timeInterval); + + } catch (Exception e) { + Log.write("[SYSTEM ERROR Scheduler.run] Exception: " + e.getMessage()); + //e.printStackTrace(); + } + finally { + + try { + sendNotifications.deInit(); + } catch (SQLException e) { + Log.write("[SYSTEM ERROR Scheduler.run] Could not close connection: " + e.getMessage()); + } + } + } // run + +} // Scheduler diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/Utils.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/Utils.java new file mode 100644 index 00000000..e8ca4292 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/Utils.java @@ -0,0 +1,372 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file 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. + * ================================================================================ + */ +package org.openecomp.portalsdk.analytics.util; + +import java.util.*; +import java.util.regex.Pattern; +import java.io.File; +import java.text.*; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; + +import org.openecomp.portalsdk.analytics.error.RaptorException; +import org.openecomp.portalsdk.analytics.model.base.*; +import org.openecomp.portalsdk.analytics.system.*; +import org.openecomp.portalsdk.analytics.system.fusion.adapter.Item; + + +public class Utils extends org.openecomp.portalsdk.analytics.RaptorObject { + + public Utils() { + } + + public static String getCurrentDateTime() { + return (new SimpleDateFormat(Globals.getJavaTimeFormat())).format(new Date()); + } // getCurrentDateTime + + public static String truncateDecimals(String value, int maxDecimals) { + return (maxDecimals < 0 || value == null || value.indexOf('.') < 0 + || (value.indexOf('.') == value.length() - 1) || value.substring( + value.indexOf('.')).length() - 1 <= maxDecimals) ? value : value.substring(0, + value.indexOf('.') + maxDecimals + 1); + } // truncateDecimals + + public static String truncateTotalDecimals(String value) { + return truncateDecimals(value, Globals.getMaxDecimalsOnTotals()); + } // truncateTotalDecimals + + public static String replaceInString(String replaceInStr, String replaceStr, + String replaceWithStr) { + if (replaceStr.equals(replaceWithStr)) + return replaceInStr; + + while (replaceInStr!=null && replaceInStr.indexOf(replaceStr) >= 0) { + int startIdx = replaceInStr.indexOf(replaceStr); + int endIdx = startIdx + replaceStr.length(); + + StringBuffer sb = new StringBuffer(); + if (startIdx > 0) + sb.append(replaceInStr.substring(0, startIdx)); + sb.append(nvls(replaceWithStr)); + if (endIdx < replaceInStr.length()) + sb.append(replaceInStr.substring(endIdx)); + replaceInStr = sb.toString(); + } // while + + return replaceInStr; + } // replaceInString + + public static String singleQuoteEncode(String value) { + value = value!=null?value:""; + value = Pattern.compile("[\']",Pattern.DOTALL).matcher(value).replaceAll("\\\\\\'"); + return value; + } + + public static String htmlEncode(String value) { + return replaceInString(replaceInString(value, "<", "<"), ">", ">"); + } // htmlEncode + + public static String excelEncode(String value) { + String replaceStr = replaceInString(replaceInString(value, "<", "<"), ">", ">"); + String reg = "&(?!&#)"; + Pattern p = Pattern.compile(reg); + String replaceStrAmpersand = p.matcher(replaceStr).replaceAll("&"); + return replaceStrAmpersand; + } // htmlEncode + + + public static String oracleSafe(String s) { + if (s == null) + return null; + + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < s.length(); i++) { + char ch = s.charAt(i); + if (ch == '\''/* &&(i>=s.length()-1||s.charAt(i+1)!='\'') */) + sb.append('\''); + sb.append(ch); + } // for + + return sb.toString(); + } // oracleSafe + + + public static String javaSafe(String s) { + if (s == null) + return null; + + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < s.length(); i++) { + char ch = s.charAt(i); + if (ch == '"') + sb.append('\\'); + sb.append(ch); + } // for + + return sb.toString(); + } // javaSafe + + public static Vector getUsersNotInList(List excludeValues, HttpServletRequest request)throws RaptorException { + HttpSession session = request.getSession(); +// String[] whereConditionAndSess = Globals.getWhereConditionForUserRole().split(","); +// String whereCondition = ""; +// String conditionalValue = ""; +// for (int i = 0; i < whereConditionAndSess.length; i++) { +// whereCondition = whereConditionAndSess[0]; +// } +// for (int i = 1; i < whereConditionAndSess.length; i++) { +// conditionalValue = whereConditionAndSess[1]; +// } +// whereCondition = " where "+ whereCondition + "'" + (String)session.getAttribute(conditionalValue) + "'"; + +// Vector allUsers = AppUtils.getAllUsers(whereCondition); + String query = Globals.getCustomizedScheduleQueryForUsers(); + session.setAttribute("login_id", AppUtils.getUserBackdoorLoginId(request)); + String userId = AppUtils.getUserID(request); + session.setAttribute("LOGGED_USERID", userId); + String[] sessionParameters = Globals.getSessionParams().split(","); + String param = ""; + for (int i = 0; i < sessionParameters.length; i++) { + param = (String)session.getAttribute(sessionParameters[0]); + query = Utils.replaceInString(query, "[" + sessionParameters[i].toUpperCase()+"]", (String)session.getAttribute(sessionParameters[i]) ); + } + boolean isAdmin = AppUtils.isAdminUser(request); + Vector allUsers = AppUtils.getAllUsers(query,param, isAdmin); + Vector result = new Vector(allUsers.size()); + + for (Iterator iter = allUsers.iterator(); iter.hasNext();) { + IdNameValue value = (IdNameValue) iter.next(); + + boolean exclude = false; + for (Iterator iterE = excludeValues.iterator(); iterE.hasNext();) + if (((IdNameValue) iterE.next()).getId().equals(value.getId())) { + exclude = true; + break; + } // if + + if (!exclude) + result.add(value); + } // for + + return result; + } // getUsersNotInList + + public static Vector getRolesNotInList(List excludeValues, HttpServletRequest request) throws RaptorException { + HttpSession session = request.getSession(); + String query = Globals.getCustomizedScheduleQueryForRoles(); + session.setAttribute("login_id", AppUtils.getUserBackdoorLoginId(request)); + String userId = AppUtils.getUserID(request); + session.setAttribute("LOGGED_USERID", userId); + String[] sessionParameters = Globals.getSessionParams().split(","); + String param = ""; + for (int i = 0; i < sessionParameters.length; i++) { + param = (String)session.getAttribute(sessionParameters[0]); + query = Utils.replaceInString(query, "[" + sessionParameters[i].toUpperCase()+"]", (String)session.getAttribute(sessionParameters[i]) ); + } + boolean isAdmin = AppUtils.isAdminUser(request); + Vector allRoles = AppUtils.getAllRoles(query, param, isAdmin); + Vector result = new Vector(allRoles.size()); + + for (Iterator iter = allRoles.iterator(); iter.hasNext();) { + IdNameValue value = (IdNameValue) iter.next(); + + boolean exclude = false; + for (Iterator iterE = excludeValues.iterator(); iterE.hasNext();) + if (((IdNameValue) iterE.next()).getId().equals(value.getId())) { + exclude = true; + break; + } // if + + // Exclude the super role + if (value.getId().equals(AppUtils.getSuperRoleID())) + exclude = true; + + if (!exclude) + result.add(value); + } // for + + return result; + } // getRolesNotInList + + public static List getUsersNotInListLatest(List excludeValues, HttpServletRequest request)throws RaptorException { + HttpSession session = request.getSession(); + String query = Globals.getCustomizedScheduleQueryForUsers(); + session.setAttribute("login_id", AppUtils.getUserBackdoorLoginId(request)); + String userId = AppUtils.getUserID(request); + session.setAttribute("LOGGED_USERID", userId); + String[] sessionParameters = Globals.getSessionParams().split(","); + String param = ""; + for (int i = 0; i < sessionParameters.length; i++) { + param = (String)session.getAttribute(sessionParameters[i]); + query = Utils.replaceInString(query, "[" + sessionParameters[i].toUpperCase()+"]", (String)session.getAttribute(sessionParameters[i]) ); + } + boolean isAdmin = AppUtils.isAdminUser(request); + Vector allUsers = AppUtils.getAllUsers(query,param, isAdmin); + Vector result = new Vector(allUsers.size()); + + List resultLatest = new ArrayList(); + + for (Iterator iter = allUsers.iterator(); iter.hasNext();) { + IdNameValue value = (IdNameValue) iter.next(); + + boolean exclude = false; + for (Iterator iterE = excludeValues.iterator(); iterE.hasNext();) + if (((IdNameValue) iterE.next()).getId().equals(value.getId())) { + exclude = true; + break; + } // if + + if (!exclude) + resultLatest.add(new Item(value.getId(), value.getName())); + } // for + + return resultLatest; + } // getUsersNotInListLatest + + + public static List getRolesNotInListLatest(List excludeValues, HttpServletRequest request) throws RaptorException { + HttpSession session = request.getSession(); + String query = Globals.getCustomizedScheduleQueryForRoles(); + session.setAttribute("login_id", AppUtils.getUserBackdoorLoginId(request)); + String userId = AppUtils.getUserID(request); + session.setAttribute("LOGGED_USERID", userId); + String[] sessionParameters = Globals.getSessionParams().split(","); + String param = ""; + for (int i = 0; i < sessionParameters.length; i++) { + param = (String)session.getAttribute(sessionParameters[i]); + query = Utils.replaceInString(query, "[" + sessionParameters[i].toUpperCase()+"]", (String)session.getAttribute(sessionParameters[i]) ); + } + boolean isAdmin = AppUtils.isAdminUser(request); + Vector allRoles = AppUtils.getAllRoles(query, param, isAdmin); + Vector result = new Vector(allRoles.size()); + + List resultLatest = new ArrayList(); + + for (Iterator iter = allRoles.iterator(); iter.hasNext();) { + IdNameValue value = (IdNameValue) iter.next(); + + boolean exclude = false; + for (Iterator iterE = excludeValues.iterator(); iterE.hasNext();) + if (((IdNameValue) iterE.next()).getId().equals(value.getId())) { + exclude = true; + break; + } // if + + // Exclude the super role + if (value.getId().equals(AppUtils.getSuperRoleID())) + exclude = true; + + if (!exclude) + resultLatest.add(new Item(value.getId(), value.getName())); + } // for + + return resultLatest; + } // getRolesNotInList + /* + * public static String nvl(String s) { return (s==null)?"":s; } // nvl + * + * public static String nvl(String s, String sDefault) { return + * nvl(s).equals("")?sDefault:s; } // nvl + */ + + public static void _assert(boolean condition, String errMsg) { + if (org.openecomp.portalsdk.analytics.system.Globals.getDebugLevel() > 0) + if (!condition) + throw new RuntimeException(errMsg); + } // _assert + + public static boolean isNull(String a) { + if ((a == null) || (a.length() == 0) || a.equalsIgnoreCase("null")) + return true; + else + return false; + } + + + public static boolean isDownloadFileExists(String fileNamePrefix) { + File f = new File (Globals.getShellScriptDir()+AppConstants.SHELL_DATA_DIR); + String[] fileNames = f.list(); + //System.out.println("Util.boolean Prefix" + fileNamePrefix); + if(fileNames!=null) { + for (int i = 0; i < fileNames.length; i++) { + //System.out.println("Util.boolean " + fileNames[i]); + if(fileNames[i].startsWith(fileNamePrefix)) { + return true; + } + } + } + return false; + + } + + public static String getLatestDownloadableFile(String fileNamePrefix) { + File f = new File (Globals.getShellScriptDir()+AppConstants.SHELL_DATA_DIR); + String[] fileNames = f.list(); + ArrayList matchingFiles = new ArrayList(); + //System.out.println("Util.download Prefix" + fileNamePrefix); + for (int i = 0; i < fileNames.length; i++) { + //System.out.println("Util.download " + fileNames[i]); + if(fileNames[i].startsWith(fileNamePrefix)) { + matchingFiles.add(fileNames[i]); + } + } + //System.out.println("SIZE 1 " + matchingFiles.size()); + String tmpFileName = ""; + int numberOfTimesLooped = 0; + boolean isSorted = false; + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); + Date date1 = null, date2 = null; + Date currDate = new Date(); + Object[] matchingfileNamesArr = matchingFiles.toArray(); + //System.out.println("SIZE " + matchingFiles.size()); + String fileName1 = "", fileName2 =""; + do { + isSorted = true; + for (int j = 1; j < matchingfileNamesArr.length - numberOfTimesLooped++; j++) { + fileName1 = (String) matchingfileNamesArr[j]; + fileName2 = (String) matchingfileNamesArr[j-1]; + try{ + date1 = sdf.parse(fileName1.substring(fileName1.lastIndexOf("_")+1,fileName1.lastIndexOf("."))); + date2 = sdf.parse(fileName2.substring(fileName2.lastIndexOf("_")+1,fileName2.lastIndexOf("."))); + } + catch(ParseException ex) { + return null; + } + + if ( (currDate.getTime()-date1.getTime()) < (currDate.getTime()-date2.getTime())) { + tmpFileName = fileName1; + matchingfileNamesArr[j] = fileName2; + matchingfileNamesArr[j-1] = tmpFileName; + isSorted = false; + } + + } + } while (!isSorted); + if(matchingfileNamesArr.length>0) + return (String)matchingfileNamesArr[0]; + else + return null; + + } + + +} // Utils + diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/XSSFilter.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/XSSFilter.java new file mode 100644 index 00000000..1d8af016 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/XSSFilter.java @@ -0,0 +1,91 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file 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. + * ================================================================================ + */ +package org.openecomp.portalsdk.analytics.util; + + /** + * + * @author Sundar + * This class is used to filter javascript tags to avoid XSS attacks. + */ +public class XSSFilter { + + // private static String[] filterChars = { "<", ">", "<", ">", "\"", "\\", "0x" }; +// private static String[] replacementChars = { " ", " ", " ", " ", "'", "/", "0 x" }; + +/* public static synchronized String filterRequest(String param) { + String value = param; + + if (param != null) { + + for (int i = 0; i < filterChars.length; i++) { + value = filterCharacters(filterChars[i], replacementChars[i], + value); + } + + } + + return value; + + } +*/ + + public static synchronized String filterRequestOnlyScript(String param) { + String value = ""; + value = nvl(param); + value = value.replaceAll("<[\\s]*[sS][\\s]*[cC][\\s]*[rR][\\s]*[iI][\\s]*[pP][\\s]*[tT][\\s]*>", ""); + value = value.replaceAll("", ""); + value = value.replaceAll("[\\s]*[jJ][\\s]*[aA][\\s]*[vV][\\s]*[aA][\\s]*[sS][\\s]*[cC][\\s]*[rR][\\s]*[iI][\\s]*[pP][\\s]*[tT][\\s]*", ""); + return value; + } + public static synchronized String filterRequest (String param) { + String value = ""; + value = nvl(param); + value = value.replaceAll("<[\\s]*[sS][\\s]*[cC][\\s]*[rR][\\s]*[iI][\\s]*[pP][\\s]*[tT][\\s]*>", ""); + value = value.replaceAll("", ""); + value = value.replaceAll("[\\s]*[jJ][\\s]*[aA][\\s]*[vV][\\s]*[aA][\\s]*[sS][\\s]*[cC][\\s]*[rR][\\s]*[iI][\\s]*[pP][\\s]*[tT][\\s]*", ""); + value = value.replaceAll("[\\s]*<", ""); + value = value.replaceAll("[\\s]*>", ""); + + return value; + } + +// private static synchronized String filterCharacters(String originalChar, String newChar, +// String param) { +// StringBuffer sb = new StringBuffer(param); +// +// for (int position = param.toLowerCase().indexOf(originalChar); position >= 0;) { +// sb.replace(position, position + originalChar.length(), newChar); +// param = sb.toString(); +// position = param.toLowerCase().indexOf(originalChar); +// } +// +// return sb.toString(); +// } + + public static void main (String args[]) { + String value = XSSFilter.filterRequest("\na\nl\ne\nr\nt\n('sundar');javascript:alert('Sundar');"); + int i = Integer.parseInt("8989"); + System.out.println(value); + } + + private static String nvl(String s) { + return (s == null) ? "" : s; + } +} \ No newline at end of file diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/jar/ExtractJar.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/jar/ExtractJar.java new file mode 100644 index 00000000..822456d7 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/jar/ExtractJar.java @@ -0,0 +1,237 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file 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. + * ================================================================================ + */ +package org.openecomp.portalsdk.analytics.util.jar; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.Reader; +import java.io.Writer; +import java.net.URL; +import java.util.jar.JarEntry; +import java.util.jar.JarInputStream; + +public class ExtractJar { + + public static int bufferSize = 8192; + public static String JARFILE = "raptor_upgrade.jar"; + + /** + * @param args + */ + public static void main(String[] args) throws Exception { + if (args.length > 0 && args[0] != null && args[0].length() > 0) + extractFilesFromJar(args[0]); + else { + System.out.println("Current Directory is taken as webapp path"); + String currentDir = new File(".").getAbsolutePath(); + extractFilesFromJar(currentDir); + } + } + + /** + * + * @param jarFile + * @throws Exception + */ + public static void readJar(File jarFile) throws Exception { + JarInputStream in = new JarInputStream(new FileInputStream(jarFile)); + JarEntry je; + while ((je = in.getNextJarEntry()) != null) { + if (je.isDirectory() == false) { + if (je.getName().startsWith("org/openecomp/portalsdk/analytics/config/")) { + System.out.println(je.getName() + " " + je.getTime()); + + } + } + } + in.close(); + } + + /** + * + * @param directory + * @throws IOException + */ + public static void extractFilesFromJar(String directory) throws IOException { + Class clazz = ExtractJar.class; + URL jarUrl = clazz.getProtectionDomain().getCodeSource().getLocation(); + + JarInputStream entryStream = new JarInputStream(jarUrl.openStream()); + JarEntry entry; + + while (true) { + entry = entryStream.getNextJarEntry(); + if (entry == null) + break; + if (entry.getName().indexOf("jarutil") < 0) { + System.out.println(entry.getName()); + File file = new File(directory, entry.getName()); + if (entry.isDirectory()) { + if (!file.exists()) + file.mkdirs(); + } else { + File dir = new File(file.getParent()); + if (!dir.exists()) + dir.mkdirs(); + if (file.exists()) + file.delete(); + FileOutputStream fout = new FileOutputStream(file); + copy(entryStream, fout); + fout.close(); + + if (entry.getTime() >= 0) + file.setLastModified(entry.getTime()); + } + + } + entryStream.closeEntry(); + } + entryStream.close(); + System.out.println("/WEB-INF/classes/org/openecomp/portalsdk/analytics"); + System.out.println("Delete .... "); + + File file1 = new File(directory, "/WEB-INF/classes/org/openecomp/portalsdk/analytics"); + + deleteDir(file1); + System.out.println("Deleted ...."); + + System.out.println("raptor_upgrade_setup.jar"); + file1 = new File(directory, "/raptor_upgrade_setup.jar"); + + deleteDir(file1); + System.out.println("Deleted ...."); + + System.out.println("/org"); + System.out.println("Delete .... "); + + file1 = new File(directory, "/org"); + System.out.println(" ********************************* "); + deleteDir(file1); + System.out.println("Deleted ...."); + System.out.println("org"); + System.out.println("Delete .... "); + + System.out.println("************************************************"); + System.out.println("* *"); + System.out.println("* *"); + System.out.println("* RAPTOR SETUP COMPLETE. *"); + System.out.println("* *"); + System.out.println("* Thank you for upgrading. *"); + System.out.println("* *"); + System.out.println("************************************************"); + } + + /** + * + * @param in + * @param out + * @param byteCount + * @throws IOException + */ + public static void copy(InputStream in, OutputStream out, long byteCount) throws IOException { + byte buffer[] = new byte[bufferSize]; + int len = bufferSize; + if (byteCount >= 0) { + while (byteCount > 0) { + if (byteCount < bufferSize) + len = in.read(buffer, 0, (int) byteCount); + else + len = in.read(buffer, 0, bufferSize); + if (len == -1) + break; + + byteCount -= len; + out.write(buffer, 0, len); + } + } else { + while (true) { + len = in.read(buffer, 0, bufferSize); + if (len < 0) + break; + out.write(buffer, 0, len); + } + } + } + + /** + * Copy Reader to Writer for byteCount bytes or until EOF or exception. + * + * @param in + * @param out + * @param byteCount + * @throws IOException + */ + public static void copy(Reader in, Writer out, long byteCount) throws IOException { + char buffer[] = new char[bufferSize]; + int len = bufferSize; + if (byteCount >= 0) { + while (byteCount > 0) { + if (byteCount < bufferSize) + len = in.read(buffer, 0, (int) byteCount); + else + len = in.read(buffer, 0, bufferSize); + + if (len == -1) + break; + byteCount -= len; + out.write(buffer, 0, len); + } + } else { + while (true) { + len = in.read(buffer, 0, bufferSize); + if (len == -1) + break; + out.write(buffer, 0, len); + } + } + } + + /** + * Copy Stream in to Stream out until EOF or exception. + * + * @param in + * @param out + * @throws IOException + */ + public static void copy(InputStream in, OutputStream out) throws IOException { + copy(in, out, -1); + } + + public static boolean deleteDir(File dir) { + System.out.println("Name: " + dir.getName() + " " + dir.isDirectory()); + if (dir.isDirectory()) { + String[] children = dir.list(); + System.out.println(children); + for (int i = 0; i < children.length; i++) { + boolean success = deleteDir(new File(dir, children[i])); + if (!success) { + return false; + } + } + } + + return dir.delete(); + } + +} diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/upgrade/SystemUpgrade.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/upgrade/SystemUpgrade.java new file mode 100644 index 00000000..fc39af91 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/openecomp/portalsdk/analytics/util/upgrade/SystemUpgrade.java @@ -0,0 +1,127 @@ +/*- + * ================================================================================ + * eCOMP Portal SDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file 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. + * ================================================================================ + */ +package org.openecomp.portalsdk.analytics.util.upgrade; + +import java.io.*; +import java.sql.*; +import java.util.*; +import javax.servlet.http.*; + +import org.openecomp.portalsdk.analytics.controller.*; +import org.openecomp.portalsdk.analytics.error.*; +import org.openecomp.portalsdk.analytics.model.*; +import org.openecomp.portalsdk.analytics.model.base.*; +import org.openecomp.portalsdk.analytics.model.definition.*; +import org.openecomp.portalsdk.analytics.model.runtime.*; +import org.openecomp.portalsdk.analytics.system.*; +import org.openecomp.portalsdk.analytics.util.*; +import org.openecomp.portalsdk.analytics.view.*; +import org.openecomp.portalsdk.analytics.xmlobj.*; + +public class SystemUpgrade extends org.openecomp.portalsdk.analytics.RaptorObject { + private static final String upgradeFromVersion = "1.x"; + private static final String upgradeToVersion = "2.0"; + +/* This script upgrades the Raptor database to a newer version + Make sure you execute the "upgrade_v0_to_v1_0_before_java.sql" before running this + and "upgrade_v0_to_v1_0_after_java.sql" afterwards + + URL example: http://localhost:8082/databank/dispatcher?action=raptor&r_action=system_upgrade +*/ + public static String upgradeDB(HttpServletRequest request) { + request.setAttribute("system_message", "System upgrade disabled"); + return "raptor/blank.jsp"; + +/* try { + if(upgradeFromVersion.equals("1.x")&&upgradeToVersion.equals("2.0")) + upgrateFromV1ToV2_0(request); + else + throw new RuntimeException("Invalid version"); + + return "raptor/blank.jsp"; + } catch(Exception e) { + return (new ErrorHandler()).processFatalError(request, e); + }*/ + } // upgradeDB + + private static void upgrateFromV1ToV2_0(HttpServletRequest request) throws Exception { + StringBuffer log = new StringBuffer(); + log.append("Starting upgrade...
\n"); + + DataSet ds = DbUtils.executeQuery("SELECT cr.rep_id, cr.sched_mailto_user_ids FROM cr_report cr"); + for(int i=0; iProcessing report ["+repId+"]: "); + + Connection connection = DbUtils.startTransaction(); + String emailIds = nvls(ds.getString(i, 1)); + if(emailIds.length()>0) + try { + log.append("Converting emails "); + StringTokenizer st = new StringTokenizer(emailIds, ","); + while(st.hasMoreTokens()) { + String userId = nvls(st.nextToken()); + log.append(userId); + if(userId.length()>0) + DbUtils.executeUpdate(connection, "INSERT INTO cr_report_schedule_users (rep_id, user_id) VALUES ("+repId+", "+userId+")"); + log.append("-success, "); + } // while + log.append(" COMPLETED; "); + } catch(Exception e) { + log.append("-FAILED; "); + } + + String reportXML = ReportLoader.loadCustomReportXML(repId); + ReportDefinition rdef = ReportDefinition.unmarshal(reportXML, repId, request); + ReportWrapper rw = new ReportWrapper(rdef.cloneCustomReport(), repId, null, null, null, null, null, null, false); + + for(Iterator iter=rw.getAllColumns().iterator(); iter.hasNext(); ) { + DataColumnType col = (DataColumnType) iter.next(); + String drillDownURL = nvls(col.getDrillDownURL()); + if(drillDownURL.startsWith("dispatcher?action=custrep.run&c_master=")) { + drillDownURL = AppUtils.getReportExecuteActionURL()+drillDownURL.substring("dispatcher?action=custrep.run&c_master=".length()); + log.append("Drill-down processed; "); + col.setDrillDownURL(drillDownURL); + } + } // for + + reportXML = rw.marshal(); + + /*PrintWriter xmlOut = new PrintWriter(new BufferedWriter(new FileWriter(new File(AppUtils.getTempFolderPath()+AppUtils.getUserID(request))))); + xmlOut.println(reportXML); + xmlOut.close();*/ + + try { + ReportLoader.updateCustomReportRec(connection, rw, reportXML); + DbUtils.commitTransaction(connection); + log.append("REPORT UPDATED\n"); + } catch(Exception e) { + log.append("REPORT UPDATE FAILED\n"); + DbUtils.rollbackTransaction(connection); + } finally { + DbUtils.clearConnection(connection); + } + } // for + + log.append("
\nSystem upgrade successfully completed...
\n"); + request.setAttribute("system_message", log.toString()); + } // upgrateFromV1ToV2_0 + +} // SystemUpgrade -- cgit 1.2.3-korg