mirror of
https://github.com/PAMGuard/PAMGuard.git
synced 2024-11-21 22:52:22 +00:00
updated doc names
Dog names now match their id so it's easier to delete them from Tethys
This commit is contained in:
parent
c7ceba1604
commit
642f1da873
@ -1,6 +1,9 @@
|
||||
package tethys.dbxml;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -11,6 +14,7 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import dbxml.JerseyClient;
|
||||
import dbxml.Queries;
|
||||
import dbxml.uploader.Importer;
|
||||
import nilus.Deployment;
|
||||
import nilus.MarshalXML;
|
||||
@ -28,9 +32,13 @@ import PamguardMVC.PamDataBlock;
|
||||
public class DBXMLConnect {
|
||||
|
||||
private TethysControl tethysControl;
|
||||
|
||||
private File tempDirectory;
|
||||
|
||||
public DBXMLConnect(TethysControl tethysControl) {
|
||||
this.tethysControl = tethysControl;
|
||||
|
||||
checkTempFolder();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -42,27 +50,27 @@ public class DBXMLConnect {
|
||||
* @param pamGuardObjs all nilus objects loaded with PamGuard data
|
||||
* @return error string, null string means there are no errors
|
||||
*/
|
||||
public String postToTethys(List<?> pamGuardObjs)
|
||||
public String postToTethys(Object nilusObject)
|
||||
{
|
||||
Class objClass = pamGuardObjs.get(0).getClass();
|
||||
Class objClass = nilusObject.getClass();
|
||||
String collection = getTethysCollection(objClass.getName());
|
||||
PamDataBlock defaultPamBlock = null;
|
||||
TethysExportParams params = new TethysExportParams();
|
||||
String fileError = null;
|
||||
String tempName = getTempFileName(nilusObject);
|
||||
tempName = tempDirectory.getAbsolutePath() + File.separator + tempName + ".xml";
|
||||
File tempFile = new File(tempName);
|
||||
try {
|
||||
MarshalXML marshal = new MarshalXML();
|
||||
marshal.createInstance(objClass);
|
||||
for (Object obj : pamGuardObjs )
|
||||
{
|
||||
Path tempFile = Files.createTempFile("pamGuardToTethys", ".xml");
|
||||
marshal.marshal(obj, tempFile.toString());
|
||||
marshal.createInstance(objClass);
|
||||
// Path tempFile = Files.createTempFile("pamGuardToTethys", ".xml");
|
||||
marshal.marshal(nilusObject, tempFile.toString());
|
||||
fileError = Importer.ImportFiles(params.getFullServerName(), collection,
|
||||
new String[] { tempFile.toString() }, "", "", false);
|
||||
|
||||
// System.out.println(fileError);
|
||||
|
||||
tempFile.toFile().deleteOnExit();
|
||||
}
|
||||
tempFile.deleteOnExit();
|
||||
} catch(IllegalArgumentException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
@ -77,6 +85,74 @@ public class DBXMLConnect {
|
||||
return fileError;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a temp folder to hold xml output. This will be the standard
|
||||
* temp folder + /PAMGuardTethys. Files will be left here until PAMGUard
|
||||
* exits then should delete automatically
|
||||
*/
|
||||
private void checkTempFolder() {
|
||||
String javaTmpDirs = System.getProperty("java.io.tmpdir") + File.separator + "PAMGuardTethys";
|
||||
|
||||
File tempDir = new File(javaTmpDirs);
|
||||
if (tempDir.exists() == false) {
|
||||
if (tempDir.mkdirs()) {
|
||||
tempDirectory = tempDir;
|
||||
};
|
||||
}
|
||||
if (tempDirectory == null) {
|
||||
tempDirectory = new File(System.getProperty("java.io.tmpdir"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* needs to be based on the document id, but the getter for this can vary by type, so time
|
||||
* to start casting !
|
||||
* @param nilusObject
|
||||
* @return
|
||||
*/
|
||||
private String getTempFileName(Object nilusObject) {
|
||||
/**
|
||||
* While all nilus objects should have a getId function, they have no
|
||||
* common root, so try to get the function via the class declared methods.
|
||||
*/
|
||||
String tempName = "PamguardTethys";
|
||||
Class nilusClass = nilusObject.getClass();
|
||||
try {
|
||||
Method getId = nilusClass.getDeclaredMethod("getId", null);
|
||||
Object[] inputs = new Object[0];
|
||||
Object res = getId.invoke(nilusObject, inputs);
|
||||
if (res instanceof String) {
|
||||
tempName = (String) res;
|
||||
return tempName;
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (SecurityException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IllegalArgumentException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (nilusObject instanceof nilus.Deployment) {
|
||||
tempName = ((Deployment) nilusObject).getId();
|
||||
}
|
||||
else if (nilusObject instanceof nilus.Detections) {
|
||||
tempName = ((nilus.Detections) nilusObject).getId();
|
||||
}
|
||||
return tempName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get Tethys collection name from nilus collection objects
|
||||
* @param className nilus object Class Name
|
||||
@ -115,30 +191,34 @@ public class DBXMLConnect {
|
||||
public boolean deleteDeployment(String deploymentId) {
|
||||
ArrayList<String> detDocNames = tethysControl.getDbxmlQueries().getDetectionsDocsIds(deploymentId);
|
||||
JerseyClient jerseyClient = null;
|
||||
Queries queries = null;
|
||||
try {
|
||||
jerseyClient = new JerseyClient(tethysControl.getTethysExportParams().getFullServerName());
|
||||
queries = new Queries(jerseyClient);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
String result;
|
||||
for (int i = 0; i < detDocNames.size(); i++) {
|
||||
try {
|
||||
System.out.println("Delete " + detDocNames.get(i));
|
||||
result = jerseyClient.removeDocument("Detections", detDocNames.get(i));
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
// return false;
|
||||
// break;
|
||||
}
|
||||
}
|
||||
// for (int i = 0; i < detDocNames.size(); i++) {
|
||||
// try {
|
||||
// System.out.println("Delete " + detDocNames.get(i));
|
||||
// result = jerseyClient.removeDocument("Detections", detDocNames.get(i));
|
||||
// }
|
||||
// catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
//// return false;
|
||||
//// break;
|
||||
// }
|
||||
// }
|
||||
try {
|
||||
result = jerseyClient.removeDocument("Deployments", deploymentId);
|
||||
String doc = queries.getDocument("Deployments", deploymentId);
|
||||
// queries.
|
||||
result = jerseyClient.removeDocument("Deployments", deploymentId );
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
// e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -17,6 +17,7 @@ import org.xml.sax.InputSource;
|
||||
import PamController.settings.output.xml.PamguardXMLWriter;
|
||||
import PamguardMVC.PamDataBlock;
|
||||
import dbxml.JerseyClient;
|
||||
import dbxml.Queries;
|
||||
import nilus.Deployment;
|
||||
import nilus.Deployment.Instrument;
|
||||
import nilus.DeploymentRecoveryDetails;
|
||||
@ -28,7 +29,7 @@ import tethys.output.TethysExportParams;
|
||||
|
||||
/**
|
||||
* Some standard queries we're going to want to make from various
|
||||
* parts of the system as the user interracts with the GUI.
|
||||
* parts of the system as the user interacts with the GUI.
|
||||
* @author dg50
|
||||
*
|
||||
*/
|
||||
@ -65,6 +66,8 @@ public class DBXMLQueries {
|
||||
try {
|
||||
JerseyClient jerseyClient = new JerseyClient(params.getFullServerName());
|
||||
|
||||
Queries queries = new Queries(jerseyClient);
|
||||
|
||||
queryResult = jerseyClient.queryJSON(jsonQueryString, 0);
|
||||
schemaPlan = jerseyClient.queryJSON(jsonQueryString, 1);
|
||||
|
||||
@ -159,10 +162,12 @@ public class DBXMLQueries {
|
||||
NodeList returns = doc.getElementsByTagName("Return");
|
||||
// System.out.println("N projects = " + returns.getLength());
|
||||
int n = returns.getLength();
|
||||
// Queries queries = new Queries(null)
|
||||
for (int i = 0; i < n; i++) {
|
||||
Node aNode = returns.item(i);
|
||||
if (aNode instanceof Element) {
|
||||
Element returnedEl = (Element) aNode;
|
||||
|
||||
String Id = getElementData(returnedEl, "Id");
|
||||
String project = getElementData(returnedEl, "Project");
|
||||
String DeploymentId = getElementData(returnedEl, "DeploymentId");
|
||||
|
@ -177,7 +177,7 @@ public class DetectionsHandler {
|
||||
ArrayList<Detections> detectionDocuments = new ArrayList();
|
||||
detectionDocuments.add(detections);
|
||||
|
||||
tethysControl.getDbxmlConnect().postToTethys(detectionDocuments); // call whatever you need to call in here to write the Detections.
|
||||
// tethysControl.getDbxmlConnect().postToTethys(detectionDocuments); // call whatever you need to call in here to write the Detections.
|
||||
|
||||
|
||||
return true;
|
||||
|
@ -189,10 +189,10 @@ public class TethysExporter {
|
||||
Deployment deployment = deploymentHandler.createDeploymentDocument(i++, recordingPeriod);
|
||||
// System.out.println(deployment.toString());
|
||||
deploymentDocs.add(deployment);
|
||||
tethysControl.getDbxmlConnect().postToTethys(deployment);
|
||||
|
||||
}
|
||||
|
||||
tethysControl.getDbxmlConnect().postToTethys(deploymentDocs);
|
||||
|
||||
/*
|
||||
* go through the export params and call something for every data block that's
|
||||
|
Loading…
Reference in New Issue
Block a user