Example usage for com.mongodb.client MongoCursor next

List of usage examples for com.mongodb.client MongoCursor next

Introduction

In this page you can find the example usage for com.mongodb.client MongoCursor next.

Prototype

@Override
    TResult next();

Source Link

Usage

From source file:DS.Model.java

public List<Restaurant> getRestaurants() {
    MongoCollection<Document> collection = db.getCollection("restaurants");
    MongoCursor<Document> cursor = collection.find().iterator();

    resList = new ArrayList<Restaurant>();
    try {//ww w.  ja v  a2 s .c o  m
        //Iterate through all the returned restaurants and store the information into the resList list
        while (cursor.hasNext()) {
            String json = cursor.next().toJson();
            JsonParser parser = new JsonParser();
            JsonElement jsonTree = parser.parse(json);
            if (jsonTree.isJsonObject()) {
                Restaurant r = new Restaurant();
                JsonObject j = jsonTree.getAsJsonObject();
                r.setName(j.get("name").getAsString());
                r.setLocation(j.get("address").getAsString());
                r.setRating(Double.parseDouble(j.get("rating").getAsString()));
                resList.add(r);
            }
        }
    } finally {
        cursor.close();
    }

    return resList;
}

From source file:DS.Model.java

public List<Request> getRequests() {
    MongoCollection<Document> collection = db.getCollection("requests");
    MongoCursor<Document> cursor = collection.find().iterator();

    reqList = new ArrayList<Request>();
    try {//  w w w.  ja  v a  2 s.  c om
        //Iterate through all the requests to retrieve the information and add to the reqList list
        while (cursor.hasNext()) {
            String json = cursor.next().toJson();
            JsonParser parser = new JsonParser();
            JsonElement jsonTree = parser.parse(json);
            if (jsonTree.isJsonObject()) {
                Request r = new Request();
                JsonObject j = jsonTree.getAsJsonObject();
                String term = j.get("term").getAsString();
                String location = j.get("location").getAsString();
                r.setLocation(location);
                r.setTerm(term);
                r.setTimestamp(j.get("time").getAsString());
                r.setPhone(j.get("phone").getAsString());
                r.setDelay(Double.parseDouble(j.get("delay").getAsString()));
                reqList.add(r);

                //Add the term to the termCount map, used to find which term is the most popular
                //Check if the term already exists.  IF yes, increment by one, else add as new term
                if (termCount.containsKey(term)) {
                    int count = termCount.get(term);
                    termCount.put(term, count + 1);
                } else {
                    termCount.put(term, 0);
                }

                //Add the location to the locCount map, used to find which term is the most popular
                //Check if the location already exists.  IF yes, increment by one, else add as new loc
                if (locCount.containsKey(location)) {
                    int count = locCount.get(location);
                    locCount.put(location, count + 1);
                } else {
                    locCount.put(location, 0);
                }
            }
        }
    } finally {
        cursor.close();
    }

    return reqList;
}

From source file:dto.Dto.java

public String listarTesis() {
    String cadena = "";
    MongoCollection<Document> col = c.getConnection("universo_tesis");
    MongoCursor<Document> cursor = col.find().sort(Sorts.orderBy(Sorts.descending("ao"))).iterator();
    Document doc;/*from   www  . j a v  a  2  s. c o m*/
    try {
        while (cursor.hasNext()) {
            doc = cursor.next();
            cadena += "<tr>" + "<td width='20%'>" + doc.getString("titulo").toUpperCase().trim() + "</td>"
                    + "<td width='20%'>" + doc.getString("ao") + "</td>" + "<td width='20%'>"
                    + doc.getString("estado").toUpperCase().trim() + "</td>" + "</tr>";
        }
    } catch (Exception e) {
        System.out.println("listarTesis universo: " + e);
    } finally {
        cursor.close();
    }
    return cadena;
}

From source file:dto.Dto.java

public String listarActas() {
    String cadena = "";
    MongoCollection<Document> col = c.getConnection("actas");
    MongoCursor<Document> cursor = col.find(eq("estado", "pendiente")).iterator();
    Document doc;//from   w  w  w  .ja v  a2  s  .  c om
    try {
        while (cursor.hasNext()) {
            doc = cursor.next();
            cadena += "<tr>" + "<td width='20%'>" + doc.getString("tema").toUpperCase().trim() + "</td>"
                    + "<td width='20%'>" + doc.getString("temas") + "</td>" + "<td width='20%'>"
                    + doc.getString("reco").toUpperCase().trim() + "</td>" + "<td width='20%'>"
                    + getNombreAlumno(doc.getString("idAlumno")) + "</td>";
            if (doc.getString("estado").equalsIgnoreCase("pendiente")) {
                cadena += "<td width='20%'><button onclick='aceptarActa(" + doc.getString("_id")
                        + ")'>OK</button>" + "<button onclick='rechazarActa(" + doc.getString("_id")
                        + ")'>X</button></td><tr>";
            } else {
                cadena += "<td width='20%'></td><tr>";
            }
        }
    } catch (Exception e) {
        cadena = "No tiene actas pendientes";
        System.out.println("listarActas: " + e);
    } finally {
        cursor.close();
    }
    return cadena;
}

From source file:dto.Dto.java

public String listarTesisAsesor(String id) {
    String cadena = "";
    MongoCollection<Document> col = c.getConnection("tesis_alumno_asesor");
    MongoCursor<Document> cursor = col.find(and(eq("estadoA", "pendiente"), eq("idAsesor", id))).iterator();
    Document doc;/* ww w  .  j  a va 2 s.  com*/
    try {

        while (cursor.hasNext()) {
            System.out.println("while asessor");
            doc = cursor.next();
            cadena += "<tr>" + "<td width='20%'>" + doc.getString("titulo").toUpperCase().trim() + "</td>"
                    + "<td width='20%'>" + getNombreAlumno(doc.getString("idAlumno")) + "</td>";
            if (doc.getString("estadoA").equalsIgnoreCase("pendiente")) {
                cadena += "<td width='20%'><button onclick='aceptarSolicitud(" + doc.getString("_id")
                        + ")'>OK</button>" + "<button onclick='rechazarSolicitud(" + doc.getString("_id")
                        + ")'>X</button></td><tr>";
            } else {
                cadena += "<td width='20%'></td><tr>";
            }
            //System.out.println(doc);               
        }
        //p = doc.getString("nombre");
    } catch (NullPointerException e) {
        System.out.println("tesisAsesor: " + e);
    } finally {
        cursor.close();
    }
    return cadena;
}

From source file:dto.Dto.java

public String listarTesisProfesor(String seccion) {
    MongoCollection<Document> col = c.getConnection("tesis_alumno_asesor");
    MongoCursor<Document> cursor = col.find(eq("seccion", seccion)).iterator();
    Document doc;//from  w  w w.ja v  a2  s  .  co  m
    String cadena = "";
    try {

        while (cursor.hasNext()) {
            doc = cursor.next();
            cadena += "<tr>" + "<td width='20%'>" + doc.getString("titulo").toUpperCase().trim() + "</td>"
                    + "<td width='20%'>" + getNombreAlumno(doc.getString("idAlumno")) + "</td>";
            if (doc.getString("estadoP").equalsIgnoreCase("pendiente")) {
                cadena += "<td width='20%'><button onclick='aceptarTesis(" + doc.getString("_id")
                        + ")'>OK</button>" + "<button onclick='rechazarTesis(" + doc.getString("_id")
                        + ")'>X</button></td><tr>";
            } else {
                cadena += "<td width='20%'></td><tr>";
            }
            //System.out.println(doc);               
        }
        //p = doc.getString("nombre");
    } catch (NullPointerException e) {
        System.out.println("listar tesis: " + e);
    } finally {
        cursor.close();
    }
    return cadena;
}

From source file:dto.Dto.java

public String listarTesisSinAsesor(String seccion) {
    MongoCollection<Document> col = c.getConnection("tesis_alumno_asesor");
    MongoCursor<Document> cursor = col.find(and(eq("seccion", (seccion)), eq("idAsesor", "0"))).iterator();
    Document doc;/*from  w w  w . j av  a  2s  .  co m*/
    String cadena = "";
    try {

        while (cursor.hasNext()) {
            doc = cursor.next();
            cadena += "<tr>" + "<td width='20%'>" + doc.getString("titulo").toUpperCase().trim() + "</td>"
                    + "<td width='20%'><select id='sel' style='display:inline'><option>*** Seleccione asesor ***</option></select></td>"
                    + "<td><button onclick='enviarSolicitud(" + doc.getString("_id")
                    + ")'>Enviar</button></td></tr>";
            //System.out.println(doc);               
        }
        //p = doc.getString("nombre");
    } catch (NullPointerException e) {
        System.out.println("listar sin asesor: " + e);
    } finally {
        cursor.close();
    }
    return cadena;
}

From source file:dto.Dto.java

public String listarAsesores() {
    String cadena = "";
    MongoCollection<Document> col = c.getConnection("profesores");
    MongoCursor<Document> cursor = col.find().iterator();
    Document doc;/*from w  ww .  j a v  a  2  s. c o m*/
    try {
        while (cursor.hasNext()) {
            doc = cursor.next();
            cadena += "<option value='" + doc.getString("_id") + "'>" + doc.getString("nombre") + "</option>";
        }
    } catch (Exception e) {
        System.out.println("listarTesisAsesores: " + e);
    } finally {
        cursor.close();
    }
    return cadena;
}

From source file:edu.ucuenca.storage.services.MongoServiceImpl.java

License:Apache License

@Override
public Document getCluster(String... uri) {
    List<Bson> ls = new ArrayList<>();
    List<Document> c = new ArrayList<>();
    for (String p : uri) {
        Bson eq = eq("_id", p);
        ls.add(eq);//w  ww .  ja va  2 s.  co m
    }
    FindIterable<Document> sort = clusters.find(or(ls)).projection(include("subclusters"))
            .sort(ascending("label-en"));
    MongoCursor<Document> it = sort.iterator();
    while (it.hasNext()) {
        c.add(it.next());
    }
    Document parse = new Document();

    if (c.size() == 1) {
        parse = c.get(0);
    } else {
        parse.put("data", c);
    }
    return parse;

}

From source file:edu.ucuenca.storage.services.MongoServiceImpl.java

License:Apache License

@Override
public List<Document> getClusters() {
    List<Document> c = new ArrayList<>();
    FindIterable<Document> cls = clusters.find().projection(exclude("subclusters"))
            .sort(ascending("label-en", "label-es"));
    MongoCursor<Document> it = cls.iterator();
    while (it.hasNext()) {
        c.add(it.next());
    }//from  www  .  j  av a  2 s  . c  om
    return c;
}