Search in sources :

Example 46 with BSONObject

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);
}
Also used : BSONObject(org.bson.BSONObject) BSONObject(org.bson.BSONObject) Map(java.util.Map)

Example 47 with BSONObject

use of org.bson.BSONObject in project v7files by thiloplanz.

the class BSONUtils method get.

public static Object get(BSONObject 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 get((BSONObject) nested, path[1]);
    throw new IllegalArgumentException("cannot get field `" + fieldName + "` of " + b);
}
Also used : BSONObject(org.bson.BSONObject) BSONObject(org.bson.BSONObject)

Example 48 with BSONObject

use of org.bson.BSONObject in project v7files by thiloplanz.

the class V7File method getAcl.

public Object[] getAcl(String permission) {
    BSONObject acls = (BSONObject) metaData.get("acl");
    if (acls == null)
        return null;
    List<?> acl = (List<?>) acls.get(permission);
    if (acl == null)
        return ArrayUtils.EMPTY_OBJECT_ARRAY;
    return acl.toArray();
}
Also used : BSONObject(org.bson.BSONObject) List(java.util.List)

Example 49 with BSONObject

use of org.bson.BSONObject in project v7files by thiloplanz.

the class V7File method getEffectiveAcl.

/**
 * @param permission
 *            "read", "write", or "open"
 * @return the ACL for this permission, if not set, inherited from parents
 *         null if not set (not even at parents), empty if set but empty
 */
public Object[] getEffectiveAcl(String permission) {
    BSONObject acls = (BSONObject) metaData.get("acl");
    if (acls == null)
        if (parent != null)
            return parent.getEffectiveAcl(permission);
        else
            return null;
    List<?> acl = (List<?>) acls.get(permission);
    if (acl == null)
        return ArrayUtils.EMPTY_OBJECT_ARRAY;
    return acl.toArray();
}
Also used : BSONObject(org.bson.BSONObject) List(java.util.List)

Example 50 with BSONObject

use of org.bson.BSONObject in project v7files by thiloplanz.

the class V7GridFS method updateContents.

void updateContents(DBObject metaData, ContentPointer newContents) throws IOException {
    ContentPointer oldContents = getContentPointer(metaData);
    if (newContents.contentEquals(oldContents))
        return;
    String filename = (String) metaData.get("filename");
    String contentType = (String) metaData.get("contentType");
    Object fileId = metaData.get("_id");
    BSONObject newContent = storage.updateBackRefs(newContents, fileId, filename, contentType);
    metaData.removeField("sha");
    metaData.removeField("length");
    metaData.removeField("in");
    metaData.putAll(newContent);
    updateMetaData(metaData);
}
Also used : ContentPointer(v7db.files.spi.ContentPointer) BSONObject(org.bson.BSONObject) BasicDBObject(com.mongodb.BasicDBObject) BSONObject(org.bson.BSONObject) DBObject(com.mongodb.DBObject)

Aggregations

BSONObject (org.bson.BSONObject)101 BasicBSONObject (org.bson.BasicBSONObject)49 Test (org.junit.Test)34 BasicDBObject (com.mongodb.BasicDBObject)19 SerializableString (com.fasterxml.jackson.core.SerializableString)14 SerializedString (com.fasterxml.jackson.core.io.SerializedString)14 LinkedHashMap (java.util.LinkedHashMap)14 ByteArrayInputStream (java.io.ByteArrayInputStream)13 IOException (java.io.IOException)11 DBObject (com.mongodb.DBObject)10 ArrayList (java.util.ArrayList)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 Map (java.util.Map)6 BasicBSONDecoder (org.bson.BasicBSONDecoder)6 BSONDecoder (org.bson.BSONDecoder)5 BSONEncoder (org.bson.BSONEncoder)5 BasicBSONEncoder (org.bson.BasicBSONEncoder)5 LazyBSONObject (org.bson.LazyBSONObject)5 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)4 BSONFileSplit (com.mongodb.hadoop.input.BSONFileSplit)4