Example usage for com.mongodb BasicDBList BasicDBList

List of usage examples for com.mongodb BasicDBList BasicDBList

Introduction

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

Prototype

BasicDBList

Source Link

Usage

From source file:com.eywa.impl.app.mongo.services.ProductService.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 w w .  j a  v a  2s .  c o  m*/
    DBObject query2 = null;

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

    if (!StringUtils.isNULL(searchText)) {
        if (searchText.startsWith("#")) {
            query2 = new BasicDBObject();
            query2.put(Product.KEYWORDS, searchText.substring(1));
        } else {
            query2 = new BasicDBObject();
            final BasicDBList conditions = new BasicDBList();
            conditions.add(MongoUtils.queryEquals(Product.ID, searchText, MongoUtils.CASE_INSENSITIVE));
            conditions.add(MongoUtils.queryContains(Product.UID, searchText, MongoUtils.CASE_INSENSITIVE));
            conditions.add(MongoUtils.queryEquals(Product.KEYWORDS, 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.ProductTemplateListService.java

License:Open Source License

public static List<DBObject> getList(final String lang, final String uid) {
    try {//from   w w  w . jav a  2s.  c  o m
        final ProductTemplateListService srvc = new ProductTemplateListService();
        final List<DBObject> result;
        if (StringUtils.hasText(uid)) {
            final BasicDBList or = new BasicDBList();
            or.add(new BasicDBObject(ProductTemplateList.UID, uid));
            or.add(new BasicDBObject(ProductTemplateList.UID, '*'));
            final DBObject query = new BasicDBObject();
            query.put(MongoUtils.OP_OR, or);
            result = srvc.find(query);
        } else {
            result = srvc.find();
        }
        srvc.localize(result, lang);
        return result;
    } catch (Throwable ignored) {
    }
    return null;
}

From source file:com.eywa.impl.app.mongo.services.ShopService.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[] collaborations = User.getCollaborationsAsArray(user);
        if (!CollectionUtils.isEmpty(collaborations)) {
            // user filter
            final DBObject query_user = this.queryByUserId(userId);

            // collaboration filter
            final DBObject query_collaborations = MongoUtils.queryIn(Shop.ID, collaborations);

            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 {/*from  w ww .  j  av a2 s  .com*/
            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[] { Shop.NAME }, null);
        return result;
    }
    return new MongoPage();
}

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

License:Open Source License

private static DBObject queryLookup(final String searchText) {
    if (StringUtils.hasText(searchText)) {

        final BasicDBList conditions = new BasicDBList();
        conditions.add(MongoUtils.queryContains(Shop.NAME, searchText, MongoUtils.CASE_INSENSITIVE));
        conditions.add(MongoUtils.queryContains(Shop.DESCRIPTION, searchText, MongoUtils.CASE_INSENSITIVE));

        return new BasicDBObject(MongoUtils.OP_OR, conditions);
    }/*from ww w  . ja v a  2 s  .  c o m*/
    return null;
}

From source file:com.ff.reportgenerator.mongodb.DynamicDatabase.java

public String query(Hashtable conditions) {
    List<DBObject> list = null;

    DB myDB = getDB(DB_NAME);/*from   w  w w . jav  a2  s . c o  m*/
    DBCollection coll = myDB.getCollection("projects");

    BasicDBObject cond = new BasicDBObject();

    Set<String> keySet = conditions.keySet();
    Iterator<String> it = keySet.iterator();

    while (it.hasNext()) {
        String key = it.next();
        String value = (String) conditions.get(key);
        if (value == null || value.equals("All")) {
            continue;
        }

        Pattern pattern = null;
        if (key.equals("Project_Phase")) {
            if (value.equals("Ongoing")) {
                BasicDBList dlist = new BasicDBList();
                dlist.add(new BasicDBObject(key, new BasicDBObject("$ne", "Completed")));
                dlist.add(new BasicDBObject(key, new BasicDBObject("$ne", "Eng-Complete")));
                dlist.add(new BasicDBObject(key, new BasicDBObject("$ne", "Canceled")));
                dlist.add(new BasicDBObject(key, new BasicDBObject("$ne", "Publication")));
                cond.append("$and", dlist);
            } else if (value.equals("Complete")) {
                ArrayList<String> slist = new ArrayList();
                slist.add("Completed");
                slist.add("Eng-Complete");
                slist.add("Publication");
                cond.append(key, new BasicDBObject("$in", slist));

                //Limited to FY15 projects
                //pattern = Pattern.compile("^.*15-\\[.*$", Pattern.CASE_INSENSITIVE);

                //Limited to FY16 projects
                pattern = Pattern.compile("^.*16-.*$", Pattern.CASE_INSENSITIVE);
                cond.append("ISVe_Goal", pattern);
            }
        } else if (key.equals("Keywords") && value.equals("Non-OPI")) { // not like 'OPI'
            pattern = Pattern.compile("^((?!OPI).)*$", Pattern.CASE_INSENSITIVE);
            cond.append(key, pattern);
        } else { // like '*OPI*'
            pattern = Pattern.compile("^.*" + value + ".*$", Pattern.CASE_INSENSITIVE);
            cond.append(key, pattern);
        }

        System.out.println(key + ":" + value);
    }

    DBCursor ret = coll.find(cond);

    BasicDBObject sort = new BasicDBObject("PROJECT_ID", 1);
    ret.sort(sort);

    try {
        list = ret.toArray();
    } finally {
        ret.close();
    }

    //System.out.println(list.toString());
    return list.toString();
}

From source file:com.fliker.Modal.GuidancePreview.java

public BasicDBList getGuidanceCosumeruserid(String guidanceid) {
    // TODO Auto-generated method stub

    BasicDBList useridlist = new BasicDBList();
    MongoConnection mongocon = new MongoConnection();
    DBCursor resultcursor = mongocon.getDBObject("guidanceid", guidanceid, "GuidanceContent");
    if (resultcursor.hasNext()) {
        DBObject theObj = resultcursor.next();

        useridlist = (BasicDBList) theObj.get("consumeruserid");
    }/*from  w  w w  .  j a v  a2s. c  om*/

    return useridlist;
}

From source file:com.fpt.xml.hth.db.lib.converter.MovieTheaterSessionConverter.java

/**
 * To convert from MovieDBTheaterSessionDTO object to BasicDBObject object
 *
 * @param model/*from  w ww .  j av a2s  . c  o m*/
 * @return BasicDBObject
 */
public BasicDBObject convertModelToBasicObject(MovieTheaterSessionDTO model) {
    ObjectId id = model.getId();
    MovieDB movie = model.getMovie();
    List<TheaterSessionDTO> theaters = model.getTheaters();
    //convert movie to BasicDBObject
    BasicDBObject basicMovie = movieConverter.convertModelToBasicObject(movie);
    //convert lstTheaters to BasicDBList
    BasicDBList basicLst = new BasicDBList();
    for (int i = 0; i < theaters.size(); i++) {
        TheaterSessionDTO theaterSessionDTO = (TheaterSessionDTO) theaters.get(i);
        BasicDBObject basic = tsConverter.convertModelToBasicObject(theaterSessionDTO);
        basicLst.add(basic);
    }
    // set value for basicMovieTheaterSession
    BasicDBObject basicMovieTheaterSession = new BasicDBObject();
    basicMovieTheaterSession.append("_id", id);
    basicMovieTheaterSession.append("movie", basicMovie);
    basicMovieTheaterSession.append("theaters", basicLst);

    return basicMovieTheaterSession;
}

From source file:com.fpt.xml.hth.db.lib.converter.TheaterSessionConverter.java

/**
 * To convert from TheaterDBSessionDTO object to BasicDBObject object
 *
 * @param model//w w w.  j  a  va  2  s  . c  om
 * @return BasicDBObject
 */
public BasicDBObject convertModelToBasicObject(TheaterSessionDTO model) {
    String cinemaName = model.getCinemaName();
    String id = model.getId();
    TheaterDB theater = model.getTheater();
    List<String> lstSessions = model.getLstSession();
    // convert theather to basicTheater
    BasicDBObject basicTheater = conveter.convertModelToBasicObject(theater);
    // convert lstSessions to 
    BasicDBList basicLst = new BasicDBList();
    for (int i = 0; i < lstSessions.size(); i++) {
        basicLst.add(lstSessions.get(i));
    }
    // convert object theater
    BasicDBObject basicTheaterSession = new BasicDBObject();
    basicTheaterSession.append("cinemaName", cinemaName);
    basicTheaterSession.append("theater", basicTheater);
    basicTheaterSession.append("sessions", basicLst);
    basicTheaterSession.append("id", id);
    return basicTheaterSession;
}

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

License:Open Source License

private BasicDBList toMap(Object property) {

    BasicDBList builder = new BasicDBList();

    @SuppressWarnings("rawtypes")
    Map<?, ?> map = (Map) property;

    builder.add(property.getClass().getName());

    for (Map.Entry<?, ?> entry : map.entrySet()) {
        builder.add(toObject(entry.getKey()));
        builder.add(toObject(entry.getValue()));
    }//ww w  .ja  v  a 2s  .com

    return builder;
}

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

License:Open Source License

private BasicDBList toCollection(Object property) {

    BasicDBList builder = new BasicDBList();

    @SuppressWarnings("rawtypes")
    Collection collection = (Collection) property;

    builder.add(property.getClass().getName());

    for (Object e : collection) {
        builder.add(toObject(e));// w  w w  .ja  va2 s  .com
    }

    return builder;
}