List of usage examples for com.mongodb BasicDBObject getBoolean
public boolean getBoolean(final String key)
From source file:com.images3.data.impl.MongoDBObjectMapper.java
License:Apache License
public TemplateOS mapToTemplateOS(BasicDBObject source) { return new TemplateOS(new TemplateIdentity(source.getString("imagePlantId"), source.getString("name")), source.getBoolean("isArchived"), source.getBoolean("isRemovable"), mapToResizingConfig((BasicDBObject) source.get("resizingConfig"))); }
From source file:com.images3.data.impl.MongoDBObjectMapper.java
License:Apache License
public ResizingConfig mapToResizingConfig(BasicDBObject source) { return new ResizingConfig(ResizingUnit.valueOf(source.getString("unit")), source.getInt("width"), source.getInt("height"), source.getBoolean("isKeepProportions")); }
From source file:com.mobileman.kuravis.core.ws.user.UserController.java
License:Apache License
/** * process sign-in// ww w .j ava2 s . com * @param body sign-in data * @return error message in case of error */ @RequestMapping(value = "/user/signin", method = RequestMethod.POST, produces = { JsonUtil.MEDIA_TYPE_APPLICATION_JSON }) @ResponseBody public ResponseEntity<DBObject> signin(@RequestBody BasicDBObject body) { if (log.isDebugEnabled()) { log.debug("signin(" + body + ") - start"); } String userName = body.getString("login"); String password = body.getString("password"); String captcha_answer = body.getString("captcha_answer"); boolean rememberMe = body.getBoolean("rememberMe"); DBObject result = this.userService.signin(userName, password, captcha_answer, rememberMe); ResponseEntity<DBObject> response = new ResponseEntity<DBObject>(result, new HttpHeaders(), ErrorUtils.getStatus(result)); if (log.isDebugEnabled()) { log.debug("return " + response); } return response; }
From source file:com.mongodash.dao.mapper.SettingsDBObjectMapper.java
@Override public Settings mapDBObject(BasicDBObject object) { Settings settings = null;/* w w w . j a v a 2 s . c om*/ String _id = object.getString(Config.COMMON_FIELDS._id.name()); if (SETTINGS_KEY.email.name().equals(_id)) { settings = new EmailSettings(); if (object != null) { ((EmailSettings) settings).setEnabled(object.getBoolean("enabled")); ((EmailSettings) settings).setServer(object.getString("server")); ((EmailSettings) settings).setPort(object.getString("port")); ((EmailSettings) settings).setSender(object.getString("sender")); if (object.containsField("username") && object.containsField("password")) { ((EmailSettings) settings).setUsername(object.getString("username")); ((EmailSettings) settings).setPassword(PasswordUtil.decrypt(object.getString("password"))); } ((EmailSettings) settings).setSsl(object.getBoolean("ssl")); } } else if (SETTINGS_KEY.ldap.name().equals(_id)) { settings = new LdapSettings(); if (object != null) { ((LdapSettings) settings).setEnabled(object.getBoolean("enabled")); ((LdapSettings) settings).setHost(object.getString("host")); ((LdapSettings) settings).setPort(object.getString("port")); ((LdapSettings) settings).setAdminDn(object.getString("adminDn")); ((LdapSettings) settings).setAdminPassword(object.getString("adminPassword")); ((LdapSettings) settings).setBaseDn(object.getString("baseDn")); ((LdapSettings) settings).setLoginAttribute(object.getString("loginAttr")); ((LdapSettings) settings).setSecure(object.getBoolean("secure")); } } else if (SETTINGS_KEY.alerts.name().equals(_id)) { settings = new AlertSettings(); if (object != null) { ((AlertSettings) settings).setEnabled(object.getBoolean("enabled")); ((AlertSettings) settings).setEmailSubject(object.getString("emailSubject")); ((AlertSettings) settings).setEmailRecipients(object.getString("emailRecipients")); } } else if (SETTINGS_KEY.notifications.name().equals(_id)) { settings = new NotificationSettings(); if (object != null) { ((NotificationSettings) settings).setEnabled(object.getBoolean("enabled")); ((NotificationSettings) settings).setEmailEnabled(object.getBoolean("emailEnabled")); ((NotificationSettings) settings).setEmailSubject(object.getString("emailSubject")); ((NotificationSettings) settings).setEmailRecipients(object.getString("emailRecipients")); if (object.containsField("enabledNotifications")) { BasicDBList list = (BasicDBList) object.get("enabledNotifications"); List<String> enabledNotifications = new ArrayList<String>(); for (int i = 0; i < list.size(); i++) { enabledNotifications.add((String) list.get(i)); } ((NotificationSettings) settings).setEnabledNotifications(enabledNotifications); } } } else if (SETTINGS_KEY.licenseKey.name().equals(_id)) { settings = new LicenseKeySettings(); if (object != null) { ((LicenseKeySettings) settings).setPrivateKey(object.getString("privateKey")); ((LicenseKeySettings) settings).setPublicKey(object.getString("publicKey")); } } return settings; }
From source file:GeoHazardServices.Inst.java
License:Apache License
@POST @Path("/signin") @Produces(MediaType.APPLICATION_JSON)/* w ww . j a v a2 s . c o m*/ public String signin(@Context HttpServletRequest request, @Context HttpServletResponse response, @FormParam("username") String username, @FormParam("password") String password) { Cookie sessionCookie = new Cookie("server_cookie", "java!"); sessionCookie.setPath("/"); sessionCookie.setHttpOnly(true); //sessionCookie.setSecure( true ); if (username == null || password == null || username.equals("") || password.equals("")) return jsfailure(); DBCollection coll = db.getCollection("users"); DBCursor cursor = coll.find(new BasicDBObject("username", username)); DBObject obj; if (cursor.hasNext()) { obj = cursor.next(); String hash = (String) obj.get("password"); String session = (String) obj.get("session"); MessageDigest sha256; try { sha256 = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException e) { return "{ \"status\": \"error\" }"; } Base64Codec base64Codec = new Base64Codec(); if (hash.equals(base64Codec.encode(sha256.digest(password.getBytes())))) { if (session == null) { session = getSessionKey(); obj.put("session", session); coll.update(new BasicDBObject("username", username), obj); } sessionCookie.setValue(session); response.addCookie(sessionCookie); BasicDBObject result = new BasicDBObject("status", "success"); result.put("user", getUserObj(username)); BasicDBObject perm = (BasicDBObject) obj.get("permissions"); if (perm != null && perm.getBoolean("nologin") == true) return jsdenied(new BasicDBObject("nologin", true)); System.out.println("CLOUD " + new Date() + " SignIn from user " + username); DBObject login = new BasicDBObject("date", new Date()).append("user", username); db.getCollection("logins").insert(login); return gson.toJson(result); } } return jsfailure(); }
From source file:GeoHazardServices.Inst.java
License:Apache License
@POST @Path("/session") @Produces(MediaType.APPLICATION_JSON)/*from w w w . j av a 2s . c o m*/ public String session(@Context HttpServletRequest request, @Context HttpServletResponse response, @CookieParam("server_cookie") String session) { if (session == null) return jsfailure(); User user = signedIn(session); if (user != null) { DBObject userObj = getUserObj(user.name); BasicDBObject result = new BasicDBObject("status", "success"); result.put("user", userObj); BasicDBObject perm = (BasicDBObject) userObj.get("permissions"); if (perm != null && perm.getBoolean("nologin") == true) return jsdenied(new BasicDBObject("nologin", true)); System.out.println("CLOUD " + new Date() + " Resuming session for user " + user.name); return gson.toJson(result); } return jsfailure(); }
From source file:org.apache.gora.mongodb.utils.BSONDecorator.java
License:Apache License
/** * Access field as a boolean./* w ww .j a v a2 s . c o m*/ * * @param fieldName * fully qualified name of the field to be accessed * @return value of the field as a boolean */ public Boolean getBoolean(String fieldName) { BasicDBObject parent = getFieldParent(fieldName); return parent.getBoolean(getLeafName(fieldName)); }
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 {//from w w w .j a va 2 s. co m 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 ww. j a v a 2 s . com*/ } return pcjBuilder; }
From source file:org.canedata.provider.mongodb.entity.MongoEntity.java
License:Apache License
public List<Fields> list(int offset, int count) { if (logger.isDebug()) logger.debug("Listing entities, Database is {0}, Collection is {1}, offset is {2}, count is {3}.", getSchema(), getName(), offset, count); List<Fields> rlt = new ArrayList<Fields>(); BasicDBObject options = new BasicDBObject(); DBCursor cursor = null;//from w ww . j a v a 2 s. c o m try { validateState(); MongoExpressionFactory expFactory = new MongoExpressionFactory.Impl(); BasicDBObject projection = new BasicDBObject(); Limiter limiter = new Limiter.Default(); BasicDBObject sorter = new BasicDBObject(); IntentParser.parse(getIntent(), expFactory, null, projection, limiter, sorter, options); if (!options.isEmpty()) prepareOptions(options); if (null != getCache()) {// cache cursor = getCollection().find(expFactory.toQuery(), new BasicDBObject().append("_id", 1)); } else {// no cache // projection if (projection.isEmpty()) cursor = getCollection().find(expFactory.toQuery()); else cursor = getCollection().find(expFactory.toQuery(), projection); } // sort if (!sorter.isEmpty()) cursor.sort(sorter); if (offset > 0) limiter.offset(offset); if (count > 0) limiter.count(count); if (limiter.offset() > 0) cursor.skip(limiter.offset()); if (limiter.count() > 0) cursor.limit(limiter.count()); if (null != getCache()) { Map<Object, MongoFields> missedCacheHits = new HashMap<Object, MongoFields>(); while (cursor.hasNext()) { BasicDBObject dbo = (BasicDBObject) cursor.next(); Object key = dbo.get("_id"); String cacheKey = getKey().concat("#").concat(key.toString()); MongoFields ele = null; if (getCache().isAlive(cacheKey)) {// load from cache MongoFields mf = (MongoFields) getCache().restore(cacheKey); if (null != mf) ele = mf.clone();// pooling } if (null != ele && !projection.isEmpty()) ele.project(projection.keySet()); if (null == ele) { ele = new MongoFields(this, getIntent()); missedCacheHits.put(key, ele); } rlt.add(ele); } // load missed cache hits. if (!missedCacheHits.isEmpty()) { loadForMissedCacheHits(missedCacheHits, projection.keySet()); missedCacheHits.clear(); } if (logger.isDebug()) logger.debug("Listed entities hit cache ..."); } else { while (cursor.hasNext()) { BasicDBObject dbo = (BasicDBObject) cursor.next(); rlt.add(new MongoFields(this, getIntent(), dbo)); } if (logger.isDebug()) logger.debug("Listed entities ..."); } return rlt; } catch (AnalyzeBehaviourException abe) { if (logger.isDebug()) logger.debug(abe, "Analyzing behaviour failure, cause by: {0}.", abe.getMessage()); throw new RuntimeException(abe); } finally { if (!options.getBoolean(Options.RETAIN)) getIntent().reset(); if (cursor != null) cursor.close(); } }