Example usage for com.mongodb BasicDBObject getString

List of usage examples for com.mongodb BasicDBObject getString

Introduction

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

Prototype

public String getString(final String key) 

Source Link

Document

Returns the value of a field as a string

Usage

From source file:tad.grupo7.ccamistadeslargas.DAO.GastoDAO.java

/**
 * Obtiene un Gasto coincidente con un ID.
 * @param id ObjectId del gasto./*from  w ww.  j  a  v a  2s  .  c o  m*/
 * @return Gasto
 */
public static Gasto read(ObjectId id) {
    BasicDBObject whereQuery = new BasicDBObject();
    whereQuery.put("_id", id);
    BasicDBObject document = (BasicDBObject) gastos.findOne(whereQuery);
    String nombre = document.getString("nombre");
    Double precio = (Double) document.get("precio");
    ObjectId evento = document.getObjectId("idEvento");
    ObjectId pagador = document.getObjectId("idPagador");
    List<Participante> deudores = new ArrayList<>();
    BasicDBList deudoresDB = (BasicDBList) document.get("deudores");
    Iterator it = deudoresDB.iterator();
    while (it.hasNext()) {
        BasicDBObject b = (BasicDBObject) it.next();
        Participante p = new Participante(b.getObjectId("_id"), b.getString("nombre"),
                b.getObjectId("idAmigoDe"));
        deudores.add(p);
    }
    return new Gasto(id, nombre, precio, evento, pagador, deudores);
}

From source file:tad.grupo7.ccamistadeslargas.DAO.GastoDAO.java

/**
 * Obtiene todos los gastos pertenecientes a un evento.
 * @param idEvento ObjectId del evento./*  ww  w  .  j ava2s  .com*/
 * @return List
 */
public static List<Gasto> readAll(ObjectId idEvento) {
    BasicDBObject whereQuery = new BasicDBObject();
    whereQuery.put("idEvento", idEvento);
    DBCursor cursor = gastos.find(whereQuery);
    List<Gasto> gastos = new ArrayList<>();
    while (cursor.hasNext()) {
        BasicDBObject g = (BasicDBObject) cursor.next();
        ObjectId id = g.getObjectId("_id");
        String nombre = g.getString("nombre");
        Double precio = g.getDouble("precio");
        ObjectId idPagador = g.getObjectId("idPagador");
        List<Participante> deudores = ParticipanteDAO.readAllDeudoresFromPago(id);
        gastos.add(new Gasto(id, nombre, precio, idEvento, idPagador, deudores));
    }
    return gastos;
}

From source file:tad.grupo7.ccamistadeslargas.DAO.ParticipanteDAO.java

/**
 * Obtiene un Participante de la BD.//  w  w w  .ja  v  a2s  .  c  o  m
 * @param id ObjectId del participante a obtener.
 * @return Participante
 */
public static Participante read(ObjectId id) {
    BasicDBObject whereQuery = new BasicDBObject();
    whereQuery.put("_id", id);
    BasicDBObject document = (BasicDBObject) participantes.findOne(whereQuery);
    String nombre = document.getString("nombre");
    ObjectId idAmigoDe = document.getObjectId("idAmigoDe");
    return new Participante(id, nombre, idAmigoDe);
}

From source file:tad.grupo7.ccamistadeslargas.DAO.ParticipanteDAO.java

/**
 * Obtiene una lista de todos los participantes de un evento.
 * @param idEvento ObjectId del evento.//from w  w  w.  j  a v a  2  s .c o m
 * @return List
 */
public static List<Participante> readAllFromEvento(ObjectId idEvento) {
    List<Participante> participantes = new ArrayList<>();
    try {
        BasicDBObject whereQuery = new BasicDBObject();
        whereQuery.put("_id", idEvento);
        BasicDBObject document = (BasicDBObject) dataBase.getCollection("Evento").findOne(whereQuery);
        BasicDBList participantesDB = (BasicDBList) document.get("participantes");
        Iterator it = participantesDB.iterator();

        while (it.hasNext()) {
            BasicDBObject p = (BasicDBObject) it.next();
            participantes.add(
                    new Participante(p.getObjectId("_id"), p.getString("nombre"), p.getObjectId("idAmigoDe")));
        }
    } catch (NullPointerException ex) {
    }
    return participantes;
}

From source file:tad.grupo7.ccamistadeslargas.DAO.ParticipanteDAO.java

/**
 * Obtiene todos los participantes(amigos) de un Usuario.
 * @param idUsuario ObjectId del usuario.
 * @return List/*from   w  w w .  j  av a  2 s  .c  om*/
 */
public static List<Participante> readAllFromUsuario(ObjectId idUsuario) {
    BasicDBObject whereQuery = new BasicDBObject();
    whereQuery.put("_id", idUsuario);
    BasicDBObject document = (BasicDBObject) dataBase.getCollection("Usuario").findOne(whereQuery);
    List<Participante> participantes = new ArrayList<>();
    try {
        BasicDBList participantesDB = (BasicDBList) document.get("amigos");
        Iterator it = participantesDB.iterator();

        while (it.hasNext()) {
            BasicDBObject p = (BasicDBObject) it.next();
            participantes.add(
                    new Participante(p.getObjectId("_id"), p.getString("nombre"), p.getObjectId("idAmigoDe")));
        }
    } catch (NullPointerException ex) {
    }

    return participantes;
}

From source file:tad.grupo7.ccamistadeslargas.DAO.ParticipanteDAO.java

/**
 * Obtiene un listado de todos los deudores de un pago de un evento.
 * @param idGasto ObjectId del gasto./*from  w w  w .j av  a  2  s. c o  m*/
 * @return List
 */
public static List<Participante> readAllDeudoresFromPago(ObjectId idGasto) {
    BasicDBObject whereQuery = new BasicDBObject();
    whereQuery.put("_id", idGasto);
    BasicDBObject document = (BasicDBObject) dataBase.getCollection("Gasto").findOne(whereQuery);
    BasicDBList participantesDB = (BasicDBList) document.get("deudores");
    Iterator it = participantesDB.iterator();
    List<Participante> participantes = new ArrayList<>();
    while (it.hasNext()) {
        BasicDBObject p = (BasicDBObject) it.next();
        participantes
                .add(new Participante(p.getObjectId("_id"), p.getString("nombre"), p.getObjectId("idAmigoDe")));
    }
    return participantes;
}

From source file:tad.grupo7.ccamistadeslargas.DAO.UsuarioDAO.java

/**
 * Obtiene un Usuario de la BD./*from  ww w.j  a  v  a2s .c om*/
 * @param id ObjectId del usuario.
 * @return Usuario.
 */
public static Usuario read(ObjectId id) {
    BasicDBObject whereQuery = new BasicDBObject();
    whereQuery.put("_id", id);
    BasicDBObject document = (BasicDBObject) usuarios.findOne(whereQuery);
    String nombre = document.getString("nombre");
    String password = document.getString("password");
    String email = document.getString("email");
    return new Usuario(id, nombre, password, email, ParticipanteDAO.readAllFromUsuario(id));
}

From source file:tad.grupo7.ccamistadeslargas.DAO.UsuarioDAO.java

/**
 * Obtiene un Usuario de la BD./*from  w ww .  j  a  v a2 s . co  m*/
 * @param email String email del usuario.
 * @param password String password del usuario.
 * @return Usuario
 */
public static Usuario read(String email, String password) {
    BasicDBObject andQuery = new BasicDBObject();
    List<BasicDBObject> obj = new ArrayList<>();
    obj.add(new BasicDBObject("email", email));
    obj.add(new BasicDBObject("password", password));
    andQuery.put("$and", obj);
    BasicDBObject document = (BasicDBObject) usuarios.findOne(andQuery);
    Usuario u = null;
    if (document != null) {
        u = new Usuario(document.getObjectId("_id"), document.getString("nombre"), password, email,
                ParticipanteDAO.readAllFromUsuario(document.getObjectId("_id")));
    }
    return u;
}

From source file:tad.grupo7.ccamistadeslargas.DAO.UsuarioDAO.java

/**
 * Devuelve todos los usuarios de la BD.
 * @return List//from www  . jav a  2 s  . co  m
 */
public static List<Usuario> readAll() {
    DBCursor cursor = usuarios.find();
    List<Usuario> usuarios = new ArrayList<>();
    while (cursor.hasNext()) {
        BasicDBObject u = (BasicDBObject) cursor.next();
        usuarios.add(new Usuario(u.getObjectId("_id"), u.getString("nombre"), u.getString("password"),
                u.getString("email"), ParticipanteDAO.readAllFromUsuario(u.getObjectId("_id"))));
    }
    return usuarios;
}

From source file:tango.dataStructure.Experiment.java

License:Open Source License

private void getStructureProps() {
    structureSettings = new BasicDBObject[structures.size() + virtualStructures.size()];
    for (int i = 0; i < structures.size(); i++)
        structureSettings[i] = (BasicDBObject) structures.get(i);
    for (int i = 0; i < virtualStructures.size(); i++)
        structureSettings[i + structures.size()] = (BasicDBObject) virtualStructures.get(i);
    processingChain = new BasicDBObject[structures.size()];
    for (int i = 0; i < structures.size(); i++) {
        if (structureSettings[i].containsField("processingChain"))
            processingChain[i] = (BasicDBObject) structureSettings[i].get("processingChain");
        else if (structureSettings[i].containsField("settings"))
            processingChain[i] = (i == 0) ? mc.getNucSettings(structureSettings[i].getString("settings"))
                    : mc.getChannelSettings(structureSettings[i].getString("settings")); // for compatibility with older versions
    }/*from www  .  j  a  va  2s  . c  om*/
    fileKeyword = new String[channelFiles.size()];
    for (int i = 0; i < channelFiles.size(); i++) {
        BasicDBObject file = (BasicDBObject) channelFiles.get(i);
        fileKeyword[i] = file.getString("keyword");
        if (fileKeyword[i] == null || fileKeyword[i].length() == 0) {
            fileKeyword[i] = "" + (i + 1);
            file.append("keyword", fileKeyword[i]);
        }
    }
    fileRank = new int[structures.size()];
    for (int i = 0; i < structures.size(); i++) {
        fileRank[i] = structureSettings[i].getInt("file", 0);
        if (fileRank[i] == -1)
            ij.IJ.log("Experiment configuration error: structure:" + i + " not associated to a channel image");
    }
    ChannelFileParameter.setChannels(fileKeyword);
    StructureParameter.setStructures(this.getStructureNames(false), this.getVirtualStructureNames());
    SamplerParameter.setChannels(this.getSampleChannelNames());
}