Example usage for com.mongodb DBObject toMap

List of usage examples for com.mongodb DBObject toMap

Introduction

In this page you can find the example usage for com.mongodb DBObject toMap.

Prototype

Map toMap();

Source Link

Document

Returns a map representing this BSONObject.

Usage

From source file:org.graylog2.indexer.IndexFailureServiceImpl.java

License:Open Source License

@Override
public List<IndexFailure> all(int limit, int offset) {
    List<IndexFailure> failures = Lists.newArrayList();

    DBObject sort = new BasicDBObject();
    sort.put("$natural", -1);

    List<DBObject> results = query(IndexFailureImpl.class, new BasicDBObject(), sort, limit, offset);
    for (DBObject o : results) {
        failures.add(new IndexFailureImpl((ObjectId) o.get("_id"), o.toMap()));
    }//  w w w . jav  a  2s.  co  m

    return failures;
}

From source file:org.graylog2.indexer.ranges.IndexRangeServiceImpl.java

License:Open Source License

@Override
public IndexRange get(String index) throws NotFoundException {
    DBObject dbo = findOne(IndexRangeImpl.class, new BasicDBObject("index", index));

    if (dbo == null)
        throw new NotFoundException("Index " + index + " not found.");

    return new IndexRangeImpl((ObjectId) dbo.get("_id"), dbo.toMap());
}

From source file:org.graylog2.indexer.ranges.IndexRangeServiceImpl.java

License:Open Source License

@Override
public List<IndexRange> getFrom(int timestamp) {
    List<IndexRange> ranges = Lists.newArrayList();

    BasicDBObject query = new BasicDBObject();
    query.put("start", new BasicDBObject("$gte", timestamp));

    for (DBObject dbo : query(IndexRangeImpl.class, query)) {
        ranges.add(new IndexRangeImpl((ObjectId) dbo.get("_id"), dbo.toMap()));
    }/*ww w .j  a v  a  2  s  .  com*/

    Collections.sort(ranges, new Comparator<IndexRange>() {
        @Override
        public int compare(IndexRange o1, IndexRange o2) {
            return o2.getStart().compareTo(o1.getStart());
        }
    });

    return ranges;
}

From source file:org.graylog2.inputs.InputServiceImpl.java

License:Open Source License

@Override
public List<Input> allOfThisNode(final String nodeId) {
    final List<BasicDBObject> query = ImmutableList.of(new BasicDBObject(MessageInput.FIELD_NODE_ID, nodeId),
            new BasicDBObject(MessageInput.FIELD_GLOBAL, true));
    final List<DBObject> ownInputs = query(InputImpl.class, new BasicDBObject("$or", query));

    final ImmutableList.Builder<Input> inputs = ImmutableList.builder();
    for (final DBObject o : ownInputs) {
        inputs.add(new InputImpl((ObjectId) o.get("_id"), o.toMap()));
    }/*from   www  .j ava 2  s  .c om*/

    return inputs.build();
}

From source file:org.graylog2.inputs.InputServiceImpl.java

License:Open Source License

@Override
public List<Input> allOfRadio(Node radio) {
    final List<BasicDBObject> query = ImmutableList.of(
            new BasicDBObject(MessageInput.FIELD_RADIO_ID, radio.getNodeId()),
            new BasicDBObject(MessageInput.FIELD_NODE_ID, radio.getNodeId()),
            new BasicDBObject(MessageInput.FIELD_GLOBAL, true));

    final ImmutableList.Builder<Input> inputs = ImmutableList.builder();
    for (DBObject o : query(InputImpl.class, new BasicDBObject("$or", query))) {
        inputs.add(new InputImpl((ObjectId) o.get("_id"), o.toMap()));
    }//from   w  w  w . j  a v a  2 s  .c  o  m

    return inputs.build();
}

From source file:org.graylog2.inputs.InputServiceImpl.java

License:Open Source License

@Override
public Input find(String id) throws NotFoundException {
    final DBObject o = get(org.graylog2.inputs.InputImpl.class, id);
    if (o == null) {
        throw new NotFoundException("Input <" + id + "> not found!");
    }//from   ww  w .  java2  s  . co m
    return new org.graylog2.inputs.InputImpl((ObjectId) o.get("_id"), o.toMap());
}

From source file:org.graylog2.inputs.InputServiceImpl.java

License:Open Source License

@Override
public Input findForThisNodeOrGlobal(String nodeId, String id) throws NotFoundException {
    final List<BasicDBObject> forThisNodeOrGlobal = ImmutableList.of(
            new BasicDBObject(MessageInput.FIELD_NODE_ID, nodeId),
            new BasicDBObject(MessageInput.FIELD_GLOBAL, true));

    final List<BasicDBObject> query = ImmutableList.of(new BasicDBObject("_id", new ObjectId(id)),
            new BasicDBObject("$or", forThisNodeOrGlobal));

    final DBObject o = findOne(InputImpl.class, new BasicDBObject("$and", query));
    return new InputImpl((ObjectId) o.get("_id"), o.toMap());
}

From source file:org.graylog2.inputs.InputServiceImpl.java

License:Open Source License

@Override
public Input findForThisRadioOrGlobal(final String radioId, String id) throws NotFoundException {
    final List<DBObject> radioIdOrGlobal = ImmutableList.<DBObject>of(
            new BasicDBObject(MessageInput.FIELD_RADIO_ID, radioId),
            new BasicDBObject(MessageInput.FIELD_NODE_ID, radioId),
            new BasicDBObject(MessageInput.FIELD_GLOBAL, true));

    final List<DBObject> query = ImmutableList.<DBObject>of(new BasicDBObject("_id", new ObjectId(id)),
            new BasicDBObject("$or", radioIdOrGlobal));

    final DBObject o = findOne(InputImpl.class, new BasicDBObject("$and", query));
    if (o == null) {
        throw new NotFoundException();
    } else {//from  w  w  w.j  a  v  a  2 s  . c om
        return new InputImpl((ObjectId) o.get("_id"), o.toMap());
    }
}

From source file:org.graylog2.inputs.InputServiceImpl.java

License:Open Source License

@Override
public Input findForThisNode(String nodeId, String id) throws NotFoundException, IllegalArgumentException {
    final List<BasicDBObject> forThisNode = ImmutableList.of(
            new BasicDBObject(MessageInput.FIELD_NODE_ID, nodeId),
            new BasicDBObject(MessageInput.FIELD_GLOBAL, false));

    final List<BasicDBObject> query = ImmutableList.of(new BasicDBObject("_id", new ObjectId(id)),
            new BasicDBObject("$and", forThisNode));

    final DBObject o = findOne(InputImpl.class, new BasicDBObject("$and", query));
    if (o == null) {
        throw new NotFoundException();
    } else {/*from   ww  w  .  j a  va  2s.co m*/
        return new InputImpl((ObjectId) o.get("_id"), o.toMap());
    }
}

From source file:org.graylog2.inputs.InputServiceImpl.java

License:Open Source License

@Override
public Input findForThisRadio(String radioId, String id) throws NotFoundException {
    final List<Object> list = new ArrayList<Object>() {
        {/*from  www .  j  ava  2 s .  c  o m*/
            add(false);
            add(null);
        }
    };

    final List<DBObject> query = ImmutableList.of(new BasicDBObject("_id", new ObjectId(id)),
            new BasicDBObject(MessageInput.FIELD_RADIO_ID, radioId),
            QueryBuilder.start(MessageInput.FIELD_GLOBAL).in(list).get());

    final DBObject o = findOne(InputImpl.class, new BasicDBObject("$and", query));
    if (o == null) {
        throw new NotFoundException();
    } else {
        return new InputImpl((ObjectId) o.get("_id"), o.toMap());
    }
}