use of org.ff4j.exception.FeatureNotFoundException in project ff4j by ff4j.
the class FeatureStoreMongo method updateStatus.
/**
* Update status of feature.
*
* @param uid
* feature id
* @param enable
* enabler
*/
private void updateStatus(String uid, boolean enable) {
if (uid == null || uid.isEmpty()) {
throw new IllegalArgumentException(FEATURE_IDENTIFIER_CANNOT_BE_NULL_NOR_EMPTY);
}
if (!exist(uid)) {
throw new FeatureNotFoundException(uid);
}
Document target = BUILDER.getFeatUid(uid);
Object enabledd = BUILDER.getEnable(enable);
getFeaturesCollection().updateOne(target, new Document(MONGO_SET, enabledd));
}
use of org.ff4j.exception.FeatureNotFoundException in project ff4j by ff4j.
the class FeatureStoreMongo 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);
}
Document target = BUILDER.getFeatUid(uid);
Document nGroupName = BUILDER.getGroupName(groupName);
getFeaturesCollection().updateOne(target, new Document(MONGO_SET, nGroupName));
}
use of org.ff4j.exception.FeatureNotFoundException in project ff4j by ff4j.
the class FF4jResource method checkPOST.
/**
* Check if feature if flipped
*
* @param formParams
* target custom params
* @return
* boolean if feature if flipped
*/
@POST
@Path("/" + OPERATION_CHECK + "/{uid}")
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@ApiOperation(value = "<b>Advanced check</b> feature toggle (parameterized)", response = Boolean.class)
@ApiResponses({ @ApiResponse(code = 200, message = "if feature is flipped"), @ApiResponse(code = 400, message = "Invalid parameter") })
public Response checkPOST(@Context HttpHeaders headers, @PathParam("uid") String uid, MultivaluedMap<String, String> formParams) {
// HoldSecurity Context
FF4JSecurityContextHolder.save(securityContext);
if (!ff4j.getFeatureStore().exist(uid)) {
String errMsg = new FeatureNotFoundException(uid).getMessage();
return Response.status(Response.Status.NOT_FOUND).entity(errMsg).build();
}
// Flipping Strategy may expected some dedicated parameters if not present, will return 400
FlippingExecutionContext flipExecCtx = new FlippingExecutionContext();
for (String key : formParams.keySet()) {
flipExecCtx.putString(key, formParams.getFirst(key));
}
try {
boolean flipped = ff4j.check(uid, flipExecCtx);
return Response.ok(String.valueOf(flipped)).build();
} catch (IllegalArgumentException iae) {
String errMsg = "Invalid parameter " + iae.getMessage();
return Response.status(Response.Status.BAD_REQUEST).entity(errMsg).build();
}
}
use of org.ff4j.exception.FeatureNotFoundException in project ff4j by ff4j.
the class FeatureResource method operationRemoveRole.
/**
* Convenient method to update partially the feature: Here removing a role
*
* @return http response.
*/
@POST
@RolesAllowed({ ROLE_WRITE })
@Path("/" + OPERATION_REMOVEROLE + "/{role}")
@ApiOperation(value = "Remove a permission on a feature", response = Response.class)
@ApiResponses({ @ApiResponse(code = 204, message = "Permission has been granted"), @ApiResponse(code = 404, message = "Feature not found"), @ApiResponse(code = 400, message = "Invalid RoleName") })
public Response operationRemoveRole(@PathParam("uid") String id, @PathParam("role") String role) {
if (!ff4j.getFeatureStore().exist(id)) {
String errMsg = new FeatureNotFoundException(id).getMessage();
return Response.status(Response.Status.NOT_FOUND).entity(errMsg).build();
}
Set<String> permissions = ff4j.getFeatureStore().read(id).getPermissions();
if (!permissions.contains(role)) {
String errMsg = "Invalid role should be within " + permissions;
return Response.status(Response.Status.BAD_REQUEST).entity(errMsg).build();
}
getFeatureStore().removeRoleFromFeature(id, role);
return Response.noContent().build();
}
use of org.ff4j.exception.FeatureNotFoundException in project ff4j by ff4j.
the class MonitoringResource method getFeatureMonitoring.
/**
* Provide core information on store and available sub resources.
*/
@GET
@Path("/{uid}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Display <b>Monitoring</b> for a <b><u>single</u></b> feature", notes = "Each feature will display a pieChart and a barChart for hits", response = FeatureMonitoringApiBean.class)
@ApiResponses({ @ApiResponse(code = 200, message = "Status of current ff4j monitoring bean", response = FeatureMonitoringApiBean.class), @ApiResponse(code = 404, message = "Feature not found", response = String.class) })
public Response getFeatureMonitoring(@ApiParam(required = true, name = "uid", value = "Unique identifier of feature") @PathParam("uid") String uid, @ApiParam(required = false, name = "start", value = "Start of window <br>(default is today 00:00)") @QueryParam(PARAM_START) Long start, @ApiParam(required = false, name = "end", value = "End of window <br>(default is tomorrow 00:00)") @QueryParam(PARAM_END) Long end) {
if (!ff4j.getFeatureStore().exist(uid)) {
String errMsg = new FeatureNotFoundException(uid).getMessage();
return Response.status(Response.Status.NOT_FOUND).entity(errMsg).build();
}
// Today
Calendar c = Calendar.getInstance();
c.set(Calendar.HOUR_OF_DAY, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
if (start == null) {
start = c.getTimeInMillis();
}
// Tomorrow 00:00
Calendar c2 = Calendar.getInstance();
c2.setTime(new Date(System.currentTimeMillis() + 1000 * 3600 * 24));
c2.set(Calendar.HOUR_OF_DAY, 0);
c2.set(Calendar.MINUTE, 0);
c2.set(Calendar.SECOND, 0);
if (end == null) {
end = c2.getTimeInMillis();
}
// Build response
FeatureMonitoringApiBean fmab = new FeatureMonitoringApiBean(uid);
int hitcount = 0;
for (PieSectorApiBean sec : fmab.getEventsPie().getSectors()) {
hitcount += sec.getValue();
}
fmab.setHitCount(hitcount);
return Response.ok().entity(fmab).build();
}
Aggregations