/** {@inheritDoc} */ @Override public Map<String, Feature> readAll() { return target.readAll(); }
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(); }
/** {@inheritDoc} */ @Override public Map<String, Feature> readAll() { // Cannot be sure of whole cache - do not test any feature one-by-one : accessing FeatureStore return getTargetFeatureStore().readAll(); }
/** * Constructor from its feature store. * * @param featureStore * cuurent fature store */ public FeatureStoreApiBean(FeatureStore featureStore) { type = featureStore.getClass().getName(); if (featureStore instanceof FF4jCacheProxy) { cache = new CacheApiBean(featureStore); } features = new ArrayList<String>(featureStore.readAll().keySet()); groups = new ArrayList<String>(featureStore.readAllGroups()); numberOfFeatures = features.size(); numberOfGroups = groups.size(); }
/** * Read Features from store. * * @return get store features */ public Map<String, Feature> getFeatures() { return getFeatureStore().readAll(); }
Map<String, Feature> mapOfFeatures = ff4j.getFeatureStore().readAll(); List<String> featuresNames = Arrays.asList(mapOfFeatures.keySet().toArray(new String[0])); Collections.sort(featuresNames);
@GET @Path("/" + RESOURCE_FEATURES) @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value= "Display information regarding <b>Features</b>", response=FeatureApiBean.class) @ApiResponses(@ApiResponse(code = 200, message= "get all features")) public List < FeatureApiBean> readFeatures() { Feature[] storeContent = getFeatureStore().readAll().values().toArray(new Feature[0]); List < FeatureApiBean > apiBean = new ArrayList<FeatureApiBean>(); for (Feature feature : storeContent) { apiBean.add(new FeatureApiBean(feature)); } return apiBean; }
FeatureStore fs = ff4j.getConcreteFeatureStore(); this.featureStore = fs.getClass().getSimpleName(); this.nbFeature = fs.readAll().size(); this.nbGroup = fs.readAllGroups().size(); featureStore = featureStore.replaceAll("FeatureStore", "").toLowerCase();
public Collection<FeatureApiBean> getAllFeatures() { List<FeatureApiBean> features; Map<String, Feature> featureMap = ff4j.getFeatureStore().readAll(); if (CollectionUtils.isEmpty(featureMap)) { features = new ArrayList<FeatureApiBean>(0); } else { features = new ArrayList<FeatureApiBean>(featureMap.size()); for (Feature feature : featureMap.values()) { features.add(new FeatureApiBean(feature)); } } return features; }
public Collection<GroupDescApiBean> getAllGroups() { Map<String, GroupDescApiBean> groups = new HashMap<String, GroupDescApiBean>(); Map<String, Feature> featureMap = ff4j.getFeatureStore().readAll(); if (!CollectionUtils.isEmpty(featureMap)) { for (Feature feature : featureMap.values()) { initGroupMap(groups, feature.getUid(), feature.getGroup()); } } return groups.values(); }
/** * Access groups part of the API. * * @return groups resource */ @GET @Path("/" + RESOURCE_GROUPS) @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value= "Display information regarding <b>Groups</b>", response=GroupDescApiBean.class) @ApiResponses({@ApiResponse(code = 200, message="Groups resource", response=GroupDescApiBean.class)}) public List < GroupDescApiBean > readGroups() { Map< String, Feature > features = getFeatureStore().readAll(); Map< String , GroupDescApiBean > groups = new HashMap<String, GroupDescApiBean>(); if (features != null && !features.isEmpty()) { // Build groups from features for (Map.Entry<String,Feature> featureName : features.entrySet()) { String groupName = featureName.getValue().getGroup(); // Add current group to list if (groupName != null && !groupName.isEmpty()) { if (!groups.containsKey(groupName)) { groups.put(groupName, new GroupDescApiBean(groupName, new ArrayList<String>())); } groups.get(groupName).getFeatures().add(featureName.getKey()); } } } return new ArrayList<GroupDescApiBean>(groups.values()); }
/** * Check Number of features * * @param featureName * target featureName * @return current object */ public final AssertFf4j assertThatStoreHasSize(int expectedNumber) { Assert.assertEquals(expectedNumber, ff4j.getFeatureStore().readAll().size()); waitSomeSeconds(); return this; }
@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()); } }
/** * Build Http response when invoking export features. * * @param res * http response * @throws IOException * error when building response */ public static void exportFile(FF4j ff4j, HttpServletResponse res) throws IOException { Map<String, Feature> features = ff4j.getFeatureStore().readAll(); InputStream in = new XmlParser().exportFeatures(features); ServletOutputStream sos = null; try { sos = res.getOutputStream(); res.setContentType("text/xml"); res.setHeader("Content-Disposition", "attachment; filename=\"ff4j.xml\""); // res.setContentLength() org.apache.commons.io.IOUtils.copy(in, sos); LOGGER.info(features.size() + " features have been exported."); } finally { if (in != null) { in.close(); } if (sos != null) { sos.flush(); sos.close(); } } } }
/** * Export Feature through FF4J. * * @return * @throws IOException */ public InputStream exportFeatures() throws IOException { return new XmlParser().exportFeatures(getFeatureStore().readAll()); }
Map< String, Feature > mapOfFeatures = getFf4j().getFeatureStore().readAll(); StringBuilder sb = new StringBuilder("["); boolean first = true;
/** * Return status of all the features to calculate. * * @param currentStore * current store for features * @return current statuses for stores */ private Map<String, Boolean> getFeaturesStatus(FeatureStore currentStore, FlippingExecutionContext executionContext) { Map<String, Boolean> bools = new HashMap<String, Boolean>(); List<Feature> listOfFlip = new ArrayList<Feature>(); listOfFlip.addAll(currentStore.readAll().values()); for (Feature fp : listOfFlip) { if (fp.isEnable() && null != fp.getFlippingStrategy() && !(fp.getFlippingStrategy() instanceof ExpressionFlipStrategy)) { bools.put(fp.getUid(), fp.getFlippingStrategy().evaluate(fp.getUid(), currentStore, executionContext)); } else { bools.put(fp.getUid(), fp.isEnable()); } } return bools; }
Map < String, Feature > mapOfFeatures = sourceFeatureStore.readAll();
/** * TDD. */ @Test public void testReadAllFeatures() { // Given assertFf4j.assertThatFeatureExist(F4); assertFf4j.assertThatStoreHasSize(EXPECTED_FEATURES_NUMBERS); // When Map<String, Feature> features = testedStore.readAll(); // Then Assert.assertEquals(EXPECTED_FEATURES_NUMBERS, features.size()); // Then testing whole structure Feature f = features.get(F4); Assert.assertEquals(F4 + " does not exist", f.getUid(), F4); Assert.assertTrue("no description", f.getDescription() != null && !"".equals(f.getDescription())); Assert.assertTrue("no authorizations", f.getPermissions() != null && !f.getPermissions().isEmpty()); assertFf4j.assertThatFeatureHasRole(F4, ROLE_ADMIN); assertFf4j.assertThatFeatureIsInGroup(F4, G1); }
/** * 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); }