use of org.ff4j.exception.FeatureAccessException in project ff4j by ff4j.
the class JdbcFeatureStore method clear.
/**
* {@inheritDoc}
*/
@Override
public void clear() {
Connection sqlConn = null;
PreparedStatement ps = null;
try {
sqlConn = dataSource.getConnection();
ps = sqlConn.prepareStatement(getQueryBuilder().deleteAllCustomProperties());
ps.executeUpdate();
closeStatement(ps);
ps = null;
ps = sqlConn.prepareStatement(getQueryBuilder().deleteAllRoles());
ps.executeUpdate();
closeStatement(ps);
ps = null;
ps = sqlConn.prepareStatement(getQueryBuilder().deleteAllFeatures());
ps.executeUpdate();
closeStatement(ps);
ps = null;
} catch (SQLException sqlEX) {
throw new FeatureAccessException(CANNOT_CHECK_FEATURE_EXISTENCE_ERROR_RELATED_TO_DATABASE, sqlEX);
} finally {
closeStatement(ps);
closeConnection(sqlConn);
}
}
use of org.ff4j.exception.FeatureAccessException in project ff4j by ff4j.
the class JdbcFeatureStore method createCustomProperties.
/**
* Ease creation of properties in Database.
*
* @param uid
* target unique identifier
* @param props
* target properties.
*/
public void createCustomProperties(String uid, Collection<Property<?>> props) {
Util.assertNotNull(uid);
if (props == null)
return;
Connection sqlConn = null;
PreparedStatement ps = null;
Boolean previousAutoCommit = null;
try {
sqlConn = dataSource.getConnection();
// Begin TX
previousAutoCommit = sqlConn.getAutoCommit();
sqlConn.setAutoCommit(false);
// Queries
for (Property<?> pp : props) {
ps = createCustomProperty(sqlConn, uid, pp);
closeStatement(ps);
ps = null;
}
// End TX
sqlConn.commit();
} catch (SQLException sqlEX) {
rollback(sqlConn);
throw new FeatureAccessException(CANNOT_CHECK_FEATURE_EXISTENCE_ERROR_RELATED_TO_DATABASE, sqlEX);
} finally {
closeStatement(ps);
closeConnection(sqlConn, previousAutoCommit);
}
}
use of org.ff4j.exception.FeatureAccessException in project ff4j by ff4j.
the class PropertyStoreHttp method createProperty.
/**
* {@inheritDoc}
*/
public <T> void createProperty(Property<T> value) {
Util.assertNotNull(value);
Util.assertHasLength(value.getName());
if (existProperty(value.getName())) {
throw new PropertyAlreadyExistException("Property already exist");
}
/* Now can process upsert through PUT HTTP method
Response cRes = getStore().path(value.getName())//
.request(MediaType.APPLICATION_JSON)
.put(Entity.entity(new PropertyApiBean(value), MediaType.APPLICATION_JSON));*/
Response cRes = ClientHttpUtils.createRequest(getStore().path(value.getName()), authorization, null).put(Entity.entity(new PropertyApiBean(value), MediaType.APPLICATION_JSON));
// Check response code CREATED or raised error
if (Status.CREATED.getStatusCode() != cRes.getStatus()) {
throw new FeatureAccessException("Cannot create properties, an HTTP error " + cRes.getStatus() + OCCURED);
}
}
use of org.ff4j.exception.FeatureAccessException in project ff4j by ff4j.
the class FeatureStoreHttp method readGroup.
/**
* {@inheritDoc}
*/
public Map<String, Feature> readGroup(String groupName) {
Util.assertHasLength(groupName);
Response cRes = ClientHttpUtils.invokeGetMethod(getGroups().path(groupName), authorizationHeaderValue);
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.readEntity(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 disableGroup.
/**
* {@inheritDoc}
*/
@Override
public void disableGroup(String groupName) {
Util.assertHasLength(groupName);
Response cRes = ClientHttpUtils.invokePostMethod(getGroups().path(groupName).path(OPERATION_DISABLE), authorizationHeaderValue);
if (Status.NOT_FOUND.getStatusCode() == cRes.getStatus()) {
throw new GroupNotFoundException(groupName);
}
if (Status.NO_CONTENT.getStatusCode() != cRes.getStatus()) {
throw new FeatureAccessException(CANNOT_GRANT_ROLE_ON_FEATURE_AN_HTTP_ERROR + cRes.getStatus() + OCCURED);
}
}
Aggregations