Autopsy  4.9.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 2011-2018 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;
45 
51 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
52 final class HashDbImportDatabaseDialog extends javax.swing.JDialog {
53 
54  private final JFileChooser fileChooser;
55  private String selectedFilePath = "";
56  private HashDb selectedHashDb = null;
57  private final static String LAST_FILE_PATH_KEY = "HashDbImport_Path";
58  private EamOrganization selectedOrg = null;
59  private List<EamOrganization> orgs = null;
60 
66  HashDbImportDatabaseDialog() {
67  super((JFrame) WindowManager.getDefault().getMainWindow(),
68  NbBundle.getMessage(HashDbImportDatabaseDialog.class, "HashDbImportDatabaseDialog.importHashDbMsg"),
69  true);
70  this.fileChooser = new JFileChooser();
71  initComponents();
72  enableComponents();
73  initFileChooser();
74  display();
75  }
76 
82  HashDb getHashDatabase() {
83  return selectedHashDb;
84  }
85 
86  private void initFileChooser() {
87  fileChooser.setDragEnabled(false);
88  fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
89  String[] EXTENSION = new String[]{"txt", "kdb", "idx", "hash", "Hash", "hsh"}; //NON-NLS
90  FileNameExtensionFilter filter = new FileNameExtensionFilter(
91  NbBundle.getMessage(this.getClass(), "HashDbImportDatabaseDialog.fileNameExtFilter.text"), EXTENSION);
92  fileChooser.setFileFilter(filter);
93  fileChooser.setMultiSelectionEnabled(false);
94  }
95 
96  private void display() {
97  setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
98  setVisible(true);
99  }
100 
101  private static String shortenPath(String path) {
102  String shortenedPath = path;
103  if (shortenedPath.length() > 50) {
104  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));
105  }
106  return shortenedPath;
107  }
108 
109  private void enableComponents(){
110 
111 
112  if(! EamDb.isEnabled()){
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  EamDb dbManager = EamDb.getInstance();
136  orgs = dbManager.getOrganizations();
137  orgs.forEach((org) -> {
138  orgComboBox.addItem(org.getName());
139  if(EamDbUtil.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 (EamDbException 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(EamDb.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 (EamDbException 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()) return;
617  String orgName = this.orgComboBox.getSelectedItem().toString();
618  for (EamOrganization org : orgs) {
619  if (org.getName().equals(orgName)) {
620  selectedOrg = org;
621  return;
622  }
623  }
624  }//GEN-LAST:event_orgComboBoxActionPerformed
625 
626  private void readOnlyCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_readOnlyCheckboxActionPerformed
627  enableComponents();
628  }//GEN-LAST:event_readOnlyCheckboxActionPerformed
629 
630  // Variables declaration - do not modify//GEN-BEGIN:variables
631  private javax.swing.ButtonGroup buttonGroup1;
632  private javax.swing.JButton cancelButton;
633  private javax.swing.JRadioButton centralRepoRadioButton;
634  private javax.swing.JTextField databasePathTextField;
635  private javax.swing.JRadioButton fileTypeRadioButton;
636  private javax.swing.JTextField hashSetNameTextField;
637  private javax.swing.JLabel jLabel1;
638  private javax.swing.JLabel jLabel2;
639  private javax.swing.JLabel jLabel3;
640  private javax.swing.JLabel jLabel4;
641  private javax.swing.JRadioButton knownBadRadioButton;
642  private javax.swing.JRadioButton knownRadioButton;
643  private javax.swing.JLabel lbOrg;
644  private javax.swing.JLabel lbVersion;
645  private javax.swing.JButton okButton;
646  private javax.swing.JButton openButton;
647  private javax.swing.JButton orgButton;
648  private javax.swing.JComboBox<String> orgComboBox;
649  private javax.swing.JCheckBox readOnlyCheckbox;
650  private javax.swing.JCheckBox saveInUserConfigFolderCheckbox;
651  private javax.swing.JCheckBox sendIngestMessagesCheckbox;
652  private javax.swing.ButtonGroup storageTypeButtonGroup;
653  private javax.swing.JTextField versionTextField;
654  // End of variables declaration//GEN-END:variables
655 }

Copyright © 2012-2018 Basis Technology. Generated on: Tue Dec 18 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.