List of usage examples for com.mongodb BasicDBObject putAll
@SuppressWarnings("unchecked") @Override public void putAll(final Map m)
From source file:ch.bfh.uniboard.persistence.mongodb.PersistedPost.java
License:GNU General Public License
/** * Method allowing to convert the current PersistedPost to the format supported by the database * @return a DBObject format of the PersistedPost *///from w w w. ja v a 2 s . com public BasicDBObject toDBObject() { BasicDBObject doc = new BasicDBObject(); //Save raw message doc.put("message", Base64.encode(message)); //Check if message is a JSON message DBObject jsonMessageContent = null; try { jsonMessageContent = (DBObject) JSON.parse(new String(message, "UTF-8")); } catch (JSONParseException | UnsupportedEncodingException ex) { Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Message is not a JSON string {0}", ex.getMessage()); } if (jsonMessageContent != null) { //save message as JSON content DBObject jsonMessage = new BasicDBObject("searchable-message", jsonMessageContent); doc.putAll(jsonMessage); } //Prepares the Alpha attributes BasicDBObject alphaList = new BasicDBObject(); for (Entry<String, Value> entry : alpha.getEntries()) { alphaList.put(entry.getKey(), entry.getValue().getValue()); } doc.put("alpha", alphaList); //Prepares the Beta attributes BasicDBObject betaList = new BasicDBObject(); for (Entry<String, Value> entry : beta.getEntries()) { betaList.put(entry.getKey(), entry.getValue().getValue()); } doc.put("beta", betaList); return doc; }
From source file:com.affairs.dao.zaffar.CurrentAffairsDAO.java
License:Apache License
public boolean upsertSayDoProject(String username, Map whereConditionMap, Map updateConditionMap) { boolean upsertSuccess = true; BasicDBObject whereConditionObj = new BasicDBObject(whereConditionMap); BasicDBObject updateConditionObj = new BasicDBObject(updateConditionMap); BasicDBObject updateCurrentObj = new BasicDBObject("isCurrent", false); updateCurrentObj.append("updatedBy", username); updateCurrentObj.append("updatedDate", new Date()); BasicDBObject currentProjectObj = (BasicDBObject) findOneObjectByCondition(whereConditionObj); WriteResult updateResult = null;//from w w w. j a va2 s. c o m try { updateResult = this.saydoCollection.update(whereConditionObj, new BasicDBObject("$set", updateCurrentObj)); } catch (Exception exp) { System.out.println(exp.getMessage()); } if (updateResult.getLastError() != null) { System.out.println("Update did not happen properly"); upsertSuccess = false; } else { currentProjectObj.putAll(updateConditionMap); upsertSuccess = addSayDoProject(username, currentProjectObj); } return upsertSuccess; }
From source file:com.ccoe.build.alerts.connector.Connector.java
License:Apache License
public static DBObject getLastRecord(DBCollection collection, Date startDate, Date endDate) { DBObject lastone = null;// w w w . ja v a 2s.c om try { BasicDBObject searchQuery = new BasicDBObject(); QueryBuilder qb = new QueryBuilder(); qb.put("Date").greaterThanEquals(startDate).lessThanEquals(endDate); searchQuery.putAll(qb.get()); DBCursor cursor = collection.find(searchQuery); while (cursor.hasNext()) { lastone = cursor.next(); } } catch (MongoException e) { e.printStackTrace(); } return lastone; }
From source file:com.ccoe.build.alerts.connector.Connector.java
License:Apache License
public static double getMovingAverage(DBCollection collection, String field, Date startDate, Date endDate) { double weekSum = 0; DBObject record = null;/*ww w . j a v a 2 s . c o m*/ int count = 0; try { BasicDBObject searchQuery = new BasicDBObject(); QueryBuilder qb = new QueryBuilder(); qb.put("Date").greaterThanEquals(startDate).lessThanEquals(endDate); searchQuery.putAll(qb.get()); DBCursor cursor = collection.find(searchQuery); while (cursor.hasNext()) { record = cursor.next(); DBObject dbo = (DBObject) record.get("Data"); Set<String> keySet = dbo.keySet(); for (String keyName : keySet) { if (field.equals(keyName)) { count++; Object keyValue = dbo.get(keyName); double keyValueNum = 0; if (keyValue instanceof Integer) { int intValue = (Integer) keyValue; keyValueNum = Double.parseDouble("" + intValue); } else if (keyValue instanceof Double) { keyValueNum = (Double) keyValue; } weekSum += keyValueNum; } } } } catch (MongoException e) { e.printStackTrace(); } DAYS = count; return weekSum * 1.0 / count; }
From source file:com.edgytech.umongo.ReplSetPanel.java
License:Apache License
public void queryOplog(ButtonBase button) { final DBCollection oplog = getReplSetNode().getMongoClient().getDB("local").getCollection("oplog.rs"); DBObject start = ((DocBuilderField) getBoundUnit(Item.qoStart)).getDBObject(); DBObject end = ((DocBuilderField) getBoundUnit(Item.qoEnd)).getDBObject(); DBObject extra = ((DocBuilderField) getBoundUnit(Item.qoQuery)).getDBObject(); BasicDBObject query = new BasicDBObject(); BasicDBObject range = new BasicDBObject(); if (start != null) range.put("$gte", start.get("ts")); if (end != null) range.put("$lte", end.get("ts")); query.put("ts", range); if (extra != null) query.putAll(extra); CollectionPanel.doFind(oplog, query, null, null, 0, 0, 0, false, null, Bytes.QUERYOPTION_OPLOGREPLAY); }
From source file:com.edgytech.umongo.ServerPanel.java
License:Apache License
public void setParameter(ButtonBase button) { BasicDBObject cmd = new BasicDBObject("setParameter", 1); DBObject param = ((DocBuilderField) getBoundUnit(Item.setParameterValue)).getDBObject(); cmd.putAll(param); new DbJobCmd(getServerNode().getServerMongoClient().getDB("admin"), cmd).addJob(); }
From source file:com.groupon.jenkins.dynamic.build.repository.DynamicBuildRepository.java
License:Open Source License
public DbBackedBuild getPreviousFinishedBuildOfSameBranch(DbBackedBuild build, String branch) { BasicDBObject query = getQuery((DbBackedProject) build.getProject()); query.append("branch", branch); query.append("state", "COMPLETED"); query.putAll(QueryBuilder.start("number").lessThan(build.getNumber()).get()); return findOne(query, null, new BasicDBObject("number", -1), getTransformer((DbBackedProject) build.getProject())); }
From source file:com.hangum.tadpole.mongodb.core.test.MongoTestReferenceCollection.java
License:Open Source License
public static void createRef1Collection(DB db, Object objId) { DBObject colInformation = (DBObject) JSON.parse("{capped:true, size:100000}"); DBCollection ref2Coll = db.getCollection(REF_2); if (ref2Coll != null) ref2Coll.drop();// www . j av a 2s .c om ref2Coll = db.createCollection(REF_2, colInformation); BasicDBObject insertObj = new BasicDBObject(); insertObj.put(REF_1 + "_id", objId); DBObject addField = new BasicDBObject(); addField.put("name", "Reference id"); insertObj.putAll(addField); // DBObject dbObjRef2 = (DBObject) JSON.parse("{'ref1_id': 50f9437cf023f820730a3b42, {'names': {'First': 'Gonza', 'Last': 'Vieira'}}}"); ref2Coll.insert(insertObj); }
From source file:com.ikanow.infinit.e.utility.MongoAssociationFeatureTxfer.java
License:Apache License
private void doChunkedTransfer(BasicDBObject query, int nSkip, int nLimit, String chunksDescription) throws IOException { List<BasicDBObject> chunkList = MongoIndexerUtils.getChunks("feature.association", chunksDescription); System.out.println("CHUNKS: Found " + chunkList.size() + " chunks"); //DEBUG/*from w w w . j av a 2s.c o m*/ //System.out.println("Chunklist= " + chunkList); for (BasicDBObject chunk : chunkList) { BasicDBObject cleanQuery = new BasicDBObject(); cleanQuery.putAll((BSONObject) query); String id = null; try { id = (String) chunk.remove("$id"); System.out.println("CHUNK: " + id); doTransfer(cleanQuery, 0, 0, chunk); } catch (Exception e) { System.out.println("FAILED CHUNK: " + id + " ... " + e.getMessage()); } } }
From source file:com.ikanow.infinit.e.utility.MongoDocumentTxfer.java
License:Apache License
private void doChunkedTransfer(BasicDBObject query, int nSkip, int nLimit, boolean bAggregate, String chunksDescription) throws IOException { List<BasicDBObject> chunkList = MongoIndexerUtils.getChunks("doc_metadata.metadata", chunksDescription); System.out.println("CHUNKS: Found " + chunkList.size() + " chunks"); //DEBUG/*from www . ja v a 2 s . c o m*/ //System.out.println("Chunklist= " + chunkList); for (BasicDBObject chunk : chunkList) { BasicDBObject cleanQuery = new BasicDBObject(); cleanQuery.putAll((BSONObject) query); String id = null; try { id = (String) chunk.remove("$id"); System.out.println("CHUNK: " + id); doTransfer(cleanQuery, 0, 0, bAggregate, chunk); } catch (Exception e) { System.out.println("FAILED CHUNK: " + id + " ... " + e.getMessage()); } } }