Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get active users in liferay

Tags:

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?

like image 550
ravicandy Avatar asked Nov 10 '22 09:11

ravicandy


1 Answers

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;
    }
like image 195
ravicandy Avatar answered Dec 21 '22 18:12

ravicandy