List of usage examples for com.mongodb BasicDBObject get
public Object get(final String key)
From source file:org.exoplatform.chat.server.ChatServer.java
License:Open Source License
@Resource @Route("/getMeetingNotes") public Response.Content getMeetingNotes(String user, String token, String room, String fromTimestamp, String toTimestamp, String serverBase) throws IOException { if (!tokenService.hasUserWithToken(user, token)) { return Response.notFound("Petit malin !"); }//from w w w.java2 s . c o m Long from = null; Long to = null; String xwiki = ""; try { if (fromTimestamp != null && !"".equals(fromTimestamp)) from = Long.parseLong(fromTimestamp); } catch (NumberFormatException nfe) { LOG.info("fromTimestamp is not a valid Long number"); } try { if (toTimestamp != null && !"".equals(toTimestamp)) to = Long.parseLong(toTimestamp); } catch (NumberFormatException nfe) { LOG.info("fromTimestamp is not a valid Long number"); } String data = chatService.read(room, userService, false, from, to); BasicDBObject datao = (BasicDBObject) JSON.parse(data); if (datao.containsField("messages")) { List<UserBean> users = userService.getUsers(room); ReportBean reportBean = new ReportBean(); reportBean.fill((BasicDBList) datao.get("messages"), users); String roomName = ""; List<SpaceBean> spaces = userService.getSpaces(user); for (SpaceBean spaceBean : spaces) { if (room.equals(spaceBean.getRoom())) { roomName = spaceBean.getDisplayName(); } } List<RoomBean> roomBeans = userService.getTeams(user); for (RoomBean roomBean : roomBeans) { if (room.equals(roomBean.getRoom())) { roomName = roomBean.getFullname(); } } xwiki = reportBean.getAsXWiki(serverBase); } return Response.ok(xwiki).withMimeType("text/event-stream; charset=UTF-8").withHeader("Cache-Control", "no-cache"); }
From source file:org.fastmongo.odm.dbobject.mapping.core.DbObjectToDomainConverter.java
License:Apache License
/** * Fills and returns an object represented by the given dbObject and stored as a map value. * * @param map the map holding this object. * @param mapValueType the type of values in the map, not assignable from {@link java.util.Collection}. * @param key the corresponded key in the map for this object. * @param dbObject the mongo DBObject which represents result object. * @param context the context for this operation, bounded to the root document. * @return the filled map value./*from w ww . j a v a 2 s.co m*/ */ private Object fillMapObjectValue(Map<String, Object> map, Type mapValueType, String key, BasicDBObject dbObject, Context context) { String className = classNameResolver.getClassName(mapValueType, dbObject, classPrefix); if (className != null) { String link = (String) dbObject.get(LINK_KEY); if (link != null) { final Object id = dbObject.get(ID_KEY); final Class<?> clazz = loadClass(className); return newProxy(clazz, new LinkObjectLoader(clazz, id, context), new MapValueReplacer(map, key)); } else { Object obj = newInstance(className); fillObject(obj, dbObject, context); return obj; } } else { Map<String, Object> childMap = new LinkedHashMap<>(); fillMap(childMap, dbObject, mapValueType, context); return childMap; } }
From source file:org.fudgemsg.mapping.mongo.MongoDBFudgeBuilder.java
License:Apache License
@Override public DBObject buildObject(FudgeDeserializer deserializer, FudgeMsg fields) { if (fields == null) { return null; }//from ww w. j a v a 2s. c o m BasicDBObject dbObject = new BasicDBObject(); for (FudgeField field : fields.getAllFields()) { if (field.getName() == null) { if (field.getOrdinal() == 0) { continue; } // REVIEW kirk 2009-10-22 -- Should this be configurable so that it just // silently drops unnamed fields? throw new IllegalArgumentException("Field encountered without a name (" + field + ")"); } Object value = field.getValue(); value = encodeFieldValue(deserializer, dbObject.get(field.getName()), value); dbObject.put(field.getName(), value); } return dbObject; }
From source file:org.fudgemsg.mapping.MongoDBFudgeBuilder.java
License:Apache License
/** * {@inheritDoc}/*from w ww. jav a2s.co m*/ */ @Override public DBObject buildObject(FudgeDeserializationContext context, FudgeFieldContainer fields) { if (fields == null) { return null; } BasicDBObject dbObject = new BasicDBObject(); for (FudgeField field : fields.getAllFields()) { if (field.getName() == null) { if (field.getOrdinal() == 0) { continue; } // REVIEW kirk 2009-10-22 -- Should this be configurable so that it just // silently drops unnamed fields? throw new IllegalArgumentException("Field encountered without a name (" + field + ")"); } Object value = field.getValue(); value = encodeFieldValue(context, dbObject.get(field.getName()), value); dbObject.put(field.getName(), value); } return dbObject; }
From source file:org.grails.datastore.mapping.mongo.engine.MongoEntityPersister.java
License:Apache License
@Override protected void loadEmbeddedCollection(@SuppressWarnings("rawtypes") EmbeddedCollection embeddedCollection, EntityAccess ea, Object embeddedInstances, String propertyKey) { Collection<Object> instances; if (List.class.isAssignableFrom(embeddedCollection.getType())) { instances = new ArrayList<Object>(); } else {// ww w . j a v a 2 s. c o m instances = new HashSet<Object>(); } if (embeddedInstances instanceof BasicDBList) { BasicDBList list = (BasicDBList) embeddedInstances; for (Object dbo : list) { if (dbo instanceof BasicDBObject) { PersistentEntity embeddedPersistentEntity; BasicDBObject nativeEntry = (BasicDBObject) dbo; PersistentEntity associatedEntity = embeddedCollection.getAssociatedEntity(); MappingContext mappingContext = associatedEntity.getMappingContext(); String embeddedClassName = mappingContext.isInInheritanceHierarchy(associatedEntity) ? (String) nativeEntry.get("_embeddedClassName") : null; if (embeddedClassName != null) { embeddedPersistentEntity = getMappingContext().getPersistentEntity(embeddedClassName); } else { embeddedPersistentEntity = associatedEntity; } Object instance = newEntityInstance(embeddedPersistentEntity); refreshObjectStateFromNativeEntry(embeddedPersistentEntity, instance, null, nativeEntry, true); instances.add(instance); } } } ea.setProperty(embeddedCollection.getName(), instances); }
From source file:org.graylog2.dashboards.DashboardServiceImpl.java
License:Open Source License
@Override public Dashboard load(String id) throws NotFoundException { BasicDBObject o = (BasicDBObject) get(DashboardImpl.class, id); if (o == null) { throw new NotFoundException(); }// ww w. j a va2 s.com return new DashboardImpl((ObjectId) o.get("_id"), o.toMap()); }
From source file:org.graylog2.dashboards.DashboardServiceImpl.java
License:Open Source License
@Override public List<Dashboard> all() { List<Dashboard> dashboards = Lists.newArrayList(); List<DBObject> results = query(DashboardImpl.class, new BasicDBObject()); for (DBObject o : results) { Map<String, Object> fields = o.toMap(); Dashboard dashboard = new DashboardImpl((ObjectId) o.get("_id"), fields); // Add all widgets of this dashboard. if (fields.containsKey(DashboardImpl.EMBEDDED_WIDGETS)) { for (BasicDBObject widgetFields : (List<BasicDBObject>) fields .get(DashboardImpl.EMBEDDED_WIDGETS)) { DashboardWidget widget = null; try { widget = DashboardWidget.fromPersisted(metricRegistry, searches, widgetFields); } catch (DashboardWidget.NoSuchWidgetTypeException e) { LOG.error("No such widget type: [" + widgetFields.get("type") + "] - Dashboard: [" + dashboard.getId() + "]", e); continue; } catch (InvalidRangeParametersException e) { LOG.error("Invalid range parameters of widget in dashboard: [" + dashboard.getId() + "]", e);// ww w .j av a 2 s . c om continue; } catch (InvalidWidgetConfigurationException e) { LOG.error("Invalid configuration of widget in dashboard: [" + dashboard.getId() + "]", e); continue; } dashboard.addPersistedWidget(widget); } } dashboards.add(dashboard); } return dashboards; }
From source file:org.graylog2.dashboards.widgets.DashboardWidget.java
License:Open Source License
public static DashboardWidget fromPersisted(MetricRegistry metricRegistry, Searches searches, BasicDBObject fields) throws NoSuchWidgetTypeException, InvalidRangeParametersException, InvalidWidgetConfigurationException { Type type;// www .ja v a 2s. co m try { type = Type.valueOf(((String) fields.get(FIELD_TYPE)).toUpperCase()); } catch (IllegalArgumentException e) { throw new NoSuchWidgetTypeException(); } BasicDBObject config = (BasicDBObject) fields.get(FIELD_CONFIG); // Build timerange. BasicDBObject timerangeConfig = (BasicDBObject) config.get("timerange"); final String rangeType = (String) timerangeConfig.get(FIELD_TYPE); if (rangeType == null) { throw new InvalidRangeParametersException("range type not set"); } TimeRange timeRange; switch (rangeType) { case "relative": timeRange = new RelativeRange((Integer) timerangeConfig.get("range")); break; case "keyword": timeRange = new KeywordRange((String) timerangeConfig.get("keyword"), true); break; case "absolute": String from = new DateTime(timerangeConfig.get("from"), DateTimeZone.UTC) .toString(Tools.ES_DATE_FORMAT); String to = new DateTime(timerangeConfig.get("to"), DateTimeZone.UTC).toString(Tools.ES_DATE_FORMAT); timeRange = new AbsoluteRange(from, to); break; default: throw new InvalidRangeParametersException("range_type not recognized"); } final String description = (String) fields.get(FIELD_DESCRIPTION); final int cacheTime = (int) firstNonNull(fields.get(FIELD_CACHE_TIME), 0); return buildDashboardWidget(type, metricRegistry, searches, (String) fields.get(FIELD_ID), description, cacheTime, config, (String) config.get("query"), timeRange, (String) fields.get(FIELD_CREATOR_USER_ID)); }
From source file:org.graylog2.dashboards.widgets.DashboardWidgetCreator.java
License:Open Source License
public DashboardWidget fromPersisted(Searches searches, BasicDBObject fields) throws DashboardWidget.NoSuchWidgetTypeException, InvalidRangeParametersException, InvalidWidgetConfigurationException { DashboardWidget.Type type;// ww w . j av a 2 s . c o m try { type = DashboardWidget.Type .valueOf(((String) fields.get(DashboardWidget.FIELD_TYPE)).toUpperCase(Locale.ENGLISH)); } catch (IllegalArgumentException e) { throw new DashboardWidget.NoSuchWidgetTypeException(); } BasicDBObject config = (BasicDBObject) fields.get(DashboardWidget.FIELD_CONFIG); // Build timerange. BasicDBObject timerangeConfig = (BasicDBObject) config.get("timerange"); final String rangeType = (String) timerangeConfig.get(DashboardWidget.FIELD_TYPE); if (rangeType == null) { throw new InvalidRangeParametersException("range type not set"); } final String widgetId = (String) fields.get(DashboardWidget.FIELD_ID); TimeRange timeRange; try { switch (rangeType) { case "relative": timeRange = new RelativeRange((Integer) timerangeConfig.get("range")); break; case "keyword": timeRange = new KeywordRange((String) timerangeConfig.get("keyword")); break; case "absolute": String from = new DateTime(timerangeConfig.get("from"), DateTimeZone.UTC) .toString(Tools.ES_DATE_FORMAT); String to = new DateTime(timerangeConfig.get("to"), DateTimeZone.UTC) .toString(Tools.ES_DATE_FORMAT); timeRange = new AbsoluteRange(from, to); break; default: throw new InvalidRangeParametersException("range_type not recognized"); } } catch (InvalidRangeParametersException e) { LOG.error("Invalid time range provided on widget " + widgetId, e); timeRange = null; } final String description = (String) fields.get(DashboardWidget.FIELD_DESCRIPTION); final int cacheTime = (int) firstNonNull(fields.get(DashboardWidget.FIELD_CACHE_TIME), 0); return buildDashboardWidget(type, searches, widgetId, description, cacheTime, config, (String) config.get("query"), timeRange, (String) fields.get(DashboardWidget.FIELD_CREATOR_USER_ID)); }
From source file:org.graylog2.savedsearches.SavedSearchServiceImpl.java
License:Open Source License
@Override @SuppressWarnings("unchecked") public SavedSearchImpl load(String id) throws NotFoundException { BasicDBObject o = (BasicDBObject) get(SavedSearchImpl.class, id); if (o == null) { throw new NotFoundException(); }/*www . j av a 2 s.c o m*/ return new SavedSearchImpl((ObjectId) o.get("_id"), o.toMap()); }