Autopsy  4.19.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
HashDbImportDatabaseDialog.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2013-2020 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.modules.hashdatabase;
20 
21 import java.io.File;
22 import java.io.IOException;
23 import java.nio.file.Paths;
24 import java.util.List;
25 import java.util.logging.Level;
26 import javax.swing.JFileChooser;
27 import javax.swing.JFrame;
28 import javax.swing.JOptionPane;
29 import javax.swing.filechooser.FileNameExtensionFilter;
30 import org.apache.commons.io.FileUtils;
31 import org.apache.commons.io.FilenameUtils;
32 import org.openide.util.NbBundle;
33 import org.openide.windows.WindowManager;
46 
52 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
53 final class HashDbImportDatabaseDialog extends javax.swing.JDialog {
54 
55  private final JFileChooser fileChooser;
56  private String selectedFilePath = "";
57  private HashDb selectedHashDb = null;
58  private final static String LAST_FILE_PATH_KEY = "HashDbImport_Path";
59  private CentralRepoOrganization selectedOrg = null;
60  private List<CentralRepoOrganization> orgs = null;
61 
67  HashDbImportDatabaseDialog() {
68  super((JFrame) WindowManager.getDefault().getMainWindow(),
69  NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.importHashDbMsg"),
70  true);
71  this.fileChooser = new JFileChooser();
72  initComponents();
73  enableComponents();
74  initFileChooser();
75  display();
76  }
77 
83  HashDb getHashDatabase() {
84  return selectedHashDb;
85  }
86 
87  private void initFileChooser() {
88  fileChooser.setDragEnabled(false);
89  fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
90  String[] EXTENSION = new String[]{"txt", "kdb", "idx", "hash", "Hash", "hsh"}; //NON-NLS
91  FileNameExtensionFilter filter = new FileNameExtensionFilter(
92  NbBundle.getMessage(this.getClass(), "HashDbImportDatabaseDialog.fileNameExtFilter.text"), EXTENSION);
93  fileChooser.setFileFilter(filter);
94  fileChooser.setMultiSelectionEnabled(false);
95  }
96 
97  private void display() {
98  setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
99  setVisible(true);
100  }
101 
102  private static String shortenPath(String path) {
103  String shortenedPath = path;
104  if (shortenedPath.length() > 50) {
105  shortenedPath = shortenedPath.substring(0, 10 + shortenedPath.substring(10).indexOf(File.separator) + 1) + "..." + shortenedPath.substring((shortenedPath.length() - 20) + shortenedPath.substring(shortenedPath.length() - 20).indexOf(File.separator));
106  }
107  return shortenedPath;
108  }
109 
110  private void enableComponents() {
111 
112  if (!CentralRepository.isEnabled() || !FeatureAccessUtils.canAddHashSetsToCentralRepo()) {
113  centralRepoRadioButton.setEnabled(false);
114  fileTypeRadioButton.setSelected(true);
115  } else {
116  populateCombobox();
117  }
118 
119  boolean isFileType = fileTypeRadioButton.isSelected();
120 
121  // Central repo only
122  lbVersion.setEnabled((!isFileType) && (readOnlyCheckbox.isSelected()));
123  versionTextField.setEnabled((!isFileType) && (readOnlyCheckbox.isSelected()));
124 
125  lbOrg.setEnabled(!isFileType);
126  orgButton.setEnabled(!isFileType);
127  orgComboBox.setEnabled(!isFileType);
128  readOnlyCheckbox.setEnabled(!isFileType);
129  }
130 
131  @NbBundle.Messages({"HashDbImportDatabaseDialog.populateOrgsError.message=Failure loading organizations."})
132  private void populateCombobox() {
133  orgComboBox.removeAllItems();
134  try {
135  CentralRepository dbManager = CentralRepository.getInstance();
136  orgs = dbManager.getOrganizations();
137  orgs.forEach((org) -> {
138  orgComboBox.addItem(org.getName());
139  if (CentralRepoDbUtil.isDefaultOrg(org)) {
140  orgComboBox.setSelectedItem(org.getName());
141  selectedOrg = org;
142  }
143  });
144  if ((selectedOrg == null) && (!orgs.isEmpty())) {
145  selectedOrg = orgs.get(0);
146  }
147  } catch (CentralRepoException ex) {
148  JOptionPane.showMessageDialog(this, Bundle.HashDbImportDatabaseDialog_populateOrgsError_message());
149  Logger.getLogger(ImportCentralRepoDbProgressDialog.class.getName()).log(Level.SEVERE, "Failure loading organizations", ex);
150  }
151  }
152 
158  @SuppressWarnings("unchecked")
159  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
160  private void initComponents() {
161 
162  buttonGroup1 = new javax.swing.ButtonGroup();
163  storageTypeButtonGroup = new javax.swing.ButtonGroup();
164  okButton = new javax.swing.JButton();
165  cancelButton = new javax.swing.JButton();
166  databasePathTextField = new javax.swing.JTextField();
167  openButton = new javax.swing.JButton();
168  knownRadioButton = new javax.swing.JRadioButton();
169  knownBadRadioButton = new javax.swing.JRadioButton();
170  jLabel1 = new javax.swing.JLabel();
171  hashSetNameTextField = new javax.swing.JTextField();
172  jLabel2 = new javax.swing.JLabel();
173  sendIngestMessagesCheckbox = new javax.swing.JCheckBox();
174  jLabel3 = new javax.swing.JLabel();
175  lbVersion = new javax.swing.JLabel();
176  versionTextField = new javax.swing.JTextField();
177  lbOrg = new javax.swing.JLabel();
178  orgComboBox = new javax.swing.JComboBox<>();
179  orgButton = new javax.swing.JButton();
180  readOnlyCheckbox = new javax.swing.JCheckBox();
181  fileTypeRadioButton = new javax.swing.JRadioButton();
182  centralRepoRadioButton = new javax.swing.JRadioButton();
183  jLabel4 = new javax.swing.JLabel();
184  saveInUserConfigFolderCheckbox = new javax.swing.JCheckBox();
185  noChangeRadioButton = new javax.swing.JRadioButton();
186 
187  setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
188 
189  org.openide.awt.Mnemonics.setLocalizedText(okButton, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.okButton.text")); // NOI18N
190  okButton.addActionListener(new java.awt.event.ActionListener() {
191  public void actionPerformed(java.awt.event.ActionEvent evt) {
192  okButtonActionPerformed(evt);
193  }
194  });
195 
196  org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.cancelButton.text")); // NOI18N
197  cancelButton.addActionListener(new java.awt.event.ActionListener() {
198  public void actionPerformed(java.awt.event.ActionEvent evt) {
199  cancelButtonActionPerformed(evt);
200  }
201  });
202 
203  databasePathTextField.setEditable(false);
204  databasePathTextField.setText(org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.databasePathTextField.text")); // NOI18N
205 
206  org.openide.awt.Mnemonics.setLocalizedText(openButton, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.openButton.text")); // NOI18N
207  openButton.addActionListener(new java.awt.event.ActionListener() {
208  public void actionPerformed(java.awt.event.ActionEvent evt) {
209  openButtonActionPerformed(evt);
210  }
211  });
212 
213  buttonGroup1.add(knownRadioButton);
214  org.openide.awt.Mnemonics.setLocalizedText(knownRadioButton, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.knownRadioButton.text")); // NOI18N
215  knownRadioButton.addActionListener(new java.awt.event.ActionListener() {
216  public void actionPerformed(java.awt.event.ActionEvent evt) {
217  knownRadioButtonActionPerformed(evt);
218  }
219  });
220 
221  buttonGroup1.add(knownBadRadioButton);
222  knownBadRadioButton.setSelected(true);
223  org.openide.awt.Mnemonics.setLocalizedText(knownBadRadioButton, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.knownBadRadioButton.text")); // NOI18N
224  knownBadRadioButton.addActionListener(new java.awt.event.ActionListener() {
225  public void actionPerformed(java.awt.event.ActionEvent evt) {
226  knownBadRadioButtonActionPerformed(evt);
227  }
228  });
229 
230  org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.jLabel1.text")); // NOI18N
231 
232  hashSetNameTextField.setText(org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.hashSetNameTextField.text")); // NOI18N
233 
234  org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.jLabel2.text")); // NOI18N
235 
236  sendIngestMessagesCheckbox.setSelected(true);
237  org.openide.awt.Mnemonics.setLocalizedText(sendIngestMessagesCheckbox, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.sendIngestMessagesCheckbox.text")); // NOI18N
238  sendIngestMessagesCheckbox.addActionListener(new java.awt.event.ActionListener() {
239  public void actionPerformed(java.awt.event.ActionEvent evt) {
240  sendIngestMessagesCheckboxActionPerformed(evt);
241  }
242  });
243 
244  org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.jLabel3.text")); // NOI18N
245 
246  org.openide.awt.Mnemonics.setLocalizedText(lbVersion, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.lbVersion.text")); // NOI18N
247 
248  versionTextField.setText(org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.versionTextField.text")); // NOI18N
249 
250  org.openide.awt.Mnemonics.setLocalizedText(lbOrg, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.lbOrg.text")); // NOI18N
251 
252  orgComboBox.addActionListener(new java.awt.event.ActionListener() {
253  public void actionPerformed(java.awt.event.ActionEvent evt) {
254  orgComboBoxActionPerformed(evt);
255  }
256  });
257 
258  org.openide.awt.Mnemonics.setLocalizedText(orgButton, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.orgButton.text")); // NOI18N
259  orgButton.addActionListener(new java.awt.event.ActionListener() {
260  public void actionPerformed(java.awt.event.ActionEvent evt) {
261  orgButtonActionPerformed(evt);
262  }
263  });
264 
265  readOnlyCheckbox.setSelected(true);
266  org.openide.awt.Mnemonics.setLocalizedText(readOnlyCheckbox, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.readOnlyCheckbox.text")); // NOI18N
267  readOnlyCheckbox.addActionListener(new java.awt.event.ActionListener() {
268  public void actionPerformed(java.awt.event.ActionEvent evt) {
269  readOnlyCheckboxActionPerformed(evt);
270  }
271  });
272 
273  storageTypeButtonGroup.add(fileTypeRadioButton);
274  fileTypeRadioButton.setSelected(true);
275  org.openide.awt.Mnemonics.setLocalizedText(fileTypeRadioButton, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.fileTypeRadioButton.text")); // NOI18N
276  fileTypeRadioButton.addActionListener(new java.awt.event.ActionListener() {
277  public void actionPerformed(java.awt.event.ActionEvent evt) {
278  fileTypeRadioButtonActionPerformed(evt);
279  }
280  });
281 
282  storageTypeButtonGroup.add(centralRepoRadioButton);
283  org.openide.awt.Mnemonics.setLocalizedText(centralRepoRadioButton, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.centralRepoRadioButton.text")); // NOI18N
284  centralRepoRadioButton.addActionListener(new java.awt.event.ActionListener() {
285  public void actionPerformed(java.awt.event.ActionEvent evt) {
286  centralRepoRadioButtonActionPerformed(evt);
287  }
288  });
289 
290  org.openide.awt.Mnemonics.setLocalizedText(jLabel4, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.jLabel4.text")); // NOI18N
291 
292  org.openide.awt.Mnemonics.setLocalizedText(saveInUserConfigFolderCheckbox, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.saveInUserConfigFolderCheckbox.text")); // NOI18N
293  saveInUserConfigFolderCheckbox.setToolTipText(org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.saveInUserConfigFolderCheckbox.toolTipText")); // NOI18N
294 
295  buttonGroup1.add(noChangeRadioButton);
296  org.openide.awt.Mnemonics.setLocalizedText(noChangeRadioButton, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.noChangeRadioButton.text")); // NOI18N
297  noChangeRadioButton.setToolTipText(org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.noChangeRadioButton.toolTipText")); // NOI18N
298  noChangeRadioButton.addActionListener(new java.awt.event.ActionListener() {
299  public void actionPerformed(java.awt.event.ActionEvent evt) {
300  noChangeRadioButtonActionPerformed(evt);
301  }
302  });
303 
304  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
305  getContentPane().setLayout(layout);
306  layout.setHorizontalGroup(
307  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
308  .addGroup(layout.createSequentialGroup()
309  .addContainerGap()
310  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
311  .addGroup(layout.createSequentialGroup()
312  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
313  .addComponent(jLabel3)
314  .addComponent(jLabel4))
315  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
316  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
317  .addGroup(layout.createSequentialGroup()
318  .addComponent(fileTypeRadioButton)
319  .addGap(26, 26, 26)
320  .addComponent(centralRepoRadioButton)
321  .addGap(0, 0, Short.MAX_VALUE))
322  .addGroup(layout.createSequentialGroup()
323  .addComponent(databasePathTextField)
324  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
325  .addComponent(openButton))))
326  .addGroup(layout.createSequentialGroup()
327  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
328  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
329  .addComponent(lbOrg)
330  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
331  .addComponent(orgComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
332  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
333  .addComponent(orgButton))
334  .addGroup(layout.createSequentialGroup()
335  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
336  .addComponent(jLabel1)
337  .addComponent(lbVersion))
338  .addGap(40, 40, 40)
339  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
340  .addComponent(versionTextField)
341  .addComponent(hashSetNameTextField))))
342  .addGap(81, 81, 81))
343  .addGroup(layout.createSequentialGroup()
344  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
345  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
346  .addComponent(sendIngestMessagesCheckbox)
347  .addGap(0, 0, Short.MAX_VALUE))
348  .addGroup(layout.createSequentialGroup()
349  .addGap(0, 0, Short.MAX_VALUE)
350  .addComponent(okButton)))
351  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
352  .addComponent(cancelButton))
353  .addGroup(layout.createSequentialGroup()
354  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
355  .addComponent(jLabel2)
356  .addGroup(layout.createSequentialGroup()
357  .addGap(19, 19, 19)
358  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
359  .addComponent(knownRadioButton)
360  .addComponent(knownBadRadioButton)
361  .addComponent(noChangeRadioButton)))
362  .addComponent(saveInUserConfigFolderCheckbox)
363  .addComponent(readOnlyCheckbox))
364  .addGap(0, 0, Short.MAX_VALUE)))
365  .addContainerGap())
366  );
367 
368  layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cancelButton, okButton});
369 
370  layout.setVerticalGroup(
371  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
372  .addGroup(layout.createSequentialGroup()
373  .addContainerGap()
374  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
375  .addComponent(databasePathTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
376  .addComponent(jLabel3)
377  .addComponent(openButton))
378  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
379  .addComponent(fileTypeRadioButton)
380  .addComponent(centralRepoRadioButton)
381  .addComponent(jLabel4))
382  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
383  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
384  .addComponent(jLabel1)
385  .addComponent(hashSetNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
386  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
387  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
388  .addComponent(lbVersion)
389  .addComponent(versionTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
390  .addGap(5, 5, 5)
391  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
392  .addComponent(orgButton)
393  .addComponent(orgComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
394  .addComponent(lbOrg))
395  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
396  .addComponent(jLabel2)
397  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
398  .addComponent(knownRadioButton)
399  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
400  .addComponent(knownBadRadioButton)
401  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
402  .addComponent(noChangeRadioButton)
403  .addGap(5, 5, 5)
404  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
405  .addGroup(layout.createSequentialGroup()
406  .addComponent(readOnlyCheckbox)
407  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
408  .addComponent(sendIngestMessagesCheckbox)
409  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
410  .addComponent(saveInUserConfigFolderCheckbox)
411  .addGap(0, 0, Short.MAX_VALUE))
412  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
413  .addGap(81, 81, 81)
414  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
415  .addComponent(cancelButton)
416  .addComponent(okButton))))
417  .addGap(18, 18, 18))
418  );
419 
420  pack();
421  }// </editor-fold>//GEN-END:initComponents
422 
423  private void openButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openButtonActionPerformed
424  String lastBaseDirectory = Paths.get(PlatformUtil.getUserConfigDirectory(), HashDbCreateDatabaseDialog.HASH_DATABASE_DIR_NAME).toString();
425  if (ModuleSettings.settingExists(ModuleSettings.MAIN_SETTINGS, LAST_FILE_PATH_KEY)) {
426  lastBaseDirectory = ModuleSettings.getConfigSetting(ModuleSettings.MAIN_SETTINGS, LAST_FILE_PATH_KEY);
427  }
428  File hashDbFolder = new File(lastBaseDirectory);
429  // create the folder if it doesn't exist
430  if (!hashDbFolder.exists()) {
431  hashDbFolder.mkdir();
432  }
433  fileChooser.setCurrentDirectory(hashDbFolder);
434  if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
435  File databaseFile = fileChooser.getSelectedFile();
436  try {
437  selectedFilePath = databaseFile.getCanonicalPath();
438  databasePathTextField.setText(shortenPath(selectedFilePath));
439  hashSetNameTextField.setText(FilenameUtils.removeExtension(databaseFile.getName()));
440  if (hashSetNameTextField.getText().toLowerCase().contains("nsrl")) { //NON-NLS
441  knownRadioButton.setSelected(true);
442  knownRadioButtonActionPerformed(null);
443  }
444  ModuleSettings.setConfigSetting(ModuleSettings.MAIN_SETTINGS, LAST_FILE_PATH_KEY, databaseFile.getParent());
445  } catch (IOException ex) {
446  Logger.getLogger(HashDbImportDatabaseDialog.class.getName()).log(Level.SEVERE, "Failed to get path of selected hash set", ex); //NON-NLS
447  JOptionPane.showMessageDialog(this,
448  NbBundle.getMessage(this.getClass(),
449  "HashDbImportDatabaseDialog.failedToGetDbPathMsg"));
450  }
451  }
452  }//GEN-LAST:event_openButtonActionPerformed
453 
454  private void knownRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_knownRadioButtonActionPerformed
455  sendIngestMessagesCheckbox.setSelected(KnownFilesType.KNOWN.isDefaultInboxMessages());
456  sendIngestMessagesCheckbox.setEnabled(KnownFilesType.KNOWN.isInboxMessagesAllowed());
457  }//GEN-LAST:event_knownRadioButtonActionPerformed
458 
459  private void knownBadRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_knownBadRadioButtonActionPerformed
460  sendIngestMessagesCheckbox.setSelected(KnownFilesType.KNOWN_BAD.isDefaultInboxMessages());
461  sendIngestMessagesCheckbox.setEnabled(KnownFilesType.KNOWN_BAD.isInboxMessagesAllowed());
462  }//GEN-LAST:event_knownBadRadioButtonActionPerformed
463 
464  private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
465  this.dispose();
466  }//GEN-LAST:event_cancelButtonActionPerformed
467 
468  @NbBundle.Messages({"HashDbImportDatabaseDialog.missingVersion=A version must be entered",
469  "HashDbImportDatabaseDialog.missingOrg=An organization must be selected",
470  "HashDbImportDatabaseDialog.duplicateName=A hashset with this name and version already exists",
471  "HashDbImportDatabaseDialog.databaseLookupError=Error accessing central repository",
472  "HashDbImportDatabaseDialog.mustEnterHashSetNameMsg=A hash set name must be entered."
473  })
474  private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
475  // Note that the error handlers in this method call return without disposing of the
476  // dialog to allow the user to try again, if desired.
477 
478  if (hashSetNameTextField.getText().isEmpty()) {
479  JOptionPane.showMessageDialog(this,
480  NbBundle.getMessage(this.getClass(),
481  "HashDbImportDatabaseDialog.mustEnterHashSetNameMsg"),
482  NbBundle.getMessage(this.getClass(),
483  "HashDbImportDatabaseDialog.importHashDbErr"),
484  JOptionPane.ERROR_MESSAGE);
485  return;
486  }
487 
488  if (centralRepoRadioButton.isSelected()) {
489  if (readOnlyCheckbox.isSelected() && versionTextField.getText().isEmpty()) {
490  JOptionPane.showMessageDialog(this,
491  NbBundle.getMessage(this.getClass(),
492  "HashDbImportDatabaseDialog.missingVersion"),
493  NbBundle.getMessage(this.getClass(),
494  "HashDbImportDatabaseDialog.importHashDbErr"),
495  JOptionPane.ERROR_MESSAGE);
496  return;
497  }
498 
499  if (selectedOrg == null) {
500  JOptionPane.showMessageDialog(this,
501  NbBundle.getMessage(this.getClass(),
502  "HashDbImportDatabaseDialog.missingOrg"),
503  NbBundle.getMessage(this.getClass(),
504  "HashDbImportDatabaseDialog.importHashDbErr"),
505  JOptionPane.ERROR_MESSAGE);
506  return;
507  }
508  }
509 
510  if (selectedFilePath.isEmpty()) {
511  JOptionPane.showMessageDialog(this,
512  NbBundle.getMessage(this.getClass(),
513  "HashDbImportDatabaseDialog.mustSelectHashDbFilePathMsg"),
514  NbBundle.getMessage(this.getClass(),
515  "HashDbImportDatabaseDialog.importHashDbErr"),
516  JOptionPane.ERROR_MESSAGE);
517  return;
518  }
519 
520  File file = new File(selectedFilePath);
521  if (!file.exists()) {
522  JOptionPane.showMessageDialog(this,
523  NbBundle.getMessage(this.getClass(),
524  "HashDbImportDatabaseDialog.hashDbDoesNotExistMsg"),
525  NbBundle.getMessage(this.getClass(),
526  "HashDbImportDatabaseDialog.importHashDbErr"),
527  JOptionPane.ERROR_MESSAGE);
528  return;
529  }
530 
531  if (saveInUserConfigFolderCheckbox.isSelected()) {
532  // copy the hash database to user configuration directory and use that path instead (JIRA-4177)
533  String locationInUserConfigDir = Paths.get(PlatformUtil.getUserConfigDirectory(), HashDbCreateDatabaseDialog.HASH_DATABASE_DIR_NAME, hashSetNameTextField.getText(), file.getName()).toString();
534  try {
535  FileUtils.copyFile(file, new File(locationInUserConfigDir));
536  // update the hash database location
537  selectedFilePath = locationInUserConfigDir;
538  } catch (IOException ex) {
539  String errorMessage = NbBundle.getMessage(this.getClass(), "HashDbImportDatabaseDialog.unableToCopyToUserDirMsg", locationInUserConfigDir);
540  Logger.getLogger(HashDbImportDatabaseDialog.class.getName()).log(Level.SEVERE, errorMessage, ex);
541  JOptionPane.showMessageDialog(this, errorMessage, NbBundle.getMessage(this.getClass(), "HashDbImportDatabaseDialog.importHashDbErr"),
542  JOptionPane.ERROR_MESSAGE);
543  return;
544  }
545  }
546 
547  KnownFilesType type;
548  if (knownRadioButton.isSelected()) {
549  type = KnownFilesType.KNOWN;
550  } else if (noChangeRadioButton.isSelected()) {
551  type = KnownFilesType.NO_CHANGE;
552  } else {
553  type = KnownFilesType.KNOWN_BAD;
554  }
555 
556  String errorMessage = NbBundle.getMessage(this.getClass(),
557  "HashDbImportDatabaseDialog.errorMessage.failedToOpenHashDbMsg",
558  selectedFilePath);
559  if (fileTypeRadioButton.isSelected()) {
560 
561  try {
562  selectedHashDb = HashDbManager.getInstance().addExistingHashDatabaseNoSave(hashSetNameTextField.getText(), selectedFilePath, true, sendIngestMessagesCheckbox.isSelected(), type);
563  } catch (HashDbManagerException ex) {
564  Logger.getLogger(HashDbImportDatabaseDialog.class.getName()).log(Level.WARNING, errorMessage, ex);
565  JOptionPane.showMessageDialog(this,
566  ex.getMessage(),
567  NbBundle.getMessage(this.getClass(),
568  "HashDbImportDatabaseDialog.importHashDbErr"),
569  JOptionPane.ERROR_MESSAGE);
570  return;
571  }
572  } else {
573 
574  // Check if a hash set with the same name/version already exists
575  try {
576  if (CentralRepository.getInstance().referenceSetExists(hashSetNameTextField.getText(), versionTextField.getText())) {
577  JOptionPane.showMessageDialog(this,
578  NbBundle.getMessage(this.getClass(),
579  "HashDbImportDatabaseDialog.duplicateName"),
580  NbBundle.getMessage(this.getClass(),
581  "HashDbImportDatabaseDialog.importHashDbErr"),
582  JOptionPane.ERROR_MESSAGE);
583  return;
584  }
585  } catch (CentralRepoException ex) {
586  Logger.getLogger(HashDbImportDatabaseDialog.class.getName()).log(Level.SEVERE, "Error looking up reference set", ex);
587  JOptionPane.showMessageDialog(this,
588  NbBundle.getMessage(this.getClass(),
589  "HashDbImportDatabaseDialog.databaseLookupError"),
590  NbBundle.getMessage(this.getClass(),
591  "HashDbImportDatabaseDialog.importHashDbErr"),
592  JOptionPane.ERROR_MESSAGE);
593  return;
594  }
595 
596  String version;
597  if (readOnlyCheckbox.isSelected()) {
598  version = versionTextField.getText();
599  } else {
600  // Editable databases don't have a version
601  version = "";
602  }
603  ImportCentralRepoDbProgressDialog progressDialog = new ImportCentralRepoDbProgressDialog();
604  progressDialog.importFile(hashSetNameTextField.getText(), version,
605  selectedOrg.getOrgID(), true, sendIngestMessagesCheckbox.isSelected(), type,
606  readOnlyCheckbox.isSelected(), selectedFilePath);
607  selectedHashDb = progressDialog.getDatabase();
608  }
609 
610  dispose();
611  }//GEN-LAST:event_okButtonActionPerformed
612 
613  private void sendIngestMessagesCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sendIngestMessagesCheckboxActionPerformed
614  // TODO add your handling code here:
615  }//GEN-LAST:event_sendIngestMessagesCheckboxActionPerformed
616 
617  private void fileTypeRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fileTypeRadioButtonActionPerformed
618  enableComponents();
619  }//GEN-LAST:event_fileTypeRadioButtonActionPerformed
620 
621  private void centralRepoRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_centralRepoRadioButtonActionPerformed
622  enableComponents();
623  }//GEN-LAST:event_centralRepoRadioButtonActionPerformed
624 
625  private void orgButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_orgButtonActionPerformed
626  ManageOrganizationsDialog dialog = new ManageOrganizationsDialog();
627  // update the combobox options
628  if (dialog.isChanged()) {
629  populateCombobox();
630  }
631  }//GEN-LAST:event_orgButtonActionPerformed
632 
633  private void orgComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_orgComboBoxActionPerformed
634  if (null == orgComboBox.getSelectedItem()) {
635  return;
636  }
637  String orgName = this.orgComboBox.getSelectedItem().toString();
638  for (CentralRepoOrganization org : orgs) {
639  if (org.getName().equals(orgName)) {
640  selectedOrg = org;
641  return;
642  }
643  }
644  }//GEN-LAST:event_orgComboBoxActionPerformed
645 
646  private void readOnlyCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_readOnlyCheckboxActionPerformed
647  enableComponents();
648  }//GEN-LAST:event_readOnlyCheckboxActionPerformed
649 
650  private void noChangeRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_noChangeRadioButtonActionPerformed
651  sendIngestMessagesCheckbox.setSelected(KnownFilesType.NO_CHANGE.isDefaultInboxMessages());
652  sendIngestMessagesCheckbox.setEnabled(KnownFilesType.NO_CHANGE.isInboxMessagesAllowed());
653  }//GEN-LAST:event_noChangeRadioButtonActionPerformed
654 
655  // Variables declaration - do not modify//GEN-BEGIN:variables
656  private javax.swing.ButtonGroup buttonGroup1;
657  private javax.swing.JButton cancelButton;
658  private javax.swing.JRadioButton centralRepoRadioButton;
659  private javax.swing.JTextField databasePathTextField;
660  private javax.swing.JRadioButton fileTypeRadioButton;
661  private javax.swing.JTextField hashSetNameTextField;
662  private javax.swing.JLabel jLabel1;
663  private javax.swing.JLabel jLabel2;
664  private javax.swing.JLabel jLabel3;
665  private javax.swing.JLabel jLabel4;
666  private javax.swing.JRadioButton knownBadRadioButton;
667  private javax.swing.JRadioButton knownRadioButton;
668  private javax.swing.JLabel lbOrg;
669  private javax.swing.JLabel lbVersion;
670  private javax.swing.JRadioButton noChangeRadioButton;
671  private javax.swing.JButton okButton;
672  private javax.swing.JButton openButton;
673  private javax.swing.JButton orgButton;
674  private javax.swing.JComboBox<String> orgComboBox;
675  private javax.swing.JCheckBox readOnlyCheckbox;
676  private javax.swing.JCheckBox saveInUserConfigFolderCheckbox;
677  private javax.swing.JCheckBox sendIngestMessagesCheckbox;
678  private javax.swing.ButtonGroup storageTypeButtonGroup;
679  private javax.swing.JTextField versionTextField;
680  // End of variables declaration//GEN-END:variables
681 }

Copyright © 2012-2021 Basis Technology. Generated on: Fri Aug 6 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.