use of org.ff4j.exception.GroupNotFoundException in project ff4j by ff4j.
the class AbstractFeatureStore method removeFromGroup.
/**
* {@inheritDoc}
*/
@Override
public void removeFromGroup(String featureId, String groupName) {
Util.assertParamHasLength(groupName, "groupName (#2)");
if (!existGroup(groupName)) {
throw new GroupNotFoundException(groupName);
}
// retrieve
Feature f = read(featureId);
f.setGroup(null);
// persist modification
update(f);
}
use of org.ff4j.exception.GroupNotFoundException 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.GroupNotFoundException 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);
}
}
use of org.ff4j.exception.GroupNotFoundException in project ff4j by ff4j.
the class FeatureStoreHttp method removeFromGroup.
/**
* {@inheritDoc}
*/
@Override
public void removeFromGroup(String uid, String groupName) {
Util.assertHasLength(uid, groupName);
Response cRes = ClientHttpUtils.invokePostMethod(getStore().path(uid).path(OPERATION_REMOVEGROUP).path(groupName), authorizationHeaderValue);
if (Status.NOT_FOUND.getStatusCode() == cRes.getStatus()) {
throw new FeatureNotFoundException(uid);
}
if (Status.BAD_REQUEST.getStatusCode() == cRes.getStatus()) {
throw new GroupNotFoundException(groupName);
}
if (Status.NO_CONTENT.getStatusCode() != cRes.getStatus()) {
throw new FeatureAccessException("Cannot remove feature from group, an HTTP error " + cRes.getStatus() + OCCURED);
}
}
use of org.ff4j.exception.GroupNotFoundException in project ff4j by ff4j.
the class FeatureStoreMongoDB method disableGroup.
/**
* {@inheritDoc}
*/
@Override
public void disableGroup(String groupName) {
if (groupName == null || groupName.isEmpty()) {
throw new IllegalArgumentException(GROUPNAME_CANNOT_BE_NULL_NOR_EMPTY);
}
if (!existGroup(groupName)) {
throw new GroupNotFoundException(groupName);
}
for (DBObject dbObject : getFeaturesCollection().find(BUILDER.getGroupName(groupName))) {
Object enabledd = BUILDER.getEnable(false);
getFeaturesCollection().update(dbObject, BasicDBObjectBuilder.start(MONGO_SET, enabledd).get());
}
}
Aggregations