19 package org.sleuthkit.autopsy.modules.hashdatabase;
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;
52 @SuppressWarnings(
"PMD.SingularField")
53 final class HashDbImportDatabaseDialog extends javax.swing.JDialog {
55 private 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 private final JFileChooserFactory chooserHelper;
68 HashDbImportDatabaseDialog() {
69 super((JFrame) WindowManager.getDefault().getMainWindow(),
70 NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.importHashDbMsg"),
72 chooserHelper =
new JFileChooserFactory();
83 HashDb getHashDatabase() {
84 return selectedHashDb;
87 private void display() {
88 setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
92 private static String shortenPath(String path) {
93 String shortenedPath = path;
94 if (shortenedPath.length() > 50) {
95 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));
100 private void enableComponents() {
102 if (!CentralRepository.isEnabled() || !FeatureAccessUtils.canAddHashSetsToCentralRepo()) {
103 centralRepoRadioButton.setEnabled(
false);
104 fileTypeRadioButton.setSelected(
true);
109 boolean isFileType = fileTypeRadioButton.isSelected();
112 lbVersion.setEnabled((!isFileType) && (readOnlyCheckbox.isSelected()));
113 versionTextField.setEnabled((!isFileType) && (readOnlyCheckbox.isSelected()));
115 lbOrg.setEnabled(!isFileType);
116 orgButton.setEnabled(!isFileType);
117 orgComboBox.setEnabled(!isFileType);
118 readOnlyCheckbox.setEnabled(!isFileType);
121 @NbBundle.Messages({
"HashDbImportDatabaseDialog.populateOrgsError.message=Failure loading organizations."})
122 private void populateCombobox() {
123 orgComboBox.removeAllItems();
125 CentralRepository dbManager = CentralRepository.getInstance();
126 orgs = dbManager.getOrganizations();
127 orgs.forEach((
org) -> {
128 orgComboBox.addItem(
org.getName());
129 if (CentralRepoDbUtil.isDefaultOrg(
org)) {
130 orgComboBox.setSelectedItem(
org.getName());
134 if ((selectedOrg == null) && (!orgs.isEmpty())) {
135 selectedOrg = orgs.get(0);
137 }
catch (CentralRepoException ex) {
138 JOptionPane.showMessageDialog(
this, Bundle.HashDbImportDatabaseDialog_populateOrgsError_message());
139 Logger.getLogger(ImportCentralRepoDbProgressDialog.class.getName()).log(Level.SEVERE,
"Failure loading organizations", ex);
148 @SuppressWarnings(
"unchecked")
150 private
void initComponents() {
152 buttonGroup1 =
new javax.swing.ButtonGroup();
153 storageTypeButtonGroup =
new javax.swing.ButtonGroup();
154 okButton =
new javax.swing.JButton();
155 cancelButton =
new javax.swing.JButton();
156 databasePathTextField =
new javax.swing.JTextField();
157 openButton =
new javax.swing.JButton();
158 knownRadioButton =
new javax.swing.JRadioButton();
159 knownBadRadioButton =
new javax.swing.JRadioButton();
160 jLabel1 =
new javax.swing.JLabel();
161 hashSetNameTextField =
new javax.swing.JTextField();
162 jLabel2 =
new javax.swing.JLabel();
163 sendIngestMessagesCheckbox =
new javax.swing.JCheckBox();
164 jLabel3 =
new javax.swing.JLabel();
165 lbVersion =
new javax.swing.JLabel();
166 versionTextField =
new javax.swing.JTextField();
167 lbOrg =
new javax.swing.JLabel();
168 orgComboBox =
new javax.swing.JComboBox<>();
169 orgButton =
new javax.swing.JButton();
170 readOnlyCheckbox =
new javax.swing.JCheckBox();
171 fileTypeRadioButton =
new javax.swing.JRadioButton();
172 centralRepoRadioButton =
new javax.swing.JRadioButton();
173 jLabel4 =
new javax.swing.JLabel();
174 saveInUserConfigFolderCheckbox =
new javax.swing.JCheckBox();
175 noChangeRadioButton =
new javax.swing.JRadioButton();
177 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
179 org.openide.awt.Mnemonics.setLocalizedText(okButton,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.okButton.text"));
180 okButton.addActionListener(
new java.awt.event.ActionListener() {
181 public void actionPerformed(java.awt.event.ActionEvent evt) {
182 okButtonActionPerformed(evt);
186 org.openide.awt.Mnemonics.setLocalizedText(cancelButton,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.cancelButton.text"));
187 cancelButton.addActionListener(
new java.awt.event.ActionListener() {
188 public void actionPerformed(java.awt.event.ActionEvent evt) {
189 cancelButtonActionPerformed(evt);
193 databasePathTextField.setEditable(
false);
194 databasePathTextField.setText(
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.databasePathTextField.text"));
196 org.openide.awt.Mnemonics.setLocalizedText(openButton,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.openButton.text"));
197 openButton.addActionListener(
new java.awt.event.ActionListener() {
198 public void actionPerformed(java.awt.event.ActionEvent evt) {
199 openButtonActionPerformed(evt);
203 buttonGroup1.add(knownRadioButton);
204 org.openide.awt.Mnemonics.setLocalizedText(knownRadioButton,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.knownRadioButton.text"));
205 knownRadioButton.addActionListener(
new java.awt.event.ActionListener() {
206 public void actionPerformed(java.awt.event.ActionEvent evt) {
207 knownRadioButtonActionPerformed(evt);
211 buttonGroup1.add(knownBadRadioButton);
212 knownBadRadioButton.setSelected(
true);
213 org.openide.awt.Mnemonics.setLocalizedText(knownBadRadioButton,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.knownBadRadioButton.text"));
214 knownBadRadioButton.addActionListener(
new java.awt.event.ActionListener() {
215 public void actionPerformed(java.awt.event.ActionEvent evt) {
216 knownBadRadioButtonActionPerformed(evt);
220 org.openide.awt.Mnemonics.setLocalizedText(jLabel1,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.jLabel1.text"));
222 hashSetNameTextField.setText(
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.hashSetNameTextField.text"));
224 org.openide.awt.Mnemonics.setLocalizedText(jLabel2,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.jLabel2.text"));
226 sendIngestMessagesCheckbox.setSelected(
true);
227 org.openide.awt.Mnemonics.setLocalizedText(sendIngestMessagesCheckbox,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.sendIngestMessagesCheckbox.text"));
228 sendIngestMessagesCheckbox.addActionListener(
new java.awt.event.ActionListener() {
229 public void actionPerformed(java.awt.event.ActionEvent evt) {
230 sendIngestMessagesCheckboxActionPerformed(evt);
234 org.openide.awt.Mnemonics.setLocalizedText(jLabel3,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.jLabel3.text"));
236 org.openide.awt.Mnemonics.setLocalizedText(lbVersion,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.lbVersion.text"));
238 versionTextField.setText(
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.versionTextField.text"));
240 org.openide.awt.Mnemonics.setLocalizedText(lbOrg,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.lbOrg.text"));
242 orgComboBox.addActionListener(
new java.awt.event.ActionListener() {
243 public void actionPerformed(java.awt.event.ActionEvent evt) {
244 orgComboBoxActionPerformed(evt);
248 org.openide.awt.Mnemonics.setLocalizedText(orgButton,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.orgButton.text"));
249 orgButton.addActionListener(
new java.awt.event.ActionListener() {
250 public void actionPerformed(java.awt.event.ActionEvent evt) {
251 orgButtonActionPerformed(evt);
255 readOnlyCheckbox.setSelected(
true);
256 org.openide.awt.Mnemonics.setLocalizedText(readOnlyCheckbox,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.readOnlyCheckbox.text"));
257 readOnlyCheckbox.addActionListener(
new java.awt.event.ActionListener() {
258 public void actionPerformed(java.awt.event.ActionEvent evt) {
259 readOnlyCheckboxActionPerformed(evt);
263 storageTypeButtonGroup.add(fileTypeRadioButton);
264 fileTypeRadioButton.setSelected(
true);
265 org.openide.awt.Mnemonics.setLocalizedText(fileTypeRadioButton,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.fileTypeRadioButton.text"));
266 fileTypeRadioButton.addActionListener(
new java.awt.event.ActionListener() {
267 public void actionPerformed(java.awt.event.ActionEvent evt) {
268 fileTypeRadioButtonActionPerformed(evt);
272 storageTypeButtonGroup.add(centralRepoRadioButton);
273 org.openide.awt.Mnemonics.setLocalizedText(centralRepoRadioButton,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.centralRepoRadioButton.text"));
274 centralRepoRadioButton.addActionListener(
new java.awt.event.ActionListener() {
275 public void actionPerformed(java.awt.event.ActionEvent evt) {
276 centralRepoRadioButtonActionPerformed(evt);
280 org.openide.awt.Mnemonics.setLocalizedText(jLabel4,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.jLabel4.text"));
282 org.openide.awt.Mnemonics.setLocalizedText(saveInUserConfigFolderCheckbox,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.saveInUserConfigFolderCheckbox.text"));
283 saveInUserConfigFolderCheckbox.setToolTipText(
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.saveInUserConfigFolderCheckbox.toolTipText"));
285 buttonGroup1.add(noChangeRadioButton);
286 org.openide.awt.Mnemonics.setLocalizedText(noChangeRadioButton,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.noChangeRadioButton.text"));
287 noChangeRadioButton.setToolTipText(
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.noChangeRadioButton.toolTipText"));
288 noChangeRadioButton.addActionListener(
new java.awt.event.ActionListener() {
289 public void actionPerformed(java.awt.event.ActionEvent evt) {
290 noChangeRadioButtonActionPerformed(evt);
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()
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)
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()
320 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
321 .addComponent(orgComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
322 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
323 .addComponent(orgButton))
324 .addGroup(layout.createSequentialGroup()
325 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
326 .addComponent(jLabel1)
327 .addComponent(lbVersion))
329 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
330 .addComponent(versionTextField)
331 .addComponent(hashSetNameTextField))))
333 .addGroup(layout.createSequentialGroup()
334 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
335 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
336 .addComponent(sendIngestMessagesCheckbox)
337 .addGap(0, 0, Short.MAX_VALUE))
338 .addGroup(layout.createSequentialGroup()
339 .addGap(0, 0, Short.MAX_VALUE)
340 .addComponent(okButton)))
341 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
342 .addComponent(cancelButton))
343 .addGroup(layout.createSequentialGroup()
344 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
345 .addComponent(jLabel2)
346 .addGroup(layout.createSequentialGroup()
348 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
349 .addComponent(knownRadioButton)
350 .addComponent(knownBadRadioButton)
351 .addComponent(noChangeRadioButton)))
352 .addComponent(saveInUserConfigFolderCheckbox)
353 .addComponent(readOnlyCheckbox))
354 .addGap(0, 0, Short.MAX_VALUE)))
358 layout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
new java.awt.Component[] {cancelButton, okButton});
360 layout.setVerticalGroup(
361 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
362 .addGroup(layout.createSequentialGroup()
364 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
365 .addComponent(databasePathTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
366 .addComponent(jLabel3)
367 .addComponent(openButton))
368 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
369 .addComponent(fileTypeRadioButton)
370 .addComponent(centralRepoRadioButton)
371 .addComponent(jLabel4))
372 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
373 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
374 .addComponent(jLabel1)
375 .addComponent(hashSetNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
376 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
377 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
378 .addComponent(lbVersion)
379 .addComponent(versionTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
381 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
382 .addComponent(orgButton)
383 .addComponent(orgComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
384 .addComponent(lbOrg))
385 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
386 .addComponent(jLabel2)
387 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
388 .addComponent(knownRadioButton)
389 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
390 .addComponent(knownBadRadioButton)
391 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
392 .addComponent(noChangeRadioButton)
394 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
395 .addGroup(layout.createSequentialGroup()
396 .addComponent(readOnlyCheckbox)
397 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
398 .addComponent(sendIngestMessagesCheckbox)
399 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
400 .addComponent(saveInUserConfigFolderCheckbox)
401 .addGap(0, 0, Short.MAX_VALUE))
402 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
404 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
405 .addComponent(cancelButton)
406 .addComponent(okButton))))
413 private void openButtonActionPerformed(java.awt.event.ActionEvent evt) {
414 if(fileChooser == null) {
415 fileChooser = chooserHelper.getChooser();
416 fileChooser.setDragEnabled(
false);
417 fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
418 String[] EXTENSION =
new String[]{
"txt",
"kdb",
"idx",
"hash",
"Hash",
"hsh"};
419 FileNameExtensionFilter filter =
new FileNameExtensionFilter(
420 NbBundle.getMessage(
this.getClass(),
"HashDbImportDatabaseDialog.fileNameExtFilter.text"), EXTENSION);
421 fileChooser.setFileFilter(filter);
422 fileChooser.setMultiSelectionEnabled(
false);
425 String lastBaseDirectory = HashLookupSettings.getDefaultDbPath();
426 if (ModuleSettings.settingExists(ModuleSettings.MAIN_SETTINGS, LAST_FILE_PATH_KEY)) {
427 lastBaseDirectory = ModuleSettings.getConfigSetting(ModuleSettings.MAIN_SETTINGS, LAST_FILE_PATH_KEY);
429 File hashDbFolder =
new File(lastBaseDirectory);
431 if (!hashDbFolder.exists()) {
432 hashDbFolder.mkdirs();
434 fileChooser.setCurrentDirectory(hashDbFolder);
435 if (fileChooser.showOpenDialog(
this) == JFileChooser.APPROVE_OPTION) {
436 File databaseFile = fileChooser.getSelectedFile();
438 selectedFilePath = databaseFile.getCanonicalPath();
439 databasePathTextField.setText(shortenPath(selectedFilePath));
440 hashSetNameTextField.setText(FilenameUtils.removeExtension(databaseFile.getName()));
441 if (hashSetNameTextField.getText().toLowerCase().contains(
"nsrl")) {
442 knownRadioButton.setSelected(
true);
443 knownRadioButtonActionPerformed(null);
445 ModuleSettings.setConfigSetting(ModuleSettings.MAIN_SETTINGS, LAST_FILE_PATH_KEY, databaseFile.getParent());
446 }
catch (IOException ex) {
447 Logger.getLogger(HashDbImportDatabaseDialog.class.getName()).log(Level.SEVERE,
"Failed to get path of selected hash set", ex);
448 JOptionPane.showMessageDialog(
this,
449 NbBundle.getMessage(
this.getClass(),
450 "HashDbImportDatabaseDialog.failedToGetDbPathMsg"));
455 private void knownRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {
456 sendIngestMessagesCheckbox.setSelected(KnownFilesType.KNOWN.isDefaultInboxMessages());
457 sendIngestMessagesCheckbox.setEnabled(KnownFilesType.KNOWN.isInboxMessagesAllowed());
460 private void knownBadRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {
461 sendIngestMessagesCheckbox.setSelected(KnownFilesType.KNOWN_BAD.isDefaultInboxMessages());
462 sendIngestMessagesCheckbox.setEnabled(KnownFilesType.KNOWN_BAD.isInboxMessagesAllowed());
465 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
469 @NbBundle.Messages({
"HashDbImportDatabaseDialog.missingVersion=A version must be entered",
470 "HashDbImportDatabaseDialog.missingOrg=An organization must be selected",
471 "HashDbImportDatabaseDialog.duplicateName=A hashset with this name and version already exists",
472 "HashDbImportDatabaseDialog.databaseLookupError=Error accessing central repository",
473 "HashDbImportDatabaseDialog.mustEnterHashSetNameMsg=A hash set name must be entered."
475 private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {
479 if (hashSetNameTextField.getText().isEmpty()) {
480 JOptionPane.showMessageDialog(
this,
481 NbBundle.getMessage(
this.getClass(),
482 "HashDbImportDatabaseDialog.mustEnterHashSetNameMsg"),
483 NbBundle.getMessage(
this.getClass(),
484 "HashDbImportDatabaseDialog.importHashDbErr"),
485 JOptionPane.ERROR_MESSAGE);
489 if (centralRepoRadioButton.isSelected()) {
490 if (readOnlyCheckbox.isSelected() && versionTextField.getText().isEmpty()) {
491 JOptionPane.showMessageDialog(
this,
492 NbBundle.getMessage(
this.getClass(),
493 "HashDbImportDatabaseDialog.missingVersion"),
494 NbBundle.getMessage(
this.getClass(),
495 "HashDbImportDatabaseDialog.importHashDbErr"),
496 JOptionPane.ERROR_MESSAGE);
500 if (selectedOrg == null) {
501 JOptionPane.showMessageDialog(
this,
502 NbBundle.getMessage(
this.getClass(),
503 "HashDbImportDatabaseDialog.missingOrg"),
504 NbBundle.getMessage(
this.getClass(),
505 "HashDbImportDatabaseDialog.importHashDbErr"),
506 JOptionPane.ERROR_MESSAGE);
511 if (selectedFilePath.isEmpty()) {
512 JOptionPane.showMessageDialog(
this,
513 NbBundle.getMessage(
this.getClass(),
514 "HashDbImportDatabaseDialog.mustSelectHashDbFilePathMsg"),
515 NbBundle.getMessage(
this.getClass(),
516 "HashDbImportDatabaseDialog.importHashDbErr"),
517 JOptionPane.ERROR_MESSAGE);
521 File file =
new File(selectedFilePath);
522 if (!file.exists()) {
523 JOptionPane.showMessageDialog(
this,
524 NbBundle.getMessage(
this.getClass(),
525 "HashDbImportDatabaseDialog.hashDbDoesNotExistMsg"),
526 NbBundle.getMessage(
this.getClass(),
527 "HashDbImportDatabaseDialog.importHashDbErr"),
528 JOptionPane.ERROR_MESSAGE);
532 if (saveInUserConfigFolderCheckbox.isSelected()) {
534 String locationInUserConfigDir = Paths.get(HashLookupSettings.getDefaultDbPath(), hashSetNameTextField.getText(), file.getName()).toString();
536 File newFileLoc =
new File(locationInUserConfigDir);
537 newFileLoc.getParentFile().mkdirs();
538 FileUtils.copyFile(file, newFileLoc);
540 selectedFilePath = locationInUserConfigDir;
541 }
catch (IOException ex) {
542 String errorMessage = NbBundle.getMessage(this.getClass(),
"HashDbImportDatabaseDialog.unableToCopyToUserDirMsg", locationInUserConfigDir);
543 Logger.getLogger(HashDbImportDatabaseDialog.class.getName()).log(Level.SEVERE, errorMessage, ex);
544 JOptionPane.showMessageDialog(
this, errorMessage, NbBundle.getMessage(
this.getClass(),
"HashDbImportDatabaseDialog.importHashDbErr"),
545 JOptionPane.ERROR_MESSAGE);
551 if (knownRadioButton.isSelected()) {
552 type = KnownFilesType.KNOWN;
553 }
else if (noChangeRadioButton.isSelected()) {
554 type = KnownFilesType.NO_CHANGE;
556 type = KnownFilesType.KNOWN_BAD;
559 String errorMessage = NbBundle.getMessage(this.getClass(),
560 "HashDbImportDatabaseDialog.errorMessage.failedToOpenHashDbMsg",
562 if (fileTypeRadioButton.isSelected()) {
565 selectedHashDb = HashDbManager.getInstance().addExistingHashDatabaseNoSave(hashSetNameTextField.getText(), selectedFilePath,
true, sendIngestMessagesCheckbox.isSelected(), type);
566 }
catch (HashDbManagerException ex) {
567 Logger.getLogger(HashDbImportDatabaseDialog.class.getName()).log(Level.WARNING, errorMessage, ex);
568 JOptionPane.showMessageDialog(
this,
570 NbBundle.getMessage(this.getClass(),
571 "HashDbImportDatabaseDialog.importHashDbErr"),
572 JOptionPane.ERROR_MESSAGE);
579 if (CentralRepository.getInstance().referenceSetExists(hashSetNameTextField.getText(), versionTextField.getText())) {
580 JOptionPane.showMessageDialog(
this,
581 NbBundle.getMessage(
this.getClass(),
582 "HashDbImportDatabaseDialog.duplicateName"),
583 NbBundle.getMessage(
this.getClass(),
584 "HashDbImportDatabaseDialog.importHashDbErr"),
585 JOptionPane.ERROR_MESSAGE);
588 }
catch (CentralRepoException ex) {
589 Logger.getLogger(HashDbImportDatabaseDialog.class.getName()).log(Level.SEVERE,
"Error looking up reference set", ex);
590 JOptionPane.showMessageDialog(
this,
591 NbBundle.getMessage(
this.getClass(),
592 "HashDbImportDatabaseDialog.databaseLookupError"),
593 NbBundle.getMessage(
this.getClass(),
594 "HashDbImportDatabaseDialog.importHashDbErr"),
595 JOptionPane.ERROR_MESSAGE);
600 if (readOnlyCheckbox.isSelected()) {
601 version = versionTextField.getText();
606 ImportCentralRepoDbProgressDialog progressDialog =
new ImportCentralRepoDbProgressDialog();
607 progressDialog.importFile(hashSetNameTextField.getText(), version,
608 selectedOrg.getOrgID(),
true, sendIngestMessagesCheckbox.isSelected(), type,
609 readOnlyCheckbox.isSelected(), selectedFilePath);
610 selectedHashDb = progressDialog.getDatabase();
616 private void sendIngestMessagesCheckboxActionPerformed(java.awt.event.ActionEvent evt) {
620 private void fileTypeRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {
624 private void centralRepoRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {
628 private void orgButtonActionPerformed(java.awt.event.ActionEvent evt) {
629 ManageOrganizationsDialog dialog =
new ManageOrganizationsDialog();
631 if (dialog.isChanged()) {
636 private void orgComboBoxActionPerformed(java.awt.event.ActionEvent evt) {
637 if (null == orgComboBox.getSelectedItem()) {
640 String orgName = this.orgComboBox.getSelectedItem().toString();
641 for (CentralRepoOrganization
org : orgs) {
642 if (
org.getName().equals(orgName)) {
649 private void readOnlyCheckboxActionPerformed(java.awt.event.ActionEvent evt) {
653 private void noChangeRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {
654 sendIngestMessagesCheckbox.setSelected(KnownFilesType.NO_CHANGE.isDefaultInboxMessages());
655 sendIngestMessagesCheckbox.setEnabled(KnownFilesType.NO_CHANGE.isInboxMessagesAllowed());
659 private javax.swing.ButtonGroup buttonGroup1;
660 private javax.swing.JButton cancelButton;
661 private javax.swing.JRadioButton centralRepoRadioButton;
662 private javax.swing.JTextField databasePathTextField;
663 private javax.swing.JRadioButton fileTypeRadioButton;
664 private javax.swing.JTextField hashSetNameTextField;
665 private javax.swing.JLabel jLabel1;
666 private javax.swing.JLabel jLabel2;
667 private javax.swing.JLabel jLabel3;
668 private javax.swing.JLabel jLabel4;
669 private javax.swing.JRadioButton knownBadRadioButton;
670 private javax.swing.JRadioButton knownRadioButton;
671 private javax.swing.JLabel lbOrg;
672 private javax.swing.JLabel lbVersion;
673 private javax.swing.JRadioButton noChangeRadioButton;
674 private javax.swing.JButton okButton;
675 private javax.swing.JButton openButton;
676 private javax.swing.JButton orgButton;
677 private javax.swing.JComboBox<String> orgComboBox;
678 private javax.swing.JCheckBox readOnlyCheckbox;
679 private javax.swing.JCheckBox saveInUserConfigFolderCheckbox;
680 private javax.swing.JCheckBox sendIngestMessagesCheckbox;
681 private javax.swing.ButtonGroup storageTypeButtonGroup;
682 private javax.swing.JTextField versionTextField;