Merge branch 'feature/group-count-for-pagination' into feature/group-search-and-pagination
This commit is contained in:
commit
6929dddacf
9 changed files with 102 additions and 1 deletions
|
@ -67,6 +67,29 @@ public interface GroupsResource {
|
||||||
@QueryParam("first") Integer first,
|
@QueryParam("first") Integer first,
|
||||||
@QueryParam("max") Integer max);
|
@QueryParam("max") Integer max);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Counts all groups.
|
||||||
|
* @return The number of groups.
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@NoCache
|
||||||
|
@Path("/count")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
Response count();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Counts groups by name search.
|
||||||
|
* @param search max number of occurrences
|
||||||
|
* @return The number of group containing search therm.
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@NoCache
|
||||||
|
@Path("/count")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
Response count(@QueryParam("search") String search);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create or add a top level realm groupSet or create child. This will update the group and set the parent if it exists. Create it and set the parent
|
* create or add a top level realm groupSet or create child. This will update the group and set the parent if it exists. Create it and set the parent
|
||||||
* if the group doesn't exist.
|
* if the group doesn't exist.
|
||||||
|
|
|
@ -1200,6 +1200,16 @@ public class RealmAdapter implements CachedRealmModel {
|
||||||
return cacheSession.getGroups(this);
|
return cacheSession.getGroups(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long getGroupsCount() {
|
||||||
|
return cacheSession.getGroupsCount(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long getGroupsCountByNameContaining(String search) {
|
||||||
|
return cacheSession.getGroupsCountByNameContaining(this, search);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<GroupModel> getTopLevelGroups() {
|
public List<GroupModel> getTopLevelGroups() {
|
||||||
return cacheSession.getTopLevelGroups(this);
|
return cacheSession.getTopLevelGroups(this);
|
||||||
|
|
|
@ -841,6 +841,16 @@ public class RealmCacheSession implements CacheRealmProvider {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long getGroupsCount(RealmModel realm) {
|
||||||
|
return getDelegate().getGroupsCount(realm);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long getGroupsCountByNameContaining(RealmModel realm, String search) {
|
||||||
|
return getDelegate().getGroupsCountByNameContaining(realm, search);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<GroupModel> getTopLevelGroups(RealmModel realm) {
|
public List<GroupModel> getTopLevelGroups(RealmModel realm) {
|
||||||
String cacheKey = getTopGroupsQueryCacheKey(realm.getId());
|
String cacheKey = getTopGroupsQueryCacheKey(realm.getId());
|
||||||
|
|
|
@ -322,6 +322,25 @@ public class JpaRealmProvider implements RealmProvider {
|
||||||
Collectors.toList(), Collections::unmodifiableList));
|
Collectors.toList(), Collections::unmodifiableList));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long getGroupsCount(RealmModel realm) {
|
||||||
|
Long count = em.createNamedQuery("getGroupCount", Long.class)
|
||||||
|
.setParameter("realm", realm.getId())
|
||||||
|
.getSingleResult();
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long getGroupsCountByNameContaining(RealmModel realm, String search) {
|
||||||
|
Long count = em.createNamedQuery("getGroupCountByNameContaining", Long.class)
|
||||||
|
.setParameter("realm", realm.getId())
|
||||||
|
.setParameter("name", search)
|
||||||
|
.getSingleResult();
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<GroupModel> getTopLevelGroups(RealmModel realm) {
|
public List<GroupModel> getTopLevelGroups(RealmModel realm) {
|
||||||
RealmEntity ref = em.getReference(RealmEntity.class, realm.getId());
|
RealmEntity ref = em.getReference(RealmEntity.class, realm.getId());
|
||||||
|
|
|
@ -1674,6 +1674,16 @@ public class RealmAdapter implements RealmModel, JpaModel<RealmEntity> {
|
||||||
return session.realms().getGroups(this);
|
return session.realms().getGroups(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long getGroupsCount() {
|
||||||
|
return session.realms().getGroupsCount(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long getGroupsCountByNameContaining(String search) {
|
||||||
|
return session.realms().getGroupsCountByNameContaining(this, search);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<GroupModel> getTopLevelGroups() {
|
public List<GroupModel> getTopLevelGroups() {
|
||||||
return session.realms().getTopLevelGroups(this);
|
return session.realms().getTopLevelGroups(this);
|
||||||
|
|
|
@ -28,7 +28,9 @@ import java.util.Collection;
|
||||||
@NamedQueries({
|
@NamedQueries({
|
||||||
@NamedQuery(name="getGroupIdsByParent", query="select u.id from GroupEntity u where u.parent = :parent"),
|
@NamedQuery(name="getGroupIdsByParent", query="select u.id from GroupEntity u where u.parent = :parent"),
|
||||||
@NamedQuery(name="getGroupIdsByNameContaining", query="select u.id from GroupEntity u where u.realm.id = :realm and u.name like concat('%',:search,'%') order by u.name ASC"),
|
@NamedQuery(name="getGroupIdsByNameContaining", query="select u.id from GroupEntity u where u.realm.id = :realm and u.name like concat('%',:search,'%') order by u.name ASC"),
|
||||||
@NamedQuery(name="getTopLevelGroupIds", query="select u.id from GroupEntity u where u.parent is null and u.realm.id = :realm")
|
@NamedQuery(name="getTopLevelGroupIds", query="select u.id from GroupEntity u where u.parent is null and u.realm.id = :realm"),
|
||||||
|
@NamedQuery(name="getGroupCount", query="select count(u) from GroupEntity u where u.realm.id = :realm"),
|
||||||
|
@NamedQuery(name="getGroupCountByNameContaining", query="select count(u) from GroupEntity u where u.realm.id = :realm and u.name like concat('%',:name,'%')")
|
||||||
})
|
})
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name="KEYCLOAK_GROUP")
|
@Table(name="KEYCLOAK_GROUP")
|
||||||
|
|
|
@ -397,6 +397,8 @@ public interface RealmModel extends RoleContainerModel {
|
||||||
|
|
||||||
GroupModel getGroupById(String id);
|
GroupModel getGroupById(String id);
|
||||||
List<GroupModel> getGroups();
|
List<GroupModel> getGroups();
|
||||||
|
Long getGroupsCount();
|
||||||
|
Long getGroupsCountByNameContaining(String search);
|
||||||
List<GroupModel> getTopLevelGroups();
|
List<GroupModel> getTopLevelGroups();
|
||||||
List<GroupModel> getTopLevelGroups(Integer first, Integer max);
|
List<GroupModel> getTopLevelGroups(Integer first, Integer max);
|
||||||
List<GroupModel> searchForGroupByName(String search, Integer first, Integer max);
|
List<GroupModel> searchForGroupByName(String search, Integer first, Integer max);
|
||||||
|
|
|
@ -40,6 +40,10 @@ public interface RealmProvider extends Provider {
|
||||||
|
|
||||||
List<GroupModel> getGroups(RealmModel realm);
|
List<GroupModel> getGroups(RealmModel realm);
|
||||||
|
|
||||||
|
Long getGroupsCount(RealmModel realm);
|
||||||
|
|
||||||
|
Long getGroupsCountByNameContaining(RealmModel realm, String search);
|
||||||
|
|
||||||
List<GroupModel> getTopLevelGroups(RealmModel realm);
|
List<GroupModel> getTopLevelGroups(RealmModel realm);
|
||||||
|
|
||||||
List<GroupModel> getTopLevelGroups(RealmModel realm, Integer first, Integer max);
|
List<GroupModel> getTopLevelGroups(RealmModel realm, Integer first, Integer max);
|
||||||
|
@ -89,6 +93,8 @@ public interface RealmProvider extends Provider {
|
||||||
ClientTemplateModel getClientTemplateById(String id, RealmModel realm);
|
ClientTemplateModel getClientTemplateById(String id, RealmModel realm);
|
||||||
GroupModel getGroupById(String id, RealmModel realm);
|
GroupModel getGroupById(String id, RealmModel realm);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
List<RealmModel> getRealms();
|
List<RealmModel> getRealms();
|
||||||
boolean removeRealm(String id);
|
boolean removeRealm(String id);
|
||||||
void close();
|
void close();
|
||||||
|
|
|
@ -101,6 +101,25 @@ public class GroupsResource {
|
||||||
return resource;
|
return resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the groups counts.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@NoCache
|
||||||
|
@Path("/count")
|
||||||
|
public Response getGroupCount(@QueryParam("search") String search) {
|
||||||
|
auth.requireView();
|
||||||
|
Long results;
|
||||||
|
if (Objects.nonNull(search)) {
|
||||||
|
results = realm.getGroupsCountByNameContaining(search);
|
||||||
|
} else {
|
||||||
|
results = realm.getGroupsCount();
|
||||||
|
}
|
||||||
|
return Response.ok(results).build();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create or add a top level realm groupSet or create child. This will update the group and set the parent if it exists. Create it and set the parent
|
* create or add a top level realm groupSet or create child. This will update the group and set the parent if it exists. Create it and set the parent
|
||||||
* if the group doesn't exist.
|
* if the group doesn't exist.
|
||||||
|
|
Loading…
Reference in a new issue