use of cz.metacentrum.perun.audit.events.UserManagerEvents.UserCreated in project perun by CESNET.
the class UsersManagerBlImpl method createUser.
@Override
public User createUser(PerunSession sess, User user) {
// trim input
if (user.getFirstName() != null)
user.setFirstName(user.getFirstName().trim());
if (user.getLastName() != null)
user.setLastName(user.getLastName().trim());
if (user.getMiddleName() != null)
user.setMiddleName(user.getMiddleName().trim());
if (user.getTitleBefore() != null)
user.setTitleBefore(user.getTitleBefore().trim());
if (user.getTitleAfter() != null)
user.setTitleAfter(user.getTitleAfter().trim());
// Convert empty strings to null
if (user.getFirstName() != null && user.getFirstName().isEmpty())
user.setFirstName(null);
if (user.getLastName() != null && user.getLastName().isEmpty())
user.setLastName(null);
if (user.getMiddleName() != null && user.getMiddleName().isEmpty())
user.setMiddleName(null);
if (user.getTitleBefore() != null && user.getTitleBefore().isEmpty())
user.setTitleBefore(null);
if (user.getTitleAfter() != null && user.getTitleAfter().isEmpty())
user.setTitleAfter(null);
user = getUsersManagerImpl().createUser(sess, user);
getPerunBl().getAuditer().log(sess, new UserCreated(user));
// Add default userExtSource
ExtSource es;
try {
es = getPerunBl().getExtSourcesManagerBl().getExtSourceByName(sess, ExtSourcesManager.EXTSOURCE_NAME_PERUN);
} catch (ExtSourceNotExistsException e1) {
throw new ConsistencyErrorException("Default extSource PERUN must exists! It is created in ExtSourcesManagerImpl.init function.", e1);
}
UserExtSource ues = new UserExtSource(es, 0, String.valueOf(user.getId()));
try {
this.addUserExtSource(sess, user, ues);
} catch (UserExtSourceExistsException e) {
throw new ConsistencyErrorException(e);
}
return user;
}
Aggregations