Search in sources :

Example 31 with OperationFailedException

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

the class CassandraFollowerRepository method getApplicationsFollowedBy.

@Override
public List<Application> getApplicationsFollowedBy(String userId) throws TException {
    checkUserId(userId);
    Statement query = createQueryForAppsFollowedBy(userId);
    ResultSet results;
    try {
        results = cassandra.execute(query);
    } catch (Exception ex) {
        LOG.error("Failed to query Cassandra for apps followed by User: [{}]", userId, ex);
        throw new OperationFailedException("Could not find apps followed by user: " + ex.getMessage());
    }
    List<Application> apps = Lists.create();
    for (Row row : results) {
        Application app = createAppFromRow(row);
        apps.add(app);
    }
    LOG.debug("Found {} apps followed by {}", apps.size(), userId);
    return apps;
}
Also used : BatchStatement(com.datastax.driver.core.BatchStatement) Statement(com.datastax.driver.core.Statement) ResultSet(com.datastax.driver.core.ResultSet) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException) Row(com.datastax.driver.core.Row) RequestAssertions.validApplication(tech.aroma.data.assertions.RequestAssertions.validApplication) Application(tech.aroma.thrift.Application) TException(org.apache.thrift.TException) InvalidArgumentException(tech.aroma.thrift.exceptions.InvalidArgumentException) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException)

Example 32 with OperationFailedException

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

the class CassandraFollowerRepository method deleteFollowing.

@Override
public void deleteFollowing(String userId, String applicationId) throws TException {
    checkUserId(userId);
    checkAppId(applicationId);
    Statement deleteStatement = createDeleteStatementFor(userId, applicationId);
    try {
        cassandra.execute(deleteStatement);
    } catch (Exception ex) {
        LOG.error("Failed to delete the following between User: [{}] App: [{}]", userId, applicationId, ex);
        throw new OperationFailedException("Could not delete following: " + ex.getMessage());
    }
}
Also used : BatchStatement(com.datastax.driver.core.BatchStatement) 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 33 with OperationFailedException

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

the class CassandraInboxRepository method deleteAllMessagesForUser.

@Override
public void deleteAllMessagesForUser(String userId) throws TException {
    checkUserId(userId);
    Statement deleteStatement = createDeleteAllStatementFor(userId);
    try {
        cassandra.execute(deleteStatement);
    } catch (Exception ex) {
        LOG.error("Failed to delete all messages for User [{}] from Inbox", userId, ex);
        throw new OperationFailedException("Could not delete message: " + ex.getMessage());
    }
}
Also used : 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 34 with OperationFailedException

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

the class CassandraInboxRepository method deleteMessageForUser.

@Override
public void deleteMessageForUser(String userId, String messageId) throws TException {
    checkUserId(userId);
    checkMessageId(messageId);
    Statement deleteStatement = createDeleteStatementFor(userId, messageId);
    try {
        cassandra.execute(deleteStatement);
    } catch (Exception ex) {
        LOG.error("Failed to delete message [{}] for User [{}] from Inbox", messageId, userId, ex);
        throw new OperationFailedException("Could not delete message: " + ex.getMessage());
    }
}
Also used : 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 35 with OperationFailedException

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

the class CassandraInboxRepository method containsMessageInInbox.

@Override
public boolean containsMessageInInbox(String userId, Message message) throws TException {
    checkUserId(userId);
    checkThat(message).throwing(InvalidArgumentException.class).is(validMessage());
    Statement query = createQueryToCheckIfInInboxOf(userId, message);
    ResultSet results;
    try {
        results = cassandra.execute(query);
    } catch (Exception ex) {
        LOG.error("Failed to query Cassandra for presence of message [{}] for User [{}]", message.messageId, userId, ex);
        throw new OperationFailedException("Could not check if message exists: " + ex.getMessage());
    }
    Row row = results.one();
    checkThat(row).throwing(OperationFailedException.class).usingMessage("Query for message failed").is(notNull());
    long count = row.getLong(0);
    return count > 0;
}
Also used : InvalidArgumentException(tech.aroma.thrift.exceptions.InvalidArgumentException) Statement(com.datastax.driver.core.Statement) ResultSet(com.datastax.driver.core.ResultSet) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException) Row(com.datastax.driver.core.Row) TException(org.apache.thrift.TException) InvalidArgumentException(tech.aroma.thrift.exceptions.InvalidArgumentException) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException)

Aggregations

OperationFailedException (tech.aroma.thrift.exceptions.OperationFailedException)40 TException (org.apache.thrift.TException)32 InvalidArgumentException (tech.aroma.thrift.exceptions.InvalidArgumentException)32 Statement (com.datastax.driver.core.Statement)29 ResultSet (com.datastax.driver.core.ResultSet)19 Row (com.datastax.driver.core.Row)17 BatchStatement (com.datastax.driver.core.BatchStatement)13 OrganizationDoesNotExistException (tech.aroma.thrift.exceptions.OrganizationDoesNotExistException)9 Test (org.junit.Test)8 ApplicationDoesNotExistException (tech.aroma.thrift.exceptions.ApplicationDoesNotExistException)7 RequestAssertions.validApplication (tech.aroma.data.assertions.RequestAssertions.validApplication)6 Application (tech.aroma.thrift.Application)6 DontRepeat (tech.sirwellington.alchemy.test.junit.runners.DontRepeat)6 RequestAssertions.validUser (tech.aroma.data.assertions.RequestAssertions.validUser)4 User (tech.aroma.thrift.User)4 RequestAssertions.validMessage (tech.aroma.data.assertions.RequestAssertions.validMessage)2 Message (tech.aroma.thrift.Message)2 InvalidTokenException (tech.aroma.thrift.exceptions.InvalidTokenException)2 MessageDoesNotExistException (tech.aroma.thrift.exceptions.MessageDoesNotExistException)2 Session (com.datastax.driver.core.Session)1