Package org.openmhealth.reference.exception

Examples of org.openmhealth.reference.exception.OmhException


   
    // If multiple authorization codes were returned, that is a violation
    // of the system.
    if(result.count() > 1) {
      throw
        new OmhException(
          "Multiple copies of the same authorization code exist: " +
            code);
    }
   
    // If no codes were returned, then return null.
View Full Code Here


        new MongoClient(
          new ServerAddress(getDatabaseAddress(), getDatabasePort()),
          credentials);
    }
    catch(UnknownHostException e) {
      throw new OmhException("The database could not setup.", e);
    }
   
    // Instantiate the specific components.
    new MongoAuthenticationTokenBin();
    new MongoAuthorizationCodeBin();
View Full Code Here

   */
  @Override
  public void createUser(final User user) throws OmhException {
    // Validate the parameter.
    if(user == null) {
      throw new OmhException("The user is null.");
    }
   
    // Get the DAO.
    SqlDao dao = SqlDao.getInstance();

    // Get the transaction manager.
    PlatformTransactionManager transactionManager =
      dao.getTransactionManager();
   
    // Create a new transaction definition and name it.
    DefaultTransactionDefinition transactionDefinition =
      new DefaultTransactionDefinition();
    transactionDefinition.setName("Adding a user.");
   
    // Create the new transaction.
    TransactionStatus transactionStatus =
      transactionManager.getTransaction(transactionDefinition);
   
    // Get the JDBC template.
    JdbcTemplate jdbcTemplate = dao.getJdbcTemplate();
   
    // Add the authentication token.
    try {
      jdbcTemplate
        .update(
          "INSERT INTO " + UserBin.DB_NAME +
            " (" +
              User.JSON_KEY_USERNAME + ", " +
              User.JSON_KEY_PASSWORD + ", " +
              User.JSON_KEY_EMAIL + ", " +
              User.JSON_KEY_REGISTRATION_KEY + ", " +
              User.JSON_KEY_DATE_REGISTERED + ", " +
              User.JSON_KEY_DATE_ACTIVATED + " " +
            ") " +
            "VALUES" +
            " (" +
              "?, " +
              "?, " +
              "?, " +
              "?, " +
              "?, " +
              "?" +
            ")",
          new Object[] {
            user.getUsername(),
            user.getPassword(),
            user.getEmail().toString(),
            user.getRegistratioKey(),
            user.getDateRegistered(),
            user.getDateActivated()
          }
        );
     
      // Commit the transaction.
      transactionManager.commit(transactionStatus);
    }
    catch(DataAccessException e) {
      transactionManager.rollback(transactionStatus);
      throw new OmhException("There was a problem storing the user.", e);
    }
  }
View Full Code Here

        return null;
      }
     
      // Otherwise, we throw an exception.
      throw
        new OmhException("Multiple users have the same username.", e);
    }
    // For all other issues, we simply propagate the exception.
    catch(DataAccessException e) {
      throw
        new OmhException("There was an error querying for a user.", e);
    }
  }
View Full Code Here

        return null;
      }
     
      // Otherwise, we throw an exception.
      throw
        new OmhException(
          "Multiple users have the same registration ID.",
          e);
    }
    // For all other issues, we simply propagate the exception.
    catch(DataAccessException e) {
      throw
        new OmhException("There was an error querying for a user.", e);
    }
  }
View Full Code Here

   */
  @Override
  public void updateUser(final User user) throws OmhException {
    // Validate the parameter.
    if(user == null) {
      throw new OmhException("The user is null.");
    }
   
    // Get the DAO.
    SqlDao dao = SqlDao.getInstance();

    // Get the transaction manager.
    PlatformTransactionManager transactionManager =
      dao.getTransactionManager();
   
    // Create a new transaction definition and name it.
    DefaultTransactionDefinition transactionDefinition =
      new DefaultTransactionDefinition();
    transactionDefinition.setName("Adding a user.");
   
    // Create the new transaction.
    TransactionStatus transactionStatus =
      transactionManager.getTransaction(transactionDefinition);
   
    // Get the JDBC template.
    JdbcTemplate jdbcTemplate = dao.getJdbcTemplate();
   
    // Add the authentication token.
    try {
      jdbcTemplate
        .update(
          "UPDATE " + UserBin.DB_NAME + " " +
          "SET " +
            User.JSON_KEY_PASSWORD + " = ?, " +
            User.JSON_KEY_EMAIL + " = ?, " +
            User.JSON_KEY_REGISTRATION_KEY + " = ?, " +
            User.JSON_KEY_DATE_REGISTERED + " = ?, " +
            User.JSON_KEY_DATE_ACTIVATED + " = ? " +
          "WHERE " + User.JSON_KEY_USERNAME + " = ?",
          new Object[] {
            user.getPassword(),
            user.getEmail().toString(),
            user.getRegistratioKey(),
            user.getDateRegistered(),
            user.getDateActivated(),
            user.getUsername()
          }
        );
     
      // Commit the transaction.
      transactionManager.commit(transactionStatus);
    }
    catch(DataAccessException e) {
      transactionManager.rollback(transactionStatus);
      throw new OmhException("There was a problem storing the user.", e);
    }
  }
View Full Code Here

   */
  @Override
  public void createUser(final User user) throws OmhException {
    // Validate the input.
    if(user == null) {
      throw new OmhException("The user is null.");
    }
   
    // Get the user collection.
    JacksonDBCollection<User, Object> collection =
      JacksonDBCollection
        .wrap(
          MongoDao.getInstance()
            .getDb()
            .getCollection(DB_NAME),
          User.class,
          Object.class,
          JSON_MAPPER);
   
    // Save the user.
    try {
      collection.insert(user);
    }
    catch(MongoException.DuplicateKey e) {
      throw
        new OmhException(
          "A user with that username already exists.",
          e);
    }
  }
View Full Code Here

   */
  @Override
  public User getUser(final String username) throws OmhException {
    // Validate the parameter.
    if(username == null) {
      throw new OmhException("The username is null.");
    }
   
    // Get the authentication token collection.
    JacksonDBCollection<MongoUser, Object> collection =
      JacksonDBCollection
        .wrap(
          MongoDao.getInstance()
            .getDb()
            .getCollection(DB_NAME),
          MongoUser.class,
          Object.class,
          JSON_MAPPER);
   
    // Build the query.
    QueryBuilder queryBuilder = QueryBuilder.start();
   
    // Add the authentication token to the query
    queryBuilder.and(MongoUser.JSON_KEY_USERNAME).is(username);
   
    // Execute query.
    DBCursor<MongoUser> result = collection.find(queryBuilder.get());
   
    // If multiple authentication tokens were returned, that is a violation
    // of the system.
    if(result.count() > 1) {
      throw
        new OmhException(
          "Multiple users exist with the same username: " +
            username);
    }
   
    // If no tokens were returned, then return null.
View Full Code Here

    final String registrationId)
    throws OmhException {
   
    // Validate the parameter.
    if(registrationId == null) {
      throw new OmhException("The registration ID is null.");
    }
   
    // Get the authentication token collection.
    JacksonDBCollection<MongoUser, Object> collection =
      JacksonDBCollection
        .wrap(
          MongoDao.getInstance()
            .getDb()
            .getCollection(DB_NAME),
          MongoUser.class,
          Object.class,
          JSON_MAPPER);
   
    // Build the query.
    QueryBuilder queryBuilder = QueryBuilder.start();
   
    // Add the authentication token to the query
    queryBuilder
      .and(MongoUser.JSON_KEY_REGISTRATION_KEY)
      .is(registrationId);
   
    // Execute query.
    DBCursor<MongoUser> result = collection.find(queryBuilder.get());
   
    // If multiple authentication tokens were returned, that is a violation
    // of the system.
    if(result.count() > 1) {
      throw
        new OmhException(
          "Multiple users exist with the same registration ID: " +
            registrationId);
    }
   
    // If no tokens were returned, then return null.
View Full Code Here

   */
  @Override
  public void updateUser(final User user) throws OmhException {
    // Validate the input.
    if(user == null) {
      throw new OmhException("The user is null.");
    }
   
    // Get the user collection.
    JacksonDBCollection<User, Object> collection =
      JacksonDBCollection
        .wrap(
          MongoDao.getInstance()
            .getDb()
            .getCollection(DB_NAME),
          User.class,
          Object.class,
          JSON_MAPPER);
   
    // Ensure that we are only updating the user with the same user-name.
    Query query = DBQuery.is(User.JSON_KEY_USERNAME, user.getUsername());
   
    // Save the user.
    try {
      collection.update(query, user);
    }
    catch(MongoException e) {
      throw new OmhException("An internal error occurred.", e);
    }
  }
View Full Code Here

TOP

Related Classes of org.openmhealth.reference.exception.OmhException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.