Package org.openmhealth.reference.exception

Examples of org.openmhealth.reference.exception.OmhException


            });
    }
    // For all issues, we simply propagate the exception.
    catch(DataAccessException e) {
      throw
        new OmhException(
          "There was an error querying for schemas.",
          e);
    }
   
    // Create the SELECT portion of the count query.
    StringBuilder countBuilder =
      new StringBuilder("SELECT COUNT(1) ");
   
    // Add the shared FROM clause.
    countBuilder.append(sqlFrom);
   
    // Add the WHERE clause if it is not null.
    if(sqlWhere != null) {
      countBuilder.append(sqlWhere);
    }
   
    // Retrieve the total count of results.
    int count;
    try {
      count =
        SqlDao
          .getInstance()
          .getJdbcTemplate()
          .queryForInt(
            countBuilder.toString(),
            sqlParameters.toArray());
    }
    // For all issues, we simply propagate the exception.
    catch(DataAccessException e) {
      throw
        new OmhException(
          "There was an error querying for schemas count.",
          e);
    }
   
    return new SqlMultiValueResult<Schema>(list, count);
View Full Code Here


    final AuthenticationToken token)
    throws OmhException {
   
    // Validate the parameter.
    if(token == null) {
      throw new OmhException("The token 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 an authentication token.");
   
    // 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 " + AuthenticationTokenBin.DB_NAME +
            " (" +
              UserBin.DB_NAME + "_id" + ", " +
              AuthenticationToken.JSON_KEY_TOKEN + ", " +
              AuthenticationToken.JSON_KEY_GRANTED + ", " +
              AuthenticationToken.JSON_KEY_EXPIRES + " " +
            ") " +
            "VALUES" +
            " (" +
              "(" +
                "SELECT " + SqlDao.KEY_DATABASE_ID + " " +
                "FROM " + UserBin.DB_NAME + " " +
                "WHERE " + User.JSON_KEY_USERNAME + " = ?" +
              "), " +
              "?, " +
              "?, " +
              "?" +
            ")",
          new Object[] {
            token.getUsername(),
            token.getToken(),
            token.getGranted(),
            token.getExpires()
            }
          );
     
      // Commit the transaction.
      transactionManager.commit(transactionStatus);
    }
    catch(DataAccessException e) {
      transactionManager.rollback(transactionStatus);
      throw
        new OmhException(
          "There was a problem storing the authentication token.",
          e);
    }
  }
View Full Code Here

    final String token)
    throws OmhException {
   
    // Validate the parameter.
    if(token == null) {
      throw new OmhException("The token is null.");
    }
   
    try {
      return
        SqlDao
          .getInstance()
          .getJdbcTemplate()
          .queryForObject(
            "SELECT " +
                User.JSON_KEY_USERNAME + ", " +
                AuthenticationToken.JSON_KEY_TOKEN + ", " +
                AuthenticationToken.JSON_KEY_GRANTED + ", " +
                AuthenticationToken.JSON_KEY_EXPIRES + " " +
              "FROM " +
                UserBin.DB_NAME + ", " +
                AuthenticationTokenBin.DB_NAME + " " +
              "WHERE " +
                  UserBin.DB_NAME +
                  "." +
                  SqlDao.KEY_DATABASE_ID +
                " = " +
                  AuthenticationTokenBin.DB_NAME +
                  "." +
                  UserBin.DB_NAME + "_id " +
              "AND " +
                AuthenticationToken.JSON_KEY_TOKEN + " = ?",
            new Object[] { token },
            new RowMapper<AuthenticationToken>() {
              /**
               * Maps the row to an {@link AuthenticationToken}
               * object.
               */
              @Override
              public AuthenticationToken mapRow(
                final ResultSet resultSet,
                final int rowNum)
                throws SQLException {
               
                return
                  new AuthenticationToken(
                    resultSet
                      .getString(
                        AuthenticationToken
                          .JSON_KEY_TOKEN),
                    resultSet
                      .getString(User.JSON_KEY_USERNAME),
                    resultSet
                      .getLong(
                        AuthenticationToken
                          .JSON_KEY_GRANTED),
                    resultSet
                      .getLong(
                        AuthenticationToken
                          .JSON_KEY_EXPIRES));
              }
            });
    }
    // If the problem is that the number of results isn't what we expected,
    // we may still be alright.
    catch(IncorrectResultSizeDataAccessException e) {
      // If there weren't any tokens with the given token value, then we
      // simply return null.
      if(e.getActualSize() == 0) {
        return null;
      }
     
      // Otherwise, we throw an exception.
      throw
        new OmhException(
          "Multiple authentication tokens have the same token " +
            "value.",
          e);
    }
    // For all other issues, we simply propagate the exception.
    catch(DataAccessException e) {
      throw
        new OmhException(
          "There was an error querying for an authentication token.",
          e);
    }
  }
View Full Code Here

    final AuthorizationCodeResponse response)
    throws OmhException {

    // Validate the parameter.
    if(response == null) {
      throw new OmhException("The response 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 an authorization code response.");
   
    // Create the new transaction.
    TransactionStatus transactionStatus =
      transactionManager.getTransaction(transactionDefinition);
   
    // Get the JDBC template.
    JdbcTemplate jdbcTemplate = dao.getJdbcTemplate();
   
    // Add the authorization code response.
    try {
      jdbcTemplate
        .update(
          "INSERT INTO " + AuthorizationCodeResponseBin.DB_NAME +
            " (" +
              UserBin.DB_NAME + "_id" + ", " +
              AuthorizationCodeBin.DB_NAME + "_id" + ", " +
              AuthorizationCodeResponse.JSON_KEY_GRANTED + " " +
            ") " +
            "VALUES" +
            " (" +
              "(" +
                "SELECT " + SqlDao.KEY_DATABASE_ID + " " +
                "FROM " + UserBin.DB_NAME + " " +
                "WHERE " + User.JSON_KEY_USERNAME + " = ?" +
              "), " +
              "(" +
                "SELECT " + SqlDao.KEY_DATABASE_ID + " " +
                "FROM " + AuthorizationCodeBin.DB_NAME + " " +
                "WHERE " +
                  AuthorizationCode.JSON_KEY_CODE + " = ?" +
              "), " +
              "?" +
            ")",
          new Object[] {
            response.getOwnerUsername(),
            response.getAuthorizationCode(),
            response.getGranted()
            }
          );
    }
    catch(DataAccessException e) {
      transactionManager.rollback(transactionStatus);
      throw
        new OmhException(
          "There was a problem storing the authorization code " +
            "response.",
          e);
    }
   
    // Commit the transaction.
    try {
      transactionManager.commit(transactionStatus);
    }
    catch(DataAccessException e) {
      transactionManager.rollback(transactionStatus);
      throw
        new OmhException(
          "There was a problem storing the authorization code " +
            "response.",
          e);
    }
  }
View Full Code Here

    final String code)
    throws OmhException {

    // Validate the parameter.
    if(code == null) {
      throw new OmhException("The authorization code is null.");
    }
   
    try {
      return
        SqlDao
          .getInstance()
          .getJdbcTemplate()
          .queryForObject(
            "SELECT " +
                User.JSON_KEY_USERNAME + ", " +
                AuthorizationCode.JSON_KEY_CODE + ", " +
                AuthorizationCodeResponse.JSON_KEY_GRANTED +
                  " " +
              "FROM " +
                UserBin.DB_NAME + ", " +
                AuthorizationCodeBin.DB_NAME + ", " +
                AuthorizationCodeResponseBin.DB_NAME + " " +
              "WHERE " +
                  UserBin.DB_NAME +
                  "." +
                  SqlDao.KEY_DATABASE_ID +
                " = " +
                  AuthorizationCodeResponseBin.DB_NAME +
                  "." +
                  UserBin.DB_NAME + "_id " +
              "AND " +
                  AuthorizationCodeBin.DB_NAME +
                  "." +
                  SqlDao.KEY_DATABASE_ID +
                " = " +
                  AuthorizationCodeResponseBin.DB_NAME +
                  "." +
                  AuthorizationCodeBin.DB_NAME + "_id " +
              "AND " +
                AuthorizationCode.JSON_KEY_CODE + " = ?",
            new Object[] { code },
            new RowMapper<AuthorizationCodeResponse>() {
              /**
               * Maps the row to an
               * {@link AuthorizationCodeResponse} object.
               */
              @Override
              public AuthorizationCodeResponse mapRow(
                final ResultSet resultSet,
                final int rowNum)
                throws SQLException {
               
                return
                  new AuthorizationCodeResponse(
                    resultSet
                      .getString(
                        AuthorizationCode
                          .JSON_KEY_CODE),
                    resultSet
                      .getString(User.JSON_KEY_USERNAME),
                    resultSet
                      .getBoolean(
                        AuthorizationCodeResponse
                          .JSON_KEY_GRANTED));
              }
            });
    }
    // If the problem is that the number of results isn't what we expected,
    // we may still be alright.
    catch(IncorrectResultSizeDataAccessException e) {
      // If there weren't any tokens with the given token value, then we
      // simply return null.
      if(e.getActualSize() == 0) {
        return null;
      }
     
      // Otherwise, we throw an exception.
      throw
        new OmhException(
          "Multiple authorization code responses have the same " +
            "code value.",
          e);
    }
    // For all other issues, we simply propagate the exception.
    catch(DataAccessException e) {
      throw
        new OmhException(
          "Multiple authorization code responses have the same " +
            "code value.",
          e);
    }
  }
View Full Code Here

    final ThirdParty thirdParty)
    throws OmhException {
   
    // Validate the parameter.
    if(thirdParty == null) {
      throw new OmhException("The third-party 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 third-party.");
   
    // Create the new transaction.
    TransactionStatus transactionStatus =
      transactionManager.getTransaction(transactionDefinition);
   
    // Get the JDBC template.
    JdbcTemplate jdbcTemplate = dao.getJdbcTemplate();
   
    // Add the third-party.
    try {
      jdbcTemplate
        .update(
          "INSERT INTO " + ThirdPartyBin.DB_NAME + " (" +
              UserBin.DB_NAME + "_id" + ", " +
              ThirdParty.JSON_KEY_ID + ", " +
              ThirdParty.JSON_KEY_SHARED_SECRET + ", " +
              ThirdParty.JSON_KEY_NAME + ", " +
              ThirdParty.JSON_KEY_DESCRIPTION + ", " +
              ThirdParty.JSON_KEY_REDIRECT_URI + " " +
            ") VALUES (" +
              "(" +
                "SELECT " + SqlDao.KEY_DATABASE_ID + " " +
                "FROM " + UserBin.DB_NAME + " " +
                "WHERE " + User.JSON_KEY_USERNAME + " = ?" +
              "), " +
              "?, " +
              "?, " +
              "?, " +
              "?, " +
              "?" +
            ")",
          new Object[] {
              thirdParty.getOwner(),
              thirdParty.getId(),
              thirdParty.getSecret(),
              thirdParty.getName(),
              thirdParty.getDescription(),
              thirdParty.getRedirectUri().toString()
            }
          );
     
      // Commit the transaction.
      transactionManager.commit(transactionStatus);
    }
    catch(DataAccessException e) {
      transactionManager.rollback(transactionStatus);
      throw
        new OmhException(
          "There was a problem storing the third-party.",
          e);
    }
  }
View Full Code Here

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

    try {
      message.setRecipient(Message.RecipientType.TO, user.getEmail());
    }
    catch(MessagingException e) {
      throw
        new OmhException(
          "There was an error setting the recipient of the message.",
          e);
    }
   
    // Add the sender.
    try {
      message.setFrom(MAIL_SENDER_EMAIL);
    }
    catch(MessagingException e) {
      throw
        new OmhException(
          "There was an error setting the sender's email address.",
          e);
    }
   
    // Set the subject.
    try {
      message.setSubject(REGISTRATION_SUBJECT);
    }
    catch(MessagingException e) {
      throw
        new OmhException(
          "There was an error setting the subject on the message.",
          e);
    }

    // Set the content of the message.
    try {
      message.setContent(createRegistrationText(), "text/html");
    }
    catch(MessagingException e) {
      throw
        new OmhException(
          "There was an error constructing the message.",
          e);
    }
   
    // Prepare the message to be sent.
    try {
      message.saveChanges();
    }
    catch(MessagingException e) {
      throw
        new OmhException(
          "There was an error saving the changes to the message.",
          e);
    }
   
    // Send the registration email.
View Full Code Here

    MessageDigest digest;
    try {
      digest = MessageDigest.getInstance(DIGEST_ALGORITHM);
    }
    catch(NoSuchAlgorithmException e) {
      throw new OmhException("The SHA-512 algorithm is unknown.", e);
    }
   
    digest.update(username.getBytes());
    digest.update(email.getBytes());
    digest
View Full Code Here

      transport =
        (SMTPTransport) smtpSession.getTransport(MAIL_PROTOCOL);
    }
    catch(NoSuchProviderException e) {
      throw
        new OmhException(
          "There is no provider for " + MAIL_PROTOCOL + ".",
          e);
    }

    // Connect to the transport.
    try {
      transport.connect();
    }
    catch(MessagingException e) {
      throw new OmhException("Could not connect to the mail server.", e);
    }
   
    // Send the message.
    try {
      transport.sendMessage(message, message.getAllRecipients());
    }
    catch(SendFailedException e) {
      throw new OmhException("Failed to send the message.", e);
    }
    catch(MessagingException e) {
      throw
        new OmhException(
          "There was a problem while sending the message.",
          e);
    }
    finally {
      // Close the connection to the transport.
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.