+ "' is empty and therefore not valid. Cannot determine "
+ "current DJ when authentication is failing.");
}
logger.trace("Looking up current DJ based on identity {}", loginName);
JizzDj dj = jizzDjDao.findDjByLoginName(loginName);
// If this is a new DJ then need to create them
if (dj == null) {
logger.debug("Creating new DJ with identity {}", loginName);
dj = new JizzDj();
JizzStation station = jizzStationDao.getPrimaryStation();
if (station == null) {
throw new RuntimeException("No primary station - a DJ cannot "
+ "be created until Jizz has been initialised");
}
dj.setStation(station);
// Set DJ's defaults
dj.setLocale(station.getLocale());
// Make up a new name for this DJ
String djName = JizzDjNameMaker.getInstance().newNamePlease(
JizzServiceUtils.forLanguageTag(dj.getLocale()));
dj.setName(djName);
// Add the current login info for this DJ
JizzDjLogin login = new JizzDjLogin();
login.setDj(dj);
login.setLoginName(loginName);
Set<JizzDjLogin> logins = new HashSet<JizzDjLogin>();
logins.add(login);
dj.setLogins(logins);
dj = jizzDjDao.createOrUpdateDj(dj);
logger.debug("Created new DJ {}", dj);
}