mirror of
https://github.com/PAMGuard/PAMGuard.git
synced 2024-11-21 22:52:22 +00:00
Merge branch 'main' of https://github.com/douggillespie/PAMGuardTethys
This commit is contained in:
commit
289b065914
@ -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.Detections":
|
||||
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;
|
||||
|
@ -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;
|
||||
@ -143,7 +144,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;
|
||||
@ -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());
|
||||
|
@ -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(); // call whatever you need to call in here to write the Detections.
|
||||
ArrayList<Detections> 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<DetectionEffortKind> 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;
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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<String, StreamExportParams> streamParamsMap = new HashMap();
|
||||
|
||||
|
@ -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;
|
||||
@ -82,39 +82,7 @@ public class TethysExporter {
|
||||
*/
|
||||
// return false;
|
||||
// }
|
||||
|
||||
Deployment deployment1 = new Deployment();
|
||||
deployment1.setId("1");
|
||||
|
||||
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);
|
||||
tempFile = Files.createTempFile("pamGuardToTethys", ".xml");
|
||||
Files.write(tempFile, sw.toString().getBytes());
|
||||
|
||||
String fileText = Importer.ImportFiles("http://localhost:9779", "Deployment",
|
||||
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
|
||||
@ -220,7 +188,7 @@ public class TethysExporter {
|
||||
|
||||
}
|
||||
|
||||
|
||||
tethysControl.getDbxmlConnect().postToTethys(deploymentDocs);
|
||||
|
||||
/*
|
||||
* go through the export params and call something for every data block that's
|
||||
|
@ -249,7 +249,7 @@ public class AutoTethysProvider implements TethysDataProvider {
|
||||
|
||||
private SpeciesIDType getSpeciesIdType() {
|
||||
SpeciesIDType species = new SpeciesIDType();
|
||||
// species.s
|
||||
species.setValue(BigInteger.valueOf(180537));
|
||||
return species;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user