Autopsy  4.14.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 
186  setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
187 
188  org.openide.awt.Mnemonics.setLocalizedText(okButton, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.okButton.text")); // NOI18N
189  okButton.addActionListener(new java.awt.event.ActionListener() {
190  public void actionPerformed(java.awt.event.ActionEvent evt) {
191  okButtonActionPerformed(evt);
192  }
193  });
194 
195  org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.cancelButton.text")); // NOI18N
196  cancelButton.addActionListener(new java.awt.event.ActionListener() {
197  public void actionPerformed(java.awt.event.ActionEvent evt) {
198  cancelButtonActionPerformed(evt);
199  }
200  });
201 
202  databasePathTextField.setEditable(false);
203  databasePathTextField.setText(org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.databasePathTextField.text")); // NOI18N
204 
205  org.openide.awt.Mnemonics.setLocalizedText(openButton, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.openButton.text")); // NOI18N
206  openButton.addActionListener(new java.awt.event.ActionListener() {
207  public void actionPerformed(java.awt.event.ActionEvent evt) {
208  openButtonActionPerformed(evt);
209  }
210  });
211 
212  buttonGroup1.add(knownRadioButton);
213  org.openide.awt.Mnemonics.setLocalizedText(knownRadioButton, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.knownRadioButton.text")); // NOI18N
214  knownRadioButton.addActionListener(new java.awt.event.ActionListener() {
215  public void actionPerformed(java.awt.event.ActionEvent evt) {
216  knownRadioButtonActionPerformed(evt);
217  }
218  });
219 
220  buttonGroup1.add(knownBadRadioButton);
221  knownBadRadioButton.setSelected(true);
222  org.openide.awt.Mnemonics.setLocalizedText(knownBadRadioButton, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.knownBadRadioButton.text")); // NOI18N
223  knownBadRadioButton.addActionListener(new java.awt.event.ActionListener() {
224  public void actionPerformed(java.awt.event.ActionEvent evt) {
225  knownBadRadioButtonActionPerformed(evt);
226  }
227  });
228 
229  org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.jLabel1.text")); // NOI18N
230 
231  hashSetNameTextField.setText(org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.hashSetNameTextField.text")); // NOI18N
232 
233  org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.jLabel2.text")); // NOI18N
234 
235  sendIngestMessagesCheckbox.setSelected(true);
236  org.openide.awt.Mnemonics.setLocalizedText(sendIngestMessagesCheckbox, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.sendIngestMessagesCheckbox.text")); // NOI18N
237  sendIngestMessagesCheckbox.addActionListener(new java.awt.event.ActionListener() {
238  public void actionPerformed(java.awt.event.ActionEvent evt) {
239  sendIngestMessagesCheckboxActionPerformed(evt);
240  }
241  });
242 
243  org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.jLabel3.text")); // NOI18N
244 
245  org.openide.awt.Mnemonics.setLocalizedText(lbVersion, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.lbVersion.text")); // NOI18N
246 
247  versionTextField.setText(org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.versionTextField.text")); // NOI18N
248 
249  org.openide.awt.Mnemonics.setLocalizedText(lbOrg, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.lbOrg.text")); // NOI18N
250 
251  orgComboBox.addActionListener(new java.awt.event.ActionListener() {
252  public void actionPerformed(java.awt.event.ActionEvent evt) {
253  orgComboBoxActionPerformed(evt);
254  }
255  });
256 
257  org.openide.awt.Mnemonics.setLocalizedText(orgButton, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.orgButton.text")); // NOI18N
258  orgButton.addActionListener(new java.awt.event.ActionListener() {
259  public void actionPerformed(java.awt.event.ActionEvent evt) {
260  orgButtonActionPerformed(evt);
261  }
262  });
263 
264  readOnlyCheckbox.setSelected(true);
265  org.openide.awt.Mnemonics.setLocalizedText(readOnlyCheckbox, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.readOnlyCheckbox.text")); // NOI18N
266  readOnlyCheckbox.addActionListener(new java.awt.event.ActionListener() {
267  public void actionPerformed(java.awt.event.ActionEvent evt) {
268  readOnlyCheckboxActionPerformed(evt);
269  }
270  });
271 
272  storageTypeButtonGroup.add(fileTypeRadioButton);
273  fileTypeRadioButton.setSelected(true);
274  org.openide.awt.Mnemonics.setLocalizedText(fileTypeRadioButton, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.fileTypeRadioButton.text")); // NOI18N
275  fileTypeRadioButton.addActionListener(new java.awt.event.ActionListener() {
276  public void actionPerformed(java.awt.event.ActionEvent evt) {
277  fileTypeRadioButtonActionPerformed(evt);
278  }
279  });
280 
281  storageTypeButtonGroup.add(centralRepoRadioButton);
282  org.openide.awt.Mnemonics.setLocalizedText(centralRepoRadioButton, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.centralRepoRadioButton.text")); // NOI18N
283  centralRepoRadioButton.addActionListener(new java.awt.event.ActionListener() {
284  public void actionPerformed(java.awt.event.ActionEvent evt) {
285  centralRepoRadioButtonActionPerformed(evt);
286  }
287  });
288 
289  org.openide.awt.Mnemonics.setLocalizedText(jLabel4, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.jLabel4.text")); // NOI18N
290 
291  org.openide.awt.Mnemonics.setLocalizedText(saveInUserConfigFolderCheckbox, org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.saveInUserConfigFolderCheckbox.text")); // NOI18N
292  saveInUserConfigFolderCheckbox.setToolTipText(org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.saveInUserConfigFolderCheckbox.toolTipText")); // NOI18N
293 
294  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
295  getContentPane().setLayout(layout);
296  layout.setHorizontalGroup(
297  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
298  .addGroup(layout.createSequentialGroup()
299  .addContainerGap()
300  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
301  .addGroup(layout.createSequentialGroup()
302  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
303  .addComponent(jLabel3)
304  .addComponent(jLabel4))
305  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
306  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
307  .addGroup(layout.createSequentialGroup()
308  .addComponent(fileTypeRadioButton)
309  .addGap(26, 26, 26)
310  .addComponent(centralRepoRadioButton)
311  .addGap(0, 0, Short.MAX_VALUE))
312  .addGroup(layout.createSequentialGroup()
313  .addComponent(databasePathTextField)
314  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
315  .addComponent(openButton))))
316  .addGroup(layout.createSequentialGroup()
317  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
318  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
319  .addComponent(sendIngestMessagesCheckbox)
320  .addGap(0, 0, Short.MAX_VALUE))
321  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
322  .addComponent(lbOrg)
323  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
324  .addComponent(orgComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
325  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
326  .addComponent(orgButton))
327  .addGroup(layout.createSequentialGroup()
328  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
329  .addComponent(jLabel1)
330  .addComponent(lbVersion))
331  .addGap(40, 40, 40)
332  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
333  .addComponent(versionTextField)
334  .addComponent(hashSetNameTextField)))
335  .addGroup(layout.createSequentialGroup()
336  .addGap(0, 0, Short.MAX_VALUE)
337  .addComponent(okButton)))
338  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
339  .addComponent(cancelButton))
340  .addGroup(layout.createSequentialGroup()
341  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
342  .addComponent(saveInUserConfigFolderCheckbox)
343  .addComponent(jLabel2)
344  .addComponent(readOnlyCheckbox)
345  .addGroup(layout.createSequentialGroup()
346  .addGap(19, 19, 19)
347  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
348  .addComponent(knownRadioButton)
349  .addComponent(knownBadRadioButton))))
350  .addGap(0, 0, Short.MAX_VALUE)))
351  .addContainerGap())
352  );
353 
354  layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cancelButton, okButton});
355 
356  layout.setVerticalGroup(
357  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
358  .addGroup(layout.createSequentialGroup()
359  .addContainerGap()
360  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
361  .addComponent(databasePathTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
362  .addComponent(jLabel3)
363  .addComponent(openButton))
364  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
365  .addGroup(layout.createSequentialGroup()
366  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
367  .addComponent(fileTypeRadioButton)
368  .addComponent(centralRepoRadioButton)
369  .addComponent(jLabel4))
370  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
371  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
372  .addComponent(jLabel1)
373  .addComponent(hashSetNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
374  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
375  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
376  .addComponent(lbVersion)
377  .addComponent(versionTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
378  .addGap(5, 5, 5)
379  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
380  .addComponent(orgButton)
381  .addComponent(orgComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
382  .addComponent(lbOrg))
383  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
384  .addComponent(jLabel2)
385  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
386  .addComponent(knownRadioButton)
387  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
388  .addComponent(knownBadRadioButton)
389  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
390  .addComponent(readOnlyCheckbox)
391  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
392  .addComponent(sendIngestMessagesCheckbox)
393  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
394  .addComponent(saveInUserConfigFolderCheckbox)
395  .addGap(0, 29, Short.MAX_VALUE))
396  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
397  .addGap(0, 0, Short.MAX_VALUE)
398  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
399  .addComponent(cancelButton)
400  .addComponent(okButton))))
401  .addContainerGap())
402  );
403 
404  pack();
405  }// </editor-fold>//GEN-END:initComponents
406 
407  private void openButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openButtonActionPerformed
408  String lastBaseDirectory = Paths.get(PlatformUtil.getUserConfigDirectory(), HashDbCreateDatabaseDialog.HASH_DATABASE_DIR_NAME).toString();
409  if (ModuleSettings.settingExists(ModuleSettings.MAIN_SETTINGS, LAST_FILE_PATH_KEY)) {
410  lastBaseDirectory = ModuleSettings.getConfigSetting(ModuleSettings.MAIN_SETTINGS, LAST_FILE_PATH_KEY);
411  }
412  File hashDbFolder = new File(lastBaseDirectory);
413  // create the folder if it doesn't exist
414  if (!hashDbFolder.exists()) {
415  hashDbFolder.mkdir();
416  }
417  fileChooser.setCurrentDirectory(hashDbFolder);
418  if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
419  File databaseFile = fileChooser.getSelectedFile();
420  try {
421  selectedFilePath = databaseFile.getCanonicalPath();
422  databasePathTextField.setText(shortenPath(selectedFilePath));
423  hashSetNameTextField.setText(FilenameUtils.removeExtension(databaseFile.getName()));
424  if (hashSetNameTextField.getText().toLowerCase().contains("nsrl")) { //NON-NLS
425  knownRadioButton.setSelected(true);
426  knownRadioButtonActionPerformed(null);
427  }
428  ModuleSettings.setConfigSetting(ModuleSettings.MAIN_SETTINGS, LAST_FILE_PATH_KEY, databaseFile.getParent());
429  } catch (IOException ex) {
430  Logger.getLogger(HashDbImportDatabaseDialog.class.getName()).log(Level.SEVERE, "Failed to get path of selected hash set", ex); //NON-NLS
431  JOptionPane.showMessageDialog(this,
432  NbBundle.getMessage(this.getClass(),
433  "HashDbImportDatabaseDialog.failedToGetDbPathMsg"));
434  }
435  }
436  }//GEN-LAST:event_openButtonActionPerformed
437 
438  private void knownRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_knownRadioButtonActionPerformed
439  sendIngestMessagesCheckbox.setSelected(false);
440  sendIngestMessagesCheckbox.setEnabled(false);
441  }//GEN-LAST:event_knownRadioButtonActionPerformed
442 
443  private void knownBadRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_knownBadRadioButtonActionPerformed
444  sendIngestMessagesCheckbox.setSelected(true);
445  sendIngestMessagesCheckbox.setEnabled(true);
446  }//GEN-LAST:event_knownBadRadioButtonActionPerformed
447 
448  private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
449  this.dispose();
450  }//GEN-LAST:event_cancelButtonActionPerformed
451 
452  @NbBundle.Messages({"HashDbImportDatabaseDialog.missingVersion=A version must be entered",
453  "HashDbImportDatabaseDialog.missingOrg=An organization must be selected",
454  "HashDbImportDatabaseDialog.duplicateName=A hashset with this name and version already exists",
455  "HashDbImportDatabaseDialog.databaseLookupError=Error accessing central repository",
456  "HashDbImportDatabaseDialog.mustEnterHashSetNameMsg=A hash set name must be entered."
457  })
458  private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
459  // Note that the error handlers in this method call return without disposing of the
460  // dialog to allow the user to try again, if desired.
461 
462  if (hashSetNameTextField.getText().isEmpty()) {
463  JOptionPane.showMessageDialog(this,
464  NbBundle.getMessage(this.getClass(),
465  "HashDbImportDatabaseDialog.mustEnterHashSetNameMsg"),
466  NbBundle.getMessage(this.getClass(),
467  "HashDbImportDatabaseDialog.importHashDbErr"),
468  JOptionPane.ERROR_MESSAGE);
469  return;
470  }
471 
472  if (centralRepoRadioButton.isSelected()) {
473  if (readOnlyCheckbox.isSelected() && versionTextField.getText().isEmpty()) {
474  JOptionPane.showMessageDialog(this,
475  NbBundle.getMessage(this.getClass(),
476  "HashDbImportDatabaseDialog.missingVersion"),
477  NbBundle.getMessage(this.getClass(),
478  "HashDbImportDatabaseDialog.importHashDbErr"),
479  JOptionPane.ERROR_MESSAGE);
480  return;
481  }
482 
483  if (selectedOrg == null) {
484  JOptionPane.showMessageDialog(this,
485  NbBundle.getMessage(this.getClass(),
486  "HashDbImportDatabaseDialog.missingOrg"),
487  NbBundle.getMessage(this.getClass(),
488  "HashDbImportDatabaseDialog.importHashDbErr"),
489  JOptionPane.ERROR_MESSAGE);
490  return;
491  }
492  }
493 
494  if (selectedFilePath.isEmpty()) {
495  JOptionPane.showMessageDialog(this,
496  NbBundle.getMessage(this.getClass(),
497  "HashDbImportDatabaseDialog.mustSelectHashDbFilePathMsg"),
498  NbBundle.getMessage(this.getClass(),
499  "HashDbImportDatabaseDialog.importHashDbErr"),
500  JOptionPane.ERROR_MESSAGE);
501  return;
502  }
503 
504  File file = new File(selectedFilePath);
505  if (!file.exists()) {
506  JOptionPane.showMessageDialog(this,
507  NbBundle.getMessage(this.getClass(),
508  "HashDbImportDatabaseDialog.hashDbDoesNotExistMsg"),
509  NbBundle.getMessage(this.getClass(),
510  "HashDbImportDatabaseDialog.importHashDbErr"),
511  JOptionPane.ERROR_MESSAGE);
512  return;
513  }
514 
515  if (saveInUserConfigFolderCheckbox.isSelected()) {
516  // copy the hash database to user configuration directory and use that path instead (JIRA-4177)
517  String locationInUserConfigDir = Paths.get(PlatformUtil.getUserConfigDirectory(), HashDbCreateDatabaseDialog.HASH_DATABASE_DIR_NAME, hashSetNameTextField.getText(), file.getName()).toString();
518  try {
519  FileUtils.copyFile(file, new File(locationInUserConfigDir));
520  // update the hash database location
521  selectedFilePath = locationInUserConfigDir;
522  } catch (IOException ex) {
523  String errorMessage = NbBundle.getMessage(this.getClass(), "HashDbImportDatabaseDialog.unableToCopyToUserDirMsg", locationInUserConfigDir);
524  Logger.getLogger(HashDbImportDatabaseDialog.class.getName()).log(Level.SEVERE, errorMessage, ex);
525  JOptionPane.showMessageDialog(this, errorMessage, NbBundle.getMessage(this.getClass(), "HashDbImportDatabaseDialog.importHashDbErr"),
526  JOptionPane.ERROR_MESSAGE);
527  return;
528  }
529  }
530 
531  KnownFilesType type;
532  if (knownRadioButton.isSelected()) {
533  type = KnownFilesType.KNOWN;
534  } else {
535  type = KnownFilesType.KNOWN_BAD;
536  }
537 
538  String errorMessage = NbBundle.getMessage(this.getClass(),
539  "HashDbImportDatabaseDialog.errorMessage.failedToOpenHashDbMsg",
540  selectedFilePath);
541  if (fileTypeRadioButton.isSelected()) {
542 
543  try {
544  selectedHashDb = HashDbManager.getInstance().addExistingHashDatabaseNoSave(hashSetNameTextField.getText(), selectedFilePath, true, sendIngestMessagesCheckbox.isSelected(), type);
545  } catch (HashDbManagerException ex) {
546  Logger.getLogger(HashDbImportDatabaseDialog.class.getName()).log(Level.WARNING, errorMessage, ex);
547  JOptionPane.showMessageDialog(this,
548  ex.getMessage(),
549  NbBundle.getMessage(this.getClass(),
550  "HashDbImportDatabaseDialog.importHashDbErr"),
551  JOptionPane.ERROR_MESSAGE);
552  return;
553  }
554  } else {
555 
556  // Check if a hash set with the same name/version already exists
557  try {
558  if (CentralRepository.getInstance().referenceSetExists(hashSetNameTextField.getText(), versionTextField.getText())) {
559  JOptionPane.showMessageDialog(this,
560  NbBundle.getMessage(this.getClass(),
561  "HashDbImportDatabaseDialog.duplicateName"),
562  NbBundle.getMessage(this.getClass(),
563  "HashDbImportDatabaseDialog.importHashDbErr"),
564  JOptionPane.ERROR_MESSAGE);
565  return;
566  }
567  } catch (CentralRepoException ex) {
568  Logger.getLogger(HashDbImportDatabaseDialog.class.getName()).log(Level.SEVERE, "Error looking up reference set", ex);
569  JOptionPane.showMessageDialog(this,
570  NbBundle.getMessage(this.getClass(),
571  "HashDbImportDatabaseDialog.databaseLookupError"),
572  NbBundle.getMessage(this.getClass(),
573  "HashDbImportDatabaseDialog.importHashDbErr"),
574  JOptionPane.ERROR_MESSAGE);
575  return;
576  }
577 
578  String version;
579  if (readOnlyCheckbox.isSelected()) {
580  version = versionTextField.getText();
581  } else {
582  // Editable databases don't have a version
583  version = "";
584  }
585  ImportCentralRepoDbProgressDialog progressDialog = new ImportCentralRepoDbProgressDialog();
586  progressDialog.importFile(hashSetNameTextField.getText(), version,
587  selectedOrg.getOrgID(), true, sendIngestMessagesCheckbox.isSelected(), type,
588  readOnlyCheckbox.isSelected(), selectedFilePath);
589  selectedHashDb = progressDialog.getDatabase();
590  }
591 
592  dispose();
593  }//GEN-LAST:event_okButtonActionPerformed
594 
595  private void sendIngestMessagesCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sendIngestMessagesCheckboxActionPerformed
596  // TODO add your handling code here:
597  }//GEN-LAST:event_sendIngestMessagesCheckboxActionPerformed
598 
599  private void fileTypeRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fileTypeRadioButtonActionPerformed
600  enableComponents();
601  }//GEN-LAST:event_fileTypeRadioButtonActionPerformed
602 
603  private void centralRepoRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_centralRepoRadioButtonActionPerformed
604  enableComponents();
605  }//GEN-LAST:event_centralRepoRadioButtonActionPerformed
606 
607  private void orgButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_orgButtonActionPerformed
608  ManageOrganizationsDialog dialog = new ManageOrganizationsDialog();
609  // update the combobox options
610  if (dialog.isChanged()) {
611  populateCombobox();
612  }
613  }//GEN-LAST:event_orgButtonActionPerformed
614 
615  private void orgComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_orgComboBoxActionPerformed
616  if (null == orgComboBox.getSelectedItem()) {
617  return;
618  }
619  String orgName = this.orgComboBox.getSelectedItem().toString();
620  for (CentralRepoOrganization org : orgs) {
621  if (org.getName().equals(orgName)) {
622  selectedOrg = org;
623  return;
624  }
625  }
626  }//GEN-LAST:event_orgComboBoxActionPerformed
627 
628  private void readOnlyCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_readOnlyCheckboxActionPerformed
629  enableComponents();
630  }//GEN-LAST:event_readOnlyCheckboxActionPerformed
631 
632  // Variables declaration - do not modify//GEN-BEGIN:variables
633  private javax.swing.ButtonGroup buttonGroup1;
634  private javax.swing.JButton cancelButton;
635  private javax.swing.JRadioButton centralRepoRadioButton;
636  private javax.swing.JTextField databasePathTextField;
637  private javax.swing.JRadioButton fileTypeRadioButton;
638  private javax.swing.JTextField hashSetNameTextField;
639  private javax.swing.JLabel jLabel1;
640  private javax.swing.JLabel jLabel2;
641  private javax.swing.JLabel jLabel3;
642  private javax.swing.JLabel jLabel4;
643  private javax.swing.JRadioButton knownBadRadioButton;
644  private javax.swing.JRadioButton knownRadioButton;
645  private javax.swing.JLabel lbOrg;
646  private javax.swing.JLabel lbVersion;
647  private javax.swing.JButton okButton;
648  private javax.swing.JButton openButton;
649  private javax.swing.JButton orgButton;
650  private javax.swing.JComboBox<String> orgComboBox;
651  private javax.swing.JCheckBox readOnlyCheckbox;
652  private javax.swing.JCheckBox saveInUserConfigFolderCheckbox;
653  private javax.swing.JCheckBox sendIngestMessagesCheckbox;
654  private javax.swing.ButtonGroup storageTypeButtonGroup;
655  private javax.swing.JTextField versionTextField;
656  // End of variables declaration//GEN-END:variables
657 }

Copyright © 2012-2020 Basis Technology. Generated on: Wed Apr 8 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.