update autoprovider

This commit is contained in:
Douglas Gillespie 2023-03-16 16:34:03 +00:00
parent 289b065914
commit cff6f71881
2 changed files with 140 additions and 39 deletions

View File

@ -0,0 +1,22 @@
package tethys.dbxml;
import dbxml.JerseyClient;
import tethys.output.TethysExportParams;
public class DMXMLQueryTest {
public static void main(String[] args) {
new DMXMLQueryTest().runTest();
}
private void runTest() {
TethysExportParams params = new TethysExportParams();
JerseyClient jerseyClient = new JerseyClient(params.getFullServerName());
// web browse to http://localhost:9779/Client
}
}

View File

@ -32,6 +32,15 @@ import tethys.TethysTimeFuncs;
import tethys.output.StreamExportParams; import tethys.output.StreamExportParams;
import tethys.output.TethysExportParams; import tethys.output.TethysExportParams;
import whistleClassifier.WhistleContour; import whistleClassifier.WhistleContour;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.net.URISyntaxException;
/** /**
* Automatically provides Tethys data based on the SQL database interface * Automatically provides Tethys data based on the SQL database interface
@ -76,7 +85,7 @@ public class AutoTethysProvider implements TethysDataProvider {
description.setAbstract(fullUnitName); description.setAbstract(fullUnitName);
description.setObjectives(fullUnitName); description.setObjectives(fullUnitName);
description.setMethod(pamControlledUnit.getUnitType()); description.setMethod(pamControlledUnit.getUnitType());
return description; return description;
} }
@ -87,7 +96,7 @@ public class AutoTethysProvider implements TethysDataProvider {
algorithm.setSoftware("PAMGuard"); algorithm.setSoftware("PAMGuard");
algorithm.setVersion(PamguardVersionInfo.version); algorithm.setVersion(PamguardVersionInfo.version);
algorithm.setParameters(this.getAlgorithmParameters()); algorithm.setParameters(this.getAlgorithmParameters());
return algorithm; return algorithm;
} }
@ -106,59 +115,129 @@ public class AutoTethysProvider implements TethysDataProvider {
if (settingsObjs == null) { if (settingsObjs == null) {
return null; return null;
} }
// pamXMLWriter.setStaticNameSpace(TethysControl.xmlNameSpace); // pamXMLWriter.setStaticNameSpace(TethysControl.xmlNameSpace);
Element settingsEl = pamXMLWriter.writeUnitSettings(doc, dummyEl, pamSettings, settingsObjs); Element settingsEl = pamXMLWriter.writeUnitSettings(doc, dummyEl, pamSettings, settingsObjs);
if (settingsEl == null) { if (settingsEl == null) {
return null; return null;
} }
pamXMLWriter.addNameSpaceToElements(doc, settingsEl, TethysControl.xmlNameSpace);
settingsEl = addNameSpaceToElements(doc, settingsEl, TethysControl.xmlNameSpace);
dummyEl.appendChild(settingsEl); dummyEl.appendChild(settingsEl);
NodeList childs = settingsEl.getChildNodes(); NodeList childs = settingsEl.getChildNodes();
for (int i = 0; i < childs.getLength(); i++) { for (int i = 0; i < childs.getLength(); i++) {
Node el = childs.item(i); Node el = childs.item(i);
// System.out.println(el.getNodeName()); // System.out.println(el.getNodeName());
if (el instanceof Element) { if (el instanceof Element) {
paramList.add((Element) el); paramList.add((Element) el);
} }
} }
// Document doc = pamXMLWriter.writeOneModule((PamSettings) pamControlledUnit, System.currentTimeMillis()); // Document doc = pamXMLWriter.writeOneModule((PamSettings) pamControlledUnit, System.currentTimeMillis());
// String moduleXML = null; // String moduleXML = null;
if (doc != null) { if (doc != null) {
// this string should be XML of all the settings for the module controlling this // this string should be XML of all the settings for the module controlling this
// datablock. // datablock.
// moduleXML = pamXMLWriter.getAsString(doc, true); // change to false to get smaller xml // moduleXML = pamXMLWriter.getAsString(doc, true); // change to false to get smaller xml
// System.out.printf("Module settings for datablock %s are:\n", moduleXML); // System.out.printf("Module settings for datablock %s are:\n", moduleXML);
// System.out.println(moduleXML); // System.out.println(moduleXML);
// Element pamguard = doc.get("PAMGUARD"); // Element pamguard = doc.get("PAMGUARD");
// Element modules = (Element) pamguard.getElementsByTagName("MODULES"); // Element modules = (Element) pamguard.getElementsByTagName("MODULES");
// doc.get // doc.get
// NodeList childs = doc.getChildNodes(); // NodeList childs = doc.getChildNodes();
// for (int i = 0; i < childs.getLength(); i++) { // for (int i = 0; i < childs.getLength(); i++) {
// Node el = childs.item(i); // Node el = childs.item(i);
// System.out.println(el.getNodeName()); // System.out.println(el.getNodeName());
// if (el instanceof Element) { // if (el instanceof Element) {
// paramList.add((Element) el); // paramList.add((Element) el);
// } // }
// } // }
// String moduleXML = pamXMLWriter.getAsString(doc, true); // change to false to get smaller xml // String moduleXML = pamXMLWriter.getAsString(doc, true); // change to false to get smaller xml
// System.out.printf("Module settings for datablock %s are:\n%s", this.pamDataBlock.getDataName(), moduleXML); // System.out.printf("Module settings for datablock %s are:\n%s", this.pamDataBlock.getDataName(), moduleXML);
} }
// // try the old say // // try the old say
// Document doc2 = pamXMLWriter.writeOneModule((PamSettings) pamControlledUnit, System.currentTimeMillis()); // Document doc2 = pamXMLWriter.writeOneModule((PamSettings) pamControlledUnit, System.currentTimeMillis());
// String moduleXML = null; // String moduleXML = null;
// if (doc2 != null) { // if (doc2 != null) {
// // this string should be XML of all the settings for the module controlling this // // this string should be XML of all the settings for the module controlling this
// // datablock. // // datablock.
// moduleXML = pamXMLWriter.getAsString(doc2, true); // change to false to get smaller xml // moduleXML = pamXMLWriter.getAsString(doc2, true); // change to false to get smaller xml
// System.out.printf("Module settings for datablock %s are:\n%s", pamDataBlock.getDataName(),moduleXML); // System.out.printf("Module settings for datablock %s are:\n%s", pamDataBlock.getDataName(),moduleXML);
// } // }
// //
return parameters; return parameters;
} }
private Element addNameSpaceToElements(Document doc, Element settingsEl, String xmlNameSpace) {
// String xsltString = "<xsl:stylesheet version=\"1.0\" \r\n"
// + " xmlns:xsl=http://www.w3.org/1999/XSL/Transform\r\n"
// + " xmlns:ns0=http://mydata.com/H2H/Automation\r\n"
// + " exclude-result-prefixes=\"ns0\">\r\n"
// + " <xsl:output method=\"xml\" version=\"1.0\" encoding=\"UTF-8\" indent=\"yes\"/>\r\n"
// + " <xsl:strip-space elements=\"*\"/>\r\n"
// + " \r\n"
// + " <xsl:template match=\"*\">\r\n"
// + " <xsl:element name=\"{local-name()}\" namespace=http://tethys.sdsu.edu/schema/1.0>\r\n"
// + " <xsl:apply-templates/>\r\n"
// + " </xsl:element>\r\n"
// + " </xsl:template>\r\n"
// + " \r\n"
// + " <xsl:template match=\"/ns0:Document\">\r\n"
// + " <Document xmlns=http://tethys.sdsu.edu/schema/1.0 xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance> \r\n"
// + " <xsl:apply-templates/>\r\n"
// + " </Document>\r\n"
// + " </xsl:template>\r\n"
// + " \r\n"
// + "</xsl:stylesheet>\r\n";
String xsltString = "<xsl:stylesheet version=\"1.0\" \n"
+ " xmlns:xsl=http://www.w3.org/1999/XSL/Transform\n"
+ " xmlns:ns0=http://mydata.com/H2H/Automation\n"
+ " exclude-result-prefixes=\"ns0\">\n"
+ " <xsl:output method=\"xml\" version=\"1.0\" encoding=\"UTF-8\" indent=\"yes\"/>\n"
+ " <xsl:strip-space elements=\"*\"/>\n"
+ " \n"
+ " <xsl:template match=\"*\">\n"
+ " <xsl:element name=\"{local-name()}\" namespace=http://tethys.sdsu.edu/schema/1.0>\n"
+ " <xsl:apply-templates/>\n"
+ " </xsl:element>\n"
+ " </xsl:template>\n"
+ " \n"
+ " <xsl:template match=\"/ns0:Document\">\n"
+ " <Document xmlns=http://tethys.sdsu.edu/schema/1.0 xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance> \n"
+ " <xsl:apply-templates/>\n"
+ " </Document>\n"
+ " </xsl:template>\n"
+ " \n"
+ "</xsl:stylesheet>\n";
try {
TransformerFactory factory = TransformerFactory.newInstance();
// Source xslt = new StreamSource(new File("transform.xslt"));
StringReader reader = new StringReader(xmlNameSpace);
Source xslt = new StreamSource(reader);
Transformer transformer = factory.newTransformer(xslt);
DOMSource source = new DOMSource(doc);
// Result
// Source text = new StreamSource(new File("input.xml"));
DOMResult result = new DOMResult();
transformer.transform(source, result);
System.out.println(result.toString());
}
catch (Exception e) {
e.printStackTrace();
}
return null;
}
private PamSettings[] getSettingsObjects() { private PamSettings[] getSettingsObjects() {
if (pamControlledUnit instanceof PamSettings) { if (pamControlledUnit instanceof PamSettings) {
PamSettings[] settings = new PamSettings[1]; PamSettings[] settings = new PamSettings[1];
@ -188,7 +267,7 @@ public class AutoTethysProvider implements TethysDataProvider {
* NOTE: I use channel bitmaps throughout since detections are often made on multiple channels. * NOTE: I use channel bitmaps throughout since detections are often made on multiple channels.
*/ */
detection.setChannel(BigInteger.valueOf(dataUnit.getChannelBitmap())); detection.setChannel(BigInteger.valueOf(dataUnit.getChannelBitmap()));
nilus.Detection.Parameters detParams = new nilus.Detection.Parameters(); nilus.Detection.Parameters detParams = new nilus.Detection.Parameters();
detection.setParameters(detParams); detection.setParameters(detParams);
double[] freqs = dataUnit.getFrequency(); double[] freqs = dataUnit.getFrequency();
@ -198,9 +277,9 @@ public class AutoTethysProvider implements TethysDataProvider {
} }
double ampli = dataUnit.getAmplitudeDB(); double ampli = dataUnit.getAmplitudeDB();
detParams.setReceivedLevelDB(ampli); detParams.setReceivedLevelDB(ampli);
// DataUnitBaseData basicData = dataUnit.getBasicData(); // DataUnitBaseData basicData = dataUnit.getBasicData();
gotTonalContour(dataUnit, detParams); gotTonalContour(dataUnit, detParams);
return detection; return detection;
} }