38
38
import org .wso2 .charon3 .core .objects .Group ;
39
39
import org .wso2 .charon3 .core .objects .Role ;
40
40
import org .wso2 .charon3 .core .objects .User ;
41
+ import org .wso2 .charon3 .core .objects .plainobjects .RolesGetResponse ;
41
42
import org .wso2 .charon3 .core .utils .codeutils .ExpressionNode ;
42
43
import org .wso2 .charon3 .core .utils .codeutils .Node ;
43
44
import org .wso2 .charon3 .core .utils .codeutils .OperationNode ;
@@ -175,13 +176,13 @@ public void deleteRole(String roleID) throws CharonException, NotFoundException,
175
176
}
176
177
177
178
@ Override
178
- public List < Object > listRolesWithGET (Node rootNode , Integer startIndex , Integer count , String sortBy ,
179
- String sortOrder ) throws CharonException , NotImplementedException , BadRequestException {
179
+ public RolesGetResponse listRolesWithGET (Node rootNode , Integer startIndex , Integer count , String sortBy ,
180
+ String sortOrder ) throws CharonException , NotImplementedException , BadRequestException {
180
181
181
182
if (sortBy != null || sortOrder != null ) {
182
183
throw new NotImplementedException ("Sorting is not supported." );
183
184
} else if (count != null && count == 0 ) {
184
- return Collections .emptyList ();
185
+ return new RolesGetResponse ( 0 , Collections .emptyList () );
185
186
} else if (rootNode != null ) {
186
187
return filterRoles (rootNode , count , startIndex , sortBy , sortOrder );
187
188
} else {
@@ -200,7 +201,7 @@ public List<Object> listRolesWithGET(Node rootNode, Integer startIndex, Integer
200
201
* @return Detailed user list.
201
202
* @throws CharonException Error filtering the roles.
202
203
*/
203
- private List < Object > filterRoles (Node node , Integer count , Integer startIndex , String sortBy , String sortOrder )
204
+ private RolesGetResponse filterRoles (Node node , Integer count , Integer startIndex , String sortBy , String sortOrder )
204
205
throws CharonException , NotImplementedException , BadRequestException {
205
206
206
207
// Handle single attribute search.
@@ -225,7 +226,7 @@ private List<Object> filterRoles(Node node, Integer count, Integer startIndex, S
225
226
* @return Filtered roles.
226
227
* @throws CharonException Error filtering the roles.
227
228
*/
228
- private List < Object > filterRolesBySingleAttribute (ExpressionNode node , Integer count , Integer startIndex ,
229
+ private RolesGetResponse filterRolesBySingleAttribute (ExpressionNode node , Integer count , Integer startIndex ,
229
230
String sortBy , String sortOrder ) throws CharonException , BadRequestException {
230
231
231
232
String attributeName = node .getAttributeValue ();
@@ -241,9 +242,6 @@ private List<Object> filterRolesBySingleAttribute(ExpressionNode node, Integer c
241
242
throw new BadRequestException (errorMessage );
242
243
}
243
244
244
- List <Object > filteredRoles = new ArrayList <>();
245
- // 0th index is to store total number of results.
246
- filteredRoles .add (0 );
247
245
String searchFilter = getSearchFilter (filterOperation , attributeValue );
248
246
if (log .isDebugEnabled ()) {
249
247
log .debug (String .format ("Filtering roleNames from search filter: %s" , searchFilter ));
@@ -256,14 +254,8 @@ private List<Object> filterRolesBySingleAttribute(ExpressionNode node, Integer c
256
254
String .format ("Error occurred while listing roles based on the search filter: %s" , searchFilter ),
257
255
e );
258
256
}
259
- List <Object > scimRoles = getScimRolesList (roles );
260
-
261
- // Set total number of results to 0th index.
262
- filteredRoles .set (0 , scimRoles .size ());
263
- // Add the results list.
264
- filteredRoles .addAll (scimRoles );
265
-
266
- return filteredRoles ;
257
+ List <Role > scimRoles = getScimRolesList (roles );
258
+ return new RolesGetResponse (scimRoles .size (), scimRoles );
267
259
}
268
260
269
261
/**
@@ -312,35 +304,32 @@ private String getSearchFilter(String filterOperation, String attributeValue) {
312
304
* @return List of roles.
313
305
* @throws CharonException Error while listing users
314
306
*/
315
- private List < Object > listRoles (Integer count , Integer startIndex , String sortBy , String sortOrder )
307
+ private RolesGetResponse listRoles (Integer count , Integer startIndex , String sortBy , String sortOrder )
316
308
throws CharonException , BadRequestException {
317
309
318
- List <Object > rolesList = new ArrayList <>();
310
+ List <Role > rolesList = new ArrayList <>();
311
+ int rolesCount ;
319
312
try {
320
- // 0th index is to store total number of results.
321
- rolesList .add (0 );
322
313
List <RoleBasicInfo > roles = roleManagementService
323
314
.getRoles (count , startIndex , sortBy , sortOrder , tenantDomain );
324
- List <Object > scimRoles = getScimRolesList (roles );
315
+ List <Role > scimRoles = getScimRolesList (roles );
325
316
326
- int rolesCount = roleManagementService .getRolesCount (tenantDomain );
317
+ rolesCount = roleManagementService .getRolesCount (tenantDomain );
327
318
// Set total number of results to 0th index.
328
319
if (rolesCount == 0 ) {
329
- rolesList .set (0 , scimRoles .size ());
330
- } else {
331
- rolesList .set (0 , rolesCount );
320
+ rolesCount = scimRoles .size ();
332
321
}
333
322
// Add the results list.
334
323
rolesList .addAll (scimRoles );
335
324
} catch (IdentityRoleManagementException e ) {
336
325
throw new CharonException ("Error occurred while listing roles." , e );
337
326
}
338
- return rolesList ;
327
+ return new RolesGetResponse ( rolesCount , rolesList ) ;
339
328
}
340
329
341
- private List <Object > getScimRolesList (List <RoleBasicInfo > roles ) throws BadRequestException , CharonException {
330
+ private List <Role > getScimRolesList (List <RoleBasicInfo > roles ) throws BadRequestException , CharonException {
342
331
343
- List <Object > scimRoles = new ArrayList <>();
332
+ List <Role > scimRoles = new ArrayList <>();
344
333
for (RoleBasicInfo roleBasicInfo : roles ) {
345
334
Role scimRole = new Role ();
346
335
scimRole .setDisplayName (roleBasicInfo .getName ());
@@ -527,7 +516,7 @@ private boolean hasPermissionsChanged(List<String> oldRolePermissions, List<Stri
527
516
}
528
517
529
518
@ Override
530
- public List < Object > listRolesWithPost (SearchRequest searchRequest )
519
+ public RolesGetResponse listRolesWithPost (SearchRequest searchRequest )
531
520
throws NotImplementedException , BadRequestException , CharonException {
532
521
533
522
return listRolesWithGET (searchRequest .getFilter (), searchRequest .getStartIndex (), searchRequest .getCount (),
0 commit comments