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;
}
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());
}
}
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;
}
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;
}
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;
}
Aggregations