From bc686c0fe679ef3f768c64e5f9c02ab0993ca444 Mon Sep 17 00:00:00 2001 From: Douglas Gillespie <50671166+douggillespie@users.noreply.github.com> Date: Fri, 26 Jul 2024 16:12:54 +0100 Subject: [PATCH] Improved document handling Abstracted wrapper around nilus documents which allows easyish calling of internal functions in Localize and Detections document without a common base class. --- src/tethys/TethysControl.java | 7 + src/tethys/dbxml/DBXMLQueries.java | 136 ++++++++++++++++++ src/tethys/detection/DetectionsHandler.java | 7 +- .../detection/StreamDetectionsSummary.java | 7 +- .../localization/LocalizationHandler.java | 33 +++-- src/tethys/localization/PLocalization.java | 14 ++ src/tethys/niluswraps/NilusDataWrapper.java | 29 ++++ .../niluswraps/NilusDocumentWrapper.java | 86 ++++++++++- src/tethys/niluswraps/PDetections.java | 20 +-- .../swing/DatablockDetectionsPanel.java | 117 +++++++++------ 10 files changed, 377 insertions(+), 79 deletions(-) create mode 100644 src/tethys/localization/PLocalization.java diff --git a/src/tethys/TethysControl.java b/src/tethys/TethysControl.java index 4287b9db..45671af1 100644 --- a/src/tethys/TethysControl.java +++ b/src/tethys/TethysControl.java @@ -598,6 +598,13 @@ public class TethysControl extends PamControlledUnit implements PamSettings, Tet return detectionsHandler; } + /** + * @return the localizationHandler + */ + public LocalizationHandler getLocalizationHandler() { + return localizationHandler; + } + public void showException(TethysException tethysException) { String title = tethysException.getMessage(); StackTraceElement[] stack = tethysException.getStackTrace(); diff --git a/src/tethys/dbxml/DBXMLQueries.java b/src/tethys/dbxml/DBXMLQueries.java index bfddc2f0..b3392568 100644 --- a/src/tethys/dbxml/DBXMLQueries.java +++ b/src/tethys/dbxml/DBXMLQueries.java @@ -32,6 +32,7 @@ import nilus.Detections; import nilus.GranularityEnumType; import nilus.GranularityType; import nilus.Helper; +import nilus.Localize; import tethys.Collection; import tethys.DocumentInfo; import tethys.TethysControl; @@ -784,6 +785,38 @@ public class DBXMLQueries { } return count; } + + /** + * Count on effort detections in a Detections document + * @param docName + * @return + */ + public int countLocalizations2(String docName) { + TethysExportParams params = tethysControl.getTethysExportParams(); + String queryBase = "count(collection(\"Localizations\")/Localize[Id=\"ReplaceDocumentId\"]/Localizations/Localization)"; + String query = queryBase.replace("ReplaceDocumentId", docName); + + String result = null; + try { + Queries queries = dbXMLConnect.getTethysQueries(); + result = queries.QueryTethys(query); + // System.out.println(result); + } + catch (Exception e) { + System.out.println("Error executing " + query); + // e.printStackTrace(); + return -1; + } + int count = 0; + try { + count = Integer.valueOf(result); + } + catch (NumberFormatException e) { + System.out.println("Unable to interpret count data " + result); + return 0; + } + return count; + } // /** // * Get a count of the detections in a detections document. @@ -1081,5 +1114,108 @@ public class DBXMLQueries { // TODO Auto-generated method stub return detections; } + /** + * Get the basic information about a Detections document. This is basically everything apart from + * the actual detections themselves. + * @param aDoc + * @return + */ + public Localize getLocalizationDocInfo(String locDocName) { +// String oldqueryBase = "{\"species\":{\"query\":{\"op\":\"lib:abbrev2tsn\",\"optype\":\"function\",\"operands\":[\"%s\",\"SIO.SWAL.v1\"]},\"return\":{\"op\":\"lib:tsn2abbrev\",\"optype\":\"function\",\"operands\":[\"%s\",\"SIO.SWAL.v1\"]}},\"return\":[\"Detections/Id\",\"Detections/Description\",\"Detections/DataSource\",\"Detections/Algorithm\"],\"select\":[{\"op\":\"=\",\"operands\":[\"Detections/Id\",\"DetectionsDocName\"],\"optype\":\"binary\"}],\"enclose\":1}"; + // updated May 23 +// String queryBase = "{\"species\":{\"query\":{\"op\":\"lib:completename2tsn\",\"optype\":\"function\",\"operands\":[\"%s\"]},\"return\":{\"op\":\"lib:tsn2completename\",\"optype\":\"function\",\"operands\":[\"%s\"]}},\"return\":[\"Localize/Id\",\"Localize/Description\",\"Localize/DataSource\",\"Localize/Algorithm\",\"Localize/QualityAssurance\",\"Localize/UserId\",\"Localize/MetadataInfo\",\"Localize/Effort\"],\"select\":[{\"op\":\"=\",\"operands\":[\"Localize/Id\",\"LocalizationsDocName\"],\"optype\":\"binary\"}],\"enclose\":1}"; + String queryBase = "{\"species\":{\"query\":{\"op\":\"lib:completename2tsn\",\"optype\":\"function\",\"operands\":[\"%s\"]},\"return\":{\"op\":\"lib:tsn2completename\",\"optype\":\"function\",\"operands\":[\"%s\"]}},\"return\":[\"Localize/Id\",\"Localize/Description\",\"Localize/DataSource\",\"Localize/Algorithm\",\"Localize/QualityAssurance\",\"Localize/UserId\",\"Localize/Effort\"],\"select\":[{\"op\":\"=\",\"operands\":[\"Localize/Id\",\"LocalizationsDocName\"],\"optype\":\"binary\"}],\"enclose\":1}"; + String query = queryBase.replace("LocalizationsDocName", locDocName); + DBQueryResult queryResult; + try { + queryResult = executeQuery(query); + } catch (TethysQueryException e) { + tethysControl.showException(e); + return null; + } + Document doc; + try { + doc = queryResult.getDocument(); + } catch (ParserConfigurationException | SAXException | IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return null; + } + // System.out.println(queryResult.queryResult); + + Localize localize = new Localize(); + try { + Helper.createRequiredElements(localize); + } catch (IllegalArgumentException | IllegalAccessException | InstantiationException e) { + e.printStackTrace(); + } + + NodeList returns = doc.getElementsByTagName("Result"); + // System.out.println("N projects = " + returns.getLength()); + int n = returns.getLength(); + if (n == 0) { + return null; + } + Element result = (Element) returns.item(0); + + DescriptionType description = localize.getDescription(); + if (description == null) { + description = new DescriptionType(); + localize.setDescription(description); + } + localize.setId(getElementData(result, "Id")); + description.setAbstract(getElementData(result, "Description.Abstract")); + description.setMethod(getElementData(result, "Description.Method")); + description.setObjectives(getElementData(result, "Description.Objectives")); + + String deployment = getElementData(result, "DataSource.DeploymentId"); + if (deployment != null) { + DataSourceType dataSource = localize.getDataSource(); + if (dataSource == null) { + dataSource = new DataSourceType(); + localize.setDataSource(dataSource); + } + dataSource.setDeploymentId(deployment); + } + + // get the effort start an end + String effStart = getElementData(result, "Effort.Start"); + String effEnd = getElementData(result, "Effort.End"); + localize.getEffort().setStart(TethysTimeFuncs.fromGregorianXML(effStart)); + localize.getEffort().setEnd(TethysTimeFuncs.fromGregorianXML(effEnd)); + // try to find the granularity. +// String granularityString = getElementData(result, "Effort.Kind.Granularity"); +// GranularityEnumType granularity = null; +// if (granularityString != null) { +// granularity = GranularityEnumType.fromValue(granularityString); +// List kinds = detections.getEffort().getKind(); +// DetectionEffortKind kind = new DetectionEffortKind(); +// GranularityType granularityType = new GranularityType(); +// granularityType.setValue(granularity); +// kind.setGranularity(granularityType); +// // try to find the rest of the granularity information. +// String binSize_m = getElementAttribute(result, "Effort.Kind.Granularity", "BinSize_m"); +// String encounterGap_m = getElementAttribute(result, "Effort.Kind.Granularity", "EncounterGap_m"); +// String firstBinStart = getElementAttribute(result, "Effort.Kind.Granularity", "FirstBinStart"); +// try { +// granularityType.setBinSizeMin(Double.valueOf(binSize_m)); +// } +// catch (NumberFormatException e) { +// } +// try { +// granularityType.setEncounterGapMin(Double.valueOf(encounterGap_m)); +// } +// catch (NumberFormatException e) { +// } +// +// kinds.add(kind); +// } + // String + + + + // TODO Auto-generated method stub + return localize; + } } diff --git a/src/tethys/detection/DetectionsHandler.java b/src/tethys/detection/DetectionsHandler.java index 90a99378..8a6f0b88 100644 --- a/src/tethys/detection/DetectionsHandler.java +++ b/src/tethys/detection/DetectionsHandler.java @@ -51,6 +51,8 @@ import tethys.deployment.DeploymentHandler; import tethys.localization.CoordinateName; import tethys.localization.LocalizationSubType; import tethys.localization.LocalizationType; +import tethys.localization.PLocalization; +import tethys.niluswraps.NilusDataWrapper; import tethys.niluswraps.PDeployment; import tethys.niluswraps.PDetections; import tethys.output.StreamExportParams; @@ -93,9 +95,8 @@ public class DetectionsHandler extends CollectionHandler { * this data set (not the entire project). * @param dataBlock */ - public StreamDetectionsSummary getStreamDetections(PamDataBlock dataBlock) { + public StreamDetectionsSummary> getStreamDetections(PamDataBlock dataBlock) { ArrayList deployments = tethysControl.getDeploymentHandler().getMatchedDeployments(); -// getStreamLocalizations(dataBlock, deployments); return getStreamDetections(dataBlock, deployments); } @@ -106,7 +107,7 @@ public class DetectionsHandler extends CollectionHandler { * @param deployments * @return */ - public StreamDetectionsSummary getStreamDetections(PamDataBlock dataBlock, ArrayList deployments) { + public StreamDetectionsSummary> getStreamDetections(PamDataBlock dataBlock, ArrayList deployments) { // get the basic data for each document including it's Description. ArrayList detectionsDocs = new ArrayList<>(); diff --git a/src/tethys/detection/StreamDetectionsSummary.java b/src/tethys/detection/StreamDetectionsSummary.java index 70c11618..28ec72db 100644 --- a/src/tethys/detection/StreamDetectionsSummary.java +++ b/src/tethys/detection/StreamDetectionsSummary.java @@ -2,6 +2,7 @@ package tethys.detection; import java.util.ArrayList; +import tethys.niluswraps.NilusDataWrapper; import tethys.niluswraps.PDetections; /** @@ -10,11 +11,11 @@ import tethys.niluswraps.PDetections; * @author dg50 * */ -public class StreamDetectionsSummary { +public class StreamDetectionsSummary { - public ArrayList detectionsDocs; + public ArrayList detectionsDocs; - public StreamDetectionsSummary(ArrayList detectionsDocs) { + public StreamDetectionsSummary(ArrayList detectionsDocs) { this.detectionsDocs = detectionsDocs; } diff --git a/src/tethys/localization/LocalizationHandler.java b/src/tethys/localization/LocalizationHandler.java index 1741c8ac..87c5fe0a 100644 --- a/src/tethys/localization/LocalizationHandler.java +++ b/src/tethys/localization/LocalizationHandler.java @@ -5,11 +5,13 @@ import java.util.ArrayList; import PamguardMVC.PamDataBlock; import nilus.CylindricalCoordinateType; import nilus.LocalizationType; +import nilus.Localize; import nilus.Localize.Effort.CoordinateReferenceSystem; import tethys.Collection; import tethys.CollectionHandler; import tethys.TethysControl; import tethys.detection.StreamDetectionsSummary; +import tethys.niluswraps.NilusDataWrapper; import tethys.niluswraps.PDeployment; public class LocalizationHandler extends CollectionHandler { @@ -26,33 +28,45 @@ public class LocalizationHandler extends CollectionHandler { // CoordinateReferenceSystem cr; // return null; // } + + /** + * Get a list of Localization documents associated with a particular data block for all deployments + * documents. Group them by abstract or something + * @param dataBlock + * @return + */ + public StreamDetectionsSummary> getStreamLocalizations(PamDataBlock dataBlock) { + ArrayList deployments = tethysControl.getDeploymentHandler().getMatchedDeployments(); + return getStreamLocalizations(dataBlock, deployments); + } /** * Get a list of Localization documents associated with a particular data block for the list of deployments * documents. Group them by abstract or something * @param dataBlock - * @param deployments + * @param deployments can be null for all deployments. * @return */ - public StreamDetectionsSummary getStreamLocalizations(PamDataBlock dataBlock, ArrayList deployments) { + public StreamDetectionsSummary> getStreamLocalizations(PamDataBlock dataBlock, ArrayList deployments) { // get the basic data for each document including it's Description. -// ArrayList detectionsDocs = new ArrayList<>(); + ArrayList localizeDocs = new ArrayList<>(); for (PDeployment aDep : deployments) { ArrayList someNames = tethysControl.getDbxmlQueries().getLocalizationDocuments(dataBlock, aDep.getDocumentId()); if (someNames == null) { continue; } // // no have a list of all the Detections documents of interest for this datablock. -// for (String aDoc : someNames) { -// Detections detections = tethysControl.getDbxmlQueries().getDetectionsDocInfo(aDoc); -// int count = tethysControl.getDbxmlQueries().countDetections2(aDoc); + for (String aDoc : someNames) { + Localize localize = tethysControl.getDbxmlQueries().getLocalizationDocInfo(aDoc); + int count = tethysControl.getDbxmlQueries().countLocalizations2(aDoc); + PLocalization pLocalize = new PLocalization(localize, dataBlock, aDep, count); + localizeDocs.add(pLocalize); // PDetections pDetections = new PDetections(detections, dataBlock, aDep, count); // detectionsDocs.add(pDetections); -// } + } } -// return new StreamDetectionsSummary(detectionsDocs); - return null; + return new StreamDetectionsSummary(localizeDocs); } @Override @@ -60,4 +74,5 @@ public class LocalizationHandler extends CollectionHandler { // TODO Auto-generated method stub return null; } + } diff --git a/src/tethys/localization/PLocalization.java b/src/tethys/localization/PLocalization.java new file mode 100644 index 00000000..c0cb1d38 --- /dev/null +++ b/src/tethys/localization/PLocalization.java @@ -0,0 +1,14 @@ +package tethys.localization; + +import PamguardMVC.PamDataBlock; +import nilus.Localize; +import tethys.niluswraps.NilusDataWrapper; +import tethys.niluswraps.PDeployment; + +public class PLocalization extends NilusDataWrapper { + + public PLocalization(Localize nilusObject, PamDataBlock dataBlock, PDeployment deployment, Integer count) { + super(nilusObject, dataBlock, deployment, count); + } + +} diff --git a/src/tethys/niluswraps/NilusDataWrapper.java b/src/tethys/niluswraps/NilusDataWrapper.java index 503760ee..10806b30 100644 --- a/src/tethys/niluswraps/NilusDataWrapper.java +++ b/src/tethys/niluswraps/NilusDataWrapper.java @@ -1,6 +1,14 @@ package tethys.niluswraps; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import javax.xml.datatype.XMLGregorianCalendar; + import PamguardMVC.PamDataBlock; +import nilus.DataSourceType; +import nilus.DescriptionType; +import nilus.QualityAssuranceProcessType; /** * Wrapper for Nilus data objects. This means Detections and Localization documents which @@ -23,5 +31,26 @@ public class NilusDataWrapper extends NilusDocumentWrapper { this.deployment = deployment; this.count = count; } + + public DescriptionType getDescription() { + return (DescriptionType) getGotObject("getDescription"); + } + + public DataSourceType getDataSource() { + return (DataSourceType) getGotObject("getDataSource"); + } + + + public QualityAssuranceProcessType getQualityAssurance() { + return (QualityAssuranceProcessType) getGotObject("getQualityAssurance"); + } + + public XMLGregorianCalendar getEffortStart() { + return (XMLGregorianCalendar) getGotObjects("getEffort", "getStart"); + } + + public XMLGregorianCalendar getEffortEnd() { + return (XMLGregorianCalendar) getGotObjects("getEffort", "getEnd"); + } } diff --git a/src/tethys/niluswraps/NilusDocumentWrapper.java b/src/tethys/niluswraps/NilusDocumentWrapper.java index 67a46328..2ca42233 100644 --- a/src/tethys/niluswraps/NilusDocumentWrapper.java +++ b/src/tethys/niluswraps/NilusDocumentWrapper.java @@ -1,6 +1,9 @@ package tethys.niluswraps; -import PamguardMVC.PamDataBlock; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import tethys.Collection; import tethys.dbxml.DBXMLConnect; public class NilusDocumentWrapper { @@ -21,4 +24,85 @@ public class NilusDocumentWrapper { return DBXMLConnect.getDocumentId(nilusObject); } + /** + * Get an object out of the nilus object using a series of sequential getter functions + * @param getterName function names (any number to work through class list) . + * @return + */ + public Object getGotObjects(String... getterNames) { + /** + * Be aware that this will probably get called in preference to + * the function below, so need to check to see if the + */ + return getGotObjects(nilusObject, getterNames); + } + + /** + * Get an object out of the given object using a series of sequential getter functions + * @param source source object + * @param getterName function names (any number to work through class list) . + * @return + */ + public Object getGotObjects(Object source, String... getterNames) { + Object obj = source; + for (int i = 0; i < getterNames.length; i++) { + obj = getGotObject(obj, getterNames[i]); + if (obj == null) { + break; + } + } + return obj; + } + + /** + * Get an object out of the main nilus object using a getter function (no function parameters). + * @param source source object + * @param getterName function name. + * @return + */ + public Object getGotObject(String getterName) { + return getGotObject(nilusObject, getterName); + } + + /** + * Get an object out of the given object using a getter function (no function parameters). + * @param source source object + * @param getterName function name. + * @return + */ + public Object getGotObject(Object source, String getterName) { + if (source == null) { + return null; + } + Class sourceClass = source.getClass(); + Method getId; + try { + getId = sourceClass.getDeclaredMethod(getterName, null); + Object[] inputs = new Object[0]; + Object res = getId.invoke(source, inputs); + return res; + } + catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + System.err.printf("Unable to find method %s in object %s\n", getterName, source.toString()); + e.printStackTrace(); + } + return null; + } + + /** + * Get the class of the nilus object. + * @return Java class of nilus object. + */ + public Class getNilusClass() { + return nilusObject.getClass(); + } + + /** + * Collection for the nilus object. + * @return + */ + public Collection getCollection() { + return Collection.fromClass(getNilusClass()); + } + } diff --git a/src/tethys/niluswraps/PDetections.java b/src/tethys/niluswraps/PDetections.java index 892cc5c5..4067aa5d 100644 --- a/src/tethys/niluswraps/PDetections.java +++ b/src/tethys/niluswraps/PDetections.java @@ -3,30 +3,12 @@ package tethys.niluswraps; import PamguardMVC.PamDataBlock; import nilus.Detections; -public class PDetections extends NilusDataWrapper{ +public class PDetections extends NilusDataWrapper { public PDetections(Detections detections, PamDataBlock dataBlock, PDeployment deployment, Integer count) { super(detections, dataBlock, deployment, count); - // TODO Auto-generated constructor stub } -// public Detections nilusObject; -// -// public Integer count; -// -// public PDeployment deployment; -// -// public PamDataBlock dataBlock; -// -// public PDetections(Detections detections, PamDataBlock dataBlock, PDeployment deployment, Integer count) { -// super(); -// this.dataBlock = dataBlock; -// this.nilusObject = detections; -// this.deployment = deployment; -// this.count = count; -// } - - } diff --git a/src/tethys/swing/DatablockDetectionsPanel.java b/src/tethys/swing/DatablockDetectionsPanel.java index 76b4d172..cbe25cae 100644 --- a/src/tethys/swing/DatablockDetectionsPanel.java +++ b/src/tethys/swing/DatablockDetectionsPanel.java @@ -27,14 +27,20 @@ import PamView.dialog.warn.WarnOnce; import PamView.tables.SwingTableColumnWidths; import PamguardMVC.PamDataBlock; import nilus.DataSourceType; +import nilus.DescriptionType; +import nilus.DetectionEffort; import nilus.DetectionEffortKind; import nilus.Detections; import nilus.GranularityType; +import nilus.Localize.Effort; import tethys.Collection; import tethys.TethysControl; import tethys.TethysState; import tethys.dbxml.TethysException; import tethys.detection.StreamDetectionsSummary; +import tethys.localization.PLocalization; +import tethys.niluswraps.NilusDataWrapper; +import tethys.niluswraps.NilusDocumentWrapper; import tethys.niluswraps.PDeployment; import tethys.niluswraps.PDetections; @@ -57,7 +63,11 @@ public class DatablockDetectionsPanel extends TethysGUIPanel implements StreamTa private PamDataBlock dataBlock; - private StreamDetectionsSummary streamDetectionsSummary; +// private StreamDetectionsSummary> streamDetectionsSummary; +// +// private StreamDetectionsSummary> streamLocalisationsSummary; + + private StreamDetectionsSummary combinedSummary; public DatablockDetectionsPanel(TethysControl tethysControl) { super(tethysControl); @@ -144,7 +154,16 @@ public class DatablockDetectionsPanel extends TethysGUIPanel implements StreamTa @Override public String runBackgroundTask(PamWorker pamWorker) { - streamDetectionsSummary = getTethysControl().getDetectionsHandler().getStreamDetections(dataBlock); + StreamDetectionsSummary> streamDetectionsSummary = getTethysControl().getDetectionsHandler().getStreamDetections(dataBlock); + StreamDetectionsSummary> streamLocalisationsSummary = getTethysControl().getLocalizationHandler().getStreamLocalizations(dataBlock); + ArrayList allDocs = new ArrayList(); + if (streamDetectionsSummary != null) { + allDocs.addAll(streamDetectionsSummary.detectionsDocs); + } + if (streamLocalisationsSummary != null) { + allDocs.addAll(streamLocalisationsSummary.detectionsDocs); + } + combinedSummary = new StreamDetectionsSummary<>(allDocs); return null; } @@ -183,7 +202,7 @@ public class DatablockDetectionsPanel extends TethysGUIPanel implements StreamTa } int[] rows = table.getSelectedRows(); - PDetections pDets = detectionsForRow(row); + NilusDataWrapper pDets = detectionsForRow(row); if (pDets == null) { return; } @@ -216,7 +235,7 @@ public class DatablockDetectionsPanel extends TethysGUIPanel implements StreamTa menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - deleteDocument(pDets); +// deleteDocument(pDets); } }); popMenu.add(menuItem); @@ -247,11 +266,11 @@ public class DatablockDetectionsPanel extends TethysGUIPanel implements StreamTa return; } - ArrayList toDelete = new ArrayList(); + ArrayList toDelete = new ArrayList(); for (int i = 0; i < rows.length; i++) { int row = rows[i]; - PDetections pDets = detectionsForRow(row); + NilusDataWrapper pDets = detectionsForRow(row); if (pDets == null) { continue; } @@ -265,15 +284,15 @@ public class DatablockDetectionsPanel extends TethysGUIPanel implements StreamTa private class DeleteDocs implements PamWorkWrapper { - private ArrayList toDelete; + private ArrayList toDelete; - public DeleteDocs(ArrayList toDelete) { + public DeleteDocs(ArrayList toDelete) { this.toDelete = toDelete; } @Override public Integer runBackgroundTask(PamWorker pamWorker) { - for (Detections dets : toDelete) { + for (NilusDocumentWrapper dets : toDelete) { try { getTethysControl().getDbxmlConnect().deleteDocument(dets); @@ -307,36 +326,35 @@ public class DatablockDetectionsPanel extends TethysGUIPanel implements StreamTa selectDataBlock(dataBlock); // force table update. } - private void displayDocument(PDetections pDets) { - getTethysControl().displayDocument(Collection.Detections.collectionName(), pDets.getDocumentId()); + private void displayDocument(NilusDataWrapper pDets) { + getTethysControl().displayDocument(pDets.getCollection().collectionName(), pDets.getDocumentId()); } - private void exportDocument(PDetections pDets) { - getTethysControl().exportDocument(Collection.Detections.toString(), pDets.getDocumentId()); - + private void exportDocument(NilusDataWrapper pDets) { + getTethysControl().exportDocument(pDets.getCollection().collectionName(), pDets.getDocumentId()); } - private PDetections detectionsForRow(int iRow) { - if (streamDetectionsSummary == null || streamDetectionsSummary.detectionsDocs == null) { + private NilusDataWrapper detectionsForRow(int iRow) { + if (combinedSummary == null || combinedSummary.detectionsDocs == null) { return null; } - if (iRow < 0 || iRow >= streamDetectionsSummary.detectionsDocs.size()) { + if (iRow < 0 || iRow >= combinedSummary.detectionsDocs.size()) { return null; } - return streamDetectionsSummary.detectionsDocs.get(iRow); + return combinedSummary.detectionsDocs.get(iRow); } private class TableModel extends AbstractTableModel { - private String[] colNames = {"Document", "Detector", "Deployment", "Effort", "Granularity", "Count", "Abstract"}; + private String[] colNames = {"Document", "Detector", "Deployment", "Type", "Effort", "Granularity", "Count", "Abstract"}; @Override public int getRowCount() { - if (streamDetectionsSummary == null || streamDetectionsSummary.detectionsDocs == null) { + if (combinedSummary == null || combinedSummary.detectionsDocs == null) { return 0; } - return streamDetectionsSummary.detectionsDocs.size(); + return combinedSummary.detectionsDocs.size(); } @Override @@ -351,28 +369,28 @@ public class DatablockDetectionsPanel extends TethysGUIPanel implements StreamTa @Override public Object getValueAt(int rowIndex, int columnIndex) { - PDetections pDets = detectionsForRow(rowIndex); + NilusDataWrapper pDets = detectionsForRow(rowIndex); return getValueAt(pDets, columnIndex); } - private Object getValueAt(PDetections pDets, int columnIndex) { + private Object getValueAt(NilusDataWrapper pDets, int columnIndex) { if (pDets == null) { return null; } - Detections dets = pDets.nilusObject; - if (dets == null) { +// PDetections dets = pDets.nilusObject; + if (pDets == null) { return "Error in doc"; } switch (columnIndex) { case 0: - return dets.getId(); + return pDets.getDocumentId(); case 1: if (pDets.dataBlock == null) { return null; } return pDets.dataBlock.getDataName(); case 2: - DataSourceType dataSource = dets.getDataSource(); + DataSourceType dataSource = pDets.getDataSource(); if (dataSource == null) { return null; } @@ -380,28 +398,39 @@ public class DatablockDetectionsPanel extends TethysGUIPanel implements StreamTa return dataSource.getDeploymentId(); } case 3: - XMLGregorianCalendar start = dets.getEffort().getStart(); - XMLGregorianCalendar stop = dets.getEffort().getEnd(); - return start + " to " + stop; + return pDets.getCollection(); case 4: - List kinds = dets.getEffort().getKind(); - if (kinds == null) { - return null; - } - for (DetectionEffortKind kind : kinds) { - if (kind.getGranularity() != null) { - GranularityType granularity = kind.getGranularity(); - return PDeployment.formatGranularity(granularity); - // if (granularity != null) { - // return granularity.getValue(); - // } +// XMLGregorianCalendar start = dets.getEffort().getStart(); +// XMLGregorianCalendar stop = dets.getEffort().getEnd(); + XMLGregorianCalendar start = pDets.getEffortStart(); + XMLGregorianCalendar stop = pDets.getEffortEnd(); + return start + " to " + stop; + case 5: + Object effort = pDets.getGotObjects("getEffort"); + if (effort instanceof DetectionEffort) { + DetectionEffort detectionEffort = (DetectionEffort) effort; + List kinds = detectionEffort.getKind(); + if (kinds == null) { + return null; + } + for (DetectionEffortKind kind : kinds) { + if (kind.getGranularity() != null) { + GranularityType granularity = kind.getGranularity(); + return PDeployment.formatGranularity(granularity); + // if (granularity != null) { + // return granularity.getValue(); + // } + } } } break; - case 5: - return pDets.count; case 6: - return dets.getDescription().getAbstract(); + return pDets.count; + case 7: + DescriptionType desc = pDets.getDescription(); + if (desc != null) { + return desc.getAbstract(); + } } return null; }