Search in sources :

Example 1 with LengthOfTime

use of tech.aroma.thrift.LengthOfTime 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 2 with LengthOfTime

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

the class MessageRepository method saveMessage.

default void saveMessage(@Required Message message) throws TException {
    LengthOfTime defaultTime = new LengthOfTime().setValue(1).setUnit(TimeUnit.WEEKS);
    this.saveMessage(message, defaultTime);
}
Also used : LengthOfTime(tech.aroma.thrift.LengthOfTime)

Example 3 with LengthOfTime

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

the class CassandraUserRepository method createInsertIntoRecentUsersTable.

private Statement createInsertIntoRecentUsersTable(User user) {
    UUID userUuid = UUID.fromString(user.userId);
    Set<String> emails = Sets.createFrom(user.email);
    Set<String> roles = Sets.nullToEmpty(user.roles).stream().map(Role::toString).collect(toSet());
    LengthOfTime timeUserIsRecent = new LengthOfTime().setUnit(TimeUnit.DAYS).setValue(5);
    int recentDuration = (int) TimeFunctions.toSeconds(timeUserIsRecent);
    return QueryBuilder.insertInto(Users.TABLE_NAME_RECENT).value(Users.USER_ID, userUuid).value(Users.FIRST_NAME, user.firstName).value(Users.MIDDLE_NAME, user.middleName).value(Users.LAST_NAME, user.lastName).value(Users.EMAILS, emails).value(Users.ROLES, roles).value(Users.GITHUB_PROFILE, user.githubProfile).value(Users.PROFILE_IMAGE_ID, user.profileImageLink).value(Users.TIME_ACCOUNT_CREATED, Instant.now().toEpochMilli()).using(ttl(recentDuration));
}
Also used : LengthOfTime(tech.aroma.thrift.LengthOfTime) StringAssertions.nonEmptyString(tech.sirwellington.alchemy.arguments.assertions.StringAssertions.nonEmptyString) StringAssertions.validUUID(tech.sirwellington.alchemy.arguments.assertions.StringAssertions.validUUID) UUID(java.util.UUID)

Aggregations

LengthOfTime (tech.aroma.thrift.LengthOfTime)3 UUID (java.util.UUID)2 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 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