Search in sources :

Example 1 with UserChanged

use of org.bimserver.models.log.UserChanged in project BIMserver by opensourceBIM.

the class ChangeUserTypeDatabaseAction method execute.

@Override
public Void execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    User actingUser = getUserByUoid(authorization.getUoid());
    if (actingUser.getUserType() != UserType.ADMIN) {
        throw new UserException("Only admin users can change other user's types");
    }
    User user = getUserByUoid(uoid);
    if (user.getUserType() == UserType.SYSTEM) {
        throw new UserException("Type of system user cannot be changed");
    }
    user.setUserType(UserType.get(userType.getOrdinal()));
    final UserChanged userChanged = getDatabaseSession().create(UserChanged.class);
    userChanged.setAccessMethod(getAccessMethod());
    userChanged.setDate(new Date());
    userChanged.setExecutor(actingUser);
    userChanged.setUser(user);
    getDatabaseSession().addPostCommitAction(new PostCommitAction() {

        @Override
        public void execute() throws UserException {
            bimServer.getNotificationsManager().notify(new SConverter().convertToSObject(userChanged));
        }
    });
    getDatabaseSession().store(user);
    return null;
}
Also used : User(org.bimserver.models.store.User) SConverter(org.bimserver.interfaces.SConverter) PostCommitAction(org.bimserver.database.PostCommitAction) UserException(org.bimserver.shared.exceptions.UserException) Date(java.util.Date) UserChanged(org.bimserver.models.log.UserChanged)

Aggregations

Date (java.util.Date)1 PostCommitAction (org.bimserver.database.PostCommitAction)1 SConverter (org.bimserver.interfaces.SConverter)1 UserChanged (org.bimserver.models.log.UserChanged)1 User (org.bimserver.models.store.User)1 UserException (org.bimserver.shared.exceptions.UserException)1