use of org.ff4j.conf.XmlConfig in project ff4j by ff4j.
the class ConsoleOperations method importFile.
/**
* User action to import Features from a properties files.
*
* @param in
* inpustream from configuration file
* @throws IOException
* Error raised if the configuration cannot be read
*/
public static void importFile(FF4j ff4j, InputStream in) throws IOException {
FeatureStore store = ff4j.getFeatureStore();
XmlConfig xmlConfig = new XmlParser().parseConfigurationFile(in);
Map<String, Feature> mapsOfFeat = xmlConfig.getFeatures();
for (Entry<String, Feature> feature : mapsOfFeat.entrySet()) {
if (store.exist(feature.getKey())) {
store.update(feature.getValue());
} else {
store.create(feature.getValue());
}
}
LOGGER.info(mapsOfFeat.size() + " features have been imported.");
PropertyStore pstore = ff4j.getPropertiesStore();
Map<String, Property<?>> mapsOfProperties = xmlConfig.getProperties();
for (Entry<String, Property<?>> p : mapsOfProperties.entrySet()) {
if (pstore.existProperty(p.getKey())) {
pstore.updateProperty(p.getValue());
} else {
pstore.createProperty(p.getValue());
}
}
LOGGER.info(mapsOfProperties.size() + " features have been imported.");
}
use of org.ff4j.conf.XmlConfig in project ff4j by ff4j.
the class AbstractFeatureStore method importFeaturesFromXmlFile.
/**
* Initialize store from XML Configuration File.
*
* @param xmlConfFile
* xml configuration file
*/
public Map<String, Feature> importFeaturesFromXmlFile(String xmlConfFile) {
// Argument validation
if (xmlConfFile == null || xmlConfFile.isEmpty()) {
throw new IllegalArgumentException("Configuration filename cannot be null nor empty");
}
// Load as Inputstream
InputStream xmlIS = getClass().getClassLoader().getResourceAsStream(xmlConfFile);
if (xmlIS == null) {
throw new IllegalArgumentException("File " + xmlConfFile + " could not be read, please check path and rights");
}
// Use the Feature Parser
XmlConfig conf = new XmlParser().parseConfigurationFile(xmlIS);
Map<String, Feature> features = conf.getFeatures();
importFeatures(features.values());
return features;
}
use of org.ff4j.conf.XmlConfig in project ff4j by ff4j.
the class FeatureXmlParserTest method testParsingProperties.
@Test
public void testParsingProperties() throws IOException {
// Given
XmlParser parser = new XmlParser();
InputStream in = getClass().getClassLoader().getResourceAsStream("ff4j-parser-properties.xml");
// When
XmlConfig conf = parser.parseConfigurationFile(in);
// Then
Map<String, Feature> features = conf.getFeatures();
Assert.assertNotNull(features);
// Then
Map<String, Property<?>> properties = conf.getProperties();
Assert.assertNotNull(properties);
}
use of org.ff4j.conf.XmlConfig in project ff4j by ff4j.
the class FeatureXmlParserTest method importThenExportALL.
@Test
public void importThenExportALL() throws IOException {
// Given
XmlParser parser = new XmlParser();
InputStream in = getClass().getClassLoader().getResourceAsStream("ff4j-parser-all.xml");
XmlConfig conf = parser.parseConfigurationFile(in);
Assert.assertNotNull(conf.getFeatures());
Assert.assertNotNull(conf.getProperties());
// When
InputStream in3 = parser.exportAll(conf);
// Then
XmlConfig conf2 = parser.parseConfigurationFile(in3);
Assert.assertNotNull(conf2.getFeatures());
Assert.assertNotNull(conf2.getProperties());
}
Aggregations