mirror of
https://github.com/PAMGuard/PAMGuard.git
synced 2024-11-22 07:02:29 +00:00
Changes for Tethys integration
This commit is contained in:
parent
5e6cd42eea
commit
f02001a6fc
@ -6,7 +6,7 @@
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk-16.0.2">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
@ -17,5 +17,10 @@
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="lib" path="C:/Users/dg50/Tethys/NilusXMLGenerator/target/nilus-1.5.jar">
|
||||
<attributes>
|
||||
<attribute name="javadoc_location" value="jar:file:/C:/Users/dg50/Tethys/NilusXMLGenerator/target/nilus-1.5-javadoc.jar!/"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
|
23
pom.xml
23
pom.xml
@ -555,8 +555,29 @@
|
||||
<groupId>com.sun.xml.bind</groupId>
|
||||
<artifactId>jaxb-impl</artifactId>
|
||||
<version>2.3.2</version>
|
||||
</dependency>-->
|
||||
<!-- From NilusXMLGenerator POM at https://bitbucket.org/tethysacousticmetadata/nilusxmlgenerator/src/master/-->
|
||||
<dependency>
|
||||
<groupId>org.eclipse.persistence</groupId>
|
||||
<artifactId>org.eclipse.persistence.moxy</artifactId>
|
||||
<version>2.5.0</version>
|
||||
</dependency>
|
||||
-->
|
||||
<dependency>
|
||||
<groupId>javax.xml.bind</groupId>
|
||||
<artifactId>jaxb-api</artifactId>
|
||||
<version>2.4.0-b180830.0359</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jaxb</groupId>
|
||||
<artifactId>jaxb-runtime</artifactId>
|
||||
<version>2.4.0-b180830.0438</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jaxb</groupId>
|
||||
<artifactId>jaxb-xjc</artifactId>
|
||||
<version>2.4.0-b180830.0438</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.jflac/jflac-codec -->
|
||||
<dependency>
|
||||
|
@ -44,6 +44,7 @@ import whistlesAndMoans.AbstractWhistleDataUnit;
|
||||
import fftManager.FFTDataUnit;
|
||||
import fftManager.PamFFTControl;
|
||||
import group3dlocaliser.Group3DLocaliserControl;
|
||||
import metadata.MetaDataContol;
|
||||
import meygenturbine.MeygenTurbine;
|
||||
import networkTransfer.receive.BuoyStatusDataUnit;
|
||||
import networkTransfer.receive.NetworkReceiver;
|
||||
@ -461,6 +462,12 @@ final public class PamModel implements PamModelInterface, PamSettings {
|
||||
mi.setModulesMenuGroup(utilitiesGroup);
|
||||
mi.setMaxNumber(1);
|
||||
|
||||
|
||||
mi = PamModuleInfo.registerControlledUnit(MetaDataContol.class.getName(), MetaDataContol.unitType);
|
||||
mi.setToolTipText("Deployment Meta Data");
|
||||
mi.setModulesMenuGroup(utilitiesGroup);
|
||||
mi.setMaxNumber(1);
|
||||
|
||||
if (isViewer) {
|
||||
mi = PamModuleInfo.registerControlledUnit(TethysControl.class.getName(), TethysControl.defaultName);
|
||||
mi.setToolTipText("Interface to Tethys Database");
|
||||
|
@ -34,6 +34,11 @@ abstract public class PamParameterData {
|
||||
*/
|
||||
private String postTitle;
|
||||
|
||||
/**
|
||||
* field length for automatic dialogs.
|
||||
*/
|
||||
private int fieldLength;
|
||||
|
||||
|
||||
/**
|
||||
* @param parentObject
|
||||
@ -45,6 +50,21 @@ abstract public class PamParameterData {
|
||||
this.field = field;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param parentObject
|
||||
* @param field
|
||||
* @param shortName
|
||||
* @param toolTip
|
||||
* @param fieldLength length of text in automatic dialogs.
|
||||
*/
|
||||
public PamParameterData(Object parentObject, Field field, String shortName, String toolTip, int fieldLength) {
|
||||
super();
|
||||
this.field = field;
|
||||
this.shortName = shortName;
|
||||
this.toolTip = toolTip;
|
||||
this.fieldLength = fieldLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param parentObject
|
||||
* @param field
|
||||
@ -58,7 +78,6 @@ abstract public class PamParameterData {
|
||||
this.toolTip = toolTip;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param shortName the shortName to set
|
||||
*/
|
||||
@ -66,6 +85,20 @@ abstract public class PamParameterData {
|
||||
this.shortName = shortName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set info about a parameter
|
||||
* @param shortName short name, e.g. to use in a dialog
|
||||
* @param postTitle post title, e.g. text coming after a data entry field in a dialog
|
||||
* @param toolTip tool tip to display over the component in a dialog.
|
||||
* @param fieldLength length of text in automatic dialogs.
|
||||
*/
|
||||
public void setInfo(String shortName, String postTitle, String toolTip, int fieldLength) {
|
||||
this.shortName = shortName;
|
||||
this.postTitle = postTitle;
|
||||
this.toolTip = toolTip;
|
||||
this.fieldLength = fieldLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set info about a parameter
|
||||
* @param shortName short name, e.g. to use in a dialog
|
||||
@ -136,6 +169,9 @@ abstract public class PamParameterData {
|
||||
* @return a short name for the field, suitable for use in dialogs.
|
||||
*/
|
||||
public String getShortName() {
|
||||
if (shortName == null) {
|
||||
return getFieldName();
|
||||
}
|
||||
return shortName;
|
||||
}
|
||||
|
||||
@ -166,5 +202,19 @@ abstract public class PamParameterData {
|
||||
return String.format("Param %s class %s", getFieldName(), getDataClass());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the fieldLength
|
||||
*/
|
||||
public int getFieldLength() {
|
||||
return fieldLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param fieldLength the fieldLength to set
|
||||
*/
|
||||
public void setFieldLength(int fieldLength) {
|
||||
this.fieldLength = fieldLength;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -59,9 +59,12 @@ public class PamParameterDataGetter extends PrivatePamParameterData {
|
||||
if (setter == null) {
|
||||
return false;
|
||||
}
|
||||
// need to convert the type
|
||||
Object convObj = convertStringType(data);
|
||||
try {
|
||||
setter.invoke(getParentObject(), data);
|
||||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
|
||||
Object parentObj = getParentObject();
|
||||
setter.invoke(parentObj, convObj);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
|
@ -286,4 +286,5 @@ public class PamParameterSet {
|
||||
public PamParameterData removeParameterData(String paramName) {
|
||||
return parameterDatas.remove(paramName);
|
||||
}
|
||||
|
||||
}
|
||||
|
73
src/PamModel/parametermanager/ParameterSetManager.java
Normal file
73
src/PamModel/parametermanager/ParameterSetManager.java
Normal file
@ -0,0 +1,73 @@
|
||||
package PamModel.parametermanager;
|
||||
|
||||
import java.awt.Window;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.JMenuItem;
|
||||
|
||||
import PamModel.parametermanager.swing.ManagedParameterDialog;
|
||||
import generalDatabase.parameterstore.ParameterDatabaseStore;
|
||||
|
||||
/**
|
||||
* Just about everything giving overall control of some managed parameters.
|
||||
* May be a bit too specific on first cut and need to be abstracted.
|
||||
* Testing on 'Deployment' data.
|
||||
* @author dg50
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
public class ParameterSetManager<T extends ManagedParameters> {
|
||||
|
||||
private T managedParams;
|
||||
private String name;
|
||||
|
||||
public ParameterSetManager(T defaultParams, String name) {
|
||||
setManagedParams(defaultParams);
|
||||
this.name = name;
|
||||
// if (managedParams == null) {
|
||||
// managedParams = new T();
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the managedParams
|
||||
*/
|
||||
public T getManagedParams() {
|
||||
return managedParams;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param managedParams the managedParams to set
|
||||
*/
|
||||
public void setManagedParams(T managedParams) {
|
||||
this.managedParams = managedParams;
|
||||
}
|
||||
|
||||
public JMenuItem getMenuItem(Window parent) {
|
||||
if (managedParams == null) {
|
||||
return null;
|
||||
}
|
||||
JMenuItem menuItem = new JMenuItem(name + " ...");
|
||||
menuItem.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
showDialog(parent);
|
||||
}
|
||||
});
|
||||
|
||||
return menuItem;
|
||||
}
|
||||
|
||||
protected void showDialog(Window parent) {
|
||||
ManagedParameterDialog<T> dialog = new ManagedParameterDialog<T>(parent, name, managedParams);
|
||||
T newParams = dialog.showDialog(parent, name, managedParams);
|
||||
|
||||
if (newParams != null) {
|
||||
ParameterDatabaseStore paramDatabase = new ParameterDatabaseStore("MetaData");
|
||||
paramDatabase.saveParameterSet(newParams);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package PamModel.parametermanager;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
* Abstract instance of PamParameterDataInterface which implements everything
|
||||
@ -36,9 +37,48 @@ public abstract class PrivatePamParameterData extends PamParameterData {
|
||||
* This should really be implemented in every concrete class, but no time to do that now. Aim to delete
|
||||
* this function here, then go through and implement everywhere ...
|
||||
*/
|
||||
return false;
|
||||
// return false;
|
||||
Object convData = convertStringType(data);
|
||||
getField().set(this, convData);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* convert a string type to a different type appropriate for the field in
|
||||
* question.
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public Object convertStringType(Object value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
if (value instanceof String == false) {
|
||||
return value;
|
||||
}
|
||||
String str = (String) value;
|
||||
Type type = getField().getGenericType();
|
||||
Class<?> cls = getField().getType();
|
||||
String clsName = cls.getName();
|
||||
switch (clsName) {
|
||||
case "int":
|
||||
case "Integer":
|
||||
return Integer.valueOf(str);
|
||||
case "double":
|
||||
case "Double":
|
||||
return Double.valueOf(str);
|
||||
case "float":
|
||||
case "Float":
|
||||
return Float.valueOf(str);
|
||||
case "short":
|
||||
case "Short":
|
||||
return Short.valueOf(str);
|
||||
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,49 @@
|
||||
package PamModel.parametermanager.swing;
|
||||
|
||||
import java.awt.Window;
|
||||
|
||||
import PamModel.parametermanager.ManagedParameters;
|
||||
import PamView.dialog.PamDialog;
|
||||
|
||||
public class ManagedParameterDialog<T extends ManagedParameters> extends PamDialog {
|
||||
|
||||
private T params;
|
||||
|
||||
private ManagedParameterPanel<T> parameterPanel;
|
||||
|
||||
public ManagedParameterDialog(Window parentFrame, String title, T params) {
|
||||
super(parentFrame, title, false);
|
||||
parameterPanel = new ManagedParameterPanel<T>(params);
|
||||
setDialogComponent(parameterPanel.getPanel());
|
||||
}
|
||||
|
||||
public T showDialog(Window parentFrame, String title, T parameters) {
|
||||
// ManagedParameterDialog dialog = new ManagedParameterDialog<>(parentFrame, title, parameters);
|
||||
setParams(parameters);
|
||||
setVisible(true);
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
private void setParams(T params) {
|
||||
this.params = params;
|
||||
this.parameterPanel.setParams(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getParams() {
|
||||
return parameterPanel.getParams(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelButtonPressed() {
|
||||
params = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void restoreDefaultSettings() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
149
src/PamModel/parametermanager/swing/ManagedParameterPanel.java
Normal file
149
src/PamModel/parametermanager/swing/ManagedParameterPanel.java
Normal file
@ -0,0 +1,149 @@
|
||||
package PamModel.parametermanager.swing;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.text.JTextComponent;
|
||||
|
||||
import PamModel.parametermanager.FieldNotFoundException;
|
||||
import PamModel.parametermanager.ManagedParameters;
|
||||
import PamModel.parametermanager.PamParameterData;
|
||||
import PamModel.parametermanager.PamParameterSet;
|
||||
import PamView.dialog.PamDialog;
|
||||
import PamView.dialog.PamGridBagContraints;
|
||||
|
||||
public class ManagedParameterPanel<T extends ManagedParameters> {
|
||||
|
||||
private JPanel mainPanel;
|
||||
private Collection<PamParameterData> parameterSet;
|
||||
|
||||
private static final int DEFAULT_TEXT_LENGTH = 6;
|
||||
private static final int MAX_SINGLE_LINE_LENGTH = 40;
|
||||
|
||||
private JTextComponent[] textComponents;
|
||||
|
||||
public ManagedParameterPanel(T parameterExample) {
|
||||
|
||||
mainPanel = new JPanel(new GridBagLayout());
|
||||
GridBagConstraints c = new PamGridBagContraints();
|
||||
PamParameterSet exampleSet = parameterExample.getParameterSet();
|
||||
parameterSet = exampleSet.getParameterCollection();
|
||||
int n = parameterSet.size();
|
||||
textComponents = new JTextComponent[n];
|
||||
int i = 0;
|
||||
for (PamParameterData paramData : parameterSet) {
|
||||
textComponents[i] = createComponent(paramData);
|
||||
c.gridx = 0;
|
||||
c.fill = GridBagConstraints.NONE;
|
||||
c.anchor = GridBagConstraints.NORTHEAST;
|
||||
mainPanel.add(new JLabel(paramData.getShortName(), JLabel.RIGHT), c);
|
||||
c.gridx++;
|
||||
if (textComponents[i] instanceof JTextArea) {
|
||||
c.fill = GridBagConstraints.HORIZONTAL;
|
||||
}
|
||||
else {
|
||||
c.fill = GridBagConstraints.NONE;
|
||||
}
|
||||
c.anchor = GridBagConstraints.WEST;
|
||||
mainPanel.add(textComponents[i], c);
|
||||
|
||||
textComponents[i].setToolTipText(getTipText(paramData));
|
||||
|
||||
c.gridy++;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
private String getTipText(PamParameterData paramData) {
|
||||
String tip = paramData.getToolTip();
|
||||
if (tip != null) {
|
||||
return tip;
|
||||
}
|
||||
else {
|
||||
return paramData.getFieldName();
|
||||
}
|
||||
}
|
||||
|
||||
private JTextComponent createComponent(PamParameterData paramData) {
|
||||
int textLen = paramData.getFieldLength();
|
||||
if (textLen == 0) {
|
||||
textLen = DEFAULT_TEXT_LENGTH;
|
||||
}
|
||||
if (textLen <= MAX_SINGLE_LINE_LENGTH) {
|
||||
return new JTextField(textLen);
|
||||
}
|
||||
else {
|
||||
JTextField dummyField = new JTextField(2);
|
||||
// dummyField.getBorder().
|
||||
JTextArea textArea = new JTextArea(textLen/MAX_SINGLE_LINE_LENGTH+1, MAX_SINGLE_LINE_LENGTH);
|
||||
textArea.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));
|
||||
return textArea;
|
||||
}
|
||||
}
|
||||
|
||||
public JComponent getPanel() {
|
||||
return mainPanel;
|
||||
}
|
||||
|
||||
public void setParams(T params) {
|
||||
int i = 0;
|
||||
PamParameterData newParamData = null;
|
||||
Object data = null;
|
||||
for (PamParameterData paramData : this.parameterSet) {
|
||||
// find the parameter in the new parameters (parameterSet is just a formatting placeholder)
|
||||
try {
|
||||
newParamData = params.getParameterSet().findParameterData(paramData.getFieldName());
|
||||
} catch (FieldNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
data = newParamData.getData();
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (data != null) {
|
||||
textComponents[i].setText(data.toString());
|
||||
}
|
||||
else {
|
||||
textComponents[i].setText(null);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean getParams(T params) {
|
||||
int i = 0;
|
||||
PamParameterData newParamData = null;
|
||||
Object data = null;
|
||||
for (PamParameterData paramData : this.parameterSet) {
|
||||
// find the parameter in the new parameters (parameterSet is just a formatting placeholder)
|
||||
try {
|
||||
newParamData = params.getParameterSet().findParameterData(paramData.getFieldName());
|
||||
} catch (FieldNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String txt = textComponents[i].getText();
|
||||
try {
|
||||
newParamData.setData(txt);
|
||||
} catch (IllegalArgumentException | IllegalAccessException e) {
|
||||
String msg = "Invalid parameter. Data type should be " + paramData.getField().getType().getName();
|
||||
return PamDialog.showWarning(null, newParamData.getShortName(), msg);
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
187
src/generalDatabase/parameterstore/ParameterDatabaseStore.java
Normal file
187
src/generalDatabase/parameterstore/ParameterDatabaseStore.java
Normal file
@ -0,0 +1,187 @@
|
||||
package generalDatabase.parameterstore;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.sql.Types;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import PamModel.parametermanager.ManagedParameters;
|
||||
import PamModel.parametermanager.PamParameterData;
|
||||
import PamModel.parametermanager.PamParameterSet;
|
||||
import generalDatabase.DBControlUnit;
|
||||
import generalDatabase.EmptyTableDefinition;
|
||||
import generalDatabase.PamConnection;
|
||||
import generalDatabase.PamTableItem;
|
||||
import generalDatabase.SQLTypes;
|
||||
|
||||
/**
|
||||
* Store parameters from a managed parameter set in the PAMGuard database. These go into a dead simple table, which has
|
||||
* two columns. The first is a name, the second a string value. Each parameter can only appear once.
|
||||
* This works with ManagedParameters using the same names and field names that go into the xml output.
|
||||
* @author dg50
|
||||
*
|
||||
*/
|
||||
public class ParameterDatabaseStore {
|
||||
|
||||
|
||||
private EmptyTableDefinition tableDef;
|
||||
private PamTableItem nameItem, dataItem;
|
||||
|
||||
public ParameterDatabaseStore(String tableName) {
|
||||
tableDef = new EmptyTableDefinition(tableName);
|
||||
tableDef.addTableItem(nameItem = new PamTableItem("ParameterName", Types.VARCHAR));
|
||||
tableDef.addTableItem(dataItem = new PamTableItem("Value", Types.VARCHAR));
|
||||
}
|
||||
|
||||
public boolean saveParameterSet(ManagedParameters managedParameters) {
|
||||
if (managedParameters == null) {
|
||||
return false;
|
||||
}
|
||||
return saveParameterSet(managedParameters.getClass().getSimpleName(), managedParameters);
|
||||
}
|
||||
|
||||
private boolean saveParameterSet(String name, ManagedParameters managedParameters) {
|
||||
DBControlUnit dbControl = DBControlUnit.findDatabaseControl();
|
||||
if (dbControl == null) {
|
||||
return false;
|
||||
}
|
||||
PamConnection con = dbControl.getConnection();
|
||||
if (checkTable(con) == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String prefix;
|
||||
if (name == null) {
|
||||
prefix = "";
|
||||
}
|
||||
else {
|
||||
prefix = name + ".";
|
||||
}
|
||||
PamParameterSet paramSet = managedParameters.getParameterSet();
|
||||
Collection<PamParameterData> params = paramSet.getParameterCollection();
|
||||
for (PamParameterData paramData : params) {
|
||||
String paramName = paramData.getFieldName();
|
||||
paramName = prefix + paramName;
|
||||
Object data = null;
|
||||
try {
|
||||
data = paramData.getData();// .getField().get(managedParameters);
|
||||
} catch (IllegalArgumentException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// System.out.printf("Store param \"%s\" as \"%s\"\n", paramName, data);
|
||||
saveToDatabase(con, paramName, data);
|
||||
}
|
||||
dbControl.commitChanges();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean saveToDatabase(PamConnection con, String name, Object data) {
|
||||
int[] existing = findExistingRows(con, name);
|
||||
boolean ok = true;
|
||||
if (existing == null || existing.length == 0) {
|
||||
ok |= newRecord(con, name, data);
|
||||
}
|
||||
else {
|
||||
ok |= updateRecord(con, existing[0], name, data);
|
||||
if (existing.length > 1) {
|
||||
for (int i = 1; i < existing.length; i++) {
|
||||
ok |= deleteDuplicateRow(con, existing[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private int[] findExistingRows(PamConnection con, String name) {
|
||||
/**
|
||||
* Find existing rows with that name.
|
||||
*/
|
||||
int[] rows = new int[0];
|
||||
if (con == null) {
|
||||
return rows;
|
||||
}
|
||||
String qStr = String.format("SELECT Id FROM %s WHERE %s='%s'", tableDef.getTableName(), nameItem.getName(), name);
|
||||
try {
|
||||
Statement stmt = con.getConnection().createStatement();
|
||||
ResultSet res = stmt.executeQuery(qStr);
|
||||
while (res.next()) {
|
||||
int rowId = res.getInt(1);
|
||||
rows = Arrays.copyOf(rows, rows.length+1);
|
||||
rows[rows.length-1] = rowId;
|
||||
}
|
||||
res.close();
|
||||
stmt.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
private boolean newRecord(PamConnection con, String name, Object data) {
|
||||
|
||||
String insertStr = tableDef.getSQLInsertString(con.getSqlTypes());
|
||||
try {
|
||||
PreparedStatement stmt = con.getConnection().prepareStatement(insertStr);
|
||||
stmt.setString(1, name);
|
||||
if (data == null) {
|
||||
stmt.setNull(2, Types.VARCHAR);
|
||||
}
|
||||
else {
|
||||
stmt.setString(2, data.toString());
|
||||
}
|
||||
stmt.executeUpdate();
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean updateRecord(PamConnection con, int iRow, String name, Object data) {
|
||||
SQLTypes st = con.getSqlTypes();
|
||||
String updateString = String.format("UPDATE %s SET %s = '%s' WHERE Id = %d", tableDef.getTableName(),
|
||||
st.formatColumnName(dataItem.getName()), data, iRow);
|
||||
|
||||
try {
|
||||
PreparedStatement stmt = con.getConnection().prepareStatement(updateString);
|
||||
stmt.executeUpdate();
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean deleteDuplicateRow(PamConnection con, int rowId) {
|
||||
|
||||
String delStr = String.format("DELETE FROM %s WHERE Id=%d", tableDef.getTableName(), rowId);
|
||||
|
||||
try {
|
||||
PreparedStatement stmt = con.getConnection().prepareStatement(delStr);
|
||||
stmt.executeUpdate();
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean checkTable(PamConnection con) {
|
||||
DBControlUnit dbControl = DBControlUnit.findDatabaseControl();
|
||||
if (dbControl == null) {
|
||||
return false;
|
||||
}
|
||||
dbControl.commitChanges();
|
||||
return dbControl.getDbProcess().checkTable(tableDef);
|
||||
}
|
||||
|
||||
}
|
30
src/metadata/MetaDataContol.java
Normal file
30
src/metadata/MetaDataContol.java
Normal file
@ -0,0 +1,30 @@
|
||||
package metadata;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JMenuItem;
|
||||
|
||||
import PamController.PamControlledUnit;
|
||||
import PamModel.parametermanager.ParameterSetManager;
|
||||
import generalDatabase.parameterstore.ParameterDatabaseStore;
|
||||
import metadata.deployment.DeploymentData;
|
||||
|
||||
public class MetaDataContol extends PamControlledUnit {
|
||||
|
||||
public static final String unitType = "Meta Data";
|
||||
|
||||
private DeploymentData deploymentData = new DeploymentData();
|
||||
|
||||
private ParameterSetManager<DeploymentData> deploymentSetManager;
|
||||
|
||||
|
||||
public MetaDataContol(String unitName) {
|
||||
super(unitType, unitName);
|
||||
deploymentSetManager = new ParameterSetManager<DeploymentData>(deploymentData, "Deployment Data");
|
||||
}
|
||||
|
||||
@Override
|
||||
public JMenuItem createFileMenu(JFrame parentFrame) {
|
||||
return deploymentSetManager.getMenuItem(parentFrame);
|
||||
}
|
||||
|
||||
}
|
266
src/metadata/deployment/DeploymentData.java
Normal file
266
src/metadata/deployment/DeploymentData.java
Normal file
@ -0,0 +1,266 @@
|
||||
package metadata.deployment;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import PamModel.parametermanager.FieldNotFoundException;
|
||||
import PamModel.parametermanager.ManagedParameters;
|
||||
import PamModel.parametermanager.PamParameterSet;
|
||||
|
||||
/**
|
||||
* Class to hold Deployment data in a form consistent with the ANSI PAM
|
||||
* Standard. This has been keep separate from the Tethys Interface to keep it
|
||||
* easy to benefit from these data without using Tethys itself.
|
||||
*
|
||||
* @author dg50
|
||||
*
|
||||
*/
|
||||
public class DeploymentData implements Serializable, Cloneable, ManagedParameters {
|
||||
|
||||
public static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* String that uniquely identifies this deployment.
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* Name of project associated with this deployment. Can be related to a
|
||||
* geographic region, funding source, etc
|
||||
*/
|
||||
private String project;
|
||||
|
||||
/**
|
||||
* Deployment identifier, a number related to either the Nth deployment
|
||||
* operation in a series of deployments or the Nth deployment at a specific
|
||||
* site. This is different from Id which is unique across all deployments
|
||||
*/
|
||||
private int deploymentId;
|
||||
|
||||
/**
|
||||
* Alternative deployment description.
|
||||
*/
|
||||
private String deploymentAlias;
|
||||
|
||||
/**
|
||||
* Name for current location.
|
||||
*/
|
||||
private String site;
|
||||
|
||||
/**
|
||||
* Alternative names for the deployment location
|
||||
*/
|
||||
private String siteAliases;
|
||||
|
||||
/**
|
||||
* Name of deployment cruise.
|
||||
*/
|
||||
private String cruise;
|
||||
|
||||
/**
|
||||
* On what platform is the instrument deployed? (e.g. mooring, tag)
|
||||
*/
|
||||
private String platform = "Unknown";
|
||||
|
||||
/**
|
||||
* Name of geographic region.
|
||||
*/
|
||||
private String region;
|
||||
|
||||
/**
|
||||
* Instrument type, e.g. HARP, EAR, Popup, DMON, etc.
|
||||
*/
|
||||
private String instrumentType;
|
||||
|
||||
/**
|
||||
* Instrument identifier, e.g. serial number
|
||||
*/
|
||||
private String instrumentId;
|
||||
|
||||
public DeploymentData() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DeploymentData clone() {
|
||||
try {
|
||||
return (DeploymentData) super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PamParameterSet getParameterSet() {
|
||||
PamParameterSet ps = PamParameterSet.autoGenerate(this);
|
||||
try {
|
||||
ps.findParameterData("id").setInfo("Unique Id", null, "String that uniquely identifies this deployment", 128);
|
||||
// ps.setOrder("id", 0);
|
||||
ps.findParameterData("project").setInfo("Project Name", null, "Name of project associated with this deployment. Can be related to a geographic region, funding source, etc", 200);
|
||||
ps.findParameterData("deploymentId").setInfo("Deployment Identifier", null, "Deployment identifier, a number related to either the Nth deployment operation in a series of deployments or the Nth deployment at a specific site. This is different from Id which is unique across all deployments");
|
||||
ps.findParameterData("deploymentAlias").setInfo("Alternative deployment description", null, "Alternative deployment description", 20);
|
||||
ps.findParameterData("site").setInfo("Site name", null, "Name for current location", 40);
|
||||
ps.findParameterData("siteAliases").setInfo("Alternative site name", null, "Alternative site description", 40);
|
||||
ps.findParameterData("cruise").setInfo("Deployment cruise", null, "Name of deployment cruise");
|
||||
ps.findParameterData("platform").setInfo("Platform type", null, "On what platform is the instrument deployed? (e.g. mooring, tag)", 20);
|
||||
ps.findParameterData("region").setInfo("Geographic Region", "", "Name of geographic region", 40);
|
||||
} catch (FieldNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return ps;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id the id to set
|
||||
*/
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the project
|
||||
*/
|
||||
public String getProject() {
|
||||
return project;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param project the project to set
|
||||
*/
|
||||
public void setProject(String project) {
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the deploymentId
|
||||
*/
|
||||
public int getDeploymentId() {
|
||||
return deploymentId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param deploymentId the deploymentId to set
|
||||
*/
|
||||
public void setDeploymentId(int deploymentId) {
|
||||
this.deploymentId = deploymentId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the deplomentAlias
|
||||
*/
|
||||
public String getDeploymentAlias() {
|
||||
return deploymentAlias;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param deplomentAlias the deplomentAlias to set
|
||||
*/
|
||||
public void setDeploymentAlias(String deplomentAlias) {
|
||||
this.deploymentAlias = deplomentAlias;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the site
|
||||
*/
|
||||
public String getSite() {
|
||||
return site;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param site the site to set
|
||||
*/
|
||||
public void setSite(String site) {
|
||||
this.site = site;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the siteAliases
|
||||
*/
|
||||
public String getSiteAliases() {
|
||||
return siteAliases;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param siteAliases the siteAliases to set
|
||||
*/
|
||||
public void setSiteAliases(String siteAliases) {
|
||||
this.siteAliases = siteAliases;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the cruise
|
||||
*/
|
||||
public String getCruise() {
|
||||
return cruise;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cruise the cruise to set
|
||||
*/
|
||||
public void setCruise(String cruise) {
|
||||
this.cruise = cruise;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the platform
|
||||
*/
|
||||
public String getPlatform() {
|
||||
return platform;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param platform the platform to set
|
||||
*/
|
||||
public void setPlatform(String platform) {
|
||||
this.platform = platform;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the region
|
||||
*/
|
||||
public String getRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param region the region to set
|
||||
*/
|
||||
public void setRegion(String region) {
|
||||
this.region = region;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the instrumentType
|
||||
*/
|
||||
public String getInstrumentType() {
|
||||
return instrumentType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param instrumentType the instrumentType to set
|
||||
*/
|
||||
public void setInstrumentType(String instrumentType) {
|
||||
this.instrumentType = instrumentType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the instrumentId
|
||||
*/
|
||||
public String getInstrumentId() {
|
||||
return instrumentId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param instrumentId the instrumentId to set
|
||||
*/
|
||||
public void setInstrumentId(String instrumentId) {
|
||||
this.instrumentId = instrumentId;
|
||||
}
|
||||
|
||||
}
|
40
src/metadata/deployment/QAData.java
Normal file
40
src/metadata/deployment/QAData.java
Normal file
@ -0,0 +1,40 @@
|
||||
package metadata.deployment;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import PamModel.parametermanager.ManagedParameters;
|
||||
import PamModel.parametermanager.PamParameterSet;
|
||||
|
||||
/**
|
||||
* Largely the content of the Tethys QualityAssurance schema
|
||||
* @author dg50
|
||||
*
|
||||
*/
|
||||
public class QAData implements Serializable, Cloneable, ManagedParameters {
|
||||
|
||||
public static final long serialVersionUID = 1L;
|
||||
|
||||
private String objectives;
|
||||
|
||||
private String qaAbstract;
|
||||
|
||||
private String method;
|
||||
|
||||
private String responsibleName;
|
||||
private String responsibleOrganisation;
|
||||
private String responsiblePosition;
|
||||
private String responsiblePhone;
|
||||
private String responsibleAddress;
|
||||
private String responsibleEmail;
|
||||
|
||||
public QAData() {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public PamParameterSet getParameterSet() {
|
||||
PamParameterSet ps = PamParameterSet.autoGenerate(this);
|
||||
return ps;
|
||||
}
|
||||
|
||||
}
|
@ -11,6 +11,8 @@ import javax.swing.JMenuItem;
|
||||
import PamController.PamControlledUnit;
|
||||
import PamController.PamController;
|
||||
import PamguardMVC.PamDataBlock;
|
||||
import nilus.Deployment;
|
||||
import nilus.Deployment.Instrument;
|
||||
import tethys.output.StreamExportParams;
|
||||
import tethys.output.TethysExportParams;
|
||||
import tethys.output.swing.TethysExportDialog;
|
||||
@ -57,6 +59,19 @@ public class TethysControl extends PamControlledUnit {
|
||||
return tethysExportParams;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a nilus deployment document, as full populated as possible.
|
||||
* @return
|
||||
*/
|
||||
public Deployment getDeployment() {
|
||||
Deployment deployment = new Deployment();
|
||||
Deployment.Instrument instrument = new Instrument();
|
||||
// instrument.
|
||||
// deployment.
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* We'll probably want to
|
||||
* @param parentFrame
|
||||
|
85
src/tethys/deployment/DeploymentWrapper.java
Normal file
85
src/tethys/deployment/DeploymentWrapper.java
Normal file
@ -0,0 +1,85 @@
|
||||
package tethys.deployment;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.AnnotatedType;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBElement;
|
||||
import javax.xml.bind.Marshaller;
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.validation.Schema;
|
||||
|
||||
import nilus.Deployment.Data.Audio;
|
||||
import nilus.Deployment;
|
||||
import nilus.Deployment.Data;
|
||||
import nilus.Deployment.Instrument;
|
||||
|
||||
public class DeploymentWrapper<T extends Serializable> {
|
||||
|
||||
public DeploymentWrapper(T tethysObject) {
|
||||
|
||||
}
|
||||
|
||||
public List<String> getFieldNames() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<Serializable> getComplexObjects() {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// quick play with some JAXB objects to see what they can do.
|
||||
Deployment deployment = new Deployment();
|
||||
|
||||
Class<? extends Deployment> deploymentClass = deployment.getClass();
|
||||
Annotation[] annots = deploymentClass.getAnnotations();
|
||||
AnnotatedType[] annotInterfaces = deploymentClass.getAnnotatedInterfaces();
|
||||
Annotation[] declAnnots = deploymentClass.getDeclaredAnnotations();
|
||||
|
||||
Instrument instrument = new Instrument();
|
||||
instrument.setID("22");
|
||||
instrument.setType("SoundTrap");
|
||||
QName qName = new QName("Instrument");
|
||||
JAXBElement<Instrument> jInst = new JAXBElement<Deployment.Instrument>(qName, Instrument.class, instrument);
|
||||
deployment.getContent().add(jInst);
|
||||
|
||||
Deployment.Data data = new Data();
|
||||
Audio audio = new Audio();
|
||||
audio.setProcessed("??");
|
||||
data.setAudio(audio);
|
||||
JAXBElement jData = new JAXBElement<Deployment.Data>(new QName("Data"), Data.class, data);
|
||||
deployment.getContent().add(jData);
|
||||
|
||||
String project = "Project Name";
|
||||
JAXBElement<String> jProj = new JAXBElement<String>(new QName("Project"), String.class, project);
|
||||
deployment.getContent().add(jProj);
|
||||
|
||||
String aaa = "Project Something else";
|
||||
JAXBElement<String> jProj2 = new JAXBElement<String>(new QName("Region"), String.class, aaa);
|
||||
deployment.getContent().add(jProj2);
|
||||
|
||||
|
||||
try {
|
||||
JAXBContext jContext = JAXBContext.newInstance(Deployment.class);
|
||||
Marshaller mar = (Marshaller) jContext.createMarshaller();
|
||||
mar.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, true);
|
||||
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
mar.marshal(deployment, bos);
|
||||
String xml = new String(bos.toByteArray());
|
||||
System.out.println(xml);
|
||||
// Schema schema = mar.getSchema(); // is null. Can't generate it's own it seems.
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
64
src/tethys/deployment/PamDeployment.java
Normal file
64
src/tethys/deployment/PamDeployment.java
Normal file
@ -0,0 +1,64 @@
|
||||
package tethys.deployment;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import nilus.DeploymentRecoveryDetails;
|
||||
|
||||
/**
|
||||
* Wrapper and functions associated with the Tethys Deployment object which can
|
||||
* exchange these with the PAMGuard database and display Everything is just held
|
||||
* within a list, in no particular order, which getContent public
|
||||
*
|
||||
* This is from the Deployment JavaDoc. TBH it's pretty horrible, since it's possible to have
|
||||
* more than one of each type of object in the list, so not sure what to do about that. Would be nicer
|
||||
* as a HashTable. however we are where we're are for now. Start by focussing on getting the
|
||||
* content saved for each type
|
||||
*
|
||||
* List<Serializable> getContent()
|
||||
*
|
||||
* Gets the value of the content property. This accessor method returns a
|
||||
* reference to the live list,not a snapshot. Therefore any modification you
|
||||
* make to the returned list will be present inside the JAXB object.This is why
|
||||
* there is not a set method for the content property.
|
||||
*
|
||||
* For example, to add a new item, do as follows: getContent().add(newItem);
|
||||
*
|
||||
*
|
||||
* Objects of the following type(s) are allowed in the list JAXBElement<String>
|
||||
* JAXBElement<String>
|
||||
* JAXBElement<Integer>
|
||||
* JAXBElement<DeploymentRecoveryDetails>
|
||||
* JAXBElement<String>
|
||||
* JAXBElement<Deployment.SamplingDetails>
|
||||
* JAXBElement<Deployment.Sensors>
|
||||
* JAXBElement<Deployment.Instrument>
|
||||
* JAXBElement<String>
|
||||
* JAXBElement<Deployment.Data>
|
||||
* JAXBElement<String> String
|
||||
* JAXBElement<AcousticDataQAType>
|
||||
* JAXBElement<Deployment.SiteAliases>
|
||||
* JAXBElement<String>
|
||||
* JAXBElement<DeploymentRecoveryDetails>
|
||||
*
|
||||
*
|
||||
* @author dg50
|
||||
*
|
||||
*/
|
||||
public class PamDeployment {
|
||||
|
||||
public PamDeployment() {
|
||||
|
||||
}
|
||||
|
||||
public DeploymentRecoveryDetails getDeploymentRecoveryDetails() {
|
||||
DeploymentRecoveryDetails drd = new DeploymentRecoveryDetails();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void ripApart(Serializable object) {
|
||||
Class cls = object.getClass();
|
||||
// cls.get
|
||||
}
|
||||
|
||||
}
|
5
src/tethys/exchange/TethysExchange.java
Normal file
5
src/tethys/exchange/TethysExchange.java
Normal file
@ -0,0 +1,5 @@
|
||||
package tethys.exchange;
|
||||
|
||||
public interface TethysExchange {
|
||||
// JAXB
|
||||
}
|
Loading…
Reference in New Issue
Block a user