List of usage examples for com.mongodb BasicDBObject getString
public String getString(final String key)
From source file:no.nlf.avvik.melwinSOAPconnection.MongoOperations.java
/** * /* ww w . j av a 2 s.c om*/ * @param parachutistsFromMelwin */ public ArrayList<Parachutist> getParachutistsFromDB() { // HjelpeLister ArrayList<Club> clubs = getClubsFromDb(); ArrayList<License> licenses = getLicensesFromDb(); ArrayList<Parachutist> parachutistsInMongoDB = new ArrayList<>(); DBCollection dbCollectionParachutists = db.getCollection("jumpers"); DBCursor cursor = dbCollectionParachutists.find(); BasicDBObject mongoObject = new BasicDBObject(); try { int hoppteller = 0; while (cursor.hasNext()) { mongoObject = (BasicDBObject) cursor.next(); hoppteller++; ArrayList<Club> memberClubs = new ArrayList<>(); ArrayList<License> memberLicenses = new ArrayList<>(); BasicDBList referenceClubs = (BasicDBList) mongoObject.get("memberclubs"); BasicDBList referenceLicenses = (BasicDBList) mongoObject.get("licenses"); for (Object clubReference : referenceClubs) { for (Club club : clubs) { if ((int) clubReference == club.getId()) { memberClubs.add(club); } } } for (Object licenseReference : referenceLicenses) { for (License license : licenses) { if ((int) licenseReference == license.getId()) { memberLicenses.add(license); } } } Parachutist parachutist = new Parachutist(mongoObject.getObjectId("_id"), mongoObject.getInt("id"), mongoObject.getString("melwinId"), null, // nakKey new ArrayList<Club>(), // clubs new ArrayList<License>(), // licenses mongoObject.getString("firstname"), mongoObject.getString("lastname"), mongoObject.getDate("birthdate"), mongoObject.getString("gender"), mongoObject.getString("street"), mongoObject.getString("postnumber"), mongoObject.getString("postplace"), mongoObject.getString("mail"), mongoObject.getString("phone"), mongoObject.getString("password")); parachutist.setMemberclubs(memberClubs); parachutist.setLicenses(memberLicenses); parachutistsInMongoDB.add(parachutist); } } finally { cursor.close(); } return parachutistsInMongoDB; }
From source file:org.apache.gora.mongodb.utils.BSONDecorator.java
License:Apache License
/** * Access field as a Utf8 string./*from w w w . j ava2s. c om*/ * * @param fieldName * fully qualified name of the field to be accessed * @return value of the field as a {@link Utf8} string */ public Utf8 getUtf8String(String fieldName) { BasicDBObject parent = getFieldParent(fieldName); String value = parent.getString(getLeafName(fieldName)); return (value != null) ? new Utf8(value) : null; }
From source file:org.apache.rya.mongodb.instance.MongoDetailsAdapter.java
License:Apache License
public static RyaDetails toRyaDetails(final DBObject mongoObj) throws MalformedRyaDetailsException { final BasicDBObject basicObj = (BasicDBObject) mongoObj; try {// ww w . j a va 2s . c om return RyaDetails.builder().setRyaInstanceName(basicObj.getString(INSTANCE_KEY)) .setRyaVersion(basicObj.getString(VERSION_KEY)) .setEntityCentricIndexDetails( new EntityCentricIndexDetails(basicObj.getBoolean(ENTITY_DETAILS_KEY))) //RYA-215 .setGeoIndexDetails(new GeoIndexDetails(basicObj.getBoolean(GEO_DETAILS_KEY))) .setPCJIndexDetails(getPCJIndexDetails(basicObj)) .setTemporalIndexDetails(new TemporalIndexDetails(basicObj.getBoolean(TEMPORAL_DETAILS_KEY))) .setFreeTextDetails(new FreeTextIndexDetails(basicObj.getBoolean(FREETEXT_DETAILS_KEY))) .setProspectorDetails(new ProspectorDetails( Optional.<Date>fromNullable(basicObj.getDate(PROSPECTOR_DETAILS_KEY)))) .setJoinSelectivityDetails(new JoinSelectivityDetails( Optional.<Date>fromNullable(basicObj.getDate(JOIN_SELECTIVITY_DETAILS_KEY)))) .build(); } catch (final Exception e) { throw new MalformedRyaDetailsException("Failed to make RyaDetail from Mongo Object, it is malformed.", e); } }
From source file:org.apache.rya.mongodb.instance.MongoDetailsAdapter.java
License:Apache License
private static PCJIndexDetails.Builder getPCJIndexDetails(final BasicDBObject basicObj) { final BasicDBObject pcjIndexDBO = (BasicDBObject) basicObj.get(PCJ_DETAILS_KEY); final PCJIndexDetails.Builder pcjBuilder = PCJIndexDetails.builder() .setEnabled(pcjIndexDBO.getBoolean(PCJ_ENABLED_KEY)) .setFluoDetails(new FluoDetails(pcjIndexDBO.getString(PCJ_FLUO_KEY))); final BasicDBList pcjs = (BasicDBList) pcjIndexDBO.get(PCJ_PCJS_KEY); if (pcjs != null) { for (int ii = 0; ii < pcjs.size(); ii++) { final BasicDBObject pcj = (BasicDBObject) pcjs.get(ii); pcjBuilder.addPCJDetails(toPCJDetails(pcj)); }//from w w w .j a v a 2s. c o m } return pcjBuilder; }
From source file:org.apache.rya.mongodb.instance.MongoDetailsAdapter.java
License:Apache License
static PCJDetails.Builder toPCJDetails(final BasicDBObject dbo) { requireNonNull(dbo);//from w w w . jav a 2 s .c o m // 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.graylog2.system.stats.mongo.MongoProbe.java
License:Open Source License
private HostInfo createHostInfo() { final HostInfo hostInfo; final CommandResult hostInfoResult = adminDb.command("hostInfo"); if (hostInfoResult.ok()) { final BasicDBObject systemMap = (BasicDBObject) hostInfoResult.get("system"); final HostInfo.System system = HostInfo.System.create(new DateTime(systemMap.getDate("currentTime")), systemMap.getString("hostname"), systemMap.getInt("cpuAddrSize"), systemMap.getLong("memSizeMB"), systemMap.getInt("numCores"), systemMap.getString("cpuArch"), systemMap.getBoolean("numaEnabled")); final BasicDBObject osMap = (BasicDBObject) hostInfoResult.get("os"); final HostInfo.Os os = HostInfo.Os.create(osMap.getString("type"), osMap.getString("name"), osMap.getString("version")); final BasicDBObject extraMap = (BasicDBObject) hostInfoResult.get("extra"); final HostInfo.Extra extra = HostInfo.Extra.create(extraMap.getString("versionString"), extraMap.getString("libcVersion"), extraMap.getString("kernelVersion"), extraMap.getString("cpuFrequencyMHz"), extraMap.getString("cpuFeatures"), extraMap.getString("scheduler"), extraMap.getLong("pageSize", -1l), extraMap.getLong("numPages", -1l), extraMap.getLong("maxOpenFiles", -1l)); hostInfo = HostInfo.create(system, os, extra); } else {/* w ww . j a v a 2s . c om*/ hostInfo = null; } return hostInfo; }
From source file:org.jivesoftware.openfire.roster.DefaultRosterItemProvider.java
License:Open Source License
public Iterator<RosterItem> getItems(String username) { LinkedList<RosterItem> itemList = new LinkedList<RosterItem>(); try {/*from www. j a v a2s. c om*/ init(); DBCollection coll = db.getCollection("gUser"); BasicDBObject doc = new BasicDBObject("friends", 1); BasicDBObject q = new BasicDBObject("himId", username); DBCursor res = coll.find(q, doc); Iterator<DBObject> iter = res.iterator(); while (iter.hasNext()) { BasicDBList o = (BasicDBList) iter.next().get("friends"); for (int i = 0; i < o.size(); i++) { BasicDBObject dbo = (BasicDBObject) o.get(i); // information // SELECT jid, rosterID, sub, ask, recv, nick,version FROM // ofRoster WHERE username=? RosterItem item = new RosterItem(i + 1, new JID(dbo.getString("jid")), RosterItem.SubType.getTypeFromInt(dbo.getInt("sub")), RosterItem.AskType.getTypeFromInt(dbo.getInt("ask")), RosterItem.RecvType.getTypeFromInt(dbo.getInt("recv")), dbo.getString("name"), null); item.setCurrVersion(dbo.getLong("ver")); // Add the loaded RosterItem (ie. user contact) to the // result itemList.add(item); } System.out.println("sdsd"); } } catch (Exception e) { Log.warn("Error trying to get rows in ofRoster", e); } return itemList.iterator(); }
From source file:org.jivesoftware.openfire.vcard.DefaultVCardProvider.java
License:Open Source License
public Element loadVCard(String username) { synchronized (username.intern()) { if (db == null) { db = MongoDbConnectionManager.reconnect(); }/*www.ja va2 s . c o m*/ if (db == null) return null; Element vCardElement = null; SAXReader xmlReader = null; try { DBCollection coll = db.getCollection("gUser"); BasicDBObject doc = new BasicDBObject("photoId", 1).append("vcard", 1); BasicDBObject q = new BasicDBObject("himId", username); DBObject res = coll.findOne(q, doc); if (res != null) { BasicDBObject photo = (BasicDBObject) res.get("photoId"); BasicDBObject vcardXml = (BasicDBObject) res.get("vcard"); if (vcardXml != null) { vCardElement = new DOMElement("vCard", new Namespace(null, "vcard-temp-ext")); String url = (String) vcardXml.getString("url"); Element urlE = new DOMElement("url"); Element type = new DOMElement("type"); type.setText((String) vcardXml.getString("type")); urlE.setText(url); vCardElement.add(urlE); } else if (photo != null) { Element photoEl = new DOMElement("PHOTO"); Element bin = new DOMElement("BINVAL"); Element type = new DOMElement("type"); vCardElement = new DOMElement("vCard", new Namespace(null, "vcard-temp")); String url = (String) photo.getString("url"); type.setText(photo.getString("contentType")); HttpClient client = new HttpClient(); GetMethod method = new GetMethod(url); client.executeMethod(method); if (method.getStatusCode() == HttpStatus.SC_OK) { InputStream ios = method.getResponseBodyAsStream(); byte[] data = new byte[2048]; int len = 0; StringBuilder builder = new StringBuilder(); while ((len = ios.read(data)) != -1) { builder.append(Base64.encodeBytes(data, 0, len, Base64.NO_OPTIONS)); } bin.setText(builder.toString()); ios.close(); } photoEl.add(type); photoEl.add(bin); vCardElement.add(photoEl); } } } catch (Exception e) { Log.error("Error loading vCard of username: " + username, e); } finally { } return vCardElement; } }
From source file:org.keycloak.connections.mongo.updater.impl.updates.AbstractMigrateUserFedToComponent.java
License:Apache License
public void portUserFedToComponent(String providerId) { DBCollection realms = db.getCollection("realms"); DBCursor cursor = realms.find();/*from ww w.ja va 2 s. c o m*/ while (cursor.hasNext()) { BasicDBObject realm = (BasicDBObject) cursor.next(); String realmId = realm.getString("_id"); Set<String> removedProviders = new HashSet<>(); BasicDBList componentEntities = (BasicDBList) realm.get("componentEntities"); BasicDBList federationProviders = (BasicDBList) realm.get("userFederationProviders"); for (Object obj : federationProviders) { BasicDBObject fedProvider = (BasicDBObject) obj; if (fedProvider.getString("providerName").equals(providerId)) { String id = fedProvider.getString("id"); removedProviders.add(id); int priority = fedProvider.getInt("priority"); String displayName = fedProvider.getString("displayName"); int fullSyncPeriod = fedProvider.getInt("fullSyncPeriod"); int changedSyncPeriod = fedProvider.getInt("changedSyncPeriod"); int lastSync = fedProvider.getInt("lastSync"); BasicDBObject component = new BasicDBObject(); component.put("id", id); component.put("name", displayName); component.put("providerType", UserStorageProvider.class.getName()); component.put("providerId", providerId); component.put("parentId", realmId); BasicDBObject config = new BasicDBObject(); config.put("priority", Collections.singletonList(Integer.toString(priority))); config.put("fullSyncPeriod", Collections.singletonList(Integer.toString(fullSyncPeriod))); config.put("changedSyncPeriod", Collections.singletonList(Integer.toString(changedSyncPeriod))); config.put("lastSync", Collections.singletonList(Integer.toString(lastSync))); BasicDBObject fedConfig = (BasicDBObject) fedProvider.get("config"); if (fedConfig != null) { for (Map.Entry<String, Object> attr : new HashSet<>(fedConfig.entrySet())) { String attrName = attr.getKey(); String attrValue = attr.getValue().toString(); config.put(attrName, Collections.singletonList(attrValue)); } } component.put("config", config); componentEntities.add(component); } } Iterator<Object> it = federationProviders.iterator(); while (it.hasNext()) { BasicDBObject fedProvider = (BasicDBObject) it.next(); String id = fedProvider.getString("id"); if (removedProviders.contains(id)) { it.remove(); } } realms.update(new BasicDBObject().append("_id", realmId), realm); } }
From source file:org.keycloak.connections.mongo.updater.impl.updates.AbstractMigrateUserFedToComponent.java
License:Apache License
public void portUserFedMappersToComponent(String providerId, String mapperType) { //logger.info("*** port mappers"); DBCollection realms = db.getCollection("realms"); DBCursor cursor = realms.find();/* w w w .java 2 s .c o m*/ while (cursor.hasNext()) { BasicDBObject realm = (BasicDBObject) cursor.next(); String realmId = realm.getString("_id"); Set<String> removedProviders = new HashSet<>(); BasicDBList componentEntities = (BasicDBList) realm.get("componentEntities"); BasicDBList federationProviders = (BasicDBList) realm.get("userFederationProviders"); BasicDBList fedMappers = (BasicDBList) realm.get("userFederationMappers"); for (Object obj : federationProviders) { BasicDBObject fedProvider = (BasicDBObject) obj; String providerName = fedProvider.getString("providerName"); //logger.info("looking for mappers of fed provider: " + providerName); if (providerName.equals(providerId)) { String id = fedProvider.getString("id"); //logger.info("found fed provider: " + id + ", looking at mappers"); for (Object obj2 : fedMappers) { BasicDBObject fedMapper = (BasicDBObject) obj2; String federationProviderId = fedMapper.getString("federationProviderId"); //logger.info("looking at mapper with federationProviderId: " + federationProviderId); if (federationProviderId.equals(id)) { String name = fedMapper.getString("name"); String mapperId = fedMapper.getString("id"); removedProviders.add(mapperId); String mapperProviderId = fedMapper.getString("federationMapperType"); BasicDBObject component = new BasicDBObject(); component.put("id", mapperId); component.put("name", name); component.put("providerType", mapperType); component.put("providerId", mapperProviderId); component.put("parentId", id); BasicDBObject fedConfig = (BasicDBObject) fedMapper.get("config"); BasicDBObject config = new BasicDBObject(); if (fedConfig != null) { for (Map.Entry<String, Object> attr : new HashSet<>(fedConfig.entrySet())) { String attrName = attr.getKey(); String attrValue = attr.getValue().toString(); config.put(attrName, Collections.singletonList(attrValue)); } } component.put("config", config); componentEntities.add(component); } } } } Iterator<Object> it = fedMappers.iterator(); while (it.hasNext()) { BasicDBObject fedMapper = (BasicDBObject) it.next(); String id = fedMapper.getString("id"); if (removedProviders.contains(id)) { it.remove(); } } realms.update(new BasicDBObject().append("_id", realmId), realm); } }