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