From 9f78d8bb3558f4be973b5703239fd75bbe7eb1f5 Mon Sep 17 00:00:00 2001 From: "U-BASIS\\zhaohui" Date: Tue, 8 May 2018 18:02:54 -0400 Subject: [PATCH] 3779: Updates according the comments. --- .../autopsy/filesearch/Bundle.properties | 2 +- .../autopsy/filesearch/DataSourceFilter.java | 17 ++- .../autopsy/filesearch/DataSourcePanel.form | 10 +- .../autopsy/filesearch/DataSourcePanel.java | 109 ++++++++---------- 4 files changed, 66 insertions(+), 72 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/filesearch/Bundle.properties b/Core/src/org/sleuthkit/autopsy/filesearch/Bundle.properties index 1c4d93c230..62f0c656ac 100644 --- a/Core/src/org/sleuthkit/autopsy/filesearch/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/filesearch/Bundle.properties @@ -57,5 +57,5 @@ HashSearchPanel.emptyHashMsg.text=Must enter something for hash search. FileSearchPanel.errorLabel.text=\ DataSourcePanel.dataSourceCheckBox.label=Data Source: DataSourcePanel.dataSourceCheckBox.actionCommand=Data Source: -DataSourcePanel.jLabel.text=*Note: Multiple data sources can be selected DataSourcePanel.dataSourceCheckBox.text=Data Source: +DataSourcePanel.dataSourceNoteLable.text=*Note: Multiple data sources can be selected diff --git a/Core/src/org/sleuthkit/autopsy/filesearch/DataSourceFilter.java b/Core/src/org/sleuthkit/autopsy/filesearch/DataSourceFilter.java index dbb3a37fff..439b65e6b9 100755 --- a/Core/src/org/sleuthkit/autopsy/filesearch/DataSourceFilter.java +++ b/Core/src/org/sleuthkit/autopsy/filesearch/DataSourceFilter.java @@ -26,10 +26,17 @@ import org.openide.util.NbBundle.Messages; */ class DataSourceFilter extends AbstractFileSearchFilter { + /** + * Construct DataSourceFilter with the DataSourcePanel + * @param component A DataSourcePanel + */ public DataSourceFilter(DataSourcePanel component) { super(component); } + /** + * Default constructor to construct a new DataSourceFilter with a new DataSourcePanel + */ public DataSourceFilter() { this(new DataSourcePanel()); } @@ -43,16 +50,16 @@ class DataSourceFilter extends AbstractFileSearchFilter { public String getPredicate() throws FilterValidationException { String predicate = ""; for (Long dataSourceObjId : this.getComponent().getDataSourcesSelected()) { - predicate += "data_source_obj_id = '" + dataSourceObjId + "' OR "; - } - if (predicate.length() > 3) { - predicate = predicate.substring(0, predicate.length() - 3); + if (!predicate.isEmpty()) { + predicate += " OR "; + } + predicate += "data_source_obj_id = '" + dataSourceObjId + "'"; } return predicate; } @Override - public void addActionListener(ActionListener l) { + public void addActionListener(ActionListener lis) { } @Override diff --git a/Core/src/org/sleuthkit/autopsy/filesearch/DataSourcePanel.form b/Core/src/org/sleuthkit/autopsy/filesearch/DataSourcePanel.form index 438974c170..6efa43640f 100755 --- a/Core/src/org/sleuthkit/autopsy/filesearch/DataSourcePanel.form +++ b/Core/src/org/sleuthkit/autopsy/filesearch/DataSourcePanel.form @@ -33,7 +33,7 @@ - + @@ -48,7 +48,7 @@ - + @@ -65,7 +65,7 @@ - + @@ -91,13 +91,13 @@ - + - + diff --git a/Core/src/org/sleuthkit/autopsy/filesearch/DataSourcePanel.java b/Core/src/org/sleuthkit/autopsy/filesearch/DataSourcePanel.java index 4821f009fd..f76b7fc4f4 100755 --- a/Core/src/org/sleuthkit/autopsy/filesearch/DataSourcePanel.java +++ b/Core/src/org/sleuthkit/autopsy/filesearch/DataSourcePanel.java @@ -21,8 +21,6 @@ package org.sleuthkit.autopsy.filesearch; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionListener; import java.io.File; -import java.sql.ResultSet; -import java.sql.SQLException; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -36,15 +34,19 @@ import javax.swing.event.ListSelectionEvent; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.datamodel.DataSource; import org.sleuthkit.datamodel.SleuthkitCase; import org.sleuthkit.datamodel.TskCoreException; +/** + * Subpanel with controls for data source filtering. + */ public class DataSourcePanel extends javax.swing.JPanel { private static final Logger logger = Logger.getLogger(DataSourcePanel.class.getName()); private static final long serialVersionUID = 1L; private final Map dataSourceMap = new HashMap<>(); - private List toolTipList = new ArrayList<>(); + private final List toolTipList = new ArrayList<>(); /** * Creates new form DataSourcePanel @@ -52,19 +54,19 @@ public class DataSourcePanel extends javax.swing.JPanel { public DataSourcePanel() { initComponents(); setComponentsEnabled(); - this.dataSourceList.addListSelectionListener((ListSelectionEvent e) -> { + this.dataSourceList.addListSelectionListener((ListSelectionEvent evt) -> { firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null); }); this.dataSourceList.addMouseMotionListener(new MouseMotionListener() { @Override - public void mouseDragged(MouseEvent e) { + public void mouseDragged(MouseEvent evt) { } @Override - public void mouseMoved(MouseEvent e) { - JList DsList = (JList) e.getSource(); - int index = DsList.locationToIndex(e.getPoint()); + public void mouseMoved(MouseEvent evt) { + JList DsList = (JList) evt.getSource(); + int index = DsList.locationToIndex(evt.getPoint()); if (index > -1) { DsList.setToolTipText(toolTipList.get(index)); } @@ -72,29 +74,38 @@ public class DataSourcePanel extends javax.swing.JPanel { }); } + /** + * Get dataSourceMap with object id and data source display name. Add the data source full name to toolTipList + * + * @return The list of data source name + */ private List getDataSourceArray() { + List dataSourceList = new ArrayList<>(); try { - Case currentCase = Case.getOpenCase(); + Case currentCase = Case.getCurrentCaseThrows(); SleuthkitCase tskDb = currentCase.getSleuthkitCase(); - getLoadLogicalSources(tskDb); - getLoadImageSources(tskDb); + List dataSources = tskDb.getDataSources(); + Collections.sort(dataSources, (DataSource ds1, DataSource ds2) -> ds1.getName().compareTo(ds2.getName())); + for (DataSource ds : dataSources) { + String dsName = ds.getName(); + File dataSourceFullName = new File(dsName); + String displayName = dataSourceFullName.getName(); + dataSourceMap.put(ds.getId(), displayName); + toolTipList.add(dsName); + dataSourceList.add(displayName); + } } catch (NoCurrentCaseException ex) { logger.log(Level.SEVERE, "Unable to get current open case.", ex); - } catch (TskCoreException | SQLException ex) { + } catch (TskCoreException ex) { logger.log(Level.SEVERE, "Failed to get data source info from database.", ex); } - - List dataSourcesList = new ArrayList<>(dataSourceMap.values()); - Collections.sort(dataSourcesList, (String dsName1, String dsName2) -> dsName1.compareTo(dsName2)); - List dataSourceDisplayNames = new ArrayList<>(); - for (String dataSource : dataSourcesList) { - File dataSourceFullName = new File(dataSource); - dataSourceDisplayNames.add(dataSourceFullName.getName()); - toolTipList.add(dataSourceFullName.getParent()); - } - return dataSourceDisplayNames; + return dataSourceList; } + /** + * Get a set of data source object ids that are selected. + * @return A set of selected object ids. + */ Set getDataSourcesSelected() { Set dataSourceObjIdSet = new HashSet<>(); for (Long key : dataSourceMap.keySet()) { @@ -108,14 +119,21 @@ public class DataSourcePanel extends javax.swing.JPanel { return dataSourceObjIdSet; } + /** + * Is dataSourceCheckBox selected + * @return true if the dataSoureCheckBox is selected + */ boolean isSelected() { return this.dataSourceCheckBox.isSelected(); } + /** + * Enable the dataSourceList and dataSourceNoteLable if the dataSourceCheckBox is checked. + */ void setComponentsEnabled() { boolean enabled = this.isSelected(); this.dataSourceList.setEnabled(enabled); - this.jLabel.setEnabled(enabled); + this.dataSourceNoteLable.setEnabled(enabled); } /** @@ -130,7 +148,7 @@ public class DataSourcePanel extends javax.swing.JPanel { jScrollPane1 = new javax.swing.JScrollPane(); dataSourceList = new javax.swing.JList<>(); dataSourceCheckBox = new javax.swing.JCheckBox(); - jLabel = new javax.swing.JLabel(); + dataSourceNoteLable = new javax.swing.JLabel(); setMinimumSize(new java.awt.Dimension(150, 150)); setPreferredSize(new java.awt.Dimension(100, 100)); @@ -138,7 +156,7 @@ public class DataSourcePanel extends javax.swing.JPanel { dataSourceList.setModel(new javax.swing.AbstractListModel() { List strings = getDataSourceArray(); public int getSize() { return strings.size(); } - public String getElementAt(int i) { return strings.get(i); } + public String getElementAt(int idx) { return strings.get(idx); } }); dataSourceList.setMinimumSize(new java.awt.Dimension(0, 200)); jScrollPane1.setViewportView(dataSourceList); @@ -150,8 +168,8 @@ public class DataSourcePanel extends javax.swing.JPanel { } }); - jLabel.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N - org.openide.awt.Mnemonics.setLocalizedText(jLabel, org.openide.util.NbBundle.getMessage(DataSourcePanel.class, "DataSourcePanel.jLabel.text")); // NOI18N + dataSourceNoteLable.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(dataSourceNoteLable, org.openide.util.NbBundle.getMessage(DataSourcePanel.class, "DataSourcePanel.dataSourceNoteLable.text")); // NOI18N javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); @@ -165,7 +183,7 @@ public class DataSourcePanel extends javax.swing.JPanel { .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() - .addComponent(jLabel) + .addComponent(dataSourceNoteLable) .addGap(0, 0, Short.MAX_VALUE))) .addContainerGap()) ); @@ -176,7 +194,7 @@ public class DataSourcePanel extends javax.swing.JPanel { .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 95, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jLabel) + .addComponent(dataSourceNoteLable) .addContainerGap()) ); @@ -189,41 +207,10 @@ public class DataSourcePanel extends javax.swing.JPanel { this.dataSourceList.setSelectedIndices(new int[0]); }//GEN-LAST:event_dataSourceCheckBoxActionPerformed - private void getLoadLogicalSources(SleuthkitCase tskDb) throws TskCoreException, SQLException { - final String SELECT_DATA_SOURCES_LOGICAL = "select obj_id, name from tsk_files where obj_id in (SELECT obj_id FROM tsk_objects WHERE obj_id in (select obj_id from data_source_info)) order by name"; - - try ( - SleuthkitCase.CaseDbQuery query = tskDb.executeQuery(SELECT_DATA_SOURCES_LOGICAL); - ResultSet resultSet = query.getResultSet()) { - while (resultSet.next()) { - Long objectId = resultSet.getLong("obj_id"); - String dataSourceName = resultSet.getString("name"); - dataSourceMap.put(objectId, dataSourceName); - toolTipList.add(dataSourceName); - } - } - } - - private void getLoadImageSources(SleuthkitCase tskDb) throws SQLException, TskCoreException { - final String SELECT_DATA_SOURCES_IMAGE = "select obj_id, name from tsk_image_names where obj_id in (SELECT obj_id FROM tsk_objects WHERE obj_id in (select obj_id from data_source_info)) order by name"; - try ( - SleuthkitCase.CaseDbQuery query = tskDb.executeQuery(SELECT_DATA_SOURCES_IMAGE); - ResultSet resultSet = query.getResultSet()) { - - while (resultSet.next()) { - Long objectId = resultSet.getLong("obj_id"); - String dataSourceName = resultSet.getString("name"); - File image = new File(dataSourceName); - dataSourceMap.put(objectId, image.getName()); - toolTipList.add(dataSourceName); - } - } - } - // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JCheckBox dataSourceCheckBox; private javax.swing.JList dataSourceList; - private javax.swing.JLabel jLabel; + private javax.swing.JLabel dataSourceNoteLable; private javax.swing.JScrollPane jScrollPane1; // End of variables declaration//GEN-END:variables }