Example usage for com.mongodb DBObject put

List of usage examples for com.mongodb DBObject put

Introduction

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

Prototype

Object put(String key, Object v);

Source Link

Document

Sets a name/value pair in this object.

Usage

From source file:com.eywa.impl.app.mongo.services.FileService.java

License:Open Source License

private int countAllByHubId(final String hubId, final String type) {
    final DBObject query = MongoUtils.queryEquals(File.HUB_ID, hubId);
    if (StringUtils.hasText(type)) {
        query.put(File.TYPE, type);
    }// ww w .  jav a  2s.  com
    return super.count(query);
}

From source file:com.eywa.impl.app.mongo.services.FileService.java

License:Open Source License

private int countAllByHubIdAndKeywords(final String hubId, final Collection<String> keywords) {
    final DBObject query = new BasicDBObject();
    query.put(File.HUB_ID, hubId);
    MongoUtils.queryIn(query, File.PARALLEL_ARRAY_KEY, keywords.toArray(new String[keywords.size()]));

    return super.count(query);
}

From source file:com.eywa.impl.app.mongo.services.FileService.java

License:Open Source License

private long getLengthByHub(final String hubId) throws Exception {
    long length = 0;

    final DBObject match = new BasicDBObject();
    match.put(File.HUB_ID, hubId);
    match.put(File.TYPE, File.TYPE_FILE);
    final List<DBObject> items = super.find(match, new String[] { File.LENGTH }, null, null);
    for (final DBObject item : items) {
        length += File.getLength(item);
    }/*from w ww .j  av  a  2 s.co  m*/
    return length;
}

From source file:com.eywa.impl.app.mongo.services.HashfolderService.java

License:Open Source License

public List<DBObject> list(final String userId, final String hubId, final String parentId) {
    final DBObject user = UserService.getEnabled(userId);
    if (null != user) {
        final DBObject query = new BasicDBObject(Hashfolder.HUB_ID, hubId);
        query.put(Hashfolder.PARENT_ID, StringUtils.hasText(parentId) ? parentId : hubId);
        return super.find(query, null, 0, 0, new String[] { Hashfolder.NAME }, null);
    }/*w  w  w  .j a va2 s. c o  m*/
    return new ArrayList<DBObject>();
}

From source file:com.eywa.impl.app.mongo.services.HashfolderService.java

License:Open Source License

public static int countByHub(final String hubId, final String type) {
    try {// w  w w .  j av  a  2  s  .com
        final DBObject query = new BasicDBObject();
        query.put(Hashfolder.HUB_ID, hubId);
        if (StringUtils.hasText(type)) {
            query.put(Hashfolder.TYPE, type);
        }
        final HashfolderService srvc = new HashfolderService();
        return srvc.count(query);
    } catch (Throwable ignored) {
    }
    return 0;
}

From source file:com.eywa.impl.app.mongo.services.HubService.java

License:Open Source License

public DBObject getHubHome(final String userId) throws Exception {
    final DBObject user = UserService.get(userId);
    if (null != user) {
        final DBObject query = MongoUtils.queryEquals(Hub.USER_ID, userId);
        query.put(Hub.UID, Hub.HUB_HOME);
        DBObject hub = super.findOne(query);
        if (null == hub) {
            hub = new Hub();
            Hub.setUid(hub, Hub.HUB_HOME);
            Hub.setUserId(hub, userId);/* w w  w. j av  a2  s  .c  o  m*/
            Hub.setName(hub, Hub.HUB_HOME);
            Hub.setDescription(hub, Hub.HUB_HOME);
            super.insert(hub);
        }
        return hub;
    }
    return null;
}

From source file:com.eywa.impl.app.mongo.services.HubService.java

License:Open Source License

public DBObject getHubRecycleBin(final String userId) throws Exception {
    final DBObject user = UserService.getEnabled(userId);
    if (null != user) {
        final DBObject query = MongoUtils.queryEquals(Hub.USER_ID, userId);
        query.put(Hub.UID, Hub.HUB_RECYCLE_BIN);
        DBObject hub = super.findOne(query);
        if (null == hub) {
            hub = new Hub();
            Hub.setId(hub, Hub.createUUID(Hub.HUB_RECYCLE_BIN));
            Hub.setUid(hub, Hub.HUB_RECYCLE_BIN);
            Hub.setUserId(hub, userId);/* www.  ja v  a 2s . c  o m*/
            Hub.setName(hub, Hub.HUB_RECYCLE_BIN);
            Hub.setDescription(hub, Hub.HUB_RECYCLE_BIN);
            super.insert(hub);
        }
        return hub;
    }
    return null;
}

From source file:com.eywa.impl.app.mongo.services.HubService.java

License:Open Source License

public MongoPage pagedByUserId(final String userId, final String searchText, final int skip, final int limit) {
    final DBObject user = UserService.getEnabled(userId);
    if (null != user) {
        final DBObject query;

        // user collaborations
        final String[] hubCollaborations = User.getCollaborationsAsArray(user);
        if (!CollectionUtils.isEmpty(hubCollaborations)) {
            // user filter
            final DBObject query_user = this.queryByUserId(userId);

            // collaboration filter
            //final Object[] array = hubCollaborations.toArray(new Object[hubCollaborations.size()]);
            final DBObject query_collaborations = MongoUtils.queryIn(Hub.ID, hubCollaborations);

            final BasicDBList or_conditions = new BasicDBList();
            or_conditions.add(query_user);
            or_conditions.add(query_collaborations);

            query = StringUtils.hasText(searchText) ? queryLookup(searchText) : new BasicDBObject();
            query.put(IMongoConstants.OP_OR, or_conditions);
        } else {/*w w w .  j  a  v  a  2 s . c  o  m*/
            if (StringUtils.hasText(searchText)) {
                // user filter
                final BasicDBList and_conditions = new BasicDBList();
                final DBObject query_user = this.queryByUserId(userId);
                final DBObject query_search = queryLookup(searchText);
                and_conditions.add(query_user);
                and_conditions.add(query_search);

                query = new BasicDBObject();
                query.put(IMongoConstants.OP_AND, and_conditions);
            } else {
                query = this.queryByUserId(userId);
            }
        }
        final MongoPage result = super.paged(query, null, skip, limit, new String[] { Hub.NAME }, null);
        return result;
    }
    return new MongoPage();
}

From source file:com.eywa.impl.app.mongo.services.HubService.java

License:Open Source License

private DBObject queryByUserId(final String userId) {
    final DBObject query = MongoUtils.queryEquals(Hub.USER_ID, userId);

    // exclude home e recycle_bin
    final BasicDBList and_conditions = new BasicDBList();
    and_conditions.add(MongoUtils.queryNotEquals(Hub.UID, Hub.HUB_HOME));
    and_conditions.add(MongoUtils.queryNotEquals(Hub.UID, Hub.HUB_RECYCLE_BIN));
    query.put(IMongoConstants.OP_AND, and_conditions);

    return query;
}

From source file:com.eywa.impl.app.mongo.services.ImageService.java

License:Open Source License

public static List<DBObject> getByEntityId(final String entityId, final String uid) {
    try {//from  ww w. j a  v  a2 s.c  o m
        final ImageService srvc = new ImageService();
        final DBObject query = new BasicDBObject();
        query.put(Image.ENTITY_ID, entityId);
        if (StringUtils.hasText(uid)) {
            query.put(Image.UID, uid);
        }
        return srvc.find(query, null, new String[] { Image.CREATIONDATE }, null);
    } catch (Throwable ignored) {
    }
    return null;
}