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); }
/** * TDD. */ @Test public void testEnableGroup() { // Given testedStore.disable(F2); testedStore.addToGroup(F2, G0); assertFf4j.assertThatFeatureIsDisabled(F2); assertFf4j.assertThatFeatureIsInGroup(F2, G0); // When testedStore.enableGroup(G0); // Then assertFf4j.assertThatFeatureIsEnabled(F2); // Reinit testedStore.disable(F2); }
/** * TDD. */ @Test(expected = IllegalArgumentException.class) public void testEnableNull() { // Given // When testedStore.enable(null); // Then, expected error... }
public FeatureStoreApiBean(FeatureStore featureStore) { type = featureStore.getClass().getName(); if (featureStore instanceof FF4jCacheProxy) { cache = new CacheApiBean(featureStore); } features.addAll(featureStore.readAll().keySet()); groups.addAll(featureStore.readAllGroups()); numberOfFeatures = features.size(); numberOfGroups = groups.size(); }
@Test public void testClear() { // Given Assert.assertNotNull(testedStore); Map<String, Feature> before = testedStore.readAll(); Assert.assertFalse(before.isEmpty()); // When testedStore.clear(); // Then Assert.assertTrue(testedStore.readAll().isEmpty()); /// Reinit for (Map.Entry<String, Feature> pName : before.entrySet()) { testedStore.create(pName.getValue()); } }
getFf4j().getFeatureStore().delete(featureId); msg = featureId + " has been DELETED"; Set< String> featureNames = getFf4j().getFeatureStore().readAll().keySet(); if (featureNames.contains(newName)) { msgType = "warning"; msg = "Cannot rename " + featureId + " to " + newName + " : it already exists"; } else { Feature newFeature = getFf4j().getFeatureStore().read(featureId); newFeature.setUid(newName); getFf4j().getFeatureStore().delete(featureId); getFf4j().getFeatureStore().create(newFeature); msg = "Feature " + featureId + " has been renamed to " + newName; Set< String> featureNames = getFf4j().getFeatureStore().readAll().keySet(); if (featureNames.contains(newName)) { msgType = "warning"; msg = "Cannot copy " + featureId + " with name " + newName + " : it already exists"; } else { Feature newFeature = new Feature(getFf4j().getFeatureStore().read(featureId)); newFeature.setUid(newName); getFf4j().getFeatureStore().create(newFeature); msg = "Feature " + featureId + " has been copied to " + newName; String operationGroup = req.getParameter(SUBOPERATION); if (OP_ENABLE.equalsIgnoreCase(operationGroup)) { getFf4j().getFeatureStore().enableGroup(groupName); msg = groupName + " has been ENABLED"; LOGGER.info("Group '" + groupName + "' has been ENABLED.");
/** * TDD. */ @Test public void testDeleteFeature() throws Exception { // Given assertFf4j.assertThatFeatureExist(F1); Feature tmpf1 = testedStore.read(F1); int initialNumber = testedStore.readAll().size(); // When testedStore.delete(F1); // Then assertFf4j.assertThatStoreHasSize(initialNumber - 1); assertFf4j.assertThatFeatureDoesNotExist(F1); // End, Reinit initial state testedStore.create(tmpf1); assertFf4j.assertThatFeatureExist(F1); }
/** * 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 Feature read(String uid) { return target.read(uid); }
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; } }
private void processCommandEnableGroup(String commandLine, boolean enable) { try { CommandLine cmd = CMD_PARSER.parse(enableGroupOptions(), commandLine.split(" ")); if (cmd.getArgList().size() != 1 || !cmd.hasOption("g") ) { logWarn("Invalid command, expecting enableGroup/disableGroup -f <groupName>"); } else { String groupName = cmd.getOptionValue('g'); if (!currentFF4J.getFeatureStore().existGroup(groupName)) { logWarn("Group [" + groupName + "] not found"); } else if (enable){ currentFF4J.getFeatureStore().enableGroup(groupName); logInfo("Group " + groupName + " is now enabled") ; } else { currentFF4J.getFeatureStore().disableGroup(groupName); logInfo("Group " + groupName + " is now disabled") ; } } } catch (ParseException e) { error(e, ERROR_DURING_CONNECT_COMMAND); } }
/** * 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(); }
/** * TDD. */ @Test(expected = IllegalArgumentException.class) public void testDisableNull() { // Given // When testedStore.disable(null); // Then, expected error... }
/** * 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 boolean exist(String uid) { return target.exist(uid); }
/** * TDD. */ @Test(expected = IllegalArgumentException.class) public void testGrantRoleNullRole() throws Exception { // Given // When testedStore.grantRoleOnFeature(F1, null); // Then, expected error... }
/** * TDD. */ @Test(expected = IllegalArgumentException.class) public void testRemoveRoleEmptyFeature() throws Exception { // Given // When testedStore.removeRoleFromFeature("", ROLE_ADMIN); // Then, expected error... }
/** * 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(); }
/** * Disable Feature. * * @param featureID * unique feature identifier. */ public FF4j disable(String featureID) { try { getFeatureStore().disable(featureID); } catch (FeatureNotFoundException fnfe) { if (this.autocreate) { getFeatureStore().create(new Feature(featureID, false)); } else { throw fnfe; } } return this; }
/** * Enable Feature. * * @param featureID * unique feature identifier. */ public FF4j enable(String featureID) { try { getFeatureStore().enable(featureID); } catch (FeatureNotFoundException fnfe) { if (this.autocreate) { getFeatureStore().create(new Feature(featureID, true)); } else { throw fnfe; } } return this; }