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