ravicandy
ravicandy

Reputation: 151

how to get active users in liferay

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?

Upvotes: 5

Views: 1973

Answers (2)

Neeraj Gautam
Neeraj Gautam

Reputation: 164

After fetching the all users you can iterate through list and check the status of the each user like

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

Upvotes: 0

ravicandy
ravicandy

Reputation: 151

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;
    }

Upvotes: 1

Related Questions