/** * User action to create a new Feature. * * @param req http request containing operation parameters */ private void opCreateFeature(FeatureStore store, HttpServletRequest req) { // uid final String featureId = req.getParameter(FEATID); if (featureId != null && !featureId.isEmpty()) { Feature fp = new Feature(featureId, false); // Description final String featureDesc = req.getParameter(DESCRIPTION); if (null != featureDesc && !featureDesc.isEmpty()) { fp.setDescription(featureDesc); } // GroupName final String groupName = req.getParameter(GROUPNAME); if (null != groupName && !groupName.isEmpty()) { fp.setGroup(groupName); } // Strategy final String strategy = req.getParameter(STRATEGY); if (null != strategy && !strategy.isEmpty()) { try { Class<?> strategyClass = Class.forName(strategy); FlippingStrategy fstrategy = (FlippingStrategy) strategyClass.newInstance(); final String strategyParams = req.getParameter(STRATEGY_INIT); if (null != strategyParams && !strategyParams.isEmpty()) { Map<String, String> initParams = new HashMap<String, String>(); String[] params = strategyParams.split(";"); for (String currentP : params) { String[] cur = currentP.split("="); if (cur.length < 2) { throw new IllegalArgumentException( "Invalid Syntax : param1=val1,val2;param2=val3,val4"); } initParams.put(cur[0], cur[1]); } fstrategy.init(featureId, initParams); } fp.setFlippingStrategy(fstrategy); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("Cannot find strategy class", e); } catch (InstantiationException e) { throw new IllegalArgumentException("Cannot instanciate strategy", e); } catch (IllegalAccessException e) { throw new IllegalArgumentException("Cannot instanciate : no public constructor", e); } } populateFeatureWithPermissions(fp, req); // Creation store.create(fp); log.info(featureId + " has been created"); } }
/** * 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 */ private void opImportFile(FeatureStore store, InputStream in) throws IOException { Map<String, Feature> mapsOfFeat = new XmlParser().parseConfigurationFile(in).getFeatures(); for (Entry<String, Feature> feature : mapsOfFeat.entrySet()) { if (store.exist(feature.getKey())) { store.update(feature.getValue()); } else { store.create(feature.getValue()); } } log.info(mapsOfFeat.size() + " features have been imported."); }