SessiondataDao sessionDao = getBean(SessiondataDao.class);
Sessiondata sd = sessionDao.getSessionByHash(soapLogin.getSessionHash());
if (sd != null && sd.getSessionXml() != null) {
RemoteSessionObject remoteUser = RemoteSessionObject.fromXml(sd.getSessionXml());
if (remoteUser != null && !Strings.isEmpty(remoteUser.getExternalUserId())) {
AdminUserDao userDao = getBean(AdminUserDao.class);
User user = userDao.getExternalUser(remoteUser.getExternalUserId(), remoteUser.getExternalUserType());
if (user == null) {
user = userDao.getNewUserInstance(null);
user.setFirstname(remoteUser.getFirstname());
user.setLastname(remoteUser.getLastname());
user.setLogin(remoteUser.getUsername()); //FIXME check if login UNIQUE
user.setExternalUserId(remoteUser.getExternalUserId());
user.setExternalUserType(remoteUser.getExternalUserType());
user.getAdresses().setEmail(remoteUser.getEmail());
user.setPictureuri(remoteUser.getPictureUrl());
} else {
user.setFirstname(remoteUser.getFirstname());
user.setLastname(remoteUser.getLastname());
user.setPictureuri(remoteUser.getPictureUrl());
}
user = userDao.update(user, null);
soapLogin.setUsed(true);
soapLogin.setUseDate(new Date());
//soapLogin.setClientURL(clientURL); //FIXME
soapDao.update(soapLogin);