This is an automated email from the ASF dual-hosted git repository.

isjarana pushed a commit to branch baremetal
in repository https://gitbox.apache.org/repos/asf/airavata-custos.git


The following commit(s) were added to refs/heads/baremetal by this push:
     new 0f39cb10e Adding pagination for groups
     new badf7f020 Merge pull request #354 from isururanawaka/baremetal
0f39cb10e is described below

commit 0f39cb10e4806c9ae24d21c0509731b506adcfc2
Author: Isuru Ranawaka <[email protected]>
AuthorDate: Thu Feb 9 14:49:41 2023 -0500

    Adding pagination for groups
---
 .../persistance/repository/SearchGroupsRepository.java     |  3 ++-
 .../persistance/repository/SearchGroupsRepositoryImpl.java | 14 +++++++++++---
 .../custos/user/profile/service/UserProfileService.java    |  2 +-
 .../src/main/proto/UserProfileService.proto                |  3 ++-
 .../org/apache/custos/scim/resource/GroupResource.java     |  2 +-
 5 files changed, 17 insertions(+), 7 deletions(-)

diff --git 
a/custos-services/custos-core-services/user-profile-core-service/src/main/java/org/apache/custos/user/profile/persistance/repository/SearchGroupsRepository.java
 
b/custos-services/custos-core-services/user-profile-core-service/src/main/java/org/apache/custos/user/profile/persistance/repository/SearchGroupsRepository.java
index d2a798bf3..2c9694420 100644
--- 
a/custos-services/custos-core-services/user-profile-core-service/src/main/java/org/apache/custos/user/profile/persistance/repository/SearchGroupsRepository.java
+++ 
b/custos-services/custos-core-services/user-profile-core-service/src/main/java/org/apache/custos/user/profile/persistance/repository/SearchGroupsRepository.java
@@ -25,5 +25,6 @@ import java.util.List;
 
 public interface SearchGroupsRepository {
 
-    List<Group> searchEntities(long tenantId, 
org.apache.custos.user.profile.service.Group group);
+    List<Group> searchEntities(long tenantId, 
org.apache.custos.user.profile.service.Group group,int offset,
+                               int limit);
 }
diff --git 
a/custos-services/custos-core-services/user-profile-core-service/src/main/java/org/apache/custos/user/profile/persistance/repository/SearchGroupsRepositoryImpl.java
 
b/custos-services/custos-core-services/user-profile-core-service/src/main/java/org/apache/custos/user/profile/persistance/repository/SearchGroupsRepositoryImpl.java
index 32362503a..21afa302e 100644
--- 
a/custos-services/custos-core-services/user-profile-core-service/src/main/java/org/apache/custos/user/profile/persistance/repository/SearchGroupsRepositoryImpl.java
+++ 
b/custos-services/custos-core-services/user-profile-core-service/src/main/java/org/apache/custos/user/profile/persistance/repository/SearchGroupsRepositoryImpl.java
@@ -41,9 +41,10 @@ public class SearchGroupsRepositoryImpl implements 
SearchGroupsRepository {
     EntityManager entityManager;
 
     @Override
-    public List<Group> searchEntities(long tenantId, 
org.apache.custos.user.profile.service.Group group) {
+    public List<Group> searchEntities(long tenantId, 
org.apache.custos.user.profile.service.Group group, int offset,
+                                      int limit) {
         Map<String, Object> valueMap = new HashMap<>();
-        String query = createSQLQuery(tenantId, group, valueMap);
+        String query = createSQLQuery(tenantId, group, valueMap,  offset,  
limit);
 
 
         Query q = entityManager.createNativeQuery(query, Group.class);
@@ -54,7 +55,8 @@ public class SearchGroupsRepositoryImpl implements 
SearchGroupsRepository {
         return q.getResultList();
     }
 
-    private String createSQLQuery(long tenantId, 
org.apache.custos.user.profile.service.Group group, Map<String, Object> 
valueMap) {
+    private String createSQLQuery(long tenantId, 
org.apache.custos.user.profile.service.Group group,
+                                  Map<String, Object> valueMap, int offset, 
int limit) {
 
         String query = "SELECT * FROM group_entity E WHERE ";
 
@@ -106,6 +108,12 @@ public class SearchGroupsRepositoryImpl implements 
SearchGroupsRepository {
 
         query = query + " ORDER BY E.created_at DESC";
 
+        if (limit > 0) {
+            query = query + " LIMIT " + ":limit" + " OFFSET " + ":offset";
+            valueMap.put("limit", limit);
+            valueMap.put("offset", offset);
+        }
+
         return query;
     }
 
diff --git 
a/custos-services/custos-core-services/user-profile-core-service/src/main/java/org/apache/custos/user/profile/service/UserProfileService.java
 
b/custos-services/custos-core-services/user-profile-core-service/src/main/java/org/apache/custos/user/profile/service/UserProfileService.java
index 32af8bb97..084df81b9 100644
--- 
a/custos-services/custos-core-services/user-profile-core-service/src/main/java/org/apache/custos/user/profile/service/UserProfileService.java
+++ 
b/custos-services/custos-core-services/user-profile-core-service/src/main/java/org/apache/custos/user/profile/service/UserProfileService.java
@@ -686,7 +686,7 @@ public class UserProfileService extends 
UserProfileServiceGrpc.UserProfileServic
             LOGGER.debug("Request received to getAllGroups for " + 
request.getTenantId());
 
             List<org.apache.custos.user.profile.persistance.model.Group> 
groups = groupRepository
-                    .searchEntities(request.getTenantId(), request.getGroup());
+                    .searchEntities(request.getTenantId(), request.getGroup(), 
request.getOffset(),request.getLimit());
             if (groups == null || groups.isEmpty()) {
                 groups = groupRepository.
                         findAllByTenantId(request.getTenantId());
diff --git 
a/custos-services/custos-core-services/user-profile-core-service/src/main/proto/UserProfileService.proto
 
b/custos-services/custos-core-services/user-profile-core-service/src/main/proto/UserProfileService.proto
index a7557848a..a1c4ce5c8 100644
--- 
a/custos-services/custos-core-services/user-profile-core-service/src/main/proto/UserProfileService.proto
+++ 
b/custos-services/custos-core-services/user-profile-core-service/src/main/proto/UserProfileService.proto
@@ -120,7 +120,8 @@ message GroupRequest {
     string membership_type = 5;
     string id = 6;
     string client_sec =7;
-
+    int32 offset =8;
+    int32 limit=9;
 }
 
 message GetAllGroupsResponse {
diff --git 
a/custos-services/custos-integration-services/scim-service/src/main/java/org/apache/custos/scim/resource/GroupResource.java
 
b/custos-services/custos-integration-services/scim-service/src/main/java/org/apache/custos/scim/resource/GroupResource.java
index be7800962..2c0c8682d 100644
--- 
a/custos-services/custos-integration-services/scim-service/src/main/java/org/apache/custos/scim/resource/GroupResource.java
+++ 
b/custos-services/custos-integration-services/scim-service/src/main/java/org/apache/custos/scim/resource/GroupResource.java
@@ -269,7 +269,7 @@ public class GroupResource extends AbstractResource {
             @ApiResponse(code = 404, message = "Valid groups are not found")})
 
     @PostMapping(value = ("/.search"), produces = {"application/json", 
"application/scim+json"}, consumes = {"application/scim+json"})
-    public ResponseEntity getGroupsByPost(String resourceString, 
@RequestHeader(value = Constants.AUTHORIZATION) String authorizationHeader) {
+    public ResponseEntity getGroupsByPost(@RequestBody  String resourceString, 
@RequestHeader(value = Constants.AUTHORIZATION) String authorizationHeader) {
 
         authHandler.validateAndConfigure(authorizationHeader, false);
 

Reply via email to