Example usage for com.mongodb DBCursor iterator

List of usage examples for com.mongodb DBCursor iterator

Introduction

In this page you can find the example usage for com.mongodb DBCursor iterator.

Prototype

@Override
public Iterator<DBObject> iterator() 

Source Link

Document

Creates a copy of this cursor object that can be iterated.

Usage

From source file:org.sipfoundry.commons.userdb.ValidUsers.java

License:Open Source License

/**
 * Given a bunch of DTMF digits, return the list of users that matches
 *
 * @param digits DTMF digits to match against user directory
 * @param onlyVoicemailUsers limit match to users in directory who have voicemail
 * @return a Vector of users that match/*from   w  w  w. j a  v  a  2s.  co m*/
 */
public List<User> lookupDTMF(String digits, boolean onlyVoicemailUsers) {
    List<User> matches = new ArrayList<User>();
    BasicDBList permList = new BasicDBList();
    permList.add(IMDB_PERM_AA);
    BasicDBObject inDirectory = new BasicDBObject();
    inDirectory.put("$all", permList);
    BasicDBObject hasDisplayName = new BasicDBObject();
    hasDisplayName.put("$exists", Boolean.TRUE);
    BasicDBObject queryAls = new BasicDBObject();
    queryAls.put(PERMISSIONS, inDirectory);
    queryAls.put(VALID_USER, Boolean.TRUE);
    queryAls.put(DISPLAY_NAME, hasDisplayName);
    DBCursor aliasResult = getEntityCollection().find(queryAls);
    Iterator<DBObject> objects = aliasResult.iterator();
    while (objects.hasNext()) {
        User user = extractValidUser(objects.next());
        if (user.getDialPatterns() != null) {
            for (String dialPattern : user.getDialPatterns()) {
                if (dialPattern.startsWith(digits)) {
                    if (!onlyVoicemailUsers || user.hasVoicemail()) {
                        matches.add(user);
                        break;
                    }
                }
            }
        }
    }
    return matches;
}

From source file:org.sipfoundry.commons.userdb.ValidUsers.java

License:Open Source License

public List<User> getImUsersByFilter(Set<String> fields, String query, int startIndex, int numResults) {
    QueryBuilder mongoQuery = QueryBuilder.start();
    if (fields.contains(IM_USERNAME_FILTER)) {
        BasicDBObject q = new BasicDBObject();
        q.put(IM_ID, query);//from ww  w  . j a  v a 2 s . co m
        BasicDBObject altQ = new BasicDBObject();
        altQ.put(ALT_IM_ID, query);
        mongoQuery.or(q, altQ);
    }
    if (fields.contains(IM_NAME_FILTER)) {
        BasicDBObject q = new BasicDBObject();
        q.put(IM_DISPLAY_NAME, query);
        mongoQuery.or(q);
    }
    if (fields.contains(IM_EMAIL_FILTER)) {
        BasicDBObject q = new BasicDBObject();
        q.put(EMAIL, query);
        mongoQuery.or(q);
    }
    DBCursor cursor = getEntityCollection().find(mongoQuery.get()).skip(startIndex).limit(numResults);
    List<User> users = new ArrayList<User>();
    Iterator<DBObject> objects = cursor.iterator();
    while (objects.hasNext()) {
        DBObject user = objects.next();
        User imUser = extractUser(user);
        if (imUser.isImEnabled()) {
            users.add(imUser);
        }
    }
    return users;
}

From source file:org.sipfoundry.commons.userdb.ValidUsers.java

License:Open Source License

public Collection<String> getImUsernames(int startIndex, int numResults) {
    BasicDBObject query = new BasicDBObject();
    query.put(IM_ENABLED, true);//from   ww w . j a va  2 s.  c  o  m
    DBObject dbObject = (DBObject) JSON.parse("{'" + IM_ID + "':1}");
    List<String> userNames = new ArrayList<String>();
    DBCursor cursor = getEntityCollection().find(query, dbObject).skip(startIndex).limit(numResults);
    Iterator<DBObject> objects = cursor.iterator();
    while (objects.hasNext()) {
        DBObject user = objects.next();
        String imUsername = getStringValue(user, IM_ID);
        if (StringUtils.isNotBlank(imUsername)) {
            userNames.add(imUsername);
        }
    }
    return userNames;
}

From source file:org.sipfoundry.commons.userdb.ValidUsers.java

License:Open Source License

public Collection<String> getImGroupNames(int startIndex, int numResults) {
    BasicDBObject query = new BasicDBObject();
    query.put(IM_GROUP, "1");
    DBObject dbObject = (DBObject) JSON.parse("{'" + UID + "':1}");
    List<String> groupNames = new ArrayList<String>();
    DBCursor cursor = getEntityCollection().find(query, dbObject).skip(startIndex).limit(numResults);
    Iterator<DBObject> objects = cursor.iterator();
    while (objects.hasNext()) {
        DBObject group = objects.next();
        String groupName = getStringValue(group, UID);
        if (StringUtils.isNotBlank(groupName)) {
            groupNames.add(groupName);//w  w w. ja  va 2 s  . c o  m
        }
    }
    return groupNames;
}

From source file:org.sipfoundry.commons.userdb.ValidUsers.java

License:Open Source License

public List<String> getImGroupNameByQuery(String query, int startIndex, int numResults) {
    Pattern insensitiveQuery = Pattern.compile(query, Pattern.CASE_INSENSITIVE);
    QueryBuilder mongoQuery = QueryBuilder.start(ENTITY_NAME).is(ENTITY_NAME_GROUP).and(UID)
            .is(insensitiveQuery);/* w  ww .  j a va  2  s  . c om*/
    DBCursor cursor = getEntityCollection().find(mongoQuery.get()).skip(startIndex).limit(numResults);
    List<String> groups = new ArrayList<String>();
    Iterator<DBObject> objects = cursor.iterator();
    while (objects.hasNext()) {
        DBObject group = objects.next();
        groups.add(getStringValue(group, UID));
    }
    return groups;
}

From source file:org.sipfoundry.commons.userdb.ValidUsers.java

License:Open Source License

public List<String> getImUsernamesInGroup(String groupName) {
    BasicDBObject query = new BasicDBObject();
    query.put(IM_ENABLED, true);/*from   www . j a va  2 s . c  o m*/
    BasicDBList groupList = new BasicDBList();
    groupList.add(groupName);
    query.put(GROUPS, new BasicDBObject("$in", groupList));
    DBObject dbObject = (DBObject) JSON.parse("{'" + IM_ID + "':1}");
    List<String> userNames = new ArrayList<String>();
    DBCursor cursor = getEntityCollection().find(query, dbObject);
    Iterator<DBObject> objects = cursor.iterator();
    while (objects.hasNext()) {
        DBObject user = objects.next();
        String imUsername = getStringValue(user, IM_ID);
        if (StringUtils.isNotBlank(imUsername)) {
            userNames.add(imUsername);
        }
    }
    return userNames;
}