Merge branch 'ohd_15.1.1' of ssh://vlab.ncep.noaa.gov:29418/AWIPS2_Dev_Baseline into master_15.1.1

Former-commit-id: a05d428aac35687a34c7fcaefbd1665488f9ec53
This commit is contained in:
Fay.Liang 2015-04-20 15:29:13 -04:00
commit 5d1b9e165f
4 changed files with 115 additions and 14 deletions

View file

@ -86,10 +86,11 @@ import com.raytheon.viz.ui.dialogs.ICloseCallback;
* Changes for non-blocking CoopAgencyOfficeDlg.
* Changes for non-blocking CopyNewLocationDlg.
* Changes for non-blocking CountyStateDlg.
* 08 Jan 2015 15695, 15488 djingtao fix the save/update text field with apostrophe, repleace the single
* 08 Jan 2015 15695, 15488 djingtao fix the save/update text field with apostrophe, repleace the single
* apostrophe to two single apostrophe before save/update to database.
* 02 Feb 2015 13372 djingtao change the GMT time to local time for "revise" field
*
* 02 Feb 2015 13372 djingtao change the GMT time to local time for "revise" field
* 08 April 2015 17338 djingtao "Apostrophe" entered into HB text fields are not written to IHFS database
* remove the changes in 15695/15488, move the apostrophe fix into a more central position
*
* </pre>
*
@ -1810,7 +1811,7 @@ public class AddModifyLocationDlg extends CaveSWTDialog implements
/* Check if text fields in dataToSave include single apostrophe, if it do, replace to
two single apostrophe */
AppsDefaults ad = AppsDefaults.getInstance();
/* AppsDefaults ad = AppsDefaults.getInstance();
boolean debug = ad.getBoolean(HydroConstants.DEBUG_HYDRO_DB_TOKEN, false);
Class<?> c = dataToSave.getClass();
@ -1838,7 +1839,7 @@ public class AddModifyLocationDlg extends CaveSWTDialog implements
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}*/
// Save to DB via DataManager
try {

View file

@ -30,9 +30,10 @@ package com.raytheon.viz.hydrocommon.cresthistory;
* ------------ ---------- ----------- --------------------------
* Dec 11, 2008 1628 dhladky initial
* Nov 04, 2010 5518 lbousaid added all/above/bellow flag to
* getRiverCrestData
* getRiverCrestData
* Jan 09, 2015 16698 JingtaoD Crest History failed validation dialog pops up when OK button clicked
*
* April 08 2015 17338 JingtaoD "Apostrophe" entered into Hydrobase text fields in dialog window are not
* written to the IHFS database
* </pre>
*
* @author dhladky
@ -48,6 +49,7 @@ import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.viz.hydrocommon.HydroConstants;
import com.raytheon.viz.hydrocommon.data.RiverDataPoint;
import com.raytheon.viz.hydrocommon.datamanager.RiverDataManager;
import com.raytheon.viz.hydrocommon.datamanager.HydroDBDataManager;
public class CrestHistoryDataManager {
private static final transient IUFStatusHandler statusHandler = UFStatus
@ -107,6 +109,9 @@ public class CrestHistoryDataManager {
System.out.println("Query: " + deleteCrest);
}
// check if dataQuery contains any apostrophe, if does, replace it to two single appostrophe
deleteCrest = HydroDBDataManager.getInstance().checkAppostrophe(deleteCrest);
DirectDbQuery.executeStatement(deleteCrest, HydroConstants.IHFS,
QueryLanguage.SQL);
} catch (VizException ve) {
@ -151,6 +156,9 @@ public class CrestHistoryDataManager {
ad.getToken(HydroConstants.DB_NAME));
System.out.println("Query: " + query);
}
// check if dataQuery contains any apostrophe, if does, replace it to two single appostrophe
query = HydroDBDataManager.getInstance().checkAppostrophe(query);
DirectDbQuery.executeStatement(query, HydroConstants.IHFS, QueryLanguage.SQL);
} catch (VizException e) {
e.printStackTrace();
@ -206,6 +214,9 @@ public class CrestHistoryDataManager {
}
try {
// check if dataQuery contains any apostrophe, if does, replace it to two single appostrophe
insertCrest = HydroDBDataManager.getInstance().checkAppostrophe(insertCrest);
DirectDbQuery.executeStatement(insertCrest, HydroConstants.IHFS,
QueryLanguage.SQL);
} catch (VizException e) {
@ -273,8 +284,11 @@ public class CrestHistoryDataManager {
ad.getToken(HydroConstants.DB_NAME));
System.out.println("Query: " + query.toString());
}
DirectDbQuery.executeStatement(query.toString(), HydroConstants.IHFS, QueryLanguage.SQL);
// check if dataQuery contains any apostrophe, if does, replace it to two single appostrophe
String newquery = HydroDBDataManager.getInstance().checkAppostrophe(query.toString());
DirectDbQuery.executeStatement(newquery, HydroConstants.IHFS, QueryLanguage.SQL);
} catch (VizException e) {
errMsg = "Error updating data in database";
e.printStackTrace();

View file

@ -38,7 +38,7 @@ import com.raytheon.viz.hydrocommon.HydroConstants;
* Jan 3, 2013 15520 lbousaidi added a dollar-quoted string to getUpdate and
* getInsert statements to always write literally
* the string content.
* April 8, 2015 17338 jingtaoD "Apostrophes" entered into HB text fields are not written to IHFS database
*
* </pre>
*
@ -769,7 +769,7 @@ public class RiverStatData extends HydroDBData implements IHydroDBData {
String rval = "INSERT INTO riverstat ( " + columns
+ " ) VALUES ( %s, %s, %s, %s, %s, %s, %s,"
+ " %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, $$%s$$,%s,"
+ " %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, $$%s$$, %s,"
+ " %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s )";
rval = String.format(rval, getDBString(lid), getDBString(primaryPE),

View file

@ -19,6 +19,7 @@
**/
package com.raytheon.viz.hydrocommon.datamanager;
import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
@ -43,7 +44,7 @@ import com.raytheon.viz.hydrocommon.data.RatingShift;
* ------------ ---------- ----------- --------------------------
* Oct 22, 2008 1636 askripsky Initial Creation
* Sep 09, 2009 2259 mpduff Added rating shift data
*
* April 8, 2015 17338 jingtaoD add checkAppostrophe method
* </pre>
*
* @author askripsky
@ -110,7 +111,10 @@ public abstract class HydroDataManager {
System.out.println("Query: " + dataQuery);
}
QueryResult data = null;
// check if dataQuery contains any apostrophe, if does, replace it to two single appostrophe
dataQuery = checkAppostrophe(dataQuery);
data = DirectDbQuery.executeMappedQuery(dataQuery, HydroConstants.IHFS,
QueryLanguage.SQL);
@ -123,6 +127,7 @@ public abstract class HydroDataManager {
* @throws VizException
*/
public void runStatement(String dataQuery) throws VizException {
AppsDefaults ad = AppsDefaults.getInstance();
boolean debug = ad.getBoolean(HydroConstants.DEBUG_HYDRO_DB_TOKEN, false);
if (debug) {
@ -131,8 +136,89 @@ public abstract class HydroDataManager {
ad.getToken(HydroConstants.DB_NAME));
System.out.println("Query: " + dataQuery);
}
// check if dataQuery contains any apostrophe, if does, replace it to two single appostrophe
dataQuery = checkAppostrophe(dataQuery);
DirectDbQuery.executeStatement(dataQuery, HydroConstants.IHFS,
QueryLanguage.SQL);
QueryLanguage.SQL);
}
public String checkAppostrophe (String dataQuery) {
/* Check if text fields include single apostrophe, if it does, replace to
two single apostrophe since it is treated as special char in Postgres */
String newDataQuery = "";
String[] dataElement = dataQuery.split(", ");
for (int j = 0; j < dataElement.length; j++)
{
String elem = dataElement[j];
String newSubData = "";
String[] subdataElement = elem.split("=");
for (int i = 0; i < subdataElement.length; i++)
{
String subelem = subdataElement[i];
String likeStr="";
// handle the where clause contains "like '%'"
if (subelem.toUpperCase().contains("WHERE") &&
subelem.toUpperCase().contains("LIKE"))
{
int likeindex = subelem.toUpperCase().indexOf("LIKE");
likeStr = subelem.substring(likeindex , subelem.length());
subelem = subelem.substring(0, likeindex);
}
String endStr = "";
String beginStr = "";
String checkStr;
int startappostraphe, endappostraphe;
if (subelem.contains("'"))
{
if (subelem.startsWith("$$") && subelem.endsWith("$$"))
{
startappostraphe = subelem.indexOf("$$");
endappostraphe = subelem.lastIndexOf("$$");
checkStr = subelem.substring(startappostraphe+2, endappostraphe);
if (checkStr.contains("'"))
{
checkStr = checkStr.replace("'", "''");
subelem = "'" + checkStr +"'";
}
}
else
{
startappostraphe = subelem.indexOf("'");
endappostraphe = subelem.lastIndexOf("'");
checkStr = subelem.substring(startappostraphe+1, endappostraphe);
if (checkStr.contains("'"))
{
if (startappostraphe > 0)
beginStr = subelem.substring(0, startappostraphe);
if (endappostraphe + 1 < subelem.length())
endStr = subelem.substring(endappostraphe + 1, subelem.length());
checkStr = checkStr.replace("'", "''");
subelem = beginStr + "'" + checkStr +"'" + endStr;
}
}
}
if (i == subdataElement.length -1 )
newSubData = newSubData + subelem + likeStr;
else
newSubData = newSubData + subelem + "=";
}
if (j == dataElement.length - 1)
newDataQuery = newDataQuery + newSubData;
else
newDataQuery = newDataQuery + newSubData + ", ";
}
return newDataQuery;
}
/**