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

Copyright © 2012-2016 Basis Technology. Generated on: Mon May 7 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.