Search in sources :

Example 36 with BasicDBList

use of com.mongodb.BasicDBList in project graylog2-server by Graylog2.

the class SystemSetting method getList.

public BasicDBList getList(String key) {
    DBCollection coll = getCollection();
    DBObject query = new BasicDBObject();
    query.put("key", key);
    DBObject result = coll.findOne(query);
    return (BasicDBList) result.get("value");
}
Also used : DBCollection(com.mongodb.DBCollection) BasicDBObject(com.mongodb.BasicDBObject) BasicDBList(com.mongodb.BasicDBList) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject)

Example 37 with BasicDBList

use of com.mongodb.BasicDBList in project graylog2-server by Graylog2.

the class SystemSettingAccessor method getForcedAlarmCallbacks.

public Set<String> getForcedAlarmCallbacks() {
    Set<String> callbacks = Sets.newHashSet();
    SystemSetting s = new SystemSetting(mongoConnection);
    BasicDBList objs = s.getList(KEY_FORCED_ALARM_CALLBACKS);
    for (Object obj : objs) {
        String typeclass = (String) obj;
        if (typeclass != null && !typeclass.isEmpty()) {
            callbacks.add(typeclass);
        }
    }
    return callbacks;
}
Also used : BasicDBList(com.mongodb.BasicDBList)

Example 38 with BasicDBList

use of com.mongodb.BasicDBList in project graylog2-server by Graylog2.

the class LdapSettingsImpl method getGroupMapping.

@Nonnull
@SuppressWarnings("unchecked")
@Override
public Map<String, String> getGroupMapping() {
    final BasicDBList groupMappingList = (BasicDBList) fields.get(GROUP_MAPPING_LIST);
    final Map<String, String> groupMapping;
    if (groupMappingList == null) {
        // pre-2.0 storage format, convert after read
        // should actually have been converted during start, but let's play safe here
        groupMapping = (Map<String, String>) fields.get(GROUP_MAPPING);
    } else {
        groupMapping = Maps.newHashMapWithExpectedSize(groupMappingList.size());
        for (Object entry : groupMappingList) {
            final DBObject field = (DBObject) entry;
            groupMapping.put((String) field.get(LDAP_GROUP_MAPPING_NAMEKEY), (String) field.get(LDAP_GROUP_MAPPING_ROLEKEY));
        }
    }
    if (groupMapping == null || groupMapping.isEmpty()) {
        return Collections.emptyMap();
    } else {
        // we store role ids, but the outside world uses role names to identify them
        try {
            final Map<String, Role> idToRole = roleService.loadAllIdMap();
            return Maps.newHashMap(Maps.transformValues(groupMapping, Roles.roleIdToNameFunction(idToRole)));
        } catch (NotFoundException e) {
            LOG.error("Unable to load role mapping");
            return Collections.emptyMap();
        }
    }
}
Also used : Role(org.graylog2.shared.users.Role) BasicDBList(com.mongodb.BasicDBList) NotFoundException(org.graylog2.database.NotFoundException) DBObject(com.mongodb.DBObject) DBObject(com.mongodb.DBObject) Nonnull(javax.annotation.Nonnull)

Example 39 with BasicDBList

use of com.mongodb.BasicDBList in project mongo-hadoop by mongodb.

the class MongoLoaderTest method testDeepness.

@Test
public void testDeepness() throws IOException {
    String userSchema = "b:{t:tuple(t1:chararray, b:{t:tuple(i1:int, i2:int)})}";
    BasicDBList innerBag = new BasicDBList();
    innerBag.add(new BasicDBObject().append("i1", 1).append("i2", 2));
    innerBag.add(new BasicDBObject().append("i1", 3).append("i2", 4));
    BasicDBList bag = new BasicDBList();
    bag.add(new BasicDBObject().append("t1", "t1_value").append("b", innerBag));
    MongoLoader ml = new MongoLoader(userSchema);
    DataBag result = (DataBag) BSONLoader.readField(bag, ml.getFields()[0]);
    assertEquals(1, result.size());
    Iterator<Tuple> bit = result.iterator();
    Tuple t = bit.next();
    assertEquals(2, t.size());
    DataBag innerBagResult = (DataBag) t.get(1);
    assertEquals(2, innerBagResult.size());
    Iterator<Tuple> innerBit = innerBagResult.iterator();
    Tuple innerT = innerBit.next();
    assertEquals(2, innerT.get(1));
}
Also used : BasicDBList(com.mongodb.BasicDBList) BasicDBObject(com.mongodb.BasicDBObject) DataBag(org.apache.pig.data.DataBag) Tuple(org.apache.pig.data.Tuple) Test(org.junit.Test)

Example 40 with BasicDBList

use of com.mongodb.BasicDBList in project morphia by mongodb.

the class EmbeddedMapper method readCollection.

@SuppressWarnings("unchecked")
private void readCollection(final Datastore datastore, final Mapper mapper, final Object entity, final EntityCache cache, final MappedField mf, final DBObject dbObject) {
    Collection values;
    final Object dbVal = mf.getDbObjectValue(dbObject);
    if (dbVal != null) {
        // multiple documents in a List
        values = mf.isSet() ? mapper.getOptions().getObjectFactory().createSet(mf) : mapper.getOptions().getObjectFactory().createList(mf);
        final List dbValues;
        if (dbVal instanceof List) {
            dbValues = (List) dbVal;
        } else {
            dbValues = new BasicDBList();
            dbValues.add(dbVal);
        }
        EphemeralMappedField ephemeralMappedField = !mapper.isMapped(mf.getType()) && isMapOrCollection(mf) && (mf.getSubType() instanceof ParameterizedType) ? new EphemeralMappedField((ParameterizedType) mf.getSubType(), mf, mapper) : null;
        for (final Object o : dbValues) {
            Object newEntity = null;
            if (o != null) {
                //run converters
                if (mapper.getConverters().hasSimpleValueConverter(mf) || mapper.getConverters().hasSimpleValueConverter(mf.getSubClass())) {
                    newEntity = mapper.getConverters().decode(mf.getSubClass(), o, mf);
                } else {
                    newEntity = readMapOrCollectionOrEntity(datastore, mapper, cache, mf, ephemeralMappedField, (DBObject) o);
                }
            }
            values.add(newEntity);
        }
        if (!values.isEmpty() || mapper.getOptions().isStoreEmpties()) {
            if (mf.getType().isArray()) {
                mf.setFieldValue(entity, ReflectionUtils.convertToArray(mf.getSubClass(), ReflectionUtils.iterToList(values)));
            } else {
                mf.setFieldValue(entity, values);
            }
        }
    }
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) BasicDBList(com.mongodb.BasicDBList) Collection(java.util.Collection) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject) BasicDBList(com.mongodb.BasicDBList) ArrayList(java.util.ArrayList) List(java.util.List) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject)

Aggregations

BasicDBList (com.mongodb.BasicDBList)69 BasicDBObject (com.mongodb.BasicDBObject)40 DBObject (com.mongodb.DBObject)33 Test (org.junit.Test)27 Document (org.springframework.data.mongodb.core.mapping.Document)16 ArrayList (java.util.ArrayList)13 List (java.util.List)9 DBCollection (com.mongodb.DBCollection)8 Document (org.bson.Document)7 DBCursor (com.mongodb.DBCursor)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 DBRef (com.mongodb.DBRef)5 Collection (java.util.Collection)4 NotFoundException (org.graylog2.database.NotFoundException)4 ImmutableList (com.google.common.collect.ImmutableList)3 MongoClient (com.mongodb.MongoClient)3 MongoException (com.mongodb.MongoException)3 MongoInputSplit (com.mongodb.hadoop.input.MongoInputSplit)3 LinkedHashMap (java.util.LinkedHashMap)3