Search in sources :

Example 6 with OperationFailedException

use of tech.aroma.thrift.exceptions.OperationFailedException in project aroma-data-operations by RedRoma.

the class CassandraInboxRepository method getMessagesForUser.

@Override
public List<Message> getMessagesForUser(String userId) throws TException {
    checkThat(userId).throwing(InvalidArgumentException.class).is(validUserId());
    Statement query = createQueryToGetMessagesFor(userId);
    ResultSet results;
    try {
        results = cassandra.execute(query);
    } catch (Exception ex) {
        LOG.error("Failed to query for Messages in Inbox for User [{}]", userId, ex);
        throw new OperationFailedException("Could not fetch inbox: " + ex.getMessage());
    }
    checkThat(results).throwing(OperationFailedException.class).usingMessage("Cassandra returned null results").is(notNull());
    List<Message> messages = Lists.create();
    for (Row row : results) {
        Message message = messageMapper.apply(row);
        messages.add(message);
    }
    return messages;
}
Also used : InvalidArgumentException(tech.aroma.thrift.exceptions.InvalidArgumentException) RequestAssertions.validMessage(tech.aroma.data.assertions.RequestAssertions.validMessage) Message(tech.aroma.thrift.Message) Statement(com.datastax.driver.core.Statement) ResultSet(com.datastax.driver.core.ResultSet) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException) Row(com.datastax.driver.core.Row) TException(org.apache.thrift.TException) InvalidArgumentException(tech.aroma.thrift.exceptions.InvalidArgumentException) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException)

Example 7 with OperationFailedException

use of tech.aroma.thrift.exceptions.OperationFailedException in project aroma-data-operations by RedRoma.

the class CassandraInboxRepository method saveMessageForUser.

@Override
public void saveMessageForUser(@Required User user, @Required Message message, @Required LengthOfTime lifetime) throws TException {
    checkThat(message).throwing(ex -> new InvalidArgumentException(ex.getMessage())).is(validMessage());
    checkThat(user).throwing(ex -> new InvalidArgumentException(ex.getMessage())).is(validUser());
    Statement insertStatement = createStatementToSaveMessage(message, user, lifetime);
    try {
        cassandra.execute(insertStatement);
    } catch (Exception ex) {
        LOG.error("Failed to save Message in Cassandra Inbox. User [{}] Message [{}]", user.userId, message, ex);
        throw new OperationFailedException("Could not save message in Inbox: " + ex.getMessage());
    }
}
Also used : TimeFunctions(tech.aroma.thrift.functions.TimeFunctions) QueryBuilder(com.datastax.driver.core.querybuilder.QueryBuilder) LengthOfTime(tech.aroma.thrift.LengthOfTime) Row(com.datastax.driver.core.Row) LoggerFactory(org.slf4j.LoggerFactory) Required(tech.sirwellington.alchemy.annotations.arguments.Required) Function(java.util.function.Function) Arguments.checkThat(tech.sirwellington.alchemy.arguments.Arguments.checkThat) Inject(javax.inject.Inject) ResultSet(com.datastax.driver.core.ResultSet) RequestAssertions.validUserId(tech.aroma.data.assertions.RequestAssertions.validUserId) Session(com.datastax.driver.core.Session) Logger(org.slf4j.Logger) QueryBuilder.desc(com.datastax.driver.core.querybuilder.QueryBuilder.desc) QueryBuilder.eq(com.datastax.driver.core.querybuilder.QueryBuilder.eq) RequestAssertions.validMessage(tech.aroma.data.assertions.RequestAssertions.validMessage) TException(org.apache.thrift.TException) UUID(java.util.UUID) InvalidArgumentException(tech.aroma.thrift.exceptions.InvalidArgumentException) RequestAssertions.validUser(tech.aroma.data.assertions.RequestAssertions.validUser) Assertions.notNull(tech.sirwellington.alchemy.arguments.assertions.Assertions.notNull) List(java.util.List) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException) Inbox(tech.aroma.data.cassandra.Tables.Inbox) InboxRepository(tech.aroma.data.InboxRepository) User(tech.aroma.thrift.User) Statement(com.datastax.driver.core.Statement) Message(tech.aroma.thrift.Message) QueryBuilder.ttl(com.datastax.driver.core.querybuilder.QueryBuilder.ttl) Lists(sir.wellington.alchemy.collections.lists.Lists) RequestAssertions.validMessageId(tech.aroma.data.assertions.RequestAssertions.validMessageId) InvalidArgumentException(tech.aroma.thrift.exceptions.InvalidArgumentException) Statement(com.datastax.driver.core.Statement) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException) TException(org.apache.thrift.TException) InvalidArgumentException(tech.aroma.thrift.exceptions.InvalidArgumentException) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException)

Example 8 with OperationFailedException

use of tech.aroma.thrift.exceptions.OperationFailedException in project aroma-data-operations by RedRoma.

the class CassandraTokenRepository method tryToConvertRowToToken.

private AuthenticationToken tryToConvertRowToToken(Row row) throws OperationFailedException, InvalidTokenException {
    AuthenticationToken token;
    try {
        token = tokenMapper.apply(row);
    } catch (Exception ex) {
        LOG.error("Could not map Row {} to Token", row, ex);
        throw new OperationFailedException("Failed to query for Token: " + ex.getMessage());
    }
    checkThat(token).throwing(InvalidTokenException.class).is(completeToken());
    return token;
}
Also used : InvalidTokenException(tech.aroma.thrift.exceptions.InvalidTokenException) AuthenticationToken(tech.aroma.thrift.authentication.AuthenticationToken) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException) InvalidTokenException(tech.aroma.thrift.exceptions.InvalidTokenException) TException(org.apache.thrift.TException) InvalidArgumentException(tech.aroma.thrift.exceptions.InvalidArgumentException) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException)

Example 9 with OperationFailedException

use of tech.aroma.thrift.exceptions.OperationFailedException in project aroma-data-operations by RedRoma.

the class CassandraTokenRepository method tryToGetResultSetFrom.

private ResultSet tryToGetResultSetFrom(Statement statment) throws OperationFailedException {
    ResultSet results;
    try {
        results = cassandra.execute(statment);
    } catch (Exception ex) {
        LOG.error("Failed to execute Cassandra statement: {}", statment, ex);
        throw new OperationFailedException("Could not query for Token:" + ex.getMessage());
    }
    checkThat(results).usingMessage("unexpected null result from cassandra").throwing(OperationFailedException.class).is(notNull());
    return results;
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException) InvalidTokenException(tech.aroma.thrift.exceptions.InvalidTokenException) TException(org.apache.thrift.TException) InvalidArgumentException(tech.aroma.thrift.exceptions.InvalidArgumentException) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException)

Example 10 with OperationFailedException

use of tech.aroma.thrift.exceptions.OperationFailedException in project aroma-data-operations by RedRoma.

the class CassandraUserRepository method findByGithubProfile.

@Override
public User findByGithubProfile(String githubProfile) throws TException {
    checkThat(githubProfile).throwing(InvalidArgumentException.class).usingMessage("github profile cannot be empty").is(nonEmptyString());
    Statement query = createQueryToGetUsersByGithubProfile(githubProfile);
    ResultSet results;
    try {
        results = cassandra.execute(query);
    } catch (Exception ex) {
        LOG.error("Failed to query Cassandra Table {} for profile {}", TABLE_NAME_BY_GITHUB_PROFILE, githubProfile, ex);
        throw new OperationFailedException("Could not query for profile: " + ex.getMessage());
    }
    Row row = results.one();
    checkThat(row).throwing(UserDoesNotExistException.class).usingMessage("Could not find user with Github Profile: " + githubProfile).is(notNull());
    User user = convertRowToUser(row);
    return user;
}
Also used : RequestAssertions.validUser(tech.aroma.data.assertions.RequestAssertions.validUser) User(tech.aroma.thrift.User) BatchStatement(com.datastax.driver.core.BatchStatement) Statement(com.datastax.driver.core.Statement) ResultSet(com.datastax.driver.core.ResultSet) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException) Row(com.datastax.driver.core.Row) TException(org.apache.thrift.TException) InvalidArgumentException(tech.aroma.thrift.exceptions.InvalidArgumentException) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException) UserDoesNotExistException(tech.aroma.thrift.exceptions.UserDoesNotExistException)

Aggregations

OperationFailedException (tech.aroma.thrift.exceptions.OperationFailedException)40 TException (org.apache.thrift.TException)32 InvalidArgumentException (tech.aroma.thrift.exceptions.InvalidArgumentException)32 Statement (com.datastax.driver.core.Statement)29 ResultSet (com.datastax.driver.core.ResultSet)19 Row (com.datastax.driver.core.Row)17 BatchStatement (com.datastax.driver.core.BatchStatement)13 OrganizationDoesNotExistException (tech.aroma.thrift.exceptions.OrganizationDoesNotExistException)9 Test (org.junit.Test)8 ApplicationDoesNotExistException (tech.aroma.thrift.exceptions.ApplicationDoesNotExistException)7 RequestAssertions.validApplication (tech.aroma.data.assertions.RequestAssertions.validApplication)6 Application (tech.aroma.thrift.Application)6 DontRepeat (tech.sirwellington.alchemy.test.junit.runners.DontRepeat)6 RequestAssertions.validUser (tech.aroma.data.assertions.RequestAssertions.validUser)4 User (tech.aroma.thrift.User)4 RequestAssertions.validMessage (tech.aroma.data.assertions.RequestAssertions.validMessage)2 Message (tech.aroma.thrift.Message)2 InvalidTokenException (tech.aroma.thrift.exceptions.InvalidTokenException)2 MessageDoesNotExistException (tech.aroma.thrift.exceptions.MessageDoesNotExistException)2 Session (com.datastax.driver.core.Session)1