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.ContactService.java

License:Open Source License

public MongoPage lookup(final String hubId, final int skip, final int limit, final String searchText) {

    DBObject query1 = null;
    DBObject query2 = null;/*w  w w  . j a  v a2  s. c  o m*/

    if (!StringUtils.isNULL(hubId)) {
        query1 = new BasicDBObject();
        // lookup in current hub and between "cross-hub" contacts
        final BasicDBList conditions = new BasicDBList();
        conditions.add(MongoUtils.queryEquals(Contact.HUB_ID, hubId, MongoUtils.CASE_INSENSITIVE));
        conditions.add(MongoUtils.queryEquals(Contact.HUB_ID, Hub.HUB_ALL, MongoUtils.CASE_INSENSITIVE));
        query1.put(MongoUtils.OP_OR, conditions);
    }

    if (!StringUtils.isNULL(searchText)) {
        if (SPECIAL_FILTER_COLLABORATOR.equalsIgnoreCase(searchText)) {
            query2 = new BasicDBObject();
            query2.put(Contact.COLLABORATION_HUBS, hubId);
        } else if (SPECIAL_FILTER_USER.equalsIgnoreCase(searchText)) {
            query2 = new BasicDBObject();
            MongoUtils.queryNotEmpty(query2, Contact.ACCOUNT_ID);
        } else if (searchText.startsWith("#")) {
            query2 = new BasicDBObject();
            query2.put(Contact.PARALLEL_ARRAY_KEY, searchText.substring(1));
        } else {
            query2 = new BasicDBObject();
            final BasicDBList conditions = new BasicDBList();
            conditions.add(MongoUtils.queryEquals(Contact.ID, searchText, MongoUtils.CASE_INSENSITIVE));
            conditions.add(MongoUtils.queryEquals(Contact.OWNER_ID, searchText, MongoUtils.CASE_INSENSITIVE));
            conditions.add(MongoUtils.queryContains(Contact.NAME, searchText, MongoUtils.CASE_INSENSITIVE));
            conditions.add(MongoUtils.queryContains(Contact.SURNAME, searchText, MongoUtils.CASE_INSENSITIVE));
            conditions.add(
                    MongoUtils.queryContains(Contact.DESCRIPTION, searchText, MongoUtils.CASE_INSENSITIVE));
            // conditions.add(MongoUtils.queryEquals(Contact.EMAIL, searchText, MongoUtils.CASE_INSENSITIVE));
            //conditions.add(MongoUtils.queryEquals(Contact.KEYWORDS, searchText, MongoUtils.CASE_INSENSITIVE));
            conditions.add(MongoUtils.queryEquals(Contact.PARALLEL_ARRAY_KEY, searchText,
                    MongoUtils.CASE_INSENSITIVE));

            query2.put(MongoUtils.OP_OR, conditions);
        }
    }

    DBObject query = null;
    if (null != query1 && null != query2) {
        query = new BasicDBObject();
        final BasicDBList conditions = new BasicDBList();
        conditions.add(query1);
        conditions.add(query2);
        query.put(MongoUtils.OP_AND, conditions);
    } else if (null == query2) {
        query = query1;
    } else {
        query = query2;
    }

    final String[] fieldNames = null;
    final String[] sortAsc = new String[] { Contact.SURNAME, Contact.NAME };
    final String[] sortDes = new String[] {};

    return super.paged(query, fieldNames, skip, limit, sortAsc, sortDes);
}

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

License:Open Source License

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

    return super.count(query);
}

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

License:Open Source License

private DBObject createFromUser(final DBObject hub, final String userId) throws StandardCodedException {
    final String hubId = Hub.getId(hub);

    final DBObject query = new BasicDBObject();
    query.put(Contact.ACCOUNT_ID, userId);
    query.put(Contact.HUB_ID, hubId);//w  w w.jav a 2 s .c o m

    DBObject result = super.findOne(query);
    if (null == result) {
        final DBObject user = UserService.getEnabled(userId);
        if (null != hub && null != user) {
            final String ownerId = Hub.getUserId(hub);

            result = new Contact(); // already contains id

            Contact.setOwnerId(result, ownerId);
            Contact.setAccountId(result, userId);
            Contact.setLang(result, User.getLang(user));
            Contact.setHubId(result, hubId);
            Contact.setEmail(result, User.getEmail(user));
            Contact.setEmails(result, User.getEmails(user));
            final String brand = ItemBillingUser.getBrand(User.getBilling(user));
            final String name = User.getName(user);
            final String surname = User.getSurname(user);
            final String realname = User.getRealname(user);
            if (StringUtils.hasText(name) && StringUtils.hasText(surname)) {
                Contact.setName(result, name.concat(" ").concat(surname));
                if (StringUtils.hasText(brand)) {
                    Contact.setSurname(result, "(".concat(brand).concat(")"));
                } else {
                    Contact.setSurname(result, "(".concat(User.getEmail(user)).concat(")"));
                }
            } else if (StringUtils.hasText(realname)) {
                Contact.setName(result, realname);
                if (StringUtils.hasText(brand)) {
                    Contact.setSurname(result, "(".concat(brand).concat(")"));
                } else {
                    Contact.setSurname(result, "(".concat(User.getEmail(user)).concat(")"));
                }
            } else {
                Contact.setName(result, User.getEmail(user));
                Contact.setSurname(result, "");
            }

            // Contact.regenerateParallelArrayKey(result); generated in upsert

            this.upsert(result);
        }
    }

    return result;
}

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

License:Open Source License

/**
 * Returns a Set of Contact's IDs./*from   w  w w . j a va 2  s  .  c  om*/
 * An account (user) can be registered as contact from different users.
 *
 * @param accountId Id of User
 * @return Set of Contact's IDs
 */
public static Set<String> getContactIdsFromUserId(final String accountId) {
    final Set<String> result = new HashSet<String>();
    try {
        final ContactService srvc = new ContactService();
        final DBObject query = new BasicDBObject();
        final Pattern equal = MongoUtils.patternEquals(accountId); //Pattern.compile("\\A" + email + "\\z", BeeMongoUtils.CASE_INSENSITIVE);
        query.put(Contact.ACCOUNT_ID, equal);
        final List<DBObject> contacts = srvc.find(query, new String[] { Contact.ID }, null, null);
        for (final DBObject item : contacts) {
            final String id = Contact.getId(item);
            if (StringUtils.hasText(id)) {
                result.add(id);
            }
        }
    } catch (Throwable ignored) {
        // something wrong in database
    }
    return result;
}

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

License:Open Source License

public DBObject getDir(final String parentId, final String name) {
    final DBObject query = new BasicDBObject();
    query.put(File.PARENT_ID, parentId);
    query.put(File.NAME, name);/*from w w  w  . j a  v a  2s  . com*/
    return super.findOne(query);
}

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

License:Open Source License

public List<DBObject> list(final String userId, final String hubId, final String parent) {
    final DBObject user = UserService.getEnabled(userId);
    if (null != user) {
        final DBObject query = new BasicDBObject(File.HUB_ID, hubId);
        query.put(File.PARENT_ID, parent);
        return super.find(query, null, 0, 0, new String[] { File.TYPE, File.NAME }, null);
    }/*from ww w.  j  a v a  2 s.c o  m*/
    return new ArrayList<DBObject>();
}

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

License:Open Source License

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

    final String[] sortAsc = new String[] { File.NAME };
    final String[] sortDes = new String[] {};

    return super.find(query, fieldNames, sortAsc, sortDes);
}

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

License:Open Source License

public MongoPage lookup(final String hubId, final int skip, final int limit,
        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()]));

    final String[] fieldNames = null;
    final String[] sortAsc = new String[] { File.NAME };
    final String[] sortDes = new String[] {};

    return super.paged(query, fieldNames, skip, limit, sortAsc, sortDes);
}

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

License:Open Source License

public MongoPage lookup(final String hubId, final int skip, final int limit, final String searchText) {

    DBObject query1 = null;//from w  ww .  jav a2s .  com
    DBObject query2 = null;

    if (!StringUtils.isNULL(hubId)) {
        // lookup in current hub
        query1 = new BasicDBObject();
        MongoUtils.queryEquals(query1, File.HUB_ID, hubId, MongoUtils.CASE_INSENSITIVE);
    }

    if (!StringUtils.isNULL(searchText)) {
        if (searchText.startsWith("#")) {
            query2 = new BasicDBObject();
            query2.put(File.PARALLEL_ARRAY_KEY, searchText.substring(1));
        } else {
            query2 = new BasicDBObject();
            final BasicDBList conditions = new BasicDBList();
            conditions.add(MongoUtils.queryEquals(File.ID, searchText, MongoUtils.CASE_INSENSITIVE));
            conditions.add(MongoUtils.queryEquals(File.OWNER_ID, searchText, MongoUtils.CASE_INSENSITIVE));
            conditions.add(MongoUtils.queryContains(File.NAME, searchText, MongoUtils.CASE_INSENSITIVE));
            conditions.add(MongoUtils.queryContains(File.DESCRIPTION, searchText, MongoUtils.CASE_INSENSITIVE));
            conditions.add(
                    MongoUtils.queryEquals(File.PARALLEL_ARRAY_KEY, searchText, MongoUtils.CASE_INSENSITIVE));

            query2.put(MongoUtils.OP_OR, conditions);
        }
    }

    DBObject query = null;
    if (null != query1 && null != query2) {
        query = new BasicDBObject();
        final BasicDBList conditions = new BasicDBList();
        conditions.add(query1);
        conditions.add(query2);
        query.put(MongoUtils.OP_AND, conditions);
    } else if (null == query2) {
        query = query1;
    } else {
        query = query2;
    }

    final String[] fieldNames = null;
    final String[] sortAsc = new String[] { File.NAME };
    final String[] sortDes = new String[] {};

    return super.paged(query, fieldNames, skip, limit, sortAsc, sortDes);
}

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

License:Open Source License

public DBObject lookUp(final String hubId, final String parentId, final String resourceName) {
    final DBObject query = new BasicDBObject();
    query.put(File.HUB_ID, hubId);
    query.put(File.PARENT_ID, parentId);
    query.put(File.RESOURCE_NAME, resourceName);
    return super.findOne(query);
}