From e3887088c8ee7b8f9373f05ca910ce8bba5e4872 Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Fri, 28 Jun 2019 12:50:43 -0400 Subject: [PATCH 1/5] 5239 prevent duplicate named rules being created --- .../configuration/Bundle.properties-MERGED | 3 ++ .../configuration/ConfigVisualPanel2.java | 33 +++++++++++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/logicalimager/configuration/Bundle.properties-MERGED b/Core/src/org/sleuthkit/autopsy/logicalimager/configuration/Bundle.properties-MERGED index 7ef61a8452..13c4a53268 100644 --- a/Core/src/org/sleuthkit/autopsy/logicalimager/configuration/Bundle.properties-MERGED +++ b/Core/src/org/sleuthkit/autopsy/logicalimager/configuration/Bundle.properties-MERGED @@ -37,6 +37,9 @@ ConfigVisualPanel2.editConfiguration=Configure imager ConfigVisualPanel2.editRuleError=Edit rule error ConfigVisualPanel2.editRuleSet=Edit Rule ConfigVisualPanel2.newRule.name=New Rule +# {0} - ruleName +ConfigVisualPanel2.newRuleError.duplicateName=A rule with named "{0}" already exists please choose a different name +ConfigVisualPanel2.newRuleError.title=New rule error ConfigVisualPanel2.ok=OK ConfigVisualPanel2.rulesTable.columnModel.title0=Rule Name ConfigVisualPanel2.rulesTable.columnModel.title1=Description diff --git a/Core/src/org/sleuthkit/autopsy/logicalimager/configuration/ConfigVisualPanel2.java b/Core/src/org/sleuthkit/autopsy/logicalimager/configuration/ConfigVisualPanel2.java index 5b2468efdc..c16feb8dbf 100644 --- a/Core/src/org/sleuthkit/autopsy/logicalimager/configuration/ConfigVisualPanel2.java +++ b/Core/src/org/sleuthkit/autopsy/logicalimager/configuration/ConfigVisualPanel2.java @@ -442,7 +442,10 @@ final class ConfigVisualPanel2 extends JPanel { } }//GEN-LAST:event_editRuleButtonActionPerformed - @Messages({"ConfigVisualPanel2.newRule.name=New Rule"}) + @Messages({"ConfigVisualPanel2.newRule.name=New Rule", + "ConfigVisualPanel2.newRuleError.title=New rule error", + "# {0} - ruleName", + "ConfigVisualPanel2.newRuleError.duplicateName=A rule with named \"{0}\" already exists please choose a different name"}) private void newRuleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newRuleButtonActionPerformed NewRulePanel panel; panel = new NewRulePanel(okButton, cancelButton); @@ -455,14 +458,22 @@ final class ConfigVisualPanel2 extends JPanel { null, new Object[]{okButton, cancelButton}, okButton); if (option == JOptionPane.OK_OPTION) { try { - // Save the new rule + ImmutablePair ruleMap = panel.toRule(); + if (ruleExists(ruleMap)) { + JOptionPane.showMessageDialog(this, + Bundle.ConfigVisualPanel2_newRuleError_duplicateName(ruleMap.getKey()), + Bundle.ConfigVisualPanel2_newRuleError_title(), + JOptionPane.ERROR_MESSAGE); + continue; + } + // Save the new rule appendRow(ruleMap); break; } catch (IOException | NumberFormatException ex) { JOptionPane.showMessageDialog(this, ex.getMessage(), - "New rule error", + Bundle.ConfigVisualPanel2_newRuleError_title(), JOptionPane.ERROR_MESSAGE); // let user fix the error } @@ -767,6 +778,22 @@ final class ConfigVisualPanel2 extends JPanel { updatePanel(configFilename, config, ruleMap.getKey()); } + /** + * Check if a rule with the same name as this rule already exists + * + * @param ruleMap the rule to check the name of + * + * @return true if it exists, false otherwise + */ + private boolean ruleExists(ImmutablePair ruleMap) { + for (LogicalImagerRule rule : getRuleSetFromCurrentConfig().getRules()) { + if (rule.getName().equals(ruleMap.getKey())) { + return true; + } + } + return false; + } + private void appendRow(ImmutablePair ruleMap) { getRuleSetFromCurrentConfig().getRules().add(ruleMap.getValue()); updatePanel(configFilename, config, ruleMap.getKey()); From c57299480e70c2508a97c066a150a0334235f41b Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Fri, 28 Jun 2019 13:43:59 -0400 Subject: [PATCH 2/5] 5239 allow editing of rule name --- .../logicalimager/configuration/ConfigVisualPanel2.java | 9 +++++++++ .../configuration/EditFullPathsRulePanel.java | 4 ---- .../configuration/EditNonFullPathsRulePanel.java | 3 --- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/logicalimager/configuration/ConfigVisualPanel2.java b/Core/src/org/sleuthkit/autopsy/logicalimager/configuration/ConfigVisualPanel2.java index c16feb8dbf..dd666e4e39 100644 --- a/Core/src/org/sleuthkit/autopsy/logicalimager/configuration/ConfigVisualPanel2.java +++ b/Core/src/org/sleuthkit/autopsy/logicalimager/configuration/ConfigVisualPanel2.java @@ -426,6 +426,15 @@ final class ConfigVisualPanel2 extends JPanel { if (option == JOptionPane.OK_OPTION) { try { ImmutablePair ruleMap = editPanel.toRule(); + if (!ruleName.equals(ruleMap.getKey()) && ruleExists(ruleMap)) { + if (ruleExists(ruleMap)) { + JOptionPane.showMessageDialog(this, + Bundle.ConfigVisualPanel2_newRuleError_duplicateName(ruleMap.getKey()), + Bundle.ConfigVisualPanel2_editRuleError(), + JOptionPane.ERROR_MESSAGE); + continue; + } + } updateRow(row, ruleMap); break; } catch (IOException | NumberFormatException ex) { diff --git a/Core/src/org/sleuthkit/autopsy/logicalimager/configuration/EditFullPathsRulePanel.java b/Core/src/org/sleuthkit/autopsy/logicalimager/configuration/EditFullPathsRulePanel.java index af65e8eacb..c40d05cffc 100644 --- a/Core/src/org/sleuthkit/autopsy/logicalimager/configuration/EditFullPathsRulePanel.java +++ b/Core/src/org/sleuthkit/autopsy/logicalimager/configuration/EditFullPathsRulePanel.java @@ -54,10 +54,6 @@ final class EditFullPathsRulePanel extends javax.swing.JPanel { EditFullPathsRulePanel(JButton okButton, JButton cancelButton, String ruleName, LogicalImagerRule rule, boolean editing) { initComponents(); - if (editing) { - ruleNameTextField.setEnabled(!editing); - } - this.setRule(ruleName, rule); this.setButtons(okButton, cancelButton); diff --git a/Core/src/org/sleuthkit/autopsy/logicalimager/configuration/EditNonFullPathsRulePanel.java b/Core/src/org/sleuthkit/autopsy/logicalimager/configuration/EditNonFullPathsRulePanel.java index a48db9b2c4..8628cafa67 100644 --- a/Core/src/org/sleuthkit/autopsy/logicalimager/configuration/EditNonFullPathsRulePanel.java +++ b/Core/src/org/sleuthkit/autopsy/logicalimager/configuration/EditNonFullPathsRulePanel.java @@ -71,9 +71,6 @@ final class EditNonFullPathsRulePanel extends javax.swing.JPanel { }) EditNonFullPathsRulePanel(JButton okButton, JButton cancelButton, String ruleName, LogicalImagerRule rule, boolean editing) { initComponents(); - if (editing) { - ruleNameTextField.setEnabled(!editing); - } this.setRule(ruleName, rule); this.setButtons(okButton, cancelButton); From 160f145d8b26e99a1f9b1725eebcb986b864d0cd Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Fri, 28 Jun 2019 16:49:24 -0400 Subject: [PATCH 3/5] 5239 fix duplicate condition --- .../configuration/ConfigVisualPanel2.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/logicalimager/configuration/ConfigVisualPanel2.java b/Core/src/org/sleuthkit/autopsy/logicalimager/configuration/ConfigVisualPanel2.java index dd666e4e39..d45fcc99cd 100644 --- a/Core/src/org/sleuthkit/autopsy/logicalimager/configuration/ConfigVisualPanel2.java +++ b/Core/src/org/sleuthkit/autopsy/logicalimager/configuration/ConfigVisualPanel2.java @@ -427,13 +427,11 @@ final class ConfigVisualPanel2 extends JPanel { try { ImmutablePair ruleMap = editPanel.toRule(); if (!ruleName.equals(ruleMap.getKey()) && ruleExists(ruleMap)) { - if (ruleExists(ruleMap)) { - JOptionPane.showMessageDialog(this, - Bundle.ConfigVisualPanel2_newRuleError_duplicateName(ruleMap.getKey()), - Bundle.ConfigVisualPanel2_editRuleError(), - JOptionPane.ERROR_MESSAGE); - continue; - } + JOptionPane.showMessageDialog(this, + Bundle.ConfigVisualPanel2_newRuleError_duplicateName(ruleMap.getKey()), + Bundle.ConfigVisualPanel2_editRuleError(), + JOptionPane.ERROR_MESSAGE); + continue; } updateRow(row, ruleMap); break; From 78c63c06f7f7c271af3cb09bbdafe64d3b477870 Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Mon, 1 Jul 2019 15:26:57 -0400 Subject: [PATCH 4/5] 5239 adjust duplicate rule message per review comment --- .../autopsy/logicalimager/configuration/ConfigVisualPanel2.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/logicalimager/configuration/ConfigVisualPanel2.java b/Core/src/org/sleuthkit/autopsy/logicalimager/configuration/ConfigVisualPanel2.java index d45fcc99cd..967ed1ff75 100644 --- a/Core/src/org/sleuthkit/autopsy/logicalimager/configuration/ConfigVisualPanel2.java +++ b/Core/src/org/sleuthkit/autopsy/logicalimager/configuration/ConfigVisualPanel2.java @@ -452,7 +452,7 @@ final class ConfigVisualPanel2 extends JPanel { @Messages({"ConfigVisualPanel2.newRule.name=New Rule", "ConfigVisualPanel2.newRuleError.title=New rule error", "# {0} - ruleName", - "ConfigVisualPanel2.newRuleError.duplicateName=A rule with named \"{0}\" already exists please choose a different name"}) + "ConfigVisualPanel2.newRuleError.duplicateName=A rule with name \"{0}\" already exists. Please enter a different rule name"}) private void newRuleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newRuleButtonActionPerformed NewRulePanel panel; panel = new NewRulePanel(okButton, cancelButton); From 36ffb538e8f3f7952c861b1abb2cfb6bf680f31d Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Mon, 1 Jul 2019 15:33:34 -0400 Subject: [PATCH 5/5] 5239 update merged properties file --- .../logicalimager/configuration/Bundle.properties-MERGED | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/logicalimager/configuration/Bundle.properties-MERGED b/Core/src/org/sleuthkit/autopsy/logicalimager/configuration/Bundle.properties-MERGED index 13c4a53268..1006010e6b 100644 --- a/Core/src/org/sleuthkit/autopsy/logicalimager/configuration/Bundle.properties-MERGED +++ b/Core/src/org/sleuthkit/autopsy/logicalimager/configuration/Bundle.properties-MERGED @@ -38,7 +38,7 @@ ConfigVisualPanel2.editRuleError=Edit rule error ConfigVisualPanel2.editRuleSet=Edit Rule ConfigVisualPanel2.newRule.name=New Rule # {0} - ruleName -ConfigVisualPanel2.newRuleError.duplicateName=A rule with named "{0}" already exists please choose a different name +ConfigVisualPanel2.newRuleError.duplicateName=A rule with name "{0}" already exists. Please enter a different rule name ConfigVisualPanel2.newRuleError.title=New rule error ConfigVisualPanel2.ok=OK ConfigVisualPanel2.rulesTable.columnModel.title0=Rule Name