2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
38 package org.onap.portalsdk.analytics.model.runtime;
40 import java.util.Enumeration;
41 import java.util.Hashtable;
42 import java.util.Iterator;
44 import javax.servlet.http.HttpServletRequest;
46 import org.onap.portalsdk.analytics.error.RaptorException;
47 import org.onap.portalsdk.analytics.system.ConnectionUtils;
48 import org.onap.portalsdk.analytics.system.DbUtils;
49 import org.onap.portalsdk.analytics.system.Globals;
50 import org.onap.portalsdk.analytics.util.AppConstants;
51 import org.onap.portalsdk.analytics.util.DataSet;
52 import org.onap.portalsdk.analytics.util.Utils;
53 import org.onap.portalsdk.analytics.util.XSSFilter;
54 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
56 public class ReportParamValues extends Hashtable {
58 private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ReportParamValues.class);
60 private Hashtable paramIsMultiValue = null;
61 private Hashtable paramIsTextAreaValue = null;
62 private Hashtable paramIsTextAreaDrilldownValue = null;
63 private Hashtable paramIsTextAreaValueModified = null;
64 private ReportFormFields rff = null;
66 private Hashtable multiValueBaseSQL = null;
67 private Hashtable textAreaValueBaseSQL = null;
69 public ReportParamValues() {
71 paramIsMultiValue = new Hashtable();
72 multiValueBaseSQL = new Hashtable();
73 paramIsTextAreaValue = new Hashtable();
74 paramIsTextAreaDrilldownValue = new Hashtable();
75 paramIsTextAreaValueModified = new Hashtable();
76 } // ReportParamValues
78 public ReportParamValues(ReportFormFields rff, String reportDefType) {
81 for (Iterator iter = rff.iterator(); iter.hasNext();) {
82 FormField ff = (FormField) iter.next();
83 if(ff.getValidationType().equals(FormField.VT_TIMESTAMP_HR) || ff.getValidationType().equals(FormField.VT_TIMESTAMP_MIN) || ff.getValidationType().equals(FormField.VT_TIMESTAMP_SEC)) {
84 put(ff.getFieldName(), nvl(ff.getDefaultValue()));
85 put(ff.getFieldName()+"_Hr", nvl(ff.getDefaultValue()));
86 if(ff.getValidationType().equals(FormField.VT_TIMESTAMP_MIN) || ff.getValidationType().equals(FormField.VT_TIMESTAMP_SEC)) {
87 put(ff.getFieldName()+"_Min", nvl(ff.getDefaultValue()));
89 if(ff.getValidationType().equals(FormField.VT_TIMESTAMP_SEC)) {
90 put(ff.getFieldName()+"_Sec", nvl(ff.getDefaultValue()));
93 put(ff.getFieldName(), nvl(ff.getDefaultValue()));
95 boolean isMultiValue = ff.getFieldType().equals(FormField.FFT_CHECK_BOX)
96 || ff.getFieldType().equals(FormField.FFT_LIST_MULTI);
97 boolean isTextAreaValue = ff.getFieldType().equals(FormField.FFT_TEXTAREA) && reportDefType
98 .equals(AppConstants.RD_SQL_BASED);
100 paramIsMultiValue.put(ff.getFieldName(), new Boolean(isMultiValue));
101 paramIsTextAreaValue.put(ff.getFieldName(), new Boolean(isTextAreaValue));
103 if ((isMultiValue || isTextAreaValue) && ff.getBaseSQL() != null)
104 multiValueBaseSQL.put(ff.getFieldName(), ff.getBaseSQL());
108 } // ReportParamValues
111 * public ReportParamValues(ReportFormFields rff, HttpServletRequest
112 * request) { this(rff);
114 * setParamValues(request); } // ReportParamValues
116 public boolean isParameterMultiValue(String fieldName) {
117 Boolean b = (Boolean) paramIsMultiValue.get(fieldName);
118 return (b != null) ? b.booleanValue() : false;
119 } // isParameterMultiValue
121 public boolean isParameterTextAreaValue(String fieldName) {
122 Boolean b = (Boolean) paramIsTextAreaValue.get(fieldName);
123 return (b != null) ? b.booleanValue() : false;
124 } // isParameterMultiValue
126 public boolean isParameterTextAreaValueAndModified(String fieldName) {
127 Boolean b = (Boolean) paramIsTextAreaValueModified.get(fieldName);
128 return (b != null) ? b.booleanValue() : false;
129 } // isParameterMultiValue
131 public boolean setParamValues(HttpServletRequest request, boolean refresh) {
132 long currentTime = System.currentTimeMillis();
133 //System.out.println("ReportParamValues setParamValues called " + refresh);
134 boolean paramUpdated = false;
137 for (Enumeration enKeys = keys(); enKeys.hasMoreElements();) {
138 String key = (String) enKeys.nextElement();
139 String oldValue = XSSFilter.filterRequestOnlyScript(getParamValue(key));
140 String newValue = null;
141 if (isParameterMultiValue(key)) {
142 String[] values = request.getParameterValues(key);
144 if (values != null) {
145 StringBuffer sb = new StringBuffer();
146 for (int i = 0; i < values.length; i++) {
149 sb.append(values[i]);
152 newValue = XSSFilter.filterRequestOnlyScript(sb.toString());
154 } else if (isParameterTextAreaValue(key)) {
155 /* String[] values = request.getParameterValues(key);
157 if (values != null) {
158 StringBuffer sb = new StringBuffer();
159 for (int i = 0; i < values.length; i++) {
162 sb.append(values[i]);
166 value = request.getParameter(key);
167 value = Utils.oracleSafe(nvl(value));
168 paramIsTextAreaDrilldownValue.put(key, value);
169 value = value.replaceAll(",", "|");
170 value = "('" + Utils.replaceInString(value, "|", "','") + "')";
171 //value = Utils.replaceInString(value, "|", ",");
172 newValue = XSSFilter.filterRequestOnlyScript(value);
173 paramIsTextAreaValueModified.put(key, new Boolean(true));
177 // newValue = nvl(request.getParameter(key));
178 newValue = XSSFilter.filterRequestOnlyScript(request.getParameter(key));
179 //debugLogger.debug("IN REPORTPARAM ^NEW VALUE " + newValue + " OLD VALUE " + oldValue + " KEY " + key + " isParameterMultiValue(key) " + isParameterMultiValue(key));
180 if(!isParameterMultiValue(key) && !isParameterTextAreaValue(key)) {
181 if(refresh && nvl(newValue).length()<=0) {
183 } else if ( ((newValue != null && newValue.trim().length()>0) && (oldValue!=null && oldValue.trim().length()>0) && !newValue.equals(oldValue)) ||
184 ((newValue != null && newValue.trim().length()>0) && (oldValue == null || oldValue.trim().length() <= 0)) ) {
186 //System.out.println("paramupdated1 " +paramUpdated+ " " + newValue + " " + oldValue);
187 // if(newValue.startsWith("[") && newValue.endsWith("]")) {
188 // newValue = getDateAsString(newValue);
191 } else if (((newValue == null || newValue.trim().length()<=0)) && (oldValue!=null && oldValue.trim().length()>0)) {
194 } else if (nvl(newValue).equals(nvl(oldValue)) ) {
200 if (((newValue != null && newValue.trim().length()>0) && (oldValue!=null && oldValue.trim().length()>0) && !newValue.equals(oldValue)) ||
201 ((newValue != null && newValue.trim().length()>0) && (oldValue == null || oldValue.trim().length() <= 0)) && (isParameterMultiValue(key)||isParameterTextAreaValue(key))) {
202 if(isParameterTextAreaValue(key)) {
203 newValue = getParamValueforTextAreaDrilldown(key);
204 if(newValue.length() > 0 && !newValue.equals(oldValue)) {
213 } else if (((newValue == null || newValue.trim().length()<=0)) && (oldValue!=null && oldValue.trim().length()>0) && (isParameterMultiValue(key)||isParameterTextAreaValue(key))) {
215 //System.out.println("paramupdated3 " +paramUpdated+ " N" + newValue + " O" + oldValue);
221 logger.debug(EELFLoggerDelegate.debugLogger, ("[DEBUG MESSAGE FROM RAPTOR] ------->Time Taken for Adding/Clearing Param Values for Search Field Display " + (System.currentTimeMillis() - currentTime)));
225 public String getParamValueforTextAreaDrilldown(String key) {
226 return (String) paramIsTextAreaDrilldownValue.get(key);
229 public String getParamValue(String key) {
230 //This logic below is added to avoid BLANK formfield to pass through logic - Sundar
232 if(isParameterTextAreaValueAndModified(key)) {
234 value = (String) get(key);
235 value = Utils.oracleSafe(nvl(value));
236 value = value.replaceAll(",","|");
237 if(nvl(value).length()>0) {
238 if(nvl(value).indexOf("|")!= -1) { // Need option to support "|"
239 value = Utils.replaceInString(value,"\r\n","~");
241 value = Utils.replaceInString(value, "~", "' , '");
242 value = "('" + Utils.replaceInString(value, "|", "','") + "')"; // changed from "|"
243 //value = Utils.replaceInString(value, "|", ",");
244 value = XSSFilter.filterRequestOnlyScript(value);
248 // if(nvl(value).length()>0) {
249 // value = Utils.replaceInString(value, ",", "|");
250 // value = value.indexOf("('")!=-1? value.substring(2, value.length()-2):value;
251 // value = Utils.replaceInString(value, "'|'", ",");
256 return (String) get(key);
262 public String getParamDisplayValue(String key) {
263 String value = getParamValue(key);
264 if (isParameterMultiValue(key))
265 value = "(" + Utils.replaceInString(value, "|", ",") + ")";
269 public String getParamBaseSQL(String key) {
270 return (String) multiValueBaseSQL.get(key);
273 /** ************************************************************************************************* */
275 private String nvl(String s) {
276 return (s == null) ? "" : s;
279 private String nvl(String s, String sDefault) {
280 return nvl(s).equals("") ? sDefault : s;
283 private boolean isNull(String a) {
284 if ((a == null) || (a.length() == 0) || a.equalsIgnoreCase("null"))
290 private void clearValues() {
292 String defaultValue = "";
293 String defaultSQL = "";
294 String defaultQuery = "";
295 DataSet dsDefault = null;
297 for (Enumeration enKeys = keys(); enKeys.hasMoreElements();) {
298 String key = (String) enKeys.nextElement();
299 for(rff.resetNext(); rff.hasNext(); ) {
301 if(ff.getFieldName().equals(key)) {
303 defaultValue = ff.getDefaultValue();
304 defaultSQL = ff.getFieldDefaultSQL();
305 if(nvl(defaultValue).length()>0) {
306 put(key,ff.getDefaultValue());
307 } else if(nvl(defaultSQL).length() > 0) {
308 //defaultSQL = Utils.replaceInString(defaultSQL, "[LOGGED_USERID]", userId);
309 if(!(isParameterMultiValue(key) || isParameterTextAreaValue(key))) {
310 defaultQuery = "SELECT id, name FROM (SELECT rownum r, id, name FROM (" + defaultSQL
314 dsDefault = ConnectionUtils.getDataSet(defaultQuery, ff.getDbInfo());
315 if(dsDefault!=null && dsDefault.getRowCount()>0) {
316 for (int i = 0; i < dsDefault.getRowCount(); i++) {
317 put(key, dsDefault.getString(i, 0));
320 } catch (RaptorException ex) {}
330 /* for (Enumeration enKeys = keys(); enKeys.hasMoreElements();) {
331 String key = (String) enKeys.nextElement();
338 public void printValues() {
339 for (Enumeration enKeys = keys(); enKeys.hasMoreElements();) {
340 String key = (String) enKeys.nextElement();
341 String value = (String) get(key);
342 System.out.println("ReportParamValues " + key + " "+ value);
346 private String getDateAsString (String keyword) {
348 if (keyword.equals("[PROCESSING_DATE]")) {
349 //sql = "select to_char(trunc(sysdate,'dd'), 'mm/dd/yyyy') as dateStr from dual";
350 sql = "select to_char(trunc(sysdate,'dd'), 'mm/dd/yyyy') as dateStr" + Globals.getGenerateSqlVisualDual();
351 } else if (keyword.equals("[PROCESSING_NEXT_DATE]")) {
352 //sql = "select to_char(trunc(sysdate+1,'dd'), 'mm/dd/yyyy') as dateStr from dual";
353 sql = "select to_char(trunc(sysdate+1,'dd'), 'mm/dd/yyyy') as dateStr" + Globals.getGenerateSqlVisualDual();
354 } else if (keyword.equals("[PROCESSING_DAY_BEFORE_DATE]")) {
355 //sql = "select to_char(trunc(sysdate-1,'dd'), 'mm/dd/yyyy') as dateStr from dual";
356 sql = "select to_char(trunc(sysdate-1,'dd'), 'mm/dd/yyyy') as dateStr"+ Globals.getGenerateSqlVisualDual();
357 } else if (keyword.equals("[PROCESSING_MONTH_START_DATE]")) {
358 //sql = "select to_char(trunc(sysdate,'MM'), 'mm/dd/yyyy') as dateStr from dual";
359 sql = "select to_char(trunc(sysdate,'MM'), 'mm/dd/yyyy') as dateStr"+ Globals.getGenerateSqlVisualDual();
360 } else if (keyword.equals("[PROCESSING_MONTH_END_DATE]")) {
361 //sql = "select to_char(last_day(sysdate), 'mm/dd/yyyy') as dateStr from dual";
362 sql = "select to_char(last_day(sysdate), 'mm/dd/yyyy') as dateStr" + Globals.getGenerateSqlVisualDual();
363 } else if (keyword.equals("[CURRENT_HOUR]")) {
364 //sql = "select to_char(trunc(sysdate,'HH24'),'mm/dd/yyyy HH24') as dateStr from dual";
365 sql = "select to_char(trunc(sysdate,'HH24'),'mm/dd/yyyy HH24') as dateStr"+ Globals.getGenerateSqlVisualDual();
366 } else if (keyword.equals("[PREVIOUS_HOUR]")) {
367 //sql = "select to_char(trunc(sysdate-1/24, 'HH24'),'mm/dd/yyyy HH24') as dateStr from dual";
368 sql = "select to_char(trunc(sysdate-1/24, 'HH24'),'mm/dd/yyyy HH24') as dateStr" + Globals.getGenerateSqlVisualDual();
369 } else if (keyword.equals("[NEXT_HOUR]")) {
370 //sql = "select to_char(trunc(sysdate+1/24, 'HH24'),'mm/dd/yyyy HH24') as dateStr from dual";
371 sql = "select to_char(trunc(sysdate+1/24, 'HH24'),'mm/dd/yyyy HH24') as dateStr" + Globals.getGenerateSqlVisualDual();
377 ds = DbUtils.executeQuery(sql);
378 return ds.getString(0,0);
382 } catch (RaptorException ex) {
383 logger.error(EELFLoggerDelegate.errorLogger, "RaptorException in getDateAsString", ex);
388 } // ReportParamValues