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 final 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;
67 HashDbImportDatabaseDialog() {
68 super((JFrame) WindowManager.getDefault().getMainWindow(),
69 NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.importHashDbMsg"),
71 this.fileChooser =
new JFileChooser();
83 HashDb getHashDatabase() {
84 return selectedHashDb;
87 private void initFileChooser() {
88 fileChooser.setDragEnabled(
false);
89 fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
90 String[] EXTENSION =
new String[]{
"txt",
"kdb",
"idx",
"hash",
"Hash",
"hsh"};
91 FileNameExtensionFilter filter =
new FileNameExtensionFilter(
92 NbBundle.getMessage(
this.getClass(),
"HashDbImportDatabaseDialog.fileNameExtFilter.text"), EXTENSION);
93 fileChooser.setFileFilter(filter);
94 fileChooser.setMultiSelectionEnabled(
false);
97 private void display() {
98 setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
102 private static String shortenPath(String path) {
103 String shortenedPath = path;
104 if (shortenedPath.length() > 50) {
105 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));
107 return shortenedPath;
110 private void enableComponents() {
112 if (!CentralRepository.isEnabled() || !FeatureAccessUtils.canAddHashSetsToCentralRepo()) {
113 centralRepoRadioButton.setEnabled(
false);
114 fileTypeRadioButton.setSelected(
true);
119 boolean isFileType = fileTypeRadioButton.isSelected();
122 lbVersion.setEnabled((!isFileType) && (readOnlyCheckbox.isSelected()));
123 versionTextField.setEnabled((!isFileType) && (readOnlyCheckbox.isSelected()));
125 lbOrg.setEnabled(!isFileType);
126 orgButton.setEnabled(!isFileType);
127 orgComboBox.setEnabled(!isFileType);
128 readOnlyCheckbox.setEnabled(!isFileType);
131 @NbBundle.Messages({
"HashDbImportDatabaseDialog.populateOrgsError.message=Failure loading organizations."})
132 private void populateCombobox() {
133 orgComboBox.removeAllItems();
135 CentralRepository dbManager = CentralRepository.getInstance();
136 orgs = dbManager.getOrganizations();
137 orgs.forEach((
org) -> {
138 orgComboBox.addItem(
org.getName());
139 if (CentralRepoDbUtil.isDefaultOrg(
org)) {
140 orgComboBox.setSelectedItem(
org.getName());
144 if ((selectedOrg == null) && (!orgs.isEmpty())) {
145 selectedOrg = orgs.get(0);
147 }
catch (CentralRepoException ex) {
148 JOptionPane.showMessageDialog(
this, Bundle.HashDbImportDatabaseDialog_populateOrgsError_message());
149 Logger.getLogger(ImportCentralRepoDbProgressDialog.class.getName()).log(Level.SEVERE,
"Failure loading organizations", ex);
158 @SuppressWarnings(
"unchecked")
160 private
void initComponents() {
162 buttonGroup1 =
new javax.swing.ButtonGroup();
163 storageTypeButtonGroup =
new javax.swing.ButtonGroup();
164 okButton =
new javax.swing.JButton();
165 cancelButton =
new javax.swing.JButton();
166 databasePathTextField =
new javax.swing.JTextField();
167 openButton =
new javax.swing.JButton();
168 knownRadioButton =
new javax.swing.JRadioButton();
169 knownBadRadioButton =
new javax.swing.JRadioButton();
170 jLabel1 =
new javax.swing.JLabel();
171 hashSetNameTextField =
new javax.swing.JTextField();
172 jLabel2 =
new javax.swing.JLabel();
173 sendIngestMessagesCheckbox =
new javax.swing.JCheckBox();
174 jLabel3 =
new javax.swing.JLabel();
175 lbVersion =
new javax.swing.JLabel();
176 versionTextField =
new javax.swing.JTextField();
177 lbOrg =
new javax.swing.JLabel();
178 orgComboBox =
new javax.swing.JComboBox<>();
179 orgButton =
new javax.swing.JButton();
180 readOnlyCheckbox =
new javax.swing.JCheckBox();
181 fileTypeRadioButton =
new javax.swing.JRadioButton();
182 centralRepoRadioButton =
new javax.swing.JRadioButton();
183 jLabel4 =
new javax.swing.JLabel();
184 saveInUserConfigFolderCheckbox =
new javax.swing.JCheckBox();
185 noChangeRadioButton =
new javax.swing.JRadioButton();
187 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
189 org.openide.awt.Mnemonics.setLocalizedText(okButton,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.okButton.text"));
190 okButton.addActionListener(
new java.awt.event.ActionListener() {
191 public void actionPerformed(java.awt.event.ActionEvent evt) {
192 okButtonActionPerformed(evt);
196 org.openide.awt.Mnemonics.setLocalizedText(cancelButton,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.cancelButton.text"));
197 cancelButton.addActionListener(
new java.awt.event.ActionListener() {
198 public void actionPerformed(java.awt.event.ActionEvent evt) {
199 cancelButtonActionPerformed(evt);
203 databasePathTextField.setEditable(
false);
204 databasePathTextField.setText(
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.databasePathTextField.text"));
206 org.openide.awt.Mnemonics.setLocalizedText(openButton,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.openButton.text"));
207 openButton.addActionListener(
new java.awt.event.ActionListener() {
208 public void actionPerformed(java.awt.event.ActionEvent evt) {
209 openButtonActionPerformed(evt);
213 buttonGroup1.add(knownRadioButton);
214 org.openide.awt.Mnemonics.setLocalizedText(knownRadioButton,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.knownRadioButton.text"));
215 knownRadioButton.addActionListener(
new java.awt.event.ActionListener() {
216 public void actionPerformed(java.awt.event.ActionEvent evt) {
217 knownRadioButtonActionPerformed(evt);
221 buttonGroup1.add(knownBadRadioButton);
222 knownBadRadioButton.setSelected(
true);
223 org.openide.awt.Mnemonics.setLocalizedText(knownBadRadioButton,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.knownBadRadioButton.text"));
224 knownBadRadioButton.addActionListener(
new java.awt.event.ActionListener() {
225 public void actionPerformed(java.awt.event.ActionEvent evt) {
226 knownBadRadioButtonActionPerformed(evt);
230 org.openide.awt.Mnemonics.setLocalizedText(jLabel1,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.jLabel1.text"));
232 hashSetNameTextField.setText(
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.hashSetNameTextField.text"));
234 org.openide.awt.Mnemonics.setLocalizedText(jLabel2,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.jLabel2.text"));
236 sendIngestMessagesCheckbox.setSelected(
true);
237 org.openide.awt.Mnemonics.setLocalizedText(sendIngestMessagesCheckbox,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.sendIngestMessagesCheckbox.text"));
238 sendIngestMessagesCheckbox.addActionListener(
new java.awt.event.ActionListener() {
239 public void actionPerformed(java.awt.event.ActionEvent evt) {
240 sendIngestMessagesCheckboxActionPerformed(evt);
244 org.openide.awt.Mnemonics.setLocalizedText(jLabel3,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.jLabel3.text"));
246 org.openide.awt.Mnemonics.setLocalizedText(lbVersion,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.lbVersion.text"));
248 versionTextField.setText(
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.versionTextField.text"));
250 org.openide.awt.Mnemonics.setLocalizedText(lbOrg,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.lbOrg.text"));
252 orgComboBox.addActionListener(
new java.awt.event.ActionListener() {
253 public void actionPerformed(java.awt.event.ActionEvent evt) {
254 orgComboBoxActionPerformed(evt);
258 org.openide.awt.Mnemonics.setLocalizedText(orgButton,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.orgButton.text"));
259 orgButton.addActionListener(
new java.awt.event.ActionListener() {
260 public void actionPerformed(java.awt.event.ActionEvent evt) {
261 orgButtonActionPerformed(evt);
265 readOnlyCheckbox.setSelected(
true);
266 org.openide.awt.Mnemonics.setLocalizedText(readOnlyCheckbox,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.readOnlyCheckbox.text"));
267 readOnlyCheckbox.addActionListener(
new java.awt.event.ActionListener() {
268 public void actionPerformed(java.awt.event.ActionEvent evt) {
269 readOnlyCheckboxActionPerformed(evt);
273 storageTypeButtonGroup.add(fileTypeRadioButton);
274 fileTypeRadioButton.setSelected(
true);
275 org.openide.awt.Mnemonics.setLocalizedText(fileTypeRadioButton,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.fileTypeRadioButton.text"));
276 fileTypeRadioButton.addActionListener(
new java.awt.event.ActionListener() {
277 public void actionPerformed(java.awt.event.ActionEvent evt) {
278 fileTypeRadioButtonActionPerformed(evt);
282 storageTypeButtonGroup.add(centralRepoRadioButton);
283 org.openide.awt.Mnemonics.setLocalizedText(centralRepoRadioButton,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.centralRepoRadioButton.text"));
284 centralRepoRadioButton.addActionListener(
new java.awt.event.ActionListener() {
285 public void actionPerformed(java.awt.event.ActionEvent evt) {
286 centralRepoRadioButtonActionPerformed(evt);
290 org.openide.awt.Mnemonics.setLocalizedText(jLabel4,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.jLabel4.text"));
292 org.openide.awt.Mnemonics.setLocalizedText(saveInUserConfigFolderCheckbox,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.saveInUserConfigFolderCheckbox.text"));
293 saveInUserConfigFolderCheckbox.setToolTipText(
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.saveInUserConfigFolderCheckbox.toolTipText"));
295 buttonGroup1.add(noChangeRadioButton);
296 org.openide.awt.Mnemonics.setLocalizedText(noChangeRadioButton,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.noChangeRadioButton.text"));
297 noChangeRadioButton.setToolTipText(
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.noChangeRadioButton.toolTipText"));
298 noChangeRadioButton.addActionListener(
new java.awt.event.ActionListener() {
299 public void actionPerformed(java.awt.event.ActionEvent evt) {
300 noChangeRadioButtonActionPerformed(evt);
304 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
305 getContentPane().setLayout(layout);
306 layout.setHorizontalGroup(
307 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
308 .addGroup(layout.createSequentialGroup()
310 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
311 .addGroup(layout.createSequentialGroup()
312 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
313 .addComponent(jLabel3)
314 .addComponent(jLabel4))
315 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
316 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
317 .addGroup(layout.createSequentialGroup()
318 .addComponent(fileTypeRadioButton)
320 .addComponent(centralRepoRadioButton)
321 .addGap(0, 0, Short.MAX_VALUE))
322 .addGroup(layout.createSequentialGroup()
323 .addComponent(databasePathTextField)
324 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
325 .addComponent(openButton))))
326 .addGroup(layout.createSequentialGroup()
327 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
328 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
330 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
331 .addComponent(orgComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
332 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
333 .addComponent(orgButton))
334 .addGroup(layout.createSequentialGroup()
335 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
336 .addComponent(jLabel1)
337 .addComponent(lbVersion))
339 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
340 .addComponent(versionTextField)
341 .addComponent(hashSetNameTextField))))
343 .addGroup(layout.createSequentialGroup()
344 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
345 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
346 .addComponent(sendIngestMessagesCheckbox)
347 .addGap(0, 0, Short.MAX_VALUE))
348 .addGroup(layout.createSequentialGroup()
349 .addGap(0, 0, Short.MAX_VALUE)
350 .addComponent(okButton)))
351 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
352 .addComponent(cancelButton))
353 .addGroup(layout.createSequentialGroup()
354 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
355 .addComponent(jLabel2)
356 .addGroup(layout.createSequentialGroup()
358 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
359 .addComponent(knownRadioButton)
360 .addComponent(knownBadRadioButton)
361 .addComponent(noChangeRadioButton)))
362 .addComponent(saveInUserConfigFolderCheckbox)
363 .addComponent(readOnlyCheckbox))
364 .addGap(0, 0, Short.MAX_VALUE)))
368 layout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
new java.awt.Component[] {cancelButton, okButton});
370 layout.setVerticalGroup(
371 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
372 .addGroup(layout.createSequentialGroup()
374 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
375 .addComponent(databasePathTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
376 .addComponent(jLabel3)
377 .addComponent(openButton))
378 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
379 .addComponent(fileTypeRadioButton)
380 .addComponent(centralRepoRadioButton)
381 .addComponent(jLabel4))
382 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
383 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
384 .addComponent(jLabel1)
385 .addComponent(hashSetNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
386 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
387 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
388 .addComponent(lbVersion)
389 .addComponent(versionTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
391 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
392 .addComponent(orgButton)
393 .addComponent(orgComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
394 .addComponent(lbOrg))
395 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
396 .addComponent(jLabel2)
397 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
398 .addComponent(knownRadioButton)
399 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
400 .addComponent(knownBadRadioButton)
401 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
402 .addComponent(noChangeRadioButton)
404 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
405 .addGroup(layout.createSequentialGroup()
406 .addComponent(readOnlyCheckbox)
407 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
408 .addComponent(sendIngestMessagesCheckbox)
409 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
410 .addComponent(saveInUserConfigFolderCheckbox)
411 .addGap(0, 0, Short.MAX_VALUE))
412 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
414 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
415 .addComponent(cancelButton)
416 .addComponent(okButton))))
423 private void openButtonActionPerformed(java.awt.event.ActionEvent evt) {
424 String lastBaseDirectory = Paths.get(PlatformUtil.getUserConfigDirectory(), HashDbCreateDatabaseDialog.HASH_DATABASE_DIR_NAME).toString();
425 if (ModuleSettings.settingExists(ModuleSettings.MAIN_SETTINGS, LAST_FILE_PATH_KEY)) {
426 lastBaseDirectory = ModuleSettings.getConfigSetting(ModuleSettings.MAIN_SETTINGS, LAST_FILE_PATH_KEY);
428 File hashDbFolder =
new File(lastBaseDirectory);
430 if (!hashDbFolder.exists()) {
431 hashDbFolder.mkdir();
433 fileChooser.setCurrentDirectory(hashDbFolder);
434 if (fileChooser.showOpenDialog(
this) == JFileChooser.APPROVE_OPTION) {
435 File databaseFile = fileChooser.getSelectedFile();
437 selectedFilePath = databaseFile.getCanonicalPath();
438 databasePathTextField.setText(shortenPath(selectedFilePath));
439 hashSetNameTextField.setText(FilenameUtils.removeExtension(databaseFile.getName()));
440 if (hashSetNameTextField.getText().toLowerCase().contains(
"nsrl")) {
441 knownRadioButton.setSelected(
true);
442 knownRadioButtonActionPerformed(null);
444 ModuleSettings.setConfigSetting(ModuleSettings.MAIN_SETTINGS, LAST_FILE_PATH_KEY, databaseFile.getParent());
445 }
catch (IOException ex) {
446 Logger.getLogger(HashDbImportDatabaseDialog.class.getName()).log(Level.SEVERE,
"Failed to get path of selected hash set", ex);
447 JOptionPane.showMessageDialog(
this,
448 NbBundle.getMessage(
this.getClass(),
449 "HashDbImportDatabaseDialog.failedToGetDbPathMsg"));
454 private void knownRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {
455 sendIngestMessagesCheckbox.setSelected(KnownFilesType.KNOWN.isDefaultInboxMessages());
456 sendIngestMessagesCheckbox.setEnabled(KnownFilesType.KNOWN.isInboxMessagesAllowed());
459 private void knownBadRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {
460 sendIngestMessagesCheckbox.setSelected(KnownFilesType.KNOWN_BAD.isDefaultInboxMessages());
461 sendIngestMessagesCheckbox.setEnabled(KnownFilesType.KNOWN_BAD.isInboxMessagesAllowed());
464 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
468 @NbBundle.Messages({
"HashDbImportDatabaseDialog.missingVersion=A version must be entered",
469 "HashDbImportDatabaseDialog.missingOrg=An organization must be selected",
470 "HashDbImportDatabaseDialog.duplicateName=A hashset with this name and version already exists",
471 "HashDbImportDatabaseDialog.databaseLookupError=Error accessing central repository",
472 "HashDbImportDatabaseDialog.mustEnterHashSetNameMsg=A hash set name must be entered."
474 private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {
478 if (hashSetNameTextField.getText().isEmpty()) {
479 JOptionPane.showMessageDialog(
this,
480 NbBundle.getMessage(
this.getClass(),
481 "HashDbImportDatabaseDialog.mustEnterHashSetNameMsg"),
482 NbBundle.getMessage(
this.getClass(),
483 "HashDbImportDatabaseDialog.importHashDbErr"),
484 JOptionPane.ERROR_MESSAGE);
488 if (centralRepoRadioButton.isSelected()) {
489 if (readOnlyCheckbox.isSelected() && versionTextField.getText().isEmpty()) {
490 JOptionPane.showMessageDialog(
this,
491 NbBundle.getMessage(
this.getClass(),
492 "HashDbImportDatabaseDialog.missingVersion"),
493 NbBundle.getMessage(
this.getClass(),
494 "HashDbImportDatabaseDialog.importHashDbErr"),
495 JOptionPane.ERROR_MESSAGE);
499 if (selectedOrg == null) {
500 JOptionPane.showMessageDialog(
this,
501 NbBundle.getMessage(
this.getClass(),
502 "HashDbImportDatabaseDialog.missingOrg"),
503 NbBundle.getMessage(
this.getClass(),
504 "HashDbImportDatabaseDialog.importHashDbErr"),
505 JOptionPane.ERROR_MESSAGE);
510 if (selectedFilePath.isEmpty()) {
511 JOptionPane.showMessageDialog(
this,
512 NbBundle.getMessage(
this.getClass(),
513 "HashDbImportDatabaseDialog.mustSelectHashDbFilePathMsg"),
514 NbBundle.getMessage(
this.getClass(),
515 "HashDbImportDatabaseDialog.importHashDbErr"),
516 JOptionPane.ERROR_MESSAGE);
520 File file =
new File(selectedFilePath);
521 if (!file.exists()) {
522 JOptionPane.showMessageDialog(
this,
523 NbBundle.getMessage(
this.getClass(),
524 "HashDbImportDatabaseDialog.hashDbDoesNotExistMsg"),
525 NbBundle.getMessage(
this.getClass(),
526 "HashDbImportDatabaseDialog.importHashDbErr"),
527 JOptionPane.ERROR_MESSAGE);
531 if (saveInUserConfigFolderCheckbox.isSelected()) {
533 String locationInUserConfigDir = Paths.get(PlatformUtil.getUserConfigDirectory(), HashDbCreateDatabaseDialog.HASH_DATABASE_DIR_NAME, hashSetNameTextField.getText(), file.getName()).toString();
535 FileUtils.copyFile(file,
new File(locationInUserConfigDir));
537 selectedFilePath = locationInUserConfigDir;
538 }
catch (IOException ex) {
539 String errorMessage = NbBundle.getMessage(this.getClass(),
"HashDbImportDatabaseDialog.unableToCopyToUserDirMsg", locationInUserConfigDir);
540 Logger.getLogger(HashDbImportDatabaseDialog.class.getName()).log(Level.SEVERE, errorMessage, ex);
541 JOptionPane.showMessageDialog(
this, errorMessage, NbBundle.getMessage(
this.getClass(),
"HashDbImportDatabaseDialog.importHashDbErr"),
542 JOptionPane.ERROR_MESSAGE);
548 if (knownRadioButton.isSelected()) {
549 type = KnownFilesType.KNOWN;
550 }
else if (noChangeRadioButton.isSelected()) {
551 type = KnownFilesType.NO_CHANGE;
553 type = KnownFilesType.KNOWN_BAD;
556 String errorMessage = NbBundle.getMessage(this.getClass(),
557 "HashDbImportDatabaseDialog.errorMessage.failedToOpenHashDbMsg",
559 if (fileTypeRadioButton.isSelected()) {
562 selectedHashDb = HashDbManager.getInstance().addExistingHashDatabaseNoSave(hashSetNameTextField.getText(), selectedFilePath,
true, sendIngestMessagesCheckbox.isSelected(), type);
563 }
catch (HashDbManagerException ex) {
564 Logger.getLogger(HashDbImportDatabaseDialog.class.getName()).log(Level.WARNING, errorMessage, ex);
565 JOptionPane.showMessageDialog(
this,
567 NbBundle.getMessage(this.getClass(),
568 "HashDbImportDatabaseDialog.importHashDbErr"),
569 JOptionPane.ERROR_MESSAGE);
576 if (CentralRepository.getInstance().referenceSetExists(hashSetNameTextField.getText(), versionTextField.getText())) {
577 JOptionPane.showMessageDialog(
this,
578 NbBundle.getMessage(
this.getClass(),
579 "HashDbImportDatabaseDialog.duplicateName"),
580 NbBundle.getMessage(
this.getClass(),
581 "HashDbImportDatabaseDialog.importHashDbErr"),
582 JOptionPane.ERROR_MESSAGE);
585 }
catch (CentralRepoException ex) {
586 Logger.getLogger(HashDbImportDatabaseDialog.class.getName()).log(Level.SEVERE,
"Error looking up reference set", ex);
587 JOptionPane.showMessageDialog(
this,
588 NbBundle.getMessage(
this.getClass(),
589 "HashDbImportDatabaseDialog.databaseLookupError"),
590 NbBundle.getMessage(
this.getClass(),
591 "HashDbImportDatabaseDialog.importHashDbErr"),
592 JOptionPane.ERROR_MESSAGE);
597 if (readOnlyCheckbox.isSelected()) {
598 version = versionTextField.getText();
603 ImportCentralRepoDbProgressDialog progressDialog =
new ImportCentralRepoDbProgressDialog();
604 progressDialog.importFile(hashSetNameTextField.getText(), version,
605 selectedOrg.getOrgID(),
true, sendIngestMessagesCheckbox.isSelected(), type,
606 readOnlyCheckbox.isSelected(), selectedFilePath);
607 selectedHashDb = progressDialog.getDatabase();
613 private void sendIngestMessagesCheckboxActionPerformed(java.awt.event.ActionEvent evt) {
617 private void fileTypeRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {
621 private void centralRepoRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {
625 private void orgButtonActionPerformed(java.awt.event.ActionEvent evt) {
626 ManageOrganizationsDialog dialog =
new ManageOrganizationsDialog();
628 if (dialog.isChanged()) {
633 private void orgComboBoxActionPerformed(java.awt.event.ActionEvent evt) {
634 if (null == orgComboBox.getSelectedItem()) {
637 String orgName = this.orgComboBox.getSelectedItem().toString();
638 for (CentralRepoOrganization
org : orgs) {
639 if (
org.getName().equals(orgName)) {
646 private void readOnlyCheckboxActionPerformed(java.awt.event.ActionEvent evt) {
650 private void noChangeRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {
651 sendIngestMessagesCheckbox.setSelected(KnownFilesType.NO_CHANGE.isDefaultInboxMessages());
652 sendIngestMessagesCheckbox.setEnabled(KnownFilesType.NO_CHANGE.isInboxMessagesAllowed());
656 private javax.swing.ButtonGroup buttonGroup1;
657 private javax.swing.JButton cancelButton;
658 private javax.swing.JRadioButton centralRepoRadioButton;
659 private javax.swing.JTextField databasePathTextField;
660 private javax.swing.JRadioButton fileTypeRadioButton;
661 private javax.swing.JTextField hashSetNameTextField;
662 private javax.swing.JLabel jLabel1;
663 private javax.swing.JLabel jLabel2;
664 private javax.swing.JLabel jLabel3;
665 private javax.swing.JLabel jLabel4;
666 private javax.swing.JRadioButton knownBadRadioButton;
667 private javax.swing.JRadioButton knownRadioButton;
668 private javax.swing.JLabel lbOrg;
669 private javax.swing.JLabel lbVersion;
670 private javax.swing.JRadioButton noChangeRadioButton;
671 private javax.swing.JButton okButton;
672 private javax.swing.JButton openButton;
673 private javax.swing.JButton orgButton;
674 private javax.swing.JComboBox<String> orgComboBox;
675 private javax.swing.JCheckBox readOnlyCheckbox;
676 private javax.swing.JCheckBox saveInUserConfigFolderCheckbox;
677 private javax.swing.JCheckBox sendIngestMessagesCheckbox;
678 private javax.swing.ButtonGroup storageTypeButtonGroup;
679 private javax.swing.JTextField versionTextField;