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");
}
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;
}
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();
}
}
}
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));
}
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);
}
}
}
}
Aggregations