List of usage examples for com.mongodb.util JSON parse
public static Object parse(final String jsonString)
Parses a JSON string and returns a corresponding Java object.
From source file:act.installer.Xref.java
License:Open Source License
public void parseAndAdd(String row) throws Exception { // We assume that the format is "DB_SRC\tDB_SPECIFIC_XREF\tInChI\tJSON_METADATA" // DB_SRC has type Chemical.REFS String[] entry = row.split("\t", -2); // the neg limit means that it keeps the trailing empty strings REFS typ = null;/*from ww w. j a va 2s .c o m*/ String typ_str = entry[0], dbid = entry[1], inchi = entry[2], meta = entry[3]; inchi = ConsistentInChI.consistentInChI(inchi, "Important Chemicals"); // round trip inchi to make it consistent with the rest of the system JSONObject doc = new JSONObject(); try { typ = REFS.valueOf(typ_str); } catch (Exception e) { System.err.println("Invalid important chemicals row: " + row); } doc.put("dbid", dbid); doc.put("metadata", JSON.parse(meta)); InchiMapKey large_inchi = new InchiMapKey(inchi); if (this.chems.containsKey(large_inchi)) { Xref xref = this.chems.get(large_inchi); if (xref.containsType(typ)) { // duplicate mapping... hmm... one needs to be ignored or they are redundant. // the only thing to check are dbid and metadata as the others are identical by construction JSONObject o = xref.get(typ); if (o.get("dbid") != dbid || o.get("metadata") != meta) { // conflicting entry.. error message System.err.println("ImportantChemicals: conflicting entry! leaving the old one in there."); } else { // redundant entry.. do nothing } } else { xref.add(typ, doc); // does not already have a mapping. add indiscrimately } } else { Xref xref = new Xref(); xref.add(typ, doc); this.chems.put(large_inchi, xref); this.all_inchis.add(inchi); } }
From source file:act.server.MongoDB.java
License:Open Source License
public void submitToPubmedDB(PubmedEntry entry) { List<String> xPath = new ArrayList<String>(); xPath.add("MedlineCitation"); xPath.add("PMID"); int pmid = Integer.parseInt(entry.getXPathString(xPath)); if (this.dbPubmed != null) { WriteResult result;/*from ww w . jav a 2 s . c o m*/ if (alreadyEntered(entry, pmid)) return; DBObject doc = (DBObject) JSON.parse(entry.toJSON()); doc.put("_id", pmid); this.dbPubmed.insert(doc); } else Logger.printf(0, "Pubmed Entry [%d]: %s\n", pmid, entry); // human readable... }
From source file:analyzers.DebugAnalyzer.java
License:Apache License
/** * This method extracts tweets from the JSON file * * @param n the number of tweets to analyze * @param fis stream for tweets * @param jsonFile JSON file/*from ww w . j a va 2s . co m*/ * @param analyzer the analyzer * @throws IOException cannot open file */ public static void extractTweets(int n, FileInputStream fis, File jsonFile, Analyzer analyzer) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(fis, StandardCharsets.UTF_8)); TwitterTextValueReader reader = new TwitterTextValueReader(br); while (true) { // read the next tweet from the file int tweetLen = reader.read(cbuf, 0, MAX_CHARS); if (-1 == tweetLen) break; DBObject tweetJSON = (DBObject) JSON.parse(new String(cbuf, 0, tweetLen)); String tweet = tweetJSON.get("text").toString(); System.out.printf("[%d]\t%s\n", (counter + 1), tweet); showAnalysisFromStream(new StringReader(tweet), analyzer); System.out.println(); ++counter; if (counter >= n) break; } }
From source file:applango.common.services.DB.mongo.mongoDB.java
public static int countFailureLogins(Applango applango, DBCollection collection) { logger.info("Count how many failure logins for userId : " + applango.getUsername()); String jsonCustomer = " {$and : [{'userId' : '" + applango.getUsername() + "'} , {'status':'failure'} ] }"; DBObject dbObjectRecordQuery = (DBObject) JSON.parse(jsonCustomer); return (int) collection.count(dbObjectRecordQuery); }
From source file:applango.common.services.DB.mongo.mongoDB.java
public static int countSuccessfulLogins(Applango applango, DBCollection collection) { logger.info("Count how many successful logins for userId : " + applango.getUsername()); String jsonCustomer = " {$and : [{'userId' : '" + applango.getUsername() + "'} , {'status':'success'} ] }"; DBObject dbObjectRecordQuery = (DBObject) JSON.parse(jsonCustomer); return (int) collection.count(dbObjectRecordQuery); }
From source file:applango.common.services.DB.mongo.mongoDB.java
public static int loginsThisMonth(Applango applango, DBCollection collection) { // logger.info("Count how many successful logins for userId : " + applango.getUsername()); String jsonCustomer = " {$or : [{'customerId' : 'fff'}, {'loginTime' : {$gte : '(\"2014-01-01 08:15:04.000Z\")'}} ] }"; DBObject dbObjectRecordQuery = (DBObject) JSON.parse(jsonCustomer); return (int) collection.count(dbObjectRecordQuery); }
From source file:applango.common.services.DB.mongo.mongoDB.java
public static DBObject removeRecordsFromDB(Applango applango, DBCollection coll) { logger.info("Remove all records with customerId : " + applango.getUsername()); String jsonCustomer = "{'customerId' : '" + applango.getCustomerForoAuth() + "'}"; DBObject dbObjectRecordQuery = (DBObject) JSON.parse(jsonCustomer); if (!(coll.count(dbObjectRecordQuery) == 0)) { coll.remove(dbObjectRecordQuery, WriteConcern.ACKNOWLEDGED); }/* w ww. j a v a2 s .co m*/ return dbObjectRecordQuery; }
From source file:applango.common.services.DB.mongo.mongoDB.java
public static String getSpecialToken(Applango applango, DBCollection coll) { logger.info("Get the email token of : " + applango.getUsername()); String token;//w w w. jav a 2s . c om int maxWait = 10; try { String jsonCustomer = "{'userId' : '" + applango.getUsername() + "'}"; DBObject dbObjectRecordQuery = (DBObject) JSON.parse(jsonCustomer); while ((coll.count(dbObjectRecordQuery) == 0) && maxWait > 0) { sleep(1000); maxWait--; } token = coll.find(dbObjectRecordQuery).next().get("specialToken").toString(); } catch (Exception ex) { token = null; logger.error(ex.getMessage()); } return token; }
From source file:applango.common.services.DB.mongo.mongoDB.java
public static int getNumberOfUsersWithoutEndDate(DBCollection appInfoConnection, Applango applango) { String jsonCustomerWithoutEndDate = "{$and : [{'customerId' : '" + applango.getUserForoAuth() + "'}, {endDate : null}, {beginDate : {$ne:null} }] }"; DBObject query = (DBObject) JSON.parse(jsonCustomerWithoutEndDate); return (int) appInfoConnection.count(query); }
From source file:applango.common.services.DB.mongo.mongoDB.java
public static int getNumberOfLoginUsersInLastWeek(DBCollection appInfoConnection, Applango applango) { String loginOverTheLastWeek = "( { distinct :\"loginInfo\"" + ",key: \"externalId\"" + ", query : { $and: [ {loginTime: {gte: new Date(ISODate().getTime()-1000*60*60*24*7)}}, {customerId : \"automationCustomer\"" + "}] } })"; DBObject query = (DBObject) JSON.parse(loginOverTheLastWeek); return (int) appInfoConnection.count(query); }