From addb312dc044763b36503f0b521a51a625a26ac7 Mon Sep 17 00:00:00 2001 From: Brian Sweeney Date: Tue, 21 Aug 2018 10:51:31 -0600 Subject: [PATCH] renames and usage or error manager --- .../CommonAttributePanel.java | 46 +++++-- .../commonfilesearch/PanelErrorMessages.java | 34 ------ .../UserInputErrorManager.java | 115 ++++++++++++++++++ 3 files changed, 152 insertions(+), 43 deletions(-) delete mode 100644 Core/src/org/sleuthkit/autopsy/commonfilesearch/PanelErrorMessages.java create mode 100644 Core/src/org/sleuthkit/autopsy/commonfilesearch/UserInputErrorManager.java diff --git a/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonAttributePanel.java b/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonAttributePanel.java index 737d33de7d..016bc0f2ff 100644 --- a/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonAttributePanel.java +++ b/Core/src/org/sleuthkit/autopsy/commonfilesearch/CommonAttributePanel.java @@ -58,6 +58,8 @@ public final class CommonAttributePanel extends javax.swing.JDialog { private static final long serialVersionUID = 1L; private static final Long NO_DATA_SOURCE_SELECTED = -1L; + + private final UserInputErrorManager errorManager; private boolean pictureViewCheckboxState; @@ -88,6 +90,8 @@ public final class CommonAttributePanel extends javax.swing.JDialog { this.disableIntercaseSearch(); this.disablePercentageOptions(); } + + this.errorManager = new UserInputErrorManager(); } private static boolean isEamDbAvailable() { @@ -621,20 +625,20 @@ public final class CommonAttributePanel extends javax.swing.JDialog { }//GEN-LAST:event_cancelButtonActionPerformed private void allFileCategoriesRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_allFileCategoriesRadioButtonActionPerformed - this.manageCheckBoxState(); - this.toggleErrorTextAndSearchBox(); + this.manageFileTypeCheckBoxState(); + this.updateErrorTextAndSearchBox(); }//GEN-LAST:event_allFileCategoriesRadioButtonActionPerformed private void selectedFileCategoriesButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectedFileCategoriesButtonActionPerformed - this.manageCheckBoxState(); + this.manageFileTypeCheckBoxState(); }//GEN-LAST:event_selectedFileCategoriesButtonActionPerformed private void pictureVideoCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pictureVideoCheckboxActionPerformed - this.toggleErrorTextAndSearchBox(); + this.updateErrorTextAndSearchBox(); }//GEN-LAST:event_pictureVideoCheckboxActionPerformed private void documentsCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_documentsCheckboxActionPerformed - this.toggleErrorTextAndSearchBox(); + this.updateErrorTextAndSearchBox(); }//GEN-LAST:event_documentsCheckboxActionPerformed private void intraCaseRadioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_intraCaseRadioActionPerformed @@ -669,12 +673,14 @@ public final class CommonAttributePanel extends javax.swing.JDialog { } else { this.percentageThreshold.setEnabled(false); } + + this.handleFrequencyPercentageCriteriaMet(); }//GEN-LAST:event_percentageThresholdCheckActionPerformed private void percentageThresholdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_percentageThresholdActionPerformed String percentageString = this.percentageThreshold.getText(); - Integer percentage; + Integer percentage = null; try{ percentage = Integer.parseInt(percentageString); @@ -683,6 +689,9 @@ public final class CommonAttributePanel extends javax.swing.JDialog { this.percentageThresholdValue = -1; } + this.percentageThresholdValue = percentage.intValue(); + + this.handleFrequencyPercentageCriteriaMet(); }//GEN-LAST:event_percentageThresholdActionPerformed public void handleInterCaseSearchCriteriaChanged() { @@ -696,7 +705,18 @@ public final class CommonAttributePanel extends javax.swing.JDialog { } } - private void toggleErrorTextAndSearchBox() { + private void updateErrorTextAndSearchBox() { + + if(this.errorManager.anyErrors()){ + this.searchButton.setEnabled(false); + //grab the first error error and show it + this.errorText.setText(this.errorManager.getErrors().get(0)); + this.errorText.setVisible(true); + } else { + this.searchButton.setEnabled(true); + this.errorText.setVisible(false); + } + if (!this.pictureVideoCheckbox.isSelected() && !this.documentsCheckbox.isSelected() && !this.allFileCategoriesRadioButton.isSelected()) { this.searchButton.setEnabled(false); this.errorText.setVisible(true); @@ -706,7 +726,7 @@ public final class CommonAttributePanel extends javax.swing.JDialog { } } - private void manageCheckBoxState() { + private void manageFileTypeCheckBoxState() { this.pictureViewCheckboxState = this.pictureVideoCheckbox.isSelected(); this.documentsCheckboxState = this.documentsCheckbox.isSelected(); @@ -724,7 +744,7 @@ public final class CommonAttributePanel extends javax.swing.JDialog { this.pictureVideoCheckbox.setEnabled(true); this.documentsCheckbox.setEnabled(true); - this.toggleErrorTextAndSearchBox(); + this.updateErrorTextAndSearchBox(); } } @@ -789,4 +809,12 @@ public final class CommonAttributePanel extends javax.swing.JDialog { this.percentageThresholdCheck.setEnabled(false); this.percentageThresholdCheck.setSelected(false); } + + private void handleFrequencyPercentageCriteriaMet() { + if(this.percentageThresholdValue > 0 && this.percentageThresholdValue<= 100){ + this.errorManager.setError(UserInputErrorManager.FREQUENCY_PERCENTAGE_OUT_OF_RANGE_KEY, false); + } else { + this.errorManager.setError(UserInputErrorManager.FREQUENCY_PERCENTAGE_OUT_OF_RANGE_KEY, true); + } + } } diff --git a/Core/src/org/sleuthkit/autopsy/commonfilesearch/PanelErrorMessages.java b/Core/src/org/sleuthkit/autopsy/commonfilesearch/PanelErrorMessages.java deleted file mode 100644 index fb23b9da14..0000000000 --- a/Core/src/org/sleuthkit/autopsy/commonfilesearch/PanelErrorMessages.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * - * Autopsy Forensic Browser - * - * Copyright 2018 Basis Technology Corp. - * Contact: carrier sleuthkit org - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.sleuthkit.autopsy.commonfilesearch; - -/** - * - * @author bsweeney - */ -class PanelErrorMessages { - - private class ErrorMessage{ - int id; - String message; - boolean showMessage; - } - -} diff --git a/Core/src/org/sleuthkit/autopsy/commonfilesearch/UserInputErrorManager.java b/Core/src/org/sleuthkit/autopsy/commonfilesearch/UserInputErrorManager.java new file mode 100644 index 0000000000..7490cb440a --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/commonfilesearch/UserInputErrorManager.java @@ -0,0 +1,115 @@ +/* + * + * Autopsy Forensic Browser + * + * Copyright 2018 Basis Technology Corp. + * Contact: carrier sleuthkit org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.sleuthkit.autopsy.commonfilesearch; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * Manager for present state of errors on the Common Files Search. + */ +class UserInputErrorManager { + + static final int FREQUENCY_PERCENTAGE_OUT_OF_RANGE_KEY = 1; + + private final Map currentErrors; + + UserInputErrorManager (){ + this.currentErrors = new HashMap<>(); + this.currentErrors.put(FREQUENCY_PERCENTAGE_OUT_OF_RANGE_KEY, new ErrorMessage("Frequency percentage must be greater than zero and less than or equal to 100.")); + } + + /** + * Toggle the given error message on, or off + * @param errorId the error to toggle + * @param errorState true for on, false for off + */ + void setError(int errorId, boolean errorState){ + if(this.currentErrors.containsKey(errorId)){ + this.currentErrors.get(errorId).setStatus(errorState); + } else { + throw new IllegalArgumentException(String.format("The given errorId is not mapped to an ErrorMessage: %s.", errorId)); + } + } + + /** + * Are any user settings presently in an error state? + * @return true for yes, else false + */ + boolean anyErrors(){ + return this.currentErrors.values().stream().anyMatch(errorMessage -> errorMessage.getStatus() == true); + } + + /** + * Get a list of distinct string messages describing the various error states. + */ + List getErrors(){ + return this.currentErrors.values().stream() + .filter(errorMessage -> errorMessage.getStatus() == true) + .map(ErrorMessage::getMessage) + .collect(Collectors.toList()); + } + + /** + * Represents an error message for the CommonFilesSearch panel, it's + * uniqueId, and it's status. + */ + private class ErrorMessage { + + private final String message; + private boolean status; + + /** + * Create a message with a unique uniqueId. Default status is false (off). + * @param uniqueId unique uniqueId + * @param message message to display + */ + ErrorMessage(String message){ + this.message = message; + this.status = false; + } + + /** + * Update the status of this message + * @param status + */ + void setStatus(boolean status){ + this.status = status; + } + + /** + * Return the message + * @return + */ + String getMessage(){ + return this.message; + } + + /** + * Return the status (true for error status, false for no error) + * @return + */ + boolean getStatus(){ + return this.status; + } + } +}