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

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