Commit 119eeb69 authored by michael.simon's avatar michael.simon
Browse files

added RoleGroup Methods to JPA layer

parent 43a89701
......@@ -12,7 +12,9 @@ package edu.kit.scc.webreg.dao;
import java.util.List;
import edu.kit.scc.webreg.entity.GroupEntity;
import edu.kit.scc.webreg.entity.RoleEntity;
import edu.kit.scc.webreg.entity.RoleGroupEntity;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.entity.UserRoleEntity;
......@@ -35,5 +37,13 @@ public interface RoleDao extends BaseDao<RoleEntity, Long> {
Boolean checkUserInRole(Long userId, String roleName);
Boolean checkAdminUserInRole(Long userId, String roleName);
void addGroupToRole(GroupEntity group, RoleEntity role);
void removeGroupFromRole(GroupEntity group, RoleEntity role);
RoleGroupEntity createNewRoleGroup();
RoleGroupEntity findRoleGroupEntity(GroupEntity group, RoleEntity role);
}
......@@ -21,7 +21,9 @@ import javax.persistence.criteria.JoinType;
import javax.persistence.criteria.Root;
import edu.kit.scc.webreg.dao.RoleDao;
import edu.kit.scc.webreg.entity.GroupEntity;
import edu.kit.scc.webreg.entity.RoleEntity;
import edu.kit.scc.webreg.entity.RoleGroupEntity;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.entity.UserRoleEntity;
......@@ -39,6 +41,38 @@ public class JpaRoleDao extends JpaBaseDao<RoleEntity, Long> implements RoleDao
em.persist(userRole);
}
@Override
public void addGroupToRole(GroupEntity group, RoleEntity role) {
RoleGroupEntity roleGroup = createNewRoleGroup();
roleGroup.setRole(role);
roleGroup.setGroup(group);
em.persist(roleGroup);
}
@Override
public void removeGroupFromRole(GroupEntity group, RoleEntity role) {
RoleGroupEntity roleGroup = findRoleGroupEntity(group, role);
if (roleGroup != null)
em.remove(roleGroup);
}
@Override
public RoleGroupEntity createNewRoleGroup() {
return new RoleGroupEntity();
}
@Override
public RoleGroupEntity findRoleGroupEntity(GroupEntity group, RoleEntity role) {
try {
return (RoleGroupEntity) em.createQuery("select r from RoleGroupEntity r where r.role = :role "
+ "and r.group = :group")
.setParameter("role", role).setParameter("group", group).getSingleResult();
}
catch (NoResultException e) {
return null;
}
}
@Override
public void deleteUserRole(Long userId, String roleName) {
UserRoleEntity roleEntity = (UserRoleEntity) em.createQuery("select r from UserRoleEntity r where r.user.id = :userId "
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment