Add a default organization when the central repo db is created

This commit is contained in:
Ann Priestman 2017-11-28 11:04:47 -05:00
parent 1761c5afcb
commit 6487af2f57
6 changed files with 72 additions and 13 deletions

View File

@ -37,6 +37,7 @@ public class EamDbUtil {
private final static Logger LOGGER = Logger.getLogger(EamDbUtil.class.getName());
private static final String CENTRAL_REPO_NAME = "CentralRepository";
private static final String CENTRAL_REPO_USE_KEY = "db.useCentralRepo";
private static final String DEFAULT_ORG_NAME = "Not Specified";
/**
* Close the prepared statement.
@ -175,11 +176,51 @@ public class EamDbUtil {
return true;
}
/**
* Check whether the given org is the default organization.
*
* @param org
* @return true if it is the default org, false otherwise
*/
public static boolean isDefaultOrg(EamOrganization org) {
return DEFAULT_ORG_NAME.equals(org.getName());
}
/**
* Add the default organization to the database
*
* @param conn
* @return true if successful, false otherwise
*/
static boolean insertDefaultOrganization(Connection conn) {
if (null == conn) {
return false;
}
PreparedStatement preparedStatement = null;
String sql = "INSERT INTO organizations(org_name, poc_name, poc_email, poc_phone) VALUES (?, ?, ?, ?)";
try {
preparedStatement = conn.prepareStatement(sql);
preparedStatement.setString(1, DEFAULT_ORG_NAME);
preparedStatement.setString(2, "");
preparedStatement.setString(3, "");
preparedStatement.setString(4, "");
preparedStatement.executeUpdate();
} catch (SQLException ex) {
LOGGER.log(Level.SEVERE, "Error adding default organization", ex);
return false;
} finally {
EamDbUtil.closePreparedStatement(preparedStatement);
}
return true;
}
/**
* If the Central Repos use has been enabled.
*
* @return true if the Central Repo may be configured, false if it should
* not be able to be
* not be able to be
*/
public static boolean useCentralRepo() {
return Boolean.parseBoolean(ModuleSettings.getConfigSetting(CENTRAL_REPO_NAME, CENTRAL_REPO_USE_KEY));
@ -190,7 +231,7 @@ public class EamDbUtil {
* configured.
*
* @param centralRepoCheckBoxIsSelected - true if the central repo can be
* used
* used
*/
public static void setUseCentralRepo(boolean centralRepoCheckBoxIsSelected) {
ModuleSettings.setConfigSetting(CENTRAL_REPO_NAME, CENTRAL_REPO_USE_KEY, Boolean.toString(centralRepoCheckBoxIsSelected));

View File

@ -485,7 +485,8 @@ public final class PostgresEamDbSettings {
}
boolean result = EamDbUtil.insertDefaultCorrelationTypes(conn)
&& EamDbUtil.insertSchemaVersion(conn);
&& EamDbUtil.insertSchemaVersion(conn)
&& EamDbUtil.insertDefaultOrganization(conn);
EamDbUtil.closeConnection(conn);
return result;

View File

@ -434,7 +434,8 @@ public final class SqliteEamDbSettings {
}
boolean result = EamDbUtil.insertDefaultCorrelationTypes(conn)
&& EamDbUtil.insertSchemaVersion(conn);
&& EamDbUtil.insertSchemaVersion(conn)
&& EamDbUtil.insertDefaultOrganization(conn);
EamDbUtil.closeConnection(conn);
return result;
}

View File

@ -35,6 +35,7 @@ import org.openide.util.NbBundle.Messages;
import org.openide.windows.WindowManager;
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb;
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException;
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbUtil;
import org.sleuthkit.autopsy.centralrepository.datamodel.EamOrganization;
import org.sleuthkit.autopsy.coreutils.Logger;
@ -72,7 +73,7 @@ public final class ManageOrganizationsDialog extends JDialog {
organizationList.setModel(rulesListModel);
organizationList.addListSelectionListener(new OrganizationListSelectionListener());
populateList();
setButtonsEnabled(organizationList.getSelectedValue() != null);
setButtonsEnabled(organizationList.getSelectedValue());
newOrg = null;
} catch (EamDbException ex) {
Exceptions.printStackTrace(ex);
@ -421,9 +422,15 @@ public final class ManageOrganizationsDialog extends JDialog {
return newOrg;
}
private void setButtonsEnabled(boolean isSelected) {
editButton.setEnabled(isSelected);
deleteButton.setEnabled(isSelected);
private void setButtonsEnabled(EamOrganization selectedOrg) {
boolean isSelected = (selectedOrg != null);
boolean isDefaultOrg = false;
if(selectedOrg != null){
isDefaultOrg = EamDbUtil.isDefaultOrg(selectedOrg);
}
editButton.setEnabled(isSelected && (! isDefaultOrg));
deleteButton.setEnabled(isSelected && (! isDefaultOrg));
}
/**
@ -436,9 +443,8 @@ public final class ManageOrganizationsDialog extends JDialog {
if (e.getValueIsAdjusting()) {
return;
}
EamOrganization selected = organizationList.getSelectedValue();
boolean isSelected = (selected != null);
setButtonsEnabled(isSelected);
EamOrganization selected = organizationList.getSelectedValue();
setButtonsEnabled(selected);
if (selected != null) {
orgNameTextField.setText(selected.getName());
pocNameTextField.setText(selected.getPocName());

View File

@ -33,6 +33,7 @@ import org.openide.util.NbBundle;
import org.openide.windows.WindowManager;
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb;
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException;
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbUtil;
import org.sleuthkit.autopsy.centralrepository.datamodel.EamOrganization;
import org.sleuthkit.autopsy.centralrepository.datamodel.EamGlobalSet;
import org.sleuthkit.autopsy.centralrepository.optionspanel.ManageOrganizationsDialog;
@ -154,8 +155,12 @@ final class HashDbCreateDatabaseDialog extends javax.swing.JDialog {
orgs = dbManager.getOrganizations();
orgs.forEach((org) -> {
orgComboBox.addItem(org.getName());
if(EamDbUtil.isDefaultOrg(org)){
orgComboBox.setSelectedItem(org.getName());
selectedOrg = org;
}
});
if (!orgs.isEmpty()) {
if ((selectedOrg == null) && (!orgs.isEmpty())) {
selectedOrg = orgs.get(0);
}
} catch (EamDbException ex) {

View File

@ -34,6 +34,7 @@ import org.openide.util.NbBundle;
import org.openide.windows.WindowManager;
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDb;
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbException;
import org.sleuthkit.autopsy.centralrepository.datamodel.EamDbUtil;
import org.sleuthkit.autopsy.centralrepository.datamodel.EamOrganization;
import org.sleuthkit.autopsy.centralrepository.optionspanel.ManageOrganizationsDialog;
import org.sleuthkit.autopsy.coreutils.Logger;
@ -148,8 +149,12 @@ final class HashDbImportDatabaseDialog extends javax.swing.JDialog {
orgs = dbManager.getOrganizations();
orgs.forEach((org) -> {
orgComboBox.addItem(org.getName());
if(EamDbUtil.isDefaultOrg(org)){
orgComboBox.setSelectedItem(org.getName());
selectedOrg = org;
}
});
if (!orgs.isEmpty()) {
if ((selectedOrg == null) && (!orgs.isEmpty())) {
selectedOrg = orgs.get(0);
}
} catch (EamDbException ex) {