use of org.ff4j.property.Property in project ff4j by ff4j.
the class FeatureStoreCassandra method mapFeatureRow.
protected Feature mapFeatureRow(Row row) {
Feature f = new Feature(row.getString(FEATURES_ATT_UID));
f.setDescription(row.getString(FEATURES_ATT_DESCRIPTION));
f.setEnable(row.getBoolean(FEATURES_ATT_ENABLED));
f.setGroup(row.getString(FEATURES_ATT_GROUPNAME));
f.setPermissions(row.getSet(FEATURES_ATT_ROLES, String.class));
// Flipping Strategy
UdtValue udtStrat = row.getUdtValue(FEATURES_ATT_STRATEGY);
if (null != udtStrat) {
String className = udtStrat.getString(UDT_STRATEGY_CLASS);
Map<String, String> initparams = udtStrat.getMap(UDT_STRATEGY_PARAMS, String.class, String.class);
f.setFlippingStrategy(MappingUtil.instanceFlippingStrategy(f.getUid(), className, initparams));
}
// Custom Properties
Map<String, UdtValue> mapOfProperties = row.getMap(FEATURES_ATT_PROPERTIES, String.class, UdtValue.class);
if (mapOfProperties != null) {
Map<String, Property<?>> customProperties = new HashMap<String, Property<?>>();
for (UdtValue udt : mapOfProperties.values()) {
String propName = udt.getString(UDT_PROPERTY_UID);
String propClass = udt.getString(UDT_PROPERTY_CLASS);
String propDesc = udt.getString(UDT_PROPERTY_DESCRIPTION);
String propVal = udt.getString(UDT_PROPERTY_VALUE);
Set<String> fixV = udt.getSet(UDT_PROPERTY_FIXEDVALUES, String.class);
Property<?> p = PropertyFactory.createProperty(propName, propClass, propVal, propDesc, fixV);
customProperties.put(p.getName(), p);
}
f.setCustomProperties(customProperties);
}
return f;
}
use of org.ff4j.property.Property in project ff4j by ff4j.
the class PropertyStoreEhCache method readAllProperties.
/**
* {@inheritDoc}
*/
@Override
public Map<String, Property<?>> readAllProperties() {
Map<String, Property<?>> myMap = new HashMap<String, Property<?>>();
if (wrapper.getCacheProperties().getKeys() != null) {
for (Object key : wrapper.getCacheProperties().getKeys()) {
Element element = wrapper.getCacheProperties().get(key);
if (element != null) {
Property<?> p = (Property<?>) wrapper.getCacheProperties().get(key).getObjectValue();
myMap.put((String) key, p);
}
}
}
return myMap;
}
use of org.ff4j.property.Property in project ff4j by ff4j.
the class PropertyFactory method createProperty.
/**
* Factory method to create property.
*
* @param pName
* property name.
* @param pType
* property type
* @param pValue
* property value
* @return
*/
public static Property<?> createProperty(String pName, Object value) {
Util.assertHasLength(pName);
Util.assertNotNull(value);
if (validPropertyPrimitives.containsKey(value.getClass())) {
return PropertyFactory.createProperty(pName, validPropertyPrimitives.get(value.getClass()).getName(), String.valueOf(value), null, null);
}
if (value instanceof Date) {
return PropertyFactory.createProperty(pName, PropertyDate.class.getName(), PropertyDate.SDF.format(value), null, null);
}
if (value instanceof Calendar) {
Date valueDate = ((Calendar) value).getTime();
return PropertyFactory.createProperty(pName, PropertyCalendar.class.getName(), PropertyCalendar.SDF.format(valueDate), null, null);
}
if (value instanceof Property<?>) {
return (Property<?>) value;
}
// String Value
if (value.getClass().isArray() || Util.isCollection(value)) {
return PropertyFactory.createProperty(pName, PropertyString.class.getName(), Util.join(Util.asCollection(value), ","), null, null);
}
throw new IllegalArgumentException("Cannot create property with input type " + value.getClass() + value.toString());
}
use of org.ff4j.property.Property in project ff4j by ff4j.
the class XmlParser method exportFeaturesPart.
/**
* Export Features part of the XML.
*
* @param mapOfFeatures
* current map of feaures.
*
* @return
* all XML
*/
private String exportFeaturesPart(Map<String, Feature> mapOfFeatures) {
// Create <features>
StringBuilder sb = new StringBuilder(BEGIN_FEATURES);
// Recreate Groups
Map<String, List<Feature>> featuresPerGroup = new HashMap<String, List<Feature>>();
if (mapOfFeatures != null && !mapOfFeatures.isEmpty()) {
for (Feature feat : mapOfFeatures.values()) {
String groupName = feat.getGroup();
if (!featuresPerGroup.containsKey(groupName)) {
featuresPerGroup.put(groupName, new ArrayList<Feature>());
}
featuresPerGroup.get(groupName).add(feat);
}
}
for (Map.Entry<String, List<Feature>> groupName : featuresPerGroup.entrySet()) {
// / Building featureGroup
if (null != groupName.getKey() && !groupName.getKey().isEmpty()) {
sb.append(" <" + FEATUREGROUP_TAG + " " + FEATUREGROUP_ATTNAME + "=\"" + groupName.getKey() + "\" >\n\n");
}
// Loop on feature
for (Feature feat : groupName.getValue()) {
sb.append(MessageFormat.format(XML_FEATURE, feat.getUid(), escapeXML(feat.getDescription()), feat.isEnable()));
// <security>
if (null != feat.getPermissions() && !feat.getPermissions().isEmpty()) {
sb.append(" <" + SECURITY_TAG + ">\n");
for (String auth : feat.getPermissions()) {
sb.append(MessageFormat.format(XML_AUTH, escapeXML(auth)));
}
sb.append(" </" + SECURITY_TAG + ">\n");
}
// <flipstrategy>
FlippingStrategy fs = feat.getFlippingStrategy();
if (null != fs) {
sb.append(" <" + FLIPSTRATEGY_TAG + " class=\"" + fs.getClass().getName() + "\" >\n");
for (String p : fs.getInitParams().keySet()) {
sb.append(" <" + FLIPSTRATEGY_PARAMTAG + " " + FLIPSTRATEGY_PARAMNAME + "=\"");
sb.append(p);
sb.append("\" " + FLIPSTRATEGY_PARAMVALUE + "=\"");
// Escape special characters to build XML
// https://github.com/clun/ff4j/issues/63
String paramValue = fs.getInitParams().get(p);
sb.append(escapeXML(paramValue));
sb.append("\" />\n");
}
sb.append(" </" + FLIPSTRATEGY_TAG + ">\n");
}
// <custom-properties>
Map<String, Property<?>> props = feat.getCustomProperties();
if (props != null && !props.isEmpty()) {
sb.append(BEGIN_CUSTOMPROPERTIES);
sb.append(buildPropertiesPart(feat.getCustomProperties()));
sb.append(END_CUSTOMPROPERTIES);
}
sb.append(END_FEATURE);
}
if (null != groupName.getKey() && !groupName.getKey().isEmpty()) {
sb.append(" </" + FEATUREGROUP_TAG + ">\n\n");
}
}
sb.append(END_FEATURES);
return sb.toString();
}
use of org.ff4j.property.Property in project ff4j by ff4j.
the class GeneratorUtils method generateInterfaceConstantsSource.
/**
* Generate target Java Interface.
*
* @param ff4j
* current ff4J bean
* @return
* data as inputstream
* @throws IOException
* error occu
*/
public static String generateInterfaceConstantsSource(FF4j ff4j) {
Util.assertNotNull(ff4j);
StringBuilder sb = new StringBuilder();
sb.append("/**\r\n * Constants for ff4j features and properties.");
sb.append("\r\n * Generated on : " + new SimpleDateFormat("yyyy-MM-DD HH:mm").format(new Date()));
sb.append("\r\n *");
sb.append("\r\n * @author FF4J Generator Engine");
sb.append("\r\n */");
sb.append("\r\npublic interface FF4jConstants {");
sb.append("\r\n");
sb.append("\r\n // -------------------------");
sb.append("\r\n // Features ");
sb.append("\r\n // -------------------------");
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("\r\n");
}
sb.append("\r\n // -------------------------");
sb.append("\r\n // Groups ");
sb.append("\r\n // -------------------------");
sb.append("\r\n");
for (String groupName : ff4j.getFeatureStore().readAllGroups()) {
sb.append("\r\n /* Group '" + groupName + "' */");
sb.append("\r\n String FEATURE_GROUP_" + groupName.replaceAll(" ", "_").toUpperCase() + " = \"" + groupName + "\";");
sb.append("\r\n");
}
sb.append("\r\n // -------------------------");
sb.append("\r\n // Properties ");
sb.append("\r\n // -------------------------");
sb.append("\r\n");
for (Map.Entry<String, Property<?>> prop : ff4j.getPropertiesStore().readAllProperties().entrySet()) {
sb.append("\r\n /* Property '" + prop.getKey() + "' : '" + prop.getValue().getDescription() + "' */");
sb.append("\r\n String PROPERTY_" + prop.getKey().replaceAll(" ", "_").toUpperCase() + " = \"" + prop.getKey() + "\";");
sb.append("\r\n");
}
sb.append("\r\n}");
return sb.toString();
}
Aggregations