diff --git a/Core/src/org/sleuthkit/autopsy/filesearch/Bundle.properties b/Core/src/org/sleuthkit/autopsy/filesearch/Bundle.properties index ea78d740c9..99c61a24ca 100644 --- a/Core/src/org/sleuthkit/autopsy/filesearch/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/filesearch/Bundle.properties @@ -47,6 +47,7 @@ FileSearchPanel.search.results.msg=File Search\: {0} matches found FileSearchPanel.search.results.details=Large number of matches may impact performance on some operations FileSearchPanel.search.exception.noFilterSelected.msg=At least one filter must be selected. FileSearchPanel.search.validationErr.msg=Validation Error\: {0} +FileSearchPanel.emptyWhereClause.text=Invalid options, nothing to show. KnownStatusSearchFilter.noneSelectedMsg.text=At least one known status must be selected\! NameSearchFilter.emptyNameMsg.text=Must enter something for name search. SearchNode.getName.text=Search Result diff --git a/Core/src/org/sleuthkit/autopsy/filesearch/DateSearchFilter.java b/Core/src/org/sleuthkit/autopsy/filesearch/DateSearchFilter.java index 7939c0956d..f1df56f8ac 100644 --- a/Core/src/org/sleuthkit/autopsy/filesearch/DateSearchFilter.java +++ b/Core/src/org/sleuthkit/autopsy/filesearch/DateSearchFilter.java @@ -72,9 +72,9 @@ class DateSearchFilter extends AbstractFileSearchFilter { @Override public String getPredicate() throws FilterValidationException { - String addQuery = "1"; + String query = "NULL"; DateSearchPanel panel = this.getComponent(); - + // first, get the selected timeZone from the dropdown list String tz = this.getComponent().getTimeZoneComboBox().getSelectedItem().toString(); String tzID = tz.substring(tz.indexOf(" ") + 1); // 1 index after the space is the ID @@ -92,7 +92,7 @@ class DateSearchFilter extends AbstractFileSearchFilter { startDate = Calendar.getInstance(new SimpleTimeZone(0, "GMT")); //NON-NLS startDate.setTime(temp); // convert to GMT } catch (ParseException ex) { - // for now, no need to show the error message to the user her + // for now, no need to show the error message to the user here } if (!startDateValue.equals("")) { if (startDate != null) { @@ -120,6 +120,13 @@ class DateSearchFilter extends AbstractFileSearchFilter { } } + // If they put the dates in backwards, help them out. + if (fromDate > toDate) { + long temp = toDate; + toDate = fromDate; + fromDate = temp; + } + final boolean modifiedChecked = panel.getModifiedCheckBox().isSelected(); final boolean changedChecked = panel.getChangedCheckBox().isSelected(); final boolean accessedChecked = panel.getAccessedCheckBox().isSelected(); @@ -127,30 +134,27 @@ class DateSearchFilter extends AbstractFileSearchFilter { if (modifiedChecked || changedChecked || accessedChecked || createdChecked) { - String subQuery = "0"; - if (modifiedChecked) { - subQuery += " or mtime between " + fromDate + " and " + toDate; //NON-NLS + query += " OR (mtime BETWEEN " + fromDate + " AND " + toDate + ")"; //NON-NLS } if (changedChecked) { - subQuery += " or ctime between " + fromDate + " and " + toDate; //NON-NLS + query += " OR (ctime BETWEEN " + fromDate + " AND " + toDate + ")"; //NON-NLS } if (accessedChecked) { - subQuery += " or atime between " + fromDate + " and " + toDate; //NON-NLS + query += " OR (atime BETWEEN " + fromDate + " AND " + toDate + ")"; //NON-NLS } if (createdChecked) { - subQuery += " or crtime between " + fromDate + " and " + toDate; //NON-NLS + query += " OR (crtime BETWEEN " + fromDate + " AND " + toDate + ")"; //NON-NLS } - addQuery += " and (" + subQuery + ")"; //NON-NLS } else { throw new FilterValidationException(NONE_SELECTED_MESSAGE); } - return addQuery; + return query; } diff --git a/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchPanel.java b/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchPanel.java index e2ae8bb6c2..a68a0a1903 100644 --- a/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchPanel.java +++ b/Core/src/org/sleuthkit/autopsy/filesearch/FileSearchPanel.java @@ -63,7 +63,8 @@ import org.sleuthkit.datamodel.TskCoreException; private List filterAreas = new ArrayList(); private JButton searchButton; private static int resultWindowCount = 0; //keep track of result windows so they get unique names - + private static final String EMPTY_WHERE_CLAUSE = NbBundle.getMessage(DateSearchFilter.class, "FileSearchPanel.emptyWhereClause.text"); + /** * Creates new form FileSearchPanel */ @@ -202,17 +203,29 @@ import org.sleuthkit.datamodel.TskCoreException; * org.sleuthkit.autopsy.filesearch.FileSearchFilter.FilterValidationException * if an enabled filter is in an invalid state */ - private String getQuery() throws FilterValidationException { + private String getQuery() throws FilterValidationException { - //String query = "SELECT " + tempQuery + " FROM tsk_files WHERE 1"; - String query = " 1"; + //String query = "SELECT " + tempQuery + " FROM tsk_files WHERE "; + String query = ""; + int i=0; + for (FileSearchFilter f : this.getEnabledFilters()) { + String result = f.getPredicate(); + if (!result.isEmpty()) { + if(i>0) { + query += " AND (" + result + ")"; //NON-NLS + } + else { + query += " (" + result + ")"; //NON-NLS + } + ++i; + } + } - for (FileSearchFilter f : this.getEnabledFilters()) { - query += " AND (" + f.getPredicate() + ")"; //NON-NLS - } - - return query; - } + if (query.isEmpty()) { + throw new FilterValidationException(EMPTY_WHERE_CLAUSE); + } + return query; + } private Collection getFilters() { Collection filters = new ArrayList(); diff --git a/Core/src/org/sleuthkit/autopsy/filesearch/KnownStatusSearchFilter.java b/Core/src/org/sleuthkit/autopsy/filesearch/KnownStatusSearchFilter.java index 247faa87db..5565553ebc 100644 --- a/Core/src/org/sleuthkit/autopsy/filesearch/KnownStatusSearchFilter.java +++ b/Core/src/org/sleuthkit/autopsy/filesearch/KnownStatusSearchFilter.java @@ -56,15 +56,15 @@ class KnownStatusSearchFilter extends AbstractFileSearchFilter