From 68b7d08bc69f4c25ff54da657c8ee1308d313565 Mon Sep 17 00:00:00 2001 From: kbolaughlin Date: Tue, 14 Mar 2023 14:14:22 -0700 Subject: [PATCH 1/4] Update TethysExporter.java minor tweak --- src/tethys/output/TethysExporter.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tethys/output/TethysExporter.java b/src/tethys/output/TethysExporter.java index 7a419c1e..ee8765e6 100644 --- a/src/tethys/output/TethysExporter.java +++ b/src/tethys/output/TethysExporter.java @@ -43,6 +43,7 @@ import tethys.TethysControl; import tethys.TethysLocationFuncs; import tethys.TethysTimeFuncs; import tethys.dbxml.DBXMLConnect; +import tethys.deployment.DeploymentRecoveryPair; import tethys.pamdata.TethysDataProvider; import tethys.pamdata.TethysSchema; From ceefa6188c53d4ee058aa1041ca6f104aaec3ec4 Mon Sep 17 00:00:00 2001 From: kbolaughlin Date: Wed, 15 Mar 2023 12:38:29 -0700 Subject: [PATCH 2/4] Update TethysExporter.java updated export code to add namespace to the xml produced --- src/tethys/output/TethysExporter.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/tethys/output/TethysExporter.java b/src/tethys/output/TethysExporter.java index 83de0132..c5396c3a 100644 --- a/src/tethys/output/TethysExporter.java +++ b/src/tethys/output/TethysExporter.java @@ -1,7 +1,7 @@ package tethys.output; import java.io.IOException; -import java.io.StringWriter; +import java.io.PrintWriter; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; @@ -30,6 +30,7 @@ import dbxml.uploader.Importer; import metadata.MetaDataContol; import metadata.deployment.DeploymentData; import nilus.Deployment; +import nilus.MarshalXML; import tethys.TethysControl; import tethys.dbxml.DBXMLConnect; import tethys.deployment.DeploymentHandler; @@ -85,16 +86,12 @@ public class TethysExporter { Path tempFile = null; try { - - JAXBContext jaxB = JAXBContext.newInstance(Deployment.class); - Marshaller marshall = jaxB.createMarshaller(); - marshall.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); - StringWriter sw = new StringWriter(); - marshall.marshal(deployment1, sw); + + MarshalXML marshal = new MarshalXML(); + marshal.createInstance(Deployment.class); tempFile = Files.createTempFile("pamGuardToTethys", ".xml"); - Files.write(tempFile, sw.toString().getBytes()); - - String fileText = Importer.ImportFiles("http://localhost:9779", "Deployment", + marshal.marshal(deployment1, tempFile.toString()); + String fileError = Importer.ImportFiles("http://localhost:9779", "Deployments", new String[] { tempFile.toString() }, "", "", false); tempFile.toFile().deleteOnExit(); @@ -110,6 +107,7 @@ public class TethysExporter { e.printStackTrace(); } + SnapshotGeometry arrayGeometry = findArrayGeometrey(); /** From f15a6dafa6ca1591ddb410a447348a3f76966cfd Mon Sep 17 00:00:00 2001 From: kbolaughlin Date: Wed, 15 Mar 2023 15:05:33 -0700 Subject: [PATCH 3/4] TethysExportControl add post to tethys code in TethysExportControl --- src/tethys/dbxml/DBXMLConnect.java | 89 ++++++++++++++++++++ src/tethys/deployment/DeploymentHandler.java | 2 +- src/tethys/detection/DetectionsHandler.java | 2 +- src/tethys/output/StreamExportParams.java | 2 +- src/tethys/output/TethysExportParams.java | 9 +- src/tethys/output/TethysExporter.java | 34 +------- 6 files changed, 102 insertions(+), 36 deletions(-) diff --git a/src/tethys/dbxml/DBXMLConnect.java b/src/tethys/dbxml/DBXMLConnect.java index c1613cd9..7b7439a5 100644 --- a/src/tethys/dbxml/DBXMLConnect.java +++ b/src/tethys/dbxml/DBXMLConnect.java @@ -1,6 +1,21 @@ package tethys.dbxml; +import java.io.IOException; +import java.nio.file.Files; +import java.util.List; + +import javax.xml.bind.JAXBException; + +import java.nio.file.Files; +import java.nio.file.Path; + +import dbxml.uploader.Importer; +import nilus.Deployment; +import nilus.MarshalXML; import tethys.TethysControl; +import tethys.output.TethysExportParams; +import tethys.output.StreamExportParams; +import PamguardMVC.PamDataBlock; /** * Class containing functions for managing the database connection. Opening, closing, @@ -16,6 +31,80 @@ public class DBXMLConnect { this.tethysControl = tethysControl; } + + /** + * take list of nilus objects loaded with PamGuard data and post them to the Tethys database + * all objects must be of the same nilus object + * TethysExportParams obj used from UI inputs + * + * @param pamGuardObjs all nilus objects loaded with PamGuard data + * @return error string, null string means there are no errors + */ + public String postToTethys(List pamGuardObjs) + { + Class objClass = pamGuardObjs.get(0).getClass(); + String collection = getTethysCollection(objClass.getName()); + PamDataBlock defaultPamBlock = null; + TethysExportParams params = new TethysExportParams(); + String fileError = null; + try { + MarshalXML marshal = new MarshalXML(); + marshal.createInstance(objClass); + for (Object obj : pamGuardObjs ) + { + Path tempFile = Files.createTempFile("pamGuardToTethys", ".xml"); + marshal.marshal(obj, tempFile.toString()); + fileError = Importer.ImportFiles(params.getFullServerName(), collection, + new String[] { tempFile.toString() }, "", "", false); + + System.out.println(fileError); + + tempFile.toFile().deleteOnExit(); + } + } catch(IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (JAXBException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return fileError; + } + + /** + * get tethys collection name from nilus collection objects + * @param className nilus object Class Name + * @return name of Tethys collection + */ + private String getTethysCollection(String className) { + switch(className) { + case "nilus.Deployment": + return "Deployments"; + case "nilus.Detection": + return "Detections"; + case "nilus.Calibration": + return "Calibrations"; + case "nilus.Ensemble": + return "Ensembles"; + case "nilus.Localization": + return "Localizations"; + case "nilus.SpeciesAbbreviation": + return "SpeciesAbbreviations"; + case "nilus.SourceMap": + return "SourceMaps"; + case "nilus.ITIS": + return "ITIS"; + case "nilus.ranks": + return "ITIS_ranks"; + default: + return ""; + } + } + public boolean openDatabase() { return true; diff --git a/src/tethys/deployment/DeploymentHandler.java b/src/tethys/deployment/DeploymentHandler.java index c5466966..955374b2 100644 --- a/src/tethys/deployment/DeploymentHandler.java +++ b/src/tethys/deployment/DeploymentHandler.java @@ -141,7 +141,7 @@ public class DeploymentHandler { } double[] ons = new double[n-1]; // ignore the last one since it may be artificially shortened which is OK double[] gaps = new double[n-1]; - for (int i = 0; i < n; i++) { + for (int i = 0; i < n-1; i++) { ons[i] = tempPeriods.get(i).getDuration(); } return null; diff --git a/src/tethys/detection/DetectionsHandler.java b/src/tethys/detection/DetectionsHandler.java index 4179d98f..e5e9934b 100644 --- a/src/tethys/detection/DetectionsHandler.java +++ b/src/tethys/detection/DetectionsHandler.java @@ -166,7 +166,7 @@ public class DetectionsHandler { * We should now have a fully populated Detections object, so write it to the database * using functions in DBXMLConnect */ - tethysControl.getDbxmlConnect(); // call whatever you need to call in here to write the Detections. + //tethysControl.getDbxmlConnect().postToTethys(detectionList); // call whatever you need to call in here to write the Detections. return true; diff --git a/src/tethys/output/StreamExportParams.java b/src/tethys/output/StreamExportParams.java index b19af599..d4842e64 100644 --- a/src/tethys/output/StreamExportParams.java +++ b/src/tethys/output/StreamExportParams.java @@ -12,7 +12,7 @@ import java.io.Serializable; */ public class StreamExportParams implements Serializable { - public static final long serialVersionUID = 1L; + public static final long serialVersionUID = 1L; public StreamExportParams(String longDataName, boolean selected) { super(); diff --git a/src/tethys/output/TethysExportParams.java b/src/tethys/output/TethysExportParams.java index bd1889af..c9d848e0 100644 --- a/src/tethys/output/TethysExportParams.java +++ b/src/tethys/output/TethysExportParams.java @@ -2,9 +2,9 @@ package tethys.output; import java.io.Serializable; import java.util.HashMap; - import PamguardMVC.PamDataBlock; + /** * Parameters for controlling export of Tethys data. * @author dg50 @@ -18,6 +18,13 @@ public class TethysExportParams implements Serializable, Cloneable{ * Need to add lots of other parameters here, such as the connection detils * for the tethys database. */ + public String serverName = "http://localhost"; + + public String port = "9779"; + + public String getFullServerName() { + return serverName + ":" + port; + } private HashMap streamParamsMap = new HashMap(); diff --git a/src/tethys/output/TethysExporter.java b/src/tethys/output/TethysExporter.java index e9924250..52554f0a 100644 --- a/src/tethys/output/TethysExporter.java +++ b/src/tethys/output/TethysExporter.java @@ -30,7 +30,6 @@ import dbxml.uploader.Importer; import metadata.MetaDataContol; import metadata.deployment.DeploymentData; import nilus.Deployment; -import nilus.MarshalXML; import tethys.TethysControl; import tethys.dbxml.DBXMLConnect; import tethys.deployment.DeploymentHandler; @@ -83,36 +82,7 @@ public class TethysExporter { */ // return false; // } - - Deployment deployment1 = new Deployment(); - deployment1.setId("1"); - - Path tempFile = null; - try { - - MarshalXML marshal = new MarshalXML(); - marshal.createInstance(Deployment.class); - tempFile = Files.createTempFile("pamGuardToTethys", ".xml"); - marshal.marshal(deployment1, tempFile.toString()); - String fileError = Importer.ImportFiles("http://localhost:9779", "Deployments", - new String[] { tempFile.toString() }, "", "", false); - - tempFile.toFile().deleteOnExit(); - - } catch(IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (JAXBException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - - SnapshotGeometry arrayGeometry = findArrayGeometrey(); - + /** * Doug populate instrument fields - may need to add a few things. Marie to * define what we mean by instrument. Instrument names probably need to be added @@ -218,7 +188,7 @@ public class TethysExporter { } - + tethysControl.getDbxmlConnect().postToTethys(deploymentDocs); /* * go through the export params and call something for every data block that's From 140af14cbac345e43123223528a3cc0e7d2d4bb7 Mon Sep 17 00:00:00 2001 From: kbolaughlin Date: Wed, 15 Mar 2023 16:38:13 -0700 Subject: [PATCH 4/4] required field update and post to tethys fxn updates fill in required data for deployments/detections and minor tweaks to post to tethys fxn --- src/tethys/dbxml/DBXMLConnect.java | 2 +- src/tethys/deployment/DeploymentHandler.java | 24 +++++++++++++++++-- src/tethys/detection/DetectionsHandler.java | 25 +++++++++++++++++++- src/tethys/pamdata/AutoTethysProvider.java | 2 +- 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/src/tethys/dbxml/DBXMLConnect.java b/src/tethys/dbxml/DBXMLConnect.java index 7b7439a5..88eb042a 100644 --- a/src/tethys/dbxml/DBXMLConnect.java +++ b/src/tethys/dbxml/DBXMLConnect.java @@ -84,7 +84,7 @@ public class DBXMLConnect { switch(className) { case "nilus.Deployment": return "Deployments"; - case "nilus.Detection": + case "nilus.Detections": return "Detections"; case "nilus.Calibration": return "Calibrations"; diff --git a/src/tethys/deployment/DeploymentHandler.java b/src/tethys/deployment/DeploymentHandler.java index 7ed1ab54..fdda96e1 100644 --- a/src/tethys/deployment/DeploymentHandler.java +++ b/src/tethys/deployment/DeploymentHandler.java @@ -22,6 +22,7 @@ import Array.ThreadingHydrophoneLocator; import PamController.PamControlledUnit; import PamController.PamController; import PamguardMVC.PamDataBlock; +import javafx.scene.chart.PieChart.Data; import metadata.MetaDataContol; import metadata.deployment.DeploymentData; import nilus.Audio; @@ -283,13 +284,25 @@ public class DeploymentHandler { public Deployment createDeploymentDocument(int i, DeploymentRecoveryPair drd) { Deployment deployment = new Deployment(); + try { + nilus.Helper.createRequiredElements(deployment); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } String id = String.format("%d", i); deployment.setId(id); deployment.setDeploymentId(i); deployment.setDeploymentDetails(drd.deploymentDetails); deployment.setRecoveryDetails(drd.recoveryDetails); - TethysLocationFuncs.getTrackAndPositionData(deployment); + TethysLocationFuncs.getTrackAndPositionData(deployment); getProjectData(deployment); @@ -317,9 +330,16 @@ public class DeploymentHandler { */ private boolean getProjectData(Deployment deployment) { PamControlledUnit aUnit = PamController.getInstance().findControlledUnit(MetaDataContol.class, null); - if (aUnit instanceof MetaDataContol == false) { + if (aUnit instanceof MetaDataContol == false || true) { + deployment.setProject("thisIsAProject"); + deployment.setPlatform("Yay a platform"); + Instrument instrument = new Instrument(); + instrument.setType("machiney"); + instrument.setInstrumentId("12345555"); + deployment.setInstrument(instrument); return false; } + MetaDataContol metaControl = (MetaDataContol) aUnit; DeploymentData deploymentData = metaControl.getDeploymentData(); deployment.setProject(deploymentData.getProject()); diff --git a/src/tethys/detection/DetectionsHandler.java b/src/tethys/detection/DetectionsHandler.java index e5e9934b..002f920d 100644 --- a/src/tethys/detection/DetectionsHandler.java +++ b/src/tethys/detection/DetectionsHandler.java @@ -1,5 +1,6 @@ package tethys.detection; +import java.math.BigInteger; import java.util.ArrayList; import java.util.List; @@ -166,7 +167,10 @@ public class DetectionsHandler { * We should now have a fully populated Detections object, so write it to the database * using functions in DBXMLConnect */ - //tethysControl.getDbxmlConnect().postToTethys(detectionList); // call whatever you need to call in here to write the Detections. + ArrayList detectionDocuments = new ArrayList(); + detectionDocuments.add(detections); + + tethysControl.getDbxmlConnect().postToTethys(detectionDocuments); // call whatever you need to call in here to write the Detections. return true; @@ -185,6 +189,25 @@ public class DetectionsHandler { effort.setEnd(TethysTimeFuncs.xmlGregCalFromMillis(effortEnd)); // effort.set // no setter for DetectionEffortKind List effortKinds = effort.getKind(); + DetectionEffortKind kind = new DetectionEffortKind(); + try { + nilus.Helper.createRequiredElements(kind); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + kind.getSpeciesId().setValue(BigInteger.valueOf(180537)); + kind.getGranularity().setValue(nilus.GranularityEnumType.CALL); + + effortKinds.add(kind); + return effort; } diff --git a/src/tethys/pamdata/AutoTethysProvider.java b/src/tethys/pamdata/AutoTethysProvider.java index 3f752d55..82952665 100644 --- a/src/tethys/pamdata/AutoTethysProvider.java +++ b/src/tethys/pamdata/AutoTethysProvider.java @@ -246,7 +246,7 @@ public class AutoTethysProvider implements TethysDataProvider { private SpeciesIDType getSpeciesIdType() { SpeciesIDType species = new SpeciesIDType(); -// species.s + species.setValue(BigInteger.valueOf(180537)); return species; }