List of usage examples for com.mongodb BasicDBObject containsField
public boolean containsField(final String field)
From source file:fr.gouv.vitam.mdbes.DAip.java
License:Open Source License
/** * //from w w w . j a v a 2 s . c o m * @param dbvitam * @param model * @return True if inserted in ES */ public boolean addEsIndex(final MongoDbAccess dbvitam, final String model) { BasicDBObject maip = (BasicDBObject) copy(); if (!maip.containsField(NBCHILD)) { maip.append(NBCHILD, nb); } return ElasticSearchAccess.addEsIndex(dbvitam, model, maip); }
From source file:gov.llnl.iscr.iris.Iris.java
License:Open Source License
/** * returns a single formatted <code>String</code> representation of unigrams within the given list of ngrams * @param ngrams/*ww w. j a v a 2 s. c om*/ * @return */ public String getUnigrams(List<BasicDBObject> ngrams) { StringBuffer unigrams = new StringBuffer(); int count = 0; for (BasicDBObject unigram : ngrams) { if (unigram.containsField("word")) { if (count == 0) { unigrams.append(unigram.get("word")); ++count; } else if (count < 4) { unigrams.append(", " + unigram.get("word")); ++count; } else break; } } return unigrams.toString(); }
From source file:it.wami.map.mongodeploy.OsmSaxHandler.java
License:Apache License
/** * * need refactoring// w w w .j a va 2s . c om * @param atts */ private void processTag(Attributes atts) { BasicDBObject obj; String key = atts.getValue(Node.Tag.K); String value = atts.getValue(Node.Tag.V); if (StringUtils.contains(key, "capacity:")) { //key.contains("capacity:")){ String[] tmp = StringUtils.split(key, ":");//key.split(":"); BasicDBObject o = new BasicDBObject(tmp[1], value); obj = new BasicDBObject("capacity", o); //entry.append(key, obj); if (entry.containsField("tags")) { BasicDBObject tags = (BasicDBObject) entry.get("tags"); if (tags.containsField("capacity") && tags.get("capacity") instanceof BasicDBObject) { ((BasicDBObject) tags.get("capacity")).append(tmp[1], value); } else { tags.append("capacity", o); } } else { entry.append(Node.TAGS, obj); } } else { key = StringUtils.replace(key, ".", "[dot]"); //key = key.replace(".", "[dot]"); obj = new BasicDBObject(key, value); if (entry.containsField(Node.TAGS)) { ((BasicDBObject) entry.get(Node.TAGS)).append(key, value); } else { entry.append(Node.TAGS, obj); } } // create the tag and save it inside the DB. saveTag(key, value); }
From source file:net.jurre.edutil.persistence.MongoDB.java
License:Open Source License
private void saveData(String data, String collectionName) { BasicDBObject dataObj = (BasicDBObject) JSON.parse(data); DBCollection collection = this.db.getCollection(collectionName); if (!dataObj.containsField("_id")) { if (dataObj.containsField("id")) dataObj.append("_id", dataObj.get("id")); }/*from ww w. j a v a 2 s . co m*/ /* BasicDBObject search = new BasicDBObject(); search.put("name", dataObj.getString("name")); DBObject lookup = collection.findOne(search); if ( lookup != null){ dataObj.append("_id", lookup.get("_id")); logger.debug("Found id adding to object"); } */ collection.save(dataObj); }
From source file:net.scran24.datastore.mongodb.MongoDbDataStore.java
License:Apache License
@Override public void setSurveyParameters(String survey_id, SurveyParameters newParameters) throws DataStoreException { DBCollection col = getSurveyStateCollection(); final BasicDBObject stateObj = new BasicDBObject(FIELD_SURVEY_ID, survey_id); switch (newParameters.state) { case NOT_INITIALISED: stateObj.append(FIELD_SURVEY_STATE, STATE_NOT_INITIALISED); break;// www. ja va 2 s . c om case SUSPENDED: stateObj.append(FIELD_SURVEY_STATE, STATE_SUSPENDED); break; case ACTIVE: stateObj.append(FIELD_SURVEY_STATE, STATE_ACTIVE); break; } stateObj.append(FIELD_START_DATE, newParameters.startDate); stateObj.append(FIELD_END_DATE, newParameters.endDate); stateObj.append(FIELD_SCHEME_NAME, newParameters.schemeName); stateObj.append(FIELD_LOCALE_ID, newParameters.locale); stateObj.append(FIELD_ALLOW_GEN_USERS, newParameters.allowGenUsers); stateObj.append(FIELD_SUSPENSION_REASON, newParameters.suspensionReason); newParameters.surveyMonkeyUrl.accept(new Option.SideEffectVisitor<String>() { @Override public void visitSome(String item) { stateObj.append(FIELD_SURVEY_MONKEY_URL, item); } @Override public void visitNone() { if (stateObj.containsField(FIELD_SURVEY_MONKEY_URL)) stateObj.removeField(FIELD_SURVEY_MONKEY_URL); } }); BasicDBObject query = new BasicDBObject(FIELD_SURVEY_ID, survey_id); try { col.update(query, stateObj, true, false); } catch (MongoException e) { throw new DataStoreException(e); } }
From source file:net.scran24.datastore.mongodb.MongoDbDataStore.java
License:Apache License
private SecureUserRecord parseUserRecord(BasicDBObject record) { String username = record.getString(FIELD_USERNAME); String passwordHashBase64 = record.getString(FIELD_PASSWORD); String passwordSaltBase64 = record.getString(FIELD_SALT); String hasher = record.getString(FIELD_HASHER); if (hasher == null) hasher = "shiro-sha256"; BasicDBList rolesList = (BasicDBList) record.get(FIELD_ROLES); Set<String> roles = new HashSet<String>(); if (rolesList != null) for (Object s : rolesList) roles.add((String) s); BasicDBList permissionsList = (BasicDBList) record.get(FIELD_PERMISSIONS); Set<String> permissions = new HashSet<String>(); if (permissionsList != null) for (Object s : permissionsList) permissions.add((String) s); HashMap<String, String> customFields = new HashMap<String, String>(); if (record.containsField(FIELD_USERDATA)) { BasicDBObject customData = (BasicDBObject) record.get(FIELD_USERDATA); for (String k : customData.keySet()) customFields.put(k, customData.getString(k)); }//from ww w . ja va2s. co m return new SecureUserRecord(username, passwordHashBase64, passwordSaltBase64, hasher, Option.none(), Option.none(), Option.none(), roles, permissions, customFields); }
From source file:org.apache.gora.mongodb.utils.BSONDecorator.java
License:Apache License
/** * Retrieve the parent of a field./* w w w. j a v a 2s . c om*/ * * @param fieldName * fully qualified name of the field * @param createIfMissing * create the intermediate fields if necessary * @return the parent of the field * @throws IllegalAccessError * if the field does not exist */ private BasicDBObject getFieldParent(String fieldName, boolean createIfMissing) { String[] fields = fieldName.split("\\."); int i = 0; BasicDBObject intermediate = (BasicDBObject) myBson; // Set intermediate parents while (i < (fields.length - 1)) { if (!intermediate.containsField(fields[i])) if (createIfMissing) intermediate.put(fields[i], new BasicDBObject()); else throw new IllegalAccessError( "The field '" + fieldName + "' does not exist: '" + fields[i] + "' is missing."); intermediate = (BasicDBObject) intermediate.get(fields[i]); i++; } return intermediate; }
From source file:org.apache.rya.mongodb.instance.MongoDetailsAdapter.java
License:Apache License
static PCJDetails.Builder toPCJDetails(final BasicDBObject dbo) { requireNonNull(dbo);//from w ww . ja v a 2s .c om // PCJ ID. final PCJDetails.Builder builder = PCJDetails.builder().setId(dbo.getString(PCJ_ID_KEY)); // PCJ Update Strategy if present. if (dbo.containsField(PCJ_UPDATE_STRAT_KEY)) { builder.setUpdateStrategy(PCJUpdateStrategy.valueOf(dbo.getString(PCJ_UPDATE_STRAT_KEY))); } // Last Update Time if present. if (dbo.containsField(PCJ_LAST_UPDATE_KEY)) { builder.setLastUpdateTime(dbo.getDate(PCJ_LAST_UPDATE_KEY)); } return builder; }
From source file:org.aw20.mongoworkbench.command.AggregateMongoCommand.java
License:Open Source License
@Override public void execute() throws Exception { MongoClient mdb = MongoFactory.getInst().getMongo(sName); if (mdb == null) throw new Exception("no server selected"); if (sDb == null) throw new Exception("no database selected"); MongoFactory.getInst().setActiveDB(sDb); DB db = mdb.getDB(sDb);//from w w w . java2 s .co m BasicDBObject cmdMap = parseMongoCommandString(db, cmd); if (!cmdMap.containsField("aggregateArg")) throw new Exception("no aggregate document"); // Execute the command Object result = db.eval(cmd, (Object[]) null); if (result == null) throw new Exception("null returned"); if (!(result instanceof BasicDBObject)) throw new Exception("not correct type returned: " + result.getClass().getName()); BasicDBObject dbo = (BasicDBObject) result; if (dbo.containsField("result")) { dbListResult = (BasicDBList) dbo.get("result"); setMessage("# rows=" + dbListResult.size()); } else { setMessage("# rows=0"); } }
From source file:org.aw20.mongoworkbench.command.GroupMongoCommand.java
License:Open Source License
@Override public void execute() throws Exception { MongoClient mdb = MongoFactory.getInst().getMongo(sName); if (mdb == null) throw new Exception("no server selected"); if (sDb == null) throw new Exception("no database selected"); MongoFactory.getInst().setActiveDB(sDb); DB db = mdb.getDB(sDb);//from w ww . j av a 2s. c o m BasicDBObject cmdMap = parseMongoCommandString(db, cmd); if (!cmdMap.containsField("groupArg")) throw new Exception("no group document"); // Execute the command Object result = db.eval(cmd, (Object[]) null); if (result == null) throw new Exception("null returned"); if (!(result instanceof BasicDBList)) throw new Exception("not correct type returned: " + result.getClass().getName()); dbListResult = (BasicDBList) result; setMessage("# rows=" + dbListResult.size()); }