Example usage for com.mongodb BasicDBList get

List of usage examples for com.mongodb BasicDBList get

Introduction

In this page you can find the example usage for com.mongodb BasicDBList get.

Prototype

public Object get(final String key) 

Source Link

Document

Gets a value at an index.

Usage

From source file:achmad.rifai.erp1.entity.Suplier.java

public static Suplier of(Db d, String kode) throws Exception {
    Suplier v = null;//from   ww  w  .  ja  v a 2s.c  om
    achmad.rifai.erp1.util.RSA r = achmad.rifai.erp1.util.Work.loadRSA();
    com.mongodb.DBObject p = new com.mongodb.BasicDBObject();
    p.put("berkas", kode);
    com.mongodb.DBCursor c = d.getD().getCollectionFromString("suplier").find(p);
    while (c.hasNext()) {
        com.mongodb.DBObject o = c.next();
        com.mongodb.BasicDBList l = (com.mongodb.BasicDBList) o.get("bin");
        String json = "";
        for (int x = 0; x < l.size(); x++)
            json += r.decrypt("" + l.get(x));
        v = new Suplier(json);
        break;
    }
    return v;
}

From source file:achmad.rifai.erp1.entity.Terima.java

public static Terima of(Db d, String kode) throws Exception {
    Terima t = null;/*from w w w. jav a  2 s . com*/
    achmad.rifai.erp1.util.RSA r = achmad.rifai.erp1.util.Work.loadRSA();
    com.mongodb.DBObject p = new com.mongodb.BasicDBObject();
    p.put("berkas", kode);
    com.mongodb.DBCursor c = d.getD().getCollectionFromString("terima").find(p);
    if (c.hasNext()) {
        com.mongodb.BasicDBList l = (com.mongodb.BasicDBList) c.next().get("bin");
        String json = "";
        for (int x = 0; x < l.size(); x++)
            json += r.decrypt("" + l.get(x));
        t = new Terima(json);
    }
    return t;
}

From source file:achmad.rifai.erp1.entity.Tracks.java

public static Tracks of(Db d, String kode) throws Exception {
    Tracks v = null;/*  www.  j  a va 2  s.c  o m*/
    achmad.rifai.erp1.util.RSA r = achmad.rifai.erp1.util.Work.loadRSA();
    com.mongodb.DBObject p = new com.mongodb.BasicDBObject();
    p.put("berkas", kode);
    com.mongodb.DBCursor c = d.getD().getCollectionFromString("tracks").find(p);
    while (c.hasNext()) {
        com.mongodb.DBObject o = c.next();
        com.mongodb.BasicDBList l = (com.mongodb.BasicDBList) o.get("bin");
        String json = "";
        for (int x = 0; x < l.size(); x++)
            json += r.decrypt("" + l.get(x));
        v = new Tracks(json);
        break;
    }
    return v;
}

From source file:achmad.rifai.erp1.entity.Tugas.java

public static Tugas of(Db d, String kode) throws Exception {
    Tugas t = null;//from  w w  w  .j  a v a 2 s.c  o  m
    achmad.rifai.erp1.util.RSA r = achmad.rifai.erp1.util.Work.loadRSA();
    com.mongodb.DBObject p = new com.mongodb.BasicDBObject();
    p.put("berkas", kode);
    com.mongodb.DBCursor c = d.getD().getCollection("tugas").find(p);
    while (c.hasNext()) {
        com.mongodb.DBObject o = c.next();
        com.mongodb.BasicDBList l = (com.mongodb.BasicDBList) o.get("bin");
        String json = "";
        for (int x = 0; x < l.size(); x++)
            json += r.decrypt("" + l.get(x));
        t = new Tugas(json);
        break;
    }
    return t;
}

From source file:act.server.MongoDB.java

License:Open Source License

private String getReactantFromMongoDocument(BasicDBObject family, String which, int i) {
    BasicDBList o = (BasicDBList) ((DBObject) family.get("enz_summary")).get(which);
    if (i >= o.size())
        return "";
    return "" + (Long) ((DBObject) o.get(i)).get("pubchem");
}

From source file:act.server.MongoDB.java

License:Open Source License

private static BasicDBList compare(BasicDBList l, BasicDBList refl, boolean listsAreSet) {
    boolean different = false;
    BasicDBList diff = new BasicDBList();

    if (!listsAreSet) {
        // lists are to be treated as ordered sets and so we can compare element by element
        for (int i = 0; i < l.size(); i++) {
            Object val = l.get(i);
            Object refv = refl.get(i);
            Object d;//from ww w .  j  a v a  2 s. c om
            if ((d = compare(val, refv, listsAreSet)) != null) {
                different = true;
                diff.add(d);
            } else {
                // elements at this index are identical, but we don't want to muck up the order
                // in case future elements are not identical... so add a null to the diff,
                // BUT IMP: do not set the flag that the list is different
                diff.add(null);
            }
        }
    } else {
        // lists are to be treated as unordered sets: we try to match each element best
        // effort to any one of the list elements, and if it does proceed greedily

        // we keep this as a list as opposed to a true set because the original (ref)
        // and the current (new) might have (identical) replicates, and so should not
        // be flagged different because of that.
        List<Object> refset = new ArrayList<Object>();
        refset.addAll(refl);

        for (Object e : l) {
            boolean matches_some = false;
            for (Object eref : refset) {
                if (compare(e, eref, listsAreSet) == null) {
                    // this object matches something, great, lets move to the next object
                    // also remove the matched object from the ref list, so that we have
                    // a 1-1 mapping between this and the ref list object
                    matches_some = true;
                    refset.remove(eref);
                    break;
                }
            }
            if (!matches_some) {
                // if this object in new list could not be matched against something,
                // the lists are different
                different = true;
                diff.add(e);
            }
        }

        if (refset.size() != 0) {
            // still some elements remain in the ref list, i.e., sets different
            different = true;
            diff.addAll(refset);
        }

    }

    return different ? diff : null;
}

From source file:act.server.MongoDB.java

License:Open Source License

public void updateStoichiometry(Reaction r) {
    BasicDBObject query = new BasicDBObject().append("_id", r.getUUID());
    DBObject obj = this.dbReactions.findOne(query);
    DBObject enz_summary = (DBObject) obj.get("enz_summary");
    BasicDBList substrates = (BasicDBList) enz_summary.get("substrates");
    BasicDBList newSubstrates = new BasicDBList();
    Set<Long> originalSubstrateIDs = new HashSet<Long>();
    for (int i = 0; i < substrates.size(); i++) {
        DBObject substrate = (DBObject) substrates.get(i);
        Long substrateID = (Long) substrate.get("pubchem");
        Boolean isForBalance = (Boolean) substrate.get("balance");
        if (isForBalance != null && isForBalance)
            continue;
        originalSubstrateIDs.add(substrateID);
        substrate.put("coefficient", r.getSubstrateCoefficient(substrateID));
        newSubstrates.add(substrate);//from ww w .  ja va2s .  co  m
    }
    Set<Long> substratesNew = r.getSubstrateIdsOfSubstrateCoefficients();
    for (Long s : substratesNew) {
        if (originalSubstrateIDs.contains(s))
            continue;
        if (r.getSubstrateCoefficient(s) == null)
            continue;
        DBObject substrate = new BasicDBObject();
        substrate.put("pubchem", s);
        substrate.put("coefficient", r.getSubstrateCoefficient(s));
        substrate.put("balance", true);
        newSubstrates.add(substrate);
    }

    BasicDBList products = (BasicDBList) enz_summary.get("products");
    BasicDBList newProducts = new BasicDBList();
    Set<Long> originalProductIDs = new HashSet<Long>();
    for (int i = 0; i < products.size(); i++) {
        DBObject product = (DBObject) products.get(i);
        Long productID = (Long) product.get("pubchem");
        Boolean isForBalance = (Boolean) product.get("balance");
        if (isForBalance != null && isForBalance)
            continue;
        originalProductIDs.add(productID);
        product.put("coefficient", r.getProductCoefficient(productID));
        newProducts.add(product);
    }
    Set<Long> productsNew = r.getProductIdsOfProductCoefficients();
    for (Long p : productsNew) {
        if (originalProductIDs.contains(p))
            continue;
        if (r.getProductCoefficient(p) == null)
            continue;
        DBObject product = new BasicDBObject();
        product.put("pubchem", p);
        product.put("coefficient", r.getProductCoefficient(p));
        product.put("balance", true);
        newProducts.add(product);
    }
    enz_summary.put("substrates", newSubstrates);
    enz_summary.put("products", newProducts);
    this.dbReactions.update(query, obj);
}

From source file:act.server.MongoDB.java

License:Open Source License

public Reaction convertDBObjectToReaction(DBObject o) {
    long uuid = (Integer) o.get("_id"); // checked: db type IS int
    String ecnum = (String) o.get("ecnum");
    String name_field = (String) o.get("easy_desc");
    Reaction.RxnDetailType type = Reaction.RxnDetailType.valueOf((String) o.get("is_abstract"));
    BasicDBList substrates = (BasicDBList) ((DBObject) o.get("enz_summary")).get("substrates");
    BasicDBList products = (BasicDBList) ((DBObject) o.get("enz_summary")).get("products");
    BasicDBList substrateCofactors = (BasicDBList) ((DBObject) o.get("enz_summary")).get("substrate_cofactors");
    BasicDBList productCofactors = (BasicDBList) ((DBObject) o.get("enz_summary")).get("product_cofactors");
    BasicDBList coenzymes = (BasicDBList) ((DBObject) o.get("enz_summary")).get("coenzymes");
    BasicDBList refs = (BasicDBList) (o.get("references"));
    BasicDBList proteins = (BasicDBList) (o.get("proteins"));
    DBObject mechanisticValidatorResults = (DBObject) (o.get("mechanistic_validator_result"));

    BasicDBList keywords = (BasicDBList) (o.get("keywords"));
    BasicDBList cikeywords = (BasicDBList) (o.get("keywords_case_insensitive"));

    List<Long> substr = new ArrayList<Long>();
    List<Long> prod = new ArrayList<Long>();
    List<Long> substrCofact = new ArrayList<Long>();
    List<Long> prodCofact = new ArrayList<Long>();
    List<Long> coenz = new ArrayList<Long>();

    String conversionDirectionString = (String) o.get("conversion_direction");
    ConversionDirectionType conversionDirection = conversionDirectionString == null ? null
            : ConversionDirectionType.valueOf(conversionDirectionString);

    String pathwayStepDirectionString = (String) o.get("pathway_step_direction");
    StepDirection pathwayStepDirection = pathwayStepDirectionString == null ? null
            : StepDirection.valueOf(pathwayStepDirectionString);

    for (int i = 0; i < substrates.size(); i++) {
        Boolean forBalance = (Boolean) ((DBObject) substrates.get(i)).get("balance");
        if (forBalance != null && forBalance)
            continue;
        substr.add(getEnzSummaryIDAsLong(substrates, i));
    }//  www.j a v a 2  s.  co  m
    for (int i = 0; i < products.size(); i++) {
        Boolean forBalance = (Boolean) ((DBObject) products.get(i)).get("balance");
        if (forBalance != null && forBalance)
            continue;
        prod.add(getEnzSummaryIDAsLong(products, i));
    }
    for (int i = 0; i < substrateCofactors.size(); i++) {
        substrCofact.add(getEnzSummaryIDAsLong(substrateCofactors, i));
    }
    for (int i = 0; i < productCofactors.size(); i++) {
        prodCofact.add(getEnzSummaryIDAsLong(productCofactors, i));
    }
    for (int i = 0; i < coenzymes.size(); i++) {
        coenz.add(getEnzSummaryIDAsLong(coenzymes, i));
    }

    Reaction result = new Reaction(uuid, (Long[]) substr.toArray(new Long[0]),
            (Long[]) prod.toArray(new Long[0]), (Long[]) substrCofact.toArray(new Long[0]),
            (Long[]) prodCofact.toArray(new Long[0]), (Long[]) coenz.toArray(new Long[0]), ecnum,
            conversionDirection, pathwayStepDirection, name_field, type);

    for (int i = 0; i < substrates.size(); i++) {
        Integer c = (Integer) ((DBObject) substrates.get(i)).get("coefficient");
        if (c != null)
            result.setSubstrateCoefficient(getEnzSummaryIDAsLong(substrates, i), c);
    }
    for (int i = 0; i < products.size(); i++) {
        Integer c = (Integer) ((DBObject) products.get(i)).get("coefficient");
        if (c != null)
            result.setProductCoefficient(getEnzSummaryIDAsLong(products, i), c);
    }

    Double estimatedEnergy = (Double) o.get("estimateEnergy");
    result.setEstimatedEnergy(estimatedEnergy);

    String datasrc = (String) o.get("datasource");
    if (datasrc != null && !datasrc.equals(""))
        result.setDataSource(Reaction.RxnDataSource.valueOf(datasrc));

    if (mechanisticValidatorResults != null) {
        result.setMechanisticValidatorResult(MongoDBToJSON.conv(mechanisticValidatorResults));
    }

    if (refs != null) {
        for (Object oo : refs) {
            DBObject ref = (DBObject) oo;
            Reaction.RefDataSource src = Reaction.RefDataSource.valueOf((String) ref.get("src"));
            String val = (String) ref.get("val");
            result.addReference(src, val);
        }
    }

    if (proteins != null) {
        for (Object oo : proteins) {
            result.addProteinData(MongoDBToJSON.conv((DBObject) oo));
        }
    }

    if (keywords != null)
        for (Object k : keywords)
            result.addKeyword((String) k);

    if (cikeywords != null)
        for (Object k : cikeywords)
            result.addCaseInsensitiveKeyword((String) k);

    return result;
}

From source file:act.server.MongoDB.java

License:Open Source License

private Long getEnzSummaryIDAsLong(BasicDBList reactant, int i) {
    try {//from w ww. j a  v a  2  s . c  o m
        return (Long) ((DBObject) reactant.get(i)).get("pubchem");
    } catch (ClassCastException e) {
        return ((Integer) ((DBObject) reactant.get(i)).get("pubchem")).longValue();
    }
}

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

License:Open Source License

public static JSONArray conv(BasicDBList a) {
    JSONArray result = new JSONArray();
    for (int i = 0; i < a.size(); ++i) {
        Object o = a.get(i);
        if (o instanceof DBObject) {
            result.put(conv((DBObject) o));
        } else if (o instanceof BasicDBList) {
            result.put(conv((BasicDBList) o));
        } else {/*from ww w .j  a v  a2  s. com*/
            result.put(o);
        }
    }
    return result;
}