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:Entity.Rubrique.java

public BasicDBList mapBddCritere() {
    BasicDBList result = new BasicDBList();
    for (Critere critere : lstCritere) {
        BasicDBObject dbRubriques = new BasicDBObject();
        //dbRubriques.append("_id", critere.getId());
        dbRubriques.append("libelle", critere.getLibelle());
        dbRubriques.append("poid", critere.getPoid());
        result.add(dbRubriques);//from www .  ja  v a 2  s .c o m
    }

    return result;
}

From source file:es.bsc.amon.controller.EventsDBMapper.java

License:Open Source License

public BasicDBList find(DBObject query) {
    BasicDBList dbl = new BasicDBList();
    DBCursor dbc = colEvents.find(query);
    while (dbc.hasNext()) {
        dbl.add(dbc.next());//from  ww w.j a va2 s  .  c o m
    }
    return dbl;
}

From source file:es.bsc.amon.controller.EventsDBMapper.java

License:Open Source License

public BasicDBList aggregate(BasicDBObject dbo) {
    List<DBObject> query = new ArrayList<DBObject>(1);
    query.add(dbo);//  w ww . j a v a  2  s  .  c o m
    AggregationOutput aggOut = colEvents.aggregate(query);
    BasicDBList dbl = new BasicDBList();
    Iterator<DBObject> it = aggOut.results().iterator();
    while (it.hasNext()) {
        dbl.add(it.next());
    }
    return dbl;
}

From source file:es.bsc.amon.controller.EventsDBMapper.java

License:Open Source License

public BasicDBList aggregate(BasicDBList query) {
    List<DBObject> ql = new ArrayList<DBObject>(query.size());
    Iterator<Object> itq = query.iterator();
    while (itq.hasNext())
        ql.add((DBObject) itq.next());/*from  w  ww  .  j  a  v a 2 s .co m*/
    AggregationOutput aggOut = colEvents.aggregate(ql);
    BasicDBList dbl = new BasicDBList();
    Iterator<DBObject> it = aggOut.results().iterator();
    while (it.hasNext()) {
        dbl.add(it.next());
    }
    return dbl;
}

From source file:es.bsc.amon.controller.QueriesDBMapper.java

License:Open Source License

/**
 * Uses the MongoAL query language//from   w  w  w  .j  a va  2 s  .c o m
 */
public ArrayNode aggregate(String query) {
    if (mongoAlQG == null) {
        mongoAlQG = new QueryGenerator(DBManager.instance.getDatabase());
    }

    BasicDBList dbl = new BasicDBList();
    Iterable<DBObject> it = mongoAlQG.query(query);
    for (DBObject dbo : it) {
        dbl.add(dbo);
    }
    return (ArrayNode) Json.parse(dbl.toString());

}

From source file:es.bsc.amon.DBManager.java

License:Open Source License

public BasicDBList find(String collectionName, DBObject query, DBObject orderby, Integer limit) {
    BasicDBList result = new BasicDBList();

    DBCursor c = null;//from  w w  w.ja v  a2s  .  c o m
    if (query == null) {
        c = database.getCollection(collectionName).find();
    } else {
        c = database.getCollection(collectionName).find(query);
    }

    if (orderby == null) {
        c.sort(orderby);
    }

    if (limit != null && limit > 0) {
        c = c.limit(limit);
    }

    while (c.hasNext()) {
        result.add(c.next());
    }
    c.close();
    return result;
}

From source file:eu.cassandra.server.mongo.MongoActivities.java

License:Apache License

private String withAddedWarnings(String response, boolean ary) {
    if (Utils.failed(response))
        return response;
    DBObject jsonResponse = (DBObject) JSON.parse(response);
    DBObject data = (DBObject) jsonResponse.get("data");
    String objID = new String();
    if (ary) {//from  ww w.  ja va2  s  . c o  m
        objID = (String) ((DBObject) ((BasicDBList) data).get(0)).get("_id");
    } else {
        objID = (String) data.get("_id");
    }
    BasicDBList list = new BasicDBList();
    DBObject returnQuery = new MongoDBQueries().getEntity(MongoActivityModels.COL_ACTMODELS, "act_id", objID);
    if (returnQuery == null) {
        String warning = "Add at least one activity model for this activity.";
        list.add(warning);
    }

    if (!list.isEmpty()) {
        jsonResponse.put("warnings", list);
    }
    return jsonResponse.toString();
}

From source file:eu.cassandra.server.mongo.MongoActivityModels.java

License:Apache License

private String withAddedWarnings(String response, boolean ary, boolean appliances) {
    if (Utils.failed(response))
        return response;
    DBObject jsonResponse = (DBObject) JSON.parse(response);
    DBObject data = (DBObject) jsonResponse.get("data");
    if (ary) {/*from  w w w  . ja  va2  s  . c o m*/
        data = (DBObject) ((BasicDBList) data).get(0);
    }
    BasicDBList list = new BasicDBList();
    if (appliances && (((BasicDBList) data.get("containsAppliances")) == null
            || ((BasicDBList) data.get("containsAppliances")).isEmpty())) {
        String warning = "Add at least one appliance for this activity model.";
        list.add(warning);
    }
    if ((String) data.get("duration") == null
            || ((String) data.get("duration") != null && ((String) data.get("duration")).isEmpty())) {
        String warning = "Add a duration distribution for this activity model.";
        list.add(warning);
    }
    if ((String) data.get("startTime") == null
            || ((String) data.get("startTime") != null && ((String) data.get("startTime")).isEmpty())) {
        String warning = "Add a start time distribution for this activity model.";
        list.add(warning);
    }
    if ((String) data.get("repeatsNrOfTime") == null || ((String) data.get("repeatsNrOfTime") != null
            && ((String) data.get("repeatsNrOfTime")).isEmpty())) {
        String warning = "Add a number of times distribution for this activity model.";
        list.add(warning);
    }
    if (!list.isEmpty()) {
        jsonResponse.put("warnings", list);
    }
    return jsonResponse.toString();
}

From source file:eu.cassandra.server.mongo.MongoAppliances.java

License:Apache License

public Response getAppliances(HttpHeaders httpHeaders, String scn_id, String filters, String sort, int limit,
        int skip, boolean count, boolean pertype, boolean lib) {
    // Search for the installations based on the scenario
    String installations = (new MongoInstallations()).getInstallations(httpHeaders, scn_id, null, null, 0, 0,
            false, false);//  www  .  j  a  va  2 s. co  m
    DBObject jsonResponse = (DBObject) JSON.parse(installations);
    BasicDBList list = (BasicDBList) jsonResponse.get("data");
    // Retrieve the ids
    BasicDBList appsList = new BasicDBList();
    int totalCount = 0;
    for (Object o : list) {
        DBObject dbo = (DBObject) o;
        String inst_id = (String) dbo.get("_id");
        // For each one gather the data and load a DBCursor
        totalCount += addToList(inst_id, appsList, filters, sort, count, httpHeaders);
    }
    if (lib) {
        // search also in the corresponding lib
        totalCount += addToList(scn_id, appsList, filters, sort, count, httpHeaders);
    }
    // Use limit and skip for creating a sublist => return it
    Vector<DBObject> vec = new Vector<DBObject>();
    for (Object o : appsList) {
        DBObject dbo = (DBObject) o;
        vec.add(dbo);
    }
    JSONtoReturn jSON2Rrn = new JSONtoReturn();
    String page = jSON2Rrn.createJSON(vec, "Appliances retrieved successfully").toString();
    return Utils.returnResponseWithAppend(page, "total_size", new Integer(totalCount));
}

From source file:eu.cassandra.server.mongo.MongoAppliances.java

License:Apache License

private String withAddedWarnings(String response, boolean ary) {
    if (Utils.failed(response))
        return response;
    DBObject jsonResponse = (DBObject) JSON.parse(response);
    DBObject data = (DBObject) jsonResponse.get("data");
    String objID = new String();
    if (ary) {//from   w ww . ja  v a 2 s. com
        objID = (String) ((DBObject) ((BasicDBList) data).get(0)).get("_id");
    } else {
        objID = (String) data.get("_id");
    }
    DBObject returnQuery = new MongoDBQueries().getEntity(MongoConsumptionModels.COL_CONSMODELS, "app_id",
            objID);
    if (returnQuery == null) {
        BasicDBList list = new BasicDBList();
        String warning = "Add a consumption model for this appliance.";
        list.add(warning);
        jsonResponse.put("warnings", list);
    }
    return jsonResponse.toString();
}