Java Code Examples for org.bson.types.BasicBSONList#add()

The following examples show how to use org.bson.types.BasicBSONList#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MongoDbStore.java    From swellrt with Apache License 2.0 6 votes vote down vote up
private DBObject capabilitiesToObject(RobotCapabilities capabilities) {
  if (capabilities == null) {
    return null;
  }

  BasicDBObject capabilitiesObj = new BasicDBObject();
  for (Capability capability : capabilities.getCapabilitiesMap().values()) {
    BasicBSONList contexts = new BasicBSONList();
    for (Context c : capability.getContexts()) {
      contexts.add(c.name());
    }
    capabilitiesObj.put(capability.getEventType().name(),
        new BasicDBObject()
            .append(CAPABILITY_CONTEXTS_FIELD, contexts)
            .append(CAPABILITY_FILTER_FIELD, capability.getFilter()));
  }

  BasicDBObject object =
      new BasicDBObject()
          .append(CAPABILITIES_CAPABILITIES_FIELD, capabilitiesObj)
          .append(CAPABILITIES_HASH_FIELD, capabilities.getCapabilitiesHash())
          .append(CAPABILITIES_VERSION_FIELD, capabilities.getProtocolVersion().name());

  return object;
}
 
Example 2
Source File: MongoDbStore.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
private DBObject capabilitiesToObject(RobotCapabilities capabilities) {
  if (capabilities == null) {
    return null;
  }

  BasicDBObject capabilitiesObj = new BasicDBObject();
  for (Capability capability : capabilities.getCapabilitiesMap().values()) {
    BasicBSONList contexts = new BasicBSONList();
    for (Context c : capability.getContexts()) {
      contexts.add(c.name());
    }
    capabilitiesObj.put(capability.getEventType().name(),
        new BasicDBObject()
            .append(CAPABILITY_CONTEXTS_FIELD, contexts)
            .append(CAPABILITY_FILTER_FIELD, capability.getFilter()));
  }

  BasicDBObject object =
      new BasicDBObject()
          .append(CAPABILITIES_CAPABILITIES_FIELD, capabilitiesObj)
          .append(CAPABILITIES_HASH_FIELD, capabilities.getCapabilitiesHash())
          .append(CAPABILITIES_VERSION_FIELD, capabilities.getProtocolVersion().name());

  return object;
}
 
Example 3
Source File: BSONValueLookupTest.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetValues() {
    // root.body.profile.name.first = George
    BSONObject root = new BasicBSONObject();
    BSONObject body = new BasicBSONObject();
    BasicBSONList list = new BasicBSONList();

    list.add("hello");
    list.add("goodbye");
    list.add("have a nice day");

    body.put("body", list);
    root.put("root", body);

    String[] values = BSONUtilities.getValues(root,  "root.body");
    assertNotNull(values);
    assertEquals(values.length, 3);
}
 
Example 4
Source File: MongoQueryTest.java    From usergrid with Apache License 2.0 4 votes vote down vote up
@Test
public void in() throws Exception {

    UUID appId = emf.lookupApplication( "test-organization/test-app" );
    EntityManager em = emf.getEntityManager( appId );

    Map<String, Object> properties = new LinkedHashMap<String, Object>();
    properties.put( "name", "Kings of Leon" );
    properties.put( "genre", "Southern Rock" );
    properties.put( "founded", 2000 );
    em.create( "testin", properties );

    properties = new LinkedHashMap<String, Object>();
    properties.put( "name", "Stone Temple Pilots" );
    properties.put( "genre", "Rock" );
    properties.put( "founded", 1986 );
    em.create( "testin", properties );

    properties = new LinkedHashMap<String, Object>();
    properties.put( "name", "Journey" );
    properties.put( "genre", "Classic Rock" );
    properties.put( "founded", 1973 );
    em.create( "testin", properties );

    // See http://www.mongodb.org/display/DOCS/Java+Tutorial

    Mongo m = new Mongo( "localhost", 27017 );

    DB db = m.getDB( "test-organization/test-app" );
    db.authenticate( "test", "test".toCharArray() );

    BasicBSONList list = new BasicBSONList();
    list.add( "Stone Temple Pilots" );
    list.add( "Journey" );

    BasicDBObject query = new BasicDBObject();
    query.put( "name", new BasicDBObject( "$in", list ) );

    DBCollection coll = db.getCollection( "testins" );
    DBCursor cur = coll.find( query );

    assertTrue( cur.hasNext() );

    DBObject result = cur.next();
    assertEquals( "Journey", result.get( "name" ) );
    assertEquals( "Classic Rock", result.get( "genre" ) );

    result = cur.next();
    assertEquals( "Stone Temple Pilots", result.get( "name" ) );
    assertEquals( "Rock", result.get( "genre" ) );

    assertFalse( cur.hasNext() );
}
 
Example 5
Source File: MongoQueryTest.java    From usergrid with Apache License 2.0 4 votes vote down vote up
@Test
public void or() throws Exception {

    UUID appId = emf.lookupApplication( "test-organization/test-app" );
    EntityManager em = emf.getEntityManager( appId );

    Map<String, Object> properties = new LinkedHashMap<String, Object>();
    properties.put( "name", "Kings of Leon" );
    properties.put( "genre", "Southern Rock" );
    properties.put( "founded", 2000 );
    em.create( "testor", properties );

    properties = new LinkedHashMap<String, Object>();
    properties.put( "name", "Stone Temple Pilots" );
    properties.put( "genre", "Rock" );
    properties.put( "founded", 1986 );
    em.create( "testor", properties );

    properties = new LinkedHashMap<String, Object>();
    properties.put( "name", "Journey" );
    properties.put( "genre", "Classic Rock" );
    properties.put( "founded", 1973 );
    em.create( "testor", properties );

    // See http://www.mongodb.org/display/DOCS/Java+Tutorial

    Mongo m = new Mongo( "localhost", 27017 );

    DB db = m.getDB( "test-organization/test-app" );
    db.authenticate( "test", "test".toCharArray() );

    BasicBSONList list = new BasicBSONList();
    list.add( new BasicDBObject( "founded", new BasicDBObject( "$gte", 2000 ) ) );
    list.add( new BasicDBObject( "founded", new BasicDBObject( "$lte", 1973 ) ) );

    BasicDBObject query = new BasicDBObject();
    query.put( "$or", list );

    DBCollection coll = db.getCollection( "testors" );
    DBCursor cur = coll.find( query );

    assertTrue( cur.hasNext() );

    DBObject result = cur.next();
    assertEquals( "Journey", result.get( "name" ) );
    assertEquals( "Classic Rock", result.get( "genre" ) );

    result = cur.next();
    assertEquals( "Kings of Leon", result.get( "name" ) );
    assertEquals( "Southern Rock", result.get( "genre" ) );

    assertFalse( cur.hasNext() );
}
 
Example 6
Source File: MongoQueryTest.java    From usergrid with Apache License 2.0 4 votes vote down vote up
@Test
public void and() throws Exception {

    UUID appId = emf.lookupApplication( "test-organization/test-app" );
    EntityManager em = emf.getEntityManager( appId );

    Map<String, Object> properties = new LinkedHashMap<String, Object>();
    properties.put( "name", "Kings of Leon" );
    properties.put( "genre", "Southern Rock" );
    properties.put( "founded", 2000 );
    em.create( "testand", properties );

    properties = new LinkedHashMap<String, Object>();
    properties.put( "name", "Stone Temple Pilots" );
    properties.put( "genre", "Rock" );
    properties.put( "founded", 1986 );
    em.create( "testand", properties );

    properties = new LinkedHashMap<String, Object>();
    properties.put( "name", "Journey" );
    properties.put( "genre", "Classic Rock" );
    properties.put( "founded", 1973 );
    em.create( "testand", properties );

    // See http://www.mongodb.org/display/DOCS/Java+Tutorial

    Mongo m = new Mongo( "localhost", 27017 );

    DB db = m.getDB( "test-organization/test-app" );
    db.authenticate( "test", "test".toCharArray() );

    BasicBSONList list = new BasicBSONList();
    list.add( new BasicDBObject( "founded", new BasicDBObject( "$gte", 2000 ) ) );
    list.add( new BasicDBObject( "founded", new BasicDBObject( "$lte", 2005 ) ) );

    BasicDBObject query = new BasicDBObject();
    query.put( "$and", list );

    DBCollection coll = db.getCollection( "testands" );
    DBCursor cur = coll.find( query );

    assertTrue( cur.hasNext() );

    DBObject result = cur.next();
    assertEquals( "Kings of Leon", result.get( "name" ) );
    assertEquals( "Southern Rock", result.get( "genre" ) );
    assertFalse( cur.hasNext() );
}