use of org.ff4j.exception.FeatureNotFoundException 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.FeatureNotFoundException in project ff4j by ff4j.
the class FeatureStoreNeo4J method delete.
/**
* {@inheritDoc}
*/
@Override
public void delete(String uid) {
Util.assertHasLength(uid);
if (!exist(uid)) {
throw new FeatureNotFoundException(uid);
}
// Parameter
Map<String, Object> paramUID = new HashMap<>();
paramUID.put("uid", uid);
Transaction tx = graphDb.beginTx();
// Delete Flipping Strategy if it exists
graphDb.execute(QUERY_CYPHER_DELETE_STRATEGY_FEATURE, paramUID);
// Delete Related Property if exist
graphDb.execute(QUERY_CYPHER_DELETE_PROPERTIES_FEATURE, paramUID);
// Check group
Result result = graphDb.execute(QUERY_CYPHER_GETGROUPNAME, paramUID);
if (result.hasNext()) {
String groupName = (String) result.next().get(GROUPNAME);
Map<String, Object> paramGroupName = new HashMap<>();
paramGroupName.put(GROUP_NAME, groupName);
result = graphDb.execute(QUERY_CYPHER_COUNT_FEATURE_OF_GROUP, paramGroupName);
if (result.hasNext()) {
long nbFeature = (long) result.next().get(QUERY_CYPHER_ALIAS);
if (nbFeature == 1) {
// This is the last feature of this Group => delete the GROUP
graphDb.execute(QUERY_CYPHER_DELETE_GROUP_FEATURE, paramUID);
}
}
}
// Delete feature
graphDb.execute(QUERY_CYPHER_DELETE_FEATURE, paramUID);
tx.success();
}
use of org.ff4j.exception.FeatureNotFoundException in project ff4j by ff4j.
the class FeatureStoreMongoDB method addToGroup.
/**
* {@inheritDoc}
*/
@Override
public void addToGroup(String uid, String groupName) {
if (uid == null || uid.isEmpty()) {
throw new IllegalArgumentException(FEATURE_IDENTIFIER_CANNOT_BE_NULL_NOR_EMPTY);
}
if (groupName == null || groupName.isEmpty()) {
throw new IllegalArgumentException(GROUPNAME_CANNOT_BE_NULL_NOR_EMPTY);
}
if (!exist(uid)) {
throw new FeatureNotFoundException(uid);
}
DBObject target = BUILDER.getFeatUid(uid);
DBObject nGroupName = BUILDER.getGroupName(groupName);
getFeaturesCollection().update(target, BasicDBObjectBuilder.start(MONGO_SET, nGroupName).get());
}
use of org.ff4j.exception.FeatureNotFoundException in project ff4j by ff4j.
the class FeatureStoreMongoDB method updateStatus.
/**
* Update status of feature.
*
* @param uid
* feature id
* @param enable
* enabler
*/
private void updateStatus(String uid, boolean enable) {
Util.assertParamHasLength(uid, "uid (feature identifier");
if (!exist(uid)) {
throw new FeatureNotFoundException(uid);
}
DBObject target = BUILDER.getFeatUid(uid);
Object enabledd = BUILDER.getEnable(enable);
getFeaturesCollection().update(target, BasicDBObjectBuilder.start(MONGO_SET, enabledd).get());
}
use of org.ff4j.exception.FeatureNotFoundException in project ff4j by ff4j.
the class FeatureStoreSpringJdbc method read.
/**
* {@inheritDoc}
*/
public Feature read(String uid) {
Util.assertHasLength(uid);
try {
Feature feature = getJdbcTemplate().queryForObject(getQueryBuilder().getFeature(), FMAPPER, uid);
readProperties(feature);
readPermissions(feature);
return feature;
} catch (EmptyResultDataAccessException ex) {
throw new FeatureNotFoundException(uid, ex);
}
}
Aggregations