final String ADD_USER_PROP = "automatically.add.user";
final String DEFAULT_GROUP_PROP = "default.user.group";
if (Boolean.parseBoolean(System.getProperty(ADD_USER_PROP, MCTProperties.DEFAULT_MCT_PROPERTIES.getProperty(ADD_USER_PROP, "false")))) {
// Default to "testUser1" if no user name was ever specified
String userId = whoami != null ? whoami : bundle.getString("DEFAULT_USER"); //NOI18N
Platform platform = PlatformAccess.getPlatform();
// determine if the platform has been initialized
if (platform.getBootstrapComponents().isEmpty()) {
GlobalContext.getGlobalContext().switchUser(new User() {
@Override
public String getDisciplineId() {
return ""; //rather than null, we should return an empty string --Harleigh;Issue127
}
@Override
public User getValidUser(String userID) {
return null;
}
@Override
public String getUserId() {
return whoami;
}
}, null);
platform.getDefaultComponentProvider().createDefaultComponents();
// invoke getting default components again to ensure the platform has been bootstrapped
platform.getBootstrapComponents();
}
AbstractComponent mySandbox = platform.getDefaultComponentProvider().createSandbox(userId);
AbstractComponent dropbox = platform.getDefaultComponentProvider().createDropbox(userId);
String group = System.getProperty(DEFAULT_GROUP_PROP, MCTProperties.DEFAULT_MCT_PROPERTIES.getProperty(DEFAULT_GROUP_PROP, ""));
if (group.isEmpty()) {
throw new MCTRuntimeException("Default group not specified, set the default group in mct.properties using the " + DEFAULT_GROUP_PROP + " property.");
}
platform.getPersistenceProvider().addNewUser(userId, group, mySandbox, dropbox);
currentUser = platform.getPersistenceProvider().getUser(userId);
} else {
throw new MCTRuntimeException("MCT user '" + whoami
+ "' is not in the MCT database. You can load MCT user(s) using MCT's load user tool.");
}
}