Changes to match server updates

Deleting now working. am automatically calling a windows curl command to
disable the cache on the server.
This commit is contained in:
Douglas Gillespie 2023-04-04 20:53:14 +01:00
parent faea94205c
commit 35fa8270d2
15 changed files with 310 additions and 286 deletions

View File

@ -56,6 +56,7 @@ import PamUtils.PamUtils;
import PamView.PamSymbol; import PamView.PamSymbol;
import PamView.dialog.PamGridBagContraints; import PamView.dialog.PamGridBagContraints;
import PamView.symbol.SymbolData; import PamView.symbol.SymbolData;
import PamguardMVC.debug.Debug;
import clickDetector.ClickClassifiers.basicSweep.CodeHost; import clickDetector.ClickClassifiers.basicSweep.CodeHost;
import clickDetector.ClickClassifiers.basicSweep.SweepClassifier; import clickDetector.ClickClassifiers.basicSweep.SweepClassifier;
import clickDetector.ClickClassifiers.basicSweep.SweepClassifierSet; import clickDetector.ClickClassifiers.basicSweep.SweepClassifierSet;
@ -1707,7 +1708,7 @@ public class SweepClassifierSetPaneFX extends SettingsPane<ClickTypeProperty> {
// } // }
// } // }
// else multiChan = true; // else multiChan = true;
Debug.out.println("Check multi-channel: " + multiChan); // Debug.out.println("Check multi-channel: " + multiChan);
return multiChan; return multiChan;
} }

View File

@ -43,7 +43,7 @@ public class EffortDialog extends PamDialog {
mainPanel.add(new JLabel("Observer name or initials"), c); mainPanel.add(new JLabel("Observer name or initials"), c);
c.gridx++; c.gridx++;
mainPanel.add(observer = new JComboBox<String>(), c); mainPanel.add(observer = new JComboBox<String>(), c);
outerOnly = new JRadioButton("Log uter scroll only"); outerOnly = new JRadioButton("Log outer scroll only");
allActions = new JRadioButton("Log all scroll actions"); allActions = new JRadioButton("Log all scroll actions");
ButtonGroup bg = new ButtonGroup(); ButtonGroup bg = new ButtonGroup();
bg.add(allActions); bg.add(allActions);

View File

@ -19,13 +19,13 @@ import javax.swing.Timer;
import PamController.PamControlledUnit; import PamController.PamControlledUnit;
import PamController.PamControlledUnitSettings; import PamController.PamControlledUnitSettings;
import PamController.PamController; import PamController.PamController;
import PamController.PamControllerInterface;
import PamController.PamSettingManager; import PamController.PamSettingManager;
import PamController.PamSettings; import PamController.PamSettings;
import PamView.PamTabPanel; import PamView.PamTabPanel;
import PamguardMVC.PamDataBlock; import PamguardMVC.PamDataBlock;
import metadata.MetaDataContol; import metadata.MetaDataContol;
import metadata.deployment.DeploymentData; import metadata.deployment.DeploymentData;
import pamViewFX.PamSettingsMenuPane;
import tethys.TethysState.StateType; import tethys.TethysState.StateType;
import tethys.dbxml.DBXMLConnect; import tethys.dbxml.DBXMLConnect;
import tethys.dbxml.DBXMLQueries; import tethys.dbxml.DBXMLQueries;
@ -43,8 +43,8 @@ import tethys.swing.TethysTabPanel;
/** /**
* Quick play with a simple system for outputting data to Tethys. At it's start * Quick play with a simple system for outputting data to Tethys. At it's start
* this is simply going to offer a dialog and have a few functions which show how * this is simply going to offer a dialog and have a few functions which show how
* to access data within PAMGuard. * to access data within PAMGuard.
* @author dg50 * @author dg50
* *
*/ */
@ -53,23 +53,23 @@ public class TethysControl extends PamControlledUnit implements PamSettings, Tet
public static final String unitType = "Tethys Interface"; public static final String unitType = "Tethys Interface";
public static String defaultName = "Tethys"; public static String defaultName = "Tethys";
public static String xmlNameSpace = "http://tethys.sdsu.edu/schema/1.0"; public static String xmlNameSpace = "http://tethys.sdsu.edu/schema/1.0";
private TethysExportParams tethysExportParams = new TethysExportParams(); private TethysExportParams tethysExportParams = new TethysExportParams();
private DBXMLConnect dbxmlConnect; private DBXMLConnect dbxmlConnect;
private TethysTabPanel tethysTabPanel; private TethysTabPanel tethysTabPanel;
private DBXMLQueries dbxmlQueries; private DBXMLQueries dbxmlQueries;
private ArrayList<TethysStateObserver> stateObservers; private ArrayList<TethysStateObserver> stateObservers;
private Timer serverCheckTimer; private Timer serverCheckTimer;
private ServerStatus lastServerStatus; private ServerStatus lastServerStatus;
private ArrayList<DatablockSynchInfo> dataBlockSynchInfos; private ArrayList<DatablockSynchInfo> dataBlockSynchInfos;
private DeploymentHandler deploymentHandler; private DeploymentHandler deploymentHandler;
private DetectionsHandler detectionsHandler; private DetectionsHandler detectionsHandler;
@ -89,7 +89,7 @@ public class TethysControl extends PamControlledUnit implements PamSettings, Tet
serverCheckTimer.setInitialDelay(0); serverCheckTimer.setInitialDelay(0);
PamSettingManager.getInstance().registerSettings(this); PamSettingManager.getInstance().registerSettings(this);
addStateObserver(this); addStateObserver(this);
if (PamController.getInstance().isInitializationComplete()) { if (PamController.getInstance().isInitializationComplete()) {
// must be adding module later on ... // must be adding module later on ...
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@ -103,8 +103,8 @@ public class TethysControl extends PamControlledUnit implements PamSettings, Tet
/** /**
* Get DBXML Connector. This class contains all the functions that are needed * Get DBXML Connector. This class contains all the functions that are needed
* to talk to the database. * to talk to the database.
* @return DBXML functions. * @return DBXML functions.
*/ */
public DBXMLConnect getDbxmlConnect() { public DBXMLConnect getDbxmlConnect() {
return dbxmlConnect; return dbxmlConnect;
@ -139,7 +139,7 @@ public class TethysControl extends PamControlledUnit implements PamSettings, Tet
tethysMenu.add(showDeps); tethysMenu.add(showDeps);
return tethysMenu; return tethysMenu;
} }
public void showProjectDeploymentsDialog() { public void showProjectDeploymentsDialog() {
ProjectDeploymentsDialog.showDialog(getGuiFrame(), this); ProjectDeploymentsDialog.showDialog(getGuiFrame(), this);
} }
@ -154,11 +154,11 @@ public class TethysControl extends PamControlledUnit implements PamSettings, Tet
} }
return sets; return sets;
} }
/** /**
* Get the synchronisation info for all datablocks. * Get the synchronisation info for all datablocks.
* This list should be static, but check it in case something has been * This list should be static, but check it in case something has been
* added or removed. * added or removed.
* @return * @return
*/ */
public ArrayList<DatablockSynchInfo> getSynchronisationInfos() { public ArrayList<DatablockSynchInfo> getSynchronisationInfos() {
@ -172,13 +172,13 @@ public class TethysControl extends PamControlledUnit implements PamSettings, Tet
dataBlockSynchInfos.add(new DatablockSynchInfo(this, aBlock)); dataBlockSynchInfos.add(new DatablockSynchInfo(this, aBlock));
} }
} }
// and remove any which are no longer there. // and remove any which are no longer there.
for (DatablockSynchInfo synchInfo : dataBlockSynchInfos) { for (DatablockSynchInfo synchInfo : dataBlockSynchInfos) {
if (dataBlocks.contains(synchInfo.getDataBlock()) == false) { if (!dataBlocks.contains(synchInfo.getDataBlock())) {
dataBlockSynchInfos.remove(synchInfo); dataBlockSynchInfos.remove(synchInfo);
} }
} }
return dataBlockSynchInfos; return dataBlockSynchInfos;
} }
@ -193,7 +193,7 @@ public class TethysControl extends PamControlledUnit implements PamSettings, Tet
} }
return null; return null;
} }
/** /**
* open client in the default web browser * open client in the default web browser
*/ */
@ -234,34 +234,34 @@ public class TethysControl extends PamControlledUnit implements PamSettings, Tet
} }
/** /**
* We'll probably want to * We'll probably want to
* @param parentFrame * @param parentFrame
*/ */
protected void tethysExport(JFrame parentFrame) { protected void tethysExport(JFrame parentFrame) {
TethysExportParams newExportParams = TethysExportDialog.showDialog(parentFrame, this); TethysExportParams newExportParams = TethysExportDialog.showDialog(parentFrame, this);
if (newExportParams != null) { if (newExportParams != null) {
// dialog returns null if cancel was pressed. // dialog returns null if cancel was pressed.
tethysExportParams = newExportParams; tethysExportParams = newExportParams;
exportTethysData(tethysExportParams); exportTethysData(tethysExportParams);
} }
} }
/** /**
* We'll arrive here if the dialog has been opened and we want to export Tethys data. * We'll arrive here if the dialog has been opened and we want to export Tethys data.
* @param tethysExportParams2 * @param tethysExportParams2
*/ */
private void exportTethysData(TethysExportParams tethysExportParams) { private void exportTethysData(TethysExportParams tethysExportParams) {
TethysExporter tethysExporter = new TethysExporter(this, tethysExportParams); TethysExporter tethysExporter = new TethysExporter(this, tethysExportParams);
tethysExporter.doExport(); tethysExporter.doExport();
sendStateUpdate(new TethysState(StateType.TRANSFERDATA)); sendStateUpdate(new TethysState(StateType.TRANSFERDATA));
countProjectDetections(); countProjectDetections();
sendStateUpdate(new TethysState(StateType.NEWPAMGUARDSELECTION)); sendStateUpdate(new TethysState(StateType.NEWPAMGUARDSELECTION));
} }
/** /**
* Get global deployment data. This is a bit of a mess, trying to use a separate module * Get global deployment data. This is a bit of a mess, trying to use a separate module
* so that the rest of PAMGuard can use it, but creating the * so that the rest of PAMGuard can use it, but creating the
* @return * @return
*/ */
public DeploymentData getGlobalDeplopymentData() { public DeploymentData getGlobalDeplopymentData() {
@ -271,14 +271,14 @@ public class TethysControl extends PamControlledUnit implements PamSettings, Tet
// deployment.setPlatform("Yay a platform"); // deployment.setPlatform("Yay a platform");
// Instrument instrument = new Instrument(); // Instrument instrument = new Instrument();
// instrument.setType("machiney"); // instrument.setType("machiney");
// instrument.setInstrumentId("12345555"); // instrument.setInstrumentId("12345555");
// deployment.setInstrument(instrument); // deployment.setInstrument(instrument);
// return false; // return false;
// } // }
MetaDataContol metaControl = (MetaDataContol) aUnit; MetaDataContol metaControl = (MetaDataContol) aUnit;
DeploymentData deploymentData = metaControl != null ? metaControl.getDeploymentData() : getTethysProjectData(); DeploymentData deploymentData = metaControl != null ? metaControl.getDeploymentData() : getTethysProjectData();
// deploymentData.setProject("thisIsAProject"); // deploymentData.setProject("thisIsAProject");
//// deploymentData.setPlatform("Yay a platform"); //// deploymentData.setPlatform("Yay a platform");
// deploymentData.setCruise("cruisey"); // deploymentData.setCruise("cruisey");
@ -286,14 +286,14 @@ public class TethysControl extends PamControlledUnit implements PamSettings, Tet
//// deploymentData.setInstrumentId("super instrument"); //// deploymentData.setInstrumentId("super instrument");
// deploymentData.setSite("in the ocean somewhere"); // deploymentData.setSite("in the ocean somewhere");
// deploymentData.setRegion("ocean water"); // deploymentData.setRegion("ocean water");
//// deploymentData.setInstrumentType("sensor of sorts"); //// deploymentData.setInstrumentType("sensor of sorts");
return deploymentData; return deploymentData;
} }
/** /**
* Gets a copy of Deployment data stored with other Tethys params when the more * Gets a copy of Deployment data stored with other Tethys params when the more
* general meta data provider is not present. * general meta data provider is not present.
* @return * @return
*/ */
private DeploymentData getTethysProjectData() { private DeploymentData getTethysProjectData() {
@ -301,7 +301,7 @@ public class TethysControl extends PamControlledUnit implements PamSettings, Tet
} }
/** /**
* Add a new state observer. * Add a new state observer.
* @param stateObserver * @param stateObserver
*/ */
public void addStateObserver(TethysStateObserver stateObserver) { public void addStateObserver(TethysStateObserver stateObserver) {
@ -309,16 +309,16 @@ public class TethysControl extends PamControlledUnit implements PamSettings, Tet
} }
/** /**
* Remove a state observer. * Remove a state observer.
* @param stateObserver * @param stateObserver
* @return true if it existed. * @return true if it existed.
*/ */
public boolean removeStateObserver(TethysStateObserver stateObserver) { public boolean removeStateObserver(TethysStateObserver stateObserver) {
return stateObservers.remove(stateObserver); return stateObservers.remove(stateObserver);
} }
/** /**
* Send state updates around to all state observers. * Send state updates around to all state observers.
* @param tethysState * @param tethysState
*/ */
public void sendStateUpdate(TethysState tethysState) { public void sendStateUpdate(TethysState tethysState) {
@ -327,7 +327,7 @@ public class TethysControl extends PamControlledUnit implements PamSettings, Tet
} }
} }
/** /**
* A name for any deta selectors. * A name for any deta selectors.
* @return * @return
*/ */
public String getDataSelectName() { public String getDataSelectName() {
@ -342,15 +342,15 @@ public class TethysControl extends PamControlledUnit implements PamSettings, Tet
public void notifyModelChanged(int changeType) { public void notifyModelChanged(int changeType) {
super.notifyModelChanged(changeType); super.notifyModelChanged(changeType);
switch (changeType) { switch (changeType) {
case PamController.INITIALIZATION_COMPLETE: case PamControllerInterface.INITIALIZATION_COMPLETE:
initializationStuff(); initializationStuff();
break; break;
} }
} }
/** /**
* Stuff to do on initial load (initialization complete or addition of * Stuff to do on initial load (initialization complete or addition of
* a Tethys module after initialisation). * a Tethys module after initialisation).
*/ */
private void initializationStuff() { private void initializationStuff() {
deploymentHandler.createPamguardOverview(); deploymentHandler.createPamguardOverview();
@ -360,9 +360,9 @@ public class TethysControl extends PamControlledUnit implements PamSettings, Tet
/** /**
* Check the server. This will send around a notification if the state * Check the server. This will send around a notification if the state
* has changed since the last call to this function, so it's unlikely you'll * has changed since the last call to this function, so it's unlikely you'll
* need to use the return value * need to use the return value
* @return server status. * @return server status.
*/ */
public ServerStatus checkServer() { public ServerStatus checkServer() {
ServerStatus serverState = dbxmlConnect.pingServer(); ServerStatus serverState = dbxmlConnect.pingServer();
@ -425,8 +425,8 @@ public class TethysControl extends PamControlledUnit implements PamSettings, Tet
/** /**
* One stop place to get Deployment information. Will provide * One stop place to get Deployment information. Will provide
* both information on record periods in PAMGuard and also Deployment docs in Tethys. * both information on record periods in PAMGuard and also Deployment docs in Tethys.
* @return set of functions for handling deployments. * @return set of functions for handling deployments.
*/ */
public DeploymentHandler getDeploymentHandler() { public DeploymentHandler getDeploymentHandler() {
return deploymentHandler; return deploymentHandler;

View File

@ -5,18 +5,16 @@ import Array.HydrophoneLocator;
import Array.PamArray; import Array.PamArray;
import Array.Streamer; import Array.Streamer;
import GPS.GPSControl; import GPS.GPSControl;
import GPS.GpsData;
import GPS.GpsDataUnit; import GPS.GpsDataUnit;
import PamUtils.LatLong; import PamUtils.LatLong;
import PamUtils.PamUtils; import PamUtils.PamUtils;
import PamguardMVC.PamDataUnit;
import generalDatabase.DBControlUnit; import generalDatabase.DBControlUnit;
import generalDatabase.PamConnection; import generalDatabase.PamConnection;
import nilus.Deployment; import nilus.Deployment;
import nilus.DeploymentRecoveryDetails; import nilus.DeploymentRecoveryDetails;
/** /**
* Function(s) to get location information for Tethys in the required format. * Function(s) to get location information for Tethys in the required format.
* @author dg50 * @author dg50
* *
*/ */
@ -25,10 +23,10 @@ public class TethysLocationFuncs {
/** /**
* Get everything we need for a deployment document including the track # * Get everything we need for a deployment document including the track #
* and the deployment / recovery information. Basically this means we * and the deployment / recovery information. Basically this means we
* have to load the GPS data, then potentially filter it. Slight risk this * have to load the GPS data, then potentially filter it. Slight risk this
* may all be too much for memory, but give it a go by loading GPS data for * may all be too much for memory, but give it a go by loading GPS data for
* the deployment times. * the deployment times.
* @param deployment * @param deployment
*/ */
public static void getTrackAndPositionData(Deployment deployment) { public static void getTrackAndPositionData(Deployment deployment) {
@ -41,16 +39,16 @@ public class TethysLocationFuncs {
boolean ok = true; boolean ok = true;
ok &= addPositionData(deployment.getDeploymentDetails()); ok &= addPositionData(deployment.getDeploymentDetails());
ok &= addPositionData(deployment.getRecoveryDetails()); ok &= addPositionData(deployment.getRecoveryDetails());
} }
/** /**
* Add position data to DeploymentRecoveryDetails. * Add position data to DeploymentRecoveryDetails.
* @param drd * @param drd
* @return * @return
*/ */
public static boolean addPositionData(DeploymentRecoveryDetails drd) { public static boolean addPositionData(DeploymentRecoveryDetails drd) {
long timeMillis = TethysTimeFuncs.millisFromGregorianXML(drd.getAudioTimeStamp()); long timeMillis = TethysTimeFuncs.millisFromGregorianXML(drd.getAudioTimeStamp());
LatLong pos = getLatLongData(timeMillis); LatLong pos = getLatLongData(timeMillis);
if (pos == null) { if (pos == null) {
return false; return false;
@ -61,15 +59,15 @@ public class TethysLocationFuncs {
drd.setDepthInstrumentM(-pos.getHeight()); drd.setDepthInstrumentM(-pos.getHeight());
return true; return true;
} }
public static LatLong getLatLongData(long timeMillis) { public static LatLong getLatLongData(long timeMillis) {
// check the array time. // check the array time.
PamArray array = ArrayManager.getArrayManager().getCurrentArray(); PamArray array = ArrayManager.getArrayManager().getCurrentArray();
Streamer aStreamer = array.getStreamer(0); Streamer aStreamer = array.getStreamer(0);
GPSControl gpsControl = GPSControl.getGpsControl(); GPSControl gpsControl = GPSControl.getGpsControl();
PamConnection con = DBControlUnit.findConnection(); PamConnection con = DBControlUnit.findConnection();
if (gpsControl != null) { if (gpsControl != null) {
// check GPS data are loaded for times around this. // check GPS data are loaded for times around this.
GpsDataUnit gpsData = (GpsDataUnit) gpsControl.getGpsDataBlock().getLogging().findClosestDataPoint(con, timeMillis); GpsDataUnit gpsData = (GpsDataUnit) gpsControl.getGpsDataBlock().getLogging().findClosestDataPoint(con, timeMillis);
if (gpsData != null) { if (gpsData != null) {
return gpsData.getGpsData(); return gpsData.getGpsData();

View File

@ -12,11 +12,11 @@ import javax.swing.JPopupMenu;
import tethys.niluswraps.PDeployment; import tethys.niluswraps.PDeployment;
/* /*
* Some standard meny dirven functions which we may want to call from * Some standard meny dirven functions which we may want to call from
* a few different places. * a few different places.
*/ */
public class TethysMenuActions { public class TethysMenuActions {
private TethysControl tethysControl; private TethysControl tethysControl;
public TethysMenuActions(TethysControl tethysControl) { public TethysMenuActions(TethysControl tethysControl) {

View File

@ -1,10 +1,8 @@
package tethys; package tethys;
import tethys.detection.DetectionExportProgress;
/** /**
* Basis for a message system which will get passed around whenever something happens in * Basis for a message system which will get passed around whenever something happens in
* Tethys, whether it be a new connection, progress during data output, etc. * Tethys, whether it be a new connection, progress during data output, etc.
* @author dg50 * @author dg50
* *
*/ */
@ -16,8 +14,8 @@ public class TethysState {
NEWPAMGUARDSELECTION, // new PAMGuard data are available (called once on first load) NEWPAMGUARDSELECTION, // new PAMGuard data are available (called once on first load)
UPDATEMETADATA, // META Data being prepared for output have changed (so may be able to enable output!) UPDATEMETADATA, // META Data being prepared for output have changed (so may be able to enable output!)
EXPORTING // currently exporting data. may be a while ... EXPORTING // currently exporting data. may be a while ...
}; }
public StateType stateType; public StateType stateType;
private Object stateObject; private Object stateObject;

View File

@ -1,13 +1,13 @@
package tethys; package tethys;
public interface TethysStateObserver { public interface TethysStateObserver {
/** /**
* Receive state updates when Tethys has done something (made a connection, moved some data, etc.)<br> * Receive state updates when Tethys has done something (made a connection, moved some data, etc.)<br>
* Note that this is for RECEIVING state updates, not for sending them. To avoid infinite notifications * Note that this is for RECEIVING state updates, not for sending them. To avoid infinite notifications
* loops, use tethysControl.sendStateUpdate(TethysState) if this component knows something. * loops, use tethysControl.sendStateUpdate(TethysState) if this component knows something.
* @param tethysState * @param tethysState
*/ */
public void updateState(TethysState tethysState); public void updateState(TethysState tethysState);
} }

View File

@ -14,7 +14,7 @@ import javax.xml.datatype.XMLGregorianCalendar;
import PamUtils.PamCalendar; import PamUtils.PamCalendar;
public class TethysTimeFuncs { public class TethysTimeFuncs {
private static TimeZone timeZone = TimeZone.getTimeZone("UTC"); private static TimeZone timeZone = TimeZone.getTimeZone("UTC");
/* /*
@ -33,9 +33,9 @@ public class TethysTimeFuncs {
return null; return null;
} }
} }
/** /**
* Convert a Gregorian calendar value back to milliseconds. * Convert a Gregorian calendar value back to milliseconds.
* @param xmlGregorian * @param xmlGregorian
* @return * @return
*/ */
@ -47,9 +47,9 @@ public class TethysTimeFuncs {
gc2.setTimeZone(timeZone); gc2.setTimeZone(timeZone);
return gc2.getTimeInMillis(); return gc2.getTimeInMillis();
} }
/** /**
* Make a Gregorian calendar object from a returned XML string. * Make a Gregorian calendar object from a returned XML string.
* @param gregorianString * @param gregorianString
* @return * @return
*/ */
@ -75,7 +75,7 @@ public class TethysTimeFuncs {
//// gCal.se //// gCal.se
// return gCal; // return gCal;
} }
public static String formatGregorianTime(XMLGregorianCalendar gregCal) { public static String formatGregorianTime(XMLGregorianCalendar gregCal) {
if (gregCal == null) { if (gregCal == null) {
return null; return null;

View File

@ -14,11 +14,11 @@ import org.xml.sax.SAXException;
public class DBQueryResult { public class DBQueryResult {
public long queryTimeMillis; public long queryTimeMillis;
public String queryResult; public String queryResult;
public String schemaPlan; public String schemaPlan;
public Exception queryException; public Exception queryException;
public DBQueryResult(long queryTimeMillis, String queryResult, String schemaPlan) { public DBQueryResult(long queryTimeMillis, String queryResult, String schemaPlan) {
@ -33,9 +33,9 @@ public class DBQueryResult {
this.queryTimeMillis = queryTimeMillis; this.queryTimeMillis = queryTimeMillis;
this.queryException = queryException; this.queryException = queryException;
} }
/** /**
* Get the result as an XML document. * Get the result as an XML document.
* @return XML document * @return XML document
* @throws ParserConfigurationException * @throws ParserConfigurationException
* @throws SAXException * @throws SAXException
@ -58,5 +58,5 @@ public class DBQueryResult {
Document doc = builder.parse(new InputSource(new StringReader(queryResult))); Document doc = builder.parse(new InputSource(new StringReader(queryResult)));
return doc; return doc;
} }
} }

View File

@ -4,28 +4,20 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.nio.file.Files;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.JAXBException; import javax.xml.bind.JAXBException;
import java.nio.file.Files;
import java.nio.file.Path;
import dbxml.JerseyClient; import dbxml.JerseyClient;
import dbxml.Queries; import dbxml.Queries;
import dbxml.uploader.Importer; import dbxml.uploader.Importer;
import nilus.Deployment;
import nilus.MarshalXML; import nilus.MarshalXML;
import tethys.TethysControl; import tethys.TethysControl;
import tethys.output.TethysExportParams; import tethys.output.TethysExportParams;
import tethys.output.StreamExportParams;
import PamguardMVC.PamDataBlock;
/** /**
* Class containing functions for managing the database connection. Opening, closing, * Class containing functions for managing the database connection. Opening, closing,
* writing, keeping track of performance, etc. * writing, keeping track of performance, etc.
* @author Doug Gillespie, Katie O'Laughlin * @author Doug Gillespie, Katie O'Laughlin
* *
*/ */
@ -33,23 +25,23 @@ public class DBXMLConnect {
private TethysControl tethysControl; private TethysControl tethysControl;
private File tempDirectory; private File tempDirectory;
private JerseyClient jerseyClient; private JerseyClient jerseyClient;
private Queries queries; private Queries queries;
private String currentSiteURL; private String currentSiteURL;
public DBXMLConnect(TethysControl tethysControl) { public DBXMLConnect(TethysControl tethysControl) {
this.tethysControl = tethysControl; this.tethysControl = tethysControl;
checkTempFolder(); checkTempFolder();
} }
/** /**
* Check the jersey client and the queries. Need to recreate * Check the jersey client and the queries. Need to recreate
* if the url has changed. * if the url has changed.
* @return * @return
*/ */
private boolean checkClient() { private boolean checkClient() {
@ -57,34 +49,34 @@ public class DBXMLConnect {
return false; return false;
} }
TethysExportParams params = tethysControl.getTethysExportParams(); TethysExportParams params = tethysControl.getTethysExportParams();
if (currentSiteURL.equalsIgnoreCase(params.getFullServerName()) == false) { if (!currentSiteURL.equalsIgnoreCase(params.getFullServerName())) {
return false; return false;
} }
return true; return true;
} }
/** /**
* Get the client. The client will only be recreated if the url changes * Get the client. The client will only be recreated if the url changes
* @return Jersy client * @return Jersy client
*/ */
public synchronized JerseyClient getJerseyClient() { public synchronized JerseyClient getJerseyClient() {
if (checkClient() == false) { if (!checkClient()) {
openConnections(); openConnections();
} }
return jerseyClient; return jerseyClient;
} }
/** /**
* Get the Queries object. This will only be recreated if the client changes. * Get the Queries object. This will only be recreated if the client changes.
* @return * @return
*/ */
public synchronized Queries getTethysQueries() { public synchronized Queries getTethysQueries() {
if (checkClient() == false) { if (!checkClient()) {
openConnections(); openConnections();
} }
return queries; return queries;
} }
/** /**
* Update a document within Tethys. We're assuming that a * Update a document within Tethys. We're assuming that a
* document with the same name in the same collection already * document with the same name in the same collection already
@ -95,13 +87,13 @@ public class DBXMLConnect {
*/ */
public String updateDocument(Object nilusDocument) { public String updateDocument(Object nilusDocument) {
deleteDocument(nilusDocument); deleteDocument(nilusDocument);
return postToTethys(nilusDocument); return postToTethys(nilusDocument);
} }
/** /**
* Delete a nilus document from the database. The only field which * Delete a nilus document from the database. The only field which
* needs to be populated here is the Id. The code also uses the object * needs to be populated here is the Id. The code also uses the object
* class to identify the correct collection. * class to identify the correct collection.
* @param nilusDocument * @param nilusDocument
* @return * @return
*/ */
@ -115,7 +107,7 @@ public class DBXMLConnect {
result = jerseyClient.removeDocument(collection, docId ); result = jerseyClient.removeDocument(collection, docId );
/** /**
* Return from a sucessful delete is something like * Return from a sucessful delete is something like
* *
deployment = getTethysControl().getDeploymentHandler().createDeploymentDocument(freeId++, recordPeriod); deployment = getTethysControl().getDeploymentHandler().createDeploymentDocument(freeId++, recordPeriod);
<DELETE> <DELETE>
<ITEM> ['ECoastNARW0'] </ITEM> <ITEM> ['ECoastNARW0'] </ITEM>
@ -123,19 +115,19 @@ public class DBXMLConnect {
*/ */
} }
catch (Exception e) { catch (Exception e) {
System.out.printf("Error deleting %s %s: %s\n", collection, docId, e.getMessage()); System.out.printf("Error deleting %s %s: %s\n", collection, docId, e.getMessage());
} }
forceFlush(); // forceFlush();
return result == null; return result == null;
} }
/** /**
* take a nilus object loaded with PamGuard data and post it to the Tethys database * take a nilus object loaded with PamGuard data and post it to the Tethys database
* *
* @param pamGuardObjs a nilus object loaded with PamGuard data * @param pamGuardObjs a nilus object loaded with PamGuard data
* @return error string, null string means there are no errors * @return error string, null string means there are no errors
*/ */
public String postToTethys(Object nilusObject) public String postToTethys(Object nilusObject)
{ {
Class objClass = nilusObject.getClass(); Class objClass = nilusObject.getClass();
String collection = getTethysCollection(objClass.getName()); String collection = getTethysCollection(objClass.getName());
@ -146,14 +138,14 @@ public class DBXMLConnect {
File tempFile = new File(tempName); File tempFile = new File(tempName);
try { try {
MarshalXML marshal = new MarshalXML(); MarshalXML marshal = new MarshalXML();
marshal.createInstance(objClass); marshal.createInstance(objClass);
// Path tempFile = Files.createTempFile("pamGuardToTethys", ".xml"); // Path tempFile = Files.createTempFile("pamGuardToTethys", ".xml");
marshal.marshal(nilusObject, tempFile.toString()); marshal.marshal(nilusObject, tempFile.toString());
fileError = Importer.ImportFiles(params.getFullServerName(), collection, fileError = Importer.ImportFiles(params.getFullServerName(), collection,
new String[] { tempFile.toString() }, "", "", false); new String[] { tempFile.toString() }, "", "", false);
// System.out.println(fileError); // System.out.println(fileError);
tempFile.deleteOnExit(); tempFile.deleteOnExit();
} catch(IllegalArgumentException e) { } catch(IllegalArgumentException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
@ -164,55 +156,55 @@ public class DBXMLConnect {
} catch (JAXBException e) { } catch (JAXBException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
// System.out.println(fileError); // System.out.println(fileError);
return fileError; return fileError;
} }
/*
* force a fluch by sending a dummy document to th eimporter which will rail, but ... // /*
*/ // * force a fluch by sending a dummy document to th eimporter which will rail, but ...
private void forceFlush() { // */
TethysExportParams params = new TethysExportParams(); // private void forceFlush() {
String fileError = null; // TethysExportParams params = new TethysExportParams();
try { // String fileError = null;
fileError = Importer.ImportFiles(params.getFullServerName(), "NoCollection", // try {
new String[] { "ThereIsNoFileE" }, "", "", false); // fileError = Importer.ImportFiles(params.getFullServerName(), "NoCollection",
} // new String[] { "ThereIsNoFileE" }, "", "", false);
catch (Exception e) { // }
// catch (Exception e) {
} //
// System.out.println(fileError); // }
//// System.out.println(fileError);
} //
// }
/** /**
* Get a temp folder to hold xml output. This will be the standard * Get a temp folder to hold xml output. This will be the standard
* temp folder + /PAMGuardTethys. Files will be left here until PAMGUard * temp folder + /PAMGuardTethys. Files will be left here until PAMGUard
* exits then should delete automatically * exits then should delete automatically
*/ */
private void checkTempFolder() { private void checkTempFolder() {
String javaTmpDirs = System.getProperty("java.io.tmpdir") + File.separator + "PAMGuardTethys"; String javaTmpDirs = System.getProperty("java.io.tmpdir") + File.separator + "PAMGuardTethys";
File tempDir = new File(javaTmpDirs); File tempDir = new File(javaTmpDirs);
if (tempDir.exists() == false) { if (!tempDir.exists()) {
tempDir.mkdirs(); tempDir.mkdirs();
} }
if (tempDir.exists()) { if (tempDir.exists()) {
tempDirectory = tempDir; tempDirectory = tempDir;
}; }
if (tempDirectory == null) { if (tempDirectory == null) {
tempDirectory = new File(System.getProperty("java.io.tmpdir")); tempDirectory = new File(System.getProperty("java.io.tmpdir"));
} }
} }
/** /**
* Get a document Id string. All Document objects should have a getId() function * Get a document Id string. All Document objects should have a getId() function
* however they do not have a type hierarchy, so it can't be accessed directly. * however they do not have a type hierarchy, so it can't be accessed directly.
* instead go via the class.getDeclaredMethod function and it should be possible to find * instead go via the class.getDeclaredMethod function and it should be possible to find
* it. * it.
* @param nilusObject * @param nilusObject
* @return document Id for any type of document, or null if the document doesn't have a getID function * @return document Id for any type of document, or null if the document doesn't have a getID function
*/ */
@ -235,7 +227,7 @@ public class DBXMLConnect {
} }
/** /**
* needs to be based on the document id, * needs to be based on the document id,
* @param nilusObject * @param nilusObject
* @return * @return
*/ */
@ -256,29 +248,29 @@ public class DBXMLConnect {
*/ */
public String getTethysCollection(String className) { public String getTethysCollection(String className) {
switch(className) { switch(className) {
case "nilus.Deployment": case "nilus.Deployment":
return "Deployments"; return "Deployments";
case "nilus.Detections": case "nilus.Detections":
return "Detections"; return "Detections";
case "nilus.Calibration": case "nilus.Calibration":
return "Calibrations"; return "Calibrations";
case "nilus.Ensemble": case "nilus.Ensemble":
return "Ensembles"; return "Ensembles";
case "nilus.Localization": case "nilus.Localization":
return "Localizations"; return "Localizations";
case "nilus.SpeciesAbbreviation": case "nilus.SpeciesAbbreviation":
return "SpeciesAbbreviations"; return "SpeciesAbbreviations";
case "nilus.SourceMap": case "nilus.SourceMap":
return "SourceMaps"; return "SourceMaps";
case "nilus.ITIS": case "nilus.ITIS":
return "ITIS"; return "ITIS";
case "nilus.ranks": case "nilus.ranks":
return "ITIS_ranks"; return "ITIS_ranks";
default: default:
return ""; return "";
} }
} }
/** /**
* Delete a Deploymnet and any contained Detections document. Doesn't work ! * Delete a Deploymnet and any contained Detections document. Doesn't work !
* @param deploymentId * @param deploymentId
@ -301,7 +293,7 @@ public class DBXMLConnect {
// } // }
// } // }
try { try {
String doc = queries.getDocument("Deployments", deploymentId); // String doc = queries.getDocument("Deployments", deploymentId);
// queries. // queries.
result = jerseyClient.removeDocument("Deployments", deploymentId ); result = jerseyClient.removeDocument("Deployments", deploymentId );
} }
@ -319,9 +311,29 @@ public class DBXMLConnect {
jerseyClient = new JerseyClient(currentSiteURL); jerseyClient = new JerseyClient(currentSiteURL);
queries = new Queries(jerseyClient); queries = new Queries(jerseyClient);
ServerStatus state = pingServer(); ServerStatus state = pingServer();
setCache(false);
return state.ok; return state.ok;
} }
private void setCache(boolean cacheOn) {
// from Marie. 4/4/2022: Basically it is a PUT to http://localhost:9979/Tethys/cache/off (or on).
TethysExportParams params = tethysControl.getTethysExportParams();
String cmd = String.format("curl -X PUT -data \"\" %s/Tethys/cache/%s", params.getFullServerName(), cacheOn ? "on" : "off");
System.out.println(cmd);
try {
Runtime.getRuntime().exec(cmd);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// CUrl curl = new CUrl(cmd);
}
public synchronized void closeConnections() { public synchronized void closeConnections() {
jerseyClient = null; jerseyClient = null;
queries = null; queries = null;
@ -329,8 +341,8 @@ public class DBXMLConnect {
} }
/** /**
* Get the server state via a ping ? * Get the server state via a ping ?
* @return Server state ? * @return Server state ?
*/ */
public ServerStatus pingServer() { public ServerStatus pingServer() {
@ -344,7 +356,7 @@ public class DBXMLConnect {
return new ServerStatus(ok, null); return new ServerStatus(ok, null);
} }
// add whatever calls are necessary ... // add whatever calls are necessary ...
} }

View File

@ -29,7 +29,6 @@ import nilus.Detections;
import nilus.Helper; import nilus.Helper;
import tethys.TethysControl; import tethys.TethysControl;
import tethys.TethysTimeFuncs; import tethys.TethysTimeFuncs;
import tethys.niluswraps.PDeployment;
import tethys.output.TethysExportParams; import tethys.output.TethysExportParams;
/** /**
@ -42,7 +41,7 @@ public class DBXMLQueries {
private TethysControl tethysControl; private TethysControl tethysControl;
private DBXMLConnect dbXMLConnect; private DBXMLConnect dbXMLConnect;
public DBXMLQueries(TethysControl tethysControl, DBXMLConnect dbXMLConnect) { public DBXMLQueries(TethysControl tethysControl, DBXMLConnect dbXMLConnect) {
super(); super();
this.tethysControl = tethysControl; this.tethysControl = tethysControl;
@ -75,7 +74,7 @@ public class DBXMLQueries {
// String url = jerseyClient.getURL(); // String url = jerseyClient.getURL();
Queries queries = new Queries(jerseyClient); Queries queries = new Queries(jerseyClient);
queryResult = jerseyClient.queryJSON(jsonQueryString, 0); queryResult = jerseyClient.queryJSON(jsonQueryString, 0);
schemaPlan = jerseyClient.queryJSON(jsonQueryString, 1); schemaPlan = jerseyClient.queryJSON(jsonQueryString, 1);
@ -114,26 +113,33 @@ public class DBXMLQueries {
if (doc == null) { if (doc == null) {
return null; return null;
} }
NodeList returns = doc.getElementsByTagName("Return"); NodeList returns = doc.getElementsByTagName("Project");
// System.out.println("N projects = " + returns.getLength()); // System.out.println("N projects = " + returns.getLength());
int n = returns.getLength(); int n = returns.getLength();
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
Node aNode = returns.item(i); Node aNode = returns.item(i);
if (aNode instanceof Element) { String projName = aNode.getTextContent();
Node depEl = ((Element) aNode).getFirstChild(); if (projName != null) {
if (depEl == null) { if (!projectNames.contains(projName)) {
continue; projectNames.add(projName);
}
if (depEl instanceof Element) {
Element projEl = (Element) ((Element) depEl).getFirstChild();
String projName = projEl.getTextContent();
if (projName != null) {
if (!projectNames.contains(projName)) {
projectNames.add(projName);
}
}
} }
} }
// }
// if (aNode instanceof Element) {
// Node depEl = ((Element) aNode).getFirstChild();
// if (depEl == null) {
// continue;
// }
// if (depEl instanceof Element) {
// Element projEl = (Element) ((Element) depEl).getFirstChild();
// String projName = projEl.getTextContent();
// if (projName != null) {
// if (!projectNames.contains(projName)) {
// projectNames.add(projName);
// }
// }
// }
// }
} }
Collections.sort(projectNames); Collections.sort(projectNames);
@ -142,9 +148,9 @@ public class DBXMLQueries {
} }
/** /**
* Get some basic (not all) data for deployments associated with a project. Note that * Get some basic (not all) data for deployments associated with a project. Note that
* this may include deployments which are NOT part of the current dataset. That requires * this may include deployments which are NOT part of the current dataset. That requires
* a search on Instrument as well. * a search on Instrument as well.
* @param projectName * @param projectName
* @return * @return
*/ */
@ -164,20 +170,25 @@ public class DBXMLQueries {
if (doc == null) { if (doc == null) {
return null; return null;
} }
// System.out.println(pamXMLWriter.getAsString(doc)); // System.out.println(pamXMLWriter.getAsString(doc));
ArrayList<Deployment> deployments = new ArrayList<>(); ArrayList<Deployment> deployments = new ArrayList<>();
NodeList returns = doc.getElementsByTagName("Return"); NodeList returns = doc.getElementsByTagName("Deployment");
// if (returns.getLength() == 0) {
// // try REsult instead !
// returns = doc.getElementsByTagName("Result");
// }
// System.out.println("N projects = " + returns.getLength()); // System.out.println("N projects = " + returns.getLength());
int n = returns.getLength(); int n = returns.getLength();
// Queries queries = new Queries(null) // Queries queries = new Queries(null)
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
Node aNode = returns.item(i); Node aNode = returns.item(i);
if (aNode instanceof Element) { if (aNode instanceof Element) {
Element returnedEl = (Element) aNode; Element returnedEl = (Element) aNode;
String Id = getElementData(returnedEl, "Id"); String Id = getElementData(returnedEl, "Id");
String project = getElementData(returnedEl, "Project"); String project = getElementData(returnedEl, "Project");
String DeploymentId = getElementData(returnedEl, "DeploymentId"); String DeploymentId = getElementData(returnedEl, "DeploymentId");
@ -218,7 +229,7 @@ public class DBXMLQueries {
} }
return deployments; return deployments;
} }
/** /**
* Get a list of Detections documents which associate with a datablock and a deploymentId. * Get a list of Detections documents which associate with a datablock and a deploymentId.
* @param dataBlock * @param dataBlock
@ -227,7 +238,7 @@ public class DBXMLQueries {
*/ */
public ArrayList<String> getDetectionsDocuments(PamDataBlock dataBlock, String deploymentId) { public ArrayList<String> getDetectionsDocuments(PamDataBlock dataBlock, String deploymentId) {
/** /**
* first query for Detections documents associated with this deployment and datablock. * first query for Detections documents associated with this deployment and datablock.
*/ */
String queryNoDepl = "{\"species\":{\"query\":{\"op\":\"lib:abbrev2tsn\",\"optype\":\"function\",\"operands\":[\"%s\",\"SIO.SWAL.v1\"]},\"return\":{\"op\":\"lib:tsn2abbrev\",\"optype\":\"function\",\"operands\":[\"%s\",\"SIO.SWAL.v1\"]}},\"return\":[\"Detections/Id\"],\"select\":[{\"op\":\"=\",\"operands\":[\"Detections/Algorithm/Software\",\"LongDataName\"],\"optype\":\"binary\"}],\"enclose\":1}"; String queryNoDepl = "{\"species\":{\"query\":{\"op\":\"lib:abbrev2tsn\",\"optype\":\"function\",\"operands\":[\"%s\",\"SIO.SWAL.v1\"]},\"return\":{\"op\":\"lib:tsn2abbrev\",\"optype\":\"function\",\"operands\":[\"%s\",\"SIO.SWAL.v1\"]}},\"return\":[\"Detections/Id\"],\"select\":[{\"op\":\"=\",\"operands\":[\"Detections/Algorithm/Software\",\"LongDataName\"],\"optype\":\"binary\"}],\"enclose\":1}";
String queryWithDepl = "{\"species\":{\"query\":{\"op\":\"lib:abbrev2tsn\",\"optype\":\"function\",\"operands\":[\"%s\",\"SIO.SWAL.v1\"]},\"return\":{\"op\":\"lib:tsn2abbrev\",\"optype\":\"function\",\"operands\":[\"%s\",\"SIO.SWAL.v1\"]}},\"return\":[\"Detections/Id\"],\"select\":[{\"op\":\"=\",\"operands\":[\"Detections/Algorithm/Software\",\"LongDataName\"],\"optype\":\"binary\"},{\"op\":\"=\",\"operands\":[\"Detections/DataSource/DeploymentId\",\"TheDeploymentId\"],\"optype\":\"binary\"}],\"enclose\":1}"; String queryWithDepl = "{\"species\":{\"query\":{\"op\":\"lib:abbrev2tsn\",\"optype\":\"function\",\"operands\":[\"%s\",\"SIO.SWAL.v1\"]},\"return\":{\"op\":\"lib:tsn2abbrev\",\"optype\":\"function\",\"operands\":[\"%s\",\"SIO.SWAL.v1\"]}},\"return\":[\"Detections/Id\"],\"select\":[{\"op\":\"=\",\"operands\":[\"Detections/Algorithm/Software\",\"LongDataName\"],\"optype\":\"binary\"},{\"op\":\"=\",\"operands\":[\"Detections/DataSource/DeploymentId\",\"TheDeploymentId\"],\"optype\":\"binary\"}],\"enclose\":1}";
@ -252,7 +263,10 @@ public class DBXMLQueries {
} }
ArrayList<String> detectionsNames = new ArrayList(); ArrayList<String> detectionsNames = new ArrayList();
int count = 0; int count = 0;
NodeList returns = doc.getElementsByTagName("Return"); NodeList returns = doc.getElementsByTagName("Detections");
// if (returns.getLength() == 0) {
// returns = doc.getElementsByTagName("Result");
// }
for (int i = 0; i < returns.getLength(); i++) { for (int i = 0; i < returns.getLength(); i++) {
Node aNode = returns.item(i); Node aNode = returns.item(i);
String docName = aNode.getTextContent(); String docName = aNode.getTextContent();
@ -260,9 +274,9 @@ public class DBXMLQueries {
} }
return detectionsNames; return detectionsNames;
} }
/** /**
* Get the names of all detection documents for a given deployment for all data streams. * Get the names of all detection documents for a given deployment for all data streams.
* @param deploymentId * @param deploymentId
* @return * @return
*/ */
@ -273,17 +287,20 @@ public class DBXMLQueries {
if (queryResult == null || queryResult.queryException != null) { if (queryResult == null || queryResult.queryException != null) {
return null; return null;
} }
// PamguardXMLWriter pamXMLWriter = PamguardXMLWriter.getXMLWriter(); // PamguardXMLWriter pamXMLWriter = PamguardXMLWriter.getXMLWriter();
Document doc = convertStringToXMLDocument(queryResult.queryResult); Document doc = convertStringToXMLDocument(queryResult.queryResult);
if (doc == null) { if (doc == null) {
return null; return null;
} }
ArrayList<String> detectionDocs = new ArrayList<>(); ArrayList<String> detectionDocs = new ArrayList<>();
NodeList returns = doc.getElementsByTagName("Return"); NodeList returns = doc.getElementsByTagName("Return");
if (returns.getLength() == 0) {
returns = doc.getElementsByTagName("Result");
}
for (int i = 0; i < returns.getLength(); i++) { for (int i = 0; i < returns.getLength(); i++) {
Node aNode = returns.item(i); Node aNode = returns.item(i);
detectionDocs.add(aNode.getTextContent()); detectionDocs.add(aNode.getTextContent());
@ -293,7 +310,7 @@ public class DBXMLQueries {
public int countData(PamDataBlock dataBlock, String deploymentId) { public int countData(PamDataBlock dataBlock, String deploymentId) {
// /** // /**
// * first query for Detections documents associated with this deployment and datablock. // * first query for Detections documents associated with this deployment and datablock.
// */ // */
// String queryNoDepl = "{\"species\":{\"query\":{\"op\":\"lib:abbrev2tsn\",\"optype\":\"function\",\"operands\":[\"%s\",\"SIO.SWAL.v1\"]},\"return\":{\"op\":\"lib:tsn2abbrev\",\"optype\":\"function\",\"operands\":[\"%s\",\"SIO.SWAL.v1\"]}},\"return\":[\"Detections/Id\"],\"select\":[{\"op\":\"=\",\"operands\":[\"Detections/Algorithm/Software\",\"LongDataName\"],\"optype\":\"binary\"}],\"enclose\":1}"; // String queryNoDepl = "{\"species\":{\"query\":{\"op\":\"lib:abbrev2tsn\",\"optype\":\"function\",\"operands\":[\"%s\",\"SIO.SWAL.v1\"]},\"return\":{\"op\":\"lib:tsn2abbrev\",\"optype\":\"function\",\"operands\":[\"%s\",\"SIO.SWAL.v1\"]}},\"return\":[\"Detections/Id\"],\"select\":[{\"op\":\"=\",\"operands\":[\"Detections/Algorithm/Software\",\"LongDataName\"],\"optype\":\"binary\"}],\"enclose\":1}";
// String queryWithDepl = "{\"species\":{\"query\":{\"op\":\"lib:abbrev2tsn\",\"optype\":\"function\",\"operands\":[\"%s\",\"SIO.SWAL.v1\"]},\"return\":{\"op\":\"lib:tsn2abbrev\",\"optype\":\"function\",\"operands\":[\"%s\",\"SIO.SWAL.v1\"]}},\"return\":[\"Detections/Id\"],\"select\":[{\"op\":\"=\",\"operands\":[\"Detections/Algorithm/Software\",\"LongDataName\"],\"optype\":\"binary\"},{\"op\":\"=\",\"operands\":[\"Detections/DataSource/DeploymentId\",\"TheDeploymentId\"],\"optype\":\"binary\"}],\"enclose\":1}"; // String queryWithDepl = "{\"species\":{\"query\":{\"op\":\"lib:abbrev2tsn\",\"optype\":\"function\",\"operands\":[\"%s\",\"SIO.SWAL.v1\"]},\"return\":{\"op\":\"lib:tsn2abbrev\",\"optype\":\"function\",\"operands\":[\"%s\",\"SIO.SWAL.v1\"]}},\"return\":[\"Detections/Id\"],\"select\":[{\"op\":\"=\",\"operands\":[\"Detections/Algorithm/Software\",\"LongDataName\"],\"optype\":\"binary\"},{\"op\":\"=\",\"operands\":[\"Detections/DataSource/DeploymentId\",\"TheDeploymentId\"],\"optype\":\"binary\"}],\"enclose\":1}";
@ -324,17 +341,15 @@ public class DBXMLQueries {
return 0; return 0;
} }
int count = 0; int count = 0;
for (int i = 0; i < documentNames.size(); i++) { for (String docName : documentNames) {
// Node aNode = returns.item(i);
String docName = documentNames.get(i);
// System.out.println(aNode.getTextContent()); // System.out.println(aNode.getTextContent());
int count2 = countDetections2(docName); int count2 = countDetections2(docName);
count += count2; //countDetecionsData(docName); count += count2; //countDetecionsData(docName);
} }
return count; return count;
} }
/** /**
* Count on effort detections in a Detections document * Count on effort detections in a Detections document
* @param docName * @param docName
@ -349,7 +364,7 @@ public class DBXMLQueries {
try { try {
Queries queries = dbXMLConnect.getTethysQueries(); Queries queries = dbXMLConnect.getTethysQueries();
result = queries.QueryTethys(query); result = queries.QueryTethys(query);
// System.out.println(result); // System.out.println(result);
} }
catch (Exception e) { catch (Exception e) {
System.out.println("Error executing " + query); System.out.println("Error executing " + query);
@ -368,11 +383,11 @@ public class DBXMLQueries {
} }
// /** // /**
// * Get a count of the detections in a detections document. // * Get a count of the detections in a detections document.
// * Only looking in onEffort so far. // * Only looking in onEffort so far.
// * @param deploymentId // * @param deploymentId
// * @param detectionDocId // * @param detectionDocId
// * @param dataBlock // * @param dataBlock
// * @return // * @return
// */ // */
// public int getDetectionsDetectionCount(String deploymentId, String detectionDocId, PamDataBlock dataBlock) { // public int getDetectionsDetectionCount(String deploymentId, String detectionDocId, PamDataBlock dataBlock) {
@ -391,7 +406,7 @@ public class DBXMLQueries {
// if (doc == null) { // if (doc == null) {
// return 0; // return 0;
// } // }
// //
//// System.out.println(pamXMLWriter.getAsString(doc)); //// System.out.println(pamXMLWriter.getAsString(doc));
// //
//// ArrayList<String> detectionDocs = new ArrayList<>(); //// ArrayList<String> detectionDocs = new ArrayList<>();
@ -404,7 +419,7 @@ public class DBXMLQueries {
// /** // /**
// * This is the quickest way of counting data in a project, but it will load the start // * This is the quickest way of counting data in a project, but it will load the start
// * times for every detection in a project at once, so might use a lot of memory. Also // * times for every detection in a project at once, so might use a lot of memory. Also
// * it wll probably get data for all deployments in a project, which may not be what we want. // * it wll probably get data for all deployments in a project, which may not be what we want.
// * @param projectName // * @param projectName
// * @param dataPrefixes // * @param dataPrefixes
// * @return // * @return
@ -432,7 +447,7 @@ public class DBXMLQueries {
/** /**
* Count data within a deployment document which is associated with a set of datablocks * Count data within a deployment document which is associated with a set of datablocks
* Since the detections all come back in one query, it's easier to count all datablocks at once so * Since the detections all come back in one query, it's easier to count all datablocks at once so
* that it can all happen off a single query. * that it can all happen off a single query.
* @param id * @param id
* @param dataBlockPrefixes * @param dataBlockPrefixes
* @return * @return
@ -450,20 +465,20 @@ public class DBXMLQueries {
if (doc == null) { if (doc == null) {
return null; return null;
} }
// System.out.println(pamXMLWriter.getAsString(doc)); // System.out.println(pamXMLWriter.getAsString(doc));
NodeList detsDocs = doc.getElementsByTagName("Detections"); NodeList detsDocs = doc.getElementsByTagName("Detections");
int[] blockCounts = new int[dataPrefixes.length]; int[] blockCounts = new int[dataPrefixes.length];
// String detDocPrefix = projectId + "_" + dataBlock.getDataName(); // String detDocPrefix = projectId + "_" + dataBlock.getDataName();
// int totalCalls = 0; // int totalCalls = 0;
int detCount = 0; int detCount = 0;
int dataIndex; int dataIndex;
for (int i = 0; i < detsDocs.getLength(); i++) { for (int i = 0; i < detsDocs.getLength(); i++) {
Node detNode = detsDocs.item(i); Node detNode = detsDocs.item(i);
NodeList childNodes = detNode.getChildNodes(); NodeList childNodes = detNode.getChildNodes();
detCount = childNodes.getLength()-1; detCount = childNodes.getLength()-1;
dataIndex = -1; dataIndex = -1;
@ -531,8 +546,8 @@ public class DBXMLQueries {
} }
/** /**
* Get the basic information about a Detections document. This is basically everything apart from * Get the basic information about a Detections document. This is basically everything apart from
* the actual detections themselves. * the actual detections themselves.
* @param aDoc * @param aDoc
* @return * @return
*/ */
@ -549,7 +564,7 @@ public class DBXMLQueries {
return null; return null;
} }
// System.out.println(queryResult.queryResult); // System.out.println(queryResult.queryResult);
Detections detections = new Detections(); Detections detections = new Detections();
try { try {
Helper.createRequiredElements(detections); Helper.createRequiredElements(detections);
@ -564,7 +579,7 @@ public class DBXMLQueries {
return null; return null;
} }
Element result = (Element) returns.item(0); Element result = (Element) returns.item(0);
DescriptionType description = detections.getDescription(); DescriptionType description = detections.getDescription();
if (description == null) { if (description == null) {
description = new DescriptionType(); description = new DescriptionType();
@ -574,9 +589,9 @@ public class DBXMLQueries {
description.setAbstract(getElementData(result, "Description.Abstract")); description.setAbstract(getElementData(result, "Description.Abstract"));
description.setMethod(getElementData(result, "Description.Method")); description.setMethod(getElementData(result, "Description.Method"));
description.setObjectives(getElementData(result, "Description.Objectives")); description.setObjectives(getElementData(result, "Description.Objectives"));
// TODO Auto-generated method stub // TODO Auto-generated method stub
return detections; return detections;
} }

View File

@ -1,24 +1,14 @@
package tethys.dbxml; package tethys.dbxml;
import java.io.ByteArrayOutputStream;
import java.io.StringReader; import java.io.StringReader;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactoryConfigurationError;
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
import PamController.settings.output.xml.PamguardXMLWriter; import PamController.settings.output.xml.PamguardXMLWriter;
import PamUtils.XMLUtils;
import dbxml.JerseyClient; import dbxml.JerseyClient;
import tethys.output.TethysExportParams; import tethys.output.TethysExportParams;
@ -30,23 +20,23 @@ public class DMXMLQueryTest {
private void runTest() { private void runTest() {
TethysExportParams params = new TethysExportParams(); TethysExportParams params = new TethysExportParams();
JerseyClient jerseyClient = new JerseyClient(params.getFullServerName()); JerseyClient jerseyClient = new JerseyClient(params.getFullServerName());
// String testJson = "{\"return\":[\"Deployment/Project\",\"Deployment/DeploymentId\",\"Deployment/Site\",\"Deployment/DeploymentDetails/AudioTimeStamp\",\"Deployment/RecoveryDetails/AudioTimeStamp\"],\"select\":[],\"enclose\":1}"; // String testJson = "{\"return\":[\"Deployment/Project\",\"Deployment/DeploymentId\",\"Deployment/Site\",\"Deployment/DeploymentDetails/AudioTimeStamp\",\"Deployment/RecoveryDetails/AudioTimeStamp\"],\"select\":[],\"enclose\":1}";
// String testJson = "{\"return\":[\"Deployment/Project\",\"Deployment/Region\",\"Deployment/DeploymentDetails/AudioTimeStamp\",\"Deployment/RecoveryDetails/AudioTimeStamp\"],\"select\":[{\"op\":\"=\",\"operands\":[\"Deployment/DeploymentId\",\"2\"],\"optype\":\"binary\"}],\"enclose\":1}"; // String testJson = "{\"return\":[\"Deployment/Project\",\"Deployment/Region\",\"Deployment/DeploymentDetails/AudioTimeStamp\",\"Deployment/RecoveryDetails/AudioTimeStamp\"],\"select\":[{\"op\":\"=\",\"operands\":[\"Deployment/DeploymentId\",\"2\"],\"optype\":\"binary\"}],\"enclose\":1}";
//String testJson = "{\"return\":[\"Deployment/Project\",\"Deployment/Region\",\"Deployment/DeploymentDetails/AudioTimeStamp\",\"Deployment/RecoveryDetails/AudioTimeStamp\"],\"select\":[{\"op\":\"=\",\"operands\":[\"Deployment/DeploymentId\",\"2\"],\"optype\":\"binary\"},{\"op\":\"=\",\"operands\":[\"Deployment/Project\",\"DCLDE2022\"],\"optype\":\"binary\"}],\"enclose\":1}"; //String testJson = "{\"return\":[\"Deployment/Project\",\"Deployment/Region\",\"Deployment/DeploymentDetails/AudioTimeStamp\",\"Deployment/RecoveryDetails/AudioTimeStamp\"],\"select\":[{\"op\":\"=\",\"operands\":[\"Deployment/DeploymentId\",\"2\"],\"optype\":\"binary\"},{\"op\":\"=\",\"operands\":[\"Deployment/Project\",\"DCLDE2022\"],\"optype\":\"binary\"}],\"enclose\":1}";
// String testJson = "{\"return\":[\"Deployment/Project\",\"Deployment/Region\",\"Deployment/DeploymentDetails/AudioTimeStamp\",\"Deployment/RecoveryDetails/AudioTimeStamp\",\"Deployment/DeploymentId\"],\"select\":[{\"op\":\"=\",\"operands\":[\"Deployment/DeploymentId\",\"2\"],\"optype\":\"binary\"},{\"op\":\"=\",\"operands\":[\"Deployment/Project\",\"DCLDE2022\"],\"optype\":\"binary\"}],\"enclose\":1}"; // String testJson = "{\"return\":[\"Deployment/Project\",\"Deployment/Region\",\"Deployment/DeploymentDetails/AudioTimeStamp\",\"Deployment/RecoveryDetails/AudioTimeStamp\",\"Deployment/DeploymentId\"],\"select\":[{\"op\":\"=\",\"operands\":[\"Deployment/DeploymentId\",\"2\"],\"optype\":\"binary\"},{\"op\":\"=\",\"operands\":[\"Deployment/Project\",\"DCLDE2022\"],\"optype\":\"binary\"}],\"enclose\":1}";
String testJson = "{\"return\":[\"Deployment/Project\"],\"select\":[],\"enclose\":1}"; String testJson = "{\"return\":[\"Deployment/Project\"],\"select\":[],\"enclose\":1}";
// web browse to http://localhost:9779/Client // web browse to http://localhost:9779/Client
String testResult = jerseyClient.queryJSON(testJson); String testResult = jerseyClient.queryJSON(testJson);
Document doc = convertStringToXMLDocument(testResult); Document doc = convertStringToXMLDocument(testResult);
PamguardXMLWriter pamXMLWriter = PamguardXMLWriter.getXMLWriter(); PamguardXMLWriter pamXMLWriter = PamguardXMLWriter.getXMLWriter();
String formettedXML = pamXMLWriter.getAsString(doc, true); String formettedXML = pamXMLWriter.getAsString(doc, true);
System.out.println(testResult); System.out.println(testResult);
System.out.println(formettedXML); System.out.println(formettedXML);
// try { // try {

View File

@ -1,9 +1,9 @@
package tethys.dbxml; package tethys.dbxml;
public class ServerStatus { public class ServerStatus {
public boolean ok; public boolean ok;
public Exception error; public Exception error;
public ServerStatus(boolean ok, Exception error) { public ServerStatus(boolean ok, Exception error) {
@ -11,7 +11,7 @@ public class ServerStatus {
this.ok = ok; this.ok = ok;
this.error = error; this.error = error;
} }
public String getFormatted() { public String getFormatted() {
if (ok) { if (ok) {
return "Server OK"; return "Server OK";
@ -30,6 +30,6 @@ public class ServerStatus {
public String toString() { public String toString() {
return getFormatted(); return getFormatted();
} }
} }

View File

@ -29,7 +29,10 @@ public class StreamExportParams implements Serializable {
public GranularityEnumType granularity = GranularityEnumType.CALL; public GranularityEnumType granularity = GranularityEnumType.CALL;
public nilus.DescriptionType detectionDescription; /*
* Can't have this here since it isn't serializable.
*/
transient public nilus.DescriptionType detectionDescription;
public DescriptionType getDetectionDescription() { public DescriptionType getDetectionDescription() {
if (detectionDescription == null) { if (detectionDescription == null) {

View File

@ -86,7 +86,7 @@ public class PAMGuardDeploymentsTable extends TethysGUIPanel {
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
int aRow = table.getSelectedRow(); int aRow = table.getSelectedRow();
int col = table.getSelectedColumn(); int col = table.getSelectedColumn();
if (aRow >= 0 && aRow < selection.length && col == 6) { if (aRow >= 0 && aRow < selection.length && col == TableModel.SELECTCOLUMN) {
selection[aRow] = !selection[aRow]; selection[aRow] = !selection[aRow];
for (DeploymentTableObserver obs : observers) { for (DeploymentTableObserver obs : observers) {
obs.selectionChanged(); obs.selectionChanged();
@ -193,7 +193,9 @@ public class PAMGuardDeploymentsTable extends TethysGUIPanel {
private class TableModel extends AbstractTableModel { private class TableModel extends AbstractTableModel {
private String[] columnNames = {"Id", "Start", "Stop", "Duration", "Cycle", "Tethys Deployment", "Select"}; private String[] columnNames = {"Id", "Start", "Stop", "Gap", "Duration", "Cycle", "Tethys Deployment", "Select"};
private static final int SELECTCOLUMN = 7;
@Override @Override
public int getRowCount() { public int getRowCount() {
@ -217,7 +219,7 @@ public class PAMGuardDeploymentsTable extends TethysGUIPanel {
@Override @Override
public Class<?> getColumnClass(int columnIndex) { public Class<?> getColumnClass(int columnIndex) {
if (columnIndex == 6) { if (columnIndex == SELECTCOLUMN) {
return Boolean.class; return Boolean.class;
// return JCheckBox.class; // return JCheckBox.class;
} }
@ -228,40 +230,45 @@ public class PAMGuardDeploymentsTable extends TethysGUIPanel {
public Object getValueAt(int rowIndex, int columnIndex) { public Object getValueAt(int rowIndex, int columnIndex) {
RecordingPeriod period = deploymentOverview.getRecordingPeriods().get(rowIndex); RecordingPeriod period = deploymentOverview.getRecordingPeriods().get(rowIndex);
// DeploymentRecoveryPair deplInfo = deploymentInfo.get(rowIndex); // DeploymentRecoveryPair deplInfo = deploymentInfo.get(rowIndex);
if (columnIndex == 4) { if (columnIndex == 5) {
return deploymentOverview.getDutyCycleInfo(); return deploymentOverview.getDutyCycleInfo();
} }
if (columnIndex == 3 && rowIndex > 0) {
RecordingPeriod prevPeriod = deploymentOverview.getRecordingPeriods().get(rowIndex-1);
long gap = period.getRecordStart() - prevPeriod.getRecordStop();
return PamCalendar.formatDuration(gap);
}
return getValueAt(period, rowIndex, columnIndex); return getValueAt(period, rowIndex, columnIndex);
} }
private Object getValueAt(RecordingPeriod period, int rowIndex, int columnIndex) {
switch (columnIndex) {
case 0:
return rowIndex;
case 1:
return PamCalendar.formatDBDateTime(period.getRecordStart());
// return TethysTimeFuncs.formatGregorianTime(deplInfo.deploymentDetails.getAudioTimeStamp());
case 2:
return PamCalendar.formatDBDateTime(period.getRecordStop());
// return TethysTimeFuncs.formatGregorianTime(deplInfo.recoveryDetails.getAudioTimeStamp());
case 4:
// long t1 = TethysTimeFuncs.millisFromGregorianXML(deplInfo.deploymentDetails.getAudioTimeStamp());
// long t2 = TethysTimeFuncs.millisFromGregorianXML(deplInfo.recoveryDetails.getAudioTimeStamp());
return PamCalendar.formatDuration(period.getRecordStop()-period.getRecordStart());
case 6:
PDeployment deployment = period.getMatchedTethysDeployment();
return makeDeplString(period, deployment);
case SELECTCOLUMN:
// return selectBoxes[rowIndex];
return selection[rowIndex];
}
return null;
}
@Override @Override
public boolean isCellEditable(int rowIndex, int columnIndex) { public boolean isCellEditable(int rowIndex, int columnIndex) {
return columnIndex == 6; return columnIndex == SELECTCOLUMN;
}
private Object getValueAt(RecordingPeriod period, int rowIndex, int columnIndex) {
switch (columnIndex) {
case 0:
return rowIndex;
case 1:
return PamCalendar.formatDBDateTime(period.getRecordStart());
// return TethysTimeFuncs.formatGregorianTime(deplInfo.deploymentDetails.getAudioTimeStamp());
case 2:
return PamCalendar.formatDBDateTime(period.getRecordStop());
// return TethysTimeFuncs.formatGregorianTime(deplInfo.recoveryDetails.getAudioTimeStamp());
case 3:
// long t1 = TethysTimeFuncs.millisFromGregorianXML(deplInfo.deploymentDetails.getAudioTimeStamp());
// long t2 = TethysTimeFuncs.millisFromGregorianXML(deplInfo.recoveryDetails.getAudioTimeStamp());
return PamCalendar.formatDuration(period.getRecordStop()-period.getRecordStart());
case 5:
PDeployment deployment = period.getMatchedTethysDeployment();
return makeDeplString(period, deployment);
case 6:
// return selectBoxes[rowIndex];
return selection[rowIndex];
}
return null;
} }
private String makeDeplString(RecordingPeriod period, PDeployment deployment) { private String makeDeplString(RecordingPeriod period, PDeployment deployment) {