How do I get all ACTIVE USERS in liferay? I have used this API
UserLocalServiceUtil.getUsers(QueryUtil.ALL_POS, QueryUtil.ALL_POS);
but this seems to give me all active and deactive users also. I only need active users?
I have solved that by writing an dynamic query as below. I don't know if it is correct or not. Could someone please see and answer?
public static List<User> getallActiveUsers() {
List<User> activeUsers = new ArrayList<User>();
Criterion stageCriterion = null;
int deactiveStatus = 5;
DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(User.class);
stageCriterion = PropertyFactoryUtil.forName("status").ne(deactiveStatus);
dynamicQuery.add(stageCriterion);
try {
activeUsers = UserLocalServiceUtil.dynamicQuery(dynamicQuery);
} catch (SystemException e) {
e.printStackTrace();
}
_log.info("ALL ACTIVE USERS"+activeUsers.toString());
_log.info("ALL ACTIVE Size"+activeUsers.size());
return activeUsers;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With