diff --git a/src/tethys/calibration/CalibrationHandler.java b/src/tethys/calibration/CalibrationHandler.java index 15f3ece4..f3ce8bfe 100644 --- a/src/tethys/calibration/CalibrationHandler.java +++ b/src/tethys/calibration/CalibrationHandler.java @@ -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 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; } diff --git a/src/tethys/dbxml/DBXMLConnect.java b/src/tethys/dbxml/DBXMLConnect.java index e13b05fd..d3008e30 100644 --- a/src/tethys/dbxml/DBXMLConnect.java +++ b/src/tethys/dbxml/DBXMLConnect.java @@ -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(""); + 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); diff --git a/src/tethys/deployment/DeploymentHandler.java b/src/tethys/deployment/DeploymentHandler.java index 85f834c3..610edac3 100644 --- a/src/tethys/deployment/DeploymentHandler.java +++ b/src/tethys/deployment/DeploymentHandler.java @@ -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 selectedDeployments) { + TethysReporter.getTethysReporter().clear(); if (deploymentExportOptions.separateDeployments) { exportSeparateDeployments(selectedDeployments); } else { exportOneDeploymnet(selectedDeployments); } + TethysReporter.getTethysReporter().showReport(tethysControl.getGuiFrame(), true); } /** diff --git a/src/tethys/detection/DetectionsHandler.java b/src/tethys/detection/DetectionsHandler.java index b5740ea7..f797c8ee 100644 --- a/src/tethys/detection/DetectionsHandler.java +++ b/src/tethys/detection/DetectionsHandler.java @@ -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 diff --git a/src/tethys/reporter/TethysReport.java b/src/tethys/reporter/TethysReport.java new file mode 100644 index 00000000..62c3164e --- /dev/null +++ b/src/tethys/reporter/TethysReport.java @@ -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; + } + +} diff --git a/src/tethys/reporter/TethysReporter.java b/src/tethys/reporter/TethysReporter.java new file mode 100644 index 00000000..15228a83 --- /dev/null +++ b/src/tethys/reporter/TethysReporter.java @@ -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 tethysReports; + + private TethysReporter() { + tethysReports = new ArrayList(); + } + + /** + * 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 = ""; + for (int i = 0; i < tethysReports.size(); i++) { + TethysReport aReport = tethysReports.get(i); + String res = aReport.isSuccess() ? "Success" : "Failure"; + if (i > 0) { + str += "
"; + } + str += String.format("%s writing %s document %s to Tethys", res, aReport.getCollection().collectionName(), aReport.getDocName()); + } + + + str += ""; + 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(); + } + } +}