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:fr.gouv.vitam.mdbes.ElasticSearchAccess.java

License:Open Source License

/**
 * Should be called only once saved (last time), but for the moment let the object as it is, next should remove not indexable
 * entries/*from w  w w .j a v  a  2  s  .co m*/
 *
 * @param dbvitam
 * @param model
 * @param indexes
 * @param bson
 * @return the number of DAip incorporated (0 if none)
 */
public static final int addEsIndex(final MongoDbAccess dbvitam, final String model,
        final Map<String, String> indexes, final BSONObject bson) {
    BasicDBObject maip = getFiltered(bson);
    final String id = maip.getString(VitamType.ID);
    maip.removeField(VitamType.ID);
    // System.err.println(maip);
    // System.err.println(this);
    indexes.put(id, maip.toString());
    int nb = 0;
    if (indexes.size() > GlobalDatas.LIMIT_ES_NEW_INDEX) {
        nb = indexes.size();
        dbvitam.addEsEntryIndex(indexes, model);
        // dbvitam.flushOnDisk();
        indexes.clear();
        System.out.print("o");
    }
    maip.clear();
    maip = null;
    return nb;
}

From source file:gov.llnl.iscr.iris.Iris.java

License:Open Source License

/**
 * returns a <code>String</code> representation of a trigram, if it exist, within the given list of ngrams
 * @param ngrams a list of ngram objects
 * @return/*from ww  w. j  ava  2 s .c o  m*/
 */
public String getTrigram(List<BasicDBObject> ngrams) {
    BasicDBObject trigram = ngrams.get(0);
    if ((Integer) trigram.get("size") == 3)
        return trigram.getString("ngram");
    else
        return "(No trigrams found)";
}

From source file:gr.ntua.ivml.awareness.search.SearchServiceAccess.java

public BasicDBObject searchEuropeana(String originalTerm, String type, int startPage) throws Exception {
    String[] termsarray = originalTerm.split(" ");
    List terms = Arrays.asList(termsarray);
    URI uri = constructURI(terms, type, startPage - 1);
    httpGet = new HttpGet(uri);
    BasicDBObject response = new BasicDBObject();

    httpRes = httpClient.execute(httpGet);
    httpEntity = httpRes.getEntity();/*  ww w  .ja  va 2s.  c  o m*/
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    httpEntity.writeTo(out);
    String resp = new String(out.toByteArray(), "UTF-8");
    BasicDBObject obj = (BasicDBObject) JSON.parse(resp);
    response.put("itemsCount", obj.getString("itemsCount"));
    response.put("totalResults", obj.getString("totalResults"));
    response.put("term", originalTerm);
    response.put("type", type);
    response.put("pageNumber", startPage);
    @SuppressWarnings("unchecked")
    ArrayList<Object> items = (ArrayList<Object>) obj.get("items");
    if (items != null) {
        Iterator<Object> it = items.iterator();
        ArrayList<BasicDBObject> responseItems = new ArrayList<BasicDBObject>();
        while (it.hasNext()) {
            BasicDBObject tmp = (BasicDBObject) it.next();
            BasicDBObject re = new BasicDBObject();
            String recid = tmp.getString("id");

            re.put("europeanaid", recid);
            re.put("type", tmp.getString("type"));
            re.put("source", tmp.getString("guid"));
            BasicDBList titleslist = (BasicDBList) tmp.get("title");
            if (titleslist != null)
                re.put("title", StringUtils.join(titleslist, ','));

            BasicDBList providerslist = (BasicDBList) tmp.get("dataProvider");
            if (providerslist != null)
                re.put("dataProvider", providerslist.get(0));
            providerslist = (BasicDBList) tmp.get("provider");
            if (providerslist != null)
                re.put("provider", providerslist.get(0));

            BasicDBList creatorlist = (BasicDBList) tmp.get("dcCreator");
            if (creatorlist != null)
                re.put("dcCreator", creatorlist.get(0));

            BasicDBList languagelist = (BasicDBList) tmp.get("language");
            if (languagelist != null)
                re.put("language", languagelist.get(0));

            BasicDBList thumbslist = (BasicDBList) tmp.get("edmPreview");
            if (thumbslist != null)
                re.put("url", thumbslist.get(0));

            BasicDBList rightslist = (BasicDBList) tmp.get("rights");
            if (rightslist != null)
                re.put("license", rightslist.get(0));

            responseItems.add(re);

        }
        response.put("items", responseItems);
    }
    return response;
}

From source file:japura.Tribes.Tribe.java

License:BSD License

public Block[] getEmeralds() {
    if (emeraldCache != null)
        return emeraldCache;
    Tribes.log("rebuilding emerald table for " + name);
    BasicDBObject query = new BasicDBObject();
    query.put("tribe", name);
    DBCursor cursor = Tribes.getEmeraldTable().find(query);
    int size = cursor.count();
    Block[] blocks = new Block[size];
    double x;//from w  w w  .java2 s . c  om
    double y;
    double z;
    World world;
    Location loc;
    BasicDBObject current;
    for (int i = 0; i < size; i++) {
        if (!cursor.hasNext())
            break;
        current = ((BasicDBObject) cursor.next());
        x = current.getLong("X");
        y = current.getLong("Y");
        z = current.getLong("Z");
        world = Bukkit.getWorld(current.getString("world"));
        loc = new Location(world, x, y, z);
        blocks[i] = loc.getBlock();
    }

    emeraldCache = blocks;
    return blocks;
}

From source file:japura.Tribes.Tribe.java

License:BSD License

public Block[] getDiamonds() {

    if (diamondCache != null)
        return diamondCache;
    Tribes.log("rebuilding diamond table for " + name);
    BasicDBObject query = new BasicDBObject();
    query.put("tribe", name);
    DBCursor cursor = Tribes.getDiamondTable().find(query);
    int size = cursor.count();
    Block[] blocks = new Block[size];
    double x;/*from w ww  .j a  va  2 s . com*/
    double y;
    double z;
    World world;
    Location loc;
    BasicDBObject current;
    for (int i = 0; i < size; i++) {
        current = ((BasicDBObject) cursor.next());
        x = current.getLong("X");
        y = current.getLong("Y");
        z = current.getLong("Z");
        world = Bukkit.getWorld(current.getString("world"));
        loc = new Location(world, x, y, z);
        blocks[i] = loc.getBlock();
    }

    diamondCache = blocks;
    return blocks;
}

From source file:laboratorio_2_sd.Documento.java

public Documento(BasicDBObject dBObject) {
    this.idDoc = dBObject.getInt("idDoc");
    this.titulo = dBObject.getString("titulo");
    this.usuario = dBObject.getString("usuario");
    this.url = dBObject.getString("url");
    this.cantPalabras = dBObject.getInt("cantPalabras");
}

From source file:laboratorio_2_sd.Vocabulario.java

public Vocabulario(BasicDBObject dBObject) {
    this.idPalabra = dBObject.getInt("idPalabra");
    this.palabra = dBObject.getString("palabra");
    this.cantDocumentos = dBObject.getInt("cantDocumentos");
}

From source file:mdb.utilMongoDB.java

public List<SimpleFeeling> getFeeling(int presentationId, int userId, boolean getPropertires,
        boolean getUserId) {
    ArrayList<SimpleFeeling> listFeeling = new ArrayList<>();
    BasicDBObject query = new BasicDBObject("presentationId", presentationId);

    if (getUserId) {
        query.append("userId", userId);
    }//from   www . j a  v a  2s  .co m

    try (DBCursor cursor = getPresentationData().find(query)) {
        cursor.sort(new BasicDBObject("time", 1));
        while (cursor.hasNext()) {
            DBObject feeling = cursor.next();
            SimpleFeeling sFeeling = new SimpleFeeling(presentationId, (int) feeling.get("userId"),
                    (int) feeling.get("feelingId"), (int) feeling.get("previousFeelingId"),
                    (long) feeling.get("time"));
            if (getPropertires) {
                sFeeling.setPropertires(new ArrayList<SimpleProperty>());
                for (BasicDBObject prop : (List<BasicDBObject>) feeling.get("propertires")) {
                    sFeeling.getPropertires().add(
                            new SimpleProperty(prop.getInt("propertireId"), prop.getString("propertireValue")));
                }
            }
            listFeeling.add(sFeeling);
        }
    }

    return listFeeling;
}

From source file:MDBInt.DBMongo.java

License:Apache License

/**
 * This update Federation User with element 
 * @param dbName/*w ww  . jav a  2s. co m*/
 * @param collectionName
 * @param docJSON 
 */
public void insertUser(String dbName, String collectionName, String docJSON) {

    DB dataBase = this.getDB(dbName);
    DBCollection collezione = this.getCollection(dataBase, collectionName);
    BasicDBObject obj = (BasicDBObject) JSON.parse(docJSON);
    String userName;
    userName = obj.getString("federationUser");
    obj.append("_id", userName);
    obj.append("insertTimestamp", System.currentTimeMillis());
    collezione.save(obj);
}

From source file:MDBInt.DBMongo.java

License:Apache License

public void updateUser(String dbName, String collectionName, String docJSON) {

    DB dataBase = this.getDB(dbName);
    DBCollection collezione = this.getCollection(dataBase, collectionName);
    BasicDBObject obj = (BasicDBObject) JSON.parse(docJSON);
    String userName;//from  w ww.  j ava 2  s  . c  om
    userName = obj.getString("federationUser");
    obj.append("_id", userName);

    collezione.save(obj);
}