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();
186 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
188 org.openide.awt.Mnemonics.setLocalizedText(okButton,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.okButton.text"));
189 okButton.addActionListener(
new java.awt.event.ActionListener() {
190 public void actionPerformed(java.awt.event.ActionEvent evt) {
191 okButtonActionPerformed(evt);
195 org.openide.awt.Mnemonics.setLocalizedText(cancelButton,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.cancelButton.text"));
196 cancelButton.addActionListener(
new java.awt.event.ActionListener() {
197 public void actionPerformed(java.awt.event.ActionEvent evt) {
198 cancelButtonActionPerformed(evt);
202 databasePathTextField.setEditable(
false);
203 databasePathTextField.setText(
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.databasePathTextField.text"));
205 org.openide.awt.Mnemonics.setLocalizedText(openButton,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.openButton.text"));
206 openButton.addActionListener(
new java.awt.event.ActionListener() {
207 public void actionPerformed(java.awt.event.ActionEvent evt) {
208 openButtonActionPerformed(evt);
212 buttonGroup1.add(knownRadioButton);
213 org.openide.awt.Mnemonics.setLocalizedText(knownRadioButton,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.knownRadioButton.text"));
214 knownRadioButton.addActionListener(
new java.awt.event.ActionListener() {
215 public void actionPerformed(java.awt.event.ActionEvent evt) {
216 knownRadioButtonActionPerformed(evt);
220 buttonGroup1.add(knownBadRadioButton);
221 knownBadRadioButton.setSelected(
true);
222 org.openide.awt.Mnemonics.setLocalizedText(knownBadRadioButton,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.knownBadRadioButton.text"));
223 knownBadRadioButton.addActionListener(
new java.awt.event.ActionListener() {
224 public void actionPerformed(java.awt.event.ActionEvent evt) {
225 knownBadRadioButtonActionPerformed(evt);
229 org.openide.awt.Mnemonics.setLocalizedText(jLabel1,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.jLabel1.text"));
231 hashSetNameTextField.setText(
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.hashSetNameTextField.text"));
233 org.openide.awt.Mnemonics.setLocalizedText(jLabel2,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.jLabel2.text"));
235 sendIngestMessagesCheckbox.setSelected(
true);
236 org.openide.awt.Mnemonics.setLocalizedText(sendIngestMessagesCheckbox,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.sendIngestMessagesCheckbox.text"));
237 sendIngestMessagesCheckbox.addActionListener(
new java.awt.event.ActionListener() {
238 public void actionPerformed(java.awt.event.ActionEvent evt) {
239 sendIngestMessagesCheckboxActionPerformed(evt);
243 org.openide.awt.Mnemonics.setLocalizedText(jLabel3,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.jLabel3.text"));
245 org.openide.awt.Mnemonics.setLocalizedText(lbVersion,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.lbVersion.text"));
247 versionTextField.setText(
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.versionTextField.text"));
249 org.openide.awt.Mnemonics.setLocalizedText(lbOrg,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.lbOrg.text"));
251 orgComboBox.addActionListener(
new java.awt.event.ActionListener() {
252 public void actionPerformed(java.awt.event.ActionEvent evt) {
253 orgComboBoxActionPerformed(evt);
257 org.openide.awt.Mnemonics.setLocalizedText(orgButton,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.orgButton.text"));
258 orgButton.addActionListener(
new java.awt.event.ActionListener() {
259 public void actionPerformed(java.awt.event.ActionEvent evt) {
260 orgButtonActionPerformed(evt);
264 readOnlyCheckbox.setSelected(
true);
265 org.openide.awt.Mnemonics.setLocalizedText(readOnlyCheckbox,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.readOnlyCheckbox.text"));
266 readOnlyCheckbox.addActionListener(
new java.awt.event.ActionListener() {
267 public void actionPerformed(java.awt.event.ActionEvent evt) {
268 readOnlyCheckboxActionPerformed(evt);
272 storageTypeButtonGroup.add(fileTypeRadioButton);
273 fileTypeRadioButton.setSelected(
true);
274 org.openide.awt.Mnemonics.setLocalizedText(fileTypeRadioButton,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.fileTypeRadioButton.text"));
275 fileTypeRadioButton.addActionListener(
new java.awt.event.ActionListener() {
276 public void actionPerformed(java.awt.event.ActionEvent evt) {
277 fileTypeRadioButtonActionPerformed(evt);
281 storageTypeButtonGroup.add(centralRepoRadioButton);
282 org.openide.awt.Mnemonics.setLocalizedText(centralRepoRadioButton,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.centralRepoRadioButton.text"));
283 centralRepoRadioButton.addActionListener(
new java.awt.event.ActionListener() {
284 public void actionPerformed(java.awt.event.ActionEvent evt) {
285 centralRepoRadioButtonActionPerformed(evt);
289 org.openide.awt.Mnemonics.setLocalizedText(jLabel4,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.jLabel4.text"));
291 org.openide.awt.Mnemonics.setLocalizedText(saveInUserConfigFolderCheckbox,
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.saveInUserConfigFolderCheckbox.text"));
292 saveInUserConfigFolderCheckbox.setToolTipText(
org.openide.util.NbBundle.getMessage(HashDbImportDatabaseDialog.class,
"HashDbImportDatabaseDialog.saveInUserConfigFolderCheckbox.toolTipText"));
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()
319 .addComponent(sendIngestMessagesCheckbox)
320 .addGap(0, 0, Short.MAX_VALUE))
321 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
323 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
324 .addComponent(orgComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
325 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
326 .addComponent(orgButton))
327 .addGroup(layout.createSequentialGroup()
328 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
329 .addComponent(jLabel1)
330 .addComponent(lbVersion))
332 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
333 .addComponent(versionTextField)
334 .addComponent(hashSetNameTextField)))
335 .addGroup(layout.createSequentialGroup()
336 .addGap(0, 0, Short.MAX_VALUE)
337 .addComponent(okButton)))
338 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
339 .addComponent(cancelButton))
340 .addGroup(layout.createSequentialGroup()
341 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
342 .addComponent(saveInUserConfigFolderCheckbox)
343 .addComponent(jLabel2)
344 .addComponent(readOnlyCheckbox)
345 .addGroup(layout.createSequentialGroup()
347 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
348 .addComponent(knownRadioButton)
349 .addComponent(knownBadRadioButton))))
350 .addGap(0, 0, Short.MAX_VALUE)))
354 layout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
new java.awt.Component[] {cancelButton, okButton});
356 layout.setVerticalGroup(
357 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
358 .addGroup(layout.createSequentialGroup()
360 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
361 .addComponent(databasePathTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
362 .addComponent(jLabel3)
363 .addComponent(openButton))
364 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
365 .addGroup(layout.createSequentialGroup()
366 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
367 .addComponent(fileTypeRadioButton)
368 .addComponent(centralRepoRadioButton)
369 .addComponent(jLabel4))
370 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
371 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
372 .addComponent(jLabel1)
373 .addComponent(hashSetNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
374 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
375 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
376 .addComponent(lbVersion)
377 .addComponent(versionTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
379 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
380 .addComponent(orgButton)
381 .addComponent(orgComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
382 .addComponent(lbOrg))
383 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
384 .addComponent(jLabel2)
385 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
386 .addComponent(knownRadioButton)
387 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
388 .addComponent(knownBadRadioButton)
389 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
390 .addComponent(readOnlyCheckbox)
391 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
392 .addComponent(sendIngestMessagesCheckbox)
393 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
394 .addComponent(saveInUserConfigFolderCheckbox)
395 .addGap(0, 29, Short.MAX_VALUE))
396 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
397 .addGap(0, 0, Short.MAX_VALUE)
398 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
399 .addComponent(cancelButton)
400 .addComponent(okButton))))
407 private void openButtonActionPerformed(java.awt.event.ActionEvent evt) {
408 String lastBaseDirectory = Paths.get(PlatformUtil.getUserConfigDirectory(), HashDbCreateDatabaseDialog.HASH_DATABASE_DIR_NAME).toString();
409 if (ModuleSettings.settingExists(ModuleSettings.MAIN_SETTINGS, LAST_FILE_PATH_KEY)) {
410 lastBaseDirectory = ModuleSettings.getConfigSetting(ModuleSettings.MAIN_SETTINGS, LAST_FILE_PATH_KEY);
412 File hashDbFolder =
new File(lastBaseDirectory);
414 if (!hashDbFolder.exists()) {
415 hashDbFolder.mkdir();
417 fileChooser.setCurrentDirectory(hashDbFolder);
418 if (fileChooser.showOpenDialog(
this) == JFileChooser.APPROVE_OPTION) {
419 File databaseFile = fileChooser.getSelectedFile();
421 selectedFilePath = databaseFile.getCanonicalPath();
422 databasePathTextField.setText(shortenPath(selectedFilePath));
423 hashSetNameTextField.setText(FilenameUtils.removeExtension(databaseFile.getName()));
424 if (hashSetNameTextField.getText().toLowerCase().contains(
"nsrl")) {
425 knownRadioButton.setSelected(
true);
426 knownRadioButtonActionPerformed(null);
428 ModuleSettings.setConfigSetting(ModuleSettings.MAIN_SETTINGS, LAST_FILE_PATH_KEY, databaseFile.getParent());
429 }
catch (IOException ex) {
430 Logger.getLogger(HashDbImportDatabaseDialog.class.getName()).log(Level.SEVERE,
"Failed to get path of selected hash set", ex);
431 JOptionPane.showMessageDialog(
this,
432 NbBundle.getMessage(
this.getClass(),
433 "HashDbImportDatabaseDialog.failedToGetDbPathMsg"));
438 private void knownRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {
439 sendIngestMessagesCheckbox.setSelected(
false);
440 sendIngestMessagesCheckbox.setEnabled(
false);
443 private void knownBadRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {
444 sendIngestMessagesCheckbox.setSelected(
true);
445 sendIngestMessagesCheckbox.setEnabled(
true);
448 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
452 @NbBundle.Messages({
"HashDbImportDatabaseDialog.missingVersion=A version must be entered",
453 "HashDbImportDatabaseDialog.missingOrg=An organization must be selected",
454 "HashDbImportDatabaseDialog.duplicateName=A hashset with this name and version already exists",
455 "HashDbImportDatabaseDialog.databaseLookupError=Error accessing central repository",
456 "HashDbImportDatabaseDialog.mustEnterHashSetNameMsg=A hash set name must be entered."
458 private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {
462 if (hashSetNameTextField.getText().isEmpty()) {
463 JOptionPane.showMessageDialog(
this,
464 NbBundle.getMessage(
this.getClass(),
465 "HashDbImportDatabaseDialog.mustEnterHashSetNameMsg"),
466 NbBundle.getMessage(
this.getClass(),
467 "HashDbImportDatabaseDialog.importHashDbErr"),
468 JOptionPane.ERROR_MESSAGE);
472 if (centralRepoRadioButton.isSelected()) {
473 if (readOnlyCheckbox.isSelected() && versionTextField.getText().isEmpty()) {
474 JOptionPane.showMessageDialog(
this,
475 NbBundle.getMessage(
this.getClass(),
476 "HashDbImportDatabaseDialog.missingVersion"),
477 NbBundle.getMessage(
this.getClass(),
478 "HashDbImportDatabaseDialog.importHashDbErr"),
479 JOptionPane.ERROR_MESSAGE);
483 if (selectedOrg == null) {
484 JOptionPane.showMessageDialog(
this,
485 NbBundle.getMessage(
this.getClass(),
486 "HashDbImportDatabaseDialog.missingOrg"),
487 NbBundle.getMessage(
this.getClass(),
488 "HashDbImportDatabaseDialog.importHashDbErr"),
489 JOptionPane.ERROR_MESSAGE);
494 if (selectedFilePath.isEmpty()) {
495 JOptionPane.showMessageDialog(
this,
496 NbBundle.getMessage(
this.getClass(),
497 "HashDbImportDatabaseDialog.mustSelectHashDbFilePathMsg"),
498 NbBundle.getMessage(
this.getClass(),
499 "HashDbImportDatabaseDialog.importHashDbErr"),
500 JOptionPane.ERROR_MESSAGE);
504 File file =
new File(selectedFilePath);
505 if (!file.exists()) {
506 JOptionPane.showMessageDialog(
this,
507 NbBundle.getMessage(
this.getClass(),
508 "HashDbImportDatabaseDialog.hashDbDoesNotExistMsg"),
509 NbBundle.getMessage(
this.getClass(),
510 "HashDbImportDatabaseDialog.importHashDbErr"),
511 JOptionPane.ERROR_MESSAGE);
515 if (saveInUserConfigFolderCheckbox.isSelected()) {
517 String locationInUserConfigDir = Paths.get(PlatformUtil.getUserConfigDirectory(), HashDbCreateDatabaseDialog.HASH_DATABASE_DIR_NAME, hashSetNameTextField.getText(), file.getName()).toString();
519 FileUtils.copyFile(file,
new File(locationInUserConfigDir));
521 selectedFilePath = locationInUserConfigDir;
522 }
catch (IOException ex) {
523 String errorMessage = NbBundle.getMessage(this.getClass(),
"HashDbImportDatabaseDialog.unableToCopyToUserDirMsg", locationInUserConfigDir);
524 Logger.getLogger(HashDbImportDatabaseDialog.class.getName()).log(Level.SEVERE, errorMessage, ex);
525 JOptionPane.showMessageDialog(
this, errorMessage, NbBundle.getMessage(
this.getClass(),
"HashDbImportDatabaseDialog.importHashDbErr"),
526 JOptionPane.ERROR_MESSAGE);
532 if (knownRadioButton.isSelected()) {
533 type = KnownFilesType.KNOWN;
535 type = KnownFilesType.KNOWN_BAD;
538 String errorMessage = NbBundle.getMessage(this.getClass(),
539 "HashDbImportDatabaseDialog.errorMessage.failedToOpenHashDbMsg",
541 if (fileTypeRadioButton.isSelected()) {
544 selectedHashDb = HashDbManager.getInstance().addExistingHashDatabaseNoSave(hashSetNameTextField.getText(), selectedFilePath,
true, sendIngestMessagesCheckbox.isSelected(), type);
545 }
catch (HashDbManagerException ex) {
546 Logger.getLogger(HashDbImportDatabaseDialog.class.getName()).log(Level.WARNING, errorMessage, ex);
547 JOptionPane.showMessageDialog(
this,
549 NbBundle.getMessage(this.getClass(),
550 "HashDbImportDatabaseDialog.importHashDbErr"),
551 JOptionPane.ERROR_MESSAGE);
558 if (CentralRepository.getInstance().referenceSetExists(hashSetNameTextField.getText(), versionTextField.getText())) {
559 JOptionPane.showMessageDialog(
this,
560 NbBundle.getMessage(
this.getClass(),
561 "HashDbImportDatabaseDialog.duplicateName"),
562 NbBundle.getMessage(
this.getClass(),
563 "HashDbImportDatabaseDialog.importHashDbErr"),
564 JOptionPane.ERROR_MESSAGE);
567 }
catch (CentralRepoException ex) {
568 Logger.getLogger(HashDbImportDatabaseDialog.class.getName()).log(Level.SEVERE,
"Error looking up reference set", ex);
569 JOptionPane.showMessageDialog(
this,
570 NbBundle.getMessage(
this.getClass(),
571 "HashDbImportDatabaseDialog.databaseLookupError"),
572 NbBundle.getMessage(
this.getClass(),
573 "HashDbImportDatabaseDialog.importHashDbErr"),
574 JOptionPane.ERROR_MESSAGE);
579 if (readOnlyCheckbox.isSelected()) {
580 version = versionTextField.getText();
585 ImportCentralRepoDbProgressDialog progressDialog =
new ImportCentralRepoDbProgressDialog();
586 progressDialog.importFile(hashSetNameTextField.getText(), version,
587 selectedOrg.getOrgID(),
true, sendIngestMessagesCheckbox.isSelected(), type,
588 readOnlyCheckbox.isSelected(), selectedFilePath);
589 selectedHashDb = progressDialog.getDatabase();
595 private void sendIngestMessagesCheckboxActionPerformed(java.awt.event.ActionEvent evt) {
599 private void fileTypeRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {
603 private void centralRepoRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {
607 private void orgButtonActionPerformed(java.awt.event.ActionEvent evt) {
608 ManageOrganizationsDialog dialog =
new ManageOrganizationsDialog();
610 if (dialog.isChanged()) {
615 private void orgComboBoxActionPerformed(java.awt.event.ActionEvent evt) {
616 if (null == orgComboBox.getSelectedItem()) {
619 String orgName = this.orgComboBox.getSelectedItem().toString();
620 for (CentralRepoOrganization
org : orgs) {
621 if (
org.getName().equals(orgName)) {
628 private void readOnlyCheckboxActionPerformed(java.awt.event.ActionEvent evt) {
633 private javax.swing.ButtonGroup buttonGroup1;
634 private javax.swing.JButton cancelButton;
635 private javax.swing.JRadioButton centralRepoRadioButton;
636 private javax.swing.JTextField databasePathTextField;
637 private javax.swing.JRadioButton fileTypeRadioButton;
638 private javax.swing.JTextField hashSetNameTextField;
639 private javax.swing.JLabel jLabel1;
640 private javax.swing.JLabel jLabel2;
641 private javax.swing.JLabel jLabel3;
642 private javax.swing.JLabel jLabel4;
643 private javax.swing.JRadioButton knownBadRadioButton;
644 private javax.swing.JRadioButton knownRadioButton;
645 private javax.swing.JLabel lbOrg;
646 private javax.swing.JLabel lbVersion;
647 private javax.swing.JButton okButton;
648 private javax.swing.JButton openButton;
649 private javax.swing.JButton orgButton;
650 private javax.swing.JComboBox<String> orgComboBox;
651 private javax.swing.JCheckBox readOnlyCheckbox;
652 private javax.swing.JCheckBox saveInUserConfigFolderCheckbox;
653 private javax.swing.JCheckBox sendIngestMessagesCheckbox;
654 private javax.swing.ButtonGroup storageTypeButtonGroup;
655 private javax.swing.JTextField versionTextField;