Exemple #1
0
 public boolean addUser(final Map<String, String> userInfo) {
   try {
     final MongoDatabase mdb = MongoDBConnManager.getInstance().getConnection();
     final MongoCollection<Document> coll = mdb.getCollection(DBConstants.COLL_USERS);
     final Document user = new Document();
     user.putAll(userInfo);
     coll.insertOne(user);
   } catch (MongoWriteException e) {
     if (e.getCode() == 11000) {
       throw new ApplicationException(
           MessagesEnum.DUPLICATE_USER.getMessage(userInfo.get(DBConstants.EMAIL)), e);
     }
   } catch (Exception e) {
     if (e instanceof com.mongodb.MongoTimeoutException) {
       throw new ApplicationException(MessagesEnum.MONGODB_IS_DOWN.getMessage(), e);
     }
     throw new ApplicationException(MessagesEnum.ADD_USER_FAILED.getMessage(), e);
   }
   return true;
 }
Exemple #2
0
 public boolean saveBooking(final Map<String, Object> bookingInfo) {
   try {
     final MongoDatabase mdb = MongoDBConnManager.getInstance().getConnection();
     final MongoCollection<Document> coll = mdb.getCollection(DBConstants.COLL_BOOKING);
     final Document booking = new Document();
     booking.putAll(bookingInfo);
     coll.insertOne(booking);
   } catch (MongoWriteException e) {
     if (e.getCode() == 11000) {
       throw new ApplicationException(
           MessagesEnum.BOOKINGS_ALREADY_EXISTS.getMessage(
               bookingInfo.get(DBConstants.BOX_NAME), bookingInfo.get(DBConstants.EMAIL)),
           e);
     }
   } catch (Exception e) {
     if (e instanceof com.mongodb.MongoTimeoutException) {
       throw new ApplicationException(MessagesEnum.MONGODB_IS_DOWN.getMessage(), e);
     }
     throw new ApplicationException(MessagesEnum.BOOKING_FAILED.getMessage(), e);
   }
   return true;
 }