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;
}
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;
}
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());
}
}
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);
}
}
}
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);
}
}
Aggregations