org.ff4j.core.Feature类的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(154)

本文整理了Java中org.ff4j.core.Feature类的一些代码示例,展示了Feature类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Feature类的具体详情如下:
包路径:org.ff4j.core.Feature
类名称:Feature

Feature介绍

[英]Represents a feature flag identified by an unique identifier.

Features Flags or Features Toggle have been introduced by Martin Fowler for continuous delivery perspective. It consists of enable/disable some functionalities at runtime.

SecurityManagement : Even a feature is enabled, you can limit its usage to a group of users (for instance BETA Tester) before wide over all your users.
[中]表示由唯一标识符标识的特征标志。
Martin Fowler为连续交付透视图引入了功能标志或功能切换。它包括在运行时启用/禁用某些功能。
SecurityManagement:即使启用了某个功能,您也可以在覆盖所有用户之前将其使用限制在一组用户(例如BETA-Tester)。

代码示例

代码示例来源:origin: ff4j/ff4j

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));
    }
  }
}

代码示例来源:origin: ff4j/ff4j

@SuppressWarnings("unchecked")
private static Feature parseFeatureMap(Map<String, Object> fMap) {
  Feature f = new Feature((String) fMap.get("uid"));
  f.setEnable((Boolean) fMap.get("enable"));
  f.setDescription((String) fMap.get("description"));
  f.setGroup((String) fMap.get("group"));
  // permissions
  List<String> perm = (ArrayList<String>) fMap.get("permissions");
  f.setPermissions(new HashSet<String>());
  if (perm != null) {
    f.getPermissions().addAll(perm);
  }
  // flipping strategy
  f.setFlippingStrategy(parseFlipStrategy(f.getUid(), (LinkedHashMap<String, Object>) fMap.get("flippingStrategy")));
  // custom properties
  Map <String, Object > propertyMap = (Map < String, Object >) fMap.get("customProperties");
  f.setCustomProperties(parseCustomProperties(propertyMap));
  return f;
}

代码示例来源:origin: stackoverflow.com

for (String item : items)
{
 Feature feature = new Feature();
 feature.setName(item);
 session.save(feature);
}

代码示例来源:origin: ff4j/ff4j

/**
 * Allow to update feature.
 *
 * @param featureId
 */
private void updateFeature(HttpServletRequest req, String featureId) {
  Feature old = ff4j.getFeatureStore().read(featureId);
  // Core
  Feature fp = new Feature(featureId, old.isEnable());
  fp.setPermissions(old.getPermissions());
  fp.setCustomProperties(old.getCustomProperties());
  fp.setFlippingStrategy(buildFlippingStrategy(req, fp.getUid()));
  
  // Description
  final String featureDesc = req.getParameter(DESCRIPTION);
  if (Util.hasLength(featureDesc)) {
    fp.setDescription(featureDesc);
  }
  // GroupName
  final String groupName = req.getParameter(GROUPNAME);
  if (Util.hasLength(groupName)) {
    fp.setGroup(groupName);
  }
  // Creation
  ff4j.getFeatureStore().update(fp);
}

代码示例来源:origin: ff4j/ff4j

Feature feature = new Feature(uid);
  feature.setEnable(enable.getAsBoolean());
  feature.setDescription(description.getAsString());
  feature.setGroup(group.getAsString());
  Set<String> auths = gson.fromJson(permissions, new TypeToken<HashSet<String>>() {
  }.getType());
  feature.setPermissions(auths);
  Map<String, String> initParams = (Map<String, String>) flippingStrategyParameters.get("initParams");
  feature.setFlippingStrategy(MappingUtil.instanceFlippingStrategy(uid, flippingStrategyType, initParams));
    feature.addProperty(property);

代码示例来源:origin: ff4j/ff4j

Feature fout = new Feature(uid);
fout.setDescription(
    Bytes.toString(result.getValue(B_FEATURES_CF_CORE, B_FEAT_DESCRIPTION)));
fout.setEnable(
    Bytes.toBoolean(result.getValue(B_FEATURES_CF_CORE, B_FEAT_ENABLE)));
fout.setGroup(
    Bytes.toString(result.getValue(B_FEATURES_CF_CORE, B_FEAT_GROUPNAME)));
if ("null".equals(fout.getGroup())) {
  fout.setGroup(null);
fout.setPermissions(FeatureJsonParser.parsePermissions(
    Bytes.toString(result.getValue(B_FEATURES_CF_CORE, B_FEAT_ROLES))));
fout.setFlippingStrategy(FeatureJsonParser.parseFlipStrategyAsJson(uid,
    Bytes.toString(result.getValue(B_FEATURES_CF_CORE, B_FEAT_STRATEGY))));
  fout.getCustomProperties().put(
    Bytes.toString(property.getKey()), 
    PropertyJsonParser.parseProperty(

代码示例来源:origin: ff4j/ff4j

/** {@inheritDoc} */
@Override
public Feature fromStore(Document document) {
  String featUid = document.getString(FEATURE_UUID);
  boolean status = document.getBoolean(FEATURE_ENABLE);
  Feature f = new Feature(featUid, status);
  f.setDescription(document.getString(FEATURE_DESCRIPTION));
  f.setGroup(document.getString(FEATURE_GROUPNAME));
  f.setPermissions(mapAuthorization(document));
  f.setFlippingStrategy(mapStrategy(featUid, document));
  f.setCustomProperties(mapCustomProperties(document));
  return f;
}

代码示例来源:origin: ff4j/ff4j

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());
}

代码示例来源:origin: ff4j/ff4j

Feature fp = new Feature(featureId, old.isEnable());
  fp.setDescription(featureDesc);
  fp.setGroup(groupName);
  fp.setPermissions(permissions);

代码示例来源:origin: ff4j/ff4j

Feature f = new Feature(uid, enable, parseDescription(nnm));
  f.setFlippingStrategy(parseFlipStrategy((Element) flipStrategies.item(0), f.getUid()));
  f.setPermissions(parseListAuthorizations((Element) securities.item(0)));
  f.setCustomProperties(parsePropertiesTag((Element) properties.item(0)));

代码示例来源:origin: ff4j/ff4j

/** {@inheritDoc} */
@Override
public void update(Feature fp) {
  if (fp == null) {
    throw new IllegalArgumentException("Feature cannot be null");
  }
  if (!exist(fp.getUid())) {
    throw new FeatureNotFoundException(fp.getUid());
  }
  getCache().put(new Element(fp.getUid(), fp));
}

代码示例来源:origin: ff4j/ff4j

/** {@inheritDoc} */
@Override
public Feature mapRow(ResultSet rs, int rowNum) throws SQLException {
  String featUid = rs.getString(COL_FEAT_UID);
  
  Feature f = new Feature(featUid, rs.getInt(COL_FEAT_ENABLE) > 0);
  f.setDescription(rs.getString(COL_FEAT_DESCRIPTION));
  f.setGroup(rs.getString(COL_FEAT_GROUPNAME));
  // Build Flipping Strategy From DataBase
  String strategy = rs.getString(COL_FEAT_STRATEGY);
  if (strategy != null && !"".equals(strategy)) {
    Map < String, String > initParams = MappingUtil.toMap(rs.getString(COL_FEAT_EXPRESSION));
    FlippingStrategy flipStrategy = MappingUtil.instanceFlippingStrategy(featUid, strategy, initParams);
    f.setFlippingStrategy(flipStrategy);
  }
  return f;
  
 
}

代码示例来源:origin: ff4j/ff4j

public FeatureActions createOrUpdateFeature(String featureUID, FeatureApiBean featureApiBean) {
  featureValidator.assertFeatureUIDIsNotBlank(featureApiBean.getUid());
  featureValidator.assertFeatureIdsMatch(featureUID, featureApiBean.getUid());
  Feature feature = new Feature(featureUID);
  feature.setDescription(featureApiBean.getDescription());
  feature.setEnable(featureApiBean.isEnable());
  feature.setGroup(featureApiBean.getGroup());
  feature.setPermissions(new HashSet<String>(featureApiBean.getPermissions()));
  initFlippingStrategy(featureApiBean, feature);
  initProperties(featureApiBean, feature);
  if (ff4j.getFeatureStore().exist(featureUID)) {
    ff4j.getFeatureStore().update(feature);
    return FeatureActions.UPDATED;
  } else {
    ff4j.getFeatureStore().create(feature);
    return FeatureActions.CREATED;
  }
}

代码示例来源:origin: ff4j/ff4j

/** {@inheritDoc} */
public void grantRoleOnFeature(String uid, String roleName) {
  assertFeatureExist(uid);
  assertHasLength(roleName);
  featuresMap.get(uid).getPermissions().add(roleName);
}

代码示例来源:origin: ff4j/ff4j

/** {@inheritDoc} */
@Override
public Set<String> readAllGroups() {
  Set<String> groups = new HashSet<String>();
  for (Map.Entry<String, Feature> entry : readAll().entrySet()) {
    if (null != entry.getValue().getGroup()) {
      groups.add(entry.getValue().getGroup());
    }
  }
  return groups;
}

代码示例来源:origin: ff4j/ff4j

/**
 * Return status of all the features to calculate.
 * 
 * @param currentStore
 *            current store for features
 * @return current statuses for stores
 */
private Map<String, Boolean> getFeaturesStatus(FeatureStore currentStore,
                        FlippingExecutionContext executionContext) {
  Map<String, Boolean> bools = new HashMap<String, Boolean>();
  List<Feature> listOfFlip = new ArrayList<Feature>();
  listOfFlip.addAll(currentStore.readAll().values());
  for (Feature fp : listOfFlip) {
    if (fp.isEnable() && 
      null != fp.getFlippingStrategy() &&
      !(fp.getFlippingStrategy() instanceof ExpressionFlipStrategy)) {
      bools.put(fp.getUid(), fp.getFlippingStrategy().evaluate(fp.getUid(), currentStore, executionContext));
    } else {
      bools.put(fp.getUid(), fp.isEnable());
    }
  }
  return bools;
}

代码示例来源:origin: ff4j/ff4j

/**
 * 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());
}

代码示例来源:origin: ff4j/ff4j

/** {@inheritDoc} */
@Override
public void addToGroup(String featureId, String groupName) {
  Util.assertParamHasLength(groupName, "groupName (#2)");
  // retrieve
  Feature f = read(featureId);
  f.setGroup(groupName);
  // persist modification
  update(f);
}

代码示例来源:origin: ff4j/ff4j

/**
 * Query children roles.
 *
 * @param fp
 */
private void readPermissions(Feature fp) {
  fp.getPermissions().addAll(
      getJdbcTemplate().query(getQueryBuilder().getRoles(), 
          new SingleColumnRowMapper<String>(), fp.getUid()));
}

代码示例来源:origin: ff4j/ff4j

public Collection<GroupDescApiBean> getAllGroups() {
  Map<String, GroupDescApiBean> groups = new HashMap<String, GroupDescApiBean>();
  Map<String, Feature> featureMap = ff4j.getFeatureStore().readAll();
  if (!CollectionUtils.isEmpty(featureMap)) {
    for (Feature feature : featureMap.values()) {
      initGroupMap(groups, feature.getUid(), feature.getGroup());
    }
  }
  return groups.values();
}

相关文章