Merge tag 'OB_15.1.2-9' into master_16.1.1

15.1.2-9

Conflicts:
	cave/com.raytheon.viz.aviation/src/com/raytheon/viz/aviation/editor/TafViewerEditorDlg.java
	cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/data/RiverStatData.java
	cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/datamanager/ContactsDataManager.java
	cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/datamanager/DescriptionDataManager.java
	cave/com.raytheon.viz.hydrocommon/src/com/raytheon/viz/hydrocommon/datamanager/LocationAreaManager.java
	cave/com.raytheon.viz.texteditor/src/com/raytheon/viz/texteditor/dialogs/TextEditorDialog.java

Former-commit-id: e9e9660925d0afc016f88ec73182f9eae6ab0c18
This commit is contained in:
Shawn.Hooper 2015-10-15 17:10:19 -04:00
commit 90badd7a3e
27 changed files with 916 additions and 640 deletions

View file

@ -103,6 +103,7 @@ import com.raytheon.uf.common.python.PythonScript;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.common.time.ISimulatedTimeChangeListener;
import com.raytheon.uf.common.time.SimulatedTime;
import com.raytheon.uf.viz.core.RGBColors;
import com.raytheon.uf.viz.core.VizApp;
@ -132,10 +133,12 @@ import com.raytheon.viz.avnconfig.ITafSiteConfig;
import com.raytheon.viz.avnconfig.MessageStatusComp;
import com.raytheon.viz.avnconfig.TafSiteConfigFactory;
import com.raytheon.viz.avnconfig.TafSiteData;
import com.raytheon.viz.core.mode.CAVEMode;
import com.raytheon.viz.texteditor.TextDisplayModel;
import com.raytheon.viz.texteditor.msgs.IAviationObserver;
import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
import com.raytheon.viz.ui.dialogs.ICloseCallback;
import com.raytheon.viz.ui.simulatedtime.SimulatedTimeOperations;
/**
* This class displays the TAF Viewer and Editor dialog.
@ -243,6 +246,7 @@ import com.raytheon.viz.ui.dialogs.ICloseCallback;
* 04/07/2015 17332 zhao Added code to handle case of "Cancel" in "Restore From..."
* 06/23/2015 2282 skorolev Corrected "CLEAR" case in updateSettings.
* 06/26/2015 4588 skorolev Fixed Insert/Overwrite issue.
* Sep 28, 2015 4898 rferrel Disable sending of TAF when CAVE not in real time.
*
* </pre>
*
@ -251,10 +255,16 @@ import com.raytheon.viz.ui.dialogs.ICloseCallback;
*
*/
public class TafViewerEditorDlg extends CaveSWTDialog implements ITafSettable,
IEditActions {
ISimulatedTimeChangeListener, IEditActions {
private final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(TafViewerEditorDlg.class);
/**
* Developer can use this for debug purposes by making it true. This can go
* away once AlertViz respects the Priorty setting of the status handler.
*/
private static final boolean trace = false;
private final String SPLIT_REGEX = "=+[\\s\n]*|\n{2,}|\n$";
/**
@ -555,6 +565,7 @@ public class TafViewerEditorDlg extends CaveSWTDialog implements ITafSettable,
this.stationList = stationList;
setText("AvnFPS TAF Editor");
SimulatedTime.getSystemTime().addSimulatedTimeChangeListener(this);
}
/**
@ -641,6 +652,18 @@ public class TafViewerEditorDlg extends CaveSWTDialog implements ITafSettable,
// Select the editor tab on the tab folder.
tabFolder.setSelection(editorTab);
/*
* Queue the validation so that this dialog will be displayed prior
* to the validation. This allows any validate warning to be
* displayed over this dialog.
*/
VizApp.runAsync(new Runnable() {
@Override
public void run() {
validateTime();
}
});
// Do not set editorTafTabComp radial buttons here it can corrupt a
// populated selected tab.
// Any changes must be done after a open tab is found and populated.
@ -942,6 +965,7 @@ public class TafViewerEditorDlg extends CaveSWTDialog implements ITafSettable,
@Override
public void disposeDialog() {
disposeDialog = true;
SimulatedTime.getSystemTime().removeSimulatedTimeChangeListener(this);
AvnSmartToolJob.shutdown();
for (ViewerTab viewerTab : modelsTabs) {
viewerTab.dispose();
@ -1557,6 +1581,16 @@ public class TafViewerEditorDlg extends CaveSWTDialog implements ITafSettable,
// Make the editor tab the default selection on the tab folder.
tabFolder.setSelection(editorTab);
tabFolder.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
super.widgetSelected(e);
if (e.item == editorTab) {
validateTime();
}
}
});
}
/**
@ -1780,81 +1814,7 @@ public class TafViewerEditorDlg extends CaveSWTDialog implements ITafSettable,
sendBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
if (!SendDialog.isAuthorized()) {
return;
}
// Assume editorTafTabComp is for the active tab.
if (editorTafTabComp.isTafSent()) {
putMessageToForecaster("Cannot send forecast: Forecast already sent");
return;
} else if (editorTafTabComp.isSyntaxChecked()) {
if (disallowSend.equals("always")) {
putMessageToForecaster("Cannot send forecast: Send is disabled");
return;
}
// Flag to allow sending if the syntax error threshold is
// met.
boolean okToSend = true;
if (editorTafTabComp.isErrorsInBulletin()) {
if (disallowSend.equals("warning")
&& (editorTafTabComp.getErrorLevel() >= 1)) {
okToSend = false;
} else if (disallowSend.equals("error")
&& (editorTafTabComp.getErrorLevel() >= 2)) {
okToSend = false;
} else if (disallowSend.equals("fatal")
&& (editorTafTabComp.getErrorLevel() >= 3)) {
okToSend = false;
}
}
if (okToSend) {
if (confirmSend) {
String bbb = editorTafTabComp.getBBB();
if (bbb.startsWith("AA") || bbb.startsWith("CC")) {
MessageBox mb = new MessageBox(shell,
SWT.ICON_QUESTION | SWT.OK | SWT.CANCEL);
mb.setMessage("Attempting to send an AMD or COR TAF, please confirm.");
if (mb.open() == SWT.CANCEL) {
return;
}
}
}
} else {
putMessageToForecaster("Cannot send forecast: Bulletin has errors"
+ "\n"
+ "Use Clear Errors to send it without changes");
return;
}
if (autoPrintMI.getSelection()) {
printForecast(editorTafTabComp.getTextEditorControl()
.getText());
}
if (mustCreate(sendDlg)) {
sendDlg = new SendDialog(shell, editorTafTabComp,
msgStatComp, sendCollectMI.getSelection());
sendDlg.setCloseCallback(new ICloseCallback() {
@Override
public void dialogClosed(Object returnValue) {
// sendDlg sets the "taf sent" field only
if (editorTafTabComp.isTafSent()) {
editorTafTabComp.updateTafSent(true);
}
sendDlg = null;
}
});
sendDlg.open();
} else {
sendDlg.bringToTop();
}
} else {
putMessageToForecaster("Cannot send forecast: Press Syntax before transmission");
}
sendAction();
}
});
@ -2153,6 +2113,88 @@ public class TafViewerEditorDlg extends CaveSWTDialog implements ITafSettable,
return errorFound;
}
private void sendAction() {
if (!SendDialog.isAuthorized()) {
putMessageToForecaster("Not authorized to send TAF.");
return;
}
if (!validateTime()) {
return;
}
// Assume editorTafTabComp is for the active tab.
if (editorTafTabComp.isTafSent()) {
putMessageToForecaster("Cannot send forecast: Forecast already sent");
return;
} else if (editorTafTabComp.isSyntaxChecked()) {
if (disallowSend.equals("always")) {
putMessageToForecaster("Cannot send forecast: Send is disabled");
return;
}
// Flag to allow sending if the syntax error threshold is
// met.
boolean okToSend = true;
if (editorTafTabComp.isErrorsInBulletin()) {
if (disallowSend.equals("warning")
&& (editorTafTabComp.getErrorLevel() >= 1)) {
okToSend = false;
} else if (disallowSend.equals("error")
&& (editorTafTabComp.getErrorLevel() >= 2)) {
okToSend = false;
} else if (disallowSend.equals("fatal")
&& (editorTafTabComp.getErrorLevel() >= 3)) {
okToSend = false;
}
}
if (okToSend) {
if (confirmSend) {
String bbb = editorTafTabComp.getBBB();
if (bbb.startsWith("AA") || bbb.startsWith("CC")) {
MessageBox mb = new MessageBox(shell, SWT.ICON_QUESTION
| SWT.OK | SWT.CANCEL);
mb.setMessage("Attempting to send an AMD or COR TAF, please confirm.");
if (mb.open() == SWT.CANCEL) {
return;
}
}
}
} else {
putMessageToForecaster("Cannot send forecast: Bulletin has errors"
+ "\n" + "Use Clear Errors to send it without changes");
return;
}
if (autoPrintMI.getSelection()) {
printForecast(editorTafTabComp.getTextEditorControl().getText());
}
if (mustCreate(sendDlg)) {
sendDlg = new SendDialog(shell, editorTafTabComp, msgStatComp,
sendCollectMI.getSelection());
sendDlg.setCloseCallback(new ICloseCallback() {
@Override
public void dialogClosed(Object returnValue) {
// sendDlg sets the "taf sent" field only
if (editorTafTabComp.isTafSent()) {
editorTafTabComp.updateTafSent(true);
}
sendDlg = null;
}
});
sendDlg.open();
} else {
sendDlg.bringToTop();
}
} else {
putMessageToForecaster("Cannot send forecast: Press Syntax before transmission");
}
}
private void syntaxCheck() {
// Assume editorTafTabComp is for the active tab.
st = editorTafTabComp.getTextEditorControl();
@ -2723,8 +2765,9 @@ public class TafViewerEditorDlg extends CaveSWTDialog implements ITafSettable,
.getText());
setMessageStatusOK("Temporary WRKTAF Stored in DB");
} catch (Exception e) {
String msg = e.toString();
System.out.println(msg);
statusHandler
.error("Problem storing temporary WRKTAF in text product database.",
e);
}
}
}
@ -3118,12 +3161,16 @@ public class TafViewerEditorDlg extends CaveSWTDialog implements ITafSettable,
// The keys are: index, fatal, ident, amd, itime, vtime, group, and
// bbb
for (String k : parsedText.keySet()) {
// System.out.println("The outer key is " + k);
if (traceEnabled()) {
statusHandler.debug("The outer key is " + k);
}
if ((!k.equals("group")) && (!k.equals("bbb"))) {
HashMap<String, java.util.List<String>> m = (HashMap<String, java.util.List<String>>) parsedText
.get(k);
for (String k2 : m.keySet()) {
// System.out.println("The inner key is " + k2);
if (traceEnabled()) {
statusHandler.debug("The inner key is " + k2);
}
if (k2.equals("warning") || k2.equals("error")
|| k2.equals("fatal") || k2.equals("index")) {
results = m.get(k2);
@ -3155,29 +3202,43 @@ public class TafViewerEditorDlg extends CaveSWTDialog implements ITafSettable,
}
} else if (k.equals("group")) {
Object o1 = parsedText.get(k);
// System.out.println(o1.getClass().getName());
java.util.ArrayList<HashMap> lm1 = (java.util.ArrayList) o1;
for (HashMap<String, Object> m1 : lm1) {
if (traceEnabled()) {
statusHandler.debug(o1.getClass().getName());
}
java.util.List<Map<String, Object>> lm1 = (List<Map<String, Object>>) o1;
for (Map<String, Object> m1 : lm1) {
for (String k2 : m1.keySet()) {
// System.out.println("The next inner key is " +
// k2);
if (traceEnabled()) {
statusHandler.debug("The next inner key is "
+ k2);
}
Object o2 = m1.get(k2);
// System.out.println(o2.getClass().getName());
HashMap<String, Object> m2 = (HashMap) o2;
if (traceEnabled()) {
statusHandler.debug(o2.getClass().getName());
}
Map<String, Object> m2 = (Map<String, Object>) o2;
for (String k3 : m2.keySet()) {
// System.out.println("The next next inner key is "
// + k3);
if (traceEnabled()) {
statusHandler
.debug("The next next inner key is "
+ k3);
}
Object o3 = m2.get(k3);
// System.out.println(o3.getClass().getName());
if (o3.getClass().getName()
.equals("java.util.HashMap")) {
HashMap<String, Object> m3 = (HashMap) o3;
if (traceEnabled()) {
statusHandler
.debug(o3.getClass().getName());
}
if (o3 instanceof Map) {
Map<String, Object> m3 = (Map<String, Object>) o3;
for (String k4 : m3.keySet()) {
// System.out
// .println("The next next next inner key is "
// + k4);
// Object o4 = m3.get(k4);
// System.out.println(o4.getClass().getName());
if (traceEnabled()) {
statusHandler
.debug("The next next next inner key is "
+ k4);
Object o4 = m3.get(k4);
statusHandler.debug(o4.getClass()
.getName());
}
if (k4.equals("warning")
|| k4.equals("error")
|| k4.equals("fatal")
@ -3188,23 +3249,21 @@ public class TafViewerEditorDlg extends CaveSWTDialog implements ITafSettable,
if (k4.equals("index")) {
getRange(range, results);
} else {
// System.out
// .print("The result is: ");
for (String s : results) {
errorMsg.append(s);
}
// System.out.println("At line "
// + range[frLineIndex]
// + " in column "
// + range[frColIndex] +
// "...");
// System.out.println(errorMsg
// .toString());
// st.setCaretOffset(st
// .getOffsetAtLine(currentLineNo
// + range[frLineIndex]
// - 1)
// + range[frColIndex]);
if (traceEnabled()) {
StringBuilder sb = new StringBuilder();
sb.append(
"The result is: At line ")
.append(range[frLineIndex])
.append(" in column ")
.append(range[frColIndex])
.append("...\n")
.append(errorMsg);
statusHandler.debug(sb
.toString());
}
errorLevel = createErrorStyleRange(
"'"
+ errorMsg
@ -3230,9 +3289,9 @@ public class TafViewerEditorDlg extends CaveSWTDialog implements ITafSettable,
}
}
} else if (k.equals("bbb")) {
// Object o = parsedText.get(k);
// System.out.println(o.getClass().getName());
} else if (k.equals("bbb") && traceEnabled()) {
Object o = parsedText.get(k);
statusHandler.debug(o.getClass().getName());
}
}
}
@ -3700,7 +3759,6 @@ public class TafViewerEditorDlg extends CaveSWTDialog implements ITafSettable,
if (endIndex == -1) {
endIndex = in.length();
}
boolean isWrapping = false;
String thisSite = "";
String lastLine = "";
String line = in.substring(beginIndex, endIndex);
@ -3746,7 +3804,6 @@ public class TafViewerEditorDlg extends CaveSWTDialog implements ITafSettable,
if (lineNumber == keyLineNum) {
if (!isWrappingLine(line, thisSite)) {
isWrapping = false;
text = result.get("text").toString() + "\n";
level = Integer.parseInt(result
.get("level").toString());
@ -3760,7 +3817,6 @@ public class TafViewerEditorDlg extends CaveSWTDialog implements ITafSettable,
break;
} else {
// a PROB30 group is wrapped in two lines
isWrapping = true;
text = result.get("text").toString() + "\n";
level = Integer.parseInt(result
.get("level").toString());
@ -3874,8 +3930,6 @@ public class TafViewerEditorDlg extends CaveSWTDialog implements ITafSettable,
File path = pm.getStaticFile("aviation" + fs + "config" + fs
+ "gui" + fs + "SyntaxMonitorCfg.xml");
System.out.println("path = " + path);
syntaxMonCfg = JAXB.unmarshal(path, SyntaxMonitorCfg.class);
} catch (Exception e) {
@ -3952,7 +4006,7 @@ public class TafViewerEditorDlg extends CaveSWTDialog implements ITafSettable,
sb.append(TafUtil.safeFormatTaf(t, showHeaders));
sb.append("\n");
}
}// System.out.println("TEMPO "+sb.toString().indexOf("TEMPO")+"/"+sb.toString().indexOf("\n",72));
}
tafViewerStTxt.setText(sb.toString());
hightlightTAF();
@ -4010,27 +4064,27 @@ public class TafViewerEditorDlg extends CaveSWTDialog implements ITafSettable,
.getCurrentTempoMap(stationName);// 20120711
if (tempoMap != null) {
int tempoStart = taf.indexOf(TEMPO_TXT);
int tempoEnd = taf.indexOf(TafUtil.LINE_BREAK, tempoStart);// end
// of
// the
// TEMPO
// line
// end of the TEMPO line
int tempoEnd = taf.indexOf(TafUtil.LINE_BREAK, tempoStart);
StringBuilder str = new StringBuilder(" ");
for (String alertKey : tempoMap.keySet()) {
// System.out.println("2___alertKey: "+ alertKey);
if (traceEnabled()) {
statusHandler.debug("2___alertKey: " + alertKey);
}
for (String value : tempoMap.get(alertKey)) {
// System.out.println("3___value: "+ value);
if (traceEnabled()) {
statusHandler.debug("3___value: " + value);
}
str.setLength(1);
str.append(value);
int len = str.length();
str.append(" ");
// for tempo only
int startIndex = taf
.indexOf(str.toString(), tempoStart);// for
// tempo
// only
.indexOf(str.toString(), tempoStart);
if (startIndex < 0) {
str.setLength(len);
@ -4300,7 +4354,7 @@ public class TafViewerEditorDlg extends CaveSWTDialog implements ITafSettable,
font.dispose();
printer.dispose();
} else {
System.out.println("No default printer set.");
putMessageToForecaster("Auto Print failed. No default printer set.");
}
}
@ -4317,13 +4371,8 @@ public class TafViewerEditorDlg extends CaveSWTDialog implements ITafSettable,
// Only load the latest TAF, and assume it is the first one in
// the Viewer.
sb.append(TafUtil.safeFormatTaf(tafsInViewer[0], false));
String originalBbb = "";
String[] header = tafsInViewer[0].getWmoHeader().split(" ");
if (header.length > 3) {
originalBbb = header[3];
}
ITafSiteConfig config = TafSiteConfigFactory.getInstance();
TafSiteData siteData = config.getSite(site);
@ -4500,6 +4549,45 @@ public class TafViewerEditorDlg extends CaveSWTDialog implements ITafSettable,
}
}
/**
* Validate CAVE can send a TAF.
*
* @return true when in real time.
*/
private boolean validateTime() {
if ((shell != null) && !shell.isDisposed() && shell.isVisible()) {
/*
* Currently practice mode not supported.
*/
if (CAVEMode.getMode() == CAVEMode.PRACTICE) {
putMessageToForecaster("Not allowed to send TAF when in practice mode.");
return false;
} else if (!SimulatedTimeOperations.isTransmitAllowed()) {
SimulatedTimeOperations.displayFeatureLevelWarning(shell,
"Send TAF");
return false;
}
}
return true;
}
@Override
public void timechanged() {
validateTime();
}
/**
*
* @return
*/
private boolean traceEnabled() {
/*
* TODO When alertviz respects Prioirty change this to use the
* statusHander priority debug enabled.
*/
return trace;
}
/**
* Internal class to up date the Viewer tab highlights when the Metar tab
* selections change what should be highlighted.

View file

@ -178,8 +178,9 @@ HazardsConflictDict = {
"SC.Y", "SW.Y", "SE.W", "RB.Y", "SI.Y", "CF.S", "TY.W",
"GL.A", "SR.A", "HF.A", "SE.A", "CF.W", "CF.A", "CF.Y",
"SU.W", "SU.Y"],
"TS.A" : ["TS.W"],
"TS.W" : ["TS.A"],
"TS.A" : ["TS.W", "TS.Y"],
"TS.W" : ["TS.A", "TS.Y"],
"TS.Y" : ["TS.A", "TS.W"],
"TY.A" : ["TR.A", "TY.W", "HU.S", "HF.W", "GL.A", "SR.A", "HF.A", "SE.A", "CF.A", "CF.S"],
"TY.W" : ["TY.A", "HU.S", "TR.A", "TR.W", "GL.A", "SR.A", "HF.A", "SE.A", "CF.A", "CF.S", "SU.Y",
"GL.W", "SR.W", "HF.W", "BW.Y","SC.Y", "SW.Y", "SE.W", "RB.Y", "SI.Y", "CF.W", "CF.Y", "SU.W"],

View file

@ -62,7 +62,7 @@ hazardDict = OrderedDict([
"GL.A", "GL.W", "SE.A", "SE.W", "UP.A", "UP.W", "HF.A", "HF.W", "LO.Y", "SC.Y", "SW.Y",
"RB.Y", "SI.Y", "MS.Y", "SR.A", "SR.W"]),
('Tropical Cyclone', ["HU.W", "HU.A", "TR.W", "TR.A"]),
('Tsunami', ["TS.A", "TS.W"]),
('Tsunami', ["TS.A", "TS.W", "TS.Y"]),
# ('Local', ["TEST"]), #example of adding local hazards
# you can define your own groups of hazards by adding new categories

View file

@ -86,8 +86,7 @@ public class ShowIscRequestReplyDialog extends AbstractHandler {
public boolean isEnabled() {
DataManager dm = DataManagerUIFactory.getCurrentInstance();
if (dm != null) {
return (!dm.sendIscOnSave() || !dm.sendIscOnPublish())
&& CAVEMode.getMode().equals(CAVEMode.OPERATIONAL)
return CAVEMode.getMode().equals(CAVEMode.OPERATIONAL)
&& dm.requestISC();
}

View file

@ -69,6 +69,7 @@ import com.raytheon.uf.viz.core.VizApp;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.core.requests.ThriftClient;
import com.raytheon.viz.hydrocommon.HydroConstants;
import com.raytheon.viz.hydrocommon.util.DbUtils;
import com.raytheon.viz.hydrocommon.util.RatingUtils;
import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
@ -1202,6 +1203,8 @@ public class FloodReportDlg extends CaveSWTDialog {
sql.append(", q");
}
cremark = DbUtils.escapeSpecialCharforStr(cremark);
sql.append(") values('" + data.getLid() + "', ");
sql.append("'" + dateFormat.format(eventDate) + "', ");
sql.append("'" + hourFormat.format(eventDate) + "', ");

View file

@ -31,6 +31,7 @@ import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.viz.hydrocommon.HydroConstants;
import com.raytheon.viz.hydrocommon.HydroConstants.ArealTypeSelection;
import com.raytheon.viz.hydrocommon.datamanager.HydroDataManager;
import com.raytheon.viz.hydrocommon.util.DbUtils;
/**
* GeoData Data Manager class.
@ -50,7 +51,8 @@ import com.raytheon.viz.hydrocommon.datamanager.HydroDataManager;
*/
public class GeoDataManager extends HydroDataManager {
private static final transient IUFStatusHandler statusHandler = UFStatus.getHandler(GeoDataManager.class);
private static final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(GeoDataManager.class);
private static GeoDataManager instance = null;
private GeoDataManager() {
@ -60,8 +62,7 @@ public class GeoDataManager extends HydroDataManager {
/**
* Get an instance of this class
*
* @return
* The instance
* @return The instance
*/
public static synchronized GeoDataManager getInstance() {
if (instance == null) {
@ -75,17 +76,15 @@ public class GeoDataManager extends HydroDataManager {
* Get the GeoAreas.
*
* @param type
* The type of area looking for
* @return
* List of GeoAreaData objects
* The type of area looking for
* @return List of GeoAreaData objects
* @throws VizException
*/
public ArrayList<GeoAreaData> getGeoArea(ArealTypeSelection type)
throws VizException {
ArrayList<GeoAreaData> returnList = new ArrayList<GeoAreaData>();
StringBuilder query = new StringBuilder();
query
.append("select area_id, name, boundary_type, interior_lat, interior_lon from geoarea ");
query.append("select area_id, name, boundary_type, interior_lat, interior_lon from geoarea ");
query.append(" where boundary_type = '"
+ HydroConstants.GEOAREA_DATANAMES[type.ordinal()]
+ "' order by area_id");
@ -111,9 +110,8 @@ public class GeoDataManager extends HydroDataManager {
* Delete data from the linesegs table.
*
* @param type
* The type of data to delete
* @return
* The number of lines modified
* The type of data to delete
* @return The number of lines modified
* @throws VizException
*/
public int deleteLineSegs(String type) throws VizException {
@ -129,10 +127,10 @@ public class GeoDataManager extends HydroDataManager {
/**
* Delete data from the geoarea table.
*
* @param type
* The type of data to delete
* @return
* The number of lines modified
* The type of data to delete
* @return The number of lines modified
* @throws VizException
*/
public int deleteGeoArea(String type) throws VizException {
@ -149,9 +147,8 @@ public class GeoDataManager extends HydroDataManager {
* Write the GeoAreaData data to the IHFS
*
* @param data
* The GeoAreaData object to write
* @return
* The number of rows modified
* The GeoAreaData object to write
* @return The number of rows modified
* @throws VizException
*/
public int putGeoArea(GeoAreaData data) throws VizException {
@ -171,6 +168,8 @@ public class GeoDataManager extends HydroDataManager {
return status;
}
DbUtils.escapeSpecialCharforData(data);
/*
* if the interior lat, lon were provided from the input file, then use
* them. otherwise compute them.
@ -230,9 +229,9 @@ public class GeoDataManager extends HydroDataManager {
* Write thte line segments to the linesegs table
*
* @param areaId
* The area id
* The area id
* @param binList
* The HrapBinList
* The HrapBinList
*/
public void putLineSegs(String areaId, HrapBinList binList) {
int status = 0;
@ -276,7 +275,8 @@ public class GeoDataManager extends HydroDataManager {
} catch (VizException e) {
status = -1;
statusHandler.handle(Priority.PROBLEM,
"Error putting data into LineSegs for area_id: " + areaId);
"Error putting data into LineSegs for area_id: "
+ areaId);
}
} else {
/* delete the record and insert the new record */

View file

@ -32,8 +32,7 @@ package com.raytheon.viz.hydrocommon.cresthistory;
* Nov 04, 2010 5518 lbousaid added all/above/bellow flag to
* 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
@ -50,6 +49,7 @@ 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;
import com.raytheon.viz.hydrocommon.util.DbUtils;
public class CrestHistoryDataManager {
private static final transient IUFStatusHandler statusHandler = UFStatus
@ -82,7 +82,8 @@ public class CrestHistoryDataManager {
* @param rdp
* @return
*/
public CrestHistoryData getRiverCrestData(String lid, boolean control, int allFlag) {
public CrestHistoryData getRiverCrestData(String lid, boolean control,
int allFlag) {
RiverDataManager rdm = RiverDataManager.getInstance();
RiverDataPoint rdp = rdm.getRiverDataPoint(lid);
@ -96,27 +97,24 @@ public class CrestHistoryDataManager {
* @param cd
*/
public void deleteCrest(CrestData cd, String lid) {
String deleteCrest = "delete from crest where lid = '" + lid + "' and datcrst = '"
+ cd.getDateString() + "' and timcrst ='" + cd.getTimeString()
+ "'";
String deleteCrest = "delete from crest where lid = '" + lid
+ "' and datcrst = '" + cd.getDateString() + "' and timcrst ='"
+ cd.getTimeString() + "'";
try {
AppsDefaults ad = AppsDefaults.getInstance();
boolean debug = ad.getBoolean(HydroConstants.DEBUG_HYDRO_DB_TOKEN, false);
boolean debug = ad.getBoolean(HydroConstants.DEBUG_HYDRO_DB_TOKEN,
false);
if (debug) {
System.out.println(ad.getToken(HydroConstants.PGHOST) + ":" +
ad.getToken(HydroConstants.PGPORT) + ":" +
ad.getToken(HydroConstants.DB_NAME));
System.out.println(ad.getToken(HydroConstants.PGHOST) + ":"
+ ad.getToken(HydroConstants.PGPORT) + ":"
+ ad.getToken(HydroConstants.DB_NAME));
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) {
statusHandler.error("Error deleting the crest: "
+ lid, ve);
statusHandler.error("Error deleting the crest: " + lid, ve);
}
}
@ -124,42 +122,49 @@ public class CrestHistoryDataManager {
* Insert/update a crest.
*
* @param cd
* The CrestData object holding data for database
* The CrestData object holding data for database
* @param lid
* The current lid
* The current lid
* @param selectedCrest
* The crest data currently in the database
* The crest data currently in the database
* @param mode
* The mode, 1 = new, 2 = delete, 3 = update
* The mode, 1 = new, 2 = delete, 3 = update
* @return Error Message, or null if no errors
* @throws VizException
*/
public String insertCrest(CrestData cd, String lid, CrestData selectedCrest, int mode) {
public String insertCrest(CrestData cd, String lid,
CrestData selectedCrest, int mode) {
String errMsg = null;
DbUtils.escapeSpecialCharforData(cd);
if (mode == 3) {
// Did the primary key change?
if ((selectedCrest != null) && (cd.getDateString().equals(selectedCrest.getDateString())
&& cd.getTimeString().equals(selectedCrest.getTimeString()))) {
if ((selectedCrest != null)
&& (cd.getDateString()
.equals(selectedCrest.getDateString()) && cd
.getTimeString().equals(
selectedCrest.getTimeString()))) {
// The PK is different, delete the record, then insert
String query = "delete from crest where lid = '" + lid +
"' and datcrst = '" + selectedCrest.getDateString() +
"' and timcrst = '" + selectedCrest.getTimeString() + "'";
String query = "delete from crest where lid = '" + lid
+ "' and datcrst = '" + selectedCrest.getDateString()
+ "' and timcrst = '" + selectedCrest.getTimeString()
+ "'";
try {
AppsDefaults ad = AppsDefaults.getInstance();
boolean debug = ad.getBoolean(HydroConstants.DEBUG_HYDRO_DB_TOKEN, false);
boolean debug = ad.getBoolean(
HydroConstants.DEBUG_HYDRO_DB_TOKEN, false);
if (debug) {
System.out.println(ad.getToken(HydroConstants.PGHOST) + ":" +
ad.getToken(HydroConstants.PGPORT) + ":" +
ad.getToken(HydroConstants.DB_NAME));
System.out.println(ad.getToken(HydroConstants.PGHOST)
+ ":" + ad.getToken(HydroConstants.PGPORT)
+ ":" + 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);
DirectDbQuery.executeStatement(query, HydroConstants.IHFS,
QueryLanguage.SQL);
} catch (VizException e) {
e.printStackTrace();
}
@ -176,7 +181,7 @@ public class CrestHistoryDataManager {
remarks = remarks.replaceAll("\n", "\\n");
back.append("'" + remarks + "', ");
front.append("cremark, ");
// back.append("'" + cd.getRemarks() + "', ");
// back.append("'" + cd.getRemarks() + "', ");
}
if (cd.isHighWater()) {
front.append("hw, ");
@ -205,27 +210,26 @@ public class CrestHistoryDataManager {
boolean executeUpdate = false;
AppsDefaults ad = AppsDefaults.getInstance();
boolean debug = ad.getBoolean(HydroConstants.DEBUG_HYDRO_DB_TOKEN, false);
boolean debug = ad.getBoolean(HydroConstants.DEBUG_HYDRO_DB_TOKEN,
false);
if (debug) {
System.out.println(ad.getToken(HydroConstants.PGHOST) + ":" +
ad.getToken(HydroConstants.PGPORT) + ":" +
ad.getToken(HydroConstants.DB_NAME));
System.out.println(ad.getToken(HydroConstants.PGHOST) + ":"
+ ad.getToken(HydroConstants.PGPORT) + ":"
+ ad.getToken(HydroConstants.DB_NAME));
System.out.println("Query: " + insertCrest);
}
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) {
e.printStackTrace();
e.printStackTrace();
//exception with duplicate key value is throwed in the 2nd cause
// exception with duplicate key value is throwed in the 2nd cause
if (e.getCause().getCause().getMessage().contains("crest_pk")) {
if (e.getCause().getCause().getMessage().contains("crest_pk")) {
executeUpdate = true;
} else {
errMsg = "Error inserting data into database.";
@ -236,14 +240,14 @@ public class CrestHistoryDataManager {
/* execute an update */
StringBuilder query = new StringBuilder("update crest set ");
// query.append("lid = '" + lid + "', ");
// query.append("datcrst = '" + cd.getDateString() + "', ");
// query.append("lid = '" + lid + "', ");
// query.append("datcrst = '" + cd.getDateString() + "', ");
if (cd.getRemarks() != null) {
String remarks = cd.getRemarks();
remarks = remarks.replace("\n", "\\n");
query.append("cremark = E'" + remarks + "', ");
// query.append("cremark = '" + cd.getRemarks() + "', ");
// query.append("cremark = '" + cd.getRemarks() + "', ");
}
if (cd.isHighWater()) {
@ -279,16 +283,14 @@ public class CrestHistoryDataManager {
query.append("and timcrst = '" + cd.getTimeString() + "' ");
try {
if (debug) {
System.out.println(ad.getToken(HydroConstants.PGHOST) + ":" +
ad.getToken(HydroConstants.PGPORT) + ":" +
ad.getToken(HydroConstants.DB_NAME));
System.out.println(ad.getToken(HydroConstants.PGHOST) + ":"
+ ad.getToken(HydroConstants.PGPORT) + ":"
+ ad.getToken(HydroConstants.DB_NAME));
System.out.println("Query: " + query.toString());
}
// 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);
DirectDbQuery.executeStatement(query.toString(),
HydroConstants.IHFS, QueryLanguage.SQL);
} catch (VizException e) {
errMsg = "Error updating data in database";
e.printStackTrace();

View file

@ -784,7 +784,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, %s, %s )";
rval = String.format(rval, getDBString(lid), getDBString(primaryPE),
@ -830,7 +830,7 @@ public class RiverStatData extends HydroDBData implements IHydroDBData {
public String getUpdateStatement() {
// Set the basic update statement
String rval = "UPDATE riverstat SET lid=%s, primary_pe=%s, bf=%s, cb=%s, da=%s, response_time=%s, threshold_runoff=%s,"
+ " fq=%s, fs=%s, gsno=%s, level=%s, mile=%s, pool=%s, por=%s, rated=%s, lat=%s, lon=%s, remark=$$%s$$, rrevise=%s,"
+ " fq=%s, fs=%s, gsno=%s, level=%s, mile=%s, pool=%s, por=%s, rated=%s, lat=%s, lon=%s, remark='%s', rrevise=%s,"
+ " rsource=%s, stream=%s, tide=%s, backwater=%s, vdatum=%s, action_flow=%s, wstg=%s, zd=%s, ratedat=%s,"
+ " usgs_ratenum=%s, uhgdur=%s, use_latest_fcst=%s, issuestg=%s, issueflow=%s WHERE %s";

View file

@ -25,6 +25,7 @@ import com.raytheon.uf.common.dataquery.db.QueryResult;
import com.raytheon.uf.common.dataquery.db.QueryResultRow;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.viz.hydrocommon.data.ContactsData;
import com.raytheon.viz.hydrocommon.util.DbUtils;
/**
* This class is the data manager for the contacts data.
@ -42,8 +43,7 @@ import com.raytheon.viz.hydrocommon.data.ContactsData;
* @author lvenable
* @version 1.0
*/
public class ContactsDataManager extends HydroDataManager
{
public class ContactsDataManager extends HydroDataManager {
/**
* Instance of this class.
*/
@ -72,12 +72,12 @@ public class ContactsDataManager extends HydroDataManager
/**
* Constructor.
*/
public ContactsDataManager()
{
public ContactsDataManager() {
}
/**
* Get an instance of this class.
*
* @return An instance of this class.
*/
public static synchronized ContactsDataManager getInstance() {
@ -90,12 +90,15 @@ public class ContactsDataManager extends HydroDataManager
/**
* Get the list of contacts from the specified location ID.
* @param lid Location ID.
*
* @param lid
* Location ID.
* @return ArrayList of ContactsData.
* @throws VizException Database exception.
* @throws VizException
* Database exception.
*/
public ArrayList<ContactsData> getContactData(String lid) throws VizException
{
public ArrayList<ContactsData> getContactData(String lid)
throws VizException {
ArrayList<ContactsData> rval = new ArrayList<ContactsData>();
QueryResult result = runMappedQuery(SELECT_STATEMENT + " WHERE lid='"
@ -109,15 +112,21 @@ public class ContactsDataManager extends HydroDataManager
}
/**
* Delete the record from the database the specified location ID and Contact.
* @param contactsData Contacts data.
* @throws VizException Database exception.
* Delete the record from the database the specified location ID and
* Contact.
*
* @param contactsData
* Contacts data.
* @throws VizException
* Database exception.
*/
public void deleteRecord(ContactsData contactsData) throws VizException
{
public void deleteRecord(ContactsData contactsData) throws VizException {
DbUtils.escapeSpecialCharforData(contactsData);
StringBuilder query = new StringBuilder(DELETE_STATEMENT);
String whereClaus = String.format(" WHERE lid = '%s' AND contact = '%s' ",
contactsData.getLid(), contactsData.getContact());
String whereClaus = String.format(
" WHERE lid = '%s' AND contact = '%s' ", contactsData.getLid(),
contactsData.getContact());
query.append(whereClaus);
runStatement(query.toString());
@ -125,23 +134,28 @@ public class ContactsDataManager extends HydroDataManager
/**
* Check if a specific record exists in the contacts table.
* @param lid Location ID.
* @param contactName Contact name.
*
* @param lid
* Location ID.
* @param contactName
* Contact name.
* @return True if the record exists, false otherwise.
* @throws VizException Database exception.
* @throws VizException
* Database exception.
*/
public boolean recordExists(String lid, String contactName) throws VizException
{
public boolean recordExists(String lid, String contactName)
throws VizException {
contactName = DbUtils.escapeSpecialCharforStr(contactName);
StringBuilder query = new StringBuilder(SELECT_STATEMENT);
String whereClaus = String.format(" WHERE lid = '%s' AND contact = '%s' ",
lid, contactName);
String whereClaus = String.format(
" WHERE lid = '%s' AND contact = '%s' ", lid, contactName);
query.append(whereClaus);
QueryResult result = runMappedQuery(query.toString());
if (result.getResultCount() == 0)
{
if (result.getResultCount() == 0) {
return false;
}
@ -150,11 +164,15 @@ public class ContactsDataManager extends HydroDataManager
/**
* Insert the new contact data into the database.
* @param data Contacts data.
* @throws VizException Database exception.
*
* @param data
* Contacts data.
* @throws VizException
* Database exception.
*/
public void insertContactData(ContactsData data) throws VizException
{
public void insertContactData(ContactsData data) throws VizException {
DbUtils.escapeSpecialCharforData(data);
String query = String.format(INSERT_STATEMENT, data.getLid(),
data.getContact(), data.getPhone(), data.getEmail(),
data.getRemark(), data.getPriority());
@ -164,12 +182,18 @@ public class ContactsDataManager extends HydroDataManager
/**
* Update an existing record in the contacts table with the new information.
* @param data Contacts data.
* @throws VizException Database exception.
*
* @param data
* Contacts data.
* @throws VizException
* Database exception.
*/
public void updateContactData(ContactsData data,
String originalContactName) throws VizException
{
public void updateContactData(ContactsData data, String originalContactName)
throws VizException {
DbUtils.escapeSpecialCharforData(data);
originalContactName = DbUtils
.escapeSpecialCharforStr(originalContactName);
String query = String.format(UPDATE_STATEMENT, data.getContact(),
data.getPhone(), data.getEmail(), data.getRemark(),
data.getPriority(), data.getLid(), originalContactName);

View file

@ -25,6 +25,7 @@ import com.raytheon.uf.common.dataquery.db.QueryResult;
import com.raytheon.uf.common.dataquery.db.QueryResultRow;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.viz.hydrocommon.data.DescriptionData;
import com.raytheon.viz.hydrocommon.util.DbUtils;
/**
* This class is the data manager for the description data.
@ -42,8 +43,7 @@ import com.raytheon.viz.hydrocommon.data.DescriptionData;
* @author lvenable
* @version 1.0
*/
public class DescriptionDataManager extends HydroDataManager
{
public class DescriptionDataManager extends HydroDataManager {
/**
* Instance of this class.
*/
@ -57,8 +57,7 @@ public class DescriptionDataManager extends HydroDataManager
/**
* Insert statement.
*/
private final String INSERT_STATEMENT =
"INSERT INTO descrip (lid, bed, divert, remark, ice, proximity, reach, res, topo) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')";
private final String INSERT_STATEMENT = "INSERT INTO descrip (lid, bed, divert, remark, ice, proximity, reach, res, topo) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')";
/**
* Delete statement.
@ -68,18 +67,17 @@ public class DescriptionDataManager extends HydroDataManager
/**
* Update statement.
*/
private final String UPDATE_STATEMENT =
"UPDATE descrip SET bed='%s', divert='%s', remark='%s', ice='%s', proximity='%s', reach='%s', res='%s', topo='%s' WHERE lid='%s'";
private final String UPDATE_STATEMENT = "UPDATE descrip SET bed='%s', divert='%s', remark='%s', ice='%s', proximity='%s', reach='%s', res='%s', topo='%s' WHERE lid='%s'";
/**
* Private Constructor.
*/
private DescriptionDataManager()
{
private DescriptionDataManager() {
}
/**
* Get an instance of this class.
*
* @return An instance of this class.
*/
public static synchronized DescriptionDataManager getInstance() {
@ -92,12 +90,15 @@ public class DescriptionDataManager extends HydroDataManager
/**
* Get the description data.
* @param lid Location ID.
*
* @param lid
* Location ID.
* @return An array of description data.
* @throws VizException Database exception.
* @throws VizException
* Database exception.
*/
public ArrayList<DescriptionData> getDescriptionData(String lid) throws VizException
{
public ArrayList<DescriptionData> getDescriptionData(String lid)
throws VizException {
ArrayList<DescriptionData> rval = new ArrayList<DescriptionData>();
QueryResult result = runMappedQuery(SELECT_STATEMENT + " WHERE lid='"
@ -112,11 +113,13 @@ public class DescriptionDataManager extends HydroDataManager
/**
* Delete a specified description.
* @param lid Location ID.
* @throws VizException Database exception.
*
* @param lid
* Location ID.
* @throws VizException
* Database exception.
*/
public void deleteDescription(String lid) throws VizException
{
public void deleteDescription(String lid) throws VizException {
StringBuilder query = new StringBuilder(DELETE_STATEMENT);
String whereClaus = String.format(" WHERE lid = '%s'", lid);
query.append(whereClaus);
@ -126,14 +129,20 @@ public class DescriptionDataManager extends HydroDataManager
/**
* Insert description data.
* @param descData Description data.
* @throws VizException Database exception.
*
* @param descData
* Description data.
* @throws VizException
* Database exception.
*/
public void insertDescriptionData(DescriptionData descData) throws VizException
{
public void insertDescriptionData(DescriptionData descData)
throws VizException {
DbUtils.escapeSpecialCharforData(descData);
String query = String.format(INSERT_STATEMENT, descData.getLid(),
descData.getStreamBed(), descData.getDivert(), descData.getRemark(),
descData.getIce(), descData.getProximity(), descData.getReach(),
descData.getStreamBed(), descData.getDivert(),
descData.getRemark(), descData.getIce(),
descData.getProximity(), descData.getReach(),
descData.getRegulation(), descData.getTopo());
runStatement(query);
@ -141,27 +150,36 @@ public class DescriptionDataManager extends HydroDataManager
/**
* Update description data.
* @param descData Description data.
* @throws VizException Database exception.
*
* @param descData
* Description data.
* @throws VizException
* Database exception.
*/
public void updateDescriptionData(DescriptionData descData) throws VizException
{
String query = String.format(UPDATE_STATEMENT,
descData.getStreamBed(), descData.getDivert(), descData.getRemark(),
descData.getIce(), descData.getProximity(), descData.getReach(),
descData.getRegulation(), descData.getTopo(), descData.getLid());
public void updateDescriptionData(DescriptionData descData)
throws VizException {
DbUtils.escapeSpecialCharforData(descData);
String query = String
.format(UPDATE_STATEMENT, descData.getStreamBed(),
descData.getDivert(), descData.getRemark(),
descData.getIce(), descData.getProximity(),
descData.getReach(), descData.getRegulation(),
descData.getTopo(), descData.getLid());
runStatement(query);
}
/**
* Check if a record exists.
* @param lid Location ID.
*
* @param lid
* Location ID.
* @return True if the record exists, false otherwise.
* @throws VizException Database exception.
* @throws VizException
* Database exception.
*/
public boolean recordExists(String lid) throws VizException
{
public boolean recordExists(String lid) throws VizException {
StringBuilder query = new StringBuilder(SELECT_STATEMENT);
String whereClaus = String.format(" WHERE lid = '%s'", lid);
@ -169,8 +187,7 @@ public class DescriptionDataManager extends HydroDataManager
QueryResult result = runMappedQuery(query.toString());
if (result.getResultCount() == 0)
{
if (result.getResultCount() == 0) {
return false;
}

View file

@ -29,6 +29,7 @@ import com.raytheon.uf.common.dataquery.db.QueryResult;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.viz.hydrocommon.HydroConstants;
import com.raytheon.viz.hydrocommon.data.FloodCategoryData;
import com.raytheon.viz.hydrocommon.util.DbUtils;
import com.raytheon.viz.hydrocommon.util.HydroDataUtils;
/**
@ -50,7 +51,6 @@ import com.raytheon.viz.hydrocommon.util.HydroDataUtils;
public class FloodCategoryDataManager extends HydroDataManager {
protected static FloodCategoryDataManager manager = null;
private static final String INSERT_STATEMENT = "INSERT INTO floodcat (lid, major_stage, moderate_stage, minor_stage, major_flow, moderate_flow, minor_flow) VALUES ('%s', %s, %s, %s, %s, %s, %s)";
private static final String SELECT_STATEMENT = "SELECT lid, major_stage, moderate_stage, minor_stage, major_flow, moderate_flow, minor_flow FROM floodcat";
@ -100,8 +100,8 @@ public class FloodCategoryDataManager extends HydroDataManager {
*/
public void deleteRecord(FloodCategoryData recordToDelete)
throws VizException {
runStatement(String.format(DELETE_STATEMENT, HydroDataUtils
.getPKStatement(recordToDelete)));
runStatement(String.format(DELETE_STATEMENT,
HydroDataUtils.getPKStatement(recordToDelete)));
}
/**
@ -128,8 +128,8 @@ public class FloodCategoryDataManager extends HydroDataManager {
QueryResult result = runMappedQuery(SELECT_STATEMENT + " WHERE lid='"
+ lid + "'");
return (result.getResultCount() > 0) ? new FloodCategoryData(result
.getRows()[0], result.getColumnNames())
return (result.getResultCount() > 0) ? new FloodCategoryData(
result.getRows()[0], result.getColumnNames())
: new FloodCategoryData();
}
@ -149,48 +149,54 @@ public class FloodCategoryDataManager extends HydroDataManager {
private void updateFloodCategoryData(FloodCategoryData data)
throws VizException {
Double majorS =null, minorS=null, moderateS=null, majorD=null, minorD=null, moderateD=null;
Double majorS = null, minorS = null, moderateS = null, majorD = null, minorD = null, moderateD = null;
if (data.getMajorStage() != HydroConstants.MISSING_VALUE)
majorS = data.getMajorStage();
if (data.getModerateStage() != HydroConstants.MISSING_VALUE)
moderateS = data.getModerateStage();
if (data.getMinorStage() != HydroConstants.MISSING_VALUE)
minorS = data.getMinorStage();
if (data.getMajorDischarge() != HydroConstants.MISSING_VALUE)
majorD = data.getMajorDischarge();
if (data.getModerateDischarge() != HydroConstants.MISSING_VALUE)
moderateD = data.getModerateDischarge();
if (data.getMinorDischarge() != HydroConstants.MISSING_VALUE)
minorD = data.getMinorDischarge();
DbUtils.escapeSpecialCharforData(data);
if (data.getMajorStage() != HydroConstants.MISSING_VALUE)
majorS = data.getMajorStage();
if (data.getModerateStage() != HydroConstants.MISSING_VALUE)
moderateS = data.getModerateStage();
if (data.getMinorStage() != HydroConstants.MISSING_VALUE)
minorS = data.getMinorStage();
if (data.getMajorDischarge() != HydroConstants.MISSING_VALUE)
majorD = data.getMajorDischarge();
if (data.getModerateDischarge() != HydroConstants.MISSING_VALUE)
moderateD = data.getModerateDischarge();
if (data.getMinorDischarge() != HydroConstants.MISSING_VALUE)
minorD = data.getMinorDischarge();
/*check if any of the stages or flows is missing, then assign null into database;*/
runStatement(String.format(UPDATE_STATEMENT, majorS, moderateS, minorS, majorD,
moderateD, minorD, HydroDataUtils.getPKStatement(data)));
/*
* check if any of the stages or flows is missing, then assign null into
* database;
*/
runStatement(String.format(UPDATE_STATEMENT, majorS, moderateS, minorS,
majorD, moderateD, minorD, HydroDataUtils.getPKStatement(data)));
}
private void insertFloodData(FloodCategoryData currData)
throws VizException {
Double majorS =null, minorS=null, moderateS=null, majorD=null, minorD=null, moderateD=null;
Double majorS = null, minorS = null, moderateS = null, majorD = null, minorD = null, moderateD = null;
if (currData.getMajorStage() != HydroConstants.MISSING_VALUE)
majorS = currData.getMajorStage();
if (currData.getModerateStage() != HydroConstants.MISSING_VALUE)
moderateS = currData.getModerateStage();
if (currData.getMinorStage() != HydroConstants.MISSING_VALUE)
minorS = currData.getMinorStage();
if (currData.getMajorDischarge() != HydroConstants.MISSING_VALUE)
majorD = currData.getMajorDischarge();
if (currData.getModerateDischarge() != HydroConstants.MISSING_VALUE)
moderateD = currData.getModerateDischarge();
if (currData.getMinorDischarge() != HydroConstants.MISSING_VALUE)
minorD = currData.getMinorDischarge();
DbUtils.escapeSpecialCharforData(currData);
/* if any of the stage or flows is missing, the assign null to database */
runStatement(String.format(INSERT_STATEMENT, currData.getLid(),
majorS, moderateS, minorS, majorD, moderateD, minorD));
if (currData.getMajorStage() != HydroConstants.MISSING_VALUE)
majorS = currData.getMajorStage();
if (currData.getModerateStage() != HydroConstants.MISSING_VALUE)
moderateS = currData.getModerateStage();
if (currData.getMinorStage() != HydroConstants.MISSING_VALUE)
minorS = currData.getMinorStage();
if (currData.getMajorDischarge() != HydroConstants.MISSING_VALUE)
majorD = currData.getMajorDischarge();
if (currData.getModerateDischarge() != HydroConstants.MISSING_VALUE)
moderateD = currData.getModerateDischarge();
if (currData.getMinorDischarge() != HydroConstants.MISSING_VALUE)
minorD = currData.getMinorDischarge();
/* if any of the stage or flows is missing, the assign null to database */
runStatement(String.format(INSERT_STATEMENT, currData.getLid(), majorS,
moderateS, minorS, majorD, moderateD, minorD));
}
public boolean putFloodCategoryData(String lid, String majorStage,
@ -198,41 +204,41 @@ public class FloodCategoryDataManager extends HydroDataManager {
String modDischarge, String minorDischarge, Shell shell)
throws VizException {
boolean rval = false;
String blankStr="";
String blankStr = "";
FloodCategoryData newData = new FloodCategoryData();
newData.setLid(lid);
try {
if (majorDischarge.equals(blankStr))
newData.setMajorDischarge((double) HydroConstants.MISSING_VALUE);
else
newData.setMajorDischarge(Double.parseDouble(majorDischarge));
if (majorDischarge.equals(blankStr))
newData.setMajorDischarge((double) HydroConstants.MISSING_VALUE);
else
newData.setMajorDischarge(Double.parseDouble(majorDischarge));
if (modDischarge.equals(blankStr))
newData.setModerateDischarge((double) HydroConstants.MISSING_VALUE);
else
if (modDischarge.equals(blankStr))
newData.setModerateDischarge((double) HydroConstants.MISSING_VALUE);
else
newData.setModerateDischarge(Double.parseDouble(modDischarge));
if (minorDischarge.equals(blankStr))
newData.setMinorDischarge((double) HydroConstants.MISSING_VALUE);
else
newData.setMinorDischarge(Double.parseDouble(minorDischarge));
if (minorDischarge.equals(blankStr))
newData.setMinorDischarge((double) HydroConstants.MISSING_VALUE);
else
newData.setMinorDischarge(Double.parseDouble(minorDischarge));
if (majorStage.equals(blankStr))
newData.setMajorStage((double) HydroConstants.MISSING_VALUE);
else
if (majorStage.equals(blankStr))
newData.setMajorStage((double) HydroConstants.MISSING_VALUE);
else
newData.setMajorStage(Double.parseDouble(majorStage));
if (modStage.equals(blankStr))
newData.setModerateStage((double) HydroConstants.MISSING_VALUE);
else
if (modStage.equals(blankStr))
newData.setModerateStage((double) HydroConstants.MISSING_VALUE);
else
newData.setModerateStage(Double.parseDouble(modStage));
if (minorStage.equals(blankStr))
newData.setMinorStage((double) HydroConstants.MISSING_VALUE);
else
if (minorStage.equals(blankStr))
newData.setMinorStage((double) HydroConstants.MISSING_VALUE);
else
newData.setMinorStage(Double.parseDouble(minorStage));
} catch (Exception e) {
MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);

View file

@ -25,6 +25,7 @@ import com.raytheon.uf.common.dataquery.db.QueryResult;
import com.raytheon.uf.common.dataquery.db.QueryResultRow;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.viz.hydrocommon.data.FloodData;
import com.raytheon.viz.hydrocommon.util.DbUtils;
import com.raytheon.viz.hydrocommon.util.HydroDataUtils;
/**
@ -93,8 +94,8 @@ public class FloodDataManager extends HydroDataManager {
* @throws VizException
*/
public void deleteRecord(FloodData recordToDelete) throws VizException {
runStatement(String.format(DELETE_STATEMENT, HydroDataUtils
.getPKStatement(recordToDelete)));
runStatement(String.format(DELETE_STATEMENT,
HydroDataUtils.getPKStatement(recordToDelete)));
}
/**
@ -160,14 +161,22 @@ public class FloodDataManager extends HydroDataManager {
}
private void updateFloodData(FloodData data) throws VizException {
runStatement(String.format(UPDATE_STATEMENT, data.getDamage(), data
.getDisplayStatement(), HydroDataUtils.getPKStatement(data)));
DbUtils.escapeSpecialCharforData(data);
runStatement(String
.format(UPDATE_STATEMENT, data.getDamage(),
data.getDisplayStatement(),
HydroDataUtils.getPKStatement(data)));
}
private void insertFloodData(FloodData currData) throws VizException {
runStatement(String.format(INSERT_STATEMENT, currData.getLid(), String
.format("%8.2f", currData.getStage()), currData.getDamage(),
currData.getDisplayStatement()));
DbUtils.escapeSpecialCharforData(currData);
runStatement(String.format(INSERT_STATEMENT, currData.getLid(),
String.format("%8.2f", currData.getStage()),
currData.getDamage(), currData.getDisplayStatement()));
}
public void putFloodCategoryData(String lid, double stage, String damage,

View file

@ -30,6 +30,7 @@ import com.raytheon.uf.common.dataquery.db.QueryResult;
import com.raytheon.uf.common.dataquery.db.QueryResultRow;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.viz.hydrocommon.data.HydroDBData;
import com.raytheon.viz.hydrocommon.util.DbUtils;
/**
* Class for managing database query calls.
@ -89,6 +90,9 @@ public class HydroDBDataManager extends HydroDataManager {
public <T extends HydroDBData> void deleteRecord(T recordToDelete)
throws VizException {
try {
DbUtils.escapeSpecialCharforData(recordToDelete);
String deleteQuery = (String) recordToDelete.getClass()
.getMethod("getDeleteStatement").invoke(recordToDelete);
@ -215,6 +219,9 @@ public class HydroDBDataManager extends HydroDataManager {
*/
public <T extends HydroDBData> void updateData(T data) throws VizException {
try {
DbUtils.escapeSpecialCharforData(data);
// Get the update statement with the values filled in
String updateQuery = (String) data.getClass()
.getMethod("getUpdateStatement").invoke(data);
@ -239,9 +246,11 @@ public class HydroDBDataManager extends HydroDataManager {
throws VizException {
try {
DbUtils.escapeSpecialCharforData(newData);
String updateQuery = (String) newData.getClass()
.getMethod("getUpdateStatement").invoke(newData);
DbUtils.escapeSpecialCharforData(updateData);
String pkquery = (String) updateData.getClass()
.getMethod("getPKStatement").invoke(updateData);
@ -268,6 +277,7 @@ public class HydroDBDataManager extends HydroDataManager {
String insertQuery = null;
try {
DbUtils.escapeSpecialCharforData(currData);
// if (currData.getClass() == LocationAgencyOfficeData.class) {
Method getSQLMethod = currData.getClass().getMethod(
"getInsertStatement");

View file

@ -19,7 +19,6 @@
**/
package com.raytheon.viz.hydrocommon.datamanager;
import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
@ -44,7 +43,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
@ -74,11 +73,12 @@ public abstract class HydroDataManager {
*/
protected ArrayList<Object[]> runQuery(String dataQuery) {
AppsDefaults ad = AppsDefaults.getInstance();
boolean debug = ad.getBoolean(HydroConstants.DEBUG_HYDRO_DB_TOKEN, false);
boolean debug = ad.getBoolean(HydroConstants.DEBUG_HYDRO_DB_TOKEN,
false);
if (debug) {
System.out.println(ad.getToken(HydroConstants.PGHOST) + ":" +
ad.getToken(HydroConstants.PGPORT) + ":" +
ad.getToken(HydroConstants.DB_NAME));
System.out.println(ad.getToken(HydroConstants.PGHOST) + ":"
+ ad.getToken(HydroConstants.PGPORT) + ":"
+ ad.getToken(HydroConstants.DB_NAME));
System.out.println("Query: " + dataQuery);
}
ArrayList<Object[]> data = null;
@ -103,18 +103,16 @@ public abstract class HydroDataManager {
*/
public QueryResult runMappedQuery(String dataQuery) throws VizException {
AppsDefaults ad = AppsDefaults.getInstance();
boolean debug = ad.getBoolean(HydroConstants.DEBUG_HYDRO_DB_TOKEN, false);
boolean debug = ad.getBoolean(HydroConstants.DEBUG_HYDRO_DB_TOKEN,
false);
if (debug) {
System.out.println(ad.getToken(HydroConstants.PGHOST) + ":" +
ad.getToken(HydroConstants.PGPORT) + ":" +
ad.getToken(HydroConstants.DB_NAME));
System.out.println(ad.getToken(HydroConstants.PGHOST) + ":"
+ ad.getToken(HydroConstants.PGPORT) + ":"
+ ad.getToken(HydroConstants.DB_NAME));
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);
@ -129,120 +127,20 @@ public abstract class HydroDataManager {
public void runStatement(String dataQuery) throws VizException {
AppsDefaults ad = AppsDefaults.getInstance();
boolean debug = ad.getBoolean(HydroConstants.DEBUG_HYDRO_DB_TOKEN, false);
boolean debug = ad.getBoolean(HydroConstants.DEBUG_HYDRO_DB_TOKEN,
false);
if (debug) {
System.out.println(ad.getToken(HydroConstants.PGHOST) + ":" +
ad.getToken(HydroConstants.PGPORT) + ":" +
ad.getToken(HydroConstants.DB_NAME));
System.out.println(ad.getToken(HydroConstants.PGHOST) + ":"
+ ad.getToken(HydroConstants.PGPORT) + ":"
+ 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 PDCDataStr = "";
int PDC_presetStr_begindex = 0;
/* special handling for PDC*/
if (dataQuery.toLowerCase().contains("preset_string"))
{
PDC_presetStr_begindex = dataQuery.toLowerCase().indexOf("'at=");
if (PDC_presetStr_begindex > 0)
{
PDCDataStr = dataQuery.substring(PDC_presetStr_begindex);
dataQuery = dataQuery.substring(0, PDC_presetStr_begindex);
}
}
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 + ", ";
}
if (PDC_presetStr_begindex > 0)
{
if (newDataQuery.toLowerCase().startsWith("insert"))
newDataQuery = newDataQuery + ", " + PDCDataStr;
else if (newDataQuery.toLowerCase().startsWith("update"))
newDataQuery = newDataQuery + PDCDataStr;
}
return newDataQuery;
}
/**
* Runs functions defined in the DB
*

View file

@ -25,6 +25,7 @@ import com.raytheon.uf.common.dataquery.db.QueryResult;
import com.raytheon.uf.common.dataquery.db.QueryResultRow;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.viz.hydrocommon.data.LocationAreaData;
import com.raytheon.viz.hydrocommon.util.DbUtils;
/**
* This class is the data manager for the location area data.
@ -42,8 +43,7 @@ import com.raytheon.viz.hydrocommon.data.LocationAreaData;
* @author lvenable
* @version 1.0
*/
public class LocationAreaManager extends HydroDataManager
{
public class LocationAreaManager extends HydroDataManager {
/**
* Instance of this class.
*/
@ -72,12 +72,12 @@ public class LocationAreaManager extends HydroDataManager
/**
* Private constructor.
*/
private LocationAreaManager()
{
private LocationAreaManager() {
}
/**
* Get an instance of this class.
*
* @return An instance of this class.
*/
public static synchronized LocationAreaManager getInstance() {
@ -90,12 +90,15 @@ public class LocationAreaManager extends HydroDataManager
/**
* Get the location area data.
* @param lid Location ID.
*
* @param lid
* Location ID.
* @return Array of location area data.
* @throws VizException Database exception.
* @throws VizException
* Database exception.
*/
public ArrayList<LocationAreaData> getLocationAreaData(String lid) throws VizException
{
public ArrayList<LocationAreaData> getLocationAreaData(String lid)
throws VizException {
ArrayList<LocationAreaData> rval = new ArrayList<LocationAreaData>();
QueryResult result = runMappedQuery(SELECT_STATEMENT + " WHERE lid='"
@ -110,14 +113,15 @@ public class LocationAreaManager extends HydroDataManager
/**
* Delete an existing location area record.
* @param locationID Location ID.
* @throws VizException Database exception.
*
* @param locationID
* Location ID.
* @throws VizException
* Database exception.
*/
public void deleteRecord(String locationID) throws VizException
{
public void deleteRecord(String locationID) throws VizException {
StringBuilder query = new StringBuilder(DELETE_STATEMENT);
String whereClaus = String.format(" WHERE lid = '%s'",
locationID);
String whereClaus = String.format(" WHERE lid = '%s'", locationID);
query.append(whereClaus);
runStatement(query.toString());
@ -125,11 +129,16 @@ public class LocationAreaManager extends HydroDataManager
/**
* Insert location area data.
* @param data Location area data.
* @throws VizException Database exception.
*
* @param data
* Location area data.
* @throws VizException
* Database exception.
*/
public void insertLocationAreaData(LocationAreaData data) throws VizException
{
public void insertLocationAreaData(LocationAreaData data)
throws VizException {
DbUtils.escapeSpecialCharforData(data);
String query = String.format(INSERT_STATEMENT, data.getLid(),
data.getArea());
@ -138,11 +147,16 @@ public class LocationAreaManager extends HydroDataManager
/**
* Update existing location area data.
* @param data Location area data.
* @throws VizException Database exception.
*
* @param data
* Location area data.
* @throws VizException
* Database exception.
*/
public void updateLocationAreaData(LocationAreaData data) throws VizException
{
public void updateLocationAreaData(LocationAreaData data)
throws VizException {
DbUtils.escapeSpecialCharforData(data);
String query = String.format(UPDATE_STATEMENT, data.getArea(),
data.getLid());
@ -151,12 +165,14 @@ public class LocationAreaManager extends HydroDataManager
/**
* Check of a location area record exists.
* @param lid Location ID.
*
* @param lid
* Location ID.
* @return True if the record exists, false otherwise.
* @throws VizException Database exception.
* @throws VizException
* Database exception.
*/
public boolean recordExists(String lid) throws VizException
{
public boolean recordExists(String lid) throws VizException {
StringBuilder query = new StringBuilder(SELECT_STATEMENT);
String whereClaus = String.format(" WHERE lid = '%s'", lid);
@ -164,8 +180,7 @@ public class LocationAreaManager extends HydroDataManager
QueryResult result = runMappedQuery(query.toString());
if (result.getResultCount() == 0)
{
if (result.getResultCount() == 0) {
return false;
}

View file

@ -29,6 +29,7 @@ import com.raytheon.uf.common.dataquery.db.QueryResult;
import com.raytheon.uf.common.dataquery.db.QueryResultRow;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.viz.hydrocommon.data.LowWaterData;
import com.raytheon.viz.hydrocommon.util.DbUtils;
import com.raytheon.viz.hydrocommon.util.HydroDataUtils;
/**
@ -161,6 +162,9 @@ public class LowWaterDataManager extends HydroDataManager {
}
private void updateLowWaterData(LowWaterData data) throws VizException {
DbUtils.escapeSpecialCharforData(data);
runStatement(String.format(
UPDATE_STATEMENT,
(data.getFlow() == LowWaterData.MISSING_VALUE) ? "null" : data
@ -170,6 +174,9 @@ public class LowWaterDataManager extends HydroDataManager {
}
private void insertLowWaterData(LowWaterData currData) throws VizException {
DbUtils.escapeSpecialCharforData(currData);
runStatement(String.format(INSERT_STATEMENT, currData.getLid(),
dateFormat.format(currData.getDate()),
(currData.getFlow() == LowWaterData.MISSING_VALUE) ? "null"

View file

@ -25,6 +25,7 @@ import com.raytheon.uf.common.dataquery.db.QueryResult;
import com.raytheon.uf.common.dataquery.db.QueryResultRow;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.viz.hydrocommon.data.LowWaterStatementData;
import com.raytheon.viz.hydrocommon.util.DbUtils;
import com.raytheon.viz.hydrocommon.util.HydroDataUtils;
/**
@ -94,8 +95,8 @@ public class LowWaterStatementDataManager extends HydroDataManager {
*/
public void deleteRecord(LowWaterStatementData recordToDelete)
throws VizException {
runStatement(String.format(DELETE_STATEMENT, HydroDataUtils
.getPKStatement(recordToDelete)));
runStatement(String.format(DELETE_STATEMENT,
HydroDataUtils.getPKStatement(recordToDelete)));
}
/**
@ -114,9 +115,7 @@ public class LowWaterStatementDataManager extends HydroDataManager {
+ lid + "' ORDER BY criteria_rank, lower_value ASC");
for (QueryResultRow currRow : result.getRows()) {
rval
.add(new LowWaterStatementData(currRow, result
.getColumnNames()));
rval.add(new LowWaterStatementData(currRow, result.getColumnNames()));
}
return rval;
@ -139,17 +138,23 @@ public class LowWaterStatementDataManager extends HydroDataManager {
private void updateLowWaterStatementData(LowWaterStatementData data)
throws VizException {
runStatement(String.format(UPDATE_STATEMENT, data
.getUpperValueDBString(), data.getStatement(), data
.getLowWaterCriteria(), data.getLowWaterSource(),
DbUtils.escapeSpecialCharforData(data);
runStatement(String.format(UPDATE_STATEMENT,
data.getUpperValueDBString(), data.getStatement(),
data.getLowWaterCriteria(), data.getLowWaterSource(),
HydroDataUtils.getPKStatement(data)));
}
private void insertLowWaterData(LowWaterStatementData currData)
throws VizException {
DbUtils.escapeSpecialCharforData(currData);
runStatement(String.format(INSERT_STATEMENT, currData.getLid(),
currData.getPe(), currData.getLowerValue(), currData
.getUpperValueDBString(), currData.getCriteriaRank(),
currData.getPe(), currData.getLowerValue(),
currData.getUpperValueDBString(), currData.getCriteriaRank(),
currData.getStatement(), currData.getLowWaterCriteria(),
currData.getLowWaterSource()));
}

View file

@ -23,8 +23,10 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.lang.reflect.Field;
import com.raytheon.uf.common.ohd.AppsDefaults;
import com.raytheon.viz.hydrocommon.data.HydroDBData;
/**
* Hydro Database Utilities
@ -36,7 +38,8 @@ import com.raytheon.uf.common.ohd.AppsDefaults;
* Jul 9, 2008 1194 mpduff Initial creation.
* Mar 7, 2014 16692 lbousaidi Any Forecast source other than
* H*,P*,Q*,T* should be handled by fcstother.
*
* Oct 10, 2015 17935 special char (e.g apostrophe) can not be saved/updated in Hyrobase
* *
* </pre>
*
* @author mpduff
@ -80,8 +83,7 @@ public class DbUtils {
}
/* if observed data or processed data being treated as observed */
if (ts.toUpperCase().startsWith("R")
|| treatProcessedAsObserverd
if (ts.toUpperCase().startsWith("R") || treatProcessedAsObserverd
|| ts.toUpperCase().startsWith("XX")) {
Set<String> tableKeys = tableMap.keySet();
@ -112,8 +114,8 @@ public class DbUtils {
* data
*/
retVal = fcstTableMap.get(pe.substring(0, 1).toLowerCase());
if (retVal==null) {
retVal="Fcstother";
if (retVal == null) {
retVal = "Fcstother";
}
matchFound = true;
} else { /* if type-source not valid */
@ -188,4 +190,54 @@ public class DbUtils {
fcstTableMap.put("t", "Fcsttemperature");
}
}
/**
* replace string fields in table class which contains apostrophe
*
* @param curData
*/
public static <T> void escapeSpecialCharforData(T curData) {
Class<?> c = curData.getClass();
Field fields[] = c.getDeclaredFields();
for (Field f : fields) {
try {
if (f.getType().isAssignableFrom(String.class)) {
f.setAccessible(true);
if (f.get(curData) != null) {
String value = (String) f.get(curData).toString();
if (value != null) {
if (value.contains("'")) {
value = value.replace("'", "''");
f.set(curData, value);
}
}
}
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
/**
* replace apostrophe for string
*
* @param strValue
* @return
*/
public static String escapeSpecialCharforStr(String strValue) {
String rVal;
if (strValue != null) {
if (strValue.contains("'")) {
strValue = strValue.replace("'", "''");
}
}
rVal = strValue;
return rVal;
}
}

View file

@ -0,0 +1,40 @@
package com.raytheon.viz.texteditor.dialogs;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlList;
import javax.xml.bind.annotation.XmlRootElement;
/**
* Describe rules for modifying VTEC ETNs.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Oct 07, 2015 ASM #18132 D. Friedman Initial creation
*
* </pre>
*
*/
@XmlRootElement(name = "etnRules")
@XmlAccessorType(XmlAccessType.NONE)
public class EtnRules {
private List<String> excludePhenSigs = new ArrayList<String>();
@XmlElement
@XmlList
public List<String> getExcludePhenSigs() {
return excludePhenSigs;
}
public void setExcludePhenSigs(List<String> excludePhenSigs) {
this.excludePhenSigs = excludePhenSigs;
}
}

View file

@ -142,6 +142,7 @@ import com.raytheon.uf.common.site.SiteMap;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.common.time.ISimulatedTimeChangeListener;
import com.raytheon.uf.common.time.SimulatedTime;
import com.raytheon.uf.common.time.util.TimeUtil;
import com.raytheon.uf.common.wmo.WMOHeader;
@ -188,6 +189,7 @@ import com.raytheon.viz.ui.dialogs.CaveJFACEDialog;
import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
import com.raytheon.viz.ui.dialogs.ICloseCallback;
import com.raytheon.viz.ui.dialogs.SWTMessageBox;
import com.raytheon.viz.ui.simulatedtime.SimulatedTimeOperations;
/**
* Main Text Editor dialog.
@ -349,6 +351,9 @@ import com.raytheon.viz.ui.dialogs.SWTMessageBox;
* 6Apr2015 RM14968 mgamazaychikov Fix formatting for pathcast section
* 15Jun2015 4441 randerso Unconditionally convert text to upper case for QC
* 8Jul2015 DR 15044 dhuffman Implemented tabbing and tabs to spaces.
* Sep 29 2015 4899 rferrel Do not send product while in operational mode and
* simulated time.
* 07Oct2015 RM 18132 D. Friedman Exlucde certain phensigs from automatic ETN incrementing.
*
* </pre>
*
@ -357,7 +362,8 @@ import com.raytheon.viz.ui.dialogs.SWTMessageBox;
public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
IAfosBrowserCallback, IWmoBrowserCallback, IRecoverEditSessionCallback,
ITextCharWrapCallback, IScriptRunnerObserver, IScriptEditorObserver,
INotificationObserver, IProductQueryCallback {
INotificationObserver, IProductQueryCallback,
ISimulatedTimeChangeListener {
/**
* Handler used for messges.
@ -379,6 +385,18 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
private static List<String> gfePils = Arrays.asList("WSW", "NPW", "HLS",
"CFW", "WCN", "FFA", "MWW", "RFW");
/**
* Default list of VTEC phenomena significance codes for which the ETN
* should not be changed when sending a NEW-action product.
*/
private static final List<String> defaultNoETNIncrementPhenSigs = Arrays
.asList("HU.A", "HU.S", "HU.W", "TR.A", "TR.W", "SS.A", "SS.W",
"TY.A", "TY.W");
/**
* Path of ETN rules localization file
*/
private static final String ETN_RULES_FILE = "textws/gui/EtnRules.xml";
/**
* Auto wrap start range column..
*/
@ -1466,6 +1484,7 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
callbackClient = cbClient;
this.textWorkstationFlag = textWorkstationFlag;
SimulatedTime.getSystemTime().addSimulatedTimeChangeListener(this);
}
private static JAXBManager getJaxbManager() throws JAXBException {
@ -4186,6 +4205,10 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
* Enter the text editor mode.
*/
private void enterEditor() {
if (!validateTime()) {
return;
}
initTemplateOverwriteMode();
StdTextProduct product = TextDisplayModel.getInstance()
.getStdTextProduct(token);
@ -4907,6 +4930,9 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
* true if product is to be resent
*/
synchronized private void sendProduct(final boolean resend) {
if (!validateTime()) {
return;
}
StdTextProduct prod = getStdTextProduct();
if (warnGenFlag) {
QCConfirmationMsg qcMsg = new QCConfirmationMsg();
@ -5073,8 +5099,13 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
* this case (isOpertional && ! resend) case,
* saveEditedProduct, does not actually save anything.
*/
prod.setProduct(VtecUtil.getVtec(
removeSoftReturns(prod.getProduct()), true));
if (shouldSetETNtoNextValue(prod)) {
statusHandler.handle(Priority.INFO, "Will increment ETN for this product.");
prod.setProduct(VtecUtil.getVtec(
removeSoftReturns(prod.getProduct()), true));
} else {
statusHandler.handle(Priority.INFO, "Will NOT increment ETN for this product.");
}
/*
* This silly bit of code updates the ETN of a VTEC in the
* text pane to reflect the ETN that was actually used, but
@ -5105,10 +5136,15 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
} else {
try {
if (!resend) {
body = VtecUtil
.getVtec(removeSoftReturns(MixedCaseProductSupport
.conditionalToUpper(prod.getNnnid(),
textEditor.getText())));
if (shouldSetETNtoNextValue(prod)) {
statusHandler.handle(Priority.INFO, "Will increment ETN for this product.");
body = VtecUtil
.getVtec(removeSoftReturns(MixedCaseProductSupport
.conditionalToUpper(prod.getNnnid(),
textEditor.getText())));
} else {
statusHandler.handle(Priority.INFO, "Will NOT increment ETN for this product.");
}
}
updateTextEditor(body);
if ((inEditMode || resend)
@ -5151,6 +5187,34 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
}
}
private EtnRules getETNRules() throws Exception {
LocalizationFile lf = PathManagerFactory.getPathManager()
.getStaticLocalizationFile(ETN_RULES_FILE);
if (lf == null) {
throw new Exception("ETN rules file (" + ETN_RULES_FILE + ") not found.");
}
return JAXB.unmarshal(lf.getFile(), EtnRules.class);
}
private boolean shouldSetETNtoNextValue(StdTextProduct prod) {
List<String> excludedPhenSigs = null;
try {
excludedPhenSigs = getETNRules().getExcludePhenSigs();
} catch (Exception e) {
statusHandler.handle(Priority.WARN,
"Error loading ETN assignment rules. Will use default rules.",
e);
excludedPhenSigs = defaultNoETNIncrementPhenSigs;
}
boolean result = true;
VtecObject vo = VtecUtil.parseMessage(prod.getProduct());
if (vo != null && excludedPhenSigs != null
&& excludedPhenSigs.contains(vo.getPhensig())) {
result = false;
}
return result;
}
private OUPRequest createOUPRequest(StdTextProduct prod, String text) {
OUPRequest req = new OUPRequest();
OfficialUserProduct oup = new OfficialUserProduct();
@ -7817,6 +7881,8 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
highlightBackgroundClr.dispose();
}
SimulatedTime.getSystemTime().removeSimulatedTimeChangeListener(this);
inEditMode = false;
}
@ -8064,8 +8130,8 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
&& (allText.charAt(eol + 1) == '\n')) {
deleteLen = 2;
} else if (allText.charAt(eol) == '\n') {
if ((allText.charAt(eol - 1) == '.')
&& (allText.charAt(eol - 2) != '.')) {
if (allText.charAt(eol - 1) == '.'
&& allText.charAt(eol - 2) != '.') {
// do not extend this line.
return;
} else {
@ -8736,4 +8802,25 @@ public class TextEditorDialog extends CaveSWTDialog implements VerifyListener,
return header;
}
/**
* Validate CAVE is in a state to allow sending of text product; and display
* a warning when unable to send.
*
* @return true when able to send text product
*/
private boolean validateTime() {
if ((shell != null) && !shell.isDisposed() && shell.isVisible()
&& !SimulatedTimeOperations.isTransmitAllowed()) {
SimulatedTimeOperations.displayFeatureLevelWarning(shell,
"Send Text Product");
return false;
}
return true;
}
@Override
public void timechanged() {
validateTime();
}
}

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<etnRules>
<excludePhenSigs>HU.A HU.S HU.W TR.A TR.W SS.A SS.W TY.A TY.W</excludePhenSigs>
</etnRules>

View file

@ -1107,4 +1107,7 @@ class TextProduct(TextRules.TextRules, SampleAnalysis.SampleAnalysis):
('FW.W', allActions, 'FireWx'), # RED FLAG WARNING
('FW.A', allActions, 'FireWx1'), # FIRE WEATHER WATCH
('LO.Y', marineActions, 'LowWater'), # LOW WATER ADVISORY
('TS.W', allActions, 'Tsunami'), # TSUNAMI WARNING
('TS.Y', allActions, 'Tsunami'), # TSUNAMI ADVISORY
('TS.A', allActions, 'Tsunami'), # TSUNAMI WATCH
]

View file

@ -1516,4 +1516,7 @@ class TextProduct(TextRules.TextRules, SampleAnalysis.SampleAnalysis):
('LO.Y', allActions, 'Drought'), # LOW WATER ADVISORY
('TO.A', allActions, 'Convective'), # TORNADO WATCH
('SV.A', allActions, 'Convective'), # SEVERE THUNDERSTORM WATCH
('TS.W', allActions, 'Tsunami'), # TSUNAMI WARNING
('TS.Y', allActions, 'Tsunami'), # TSUNAMI ADVISORY
('TS.A', allActions, 'Tsunami'), # TSUNAMI WATCH
]

View file

@ -1950,5 +1950,8 @@ class TextProduct(TextRules.TextRules, SampleAnalysis.SampleAnalysis):
('SU.Y', allActions, 'Marine'), # HIGH SURF ADVISORY
('RP.S', allActions, 'Rip'), # High Rip Threat
('BH.S', allActions, 'BeachHaz'), # Beach Hazards Statement
('TS.W', allActions, 'Tsunami'), # TSUNAMI WARNING
('TS.Y', allActions, 'Tsunami'), # TSUNAMI ADVISORY
('TS.A', allActions, 'Tsunami'), # TSUNAMI WATCH
]

View file

@ -84,6 +84,7 @@
<color r = "0.898039215686275" g = "0.0666666666666667" b = "0.00784313725490196" a = "1.0" />
<color r = "0.501960784313725" g = "0.611764705882353" b = "0.898039215686275" a = "1.0" />
<color r = "0" g = "0.164705882352941" b = "0.898039215686275" a = "1.0" />
<color r = "0.854901960784314" g = "0.933333333333333" b = "0.952941176470588" a = "1.0" />
<color r = "0.898039215686275" g = "0.305882352941176" b = "0" a = "1.0" />
<color r = "0.898039215686275" g = "0.576470588235294" b = "0.854901960784314" a = "1.0" />
<color r = "0.133333333333333" g = "0.603921568627451" b = "0.988235294117647" a = "1.0" />

View file

@ -60,6 +60,7 @@ import com.vividsolutions.jts.geom.GeometryFactory;
* for county based products.
* Jan 13, 2015 3996 ccody Correct NPE caused by calculating portions of Geometry objects with multiple sub Geometry objects
* This is a Jim Ramer fix
* Oct 9, 2015 #18154 Qinglu Lin Updated calculateLocationPortion().
* </pre>
*
* @author chammack
@ -353,12 +354,6 @@ public class GisUtil {
public static EnumSet<Direction> calculateLocationPortion(
Geometry locationGeom, Geometry reference, boolean useExtreme,
boolean notUseShapefileCentroid) {
CountyUserData cud = (CountyUserData) locationGeom.getUserData();
Map<String, Object> atts = cud.entry.attributes;
Number lonNumber = (Number) atts.get("LON");
double lonDouble = lonNumber.doubleValue();
Number latNumber = (Number) atts.get("LAT");
double latDouble = latNumber.doubleValue();
for (int i = 0; i < locationGeom.getNumGeometries(); i++) {
Geometry geom = locationGeom.getGeometryN(i);
if (geom.intersects(reference)) {
@ -368,9 +363,10 @@ public class GisUtil {
geomCentroid = geom.getEnvelope().getCentroid()
.getCoordinate();
} else {
Map<String, Object> atts = ((CountyUserData) locationGeom.getUserData()).entry.attributes;
geomCentroid = new Coordinate();
geomCentroid.x = lonDouble;
geomCentroid.y = latDouble;
geomCentroid.x = ((Number) atts.get("LON")).doubleValue();
geomCentroid.y = ((Number) atts.get("LAT")).doubleValue();
}
Coordinate refCentroid = reference.getCentroid()
.getCoordinate();

View file

@ -281,6 +281,9 @@ VTECTable = {
'TS.W' : {'phen': 'TS',
'sig': 'W',
'hdln': 'Tsunami Warning'},
'TS.Y' : {'phen': 'TS',
'sig': 'Y',
'hdln': 'Tsunami Advisory'},
'TY.A' : {'phen': 'TY',
'sig': 'A',
'hdln': 'Typhoon Watch'},