Search in sources :

Example 21 with FeatureAccessException

use of org.ff4j.exception.FeatureAccessException in project ff4j by ff4j.

the class FeatureStoreHttp method addToGroup.

/**
 * {@inheritDoc}
 */
@Override
public void addToGroup(String uid, String groupName) {
    Util.assertHasLength(uid, groupName);
    Response cRes = ClientHttpUtils.invokePostMethod(getStore().path(uid).path(OPERATION_ADDGROUP).path(groupName), authorizationHeaderValue);
    if (Status.NOT_FOUND.getStatusCode() == cRes.getStatus()) {
        throw new FeatureNotFoundException(uid);
    }
    if (Status.NO_CONTENT.getStatusCode() != cRes.getStatus()) {
        throw new FeatureAccessException("Cannot add feature to group, an HTTP error " + cRes.getStatus() + OCCURED);
    }
}
Also used : Response(javax.ws.rs.core.Response) FeatureAccessException(org.ff4j.exception.FeatureAccessException) FeatureNotFoundException(org.ff4j.exception.FeatureNotFoundException)

Example 22 with FeatureAccessException

use of org.ff4j.exception.FeatureAccessException in project ff4j by ff4j.

the class FeatureStoreHttp method readAllGroups.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
public Set<String> readAllGroups() {
    Response cRes = ClientHttpUtils.invokeGetMethod(getGroups(), authorizationHeaderValue);
    List<Map<String, String>> groupList = cRes.readEntity(List.class);
    if (Status.OK.getStatusCode() != cRes.getStatus()) {
        throw new FeatureAccessException("Cannot read groups, an HTTP error " + cRes.getStatus() + OCCURED);
    }
    Set<String> groupNames = new HashSet<String>();
    for (Map<String, String> currentGroup : groupList) {
        groupNames.add(currentGroup.get("groupName"));
    }
    return groupNames;
}
Also used : Response(javax.ws.rs.core.Response) FeatureAccessException(org.ff4j.exception.FeatureAccessException) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 23 with FeatureAccessException

use of org.ff4j.exception.FeatureAccessException in project ff4j by ff4j.

the class FeatureStoreHttp method exist.

/**
 * {@inheritDoc}
 */
@Override
public boolean exist(String uid) {
    Util.assertHasLength(uid);
    Response cRes = ClientHttpUtils.invokeGetMethod(getStore().path(uid), authorizationHeaderValue);
    if (Status.OK.getStatusCode() == cRes.getStatus()) {
        return true;
    }
    if (Status.NOT_FOUND.getStatusCode() == cRes.getStatus()) {
        return false;
    }
    throw new FeatureAccessException("Cannot check existence of feature, an HTTP error " + cRes.getStatus() + " occured : " + cRes.getEntity());
}
Also used : Response(javax.ws.rs.core.Response) FeatureAccessException(org.ff4j.exception.FeatureAccessException)

Example 24 with FeatureAccessException

use of org.ff4j.exception.FeatureAccessException in project ff4j by ff4j.

the class JdbcFeatureDataSourceTest method testClose2Times.

@Test(expected = FeatureAccessException.class)
public void testClose2Times() {
    Connection sqlConn = null;
    PreparedStatement ps = null;
    try {
        // Pick connection
        sqlConn = sqlDataSource.getConnection();
        // Query Exist
        ps = JdbcUtils.buildStatement(sqlConn, SQL_EXIST, F1);
        JdbcUtils.rollback(sqlConn);
        ps.close();
        ps.executeQuery();
    } catch (SQLException sqlEX) {
        throw new FeatureAccessException("Cannot check feature existence, error related to database", sqlEX);
    }
}
Also used : FeatureAccessException(org.ff4j.exception.FeatureAccessException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) JdbcUtils.closeConnection(org.ff4j.utils.JdbcUtils.closeConnection) PreparedStatement(java.sql.PreparedStatement) Test(org.junit.Test)

Example 25 with FeatureAccessException

use of org.ff4j.exception.FeatureAccessException in project ff4j by ff4j.

the class MappingUtil method instanceFlippingStrategy.

/**
 * Instanciate flipping strategy from its class name.
 *
 * @param className
 *      current class name
 * @return
 *      the flipping strategy
 */
@SuppressWarnings("unchecked")
public static FlippingStrategy instanceFlippingStrategy(String uid, String className, Map<String, String> initparams) {
    try {
        Class<FlippingStrategy> clazz = (Class<FlippingStrategy>) (classLoader == null ? Class.forName(className) : classLoader.loadClass(className));
        FlippingStrategy flipStrategy = clazz.newInstance();
        flipStrategy.init(uid, initparams);
        return flipStrategy;
    } catch (Exception ie) {
        throw new FeatureAccessException("Cannot instantiate Strategy, no default constructor available", ie);
    }
}
Also used : FeatureAccessException(org.ff4j.exception.FeatureAccessException) FlippingStrategy(org.ff4j.core.FlippingStrategy) FeatureAccessException(org.ff4j.exception.FeatureAccessException)

Aggregations

FeatureAccessException (org.ff4j.exception.FeatureAccessException)50 SQLException (java.sql.SQLException)18 Connection (java.sql.Connection)17 PreparedStatement (java.sql.PreparedStatement)16 Response (javax.ws.rs.core.Response)16 JdbcUtils.closeConnection (org.ff4j.utils.JdbcUtils.closeConnection)15 Feature (org.ff4j.core.Feature)11 ResultSet (java.sql.ResultSet)10 ClientResponse (com.sun.jersey.api.client.ClientResponse)9 JdbcUtils.closeResultSet (org.ff4j.utils.JdbcUtils.closeResultSet)8 HashMap (java.util.HashMap)7 FeatureNotFoundException (org.ff4j.exception.FeatureNotFoundException)7 GroupNotFoundException (org.ff4j.exception.GroupNotFoundException)5 WebResource (com.sun.jersey.api.client.WebResource)4 HashSet (java.util.HashSet)4 FeatureJsonParser.parseFeature (org.ff4j.utils.json.FeatureJsonParser.parseFeature)4 IOException (java.io.IOException)3 Connection (org.apache.hadoop.hbase.client.Connection)3 Table (org.apache.hadoop.hbase.client.Table)3 HBaseConnection (org.ff4j.hbase.HBaseConnection)3