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;
135 if(refresh) clearValues();
136 for (Enumeration enKeys = keys(); enKeys.hasMoreElements();) {
137 String key = (String) enKeys.nextElement();
138 String oldValue = XSSFilter.filterRequestOnlyScript(getParamValue(key));
139 String newValue = null;
140 if (isParameterMultiValue(key)) {
141 String[] values = request.getParameterValues(key);
143 if (values != null) {
144 StringBuffer sb = new StringBuffer();
145 for (int i = 0; i < values.length; i++) {
148 sb.append(values[i]);
151 newValue = XSSFilter.filterRequestOnlyScript(sb.toString());
153 } else if (isParameterTextAreaValue(key)) {
154 /* String[] values = request.getParameterValues(key);
156 if (values != null) {
157 StringBuffer sb = new StringBuffer();
158 for (int i = 0; i < values.length; i++) {
161 sb.append(values[i]);
165 value = request.getParameter(key);
166 value = Utils.oracleSafe(nvl(value));
167 paramIsTextAreaDrilldownValue.put(key, value);
168 value = value.replaceAll(",", "|");
169 value = "('" + Utils.replaceInString(value, "|", "','") + "')";
170 //value = Utils.replaceInString(value, "|", ",");
171 newValue = XSSFilter.filterRequestOnlyScript(value);
172 paramIsTextAreaValueModified.put(key, new Boolean(true));
176 // newValue = nvl(request.getParameter(key));
177 newValue = XSSFilter.filterRequestOnlyScript(request.getParameter(key));
178 //debugLogger.debug("IN REPORTPARAM ^NEW VALUE " + newValue + " OLD VALUE " + oldValue + " KEY " + key + " isParameterMultiValue(key) " + isParameterMultiValue(key));
179 if(!isParameterMultiValue(key) && !isParameterTextAreaValue(key)) {
180 if(refresh && nvl(newValue).length()<=0) {
182 } else if ( ((newValue != null && newValue.trim().length()>0) && (oldValue!=null && oldValue.trim().length()>0) && !newValue.equals(oldValue)) ||
183 ((newValue != null && newValue.trim().length()>0) && (oldValue == null || oldValue.trim().length() <= 0)) ) {
185 //System.out.println("paramupdated1 " +paramUpdated+ " " + newValue + " " + oldValue);
186 // if(newValue.startsWith("[") && newValue.endsWith("]")) {
187 // newValue = getDateAsString(newValue);
190 } else if (((newValue == null || newValue.trim().length()<=0)) && (oldValue!=null && oldValue.trim().length()>0)) {
193 } else if (nvl(newValue).equals(nvl(oldValue)) ) {
199 if (((newValue != null && newValue.trim().length()>0) && (oldValue!=null && oldValue.trim().length()>0) && !newValue.equals(oldValue)) ||
200 ((newValue != null && newValue.trim().length()>0) && (oldValue == null || oldValue.trim().length() <= 0)) && (isParameterMultiValue(key)||isParameterTextAreaValue(key))) {
201 if(isParameterTextAreaValue(key)) {
202 newValue = getParamValueforTextAreaDrilldown(key);
203 if(newValue.length() > 0 && !newValue.equals(oldValue)) {
212 } else if (((newValue == null || newValue.trim().length()<=0)) && (oldValue!=null && oldValue.trim().length()>0) && (isParameterMultiValue(key)||isParameterTextAreaValue(key))) {
214 //System.out.println("paramupdated3 " +paramUpdated+ " N" + newValue + " O" + oldValue);
220 logger.debug(EELFLoggerDelegate.debugLogger, ("[DEBUG MESSAGE FROM RAPTOR] ------->Time Taken for Adding/Clearing Param Values for Search Field Display " + (System.currentTimeMillis() - currentTime)));
224 public String getParamValueforTextAreaDrilldown(String key) {
225 return (String) paramIsTextAreaDrilldownValue.get(key);
228 public String getParamValue(String key) {
229 //This logic below is added to avoid BLANK formfield to pass through logic - Sundar
231 if(isParameterTextAreaValueAndModified(key)) {
233 value = (String) get(key);
234 value = Utils.oracleSafe(nvl(value));
235 value = value.replaceAll(",","|");
236 if(nvl(value).length()>0) {
237 if(nvl(value).indexOf("|")!= -1) { // Need option to support "|"
238 value = Utils.replaceInString(value,"\r\n","~");
240 value = Utils.replaceInString(value, "~", "' , '");
241 value = "('" + Utils.replaceInString(value, "|", "','") + "')"; // changed from "|"
242 //value = Utils.replaceInString(value, "|", ",");
243 value = XSSFilter.filterRequestOnlyScript(value);
247 // if(nvl(value).length()>0) {
248 // value = Utils.replaceInString(value, ",", "|");
249 // value = value.indexOf("('")!=-1? value.substring(2, value.length()-2):value;
250 // value = Utils.replaceInString(value, "'|'", ",");
255 return (String) get(key);
261 public String getParamDisplayValue(String key) {
262 String value = getParamValue(key);
263 if (isParameterMultiValue(key))
264 value = "(" + Utils.replaceInString(value, "|", ",") + ")";
268 public String getParamBaseSQL(String key) {
269 return (String) multiValueBaseSQL.get(key);
272 /** ************************************************************************************************* */
274 private String nvl(String s) {
275 return (s == null) ? "" : s;
278 private String nvl(String s, String sDefault) {
279 return nvl(s).equals("") ? sDefault : s;
282 private boolean isNull(String a) {
283 if ((a == null) || (a.length() == 0) || a.equalsIgnoreCase("null"))
289 private void clearValues() {
291 String defaultValue = "";
292 String defaultSQL = "";
293 String defaultQuery = "";
294 DataSet dsDefault = null;
296 for (Enumeration enKeys = keys(); enKeys.hasMoreElements();) {
297 String key = (String) enKeys.nextElement();
298 for(rff.resetNext(); rff.hasNext(); ) {
300 if(ff.getFieldName().equals(key)) {
302 defaultValue = ff.getDefaultValue();
303 defaultSQL = ff.getFieldDefaultSQL();
304 if(nvl(defaultValue).length()>0) {
305 put(key,ff.getDefaultValue());
306 } else if(nvl(defaultSQL).length() > 0) {
307 //defaultSQL = Utils.replaceInString(defaultSQL, "[LOGGED_USERID]", userId);
308 if(!(isParameterMultiValue(key) || isParameterTextAreaValue(key))) {
309 defaultQuery = "SELECT id, name FROM (SELECT rownum r, id, name FROM (" + defaultSQL
313 dsDefault = ConnectionUtils.getDataSet(defaultQuery, ff.getDbInfo());
314 if(dsDefault!=null && dsDefault.getRowCount()>0) {
315 for (int i = 0; i < dsDefault.getRowCount(); i++) {
316 put(key, dsDefault.getString(i, 0));
319 } catch (RaptorException ex) {}
329 /* for (Enumeration enKeys = keys(); enKeys.hasMoreElements();) {
330 String key = (String) enKeys.nextElement();
337 public void printValues() {
338 for (Enumeration enKeys = keys(); enKeys.hasMoreElements();) {
339 String key = (String) enKeys.nextElement();
340 String value = (String) get(key);
341 System.out.println("ReportParamValues " + key + " "+ value);
345 private String getDateAsString (String keyword) {
347 if (keyword.equals("[PROCESSING_DATE]")) {
348 //sql = "select to_char(trunc(sysdate,'dd'), 'mm/dd/yyyy') as dateStr from dual";
349 sql = "select to_char(trunc(sysdate,'dd'), 'mm/dd/yyyy') as dateStr" + Globals.getGenerateSqlVisualDual();
350 } else if (keyword.equals("[PROCESSING_NEXT_DATE]")) {
351 //sql = "select to_char(trunc(sysdate+1,'dd'), 'mm/dd/yyyy') as dateStr from dual";
352 sql = "select to_char(trunc(sysdate+1,'dd'), 'mm/dd/yyyy') as dateStr" + Globals.getGenerateSqlVisualDual();
353 } else if (keyword.equals("[PROCESSING_DAY_BEFORE_DATE]")) {
354 //sql = "select to_char(trunc(sysdate-1,'dd'), 'mm/dd/yyyy') as dateStr from dual";
355 sql = "select to_char(trunc(sysdate-1,'dd'), 'mm/dd/yyyy') as dateStr"+ Globals.getGenerateSqlVisualDual();
356 } else if (keyword.equals("[PROCESSING_MONTH_START_DATE]")) {
357 //sql = "select to_char(trunc(sysdate,'MM'), 'mm/dd/yyyy') as dateStr from dual";
358 sql = "select to_char(trunc(sysdate,'MM'), 'mm/dd/yyyy') as dateStr"+ Globals.getGenerateSqlVisualDual();
359 } else if (keyword.equals("[PROCESSING_MONTH_END_DATE]")) {
360 //sql = "select to_char(last_day(sysdate), 'mm/dd/yyyy') as dateStr from dual";
361 sql = "select to_char(last_day(sysdate), 'mm/dd/yyyy') as dateStr" + Globals.getGenerateSqlVisualDual();
362 } else if (keyword.equals("[CURRENT_HOUR]")) {
363 //sql = "select to_char(trunc(sysdate,'HH24'),'mm/dd/yyyy HH24') as dateStr from dual";
364 sql = "select to_char(trunc(sysdate,'HH24'),'mm/dd/yyyy HH24') as dateStr"+ Globals.getGenerateSqlVisualDual();
365 } else if (keyword.equals("[PREVIOUS_HOUR]")) {
366 //sql = "select to_char(trunc(sysdate-1/24, 'HH24'),'mm/dd/yyyy HH24') as dateStr from dual";
367 sql = "select to_char(trunc(sysdate-1/24, 'HH24'),'mm/dd/yyyy HH24') as dateStr" + Globals.getGenerateSqlVisualDual();
368 } else if (keyword.equals("[NEXT_HOUR]")) {
369 //sql = "select to_char(trunc(sysdate+1/24, 'HH24'),'mm/dd/yyyy HH24') as dateStr from dual";
370 sql = "select to_char(trunc(sysdate+1/24, 'HH24'),'mm/dd/yyyy HH24') as dateStr" + Globals.getGenerateSqlVisualDual();
376 ds = DbUtils.executeQuery(sql);
377 return ds.getString(0,0);
381 } catch (RaptorException ex) {
382 logger.error(EELFLoggerDelegate.errorLogger, "RaptorException in getDateAsString", ex);
387 } // ReportParamValues