Search in sources :

Example 1 with Inbox

use of tech.aroma.data.cassandra.Tables.Inbox 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)

Aggregations

ResultSet (com.datastax.driver.core.ResultSet)1 Row (com.datastax.driver.core.Row)1 Session (com.datastax.driver.core.Session)1 Statement (com.datastax.driver.core.Statement)1 QueryBuilder (com.datastax.driver.core.querybuilder.QueryBuilder)1 QueryBuilder.desc (com.datastax.driver.core.querybuilder.QueryBuilder.desc)1 QueryBuilder.eq (com.datastax.driver.core.querybuilder.QueryBuilder.eq)1 QueryBuilder.ttl (com.datastax.driver.core.querybuilder.QueryBuilder.ttl)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.validMessage (tech.aroma.data.assertions.RequestAssertions.validMessage)1 RequestAssertions.validMessageId (tech.aroma.data.assertions.RequestAssertions.validMessageId)1 RequestAssertions.validUser (tech.aroma.data.assertions.RequestAssertions.validUser)1