Refine search
final BasicDBList and = new BasicDBList(); final BasicDBObject container = new BasicDBObject(); child.addTo(container); and.add(container); obj.put("$and", and); } else { final BasicDBList or = new BasicDBList(); final BasicDBObject container = new BasicDBObject(); child.addTo(container); or.add(container); obj.put("$or", or);
@Override public long totalExtractorCount() { final DBObject query = new BasicDBObject(InputImpl.EMBEDDED_EXTRACTORS, new BasicDBObject("$exists", true)); long extractorsCount = 0; try (DBCursor inputs = dbCollection.find(query, new BasicDBObject(InputImpl.EMBEDDED_EXTRACTORS, 1))) { for (DBObject input : inputs) { final BasicDBList extractors = (BasicDBList) input.get(InputImpl.EMBEDDED_EXTRACTORS); extractorsCount += extractors.size(); } } return extractorsCount; }
/** * Copies this instance into a new Object. * * @return a new BasicDBList with the same values as this instance */ public Object copy() { // copy field values into new object BasicDBList newobj = new BasicDBList(); // need to clone the sub obj for (int i = 0; i < size(); ++i) { Object val = get(i); if (val instanceof BasicDBObject) { val = ((BasicDBObject) val).copy(); } else if (val instanceof BasicDBList) { val = ((BasicDBList) val).copy(); } newobj.add(val); } return newobj; }
/** * Creates a DBObject from this Point * * @return the DBObject */ public DBObject toDBObject() { final BasicDBList list = new BasicDBList(); list.add(longitude); list.add(latitude); return list; } }
BasicDBList dbl = new BasicDBList(); dbl.add(new BasicDBObject("NNP",0)); dbl.add(new BasicDBObject("NN", 1)); BasicDBOBject outer=new BasicDBObject("image", "cab").append("tags", dbl);
@Override public int countStepStartTimes(final String stepName, final long jobInstanceId) { final DBObject keys = new BasicDBObject(TableColumns.JOBEXECUTIONID, 1); keys.put(TableColumns._id, 0); final DBCursor cursor = db.getCollection(TableColumns.JOB_EXECUTION).find( new BasicDBObject(TableColumns.JOBINSTANCEID, jobInstanceId), keys); final BasicDBList basicDBList = new BasicDBList(); while (cursor.hasNext()) { final DBObject next = cursor.next(); basicDBList.add(next.get(TableColumns.JOBEXECUTIONID)); } final DBObject inClause = new BasicDBObject("$in", basicDBList); final DBObject query = new BasicDBObject(TableColumns.JOBEXECUTIONID, inClause); query.put(TableColumns.STEPNAME, stepName); return db.getCollection(TableColumns.STEP_EXECUTION).find(query).count(); }
@Override public StepExecutionImpl findOriginalStepExecutionForRestart(final String stepName, final JobExecutionImpl jobExecutionToRestart, final ClassLoader classLoader) { final StepExecutionImpl result = super.findOriginalStepExecutionForRestart(stepName, jobExecutionToRestart, classLoader); if (result != null) { return result; } final DBObject keys = new BasicDBObject(TableColumns.JOBEXECUTIONID, 1); keys.put(TableColumns._id, 0); final DBCursor cursor = db.getCollection(TableColumns.JOB_EXECUTION).find( new BasicDBObject(TableColumns.JOBINSTANCEID, jobExecutionToRestart.getJobInstance().getInstanceId()), keys); final BasicDBList basicDBList = new BasicDBList(); while (cursor.hasNext()) { final DBObject next = cursor.next(); basicDBList.add(next.get(TableColumns.JOBEXECUTIONID)); } final DBObject inClause = new BasicDBObject("$in", basicDBList); final DBObject query = new BasicDBObject(TableColumns.JOBEXECUTIONID, inClause); query.put(TableColumns.STEPNAME, stepName); final DBCursor cursor1 = db.getCollection(TableColumns.STEP_EXECUTION).find(query).sort( new BasicDBObject(TableColumns.STEPEXECUTIONID, -1)); return createStepExecutionFromDBObject(cursor1.one(), classLoader); }
@Override public void update(KeycloakSession session) { DBCollection realms = db.getCollection("realms"); DBCursor cursor = realms.find(); while (cursor.hasNext()) { BasicDBObject realm = (BasicDBObject) cursor.next(); String realmId = realm.getString("_id"); String privateKeyPem = realm.getString("privateKeyPem"); String certificatePem = realm.getString("certificatePem"); BasicDBList entities = (BasicDBList) realm.get("componentEntities"); component.put("config", config); entities.add(component); realm.remove("privateKeyPem"); realm.remove("codeSecret"); realms.update(new BasicDBObject().append("_id", realmId), realm);
private void addNewAdminRolesToMasterRealm(BasicDBObject adminRealm) { DBCollection realms = db.getCollection("realms"); DBCollection applications = db.getCollection("applications"); DBCollection roles = db.getCollection("roles"); DBCursor realmsCursor = realms.find(); try { while (realmsCursor.hasNext()) { BasicDBObject currentRealm = (BasicDBObject) realmsCursor.next(); String masterAdminAppName = currentRealm.getString("name") + "-realm"; BasicDBObject masterAdminApp = (BasicDBObject) applications.findOne(new BasicDBObject().append("realmId", adminRealm.get("_id")).append("name", masterAdminAppName)); String viewIdProvidersRoleId = insertApplicationRole(roles, AdminRoles.VIEW_IDENTITY_PROVIDERS, masterAdminApp.getString("_id")); String manageIdProvidersRoleId = insertApplicationRole(roles, AdminRoles.MANAGE_IDENTITY_PROVIDERS, masterAdminApp.getString("_id")); BasicDBObject adminRole = (BasicDBObject) roles.findOne(new BasicDBObject().append("realmId", adminRealm.get("_id")).append("name", AdminRoles.ADMIN)); BasicDBList adminCompositeRoles = (BasicDBList) adminRole.get("compositeRoleIds"); adminCompositeRoles.add(viewIdProvidersRoleId); adminCompositeRoles.add(manageIdProvidersRoleId); roles.save(adminRole); log.debugv("Added roles {0} and {1} to application {2}", AdminRoles.VIEW_IDENTITY_PROVIDERS, AdminRoles.MANAGE_IDENTITY_PROVIDERS, masterAdminAppName); } } finally { realmsCursor.close(); } }
private void convertSocialToIdFedUsers() { DBCollection users = db.getCollection("users"); DBCursor usersCursor = users.find(); while (usersCursor.hasNext()) { BasicDBObject user = (BasicDBObject) usersCursor.next(); BasicDBList socialLinks = (BasicDBList) user.get("socialLinks"); if (socialLinks != null) { BasicDBList federatedIdentities = (BasicDBList) user.get("federatedIdentities"); if (federatedIdentities == null) { federatedIdentities = new BasicDBList(); user.put("federatedIdentities", federatedIdentities); idFedLink.put("identityProvider", socialLink.get("socialProvider")); federatedIdentities.add(idFedLink); user.remove("socialLinks"); users.save(user); usersCursor.close();
@Override public void update(KeycloakSession session) { BasicDBList orArgs = new BasicDBList(); orArgs.add(new BasicDBObject("type", UserCredentialModel.PASSWORD)); orArgs.add(new BasicDBObject("type", UserCredentialModel.PASSWORD_HISTORY)); BasicDBObject elemMatch = new BasicDBObject("$or", orArgs); elemMatch.put("algorithm", HmacOTP.HMAC_SHA1); BasicDBObject query = new BasicDBObject("credentials", new BasicDBObject("$elemMatch", elemMatch)); BasicDBObject update = new BasicDBObject("$set", new BasicDBObject("credentials.$.algorithm", Pbkdf2PasswordHashProvider.ID)); DBCollection users = db.getCollection("users"); // Not sure how to do in single query int countModified = 1; while (countModified > 0) { WriteResult wr = users.update(query, update, false, true); countModified = wr.getN(); log.debugf("%d credentials modified in current iteration during upgrade to 1.8", countModified); } } }
BasicDBList modifiedList = new BasicDBList(); for (Object value : dbList) { if (value instanceof DBObject) { modifiedList.add(encodeReservedCharacteres((DBObject) value)); } else { modifiedList.add(value); Set<String> keySet = profileBody.keySet(); DBObject modifiedNode = new BasicDBObject(); if (keySet != null) { for (String key : keySet) { Object value = profileBody.get(key); for (char symbolToReplace : RESERVED_CHARACTERS.keySet()) { key = key.replace(symbolToReplace, RESERVED_CHARACTERS.get(symbolToReplace)); modifiedNode.put(key, encodeReservedCharacteres((DBObject) value)); } else { modifiedNode.put(key, value);
public String getFilename(String key) { DBCursor cur = audit.find(new BasicDBObject().append("auditorComments.filepath", "NewAudit6269242818132644222/withoutJS.txt")); String test = null; while (cur.hasNext()) { BasicDBObject current_object = (BasicDBObject) cur.next(); BasicDBList auditorComments = (BasicDBList) current_object.get("auditorComments"); test = ((BasicDBObject) auditorComments.get(0)).getString("filename"); System.out.println(test); } return test; }
private void updateUserAttributes() { DBCollection users = db.getCollection("users"); DBCursor usersCursor = users.find(); try { while (usersCursor.hasNext()) { BasicDBObject user = (BasicDBObject) usersCursor.next(); BasicDBObject attributes = (BasicDBObject) user.get("attributes"); if (attributes != null) { for (Map.Entry<String, Object> attr : new HashSet<>(attributes.entrySet())) { String attrName = attr.getKey(); Object attrValue = attr.getValue(); if (attrValue != null && attrValue instanceof String) { BasicDBList asList = new BasicDBList(); asList.add(attrValue); attributes.put(attrName, asList); } } user.put("attributes", attributes); users.save(user); } } } finally { usersCursor.close(); } } }
DB db = mongoClient.getDB("test"); DBCollection coll = db.getCollection("restaurants"); BasicDBObject query = new BasicDBObject(); query.put("cuisine", "Chinese"); DBCursor cursor = coll.find(query); //coordinates for box of defined range around my location. double lat1 = myPoint.closestPoints(1)[0]; double lat2 = myPoint.closestPoints(1)[1]; double lon1 = myPoint.closestPoints(1)[2]; double lon2 = myPoint.closestPoints(1)[3]; try { while(cursor.hasNext()) { BasicBSONObject addressObj = (BasicBSONObject) cursor.next().get("address"); BasicDBList addressList = (BasicDBList) addressObj.get("coord"); double restLongitude = (double) addressList.get(0); double restLatitude = (double) addressList.get(1); if ((restLatitude < lat2 && restLatitude > lat1) && (restLongitude < lon2 && restLongitude > lon1)) { System.out.println(restLatitude + "," + restLongitude + " box LAT is " + lat1 + ", " + lat2 + " box LON is " + lon1 + "," + lon2 ); } } } catch (NullPointerException e) { System.err.println("NullPointerException: " + e.getMessage()); } finally { cursor.close(); } mongoClient.close();
MongoClient mongoClient = new MongoClient("SERVER", 27017); DB db = mongoClient.getDB("DB_NAME"); DBCollection coll1 = db.getCollection("COLLECTION_NAME"); DBObject eleMatch = new BasicDBObject(); eleMatch.put("url", "www.pqr.com"); eleMatch.put("type", new BasicDBObject("$lte", 50)); BasicDBObject up = new BasicDBObject(); up.put("$elemMatch", eleMatch); BasicDBList basicDBList = new BasicDBList(); basicDBList.add(up); DBObject query = new BasicDBObject("Data", new BasicDBObject(" $all", basicDBList)); coll1.find(query);
MongoClient mongoClient = new MongoClient("localhost", 27017); DB db = mongoClient.getDB("StackOverflow"); DBCollection dbcol = db.getCollection("features"); DBCursor cursor = dbcol.find(); while (cursor.hasNext()) { DBObject Features = cursor.next(); BasicDBList features = (BasicDBList) Features.get("features"); BasicDBObject[] featuresArr = features.toArray(new BasicDBObject[0]); BasicDBObject geometry = (BasicDBObject) dbobj.get("geometry"); BasicDBList coordinates = (BasicDBList) geometry.get("coordinates"); // BasicDBList contains coordinates System.out.println(coordinates.get(0)); cursor.close();
List<Student> students = new ArrayList<Student>(); BasicDBObject query = new BasicDBObject(); query.put("user", username); DBCursor cursor = theCollection.find(query); while (cursor.hasNext()) { DBObject theObj = cursor.next(); //How to get the DBObject value to ArrayList of Java Object? BasicDBList studentsList = (BasicDBList) theObj.get("students"); for (int i = 0; i < studentsList.size(); i++) { BasicDBObject studentObj = (BasicDBObject) studentsList.get(i); String firstName = studentObj.getString("firstName"); String lastName = studentObj.getString("lastName"); String age = studentObj.getString("age"); String gender = studentObj.getString("gender"); Student student = new Student(); student.setFirstName(firstName); student.setLastName(lastName); student.setAge(age); student.setGender(gender); students.add(student); } }
private void addNewAdminRolesToRealm(BasicDBObject currentRealm) { DBCollection applications = db.getCollection("applications"); DBCollection roles = db.getCollection("roles"); BasicDBObject adminApp = (BasicDBObject) applications.findOne(new BasicDBObject().append("realmId", currentRealm.get("_id")).append("name", "realm-management")); String viewIdProvidersRoleId = insertApplicationRole(roles, AdminRoles.VIEW_IDENTITY_PROVIDERS, adminApp.getString("_id")); String manageIdProvidersRoleId = insertApplicationRole(roles, AdminRoles.MANAGE_IDENTITY_PROVIDERS, adminApp.getString("_id")); BasicDBObject adminRole = (BasicDBObject) roles.findOne(new BasicDBObject().append("applicationId", adminApp.get("_id")).append("name", AdminRoles.REALM_ADMIN)); BasicDBList adminCompositeRoles = (BasicDBList) adminRole.get("compositeRoleIds"); adminCompositeRoles.add(viewIdProvidersRoleId); adminCompositeRoles.add(manageIdProvidersRoleId); roles.save(adminRole); log.debugv("Added roles {0} and {1} to application realm-management of realm {2}", AdminRoles.VIEW_IDENTITY_PROVIDERS, AdminRoles.MANAGE_IDENTITY_PROVIDERS, currentRealm.get("name")); }