Search in sources :

Example 1 with FeatureAccessException

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

the class FeatureStoreHttp method readAllGroups.

/**
 * {@inheritDoc}
 */
@Override
public Set<String> readAllGroups() {
    ClientResponse cRes = getGroups().get(ClientResponse.class);
    List<GroupDescApiBean> groupApiBeans = cRes.getEntity(new GenericType<List<GroupDescApiBean>>() {
    });
    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 (GroupDescApiBean groupApiBean : groupApiBeans) {
        groupNames.add(groupApiBean.getGroupName());
    }
    return groupNames;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) FeatureAccessException(org.ff4j.exception.FeatureAccessException) List(java.util.List) GroupDescApiBean(org.ff4j.web.api.resources.domain.GroupDescApiBean) HashSet(java.util.HashSet)

Example 2 with FeatureAccessException

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

the class FeatureStoreHttp method readGroup.

/**
 * {@inheritDoc}
 */
@Override
public Map<String, Feature> readGroup(String groupName) {
    if (groupName == null || groupName.isEmpty()) {
        throw new IllegalArgumentException(GROUPNAME_CANNOT_BE_NULL_NOR_EMPTY);
    }
    ClientResponse cRes = getGroups().path(groupName).get(ClientResponse.class);
    if (Status.NOT_FOUND.getStatusCode() == cRes.getStatus()) {
        throw new GroupNotFoundException(groupName);
    }
    if (Status.OK.getStatusCode() != cRes.getStatus()) {
        throw new FeatureAccessException(CANNOT_GRANT_ROLE_ON_FEATURE_AN_HTTP_ERROR + cRes.getStatus() + OCCURED);
    }
    String resEntity = cRes.getEntity(String.class);
    Feature[] fArray = parseFeatureArray(resEntity);
    Map<String, Feature> features = new HashMap<String, Feature>();
    for (Feature feature : fArray) {
        features.put(feature.getUid(), feature);
    }
    return features;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) FeatureAccessException(org.ff4j.exception.FeatureAccessException) HashMap(java.util.HashMap) GroupNotFoundException(org.ff4j.exception.GroupNotFoundException) FeatureJsonParser.parseFeature(org.ff4j.utils.json.FeatureJsonParser.parseFeature) Feature(org.ff4j.core.Feature)

Example 3 with FeatureAccessException

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

the class FeatureStoreHttp method clear.

/**
 * {@inheritDoc}
 */
@Override
public void clear() {
    Util.assertHasLength(url);
    WebResource wr = getJerseyClient().resource(url).path(RESOURCE_STORE).path(STORE_CLEAR);
    if (null != authorization) {
        wr.header(HEADER_AUTHORIZATION, authorization);
    }
    ClientResponse cRes = wr.post(ClientResponse.class);
    if (Status.OK.getStatusCode() != cRes.getStatus()) {
        throw new FeatureAccessException("Cannot clear feature store - " + cRes.getStatus());
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) FeatureAccessException(org.ff4j.exception.FeatureAccessException) WebResource(com.sun.jersey.api.client.WebResource)

Example 4 with FeatureAccessException

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

the class FeatureServices method initFlippingStrategy.

private void initFlippingStrategy(FeatureApiBean featureApiBean, Feature feature) {
    FlippingStrategyApiBean flipApiBean = featureApiBean.getFlippingStrategy();
    if (null != flipApiBean) {
        try {
            Map<String, String> initParams = flipApiBean.getInitParams();
            feature.setFlippingStrategy(MappingUtil.instanceFlippingStrategy(featureApiBean.getUid(), flipApiBean.getType(), initParams));
        } catch (FeatureAccessException exception) {
            throw new FlippingStrategyBadRequestException(exception);
        }
    }
}
Also used : FlippingStrategyApiBean(org.ff4j.services.domain.FlippingStrategyApiBean) FeatureAccessException(org.ff4j.exception.FeatureAccessException) FlippingStrategyBadRequestException(org.ff4j.services.exceptions.FlippingStrategyBadRequestException)

Example 5 with FeatureAccessException

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

the class JdbcFeatureStore method readAllGroups.

/**
 * {@inheritDoc}
 */
@Override
public Set<String> readAllGroups() {
    Set<String> setOFGroup = new HashSet<String>();
    Connection sqlConn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    try {
        // Returns features
        sqlConn = dataSource.getConnection();
        ps = sqlConn.prepareStatement(getQueryBuilder().getAllGroups());
        rs = ps.executeQuery();
        while (rs.next()) {
            String groupName = rs.getString(COL_FEAT_GROUPNAME);
            if (Util.hasLength(groupName)) {
                setOFGroup.add(groupName);
            }
        }
        return setOFGroup;
    } catch (SQLException sqlEX) {
        throw new FeatureAccessException("Cannot list groups, error related to database", sqlEX);
    } finally {
        closeResultSet(rs);
        closeStatement(ps);
        closeConnection(sqlConn);
    }
}
Also used : FeatureAccessException(org.ff4j.exception.FeatureAccessException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) JdbcUtils.closeConnection(org.ff4j.utils.JdbcUtils.closeConnection) ResultSet(java.sql.ResultSet) JdbcUtils.closeResultSet(org.ff4j.utils.JdbcUtils.closeResultSet) PreparedStatement(java.sql.PreparedStatement) HashSet(java.util.HashSet)

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