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;
|
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-29 12:59:21 +01:00
|
|
|
import com.google.common.collect.Sets;
|
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() {
|
|
|
|
|
return newQuery().from(role).leftJoin(role.user).fetch().distinct().list(role);
|
2013-05-15 16:26:18 +02:00
|
|
|
}
|
|
|
|
|
|
2013-03-30 09:22:49 +01:00
|
|
|
public List<UserRole> findAll(User user) {
|
2014-08-08 16:49:02 +02:00
|
|
|
return newQuery().from(role).where(role.user.eq(user)).distinct().list(role);
|
2013-03-30 09:22:49 +01:00
|
|
|
}
|
|
|
|
|
|
2013-04-11 20:49:08 +02:00
|
|
|
public Set<Role> findRoles(User user) {
|
2013-03-30 19:06:32 +01:00
|
|
|
Set<Role> list = Sets.newHashSet();
|
2013-06-27 11:54:30 +02:00
|
|
|
for (UserRole role : findAll(user)) {
|
2013-03-28 17:07:37 +01:00
|
|
|
list.add(role.getRole());
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
}
|