Search in sources :

Example 21 with OperationFailedException

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

the class CassandraOrganizationRepository method isMemberInOrganization.

@Override
public boolean isMemberInOrganization(String organizationId, String userId) throws TException {
    checkOrganizationId(organizationId);
    checkUserId(userId);
    Statement query = createQueryToSeeIfMemberOfOrg(organizationId, userId);
    ResultSet results;
    try {
        results = cassandra.execute(query);
    } catch (Exception ex) {
        LOG.error("Failed to query for existence of Member [{]] in Organization [{}]", userId, organizationId, ex);
        throw new OperationFailedException("Could not query for membership in Organization: " + ex.getMessage());
    }
    Row row = results.one();
    checkRowIsPresent(row);
    long count = row.getLong(0);
    return count > 0L;
}
Also used : Statement(com.datastax.driver.core.Statement) ResultSet(com.datastax.driver.core.ResultSet) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException) Row(com.datastax.driver.core.Row) OrganizationDoesNotExistException(tech.aroma.thrift.exceptions.OrganizationDoesNotExistException) TException(org.apache.thrift.TException) InvalidArgumentException(tech.aroma.thrift.exceptions.InvalidArgumentException) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException)

Example 22 with OperationFailedException

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

the class CassandraOrganizationRepository method getOrganizationMembers.

@Override
public List<User> getOrganizationMembers(String organizationId) throws TException {
    checkOrganizationId(organizationId);
    Statement query = createQueryToGetOrganizationMembers(organizationId);
    ResultSet results;
    try {
        results = cassandra.execute(query);
    } catch (Exception ex) {
        LOG.error("Failed to query for Organization Members: [{}]", organizationId, ex);
        throw new OperationFailedException("Could not query for Organization Members: " + ex.getMessage());
    }
    List<User> members = Lists.create();
    for (Row row : results) {
        User member = userMapper.apply(row);
        members.add(member);
    }
    LOG.debug("Found {} members in Org [{]]", members.size(), organizationId);
    return members;
}
Also used : RequestAssertions.validUser(tech.aroma.data.assertions.RequestAssertions.validUser) User(tech.aroma.thrift.User) Statement(com.datastax.driver.core.Statement) ResultSet(com.datastax.driver.core.ResultSet) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException) Row(com.datastax.driver.core.Row) OrganizationDoesNotExistException(tech.aroma.thrift.exceptions.OrganizationDoesNotExistException) TException(org.apache.thrift.TException) InvalidArgumentException(tech.aroma.thrift.exceptions.InvalidArgumentException) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException)

Example 23 with OperationFailedException

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

the class CassandraOrganizationRepository method saveMemberInOrganization.

@Override
public void saveMemberInOrganization(String organizationId, User user) throws TException {
    checkOrganizationId(organizationId);
    checkThat(user).throwing(InvalidArgumentException.class).is(validUser());
    Statement insertStatement = createStatementToSaveMember(organizationId, user);
    try {
        cassandra.execute(insertStatement);
    } catch (Exception ex) {
        LOG.error("Failed to save Member [{}] in Organization [{}] in Cassandra: [{}]", user, organizationId, ex);
        throw new OperationFailedException("Failed to save Member in Organization: " + ex.getMessage());
    }
}
Also used : InvalidArgumentException(tech.aroma.thrift.exceptions.InvalidArgumentException) Statement(com.datastax.driver.core.Statement) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException) OrganizationDoesNotExistException(tech.aroma.thrift.exceptions.OrganizationDoesNotExistException) TException(org.apache.thrift.TException) InvalidArgumentException(tech.aroma.thrift.exceptions.InvalidArgumentException) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException)

Example 24 with OperationFailedException

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

the class CassandraOrganizationRepository method deleteOrganization.

@Override
public void deleteOrganization(String organizationId) throws TException {
    deleteAllMembers(organizationId);
    Statement deleteStatement = createStatementToDelete(organizationId);
    try {
        cassandra.execute(deleteStatement);
    } catch (Exception ex) {
        LOG.error("Failed to delete Organization in Cassandra: [{}]", organizationId, ex);
        throw new OperationFailedException("Failed to delete Organization: " + ex.getMessage());
    }
}
Also used : Statement(com.datastax.driver.core.Statement) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException) OrganizationDoesNotExistException(tech.aroma.thrift.exceptions.OrganizationDoesNotExistException) TException(org.apache.thrift.TException) InvalidArgumentException(tech.aroma.thrift.exceptions.InvalidArgumentException) OperationFailedException(tech.aroma.thrift.exceptions.OperationFailedException)

Example 25 with OperationFailedException

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

the class CassandraApplicationRepository method containsApplication.

@Override
public boolean containsApplication(String applicationId) throws TException {
    checkApplicationId(applicationId);
    Statement query = createQueryToCheckIfAppIdExists(applicationId);
    ResultSet results;
    try {
        results = cassandra.execute(query);
    } catch (Exception ex) {
        LOG.error("Failed to check Application existence for [{}]", applicationId, ex);
        throw new OperationFailedException("Could not check for application existence: " + applicationId);
    }
    Row row = results.one();
    checkRowNotMissing(applicationId, row);
    long count = row.getLong(0);
    return count > 0L;
}
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) ApplicationDoesNotExistException(tech.aroma.thrift.exceptions.ApplicationDoesNotExistException) 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