mirror of
https://github.com/PAMGuard/PAMGuard.git
synced 2024-11-25 08:32:32 +00:00
TethysExportControl
add post to tethys code in TethysExportControl
This commit is contained in:
parent
e8e947b91f
commit
f15a6dafa6
@ -1,6 +1,21 @@
|
|||||||
package tethys.dbxml;
|
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.TethysControl;
|
||||||
|
import tethys.output.TethysExportParams;
|
||||||
|
import tethys.output.StreamExportParams;
|
||||||
|
import PamguardMVC.PamDataBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class containing functions for managing the database connection. Opening, closing,
|
* Class containing functions for managing the database connection. Opening, closing,
|
||||||
@ -16,6 +31,80 @@ public class DBXMLConnect {
|
|||||||
this.tethysControl = tethysControl;
|
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() {
|
public boolean openDatabase() {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -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[] ons = new double[n-1]; // ignore the last one since it may be artificially shortened which is OK
|
||||||
double[] gaps = new double[n-1];
|
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();
|
ons[i] = tempPeriods.get(i).getDuration();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -166,7 +166,7 @@ public class DetectionsHandler {
|
|||||||
* We should now have a fully populated Detections object, so write it to the database
|
* We should now have a fully populated Detections object, so write it to the database
|
||||||
* using functions in DBXMLConnect
|
* 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;
|
return true;
|
||||||
|
@ -12,7 +12,7 @@ import java.io.Serializable;
|
|||||||
*/
|
*/
|
||||||
public class StreamExportParams implements Serializable {
|
public class StreamExportParams implements Serializable {
|
||||||
|
|
||||||
public static final long serialVersionUID = 1L;
|
public static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
public StreamExportParams(String longDataName, boolean selected) {
|
public StreamExportParams(String longDataName, boolean selected) {
|
||||||
super();
|
super();
|
||||||
|
@ -2,9 +2,9 @@ package tethys.output;
|
|||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import PamguardMVC.PamDataBlock;
|
import PamguardMVC.PamDataBlock;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parameters for controlling export of Tethys data.
|
* Parameters for controlling export of Tethys data.
|
||||||
* @author dg50
|
* @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
|
* Need to add lots of other parameters here, such as the connection detils
|
||||||
* for the tethys database.
|
* 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();
|
private HashMap<String, StreamExportParams> streamParamsMap = new HashMap();
|
||||||
|
|
||||||
|
@ -30,7 +30,6 @@ import dbxml.uploader.Importer;
|
|||||||
import metadata.MetaDataContol;
|
import metadata.MetaDataContol;
|
||||||
import metadata.deployment.DeploymentData;
|
import metadata.deployment.DeploymentData;
|
||||||
import nilus.Deployment;
|
import nilus.Deployment;
|
||||||
import nilus.MarshalXML;
|
|
||||||
import tethys.TethysControl;
|
import tethys.TethysControl;
|
||||||
import tethys.dbxml.DBXMLConnect;
|
import tethys.dbxml.DBXMLConnect;
|
||||||
import tethys.deployment.DeploymentHandler;
|
import tethys.deployment.DeploymentHandler;
|
||||||
@ -83,36 +82,7 @@ public class TethysExporter {
|
|||||||
*/
|
*/
|
||||||
// return false;
|
// 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
|
* 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
|
* 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
|
* go through the export params and call something for every data block that's
|
||||||
|
Loading…
Reference in New Issue
Block a user