Search in sources :

Example 1 with InvalidArgumentException

use of tech.aroma.thrift.exceptions.InvalidArgumentException 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) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) TException(org.apache.thrift.TException) Required(tech.sirwellington.alchemy.annotations.arguments.Required) UUID(java.util.UUID) Function(java.util.function.Function) InvalidArgumentException(tech.aroma.thrift.exceptions.InvalidArgumentException) RequestAssertions(tech.aroma.data.assertions.RequestAssertions) Inject(javax.inject.Inject) Assertions.notNull(tech.sirwellington.alchemy.arguments.assertions.Assertions.notNull) List(java.util.List) com.datastax.driver.core(com.datastax.driver.core) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException) Arguments(tech.sirwellington.alchemy.arguments.Arguments) Inbox(tech.aroma.data.cassandra.Tables.Inbox) tech.aroma.thrift(tech.aroma.thrift) InboxRepository(tech.aroma.data.InboxRepository) Message(tech.aroma.thrift.Message) Lists(sir.wellington.alchemy.collections.lists.Lists) InvalidArgumentException(tech.aroma.thrift.exceptions.InvalidArgumentException) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException) TException(org.apache.thrift.TException) InvalidArgumentException(tech.aroma.thrift.exceptions.InvalidArgumentException) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException)

Aggregations

com.datastax.driver.core (com.datastax.driver.core)1 QueryBuilder (com.datastax.driver.core.querybuilder.QueryBuilder)1 List (java.util.List)1 UUID (java.util.UUID)1 Function (java.util.function.Function)1 Inject (javax.inject.Inject)1 TException (org.apache.thrift.TException)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 Lists (sir.wellington.alchemy.collections.lists.Lists)1 InboxRepository (tech.aroma.data.InboxRepository)1 RequestAssertions (tech.aroma.data.assertions.RequestAssertions)1 Inbox (tech.aroma.data.cassandra.Tables.Inbox)1 tech.aroma.thrift (tech.aroma.thrift)1 Message (tech.aroma.thrift.Message)1 InvalidArgumentException (tech.aroma.thrift.exceptions.InvalidArgumentException)1 OperationFailedException (tech.aroma.thrift.exceptions.OperationFailedException)1 TimeFunctions (tech.aroma.thrift.functions.TimeFunctions)1 Required (tech.sirwellington.alchemy.annotations.arguments.Required)1 Arguments (tech.sirwellington.alchemy.arguments.Arguments)1