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

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.