Search in sources :

Example 1 with UserAddedToProject

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

the class AddUserToProjectDatabaseAction method execute.

@Override
public Boolean execute() throws UserException, BimserverDatabaseException, BimserverLockConflictException {
    final Project project = getProjectByPoid(poid);
    User actingUser = getUserByUoid(authorization.getUoid());
    if (authorization.hasRightsOnProject(actingUser, project)) {
        User user = getUserByUoid(uoid);
        project.getHasAuthorizedUsers().add(user);
        user.getHasRightsOn().add(project);
        final UserAddedToProject userAddedToProject = getDatabaseSession().create(UserAddedToProject.class);
        userAddedToProject.setExecutor(actingUser);
        userAddedToProject.setDate(new Date());
        userAddedToProject.setAccessMethod(getAccessMethod());
        userAddedToProject.setUser(user);
        userAddedToProject.setProject(project);
        getDatabaseSession().addPostCommitAction(new PostCommitAction() {

            @Override
            public void execute() throws UserException {
                bimServer.getNotificationsManager().notify(new SConverter().convertToSObject(userAddedToProject));
            }
        });
        getDatabaseSession().store(user);
        getDatabaseSession().store(project);
        return true;
    } else {
        throw new UserException("User has no rights to grant permission on '" + project.getName() + "'");
    }
}
Also used : UserAddedToProject(org.bimserver.models.log.UserAddedToProject) Project(org.bimserver.models.store.Project) User(org.bimserver.models.store.User) SConverter(org.bimserver.interfaces.SConverter) PostCommitAction(org.bimserver.database.PostCommitAction) UserAddedToProject(org.bimserver.models.log.UserAddedToProject) 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 UserAddedToProject (org.bimserver.models.log.UserAddedToProject)1 Project (org.bimserver.models.store.Project)1 User (org.bimserver.models.store.User)1 UserException (org.bimserver.shared.exceptions.UserException)1