2013-03-28 17:07:37 +01:00
|
|
|
package com.commafeed.backend.dao;
|
|
|
|
|
|
2013-03-30 09:22:49 +01:00
|
|
|
import java.util.List;
|
2013-03-29 12:59:21 +01:00
|
|
|
import java.util.Set;
|
2014-12-12 10:06:23 +01:00
|
|
|
import java.util.stream.Collectors;
|
2013-03-28 17:07:37 +01:00
|
|
|
|
2014-08-17 14:16:30 +02:00
|
|
|
import javax.inject.Inject;
|
|
|
|
|
import javax.inject.Singleton;
|
|
|
|
|
|
2014-08-08 16:49:02 +02:00
|
|
|
import org.hibernate.SessionFactory;
|
2013-03-28 17:07:37 +01:00
|
|
|
|
2014-08-08 16:49:02 +02:00
|
|
|
import com.commafeed.backend.model.QUserRole;
|
2013-03-28 17:07:37 +01:00
|
|
|
import com.commafeed.backend.model.User;
|
|
|
|
|
import com.commafeed.backend.model.UserRole;
|
2013-03-30 19:06:32 +01:00
|
|
|
import com.commafeed.backend.model.UserRole.Role;
|
2013-03-28 17:07:37 +01:00
|
|
|
|
2014-08-17 14:16:30 +02:00
|
|
|
@Singleton
|
2013-04-11 20:49:08 +02:00
|
|
|
public class UserRoleDAO extends GenericDAO<UserRole> {
|
2013-03-28 17:07:37 +01:00
|
|
|
|
2014-08-08 16:49:02 +02:00
|
|
|
private QUserRole role = QUserRole.userRole;
|
2013-06-08 16:15:11 +02:00
|
|
|
|
2014-08-17 14:16:30 +02:00
|
|
|
@Inject
|
2014-08-08 16:49:02 +02:00
|
|
|
public UserRoleDAO(SessionFactory sessionFactory) {
|
|
|
|
|
super(sessionFactory);
|
|
|
|
|
}
|
2013-06-08 16:15:11 +02:00
|
|
|
|
2014-08-08 16:49:02 +02:00
|
|
|
public List<UserRole> findAll() {
|
2015-07-09 12:34:54 +02:00
|
|
|
return query().selectFrom(role).leftJoin(role.user).fetchJoin().distinct().fetch();
|
2013-05-15 16:26:18 +02:00
|
|
|
}
|
|
|
|
|
|
2013-03-30 09:22:49 +01:00
|
|
|
public List<UserRole> findAll(User user) {
|
2015-07-09 12:34:54 +02:00
|
|
|
return query().selectFrom(role).where(role.user.eq(user)).distinct().fetch();
|
2013-03-30 09:22:49 +01:00
|
|
|
}
|
|
|
|
|
|
2013-04-11 20:49:08 +02:00
|
|
|
public Set<Role> findRoles(User user) {
|
2014-12-12 10:06:23 +01:00
|
|
|
return findAll(user).stream().map(r -> r.getRole()).collect(Collectors.toSet());
|
2013-03-28 17:07:37 +01:00
|
|
|
}
|
|
|
|
|
}
|