List of usage examples for com.mongodb DBObject toMap
Map toMap();
From source file:org.graylog2.notifications.NotificationServiceImpl.java
License:Open Source License
@Override public List<Notification> all() { List<Notification> notifications = Lists.newArrayList(); for (DBObject obj : query(NotificationImpl.class, new BasicDBObject(), new BasicDBObject("timestamp", -1))) { try {//from w w w. j a v a 2 s. c o m notifications.add(new NotificationImpl(new ObjectId(obj.get("_id").toString()), obj.toMap())); } catch (IllegalArgumentException e) { LOG.warn("There is a notification type we can't handle: [" + obj.get("type") + "]"); continue; } } return notifications; }
From source file:org.graylog2.plugins.PluginConfiguration.java
License:Open Source License
public static Map<String, String> load(Core server, String className) { Map<String, String> configuration = Maps.newHashMap(); try {//from w w w . j a v a 2s . c om DBCollection coll = server.getMongoConnection().getDatabase().getCollection("plugin_configurations"); DBObject query = new BasicDBObject(); query.put("typeclass", className); DBObject res = coll.findOne(query); if (res == null) { return configuration; } DBObject rawConfig = (BasicDBObject) res.get("configuration"); Map<String, String> configs = rawConfig.toMap(); return configs; } catch (Exception e) { LOG.error("Could not fetch plugin configuration for <" + className + ">.", e); } return configuration; }
From source file:org.graylog2.savedsearches.SavedSearchServiceImpl.java
License:Open Source License
@Override @SuppressWarnings("unchecked") public List<SavedSearch> all() { List<SavedSearch> searches = Lists.newArrayList(); List<DBObject> results = query(SavedSearchImpl.class, new BasicDBObject()); for (DBObject o : results) { searches.add(new SavedSearchImpl((ObjectId) o.get("_id"), o.toMap())); }//w w w . ja va 2 s . co m return searches; }
From source file:org.graylog2.security.AccessTokenServiceImpl.java
License:Open Source License
@Override @SuppressWarnings("unchecked") public AccessToken load(String token) { DBObject query = new BasicDBObject(); query.put(AccessTokenImpl.TOKEN, token); final List<DBObject> objects = query(AccessTokenImpl.class, query); if (objects.isEmpty()) { return null; }//from www.j a v a 2s . c o m if (objects.size() > 1) { LOG.error("Multiple access tokens found, this is a serious bug."); throw new IllegalStateException("Access tokens collection has no unique index!"); } final DBObject tokenObject = objects.get(0); final Object id = tokenObject.get("_id"); return new AccessTokenImpl((ObjectId) id, tokenObject.toMap()); }
From source file:org.graylog2.security.AccessTokenServiceImpl.java
License:Open Source License
@Override @SuppressWarnings("unchecked") public List<AccessToken> loadAll(String username) { DBObject query = new BasicDBObject(); query.put(AccessTokenImpl.USERNAME, username); final List<DBObject> objects = query(AccessTokenImpl.class, query); List<AccessToken> tokens = Lists.newArrayList(); for (DBObject tokenObject : objects) { final Object id = tokenObject.get("_id"); final AccessToken accessToken = new AccessTokenImpl((ObjectId) id, tokenObject.toMap()); tokens.add(accessToken);/*from w ww . j av a 2s. c o m*/ } return tokens; }
From source file:org.graylog2.security.ldap.LdapSettingsServiceImpl.java
License:Open Source License
@Override public LdapSettings load() { DBObject query = new BasicDBObject(); final List<DBObject> results = query(LdapSettingsImpl.class, query); if (results.size() == 0) { return null; }/*from w w w.j a v a 2 s. c o m*/ if (results.size() > 1) { LOG.error( "Graylog does not yet support multiple LDAP backends, but {} configurations were found. This is a bug, ignoring LDAP config.", results.size()); return null; } final DBObject settingsObject = results.get(0); return ldapSettingsFactory.create((ObjectId) settingsObject.get("_id"), settingsObject.toMap()); }
From source file:org.graylog2.security.MongoDBSessionServiceImpl.java
License:Open Source License
@Override public MongoDbSession load(String sessionId) { DBObject query = new BasicDBObject(); query.put("session_id", sessionId); DBObject result = findOne(MongoDbSession.class, query); if (result == null) { return null; }// w ww. j av a 2 s . c o m final Object objectId = result.get("_id"); return new MongoDbSession((ObjectId) objectId, result.toMap()); }
From source file:org.graylog2.security.MongoDBSessionServiceImpl.java
License:Open Source License
@Override public Collection<MongoDbSession> loadAll() { DBObject query = new BasicDBObject(); List<MongoDbSession> dbSessions = Lists.newArrayList(); final List<DBObject> sessions = query(MongoDbSession.class, query); for (DBObject session : sessions) { dbSessions.add(new MongoDbSession((ObjectId) session.get("_id"), session.toMap())); }/*from w ww . ja v a 2s . co m*/ return dbSessions; }
From source file:org.graylog2.streams.OutputServiceImpl.java
License:Open Source License
@Override public Output load(String streamOutputId) throws NotFoundException { DBObject o = get(OutputImpl.class, streamOutputId); if (o == null) { throw new NotFoundException("Output <" + streamOutputId + "> not found!"); }//from w ww . jav a 2 s. c om return new OutputImpl((ObjectId) o.get("_id"), o.toMap()); }
From source file:org.graylog2.streams.StreamImpl.java
License:Open Source License
private Map<String, Set<Map<String, String>>> buildOutputsFromMongoDoc(DBObject stream) { Map<String, Set<Map<String, String>>> o = Maps.newHashMap(); List objs = (BasicDBList) stream.get("outputs"); if (objs == null || objs.isEmpty()) { return o; }//from w w w . j a va 2s .c om for (Object obj : objs) { try { DBObject output = (BasicDBObject) obj; String typeclass = (String) output.get("typeclass"); if (!o.containsKey(typeclass)) { o.put(typeclass, new HashSet<Map<String, String>>()); } // ZOMG we need an ODM in the next version. Map<String, String> outputConfig = Maps.newHashMap(); for (Object key : output.toMap().keySet()) { outputConfig.put(key.toString(), output.get(key.toString()).toString()); } o.get(typeclass).add(outputConfig); } catch (Exception e) { LOG.warn("Could not read stream output.", e); continue; } } return o; }