List of usage examples for com.mongodb BasicDBObject getString
public String getString(final String key)
From source file:gMIRC_server.java
public static void HardClean() { try {//from www . ja va2s.c om MongoClient mongoClient = new MongoClient(); DB db = mongoClient.getDB("mirc"); DBCollection coll[] = new DBCollection[4]; coll[0] = db.getCollection("channelCollection"); coll[1] = db.getCollection("inbox"); coll[2] = db.getCollection("activeUser"); coll[3] = db.getCollection("passiveUser"); DBCursor cursor = coll[3].find(); try { while (cursor.hasNext()) { BasicDBObject temp = (BasicDBObject) cursor.next(); String username = temp.getString("username"); BasicDBObject query = new BasicDBObject("username", username); System.out.println("cleaning " + username); for (int i = 0; i < 4; i++) { DBCursor cursor2 = coll[i].find(query); try { while (cursor2.hasNext()) { DBObject temp2 = cursor2.next(); coll[i].remove(temp2); } } finally { cursor2.close(); } } } } finally { cursor.close(); } } catch (UnknownHostException ex) { Logger.getLogger(gMIRC_server.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:act.installer.reachablesexplorer.FreemarkerRenderer.java
License:Open Source License
private Object buildReachableModel(Reachable r, List<PathwayDoc> pathwayDocs) { /* Freemarker's template language is based on a notion of "hashes," which are effectively just an untyped hierarchy * of maps and arrays culminating in scalar values (think of it like a JSON doc done up in plain Java types). * There are new facilities to run some Java accessors from within freemarker templates, but the language is * sufficiently brittle on its own that complicating things seems like a recipe for much pain. *//w w w . jav a 2 s. c o m * This is just how Freemarker works. Oh well. */ Map<String, Object> model = new HashMap<>(); model.put("pageTitle", r.getPageName()); model.put("inchi", r.getInchi()); model.put("smiles", r.getSmiles()); model.put("structureRendering", r.getStructureFilename()); model.put("cascade", r.getPathwayVisualization()); if (hidePathways) { model.put("hidePathways", true); // TODO: is there a cleaner way to make this URL? model.put("orderLink", String.format("{{SERVER}}%s?%s=%s", ORDER_PATH, ORDER_INCHI_KEY_PARAM, r.getInchiKey())); } if (r.getWordCloudFilename() != null) { model.put("wordcloudRendering", r.getWordCloudFilename()); } List<Object> pathways = new ArrayList<>(); for (PathwayDoc doc : pathwayDocs) { pathways.add(new HashMap<String, String>() { { put("link", doc.getPageName()); put("name", doc.getPathText()); // With help from http://stackoverflow.com/questions/13183982/html-entity-for-check-mark put("hasDna", doc.getHasDNA() ? "✓" : ""); } }); } if (pathways.size() > 0) { model.put("pathways", pathways); } List<PatentSummary> patentSummaries = r.getPatentSummaries(); if (patentSummaries != null && !patentSummaries.isEmpty()) { List<Map<String, String>> patentModel = patentSummaries.stream().map(p -> { return new HashMap<String, String>() { { put("title", p.getTitle()); put("link", p.generateUSPTOURL()); put("id", p.getId().replaceFirst("-.*$", "")); // Strip date + XML suffix, just leave grant number. } }; }).collect(Collectors.toList()); model.put("patents", patentModel); } Map<Chemical.REFS, BasicDBObject> xrefs = r.getXref(); // We check that xrefs is not null to avoid NPEs when a Reachable does not have xrefs (cross-references) populated. // It is expected that projections such as L3 or L4 are in that situation. if (xrefs != null) { // Each XREF being populated in a Reachable as DBObjects, serialization and deserialization causes funky problems // to appear. In particular, casting to BasicDBObjects fails because Jackson deserialized it as a LinkedHashMap // See http://stackoverflow.com/questions/28821715/java-lang-classcastexception-java-util-linkedhashmap-cannot-be-cast-to-com-test if (xrefs.containsKey(Chemical.REFS.BING)) { BasicDBObject bingXref = xrefs.get(Chemical.REFS.BING); Map<String, Object> bingMetadata = (Map) bingXref.get("metadata"); List<Map> bingUsageTerms = (List) bingMetadata.get("usage_terms"); if (bingUsageTerms.size() > 0) { List<Map<String, Object>> bingUsageTermsModel = bingUsageTerms.stream() .map(usageTerm -> new HashMap<String, Object>() { { put("usageTerm", usageTerm.get("usage_term")); put("urls", usageTerm.get("urls")); } }).collect(Collectors.toList()); Collections.sort(bingUsageTermsModel, (o1, o2) -> ((ArrayList) o2.get("urls")).size() - ((ArrayList) o1.get("urls")).size()); model.put("bingUsageTerms", bingUsageTermsModel); } } if (xrefs.containsKey(Chemical.REFS.WIKIPEDIA)) { BasicDBObject wikipediaXref = xrefs.get(Chemical.REFS.WIKIPEDIA); String wikipediaUrl = wikipediaXref.getString("dbid"); model.put("wikipediaUrl", wikipediaUrl); } } if (r.getSynonyms() != null) { if (r.getSynonyms().getPubchemSynonyms() != null) { List<Map<String, Object>> pubchemSynonymModel = r.getSynonyms().getPubchemSynonyms().entrySet() .stream().map(entry -> new HashMap<String, Object>() { { put("synonymType", entry.getKey().toString()); put("synonyms", entry.getValue().stream().collect(Collectors.toList())); } }).collect(Collectors.toList()); model.put("pubchemSynonyms", pubchemSynonymModel); } if (r.getSynonyms().getMeshHeadings() != null) { List<Map<String, Object>> meshHeadingModel = r.getSynonyms().getMeshHeadings().entrySet().stream() .map(entry -> new HashMap<String, Object>() { { String key = entry.getKey().toString(); put("synonymType", "NONE".equals(key) ? "MeSH" : key); put("synonyms", entry.getValue().stream().collect(Collectors.toList())); } }).collect(Collectors.toList()); model.put("meshHeadings", meshHeadingModel); } } if (r.getPhysiochemicalProperties() != null) { PhysiochemicalProperties physiochemicalProperties = r.getPhysiochemicalProperties(); model.put("physiochemicalProperties", new HashMap<String, String>() { { put("pka", String.format("%.2f", physiochemicalProperties.getPkaAcid1())); put("logp", String.format("%.2f", physiochemicalProperties.getLogPTrue())); put("hlb", String.format("%.2f", physiochemicalProperties.getHlbVal())); } }); } return model; }
From source file:act.installer.reachablesexplorer.WordCloudGenerator.java
License:Open Source License
public Set<String> getBingInchis() { BasicDBObject query = new BasicDBObject("xref.BING.metadata.usage_terms.0", new BasicDBObject(MongoKeywords.EXISTS$.MODULE$.value(), true)); BasicDBObject keys = new BasicDBObject(ChemicalKeywords.INCHI$.MODULE$.value(), true); DBIterator ite = bingDb.getIteratorOverChemicals(query, keys); Set<String> bingSet = new HashSet<>(); while (ite.hasNext()) { BasicDBObject o = (BasicDBObject) ite.next(); String inchi = o.getString(ChemicalKeywords.INCHI$.MODULE$.value()); if (inchi != null) { bingSet.add(inchi);// ww w . j a va 2 s .co m } } return bingSet; }
From source file:at.oneminutedistraction.mongodbrealm.UserCollection.java
public String[] authenticate(final String username, final String password) throws LoginException { BasicDBObject user = find(username); if (null == user) throw new LoginException(username + " does not exist"); if (!(user.containsField(ATTR_PASSWORD) && passwordMgr.isValid(user.getString(ATTR_PASSWORD), password))) throw new LoginException("Invalid password"); return (groups(user)); // BasicDBList groups = (BasicDBList)user.get(ATTR_GROUPS); // if (null == groups) // return (new String[]{}); ////from w w w.ja va 2s . c om // // List<String> g = groups.stream() // .map(e -> { return (e.toString()); }) // .collect(Collectors.toList()); // return (g.toArray(new String[g.size()])); }
From source file:at.oneminutedistraction.mongodbrealm.UserCollection.java
public void insert(BasicDBObject insertUser) throws MongoDBRealmException { String username = insertUser.getString(ATTR_USERNAME); if (null != find(username)) throw new MongoDBRealmException("User exists: " + username); try {//from ww w .j av a2 s . c o m users.insert(insertUser); } catch (MongoException ex) { throw new MongoDBRealmException("Inserting user " + username, ex); } }
From source file:at.oneminutedistraction.mongodbrealm.UserCollection.java
public void update(BasicDBObject updateUser) throws MongoDBRealmException { String username = updateUser.getString(ATTR_USERNAME); verify(updateUser, "Cannot find user: " + username); try {/* w w w. j a v a 2 s. com*/ users.update(new BasicDBObject(ATTR_USERNAME, username), updateUser); } catch (MongoException ex) { throw new MongoDBRealmException("Updating user " + username, ex); } }
From source file:at.oneminutedistraction.mongodbrealm.UserCollection.java
public void remove(BasicDBObject deleteUser) throws MongoDBRealmException { String username = deleteUser.getString(ATTR_USERNAME); verify(deleteUser, "Cannot find user: " + username); try {/* www . j a v a 2s. c o m*/ users.remove(deleteUser); } catch (MongoException ex) { throw new MongoDBRealmException("Deleting user " + username, ex); } }
From source file:at.oneminutedistraction.mongodbrealm.UserCollection.java
private void verify(final BasicDBObject obj, final String exceptionMsg) throws MongoDBRealmException { final String username = obj.getString(ATTR_USERNAME); if (null == find(username)) throw new MongoDBRealmException(exceptionMsg); }
From source file:bd.DArticulo.java
@Override public String insertar(Object o) { CArticulo x = (CArticulo) o;/*from www .ja va2s . c om*/ String ver = verificar(x); if (ver.compareTo(MSG_ACEPTADO) != 0) return ver; conecion con = new conecion(table); BasicDBObject datos = new BasicDBObject(x.get_datos()); con.get_colletion().insert(datos); con.end(); return datos.getString("_id"); }
From source file:bd.DArticulo.java
@Override public String eliminar(Object o) { CArticulo x = (CArticulo) o;// w ww .j av a 2 s . c o m conecion con = new conecion(table); BasicDBObject datos = new BasicDBObject("_id", x.getId()); con.get_colletion().remove(datos); con.end(); return datos.getString("_id"); }