mirror of
https://github.com/PAMGuard/PAMGuard.git
synced 2024-11-21 22:52:22 +00:00
Reporting outputs to user
Use Pamguard WarnOnce system to show a message of success or failure after attempting to output to Tethys.
This commit is contained in:
parent
fa02c9826c
commit
65300d719a
@ -48,6 +48,7 @@ import tethys.dbxml.TethysException;
|
||||
import tethys.niluswraps.NilusSettingsWrapper;
|
||||
import tethys.niluswraps.NilusUnpacker;
|
||||
import tethys.pamdata.AutoTethysProvider;
|
||||
import tethys.reporter.TethysReporter;
|
||||
|
||||
public class CalibrationHandler implements TethysStateObserver {
|
||||
|
||||
@ -186,6 +187,7 @@ public class CalibrationHandler implements TethysStateObserver {
|
||||
int nExport = 0;
|
||||
boolean overwrite = false;
|
||||
boolean exists;
|
||||
TethysReporter.getTethysReporter().clear();
|
||||
for (int i = 0; i < nPhone; i++) {
|
||||
// String docName = getHydrophoneId(i);
|
||||
NilusSettingsWrapper<Calibration> clonedWrap = wrappedSample.clone();
|
||||
@ -233,6 +235,7 @@ public class CalibrationHandler implements TethysStateObserver {
|
||||
}
|
||||
}
|
||||
tethysControl.sendStateUpdate(new TethysState(TethysState.StateType.EXPORTRDATA, Collection.Calibrations));
|
||||
TethysReporter.getTethysReporter().showReport(true);
|
||||
return nExport;
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,8 @@ import tethys.TethysControl;
|
||||
import tethys.database.TethysActions;
|
||||
import tethys.database.TethysLogger;
|
||||
import tethys.output.TethysExportParams;
|
||||
import tethys.reporter.TethysReport;
|
||||
import tethys.reporter.TethysReporter;
|
||||
|
||||
/**
|
||||
* Class containing functions for managing the database connection. Opening, closing,
|
||||
@ -207,6 +209,8 @@ public class DBXMLConnect {
|
||||
*/
|
||||
boolean error = importReturn.contains("<Error");
|
||||
boolean success = importReturn.contains("<Success>");
|
||||
String name = tempFile.getName();
|
||||
TethysReporter.getTethysReporter().addReport(new TethysReport(success, collection, name, name));
|
||||
// error = !success; might be a better options.
|
||||
if (error) {
|
||||
throw new TethysException("Error posting to Tethys", importReturn);
|
||||
|
@ -84,6 +84,7 @@ import tethys.deployment.swing.RecordingGapDialog;
|
||||
import tethys.niluswraps.PDeployment;
|
||||
import tethys.output.TethysExportParams;
|
||||
import tethys.pamdata.AutoTethysProvider;
|
||||
import tethys.reporter.TethysReporter;
|
||||
import tethys.swing.DeploymentTableObserver;
|
||||
|
||||
/**
|
||||
@ -387,12 +388,14 @@ public class DeploymentHandler implements TethysStateObserver, DeploymentTableOb
|
||||
* @param selectedDeployments
|
||||
*/
|
||||
public void exportDeployments(ArrayList<RecordingPeriod> selectedDeployments) {
|
||||
TethysReporter.getTethysReporter().clear();
|
||||
if (deploymentExportOptions.separateDeployments) {
|
||||
exportSeparateDeployments(selectedDeployments);
|
||||
}
|
||||
else {
|
||||
exportOneDeploymnet(selectedDeployments);
|
||||
}
|
||||
TethysReporter.getTethysReporter().showReport(tethysControl.getGuiFrame(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -43,6 +43,7 @@ import tethys.output.DatablockSynchInfo;
|
||||
import tethys.output.StreamExportParams;
|
||||
import tethys.output.TethysExportParams;
|
||||
import tethys.pamdata.TethysDataProvider;
|
||||
import tethys.reporter.TethysReporter;
|
||||
import tethys.species.DataBlockSpeciesManager;
|
||||
import tethys.swing.export.DetectionsExportWizard;
|
||||
|
||||
@ -587,6 +588,7 @@ public class DetectionsHandler {
|
||||
this.dataBlock = dataBlock;
|
||||
this.exportParams = exportParams;
|
||||
this.exportObserver = exportObserver;
|
||||
TethysReporter.getTethysReporter().clear();
|
||||
}
|
||||
|
||||
public void publish(DetectionExportProgress exportProgress) {
|
||||
@ -617,6 +619,7 @@ public class DetectionsHandler {
|
||||
DetectionExportProgress prog = new DetectionExportProgress(null, null, 0, 0, 0, 0, DetectionExportProgress.STATE_COMPLETE);
|
||||
tethysControl.exportedDetections(dataBlock);
|
||||
exportObserver.update(prog);
|
||||
TethysReporter.getTethysReporter().showReport(tethysControl.getGuiFrame(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
56
src/tethys/reporter/TethysReport.java
Normal file
56
src/tethys/reporter/TethysReport.java
Normal file
@ -0,0 +1,56 @@
|
||||
package tethys.reporter;
|
||||
|
||||
import tethys.Collection;
|
||||
|
||||
public class TethysReport {
|
||||
|
||||
private boolean success;
|
||||
|
||||
private Collection collection;
|
||||
|
||||
private String docName;
|
||||
|
||||
private String docId;
|
||||
|
||||
/**
|
||||
* @param success
|
||||
* @param collection
|
||||
* @param docName
|
||||
* @param docId
|
||||
*/
|
||||
public TethysReport(boolean success, Collection collection, String docName, String docId) {
|
||||
this.success = success;
|
||||
this.collection = collection;
|
||||
this.docName = docName;
|
||||
this.docId = docId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the success
|
||||
*/
|
||||
public boolean isSuccess() {
|
||||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the collection
|
||||
*/
|
||||
public Collection getCollection() {
|
||||
return collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the docName
|
||||
*/
|
||||
public String getDocName() {
|
||||
return docName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the docId
|
||||
*/
|
||||
public String getDocId() {
|
||||
return docId;
|
||||
}
|
||||
|
||||
}
|
118
src/tethys/reporter/TethysReporter.java
Normal file
118
src/tethys/reporter/TethysReporter.java
Normal file
@ -0,0 +1,118 @@
|
||||
package tethys.reporter;
|
||||
|
||||
import java.awt.Window;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import PamController.PamController;
|
||||
import PamView.dialog.warn.WarnOnce;
|
||||
|
||||
/**
|
||||
* Set of functions to provide mesage reports on Tethys output. This
|
||||
* will work with the existing WarnOnce type pop-up, the primary purpose
|
||||
* of the functions here being to collate information, possibly from
|
||||
* several document writes, before issuing an overall report.
|
||||
* @author dg50
|
||||
*
|
||||
*/
|
||||
public class TethysReporter {
|
||||
|
||||
private static TethysReporter singleInstance;
|
||||
|
||||
private ArrayList<TethysReport> tethysReports;
|
||||
|
||||
private TethysReporter() {
|
||||
tethysReports = new ArrayList<TethysReport>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the reporter.
|
||||
* @return
|
||||
*/
|
||||
public static final TethysReporter getTethysReporter() {
|
||||
if (singleInstance == null) {
|
||||
singleInstance = new TethysReporter();
|
||||
}
|
||||
return singleInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all reports
|
||||
*/
|
||||
synchronized public void clear() {
|
||||
tethysReports.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a report after attempting to write a document
|
||||
* @param report
|
||||
*/
|
||||
synchronized public void addReport(TethysReport report) {
|
||||
tethysReports.add(report);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current number of reports
|
||||
* @return number of reports
|
||||
*/
|
||||
synchronized public int getSize() {
|
||||
return tethysReports.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a summary string of all reported writes using html to separate each ont a separat eline
|
||||
* @return
|
||||
*/
|
||||
synchronized public String getReportString() {
|
||||
if (tethysReports.size() == 0) {
|
||||
return "No reports";
|
||||
}
|
||||
String str = "<html>";
|
||||
for (int i = 0; i < tethysReports.size(); i++) {
|
||||
TethysReport aReport = tethysReports.get(i);
|
||||
String res = aReport.isSuccess() ? "Success" : "Failure";
|
||||
if (i > 0) {
|
||||
str += "<br>";
|
||||
}
|
||||
str += String.format("%s writing %s document %s to Tethys", res, aReport.getCollection().collectionName(), aReport.getDocName());
|
||||
}
|
||||
|
||||
|
||||
str += "</html>";
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a count of failed document writes
|
||||
* @return failure count
|
||||
*/
|
||||
public int countFails() {
|
||||
int fails = 0;
|
||||
for (TethysReport aReport : tethysReports) {
|
||||
if (aReport.isSuccess() == false) {
|
||||
fails++;
|
||||
}
|
||||
}
|
||||
return fails;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a report in a popup window
|
||||
* @param clear clear the list of reports afterwards
|
||||
*/
|
||||
public void showReport(boolean clear) {
|
||||
showReport(PamController.getMainFrame(), clear);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a report on a popup window
|
||||
* @param window parent frame
|
||||
* @param clear clear the list of reports afterwards
|
||||
*/
|
||||
public void showReport(Window window, boolean clear) {
|
||||
boolean probs = countFails() > 0;
|
||||
WarnOnce.showNamedWarning("TethysReporter", window, "Tethys Document Writer", getReportString(), WarnOnce.WARNING_MESSAGE);
|
||||
if (clear) {
|
||||
clear();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user