How to get active users in liferay

How to get all ACTIVE USERS in a lifetime? I used this API

 UserLocalServiceUtil.getUsers(QueryUtil.ALL_POS, QueryUtil.ALL_POS);

but this seems to give me all active and deactivated users. I need only active users?

+4
source share
2 answers

I solved this by writing a dynamic query as shown below. I do not know if this is right or not. Can anyone 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;
    }
+1
source

After extracting all users, you can iterate over the list and check the status of each user, for example

if (User.getStatus (). Equals (WorkflowConstants.STATUS_APPROVED))

0
source

All Articles