Fix offset is not working in getUserNames API issue #132

Closed
nishan wants to merge 3 commits from nishan/device-mgt-core:offset-is-not-working into master

@ -40,6 +40,7 @@ import io.entgra.device.mgt.core.device.mgt.core.service.EmailMetaInfo;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.ActivityList; import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.ActivityList;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.BasicUserInfo; import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.BasicUserInfo;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.BasicUserInfoList; import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.BasicUserInfoList;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.UserInfoList;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.BasicUserInfoWrapper; import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.BasicUserInfoWrapper;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.Credential; import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.Credential;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.EnrollmentInvitation; import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.EnrollmentInvitation;
@ -696,7 +697,29 @@ public class UserManagementServiceImpl implements UserManagementService {
user.setLastname(getClaimValue(username, Constants.USER_CLAIM_LAST_NAME)); user.setLastname(getClaimValue(username, Constants.USER_CLAIM_LAST_NAME));
userList.add(user); userList.add(user);
} }
if (offset==0) {
return Response.status(Response.Status.OK).entity(userList).build(); return Response.status(Response.Status.OK).entity(userList).build();
} else {
int toIndex = offset + limit;
int listSize = userList.size();
int lastIndex = listSize - 1;
List<UserInfo> offsetList;
if (offset <= lastIndex) {
if (toIndex <= listSize) {
offsetList = userList.subList(offset, toIndex);
} else {
offsetList = userList.subList(offset, listSize);
}
} else {
offsetList = new ArrayList<>();
}
UserInfoList result = new UserInfoList();
result.setList(offsetList);
result.setCount(userList.size());
return Response.status(Response.Status.OK).entity(result).build();
}
} catch (UserStoreException e) { } catch (UserStoreException e) {
String msg = "Error occurred while retrieving the list of users using the filter : " + filter; String msg = "Error occurred while retrieving the list of users using the filter : " + filter;
log.error(msg, e); log.error(msg, e);

Loading…
Cancel
Save