List of usage examples for com.mongodb.client.model Filters eq
public static <TItem> Bson eq(final String fieldName, @Nullable final TItem value)
From source file:com.gs.obevo.mongodb.impl.MongoDbChangeAuditDao.java
License:Apache License
private Bson getChangeFilter(Change change) { return Filters.and(Filters.eq(changeNameColumn, change.getChangeName()), Filters.eq("OBJECTNAME", change.getObjectName())); }
From source file:com.gs.obevo.mongodb.impl.MongoDbChangeAuditDao.java
License:Apache License
@Override public void deleteChange(Change change) { MongoCollection<Document> auditCollection = getAuditCollection(change); auditCollection.deleteOne(Filters.and(Filters.eq(changeNameColumn, change.getChangeName()), Filters.eq("OBJECTNAME", change.getObjectName()))); }
From source file:com.gs.obevo.mongodb.impl.MongoDbChangeAuditDao.java
License:Apache License
@Override public void deleteObjectChanges(Change change) { MongoCollection<Document> auditCollection = getAuditCollection(change); auditCollection.deleteOne(Filters.eq("OBJECTNAME", change.getObjectName())); }
From source file:com.gs.obevo.mongodb.impl.MongoDbDeployExecutionDao.java
License:Apache License
private Bson getChangeFilter(DeployExecution deployExecution) { return Filters.eq(idColName, deployExecution.getId()); }
From source file:com.imaginea.mongodb.services.impl.DocumentServiceImpl.java
License:Apache License
/** * Updates a document inside a collection in a database in mongo to which user is connected to. * * @param dbName Name of Database//www .j a v a2s .co m * @param collectionName Name of Collection from which to get all Documents * @param _id Id of Document to be updated * @param newData new Document value. * @return Update status * @throws DatabaseException throw super type of UndefinedDatabaseException * @throws ValidationException throw super type of * EmptyDatabaseNameException,EmptyCollectionNameException ,EmptyDocumentDataException * @throws CollectionException throw super type of UndefinedCollectionException * @throws DocumentException throw super type of UpdateDocumentException */ public String updateDocument(String dbName, String collectionName, String _id, Document newData) throws DatabaseException, CollectionException, DocumentException, ValidationException { if (dbName == null) { throw new DatabaseException(ErrorCodes.DB_NAME_EMPTY, "Database name is null"); } if (dbName.equals("")) { throw new DatabaseException(ErrorCodes.DB_NAME_EMPTY, "Database Name Empty"); } if (collectionName == null) { throw new CollectionException(ErrorCodes.COLLECTION_NAME_EMPTY, "Collection name is null"); } if (collectionName.equals("")) { throw new CollectionException(ErrorCodes.COLLECTION_NAME_EMPTY, "Collection Name Empty"); } String result = null; try { // if (!databaseService.getDbList().contains(dbName)) { // throw new DatabaseException(ErrorCodes.DB_DOES_NOT_EXISTS, // "DB [" + dbName + "] DOES NOT EXIST"); // } if (!collectionService.getCollList(dbName).contains(collectionName)) { throw new CollectionException(ErrorCodes.COLLECTION_DOES_NOT_EXIST, "COLLECTION [ " + collectionName + "] _DOES_NOT_EXIST in Db [ " + dbName + "]"); } if (_id == null) { throw new DocumentException(ErrorCodes.DOCUMENT_EMPTY, "Document is empty"); } String newId = (String) newData.get("_id"); if (newId == null) { throw new DocumentException(ErrorCodes.INVALID_OBJECT_ID, "Object Id is invalid."); } if (newId.equals("")) { throw new DocumentException(ErrorCodes.INVALID_OBJECT_ID, "Object Id is invalid."); } ObjectId docId = new ObjectId(_id); if (!newId.equals(_id)) { throw new DocumentException(ErrorCodes.UPDATE_OBJECT_ID_EXCEPTION, "_id cannot be updated."); } MongoCollection<Document> collection = mongoInstance.getDatabase(dbName).getCollection(collectionName); Document document = collection.find(Filters.eq("_id", docId)).first(); if (document != null) { ObjectId objectId = document.getObjectId("_id"); newData.put("_id", objectId); Document updateData = new Document("$set", newData); collection.updateOne(Filters.eq("_id", objectId), updateData); } else { throw new DocumentException(ErrorCodes.DOCUMENT_DOES_NOT_EXIST, "Document does not exist !"); } } catch (IllegalArgumentException e) { // When error converting object Id throw new DocumentException(ErrorCodes.INVALID_OBJECT_ID, "Object Id is invalid."); } catch (MongoException e) { throw new DocumentException(ErrorCodes.DOCUMENT_UPDATE_EXCEPTION, e.getMessage()); } result = "Document: [" + newData + "] has been updated."; return result; }
From source file:com.maschel.lca.lcacloud.analytics.Analytics.java
License:Open Source License
public void store(AnalyticsDataMessage analyticsData) { for (AnalyticsSensorDataDTO sensorData : analyticsData.values) { String collectionName = sensorData.name + "_" + sensorData.aggregate; Bson filter = Filters.eq("device-id", analyticsData.deviceId); if (!database.getCollection(collectionName).find(filter).iterator().hasNext()) { database.getCollection(collectionName).insertOne(new Document() .append("device-id", analyticsData.deviceId).append("values", new ArrayList<Document>())); }/*from w w w . j a va 2 s. c o m*/ database.getCollection(collectionName).updateOne(filter, Updates.addToSet("values", new Document(sensorData.date, sensorData.value))); } }
From source file:com.naryx.tagfusion.cfm.cache.impl.MongoCacheImpl.java
License:Open Source License
@Override public cfData get(String id) { Document doc = col.find(Filters.eq("id", id)).first(); if (doc != null) { // Check that the date is correct Date ct = (Date) doc.get("ct"); if (ct.getTime() < System.currentTimeMillis()) { delete(id, true);//w ww .j a v a2 s . co m statsMissAge++; return null; } statsHit++; if (doc.containsKey("vs")) return new cfStringData((String) doc.get("vs")); else { Object bufObj = doc.get("vb"); byte[] buf; if (bufObj instanceof org.bson.types.Binary) { buf = ((org.bson.types.Binary) bufObj).getData(); } else { // should be byte []. Keep for backwards compatibility buf = (byte[]) bufObj; } try { return (cfData) FileUtil.loadClass(buf, true); } catch (Exception e) { cfEngine.log(getName() + " id:" + id + "; Exception: " + e); } } } else { statsMiss++; } return null; }
From source file:com.project.shlok.TopicsAnalyzer.TweetAnalytics.java
/** * getSentimentScores/*from ww w .j a va 2 s .co m*/ * Gets the count of positive and negative tweets from a database * @param String - query to be tracked * @return ArrayList<Integer> - arraylist of two integers, representing count of positive and negative tweets * */ public ArrayList<Integer> getSentimentScores(String query) { FindIterable<Document> scoreIterable = sentimentsCol.find(Filters.eq("query", query)); ArrayList<Integer> scores = new ArrayList<Integer>(); Iterator<Document> scoreIterator = scoreIterable.iterator(); if (scoreIterator.hasNext()) { Document scoreDoc = scoreIterator.next(); Integer posCount = new Integer(scoreDoc.get("posCount").toString()); Integer negCount = new Integer(scoreDoc.get("negCount").toString()); scores.add(posCount); scores.add(negCount); } return scores; }
From source file:com.project.shlok.TopicsAnalyzer.TweetAnalytics.java
/** * getPositiveSentimentKeywords/*from w ww .j ava 2 s. c om*/ * Gets positive keywords from the database * @param String - query to be tracked * @return ArrayList<HashMap<String,Integer>> - an arraylist of maps containing keywords and their respective weights * */ public ArrayList<HashMap<String, Integer>> getPositiveSentimentKeywords(String query) { ArrayList<HashMap<String, Integer>> keywordsList = new ArrayList<HashMap<String, Integer>>(); FindIterable<Document> keywordsIterable = sentimentsCol.find(Filters.eq("query", query)); Iterator<Document> keywordsIterator = keywordsIterable.iterator(); if (keywordsIterator.hasNext()) { Document keywordsDoc = keywordsIterator.next(); Document posKeyWordsDoc = (Document) keywordsDoc.get("poswords"); for (String key : posKeyWordsDoc.keySet()) { Integer count = new Integer(posKeyWordsDoc.get(key).toString()); Sentiment wordsentiment = lexicon.analyze(key); Integer weight = 0; // Performs tf-idf on the keyword and assigns weights double key_tf = 0.0; double key_idf = 0.0; double key_tfidf = 0.0; int normalized_tfidf = 0; if (count != 0 && posKeyWordsDoc.size() != 0) { key_tf = (float) count / posKeyWordsDoc.size(); key_idf = Math.log(posKeyWordsDoc.size() / count); key_tfidf = key_tf * key_idf; normalized_tfidf = (int) (key_tfidf * 100); } if (!key.equals("https") && !key.equals("http") && !key.contains("https") && !key.contains("http")) { if (normalized_tfidf > 40) { weight = normalized_tfidf; } // if tf-idf weight is not above threshold but word is informative and positive else if (wordsentiment.getScore() > 0) { weight = 40 + wordsentiment.getScore(); } else if (wordsentiment.getScore() >= 0 && positivewordslist.indexOf(key) != -1) { Random random = new Random(); weight = random.nextInt(40) + 40; } if (weight != 0) { HashMap<String, Integer> posMap = new HashMap<String, Integer>(); posMap.put(key, weight); keywordsList.add(posMap); } } } } return keywordsList; }
From source file:com.project.shlok.TopicsAnalyzer.TweetAnalytics.java
/** * getStories/* ww w . ja v a2 s .co m*/ * Gets stories from a database * @param String - query to be tracked * @return ArrayList<HashMap<String,Integer>> - an arraylist of maps containing stories and their respective counts * */ public ArrayList<HashMap<String, Integer>> getStories(String query) { ArrayList<HashMap<String, Integer>> stories = new ArrayList<HashMap<String, Integer>>(); FindIterable<Document> storyIterable = storiesCol.find(Filters.eq("query", query)); Iterator<Document> storyIterator = storyIterable.iterator(); if (storyIterator.hasNext()) { Document storyDoc = storyIterator.next(); Document storiesDoc = (Document) storyDoc.get("stories"); for (String key : storiesDoc.keySet()) { Integer count = new Integer(storiesDoc.get(key).toString()); if (count > 10) { String story = key.replace("+", " "); String[] words = story.split(" "); if (words.length > 5) { HashMap<String, Integer> storyMap = new HashMap<String, Integer>(); storyMap.put(story, count); stories.add(storyMap); } } } } return stories; }