/** * Constructor initializing ff4j with an InMemoryStore using an InputStream. Simplify integration with Android through * <code>Asset</code> */ public FF4j(InputStream xmlFileResourceAsStream) { this.fstore = new InMemoryFeatureStore(xmlFileResourceAsStream); }
/** {@inheritDoc} */ public void removeFromGroup(String uid, String groupName) { assertFeatureExist(uid); assertGroupExist(groupName); Feature feat = read(uid); feat.setGroup(""); update(feat); }
/** {@inheritDoc} */ public void create(Feature fp) { assertFeatureNotNull(fp); assertFeatureNotExist(fp.getUid()); updateFeature(fp); }
/** * Constructor with full set of feature. * * @param maps */ public InMemoryFeatureStore(Map<String, Feature> maps) { createSchema(); this.featuresMap = maps; buildGroupsFromFeatures(); }
/** * Constructor with inputstream fileName. * * @param fileName * fileName present in classPath or on fileSystem. */ public InMemoryFeatureStore(InputStream xmlIN) { createSchema(); loadConf(xmlIN); }
/** {@inheritDoc} */ public void enableGroup(String groupName) { assertGroupExist(groupName); for (String feat : featureGroups.get(groupName)) { this.enable(feat); } }
/** {@inheritDoc} */ public void update(Feature fp) { assertFeatureNotNull(fp); Feature fpExist = read(fp.getUid()); // Checking new roles Set<String> toBeAdded = new HashSet<String>(); toBeAdded.addAll(fp.getPermissions()); toBeAdded.removeAll(fpExist.getPermissions()); for (String addee : toBeAdded) { // Will fail if invalid userrole grantRoleOnFeature(fpExist.getUid(), addee); } updateFeature(fp); }
/** {@inheritDoc} **/ protected void postProcess(final BeanDefinitionBuilder definitionBuilder, final Element ff4jTag) { super.postProcess(definitionBuilder, ff4jTag); logger.debug("Initialization from <ff4j:ff4j> TAG"); // If filename is present ff4j will be initialized with both features and properties inmemory. if (StringUtils.hasLength(ff4jTag.getAttribute(ATT_FF4J_FILENAME))) { String fileName = ff4jTag.getAttribute(ATT_FF4J_FILENAME); InMemoryFeatureStore imfs = new InMemoryFeatureStore(fileName); InMemoryPropertyStore imps = new InMemoryPropertyStore(fileName); definitionBuilder.getBeanDefinition().getPropertyValues().addPropertyValue("featureStore", imfs); definitionBuilder.getBeanDefinition().getPropertyValues().addPropertyValue("propertiesStore", imps); logger.debug("... Setting in-memory stores : " + imfs.readAll().size() + " feature(s), " + imps.readAllProperties().size() + " propertie(s)"); } if (StringUtils.hasLength(ff4jTag.getAttribute(ATT_FF4J_AUTOCREATE))) { String autocreate = ff4jTag.getAttribute(ATT_FF4J_AUTOCREATE); logger.debug("... Setting autocreate property to '" + autocreate + "'"); } if (StringUtils.hasLength(ff4jTag.getAttribute(ATT_FF4J_AUTH_MANAGER))) { String authManagerBeanId = ff4jTag.getAttribute(ATT_FF4J_AUTH_MANAGER); RuntimeBeanReference refSolution = new RuntimeBeanReference(authManagerBeanId); definitionBuilder.getBeanDefinition().getPropertyValues().addPropertyValue("authorizationsManager", refSolution); logger.debug("... Setting authorizationManager with " + authManagerBeanId); } logger.debug("... Initialization done"); } }
/** {@inheritDoc} */ public void disableGroup(String groupName) { assertGroupExist(groupName); for (String feat : featureGroups.get(groupName)) { this.disable(feat); } }
/** {@inheritDoc} */ public void delete(String uid) { assertFeatureExist(uid); featuresMap.remove(uid); buildGroupsFromFeatures(); }
/** * Constructor with configuration fileName. * * @param fileName * fileName present in classPath or on fileSystem. */ public InMemoryFeatureStore(String fileName) { if (fileName == null || fileName.isEmpty()) { throw new IllegalArgumentException( "fileName is required, cannot be null nor empty : the file must exist in classpath"); } createSchema(); loadConfFile(fileName); }
/** {@inheritDoc} */ public Map<String, Feature> readGroup(String groupName) { assertGroupExist(groupName); // Retrieve feature per feature (in-memory, no overhead) Map<String, Feature> features = new HashMap<String, Feature>(); for (String feat : featureGroups.get(groupName)) { features.put(feat, this.read(feat)); } return features; }
/** {@inheritDoc} */ public Feature read(String uid) { assertFeatureExist(uid); return featuresMap.get(uid); }
/** * Unique update point to force group construction. * * @param fp * Target feature to update */ private void updateFeature(Feature fp) { featuresMap.put(fp.getUid(), fp); buildGroupsFromFeatures(); }
/** {@inheritDoc} */ public void disable(String uid) { assertFeatureExist(uid); featuresMap.get(uid).disable(); }
/** * Load configuration through FF4J.vml file. * * @param conf * xml filename */ private void loadConf(InputStream xmlIN) { if (xmlIN == null) { throw new IllegalArgumentException("Cannot parse feature stream"); } this.featuresMap = new XmlParser().parseConfigurationFile(xmlIN).getFeatures(); buildGroupsFromFeatures(); }
/** * Constructor initializing ff4j with an InMemoryStore */ public FF4j(String xmlFile) { this.fstore = new InMemoryFeatureStore(xmlFile); this.pStore = new InMemoryPropertyStore(xmlFile); }
/** {@inheritDoc} */ public void enable(String uid) { assertFeatureExist(uid); featuresMap.get(uid).enable(); }
/** {@inheritDoc} */ @Before public void setUp() throws Exception { ff4j = new FF4j(); ff4j.setFeatureStore(new InMemoryFeatureStore("test-ff4j-features.xml")); ff4j.setPropertiesStore(new InMemoryPropertyStore("test-ff4j-features.xml")); ff4j.setEventRepository(initRepository()); repo = ff4j.getEventRepository(); }
/** {@inheritDoc} */ public void grantRoleOnFeature(String uid, String roleName) { assertFeatureExist(uid); assertHasLength(roleName); featuresMap.get(uid).getPermissions().add(roleName); }