Search in sources :

Example 1 with UserUndeleted

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

the class UndeleteUserDatabaseAction method execute.

@Override
public Boolean execute() throws UserException, BimserverDatabaseException, BimserverLockConflictException {
    User actingUser = getUserByUoid(authorization.getUoid());
    if (actingUser.getUserType() != UserType.ADMIN) {
        throw new UserException("Only administrators can undelete users");
    }
    final User user = getUserByUoid(uoid);
    if (user == null) {
        throw new UserException("No User with oid " + uoid + " found");
    }
    final UserUndeleted userUndeleted = getDatabaseSession().create(UserUndeleted.class);
    userUndeleted.setAccessMethod(getAccessMethod());
    userUndeleted.setDate(new Date());
    userUndeleted.setExecutor(actingUser);
    userUndeleted.setUser(user);
    getDatabaseSession().addPostCommitAction(new PostCommitAction() {

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

Aggregations

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