Search in sources :

Example 26 with OperationFailedException

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

the class CassandraApplicationRepository method getRecentlyCreated.

@Override
public List<Application> getRecentlyCreated() throws TException {
    List<Application> apps = Lists.create();
    Statement query = createQueryForRecentlyCreatedApps();
    ResultSet results = null;
    try {
        results = cassandra.execute(query);
    } catch (Exception ex) {
        LOG.error("Failed to query for recently created apps", ex);
        throw new OperationFailedException("Could not get recently created apps: " + ex.getMessage());
    }
    for (Row row : results) {
        Application app = createApplicationFromRow(row);
        apps.add(app);
    }
    LOG.debug("Found {} recently created apps", apps.size());
    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) ApplicationDoesNotExistException(tech.aroma.thrift.exceptions.ApplicationDoesNotExistException) TException(org.apache.thrift.TException) InvalidArgumentException(tech.aroma.thrift.exceptions.InvalidArgumentException) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException)

Example 27 with OperationFailedException

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

the class CassandraApplicationRepository method getApplicationsOwnedBy.

@Override
public List<Application> getApplicationsOwnedBy(String userId) throws TException {
    checkThat(userId).throwing(InvalidArgumentException.class).is(validUserId());
    Statement query = createQueryForAppsOwnedBy(userId);
    ResultSet results;
    try {
        results = cassandra.execute(query);
    } catch (Exception ex) {
        LOG.error("Failed to query for Apps owned by {}", userId, ex);
        throw new OperationFailedException("Could not determine Apps owned by user: " + userId);
    }
    List<Application> apps = Lists.create();
    for (Row row : results) {
        if (row == null) {
            continue;
        }
        Application app = createApplicationFromRow(row);
        apps.add(app);
    }
    LOG.debug("Found {} apps owned by user {}", apps.size(), userId);
    return apps;
}
Also used : InvalidArgumentException(tech.aroma.thrift.exceptions.InvalidArgumentException) 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) ApplicationDoesNotExistException(tech.aroma.thrift.exceptions.ApplicationDoesNotExistException) TException(org.apache.thrift.TException) InvalidArgumentException(tech.aroma.thrift.exceptions.InvalidArgumentException) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException)

Example 28 with OperationFailedException

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

the class CassandraApplicationRepository method getApplicationsByOrg.

@Override
public List<Application> getApplicationsByOrg(String orgId) throws TException {
    checkThat(orgId).throwing(InvalidArgumentException.class).is(validOrgId());
    Statement query = createQueryForAppsWithOrg(orgId);
    ResultSet results;
    try {
        results = cassandra.execute(query);
    } catch (Exception ex) {
        LOG.error("Failed to find Apps by Org with ID [{}]", orgId, ex);
        throw new OperationFailedException("Could not find Org's Apps: " + orgId);
    }
    List<Application> apps = Lists.create();
    for (Row row : results) {
        Application app = createApplicationFromRow(row);
        apps.add(app);
    }
    LOG.debug("Found {} apps in Org {}", apps.size(), orgId);
    return apps;
}
Also used : InvalidArgumentException(tech.aroma.thrift.exceptions.InvalidArgumentException) 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) ApplicationDoesNotExistException(tech.aroma.thrift.exceptions.ApplicationDoesNotExistException) TException(org.apache.thrift.TException) InvalidArgumentException(tech.aroma.thrift.exceptions.InvalidArgumentException) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException)

Example 29 with OperationFailedException

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

the class CassandraFollowerRepository method saveFollowing.

@Override
public void saveFollowing(User user, Application application) throws TException {
    checkThat(user).throwing(InvalidArgumentException.class).is(validUser());
    checkThat(application).throwing(InvalidArgumentException.class).is(validApplication());
    Statement insertStatement = createStatementToSaveFollowing(user, application);
    try {
        cassandra.execute(insertStatement);
    } catch (Exception ex) {
        LOG.error("Failed to save following: User: [{}] App: [{}]", user.userId, application.applicationId, ex);
        throw new OperationFailedException("Could not save following in Cassandra: " + ex.getMessage());
    }
}
Also used : InvalidArgumentException(tech.aroma.thrift.exceptions.InvalidArgumentException) 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 30 with OperationFailedException

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

the class CassandraFollowerRepository method getApplicationFollowers.

@Override
public List<User> getApplicationFollowers(String applicationId) throws TException {
    checkAppId(applicationId);
    Statement query = createQueryForFollowersOfApp(applicationId);
    ResultSet results;
    try {
        results = cassandra.execute(query);
    } catch (Exception ex) {
        LOG.error("Failed to query for App's followed: App: [{}]", applicationId, ex);
        throw new OperationFailedException("Could not query for App's Followers: " + ex.getMessage());
    }
    List<User> followers = Lists.create();
    for (Row row : results) {
        User follower = createUserFromRow(row);
        followers.add(follower);
    }
    LOG.debug("Found {} Users followed App [{}]", followers.size(), applicationId);
    return followers;
}
Also used : RequestAssertions.validUser(tech.aroma.data.assertions.RequestAssertions.validUser) User(tech.aroma.thrift.User) 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) 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