/** {@inheritDoc} */ @Override public boolean exist(String uid) { return target.exist(uid); }
/** * Convenient method to update partially the feature: Removing from a group * * @return http response. */ @POST @RolesAllowed({ROLE_WRITE}) @Path("/" + OPERATION_REMOVEGROUP + "/{groupName}") @ApiOperation(value= "Remove the group of the feature", response=Response.class) @ApiResponses({ @ApiResponse(code = 204, message= "Group has been removed"), @ApiResponse(code = 404, message= "Feature not found"), @ApiResponse(code = 400, message= "Invalid GroupName") }) public Response operationRemoveGroup(@PathParam("uid") String id, @PathParam("groupName") String groupName) { if (!ff4j.getFeatureStore().exist(id)) { String errMsg = new FeatureNotFoundException(id).getMessage(); return Response.status(Response.Status.NOT_FOUND).entity(errMsg).build(); } // Expected behaviour is no error even if invalid groupname // .. but invalid if group does not exist... if (!ff4j.getFeatureStore().existGroup(groupName)) { String errMsg = "Invalid groupName should be " + groupName; return Response.status(Response.Status.BAD_REQUEST).entity(errMsg).build(); } getFeatureStore().removeFromGroup(id, groupName); return Response.noContent().build(); }
/** * Check if target feature exist. * * @param featureId * unique feature identifier. * @return flag to check existence of */ public boolean exist(String featureId) { return getFeatureStore().exist(featureId); }
private Feature readFeature(Field field, String featureName, boolean required) { if (!ff4j.getFeatureStore().exist(featureName)) { if (required) { throw new IllegalArgumentException("Cannot autowiring field '" + field.getName() + "' with FF4J property as" + " target feature has not been found"); } else { logger.warn("Feature '" + featureName + "' has not been found but not required"); return null; } } return ff4j.getFeatureStore().read(featureName); }
@Test(expected = IllegalArgumentException.class) public void testExistNull() { ff4j.getFeatureStore().exist(null); }
@Test(expected = IllegalArgumentException.class) public void testExistEmpty() { ff4j.getFeatureStore().exist(""); }
/** * Convenient method to update partially the feature: Adding to a group * * @return http response. */ @POST @RolesAllowed({ROLE_WRITE}) @Path("/" + OPERATION_ADDGROUP + "/{groupName}" ) @ApiOperation(value= "Define the group of the feature", response=Response.class) @ApiResponses({ @ApiResponse(code = 204, message= "Group has been defined"), @ApiResponse(code = 404, message= "Feature not found"), @ApiResponse(code = 400, message= "Invalid GroupName") }) public Response operationAddGroup(@PathParam("uid") String id, @PathParam("groupName") String groupName) { if (!ff4j.getFeatureStore().exist(id)) { String errMsg = new FeatureNotFoundException(id).getMessage(); return Response.status(Response.Status.NOT_FOUND).entity(errMsg).build(); } if ("".equals(groupName)) { String errMsg = "Invalid groupName should not be null nor empty"; return Response.status(Response.Status.BAD_REQUEST).entity(errMsg).build(); } getFeatureStore().addToGroup(id, groupName); return Response.noContent().build(); }
/** * Convenient method to update partially the feature: Here disabling * * @return http response. */ @POST @Path("/" + OPERATION_DISABLE) @RolesAllowed({ROLE_WRITE}) @ApiOperation(value= "Disable a feature", response=Response.class) @ApiResponses({ @ApiResponse(code = 204, message= "Features has been disabled"), @ApiResponse(code = 404, message= "Feature not found") }) public Response operationDisable(@PathParam("uid") String id) { if (!ff4j.getFeatureStore().exist(id)) { String errMsg = new FeatureNotFoundException(id).getMessage(); return Response.status(Response.Status.NOT_FOUND).entity(errMsg).build(); } getFeatureStore().disable(id); return Response.noContent().build(); }
/** * Convenient method to update partially the feature: Here enabling * * @return http response. */ @POST @Path("/" + OPERATION_ENABLE) @RolesAllowed({ROLE_WRITE}) @ApiOperation(value= "Enable a feature", response=Response.class) @ApiResponses({ @ApiResponse(code = 204, message= "Features has been enabled"), @ApiResponse(code = 404, message= "Feature not found") }) public Response operationEnable(@PathParam("uid") String id) { if (!ff4j.getFeatureStore().exist(id)) { String errMsg = new FeatureNotFoundException(id).getMessage(); return Response.status(Response.Status.NOT_FOUND).entity(errMsg).build(); } getFeatureStore().enable(id); return Response.noContent().build(); }
/** * Check if feature if flipped * * @param formParams * target custom params * @return * boolean if feature if flipped */ @GET @Path("/" + OPERATION_CHECK + "/{uid}") @Produces(MediaType.TEXT_PLAIN) @ApiOperation(value= "<b>Simple check</b> feature toggle", response=Boolean.class) @ApiResponses({ @ApiResponse(code = 200, message= "if feature is flipped"), @ApiResponse(code = 400, message= "Invalid parameter"), @ApiResponse(code = 404, message= "feature has not been found")}) public Response check(@Context HttpHeaders headers, @PathParam("uid") String uid) { // HoldSecurity Context FF4JSecurityContextHolder.save(securityContext); // Expected Custom FlipStrategy (JSON) if (!ff4j.getFeatureStore().exist(uid)) { String errMsg = new FeatureNotFoundException(uid).getMessage(); return Response.status(Response.Status.NOT_FOUND).entity(errMsg).build(); } return Response.ok(String.valueOf(ff4j.check(uid))).build(); }
/** * Convenient method to update partially the feature: Here grant a role * * @return http response. */ @POST @RolesAllowed({ROLE_WRITE}) @Path("/" + OPERATION_GRANTROLE + "/{role}" ) @ApiOperation(value= "Grant 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 operationGrantRole(@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(); } if ("".equals(role)) { String errMsg = "Invalid role should not be null nor empty"; return Response.status(Response.Status.BAD_REQUEST).entity(errMsg).build(); } getFeatureStore().grantRoleOnFeature(id, role); return Response.noContent().build(); }
/** * Delete feature by its id. * * @return delete by its id. */ @DELETE @RolesAllowed({ROLE_WRITE}) @Produces(MediaType.TEXT_PLAIN) @ApiOperation(value= "Delete a feature", response=Response.class) @ApiResponses({ @ApiResponse(code = 404, message= "Feature has not been found"), @ApiResponse(code = 204, message= "No content, feature is deleted"), @ApiResponse(code = 400, message= "Bad identifier"), }) public Response deleteFeature(@PathParam("uid") String id) { if (id == null || "".equals(id)) { String errMsg = "Invalid URL : Must be '/features/{uid}' with {uid} not null nor empty"; return Response.status(Response.Status.BAD_REQUEST).entity(errMsg).build(); } if (!ff4j.getFeatureStore().exist(id)) { String errMsg = new FeatureNotFoundException(id).getMessage(); return Response.status(Response.Status.NOT_FOUND).entity(errMsg).build(); } getFeatureStore().delete(id); return Response.noContent().build(); }
/** * Allows to retrieve feature by its id. * * @param featId * target feature identifier * @return feature is exist */ @GET @RolesAllowed({ROLE_READ}) @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value= "Read information about a feature", response=FeatureApiBean.class) @ApiResponses({ @ApiResponse(code = 200, message= "Information about features"), @ApiResponse(code = 404, message= "Feature not found") }) public Response read(@PathParam("uid") String id) { if (!ff4j.getFeatureStore().exist(id)) { String errMsg = new FeatureNotFoundException(id).getMessage(); return Response.status(Response.Status.NOT_FOUND).entity(errMsg).build(); } return Response.ok(new FeatureApiBean(ff4j.getFeatureStore().read(id))).build(); }
/** * 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(); }
/** {@inheritDoc} */ @Override public boolean exist(String featureId) { // not in cache but maybe created from last access if (getCacheManager().getFeature(featureId) == null) { return getTargetFeatureStore().exist(featureId); } return true; }
@Override @ManagedOperation(description = "Test if a feature exists based on its identifier") @ManagedOperationParameters({@ManagedOperationParameter(name = "feature_UID", description = "Identifier of feature to test")}) public boolean exist(String feature_UID) { return internalStore.exist(feature_UID); }
Map<String, Feature> mapsOfFeat = xmlConfig.getFeatures(); for (Entry<String, Feature> feature : mapsOfFeat.entrySet()) { if (store.exist(feature.getKey())) { store.update(feature.getValue()); } else {
String feature = cmd.getOptionValue('f'); String role = cmd.getOptionValue('r'); if (!currentFF4J.getFeatureStore().exist(feature)) { logWarn("Feature does not exist, nothing updated"); } else {
} else { String featureName = cmd.getOptionValue('f'); if (!currentFF4J.getFeatureStore().exist(featureName)) { logWarn("Feature [" + featureName + "] not found");
public FeatureActions createOrUpdateFeature(String featureUID, FeatureApiBean featureApiBean) { featureValidator.assertFeatureUIDIsNotBlank(featureApiBean.getUid()); featureValidator.assertFeatureIdsMatch(featureUID, featureApiBean.getUid()); Feature feature = new Feature(featureUID); feature.setDescription(featureApiBean.getDescription()); feature.setEnable(featureApiBean.isEnable()); feature.setGroup(featureApiBean.getGroup()); feature.setPermissions(new HashSet<String>(featureApiBean.getPermissions())); initFlippingStrategy(featureApiBean, feature); initProperties(featureApiBean, feature); if (ff4j.getFeatureStore().exist(featureUID)) { ff4j.getFeatureStore().update(feature); return FeatureActions.UPDATED; } else { ff4j.getFeatureStore().create(feature); return FeatureActions.CREATED; } }