private String createUpdateCoreFeature(Feature fp) { StringBuilder cypherUpdate = new StringBuilder("MATCH (f:" + FF4jNeo4jLabels.FF4J_FEATURE + " { uid:'"); cypherUpdate.append(fp.getUid()); cypherUpdate.append("' }) "); cypherUpdate.append("SET f.enable = " + fp.isEnable()); if (fp.getDescription() != null && fp.getDescription().length() > 0) { cypherUpdate.append(", f.description = '"); cypherUpdate.append(fp.getDescription()); cypherUpdate.append("'"); } if (fp.getPermissions() != null && fp.getPermissions().size() > 0) { cypherUpdate.append(", f.roles = ["); boolean first = true; for(String role : fp.getPermissions()) { if (!first) { cypherUpdate.append(","); } cypherUpdate.append("'" + role + "'"); first = false; } cypherUpdate.append("]"); } else { // AS role is null cypherUpdate.append(", f.roles = []"); } cypherUpdate.append(";"); return cypherUpdate.toString(); }
private String createQueryNewCoreFeature(Feature fp) { StringBuilder cypherCreate = new StringBuilder("CREATE ("); cypherCreate.append("f:" + FF4jNeo4jLabels.FF4J_FEATURE + " { uid :'"); cypherCreate.append(fp.getUid()); cypherCreate.append("', enable:"); cypherCreate.append(fp.isEnable()); if (fp.getDescription() != null && fp.getDescription().length() > 0) { cypherCreate.append(", description:'"); cypherCreate.append(fp.getDescription()); cypherCreate.append("'"); } if (fp.getPermissions() != null && fp.getPermissions().size() > 0) { cypherCreate.append(", roles: ["); boolean first = true; for(String role : fp.getPermissions()) { if (!first) { cypherCreate.append(","); } cypherCreate.append("'" + role + "'"); first = false; } cypherCreate.append("]"); } cypherCreate.append("});"); return cypherCreate.toString(); }
sb.append("\r\n"); for (Map.Entry<String, Feature> feat : ff4j.getFeatureStore().readAll().entrySet()) { sb.append("\r\n /* Feature '" + feat.getKey() + "' : '" + feat.getValue().getDescription() + "' */"); sb.append("\r\n String FEATURE_" + feat.getKey().replaceAll(" ", "_").toUpperCase() + " = \"" + feat.getKey() + "\";");
sb.append(MessageFormat.format(XML_FEATURE, feat.getUid(), feat.getDescription(), feat.isEnable()));
if (null != currentFeature.getDescription()) { sb.append(" tooltip=\""); sb.append(currentFeature.getDescription()); sb.append("\""); sb.append(" data-desc=\"" + currentFeature.getDescription() + "\""); sb.append(" data-group=\"" + currentFeature.getGroup() + "\""); sb.append(" data-strategy=\"");
/** * TDD. */ @Test public void testReadFullFeature() { // Given assertFf4j.assertThatFeatureExist(F4); // When Feature f = testedStore.read(F4); // Then Assert.assertEquals(f.getUid(), F4); Assert.assertTrue(f.getDescription() != null && !"".equals(f.getDescription())); Assert.assertTrue(f.getPermissions() != null && !f.getPermissions().isEmpty()); assertFf4j.assertThatFeatureHasRole(F4, ROLE_ADMIN); assertFf4j.assertThatFeatureIsInGroup(F4, G1); }
byte[] desc = (fp.getDescription() == null) ? null : Bytes.toBytes(fp.getDescription()); put.addColumn(B_FEATURES_CF_CORE, B_FEAT_DESCRIPTION, desc);
/** * 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); }
private void createCoreFeature(Feature fp) { // Transaction wraps the method, could pipe several sql queries String strategyColumn = null; String expressionColumn = null; if (fp.getFlippingStrategy() != null) { strategyColumn = fp.getFlippingStrategy().getClass().getName(); expressionColumn = MappingUtil.fromMap(fp.getFlippingStrategy().getInitParams()); } getJdbcTemplate().update(getQueryBuilder().createFeature(), fp.getUid(), fp.isEnable() ? 1 : 0, fp.getDescription(), strategyColumn, expressionColumn, fp.getGroup()); }
/** {@inheritDoc} */ @Override public void create(Feature fp) { assertFeatureNotNull(fp); assertFeatureNotExist(fp.getUid()); // Convert map<String, Property> to map<String, String>, structure in DB Map < String, String > mapOfProperties = new HashMap<String, String>(); if (fp.getCustomProperties() != null && !fp.getCustomProperties().isEmpty()) { for (Map.Entry<String, Property<?>> customP : fp.getCustomProperties().entrySet()) { if (customP.getValue() != null) { mapOfProperties.put(customP.getKey(), customP.getValue().toJson()); } } } conn.getSession().execute(getBuilder().cqlCreateFeature(), fp.getUid(), fp.isEnable() ? 1 : 0, fp.getDescription(), JsonUtils.flippingStrategyAsJson(fp.getFlippingStrategy()), fp.getGroup(), fp.getPermissions(), mapOfProperties); }
public FeatureApiBean(Feature f) { this.uid = f.getUid(); this.enable = f.isEnable(); this.description = f.getDescription(); this.group = f.getGroup(); this.permissions = new ArrayList<String>(f.getPermissions()); if (f.getFlippingStrategy() != null) { this.flippingStrategy = new FlippingStrategyApiBean(f.getFlippingStrategy()); } if (f.getCustomProperties() != null) { for (Property<?> ap1 : f.getCustomProperties().values()) { customProperties.put(ap1.getName(), new PropertyApiBean(ap1)); } } }
/** * TDD. */ @Test public void testUpdateFeatureCoreData() { // Parameters String newDescription = "new-description"; FlippingStrategy newStrategy = new PonderationStrategy(0.12); // Given assertFf4j.assertThatFeatureExist(F1); Assert.assertFalse(newDescription.equals(testedStore.read(F1).getDescription())); // When Feature fpBis = testedStore.read(F1); fpBis.setDescription(newDescription); fpBis.setFlippingStrategy(newStrategy); testedStore.update(fpBis); // Then Feature updatedFeature = testedStore.read(F1); Assert.assertTrue(newDescription.equals(updatedFeature.getDescription())); Assert.assertNotNull(updatedFeature.getFlippingStrategy()); Assert.assertEquals(newStrategy.toString(), updatedFeature.getFlippingStrategy().toString()); }
/** * Copy constructor. * * @param f * * target feature */ public FeatureApiBean(Feature f) { this.uid = f.getUid(); this.enable = f.isEnable(); this.description = f.getDescription(); this.group = f.getGroup(); this.permissions = new ArrayList<String>(f.getPermissions()); if (f.getFlippingStrategy() != null) { this.flippingStrategy = new FlippingStrategyApiBean(f.getFlippingStrategy()); } if (f.getCustomProperties() != null) { for (Property<?> ap1 : f.getCustomProperties().values()) { customProperties.put(ap1.getName(), new PropertyApiBean(ap1)); } } }
ps.setString(1, fp.getUid()); ps.setInt(2, fp.isEnable() ? 1 : 0); ps.setString(3, fp.getDescription()); String strategyColumn = null; String expressionColumn = null;
/** * Copy constructor. * * @param f * current feature */ public Feature(final Feature f) { this(f.getUid(), f.isEnable(), f.getDescription(), f.getGroup()); this.permissions.addAll(f.getPermissions()); // Flipping Strategy if (f.getFlippingStrategy() != null) { this.flippingStrategy = MappingUtil.instanceFlippingStrategy(f.getUid(), f.getFlippingStrategy().getClass().getName(), f.getFlippingStrategy().getInitParams()); } // Custom Properties if (f.getCustomProperties() != null && !f.getCustomProperties().isEmpty()) { for(Property<?> p : f.getCustomProperties().values()) { Property<?> targetProp = PropertyFactory.createProperty( p.getName(), p.getType(), p.asString(), p.getDescription(), null); if (p.getFixedValues() != null) { for(Object o : p.getFixedValues()) { targetProp.add2FixedValueFromString(o.toString()); } } this.getCustomProperties().put(targetProp.getName(), targetProp); } } }
enable, fp.getDescription(), fStrategy, fExpression, fp.getGroup(), fp.getUid());
@Override public Document toStore(Feature feature) { String strategyColumn = null; String expressionColumn = null; if (feature.getFlippingStrategy() != null) { strategyColumn = feature.getFlippingStrategy().getClass().getName(); expressionColumn = MappingUtil.fromMap(feature.getFlippingStrategy().getInitParams()); } String customProperties = null; if (feature.getCustomProperties() != null) { customProperties = JsonUtils.customPropertiesAsJson(feature.getCustomProperties()); } return new FeatureDocumentBuilder().addFeatUid(feature.getUid()).// addEnable(feature.isEnable()).// addDescription(feature.getDescription()).// addGroupName(feature.getGroup()).// addStrategy(strategyColumn).// addExpression(expressionColumn).// addCustomProperties(customProperties). // addRoles(feature.getPermissions()).build(); }
/** * Convert {@link Feature} to {@link DBObject}. * * @param feature * target feature. * @return document in mongo db */ public DBObject toDBObject(Feature feature) { String strategyColumn = null; String expressionColumn = null; if (feature.getFlippingStrategy() != null) { strategyColumn = feature.getFlippingStrategy().getClass().getName(); expressionColumn = MappingUtil.fromMap(feature.getFlippingStrategy().getInitParams()); } String customProperties = null; if (feature.getCustomProperties() != null) { customProperties = JsonUtils.customPropertiesAsJson(feature.getCustomProperties()); } return new FeatureDBObjectBuilder().addFeatUid(feature.getUid()).// addEnable(feature.isEnable()).// addDescription(feature.getDescription()).// addGroupName(feature.getGroup()).// addStrategy(strategyColumn).// addExpression(expressionColumn).// addCustomProperties(customProperties). addRoles(feature.getPermissions()).build(); }