From 96fb0438c7429013fa83cf12a9c71bec7a1da765 Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Mon, 23 Jan 2017 16:45:48 -0500 Subject: [PATCH] 2197 added duplicate profile name detection --- ...ProfileList.java => IngestProfileMap.java} | 35 ++++++++----------- .../autopsy/ingest/ProfilePanel.java | 7 +++- .../autopsy/ingest/ProfileSettingsPanel.java | 21 ++++++++--- 3 files changed, 36 insertions(+), 27 deletions(-) rename Core/src/org/sleuthkit/autopsy/ingest/{IngestProfileList.java => IngestProfileMap.java} (93%) diff --git a/Core/src/org/sleuthkit/autopsy/ingest/IngestProfileList.java b/Core/src/org/sleuthkit/autopsy/ingest/IngestProfileMap.java similarity index 93% rename from Core/src/org/sleuthkit/autopsy/ingest/IngestProfileList.java rename to Core/src/org/sleuthkit/autopsy/ingest/IngestProfileMap.java index 09d6d11fdc..c371534a0b 100644 --- a/Core/src/org/sleuthkit/autopsy/ingest/IngestProfileList.java +++ b/Core/src/org/sleuthkit/autopsy/ingest/IngestProfileMap.java @@ -22,29 +22,33 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; -import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; -import java.util.List; +import java.util.TreeMap; import org.apache.commons.io.FileUtils; import org.openide.util.Exceptions; import org.sleuthkit.autopsy.coreutils.ModuleSettings; import org.sleuthkit.autopsy.coreutils.PlatformUtil; -class IngestProfileList { +class IngestProfileMap { private static final String PROFILE_FOLDER = "Profiles"; private static final String PROFILE_NAME_KEY = "Profile_Name"; private static final String PROFILE_DESC_KEY = "Profile_Description"; private static final String PROFILE_FILTER_KEY = "Profile_Filter"; - private List profileList = null; + private TreeMap profileMap = null; private static final Object PROFILE_LOCK = new Object(); - List getIngestProfileList() { - if (profileList == null) { + /** + * Gets the collection of profiles which currently exist. + * + * @return profileList + */ + TreeMap getIngestProfileMap() { + if (profileMap == null) { loadProfileList(); } - return profileList; + return profileMap; } /** @@ -55,17 +59,15 @@ class IngestProfileList { File dir = Paths.get(PlatformUtil.getUserConfigDirectory(), PROFILE_FOLDER).toFile(); File[] directoryListing = dir.listFiles(); + profileMap = new TreeMap<>(); if (directoryListing != null) { - profileList = new ArrayList<>(); for (File child : directoryListing) { String name = child.getName().split("\\.")[0]; String context = PROFILE_FOLDER + File.separator + name; String desc = ModuleSettings.getConfigSetting(context, PROFILE_DESC_KEY); String fileIngestFilter = ModuleSettings.getConfigSetting(context, PROFILE_FILTER_KEY); - profileList.add(new IngestProfile(name, desc, fileIngestFilter)); + profileMap.put(name, new IngestProfile(name, desc, fileIngestFilter)); } - } else { - profileList = Collections.emptyList(); } } } @@ -77,21 +79,12 @@ class IngestProfileList { readFilesFromDirectory(); } - /** - * Gets the list of profiles which currently exist. - * - * @return profileList - */ - List getProfileList() { - return this.profileList; - } - /** * Saves the list of profiles which currently exist to disk. */ void saveProfileList() { //save last used profile - for (IngestProfile profile : getIngestProfileList()) { + for (IngestProfile profile : getIngestProfileMap().values()) { IngestProfile.saveProfile(profile); } } diff --git a/Core/src/org/sleuthkit/autopsy/ingest/ProfilePanel.java b/Core/src/org/sleuthkit/autopsy/ingest/ProfilePanel.java index fc6c912480..b0d4d69811 100644 --- a/Core/src/org/sleuthkit/autopsy/ingest/ProfilePanel.java +++ b/Core/src/org/sleuthkit/autopsy/ingest/ProfilePanel.java @@ -19,10 +19,11 @@ package org.sleuthkit.autopsy.ingest; import java.beans.PropertyChangeListener; +import java.util.TreeMap; import org.openide.DialogDisplayer; import org.openide.NotifyDescriptor; import org.openide.util.NbBundle; -import org.sleuthkit.autopsy.ingest.IngestProfileList.IngestProfile; +import org.sleuthkit.autopsy.ingest.IngestProfileMap.IngestProfile; /** * Panel to display options for profile creation. @@ -60,6 +61,9 @@ public class ProfilePanel extends IngestModuleGlobalSettingsPanel { jPanel1.add(ingestSettingsPanel, 0); } + String getProfileName(){ + return profileNameField.getText(); + } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always @@ -183,6 +187,7 @@ public class ProfilePanel extends IngestModuleGlobalSettingsPanel { DialogDisplayer.getDefault().notify(notifyDesc); return false; } + return true; } } diff --git a/Core/src/org/sleuthkit/autopsy/ingest/ProfileSettingsPanel.java b/Core/src/org/sleuthkit/autopsy/ingest/ProfileSettingsPanel.java index a7b3f9c162..6a8d5b2cc5 100644 --- a/Core/src/org/sleuthkit/autopsy/ingest/ProfileSettingsPanel.java +++ b/Core/src/org/sleuthkit/autopsy/ingest/ProfileSettingsPanel.java @@ -19,6 +19,7 @@ package org.sleuthkit.autopsy.ingest; import java.util.Map; +import java.util.TreeMap; import javax.swing.DefaultListModel; import javax.swing.JOptionPane; import javax.swing.event.ListSelectionEvent; @@ -26,7 +27,8 @@ import javax.swing.event.ListSelectionListener; import org.netbeans.spi.options.OptionsPanelController; import org.openide.util.NbBundle; import org.sleuthkit.autopsy.corecomponents.OptionsPanel; -import org.sleuthkit.autopsy.ingest.IngestProfileList.IngestProfile; +import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil; +import org.sleuthkit.autopsy.ingest.IngestProfileMap.IngestProfile; import org.sleuthkit.autopsy.modules.interestingitems.FilesSet; import org.sleuthkit.autopsy.modules.interestingitems.FilesSetsManager; @@ -41,7 +43,8 @@ class ProfileSettingsPanel extends IngestModuleGlobalSettingsPanel implements Op "ProfileSettingsPanel.newProfileButton.text=New Profile", "ProfileSettingsPanel.editProfileButton.text=Edit Profile", "ProfileSettingsPanel.deleteProfileButton.text=Delete Profile", - "ProfileSettingsPanel.messages.filterLoadFailed=Failed to load file ingest filter" + "ProfileSettingsPanel.messages.filterLoadFailed=Failed to load file ingest filter", + "ProfileSettingsPanel.doFileSetsDialog.duplicateProfile.text=Profile with name {0} already exists." }) private final DefaultListModel profilesListModel = new DefaultListModel<>(); @@ -311,6 +314,15 @@ class ProfileSettingsPanel extends IngestModuleGlobalSettingsPanel implements Op option = JOptionPane.showConfirmDialog(null, panel, Bundle.ProfileSettingsPanel_title(), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); } while (option == JOptionPane.OK_OPTION && !panel.isValidDefinition()); + TreeMap profileMap = new IngestProfileMap().getIngestProfileMap(); + + if (profileMap.containsKey(panel.getProfileName()) && selectedProfile == null) { + MessageNotifyUtil.Message.error(NbBundle.getMessage(this.getClass(), + "ProfileSettingsPanel.doFileSetsDialog.duplicateProfile.text", + panel.getProfileName())); + return; + } + if (option == JOptionPane.OK_OPTION) { panel.saveSettings(); load(); @@ -335,9 +347,8 @@ class ProfileSettingsPanel extends IngestModuleGlobalSettingsPanel implements Op public void load() { int currentIndex = profileList.getSelectedIndex(); profilesListModel.clear(); - IngestProfileList iList = new IngestProfileList(); - iList.loadProfileList(); - for (IngestProfile profile : iList.getProfileList()) { + IngestProfileMap profileMap = new IngestProfileMap(); + for (IngestProfile profile : profileMap.getIngestProfileMap().values()) { profilesListModel.addElement(profile); } if (newProfileButton.isEnabled()) {