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;
53 @SuppressWarnings(
"PMD.SingularField")
54 final class HashDbImportDatabaseDialog extends javax.swing.JDialog {
56 private JFileChooser fileChooser;
57 private String selectedFilePath =
"";
58 private HashDb selectedHashDb = null;
59 private final static String LAST_FILE_PATH_KEY =
"HashDbImport_Path";
60 private CentralRepoOrganization selectedOrg = null;
61 private List<CentralRepoOrganization> orgs = null;
62 private final JFileChooserFactory chooserHelper;
69 HashDbImportDatabaseDialog() {
70 super((JFrame) WindowManager.getDefault().getMainWindow(),
71 NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.importHashDbMsg"),
73 chooserHelper =
new JFileChooserFactory();
84 HashDb getHashDatabase() {
85 return selectedHashDb;
88 private void display() {
89 setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
93 private static String shortenPath(String path) {
94 String shortenedPath = path;
95 if (shortenedPath.length() > 50) {
96 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));
101 private void enableComponents() {
103 if (!CentralRepository.isEnabled() || !FeatureAccessUtils.canAddHashSetsToCentralRepo()) {
104 centralRepoRadioButton.setEnabled(
false);
105 fileTypeRadioButton.setSelected(
true);
110 boolean isFileType = fileTypeRadioButton.isSelected();
113 lbVersion.setEnabled((!isFileType) && (readOnlyCheckbox.isSelected()));
114 versionTextField.setEnabled((!isFileType) && (readOnlyCheckbox.isSelected()));
116 lbOrg.setEnabled(!isFileType);
117 orgButton.setEnabled(!isFileType);
118 orgComboBox.setEnabled(!isFileType);
119 readOnlyCheckbox.setEnabled(!isFileType);
122 @NbBundle.Messages({
"HashDbImportDatabaseDialog.populateOrgsError.message=Failure loading organizations."})
123 private void populateCombobox() {
124 orgComboBox.removeAllItems();
126 CentralRepository dbManager = CentralRepository.getInstance();
127 orgs = dbManager.getOrganizations();
128 orgs.forEach((
org) -> {
129 orgComboBox.addItem(
org.getName());
130 if (CentralRepoDbUtil.isDefaultOrg(
org)) {
131 orgComboBox.setSelectedItem(
org.getName());
135 if ((selectedOrg == null) && (!orgs.isEmpty())) {
136 selectedOrg = orgs.get(0);
138 }
catch (CentralRepoException ex) {
139 JOptionPane.showMessageDialog(
this, Bundle.HashDbImportDatabaseDialog_populateOrgsError_message());
140 Logger.getLogger(ImportCentralRepoDbProgressDialog.class.getName()).log(Level.SEVERE,
"Failure loading organizations", ex);
149 @SuppressWarnings(
"unchecked")
151 private
void initComponents() {
153 buttonGroup1 =
new javax.swing.ButtonGroup();
154 storageTypeButtonGroup =
new javax.swing.ButtonGroup();
155 okButton =
new javax.swing.JButton();
156 cancelButton =
new javax.swing.JButton();
157 databasePathTextField =
new javax.swing.JTextField();
158 openButton =
new javax.swing.JButton();
159 knownRadioButton =
new javax.swing.JRadioButton();
160 knownBadRadioButton =
new javax.swing.JRadioButton();
161 jLabel1 =
new javax.swing.JLabel();
162 hashSetNameTextField =
new javax.swing.JTextField();
163 jLabel2 =
new javax.swing.JLabel();
164 sendIngestMessagesCheckbox =
new javax.swing.JCheckBox();
165 jLabel3 =
new javax.swing.JLabel();
166 lbVersion =
new javax.swing.JLabel();
167 versionTextField =
new javax.swing.JTextField();
168 lbOrg =
new javax.swing.JLabel();
169 orgComboBox =
new javax.swing.JComboBox<>();
170 orgButton =
new javax.swing.JButton();
171 readOnlyCheckbox =
new javax.swing.JCheckBox();
172 fileTypeRadioButton =
new javax.swing.JRadioButton();
173 centralRepoRadioButton =
new javax.swing.JRadioButton();
174 jLabel4 =
new javax.swing.JLabel();
175 saveInUserConfigFolderCheckbox =
new javax.swing.JCheckBox();
176 noChangeRadioButton =
new javax.swing.JRadioButton();
178 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
180 org.openide.awt.Mnemonics.setLocalizedText(okButton,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.okButton.text"));
181 okButton.addActionListener(
new java.awt.event.ActionListener() {
182 public void actionPerformed(java.awt.event.ActionEvent evt) {
183 okButtonActionPerformed(evt);
187 org.openide.awt.Mnemonics.setLocalizedText(cancelButton,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.cancelButton.text"));
188 cancelButton.addActionListener(
new java.awt.event.ActionListener() {
189 public void actionPerformed(java.awt.event.ActionEvent evt) {
190 cancelButtonActionPerformed(evt);
194 databasePathTextField.setEditable(
false);
195 databasePathTextField.setText(
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.databasePathTextField.text"));
197 org.openide.awt.Mnemonics.setLocalizedText(openButton,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.openButton.text"));
198 openButton.addActionListener(
new java.awt.event.ActionListener() {
199 public void actionPerformed(java.awt.event.ActionEvent evt) {
200 openButtonActionPerformed(evt);
204 buttonGroup1.add(knownRadioButton);
205 org.openide.awt.Mnemonics.setLocalizedText(knownRadioButton,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.knownRadioButton.text"));
206 knownRadioButton.addActionListener(
new java.awt.event.ActionListener() {
207 public void actionPerformed(java.awt.event.ActionEvent evt) {
208 knownRadioButtonActionPerformed(evt);
212 buttonGroup1.add(knownBadRadioButton);
213 knownBadRadioButton.setSelected(
true);
214 org.openide.awt.Mnemonics.setLocalizedText(knownBadRadioButton,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.knownBadRadioButton.text"));
215 knownBadRadioButton.addActionListener(
new java.awt.event.ActionListener() {
216 public void actionPerformed(java.awt.event.ActionEvent evt) {
217 knownBadRadioButtonActionPerformed(evt);
221 org.openide.awt.Mnemonics.setLocalizedText(jLabel1,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.jLabel1.text"));
223 hashSetNameTextField.setText(
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.hashSetNameTextField.text"));
225 org.openide.awt.Mnemonics.setLocalizedText(jLabel2,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.jLabel2.text"));
227 sendIngestMessagesCheckbox.setSelected(
true);
228 org.openide.awt.Mnemonics.setLocalizedText(sendIngestMessagesCheckbox,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.sendIngestMessagesCheckbox.text"));
229 sendIngestMessagesCheckbox.addActionListener(
new java.awt.event.ActionListener() {
230 public void actionPerformed(java.awt.event.ActionEvent evt) {
231 sendIngestMessagesCheckboxActionPerformed(evt);
235 org.openide.awt.Mnemonics.setLocalizedText(jLabel3,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.jLabel3.text"));
237 org.openide.awt.Mnemonics.setLocalizedText(lbVersion,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.lbVersion.text"));
239 versionTextField.setText(
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.versionTextField.text"));
241 org.openide.awt.Mnemonics.setLocalizedText(lbOrg,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.lbOrg.text"));
243 orgComboBox.addActionListener(
new java.awt.event.ActionListener() {
244 public void actionPerformed(java.awt.event.ActionEvent evt) {
245 orgComboBoxActionPerformed(evt);
249 org.openide.awt.Mnemonics.setLocalizedText(orgButton,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.orgButton.text"));
250 orgButton.addActionListener(
new java.awt.event.ActionListener() {
251 public void actionPerformed(java.awt.event.ActionEvent evt) {
252 orgButtonActionPerformed(evt);
256 readOnlyCheckbox.setSelected(
true);
257 org.openide.awt.Mnemonics.setLocalizedText(readOnlyCheckbox,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.readOnlyCheckbox.text"));
258 readOnlyCheckbox.addActionListener(
new java.awt.event.ActionListener() {
259 public void actionPerformed(java.awt.event.ActionEvent evt) {
260 readOnlyCheckboxActionPerformed(evt);
264 storageTypeButtonGroup.add(fileTypeRadioButton);
265 fileTypeRadioButton.setSelected(
true);
266 org.openide.awt.Mnemonics.setLocalizedText(fileTypeRadioButton,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.fileTypeRadioButton.text"));
267 fileTypeRadioButton.addActionListener(
new java.awt.event.ActionListener() {
268 public void actionPerformed(java.awt.event.ActionEvent evt) {
269 fileTypeRadioButtonActionPerformed(evt);
273 storageTypeButtonGroup.add(centralRepoRadioButton);
274 org.openide.awt.Mnemonics.setLocalizedText(centralRepoRadioButton,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.centralRepoRadioButton.text"));
275 centralRepoRadioButton.addActionListener(
new java.awt.event.ActionListener() {
276 public void actionPerformed(java.awt.event.ActionEvent evt) {
277 centralRepoRadioButtonActionPerformed(evt);
281 org.openide.awt.Mnemonics.setLocalizedText(jLabel4,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.jLabel4.text"));
283 org.openide.awt.Mnemonics.setLocalizedText(saveInUserConfigFolderCheckbox,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.saveInUserConfigFolderCheckbox.text"));
284 saveInUserConfigFolderCheckbox.setToolTipText(
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.saveInUserConfigFolderCheckbox.toolTipText"));
286 buttonGroup1.add(noChangeRadioButton);
287 org.openide.awt.Mnemonics.setLocalizedText(noChangeRadioButton,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.noChangeRadioButton.text"));
288 noChangeRadioButton.setToolTipText(
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.noChangeRadioButton.toolTipText"));
289 noChangeRadioButton.addActionListener(
new java.awt.event.ActionListener() {
290 public void actionPerformed(java.awt.event.ActionEvent evt) {
291 noChangeRadioButtonActionPerformed(evt);
295 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
296 getContentPane().setLayout(layout);
297 layout.setHorizontalGroup(
298 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
299 .addGroup(layout.createSequentialGroup()
301 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
302 .addGroup(layout.createSequentialGroup()
303 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
304 .addComponent(jLabel3)
305 .addComponent(jLabel4))
306 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
307 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
308 .addGroup(layout.createSequentialGroup()
309 .addComponent(fileTypeRadioButton)
311 .addComponent(centralRepoRadioButton)
312 .addGap(0, 0, Short.MAX_VALUE))
313 .addGroup(layout.createSequentialGroup()
314 .addComponent(databasePathTextField)
315 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
316 .addComponent(openButton))))
317 .addGroup(layout.createSequentialGroup()
318 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
319 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
321 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
322 .addComponent(orgComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
323 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
324 .addComponent(orgButton))
325 .addGroup(layout.createSequentialGroup()
326 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
327 .addComponent(jLabel1)
328 .addComponent(lbVersion))
330 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
331 .addComponent(versionTextField)
332 .addComponent(hashSetNameTextField))))
334 .addGroup(layout.createSequentialGroup()
335 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
336 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
337 .addComponent(sendIngestMessagesCheckbox)
338 .addGap(0, 0, Short.MAX_VALUE))
339 .addGroup(layout.createSequentialGroup()
340 .addGap(0, 0, Short.MAX_VALUE)
341 .addComponent(okButton)))
342 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
343 .addComponent(cancelButton))
344 .addGroup(layout.createSequentialGroup()
345 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
346 .addComponent(jLabel2)
347 .addGroup(layout.createSequentialGroup()
349 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
350 .addComponent(knownRadioButton)
351 .addComponent(knownBadRadioButton)
352 .addComponent(noChangeRadioButton)))
353 .addComponent(saveInUserConfigFolderCheckbox)
354 .addComponent(readOnlyCheckbox))
355 .addGap(0, 0, Short.MAX_VALUE)))
359 layout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
new java.awt.Component[] {cancelButton, okButton});
361 layout.setVerticalGroup(
362 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
363 .addGroup(layout.createSequentialGroup()
365 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
366 .addComponent(databasePathTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
367 .addComponent(jLabel3)
368 .addComponent(openButton))
369 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
370 .addComponent(fileTypeRadioButton)
371 .addComponent(centralRepoRadioButton)
372 .addComponent(jLabel4))
373 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
374 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
375 .addComponent(jLabel1)
376 .addComponent(hashSetNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
377 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
378 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
379 .addComponent(lbVersion)
380 .addComponent(versionTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
382 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
383 .addComponent(orgButton)
384 .addComponent(orgComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
385 .addComponent(lbOrg))
386 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
387 .addComponent(jLabel2)
388 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
389 .addComponent(knownRadioButton)
390 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
391 .addComponent(knownBadRadioButton)
392 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
393 .addComponent(noChangeRadioButton)
395 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
396 .addGroup(layout.createSequentialGroup()
397 .addComponent(readOnlyCheckbox)
398 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
399 .addComponent(sendIngestMessagesCheckbox)
400 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
401 .addComponent(saveInUserConfigFolderCheckbox)
402 .addGap(0, 0, Short.MAX_VALUE))
403 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
405 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
406 .addComponent(cancelButton)
407 .addComponent(okButton))))
414 private void openButtonActionPerformed(java.awt.event.ActionEvent evt) {
415 if(fileChooser == null) {
416 fileChooser = chooserHelper.getChooser();
417 fileChooser.setDragEnabled(
false);
418 fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
419 String[] EXTENSION =
new String[]{
"txt",
"kdb",
"idx",
"hash",
"Hash",
"hsh"};
420 FileNameExtensionFilter filter =
new FileNameExtensionFilter(
421 NbBundle.getMessage(
this.getClass(),
"HashDbImportDatabaseDialog.fileNameExtFilter.text"), EXTENSION);
422 fileChooser.setFileFilter(filter);
423 fileChooser.setMultiSelectionEnabled(
false);
426 String lastBaseDirectory = Paths.get(PlatformUtil.getUserConfigDirectory(), HashDbCreateDatabaseDialog.HASH_DATABASE_DIR_NAME).toString();
427 if (ModuleSettings.settingExists(ModuleSettings.MAIN_SETTINGS, LAST_FILE_PATH_KEY)) {
428 lastBaseDirectory = ModuleSettings.getConfigSetting(ModuleSettings.MAIN_SETTINGS, LAST_FILE_PATH_KEY);
430 File hashDbFolder =
new File(lastBaseDirectory);
432 if (!hashDbFolder.exists()) {
433 hashDbFolder.mkdir();
435 fileChooser.setCurrentDirectory(hashDbFolder);
436 if (fileChooser.showOpenDialog(
this) == JFileChooser.APPROVE_OPTION) {
437 File databaseFile = fileChooser.getSelectedFile();
439 selectedFilePath = databaseFile.getCanonicalPath();
440 databasePathTextField.setText(shortenPath(selectedFilePath));
441 hashSetNameTextField.setText(FilenameUtils.removeExtension(databaseFile.getName()));
442 if (hashSetNameTextField.getText().toLowerCase().contains(
"nsrl")) {
443 knownRadioButton.setSelected(
true);
444 knownRadioButtonActionPerformed(null);
446 ModuleSettings.setConfigSetting(ModuleSettings.MAIN_SETTINGS, LAST_FILE_PATH_KEY, databaseFile.getParent());
447 }
catch (IOException ex) {
448 Logger.getLogger(HashDbImportDatabaseDialog.class.getName()).log(Level.SEVERE,
"Failed to get path of selected hash set", ex);
449 JOptionPane.showMessageDialog(
this,
450 NbBundle.getMessage(
this.getClass(),
451 "HashDbImportDatabaseDialog.failedToGetDbPathMsg"));
456 private void knownRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {
457 sendIngestMessagesCheckbox.setSelected(KnownFilesType.KNOWN.isDefaultInboxMessages());
458 sendIngestMessagesCheckbox.setEnabled(KnownFilesType.KNOWN.isInboxMessagesAllowed());
461 private void knownBadRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {
462 sendIngestMessagesCheckbox.setSelected(KnownFilesType.KNOWN_BAD.isDefaultInboxMessages());
463 sendIngestMessagesCheckbox.setEnabled(KnownFilesType.KNOWN_BAD.isInboxMessagesAllowed());
466 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
470 @NbBundle.Messages({
"HashDbImportDatabaseDialog.missingVersion=A version must be entered",
471 "HashDbImportDatabaseDialog.missingOrg=An organization must be selected",
472 "HashDbImportDatabaseDialog.duplicateName=A hashset with this name and version already exists",
473 "HashDbImportDatabaseDialog.databaseLookupError=Error accessing central repository",
474 "HashDbImportDatabaseDialog.mustEnterHashSetNameMsg=A hash set name must be entered."
476 private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {
480 if (hashSetNameTextField.getText().isEmpty()) {
481 JOptionPane.showMessageDialog(
this,
482 NbBundle.getMessage(
this.getClass(),
483 "HashDbImportDatabaseDialog.mustEnterHashSetNameMsg"),
484 NbBundle.getMessage(
this.getClass(),
485 "HashDbImportDatabaseDialog.importHashDbErr"),
486 JOptionPane.ERROR_MESSAGE);
490 if (centralRepoRadioButton.isSelected()) {
491 if (readOnlyCheckbox.isSelected() && versionTextField.getText().isEmpty()) {
492 JOptionPane.showMessageDialog(
this,
493 NbBundle.getMessage(
this.getClass(),
494 "HashDbImportDatabaseDialog.missingVersion"),
495 NbBundle.getMessage(
this.getClass(),
496 "HashDbImportDatabaseDialog.importHashDbErr"),
497 JOptionPane.ERROR_MESSAGE);
501 if (selectedOrg == null) {
502 JOptionPane.showMessageDialog(
this,
503 NbBundle.getMessage(
this.getClass(),
504 "HashDbImportDatabaseDialog.missingOrg"),
505 NbBundle.getMessage(
this.getClass(),
506 "HashDbImportDatabaseDialog.importHashDbErr"),
507 JOptionPane.ERROR_MESSAGE);
512 if (selectedFilePath.isEmpty()) {
513 JOptionPane.showMessageDialog(
this,
514 NbBundle.getMessage(
this.getClass(),
515 "HashDbImportDatabaseDialog.mustSelectHashDbFilePathMsg"),
516 NbBundle.getMessage(
this.getClass(),
517 "HashDbImportDatabaseDialog.importHashDbErr"),
518 JOptionPane.ERROR_MESSAGE);
522 File file =
new File(selectedFilePath);
523 if (!file.exists()) {
524 JOptionPane.showMessageDialog(
this,
525 NbBundle.getMessage(
this.getClass(),
526 "HashDbImportDatabaseDialog.hashDbDoesNotExistMsg"),
527 NbBundle.getMessage(
this.getClass(),
528 "HashDbImportDatabaseDialog.importHashDbErr"),
529 JOptionPane.ERROR_MESSAGE);
533 if (saveInUserConfigFolderCheckbox.isSelected()) {
535 String locationInUserConfigDir = Paths.get(PlatformUtil.getUserConfigDirectory(), HashDbCreateDatabaseDialog.HASH_DATABASE_DIR_NAME, hashSetNameTextField.getText(), file.getName()).toString();
537 FileUtils.copyFile(file,
new File(locationInUserConfigDir));
539 selectedFilePath = locationInUserConfigDir;
540 }
catch (IOException ex) {
541 String errorMessage = NbBundle.getMessage(this.getClass(),
"HashDbImportDatabaseDialog.unableToCopyToUserDirMsg", locationInUserConfigDir);
542 Logger.getLogger(HashDbImportDatabaseDialog.class.getName()).log(Level.SEVERE, errorMessage, ex);
543 JOptionPane.showMessageDialog(
this, errorMessage, NbBundle.getMessage(
this.getClass(),
"HashDbImportDatabaseDialog.importHashDbErr"),
544 JOptionPane.ERROR_MESSAGE);
550 if (knownRadioButton.isSelected()) {
551 type = KnownFilesType.KNOWN;
552 }
else if (noChangeRadioButton.isSelected()) {
553 type = KnownFilesType.NO_CHANGE;
555 type = KnownFilesType.KNOWN_BAD;
558 String errorMessage = NbBundle.getMessage(this.getClass(),
559 "HashDbImportDatabaseDialog.errorMessage.failedToOpenHashDbMsg",
561 if (fileTypeRadioButton.isSelected()) {
564 selectedHashDb = HashDbManager.getInstance().addExistingHashDatabaseNoSave(hashSetNameTextField.getText(), selectedFilePath,
true, sendIngestMessagesCheckbox.isSelected(), type);
565 }
catch (HashDbManagerException ex) {
566 Logger.getLogger(HashDbImportDatabaseDialog.class.getName()).log(Level.WARNING, errorMessage, ex);
567 JOptionPane.showMessageDialog(
this,
569 NbBundle.getMessage(this.getClass(),
570 "HashDbImportDatabaseDialog.importHashDbErr"),
571 JOptionPane.ERROR_MESSAGE);
578 if (CentralRepository.getInstance().referenceSetExists(hashSetNameTextField.getText(), versionTextField.getText())) {
579 JOptionPane.showMessageDialog(
this,
580 NbBundle.getMessage(
this.getClass(),
581 "HashDbImportDatabaseDialog.duplicateName"),
582 NbBundle.getMessage(
this.getClass(),
583 "HashDbImportDatabaseDialog.importHashDbErr"),
584 JOptionPane.ERROR_MESSAGE);
587 }
catch (CentralRepoException ex) {
588 Logger.getLogger(HashDbImportDatabaseDialog.class.getName()).log(Level.SEVERE,
"Error looking up reference set", ex);
589 JOptionPane.showMessageDialog(
this,
590 NbBundle.getMessage(
this.getClass(),
591 "HashDbImportDatabaseDialog.databaseLookupError"),
592 NbBundle.getMessage(
this.getClass(),
593 "HashDbImportDatabaseDialog.importHashDbErr"),
594 JOptionPane.ERROR_MESSAGE);
599 if (readOnlyCheckbox.isSelected()) {
600 version = versionTextField.getText();
605 ImportCentralRepoDbProgressDialog progressDialog =
new ImportCentralRepoDbProgressDialog();
606 progressDialog.importFile(hashSetNameTextField.getText(), version,
607 selectedOrg.getOrgID(),
true, sendIngestMessagesCheckbox.isSelected(), type,
608 readOnlyCheckbox.isSelected(), selectedFilePath);
609 selectedHashDb = progressDialog.getDatabase();
615 private void sendIngestMessagesCheckboxActionPerformed(java.awt.event.ActionEvent evt) {
619 private void fileTypeRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {
623 private void centralRepoRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {
627 private void orgButtonActionPerformed(java.awt.event.ActionEvent evt) {
628 ManageOrganizationsDialog dialog =
new ManageOrganizationsDialog();
630 if (dialog.isChanged()) {
635 private void orgComboBoxActionPerformed(java.awt.event.ActionEvent evt) {
636 if (null == orgComboBox.getSelectedItem()) {
639 String orgName = this.orgComboBox.getSelectedItem().toString();
640 for (CentralRepoOrganization
org : orgs) {
641 if (
org.getName().equals(orgName)) {
648 private void readOnlyCheckboxActionPerformed(java.awt.event.ActionEvent evt) {
652 private void noChangeRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {
653 sendIngestMessagesCheckbox.setSelected(KnownFilesType.NO_CHANGE.isDefaultInboxMessages());
654 sendIngestMessagesCheckbox.setEnabled(KnownFilesType.NO_CHANGE.isInboxMessagesAllowed());
658 private javax.swing.ButtonGroup buttonGroup1;
659 private javax.swing.JButton cancelButton;
660 private javax.swing.JRadioButton centralRepoRadioButton;
661 private javax.swing.JTextField databasePathTextField;
662 private javax.swing.JRadioButton fileTypeRadioButton;
663 private javax.swing.JTextField hashSetNameTextField;
664 private javax.swing.JLabel jLabel1;
665 private javax.swing.JLabel jLabel2;
666 private javax.swing.JLabel jLabel3;
667 private javax.swing.JLabel jLabel4;
668 private javax.swing.JRadioButton knownBadRadioButton;
669 private javax.swing.JRadioButton knownRadioButton;
670 private javax.swing.JLabel lbOrg;
671 private javax.swing.JLabel lbVersion;
672 private javax.swing.JRadioButton noChangeRadioButton;
673 private javax.swing.JButton okButton;
674 private javax.swing.JButton openButton;
675 private javax.swing.JButton orgButton;
676 private javax.swing.JComboBox<String> orgComboBox;
677 private javax.swing.JCheckBox readOnlyCheckbox;
678 private javax.swing.JCheckBox saveInUserConfigFolderCheckbox;
679 private javax.swing.JCheckBox sendIngestMessagesCheckbox;
680 private javax.swing.ButtonGroup storageTypeButtonGroup;
681 private javax.swing.JTextField versionTextField;