/** {@inheritDoc} */ @Override public Feature read(String uid) { if (!exist(uid)) { throw new FeatureNotFoundException(uid); } return (Feature) getCache().get(uid).getObjectValue(); }
/** * 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(); }
/** {@inheritDoc} */ @Override public void disable(String uid) { Util.assertHasLength(uid); Response cRes = ClientHttpUtils.invokePostMethod( getStore().path(uid).path(OPERATION_DISABLE), authorizationHeaderValue); if (Status.NOT_FOUND.getStatusCode() == cRes.getStatus()) { throw new FeatureNotFoundException(uid); } }
/** * Convenient method to update partially the feature: Here enabling * * @return http response. */ @POST @Path("/" + OPERATION_UPDATE) @RolesAllowed({ROLE_WRITE}) @ApiOperation(value= "Update a property", response=Response.class) @ApiResponses({ @ApiResponse(code = 204, message= "Property has been updated"), @ApiResponse(code = 404, message= "Property not found"), @ApiResponse(code = 400, message= "Invalid new value") }) public Response operationUpdate(@PathParam("name") String name, @PathParam("groupName") String newValue) { if (!ff4j.getPropertiesStore().existProperty(name)) { String errMsg = new FeatureNotFoundException(name).getMessage(); return Response.status(Response.Status.NOT_FOUND).entity(errMsg).build(); } getPropertyStore().updateProperty(name, newValue); return Response.noContent().build(); }
/** {@inheritDoc} */ @Override public void grantRoleOnFeature(String uid, String roleName) { Util.assertHasLength(uid, roleName); Response cRes = ClientHttpUtils.invokePostMethod( getStore().path(uid).path(OPERATION_GRANTROLE).path(roleName), authorizationHeaderValue); if (Status.NOT_FOUND.getStatusCode() == cRes.getStatus()) { throw new FeatureNotFoundException(uid); } if (Status.NO_CONTENT.getStatusCode() != cRes.getStatus()) { throw new FeatureAccessException(CANNOT_GRANT_ROLE_ON_FEATURE_AN_HTTP_ERROR + cRes.getStatus() + OCCURED); } }
/** * 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(); }
/** {@inheritDoc} */ @Override public void removeRoleFromFeature(String uid, String roleName) { Util.assertHasLength(uid, roleName); Response cRes = ClientHttpUtils.invokePostMethod( getStore().path(uid).path(OPERATION_REMOVEROLE).path(roleName), authorizationHeaderValue); if (Status.NOT_FOUND.getStatusCode() == cRes.getStatus()) { throw new FeatureNotFoundException(uid); } if (Status.NO_CONTENT.getStatusCode() != cRes.getStatus()) { throw new FeatureAccessException("Cannot remove role on feature, an HTTP error " + cRes.getStatus() + OCCURED); } }
/** * 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(); }
/** {@inheritDoc} */ @Override public void enable(String uid) { Util.assertHasLength(uid); Response cRes = ClientHttpUtils.invokePostMethod( getStore().path(uid).path(OPERATION_ENABLE), authorizationHeaderValue); if (Status.NOT_FOUND.getStatusCode() == cRes.getStatus()) { throw new FeatureNotFoundException(uid); } }
/** * 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(); }
/** {@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); } }
/** * 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(); }
/** {@inheritDoc} */ @Override public void delete(String uid) { Util.assertHasLength(uid); Response cRes = ClientHttpUtils .invokeDeleteMethod(getStore().path(uid), authorizationHeaderValue); if (Status.NOT_FOUND.getStatusCode() == cRes.getStatus()) { throw new FeatureNotFoundException(uid); } if (Status.NO_CONTENT.getStatusCode() != cRes.getStatus()) { throw new FeatureAccessException("Cannot delete feature, an HTTP error " + cRes.getStatus() + OCCURED); } }
/** * Delete feature by its id. * * @return delete by its id. */ @DELETE @RolesAllowed({ROLE_WRITE}) @Produces(MediaType.TEXT_PLAIN) @ApiOperation(value= "Delete a Property", response=Response.class) @ApiResponses({ @ApiResponse(code = 404, message= "Property has not been found"), @ApiResponse(code = 204, message= "No content, Property is deleted"), @ApiResponse(code = 400, message= "Bad identifier"), }) public Response deleteProperty(@PathParam("name") String name) { if (name == null || "".equals(name)) { String errMsg = "Invalid URL : Must be '/properties/{name}' with {name} not null nor empty"; return Response.status(Response.Status.BAD_REQUEST).entity(errMsg).build(); } if (!ff4j.getPropertiesStore().existProperty(name)) { String errMsg = new FeatureNotFoundException(name).getMessage(); return Response.status(Response.Status.NOT_FOUND).entity(errMsg).build(); } getPropertyStore().deleteProperty(name); return Response.noContent().build(); }
/** {@inheritDoc} */ @Transactional public void grantRoleOnFeature(String uid, String roleName) { if (uid == null || uid.isEmpty()) { throw new IllegalArgumentException(FEATURE_IDENTIFIER_CANNOT_BE_NULL_NOR_EMPTY); } if (roleName == null || roleName.isEmpty()) { throw new IllegalArgumentException("roleName cannot be null nor empty"); } if (!exist(uid)) { throw new FeatureNotFoundException(uid); } getJdbcTemplate().update(getQueryBuilder().addRoleToFeature(), uid, roleName); }
/** * 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(); }
/** {@inheritDoc} */ @Transactional 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); } getJdbcTemplate().update(getQueryBuilder().addFeatureToGroup(), groupName, uid); }
/** * 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(); }
/** * Validate feature uid. * * @param uid * target uid */ protected void assertFeatureExist(String uid) { Util.assertHasLength(uid); if (!exist(uid)) { throw new FeatureNotFoundException(uid); } }
String errMsg = new FeatureNotFoundException(uid).getMessage(); return Response.status(Response.Status.NOT_FOUND).entity(errMsg).build();