List of usage examples for com.mongodb QueryBuilder get
public DBObject get()
From source file:org.pentaho.di.trans.dataservice.optimization.mongod.MongodbPredicate.java
License:Apache License
private DBObject[] conditionListToDBObjectArray(List<Condition> conditions) throws PushDownOptimizationException { BasicDBList basicDbList = new BasicDBList(); for (Condition condition : conditions) { QueryBuilder childContainer = QueryBuilder.start(); buildMongoCondition(condition, childContainer); basicDbList.add(childContainer.get()); }//from w w w.j ava 2 s . c om return basicDbList.toArray(new DBObject[basicDbList.size()]); }
From source file:org.sglover.entities.dao.mongo.MongoEntitiesDAO.java
License:Open Source License
@Override // TODO use skip and maxItems public Stream<Entity<String>> getNames(Node node, int skip, int maxItems) { String nodeId = node.getNodeId(); String nodeVersion = node.getVersionLabel(); Collection<Entity<String>> ret = new LinkedList<>(); QueryBuilder queryBuilder = QueryBuilder.start("n").is(nodeId).and("v").is(nodeVersion); DBObject query = queryBuilder.get(); BasicDBObjectBuilder orderByBuilder = BasicDBObjectBuilder.start("nm", 1); DBObject orderBy = orderByBuilder.get(); DBCursor cursor = entitiesData.find(query).sort(orderBy); try {/*from ww w. ja v a 2s .c om*/ for (DBObject dbObject : cursor) { String name = (String) dbObject.get("nm"); int count = (Integer) dbObject.get("c"); String type = map.get("nm"); Entity<String> entity = new Entity<>(EntityType.valueOf(type), name, count); ret.add(entity); } } finally { if (cursor != null) { cursor.close(); } } return ret.stream(); }
From source file:org.sglover.entities.dao.mongo.MongoEntitiesDAO.java
License:Open Source License
@Override // TODO use skip and maxItems public Stream<Entity<String>> getOrgs(Node node, int skip, int maxItems) { String nodeId = node.getNodeId(); String nodeVersion = node.getVersionLabel(); Collection<Entity<String>> ret = new LinkedList<>(); QueryBuilder queryBuilder = QueryBuilder.start("n").is(nodeId).and("v").is(nodeVersion); DBObject query = queryBuilder.get(); BasicDBObjectBuilder orderByBuilder = BasicDBObjectBuilder.start("o", 1); DBObject orderBy = orderByBuilder.get(); DBCursor cursor = entitiesData.find(query).sort(orderBy); try {/*from w w w . j av a2s. c om*/ for (DBObject dbObject : cursor) { String org = (String) dbObject.get("o"); int count = (Integer) dbObject.get("c"); String type = map.get("nm"); Entity<String> entity = new Entity<>(EntityType.valueOf(type), org, count); ret.add(entity); } } finally { if (cursor != null) { cursor.close(); } } return ret.stream(); }
From source file:org.sglover.entities.dao.mongo.MongoEntitiesDAO.java
License:Open Source License
@Override public Stream<Node> matchingNodes(EntityType type, String name) { List<Node> nodes = new LinkedList<>(); QueryBuilder queryBuilder = QueryBuilder.start("t").is(type).and("nm").is(name); DBObject query = queryBuilder.get(); BasicDBObjectBuilder orderByBuilder = BasicDBObjectBuilder.start("c", 1); DBObject orderBy = orderByBuilder.get(); DBCursor cursor = entitiesData.find(query).sort(orderBy); try {//from w w w.j a v a 2s . c om for (DBObject dbObject : cursor) { String nodeId = (String) dbObject.get("n"); long nodeInternalId = (Long) dbObject.get("ni"); Long nodeVersion = (Long) dbObject.get("v"); Node node = Node.build().nodeInternalId(nodeInternalId).nodeId(nodeId).nodeVersion(nodeVersion); nodes.add(node); } } finally { if (cursor != null) { cursor.close(); } } return nodes.stream(); }
From source file:org.sglover.entities.dao.mongo.MongoEntitiesDAO.java
License:Open Source License
@Override public Entities getEntities(Node node) { String nodeId = node.getNodeId(); String nodeVersion = node.getVersionLabel(); Entities entities = Entities.empty(nodeId, nodeVersion); QueryBuilder queryBuilder = QueryBuilder.start("n").is(nodeId).and("v").is(nodeVersion); Set<String> types = new HashSet<>(); types.add("names"); types.add("orgs"); queryBuilder.and("t").in(types); DBObject query = queryBuilder.get(); DBCursor cursor = entitiesData.find(query); try {// w ww .jav a2 s .c o m for (DBObject dbObject : cursor) { Entity<String> entity = getEntity(dbObject); entities.addEntity(entity); } } finally { if (cursor != null) { cursor.close(); } } return entities; }
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 w w w . j a va 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 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);/*from ww w. j a va 2s .c o m*/ 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.sipxconfig.admin.commserver.imdb.PermissionsTestIntegration.java
License:Contributor Agreement License
public void testAddUser() throws Exception { Group g = new Group(); PermissionName.INTERNATIONAL_DIALING.setEnabled(g, false); PermissionName.LONG_DISTANCE_DIALING.setEnabled(g, false); PermissionName.TOLL_FREE_DIALING.setEnabled(g, false); PermissionName.LOCAL_DIALING.setEnabled(g, true); PermissionName.FREESWITH_VOICEMAIL.setEnabled(g, false); PermissionName.EXCHANGE_VOICEMAIL.setEnabled(g, true); m_testUser.addGroup(g);/* w w w . ja v a 2 s .co m*/ m_testUser.setUserName("goober"); m_testUser.setUniqueId(1); m_permissionDataSet.generate(m_testUser, m_permissionDataSet.findOrCreate(m_testUser)); assertObjectWithIdPresent(getEntityCollection(), "User1"); assertObjectListFieldCount(getEntityCollection(), "User1", MongoConstants.PERMISSIONS, 8); QueryBuilder qb = QueryBuilder.start(MongoConstants.ID); qb.is("User1").and(MongoConstants.PERMISSIONS).size(4).and(MongoConstants.PERMISSIONS) .is(PermissionName.LOCAL_DIALING.getName()).is(PermissionName.VOICEMAIL.getName()) .is(PermissionName.EXCHANGE_VOICEMAIL.getName()).is(PermissionName.MOBILE.getName()); assertObjectPresent(getEntityCollection(), qb.get()); }
From source file:org.sipfoundry.sipxconfig.admin.commserver.imdb.PermissionsTestIntegration.java
License:Contributor Agreement License
public void testAuthCodePermissions() { InternalUser user = new InternalUser(); user.setSipPassword("123"); user.setPintoken("11"); user.setPermissionManager(getPermissionManager()); user.setPermission(PermissionName.NINEHUNDERED_DIALING, true); user.setPermission(PermissionName.INTERNATIONAL_DIALING, false); user.setPermission(PermissionName.LOCAL_DIALING, false); user.setPermission(PermissionName.LONG_DISTANCE_DIALING, false); user.setPermission(PermissionName.MOBILE, false); user.setPermission(PermissionName.TOLL_FREE_DIALING, false); AuthCode code = new AuthCode(); code.setInternalUser(user);// w ww .java 2s . c o m m_permissionDataSet.generate(code, m_permissionDataSet.findOrCreate(code)); assertObjectWithIdPresent(getEntityCollection(), "AuthCode-1"); QueryBuilder qb = QueryBuilder.start(MongoConstants.ID); qb.is("AuthCode-1").and(MongoConstants.PERMISSIONS).size(1).and(MongoConstants.PERMISSIONS) .is(PermissionName.NINEHUNDERED_DIALING.getName()); assertObjectPresent(getEntityCollection(), qb.get()); user.setPermission(PermissionName.NINEHUNDERED_DIALING, false); user.setPermission(PermissionName.INTERNATIONAL_DIALING, true); code.setInternalUser(user); m_permissionDataSet.generate(code, m_permissionDataSet.findOrCreate(code)); qb.is("AuthCode-1").and(MongoConstants.PERMISSIONS).size(1).and(MongoConstants.PERMISSIONS) .is(PermissionName.INTERNATIONAL_DIALING.getName()); assertObjectPresent(getEntityCollection(), qb.get()); }
From source file:org.sipfoundry.sipxconfig.admin.commserver.imdb.UserStaticTestIntegration.java
License:Contributor Agreement License
public void testGenerate() throws Exception { m_userstaticDataSet.generate(m_users.get(0), m_userstaticDataSet.findOrCreate(m_users.get(0))); m_userstaticDataSet.generate(m_users.get(1), m_userstaticDataSet.findOrCreate(m_users.get(1))); m_userstaticDataSet.generate(m_users.get(2), m_userstaticDataSet.findOrCreate(m_users.get(2))); assertCollectionCount(getEntityCollection(), 3); QueryBuilder qb = QueryBuilder.start(MongoConstants.ID); qb.is("User0").and(MongoConstants.STATIC + "." + MongoConstants.CONTACT) .is("sip:" + USER_DATA[0][4] + "@" + DOMAIN); assertObjectPresent(getEntityCollection(), qb.get()); assertObjectWithIdFieldValuePresent(getEntityCollection(), "User0", MongoConstants.STATIC + "." + MongoConstants.CONTACT, "sip:" + USER_DATA[0][4] + "@" + DOMAIN); assertObjectWithIdFieldValuePresent(getEntityCollection(), "User0", MongoConstants.STATIC + "." + MongoConstants.TO_URI, "sip:" + USER_DATA[0][3] + "@" + DOMAIN); assertObjectWithIdFieldValuePresent(getEntityCollection(), "User1", MongoConstants.STATIC + "." + MongoConstants.EVENT, "message-summary"); assertObjectWithIdFieldValuePresent(getEntityCollection(), "User2", MongoConstants.STATIC + "." + MongoConstants.FROM_URI, "sip:IVR@" + DOMAIN); }