use database connectivity check

This commit is contained in:
Karl Mortensen 2015-03-31 16:54:59 -04:00
parent 415c221f8a
commit d6e2f26dc9
2 changed files with 24 additions and 11 deletions

View File

@ -232,7 +232,7 @@ public class Case implements SleuthkitCase.ErrorObserver {
* *
*/ */
private static void changeCase(Case newCase) { private static void changeCase(Case newCase) {
/// KDM ensure this handles both databases properly
// close the existing case // close the existing case
Case oldCase = Case.currentCase; Case oldCase = Case.currentCase;
Case.currentCase = null; Case.currentCase = null;
@ -345,14 +345,21 @@ public class Case implements SleuthkitCase.ErrorObserver {
SleuthkitCase db = null; SleuthkitCase db = null;
try { try {
db = SleuthkitCase.newCase(dbName); /// KDM this is where newcasewizardpanel2 calls. if(isRemote==true)
{
db = SleuthkitCase.newCase(dbName, UserPreferences.getDatabaseConnectionInfo());
}
else
{
db = SleuthkitCase.newCase(dbName);
}
} catch (TskCoreException ex) { } catch (TskCoreException ex) {
logger.log(Level.SEVERE, "Error creating a case: " + caseName + " in dir " + caseDir, ex); //NON-NLS logger.log(Level.SEVERE, "Error creating a case: " + caseName + " in dir " + caseDir, ex); //NON-NLS
throw new CaseActionException( throw new CaseActionException(
NbBundle.getMessage(Case.class, "Case.create.exception.msg", caseName, caseDir), ex); NbBundle.getMessage(Case.class, "Case.create.exception.msg", caseName, caseDir), ex);
} }
Case newCase = new Case(caseName, caseNumber, examiner, configFilePath, xmlcm, db, isRemote); Case newCase = new Case(caseName, caseNumber, examiner, configFilePath, xmlcm, db, isRemote); /// KDM TODO
changeCase(newCase); changeCase(newCase);
} }
@ -387,7 +394,7 @@ public class Case implements SleuthkitCase.ErrorObserver {
} }
String dbPath = caseDir + File.separator + "autopsy.db"; //NON-NLS String dbPath = caseDir + File.separator + "autopsy.db"; //NON-NLS
db = SleuthkitCase.openCase(dbPath); // KDM db = SleuthkitCase.openCase(dbPath);
if (null != db.getBackupDatabasePath()) { if (null != db.getBackupDatabasePath()) {
JOptionPane.showMessageDialog(null, JOptionPane.showMessageDialog(null,
NbBundle.getMessage(Case.class, "Case.open.msgDlg.updated.msg", NbBundle.getMessage(Case.class, "Case.open.msgDlg.updated.msg",
@ -398,8 +405,7 @@ public class Case implements SleuthkitCase.ErrorObserver {
} }
else { else {
isRemote=true; isRemote=true;
CaseDbConnectionInfo info = UserPreferences.getDatabaseConnectionInfo(); db = SleuthkitCase.openCase(xmlcm.getDatabaseName(), UserPreferences.getDatabaseConnectionInfo());
db = SleuthkitCase.openCase(xmlcm.getDatabaseName(), info); // KDM
if (null != db.getBackupDatabasePath()) { if (null != db.getBackupDatabasePath()) {
JOptionPane.showMessageDialog(null, JOptionPane.showMessageDialog(null,
NbBundle.getMessage(Case.class, "Case.open.msgDlg.updated.msg", NbBundle.getMessage(Case.class, "Case.open.msgDlg.updated.msg",
@ -1268,4 +1274,15 @@ public class Case implements SleuthkitCase.ErrorObserver {
public boolean isRemote() { public boolean isRemote() {
return isRemote; return isRemote;
} }
/**
* Returns true if the current database settings are sufficient to talk to
* the PostgreSql database
* @return
*/
public static boolean externalDatabaseSettingsValid() {
CaseDbConnectionInfo info = UserPreferences.getDatabaseConnectionInfo();
return SleuthkitCase.settingsValid(info);
}
} }

View File

@ -47,9 +47,6 @@ final class NewCaseVisualPanel1 extends JPanel implements DocumentListener {
caseNameTextField.getDocument().addDocumentListener(this); caseNameTextField.getDocument().addDocumentListener(this);
caseParentDirTextField.getDocument().addDocumentListener(this); caseParentDirTextField.getDocument().addDocumentListener(this);
CaseDbConnectionInfo info = UserPreferences.getDatabaseConnectionInfo(); CaseDbConnectionInfo info = UserPreferences.getDatabaseConnectionInfo();
/// KDM TODO: When we have a way to validate that we can actually talk to the remote DB (settings are correct), use it.
/// The following will be set true or false depending upon if we can talk to it.
boolean remoteDatabaseConnectionSettingsOkay = true;
if (info.getDbType() == CaseDbConnectionInfo.DbType.UNKNOWN) { if (info.getDbType() == CaseDbConnectionInfo.DbType.UNKNOWN) {
rbLocalCase.setSelected(true); rbLocalCase.setSelected(true);
rbLocalCase.setEnabled(false); rbLocalCase.setEnabled(false);
@ -63,7 +60,7 @@ final class NewCaseVisualPanel1 extends JPanel implements DocumentListener {
rbSharedCase.setEnabled(true); rbSharedCase.setEnabled(true);
rbLocalCase.setVisible(true); rbLocalCase.setVisible(true);
rbSharedCase.setVisible(true); rbSharedCase.setVisible(true);
if (true == remoteDatabaseConnectionSettingsOkay) { if (true == Case.externalDatabaseSettingsValid()) {
if (UserPreferences.newCaseType() == CaseType.LOCAL.ordinal()) { if (UserPreferences.newCaseType() == CaseType.LOCAL.ordinal()) {
rbLocalCase.setSelected(true); rbLocalCase.setSelected(true);
} else { } else {
@ -123,7 +120,6 @@ final class NewCaseVisualPanel1 extends JPanel implements DocumentListener {
*/ */
public CaseType getCaseType() { public CaseType getCaseType() {
CaseType value = CaseType.LOCAL; CaseType value = CaseType.LOCAL;
/// Save the selected item out to the preferences file
if (rbLocalCase.isSelected()) { if (rbLocalCase.isSelected()) {
value = CaseType.LOCAL; value = CaseType.LOCAL;
} else if (rbSharedCase.isSelected()) { } else if (rbSharedCase.isSelected()) {