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() + "'");
}
}
Aggregations