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:act.server.MongoDB.java

License:Open Source License

public DBIterator getIdCursorForFakeChemicals() {
    DBObject fakeRegex = new BasicDBObject();
    DBObject abstractInchi = new BasicDBObject();
    fakeRegex.put(ChemicalKeywords.INCHI$.MODULE$.toString(),
            new BasicDBObject(MongoKeywords.REGEX$.MODULE$.toString(), "^InChI=/FAKE"));

    abstractInchi.put(ChemicalKeywords.INCHI$.MODULE$.toString(),
            new BasicDBObject(MongoKeywords.REGEX$.MODULE$.toString(), "^InChI=.*R.*"));

    BasicDBList conditionList = new BasicDBList();
    conditionList.add(fakeRegex);/*from   ww w . ja  v  a2s  . c  o  m*/
    conditionList.add(abstractInchi);

    BasicDBObject conditions = new BasicDBObject(MongoKeywords.OR$.MODULE$.toString(), conditionList);

    return getIteratorOverChemicals(conditions,
            new BasicDBObject(ChemicalKeywords.ID$.MODULE$.toString(), true));
}

From source file:act.server.MongoDB.java

License:Open Source License

public Iterator<Chemical> getChemicalsbyIds(List<Long> ids, boolean notimeout) {
    BasicDBList queryList = new BasicDBList();
    for (Long id : ids) {
        queryList.add(new BasicDBObject(ChemicalKeywords.ID$.MODULE$.toString(), id));
    }/*from   w  ww . ja  v  a  2  s  .  c  o  m*/

    return getJavaIteratorOverChemicals(new BasicDBObject(MongoKeywords.OR$.MODULE$.toString(), queryList));
}

From source file:act.server.MongoDB.java

License:Open Source License

public Set<Reaction> getReactionsConstrained(Map<String, Object> equalityCriteria) {
    BasicDBList andList = new BasicDBList();
    for (String k : equalityCriteria.keySet()) {
        BasicDBObject query = new BasicDBObject();
        query.put(k, equalityCriteria.get(k));
        andList.add(query);/*from  w w  w  . j a  v  a2 s.co  m*/
    }
    BasicDBObject query = new BasicDBObject();
    query.put("$and", andList);
    DBCursor cur = this.dbReactions.find(query);

    Set<Reaction> results = new HashSet<Reaction>();
    while (cur.hasNext()) {
        results.add(convertDBObjectToReaction(cur.next()));
    }
    return results;
}

From source file:act.server.MongoDB.java

License:Open Source License

public Iterator<Reaction> getReactionsIteratorById(List<Long> ids, boolean notimeout) {
    BasicDBList reactionList = new BasicDBList();

    for (Long id : ids) {
        reactionList.add(new BasicDBObject(ChemicalKeywords.ID$.MODULE$.toString(), id));
    }/*from   w  w  w  .  j av a 2s.  com*/

    BasicDBObject query = new BasicDBObject(MongoKeywords.OR$.MODULE$.toString(), reactionList);

    final DBIterator iter = getIteratorOverReactions(query, null);

    return new Iterator<Reaction>() {
        @Override
        public boolean hasNext() {
            boolean hasNext = iter.hasNext();
            if (!hasNext)
                iter.close();
            return hasNext;
        }

        @Override
        public Reaction next() {
            DBObject o = iter.next();
            return convertDBObjectToReaction(o);
        }
    };
}

From source file:act.server.MongoDB.java

License:Open Source License

public int submitToActSeqDB(Seq.AccDB src, String ec, String org, Long org_id, String seq,
        List<JSONObject> references, Set<Long> rxns, DBObject meta) {
    BasicDBObject doc = new BasicDBObject();
    int id = new Long(this.dbSeq.count()).intValue();
    doc.put("_id", id);
    doc.put("src", src.name()); // genbank, uniprot, swissprot, trembl, embl
    doc.put("ecnum", ec);
    doc.put("org", org);
    doc.put("org_id", org_id); // this is the NCBI Taxonomy id, should correlate with db.organismnames{org_id} and db.organisms.{id}
    doc.put("seq", seq);

    BasicDBList refs = new BasicDBList();
    for (JSONObject ref : references) {
        refs.add(MongoDBToJSON.conv(ref));
    }//from  w  w  w  . j  a  va2  s.c  o m
    doc.put("references", refs);

    doc.put("metadata", meta); // the metadata contains the uniprot acc#, name, uniprot catalytic activity,
    Object accession = meta.get("accession");

    doc.put("rxn_refs", to_dblist(rxns));

    this.dbSeq.insert(doc);

    if (org != null && seq != null)
        System.out.format("Inserted %s = [%s, %s] = %s %s\n", accession, ec,
                org.substring(0, Math.min(10, org.length())), seq.substring(0, Math.min(20, seq.length())),
                refs);

    return id;
}

From source file:act.server.MongoDB.java

License:Open Source License

<X> BasicDBList to_dblist(Set<X> set) {
    BasicDBList dblist = new BasicDBList();
    if (set != null)
        dblist.addAll(set);
    return dblist;
}

From source file:act.server.MongoDB.java

License:Open Source License

public void updateReferences(Seq seq) {
    BasicDBObject query = new BasicDBObject().append("_id", seq.getUUID());
    DBObject obj = this.dbSeq.findOne(query);
    BasicDBList refs = new BasicDBList();

    List<DBObject> newReferences = new ArrayList<>();
    for (JSONObject ref : seq.getReferences()) {
        newReferences.add(MongoDBToJSON.conv(ref));
    }/*from  ww w.  j a v  a 2  s. c o m*/

    refs.addAll(newReferences);
    obj.put("references", refs);
    this.dbSeq.update(query, obj);
}

From source file:act.server.MongoDB.java

License:Open Source License

/**
 * Following methods are related to Bing cross-references installation in the Installer DB along with various
 * queries to obtain names (aka synonyms)
 */// ww  w  .j  a va2 s.  co  m

public BasicDBObject createBingMetadataDoc(Set<UsageTermUrlSet> usageTerms, Long totalCountSearchResults,
        String bestName) {
    BasicDBObject metadata = new BasicDBObject();
    if (usageTerms != null) {
        BasicDBList usageTermsDBObject = new BasicDBList();
        for (UsageTermUrlSet usageTerm : usageTerms) {
            // What happens if you don't translate to basic db obj in the next line?
            usageTermsDBObject.add(usageTerm.getBasicDBObject());
        }
        metadata.put("usage_terms", usageTermsDBObject);
    }
    if (totalCountSearchResults >= 0) {
        metadata.put("total_count_search_results", totalCountSearchResults);
    }
    if (!bestName.equals("")) {
        metadata.put("best_name", bestName);
    }
    return metadata;
}

From source file:act.server.MongoDB.java

License:Open Source License

public DBCursor fetchNamesAndUsageForInchis(Set<String> inchis) {
    BasicDBList inchiList = new BasicDBList();
    inchiList.addAll(inchis);//from  www. j  ava  2s.  co m
    BasicDBObject inClause = new BasicDBObject("$in", inchiList);
    BasicDBObject whereQuery = new BasicDBObject("InChI", inClause);
    whereQuery.put("xref.BING", new BasicDBObject("$exists", true));
    BasicDBObject fields = new BasicDBObject();
    fields.put("InChI", true);
    fields.put("names.brenda", true);
    fields.put("xref", true);
    DBCursor cursor = dbChemicals.find(whereQuery, fields);
    return cursor;
}

From source file:act.shared.helpers.MongoDBToJSON.java

License:Open Source License

public static DBObject conv(JSONArray a) {
    BasicDBList result = new BasicDBList();
    try {//w  w  w.jav  a  2s. c om
        for (int i = 0; i < a.length(); ++i) {
            Object o = a.get(i);
            if (o instanceof JSONObject) {
                result.add(conv((JSONObject) o));
            } else if (o instanceof JSONArray) {
                result.add(conv((JSONArray) o));
            } else {
                result.add(o);
            }
        }
        return result;
    } catch (JSONException je) {
        return null;
    }
}