Merge branch 'Tethys' of https://github.com/douggillespie/PAMGuard into Tethys

This commit is contained in:
Marie 2024-01-20 20:01:19 -08:00
commit 98bc7587b5
7 changed files with 285 additions and 1 deletions

View File

@ -45,9 +45,11 @@ import tethys.TethysTimeFuncs;
import tethys.calibration.swing.CalibrationsExportWizard;
import tethys.dbxml.DBXMLConnect;
import tethys.dbxml.TethysException;
import tethys.niluswraps.NilusChecker;
import tethys.niluswraps.NilusSettingsWrapper;
import tethys.niluswraps.NilusUnpacker;
import tethys.pamdata.AutoTethysProvider;
import tethys.reporter.TethysReporter;
public class CalibrationHandler implements TethysStateObserver {
@ -186,6 +188,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();
@ -195,9 +198,20 @@ public class CalibrationHandler implements TethysStateObserver {
calDoc.setMetadataInfo(sampleCal.getMetadataInfo());
calDoc.setProcess(sampleCal.getProcess());
calDoc.setQualityAssurance(sampleCal.getQualityAssurance());
if (NilusChecker.isEmpty(sampleCal.getResponsibleParty()) == false) {
calDoc.setResponsibleParty(sampleCal.getResponsibleParty());
}
calDoc.setTimeStamp(sampleCal.getTimeStamp());
}
// check the contact info in the metadata.
// can't so because it's required.
// MetadataInfo metaData = calDoc.getMetadataInfo();
// if (metaData != null) {
// if (NilusChecker.isEmpty(metaData.getContact())) {
// metaData.setContact(null);
// }
// }
addParameterDetails(calDoc, i);
@ -233,6 +247,7 @@ public class CalibrationHandler implements TethysStateObserver {
}
}
tethysControl.sendStateUpdate(new TethysState(TethysState.StateType.EXPORTRDATA, Collection.Calibrations));
TethysReporter.getTethysReporter().showReport(true);
return nExport;
}
@ -405,6 +420,10 @@ public class CalibrationHandler implements TethysStateObserver {
hz.add(Double.valueOf(0));
db.add(Double.valueOf(hSens+preampGain));
if (NilusChecker.isEmpty(calibration.getResponsibleParty())) {
calibration.setResponsibleParty(null);
}
MetadataInfo metaInf = calibration.getMetadataInfo();
if (metaInf == null) {
metaInf = new MetadataInfo();
@ -417,6 +436,12 @@ public class CalibrationHandler implements TethysStateObserver {
contact = new ResponsibleParty();
metaInf.setContact(contact);
}
if (NilusChecker.isEmpty(metaInf.getContact())) {
metaInf.setContact(null);
}
if (NilusChecker.isEmpty(metaInf)) {
calibration.setMetadataInfo(null);
}
contact.setIndividualName("Unknown");
contact.setOrganizationName("unknown");

View File

@ -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);

View File

@ -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);
}
/**

View File

@ -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

View File

@ -0,0 +1,75 @@
package tethys.niluswraps;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;
import nilus.ResponsibleParty;
/**
* A few static checks of some nilus classes to see if it's
* worth writing them or not.
* @author dg50
*
*/
public class NilusChecker {
public static boolean isEmpty(Object nilusObject) {
boolean empty = true;
if (nilusObject == null) {
return true;
}
// and check all getters
Class<? extends Object> nilusClass = nilusObject.getClass();
Method[] methods = nilusClass.getDeclaredMethods();
// searching for getters.
int nGet = 0;
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
if (method.getName().startsWith("get") && method.getParameterCount() == 0) {
nGet ++;
try {
Object got = method.invoke(nilusObject, null);
if (got != null) {
if (got instanceof String) {
if (isEmptyString((String) got) == false) {
empty = false;
}
}
else if (got instanceof List<?>) {
if (isEmptyList((List) got) == false) {
empty = false;
}
}
else if (isEmpty(got) == false) {// it's some other class type, so recurecively ask back here.
empty = false;
}
}
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
return false; // better save than sorry if we don't understand.
}
}
}
if (nGet == 0) {
// there weren't any understandable getters, so assume not empty. May be some other primitive type.
empty = false;
}
return empty;
}
private static boolean isEmptyList(List got) {
if (got == null) {
return true;
}
return got.size() == 0;
}
public static boolean isEmptyString(String string) {
if (string == null || string.length() == 0) {
return true;
}
return false;
}
}

View 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;
}
}

View 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();
}
}
}