Search in sources :

Example 1 with UserCreated

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;
}
Also used : UserExtSourceExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) RichUserExtSource(cz.metacentrum.perun.core.api.RichUserExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) UserCreated(cz.metacentrum.perun.audit.events.UserManagerEvents.UserCreated) RichUserExtSource(cz.metacentrum.perun.core.api.RichUserExtSource) ExtSource(cz.metacentrum.perun.core.api.ExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) ExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException) UserExtSourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceNotExistsException)

Aggregations

UserCreated (cz.metacentrum.perun.audit.events.UserManagerEvents.UserCreated)1 ExtSource (cz.metacentrum.perun.core.api.ExtSource)1 RichUserExtSource (cz.metacentrum.perun.core.api.RichUserExtSource)1 UserExtSource (cz.metacentrum.perun.core.api.UserExtSource)1 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)1 ExtSourceNotExistsException (cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException)1 UserExtSourceExistsException (cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException)1 UserExtSourceNotExistsException (cz.metacentrum.perun.core.api.exceptions.UserExtSourceNotExistsException)1