Search in sources :

Example 11 with OperationFailedException

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

the class CassandraOrganizationRepository method containsOrganization.

@Override
public boolean containsOrganization(String organizationId) throws TException {
    checkOrganizationId(organizationId);
    Statement query = createQueryToCheckIfOrgExists(organizationId);
    ResultSet results;
    try {
        results = cassandra.execute(query);
    } catch (Exception ex) {
        LOG.error("Failed to query for existence of Organization [{}]", organizationId, ex);
        throw new OperationFailedException("Could not query for 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 12 with OperationFailedException

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

the class CassandraOrganizationRepository method getOrganization.

@Override
public Organization getOrganization(String organizationId) throws TException {
    checkOrganizationId(organizationId);
    Statement query = createQueryToGetOrganization(organizationId);
    ResultSet results;
    try {
        results = cassandra.execute(query);
    } catch (Exception ex) {
        LOG.error("Failed to query for Organization [{}]", organizationId, ex);
        throw new OperationFailedException("Could not get Organization: " + ex.getMessage());
    }
    Row row = results.one();
    checkRowIsPresent(row);
    Organization org = organizationMapper.apply(row);
    return org;
}
Also used : Organization(tech.aroma.thrift.Organization) RequestAssertions.validOrganization(tech.aroma.data.assertions.RequestAssertions.validOrganization) 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 13 with OperationFailedException

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

the class CassandraOrganizationRepository method deleteMember.

@Override
public void deleteMember(String organizationId, String userId) throws TException {
    checkOrganizationId(organizationId);
    checkUserId(userId);
    Statement deleteStatement = createStatmentToDeleteMember(organizationId, userId);
    try {
        cassandra.execute(deleteStatement);
    } catch (Exception ex) {
        LOG.error("Failed to delete Member [{}] in Organization [{}]", userId, organizationId, ex);
        throw new OperationFailedException("Failed to delete Member in 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 14 with OperationFailedException

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

the class CassandraOrganizationRepository method deleteAllMembers.

@Override
public void deleteAllMembers(String organizationId) throws TException {
    checkOrganizationId(organizationId);
    Statement deleteStatement = createStatementToDeleteAllMembers(organizationId);
    try {
        cassandra.execute(deleteStatement);
    } catch (Exception ex) {
        LOG.error("Failed to delete all Members in Organization [{}]", organizationId, ex);
        throw new OperationFailedException("Failed to delete all members in 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 15 with OperationFailedException

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

the class CassandraOrganizationRepository method saveOrganization.

@Override
public void saveOrganization(Organization organization) throws TException {
    checkThat(organization).throwing(InvalidArgumentException.class).is(validOrganization());
    Statement insertStatement = createStatementToInsert(organization);
    try {
        cassandra.execute(insertStatement);
    } catch (Exception ex) {
        LOG.error("Failed to save Organization in Cassandra: [{}]", organization, ex);
        throw new OperationFailedException("Failed to save 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)

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