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

License:Open Source License

public static String getLang(final String userId) {
    try {/*from  w ww . ja  va  2  s. c o m*/
        final UserService srvc = new UserService();
        final DBObject query = new BasicDBObject();
        query.put(User.ID, userId);
        final DBObject user = srvc.findOne(query, new String[] { User.LANG });
        return User.getLang(user);
    } catch (Throwable ignored) {
        // something wrong in database
    }
    return LocaleUtils.getCurrent().getLanguage();
}

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

License:Open Source License

public static List<DBObject> getByDomainUid(final String domainUid, final String[] fieldNames) {
    try {//  w w  w  .  jav a2s . c  o m
        final UserService srvc = new UserService();
        final DBObject query = new BasicDBObject();
        final Pattern equal = MongoUtils.patternEndWith("@" + domainUid);
        query.put(User.EMAIL, equal);
        return srvc.find(query, fieldNames, null, null);
    } catch (Throwable ignored) {
        // something wrong in database
    }
    return null;
}

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

License:Open Source License

public static int countByDomainUid(final String domainUid) {
    try {//from   w w w .  j  ava 2 s .c o m
        final UserService srvc = new UserService();
        final DBObject query = new BasicDBObject();
        final Pattern equal = MongoUtils.patternEndWith("@" + domainUid);
        query.put(User.EMAIL, equal);
        return srvc.count(query);
    } catch (Throwable ignored) {
        // something wrong in database
    }
    return 0;
}

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

License:Open Source License

public static DBObject getStatus(final String userId) {
    final DBObject user = get(userId);
    final DBObject result = new BasicDBObject();
    if (null != user) {
        final List<DBObject> accounts = UserExternalAccountService.getAccounts(userId);
        final DBObject billing = User.getBilling(user);

        final double div = 4.0;
        double count = 0;
        count += StringUtils.hasText(User.getRealname(user)) ? 1 : 0;
        count += User.getEmails(user).size() > 1 ? User.getEmails(user).size() - 1 : 0;
        count += StringUtils.hasText(ItemBillingUser.getName(billing))
                && StringUtils.hasText(ItemBillingUser.getAddress(billing))
                && StringUtils.hasText(ItemBillingUser.getVat(billing)) ? 2 : 0;
        count += accounts.size() > 0 ? 1 : 0;

        if (count > div) {
            count = div;/*from   w  ww. j  a v a2s .c  o  m*/
        }

        result.put("active", User.getEnabled(user));
        result.put("completeness", (count / div) * 100);
    }
    return result;
}

From source file:com.eywa.impl.app.rest.RESTUser.java

License:Open Source License

private static DBObject prepareUser(final DBObject user) throws Exception {
    final UserService srvc = new UserService();
    if (null != user) {

        //-- remove password --//
        user.put(User.PASSWORD, "");

        User.setType(user, User.encodeType(user));

        // init country
        srvc.initCountry(user);/*from  w  w w  . j a v a 2  s .c  o  m*/
    }
    return user;
}

From source file:com.flyingdonut.implementation.helpers.MongoDbConsumerAssociationStore.java

License:Apache License

private void mongoEnsureIndex(BasicDBObject query, BasicDBObject sort) {
    if (query.containsField(id) || query.keySet().isEmpty()) {
        return;/* w w w  . jav a  2 s  .  c o  m*/
    }

    DBObject indexDoc = new BasicDBObject();
    for (String k : query.keySet()) {
        if (k.startsWith("$")) {
            mongoEnsureIndexAddAll(indexDoc, (BasicDBList) query.get(k));
        } else {
            indexDoc.put(k, 1);
        }
    }

    if (sort != null) {
        for (String k : sort.keySet()) {
            indexDoc.put(k, sort.get(k));
        }
    }

    getMongoDBConnection().getCollection(getCollectionName()).ensureIndex(indexDoc);
}

From source file:com.flyingdonut.implementation.helpers.MongoDbConsumerAssociationStore.java

License:Apache License

private void mongoEnsureIndexAddAll(DBObject indexDoc, BasicDBList queryKeys) {
    for (String k : queryKeys.keySet()) {
        BasicDBObject value = (BasicDBObject) queryKeys.get(k);
        if (k.startsWith("$")) {
            mongoEnsureIndexAddAll(indexDoc, (BasicDBList) queryKeys.get(k));
        } else {/*from w  w  w.java 2s.  c  o m*/
            for (String kk : value.keySet()) {
                indexDoc.put(kk, 1);
            }
        }
    }
}

From source file:com.gigaspaces.persistency.datasource.MongoQueryFactory.java

License:Open Source License

@SuppressWarnings("static-access")
private static void replaceIdProperty(BasicDBObjectBuilder qResult, SpaceTypeDescriptor typeDescriptor) {

    DBObject q = qResult.get();

    if (q.containsField(typeDescriptor.getIdPropertyName())) {

        Object value = q.get(typeDescriptor.getIdPropertyName());

        q.removeField(typeDescriptor.getIdPropertyName());

        q.put(Constants.ID_PROPERTY, value);

        qResult.start(q.toMap());/*from ww  w .jav a  2 s  .c o m*/
    }
}

From source file:com.gigaspaces.persistency.metadata.SpaceDocumentMapperImpl.java

License:Open Source License

private DBObject toDBObjectDocument(SpaceDocument document) {
    DBObject bson = new BasicDBObject();

    Set<String> keys = document.getProperties().keySet();

    bson.put(TYPE, document.getTypeName());

    for (String property : keys) {

        Object value = document.getProperty(property);

        if (value == null)
            continue;

        if (spaceTypeDescriptor.getIdPropertyName().equals(property))
            property = _ID;//  w  ww.ja  va 2  s . c  o m

        bson.put(property, toObject(value));
    }

    return bson;

}

From source file:com.gigaspaces.persistency.metadata.SpaceDocumentMapperImpl.java

License:Open Source License

private DBObject toDBObjectPojo(Object pojo) {

    DBObject bson = new BasicDBObject();

    Map<String, Method> getters = repository.getGetters(pojo.getClass());

    Class<?> type = pojo.getClass();

    bson.put(TYPE, type.getName());

    for (String property : getters.keySet()) {
        Object value = null;//from ww w  . j a v a2s.  co  m
        try {

            value = repository.getGetter(type, property).get(pojo);

            if (value == null)
                continue;

            if (spaceTypeDescriptor.getIdPropertyName().equals(property))
                property = _ID;

            bson.put(property, toObject(value));

        } catch (IllegalArgumentException e) {
            throw new SpaceMongoException("Argument is: " + value, e);
        } catch (IllegalAccessException e) {
            throw new SpaceMongoException("Can not access method", e);
        } catch (InvocationTargetException e) {
            throw new SpaceMongoException("Can not invoke method", e);
        }
    }

    return bson;
}