List of usage examples for com.mongodb BasicDBObject BasicDBObject
public BasicDBObject()
From source file:at.ac.tuwien.dsg.smartcom.manager.messaging.logging.dao.MongoDBLoggingDAO.java
License:Apache License
private BasicDBObject serializeIdentifier(Identifier identifier) { try {//from ww w .j a v a 2 s. co m return new BasicDBObject().append("type", identifier.getType().toString()).append("id", identifier.getId()); } catch (Exception e) { return null; } }
From source file:at.ac.tuwien.dsg.smartcom.services.dao.MongoDBMessageInfoDAO.java
License:Apache License
BasicDBObject serializeMessageInfo(MessageInformation mi) { BasicDBObject doc = new BasicDBObject(); doc.append("_id", serializeKey(mi.getKey())); doc.append("purpose", mi.getPurpose()); doc.append("validAnswer", mi.getValidAnswer()); BasicDBList types = new BasicDBList(); for (MessageInformation.Key key : mi.getValidAnswerTypes()) { types.add(serializeKey(key));//from w w w .j a va 2 s . c o m } doc.append("validAnswerTypes", types); BasicDBList rel = new BasicDBList(); for (MessageInformation.Key key : mi.getRelatedMessages()) { rel.add(serializeKey(key)); } doc.append("relatedMessages", rel); log.trace("Saving message info in mongoDB: {}", doc); return doc; }
From source file:at.oneminutedistraction.mongodbrealm.UserCollection.java
private BasicDBObject create(String username, String password) { BasicDBObject user = new BasicDBObject(); user.append(ATTR_USERNAME, username).append(ATTR_PASSWORD, passwordMgr.encrypt(password)); return (user); }
From source file:backend.facades.UserController.java
@Override public Integer getMembersCount() { Integer listCount = 0;// w w w . j a v a 2 s . co m try { BasicDBObject query = new BasicDBObject(); DBCursor cursor = userCollection.find(query); listCount = cursor.count(); System.out.println("MEMBER COUNT backend" + listCount); } catch (Exception e) { e.printStackTrace(); } return listCount; }
From source file:backend.facades.UserController.java
public boolean updateImageId(Long userId, String imageId) { try {/*from ww w. j a v a 2 s . c o m*/ BasicDBObject document = new BasicDBObject(); document.append("$set", new BasicDBObject().append("imageId", imageId)); userCollection.update(new BasicDBObject().append("_id", userId), document); } catch (Exception e) { e.printStackTrace(); } return true; }
From source file:backend.facades.UserController.java
public void updatePassword(Long id, String password) { BasicDBObject document = new BasicDBObject(); document.append("$set", new BasicDBObject().append("passwd", hashPassword(password))); userCollection.update(new BasicDBObject().append("_id", id), document); }
From source file:backend.facades.UserController.java
public List<UserEntity> getSubscribersList() { UserEntity userEntity = null;/*w w w . j a v a 2 s .c om*/ List<UserEntity> userList = new ArrayList<UserEntity>(); BasicDBObject query = new BasicDBObject(); query.put("subscribe", StatusTypes.ACCEPT_SUBSCRB); DBCursor cursor = userCollection.find(query); try { while (cursor.hasNext()) { DBObject document = cursor.next(); userEntity = new UserEntity(); userEntity.setId((Long) document.get("_id")); userEntity.setUsername((String) document.get("username")); userEntity.setEmail((String) document.get("email")); userEntity.setFirstname((String) document.get("firstname")); userEntity.setPasswd((String) document.get("passwd")); userEntity.setLastname((String) document.get("lastname")); userEntity.setStatus((Integer) document.get("status")); userEntity.setImageId((String) document.get("imageId")); userEntity.setRegisteredDate((Date) document.get("registeredDate")); userEntity.setLastLoginDate((Date) document.get("lastLoginDate")); userEntity.setLanguageCode((String) document.get("languageCode")); userEntity.setUserRole((Integer) document.get("userRole")); userEntity.setModeratorValue((Integer) document.get("moderator")); userEntity.setPersonalWebPage((String) document.get("webpage")); Integer value = (Integer) document.get("subscribe"); if (value != null && value.equals(StatusTypes.ACCEPT_LICENSE)) { userEntity.setAcceptSubscr(true); } else { userEntity.setAcceptSubscr(false); } userList.add(userEntity); } } finally { cursor.close(); } return userList; }
From source file:backend.facades.UserController.java
public UserEntity getUserByEmail(String email) { UserEntity userEntity = null;/*from ww w . j a va 2 s . c om*/ BasicDBObject query = new BasicDBObject(); query.put("email", email); DBCursor cursor = userCollection.find(query); try { if (cursor.count() > 0) { DBObject document = cursor.next(); userEntity = new UserEntity(); userEntity.setId((Long) document.get("_id")); userEntity.setUsername((String) document.get("username")); userEntity.setEmail((String) document.get("email")); userEntity.setFirstname((String) document.get("firstname")); userEntity.setPasswd((String) document.get("passwd")); userEntity.setLastname((String) document.get("lastname")); userEntity.setStatus((Integer) document.get("status")); userEntity.setImageId((String) document.get("imageId")); userEntity.setRegisteredDate((Date) document.get("registeredDate")); userEntity.setLastLoginDate((Date) document.get("lastLoginDate")); userEntity.setLanguageCode((String) document.get("languageCode")); userEntity.setUserRole((Integer) document.get("userRole")); userEntity.setModeratorValue((Integer) document.get("moderator")); userEntity.setPersonalWebPage((String) document.get("webpage")); Integer value = (Integer) document.get("subscribe"); if (value != null && value.equals(StatusTypes.ACCEPT_LICENSE)) { userEntity.setAcceptSubscr(true); } else { userEntity.setAcceptSubscr(false); } } } finally { cursor.close(); } return userEntity; }
From source file:backend.facades.UserController.java
public UserEntity getUserById(Long id) { UserEntity userEntity = null;/*from w w w. jav a2 s . c o m*/ BasicDBObject query = new BasicDBObject(); query.put("_id", id); DBCursor cursor = userCollection.find(query); try { if (cursor.count() > 0) { DBObject document = cursor.next(); userEntity = new UserEntity(); userEntity.setId((Long) document.get("_id")); userEntity.setUsername((String) document.get("username")); userEntity.setEmail((String) document.get("email")); userEntity.setFirstname((String) document.get("firstname")); userEntity.setPasswd((String) document.get("passwd")); userEntity.setLastname((String) document.get("lastname")); userEntity.setStatus((Integer) document.get("status")); userEntity.setImageId((String) document.get("imageId")); userEntity.setRegisteredDate((Date) document.get("registeredDate")); userEntity.setLastLoginDate((Date) document.get("lastLoginDate")); userEntity.setLanguageCode((String) document.get("languageCode")); userEntity.setUserRole((Integer) document.get("userRole")); userEntity.setModeratorValue((Integer) document.get("moderator")); Integer value = (Integer) document.get("subscribe"); userEntity.setPersonalWebPage((String) document.get("webpage")); if (value != null && value.equals(StatusTypes.ACCEPT_SUBSCRB)) { userEntity.setAcceptSubscr(true); } else { userEntity.setAcceptSubscr(false); } } } finally { cursor.close(); } return userEntity; }
From source file:backend.facades.UserController.java
public void updateUserProfile(UserEntity userEntity) { BasicDBObject document = new BasicDBObject(); if (userEntity.getPasswd() != null) { document.append("$set", new BasicDBObject().append("email", userEntity.getEmail()) .append("userRole", userEntity.getUserRole()).append("username", userEntity.getUsername()) .append("firstname", userEntity.getFirstname()).append("lastname", userEntity.getLastname()) .append("passwd", hashPassword(userEntity.getPasswd() != null ? userEntity.getPasswd() : null)) .append("webpage", userEntity.getPersonalWebPage()).append("imageId", userEntity.getImageId()) .append("subscribe", userEntity.isAcceptSubscr() ? StatusTypes.ACCEPT_SUBSCRB : StatusTypes.DISABLE_SUBSCRB) .append("status", userEntity.getStatus())); } else {//www .ja v a 2 s .co m document.append("$set", new BasicDBObject().append("email", userEntity.getEmail()) .append("userRole", userEntity.getUserRole()).append("username", userEntity.getUsername()) .append("firstname", userEntity.getFirstname()).append("lastname", userEntity.getLastname()) .append("imageId", userEntity.getImageId()).append("webpage", userEntity.getPersonalWebPage()) .append("subscribe", userEntity.isAcceptSubscr() ? StatusTypes.ACCEPT_SUBSCRB : StatusTypes.DISABLE_SUBSCRB) .append("status", userEntity.getStatus())); } userCollection.update(new BasicDBObject().append("_id", userEntity.getId()), document); }