use of org.bson.BSONObject in project mongo-java-driver by mongodb.
the class DefaultDBCallback method objectDone.
@Override
public Object objectDone() {
String name = curName();
BSONObject document = (BSONObject) super.objectDone();
if (!(document instanceof BasicBSONList)) {
Iterator<String> iterator = document.keySet().iterator();
if (iterator.hasNext() && iterator.next().equals("$ref") && iterator.hasNext() && iterator.next().equals("$id")) {
_put(name, new DBRef((String) document.get("$db"), (String) document.get("$ref"), document.get("$id")));
}
}
return document;
}
use of org.bson.BSONObject in project camel by apache.
the class MongoDbConversionsTest method testInsertBsonInputStream.
@Test
public void testInsertBsonInputStream() {
assertEquals(0, testCollection.count());
DefaultDBEncoder encoder = new DefaultDBEncoder();
BSONObject bsonObject = new BasicDBObject();
bsonObject.put("_id", "testInsertBsonString");
Object result = template.requestBody("direct:insertJsonString", new ByteArrayInputStream(encoder.encode(bsonObject)));
DBObject b = testCollection.find(new BasicDBObject("_id", "testInsertBsonString")).first();
assertNotNull("No record with 'testInsertBsonString' _id", b);
}
use of org.bson.BSONObject in project v7files by thiloplanz.
the class MapUtils method get.
private static Object get(Map<?, ?> b, String fieldName) {
if (!fieldName.contains("."))
return notNull(b.get(fieldName));
String[] path = StringUtils.split(fieldName, ".", 2);
Object nested = b.get(path[0]);
if (nested == null)
return null;
if (nested instanceof BSONObject)
return BSONUtils.get((BSONObject) nested, path[1]);
if (nested instanceof Map<?, ?>)
return get((Map<?, ?>) nested, path[1]);
throw new IllegalArgumentException("cannot get field `" + fieldName + "` of " + b);
}
use of org.bson.BSONObject in project v7files by thiloplanz.
the class BucketsServlet method doEchoPutGet.
private void doEchoPutGet(HttpServletRequest request, HttpServletResponse response, BSONObject bucket, byte[] sha) throws IOException {
Content content = storage.getContent(sha);
if (content == null) {
response.sendError(HttpServletResponse.SC_NOT_FOUND, "Bucket '" + bucket.get("_id") + "' does not have a file matching digest '" + Hex.encodeHexString(sha) + "'");
return;
}
BSONObject file = new BasicBSONObject("sha", sha);
String customFilename = request.getParameter("filename");
if (StringUtils.isNotBlank(customFilename))
file.put("filename", customFilename);
sendFile(request, response, sha, file, content);
}
use of org.bson.BSONObject in project v7files by thiloplanz.
the class BucketsServlet method doPost.
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String _id = request.getPathInfo().substring(1);
BSONObject bucket = bucketCollection.findOne(_id);
if (bucket == null) {
response.sendError(HttpServletResponse.SC_NOT_FOUND, "Bucket '" + _id + "' not found");
return;
}
String mode = BSONUtils.getString(bucket, "POST");
if ("FormPost".equals(mode)) {
doFormPost(request, response, bucket);
return;
}
// method not allowed
super.doPost(request, response);
}
Aggregations