org.ff4j.core.Feature.getFlippingStrategy()方法的使用及代码示例

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

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

Feature.getFlippingStrategy介绍

[英]Getter accessor for attribute 'flippingStrategy'.
[中]属性“flippingStrategy”的Getter访问器。

代码示例

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

private String createQueryFlippingStrategy(Feature fp) {
  String fsCreateQuery = "MATCH  (f:FF4J_FEATURE {uid:'" + fp.getUid() + "'}) ";
  fsCreateQuery += "CREATE (fs:FF4J_FLIPPING_STRATEGY { type:'";
  fsCreateQuery += fp.getFlippingStrategy().getClass().getName();
  fsCreateQuery += "', initParams: [";
  Map < String, String > initParams = fp.getFlippingStrategy().getInitParams();
  if (initParams != null && initParams.size() > 0) {
    boolean first = true;
    for (Map.Entry < String, String > entry : initParams.entrySet()) {
      if (!first) {
        fsCreateQuery += ",";
      }
      fsCreateQuery += "'" + entry.getKey() + "=" + entry.getValue() + "'";
      first = false;
    }
  }
  fsCreateQuery += "]})-[:" + FF4jNeo4jRelationShips.STRATEGY_OF + "]->(f);";
  return fsCreateQuery;
}

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

private String createUpdateFlippingStrategy(Feature fp) {
  String queryUpdate = "MATCH (f:" + FF4jNeo4jLabels.FF4J_FEATURE + " { uid: '";
  queryUpdate += fp.getUid() + "' })--(s:FF4J_FLIPPING_STRATEGY) ";
  queryUpdate += "SET s.type='";
  queryUpdate += fp.getFlippingStrategy().getClass().getName();
  queryUpdate += "', s.initParams= [";
  Map < String, String > initParams = fp.getFlippingStrategy().getInitParams();
    if (initParams != null && initParams.size() > 0) {
    boolean first = true;
    for (Map.Entry < String, String > entry : initParams.entrySet()) {
      if (!first) {
        queryUpdate += ",";
      }
      queryUpdate += "'" + entry.getKey() + "=" + entry.getValue() + "'";
      first = false;
    }
  }
  queryUpdate += "];";
  return queryUpdate;
}

代码示例来源: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

/**
 * 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

Feature feature = mapOfFeatures.get(featuName);
orderedFeatures.add(feature);
FlippingStrategy strategyTargered = feature.getFlippingStrategy();
if (strategyTargered!=null) {
  if (mapOfStrategyUsed.get(strategyTargered.getClass().getSimpleName()) != null) {

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

/**
 * Check existence of the traget feature
 * 
 * @param featureName
 *            targte featurename
 * @return current object
 */
public final AssertFf4j assertThatFeatureDoesNotHaveFlippingStrategy(String featureName) {
  Assert.assertNull(FEATURE + featureName + "' must not have a flipping strategy",
      ff4j.getFeature(featureName).getFlippingStrategy());
  waitSomeSeconds();
  return this;
}

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

/**
 * Check existence of the traget feature
 * 
 * @param featureName
 *            targte featurename
 * @return current object
 */
public final AssertFf4j assertThatFeatureHasFlippingStrategy(String featureName) {
  Assert.assertNotNull(FEATURE + featureName + "' must have a FlippingStrategy but doesn't",
      ff4j.getFeature(featureName).getFlippingStrategy());
  waitSomeSeconds();
  return this;
}

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

FlippingStrategy fs = feat.getFlippingStrategy();
if (null != fs) {
  sb.append("   <" + FLIPSTRATEGY_TAG + " class=\"" + fs.getClass().getName() + "\" >\n");

代码示例来源: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

/**
 * Elegant way to ask for flipping.
 * 
 * @param featureID
 *            feature unique identifier.
 * @param executionContext
 *            current execution context
 * @return current feature status
 */
public boolean check(String featureID, FlippingExecutionContext executionContext) {
  Feature fp = getFeature(featureID);
  boolean flipped = fp.isEnable();
  // If authorization manager provided, apply security filter
  if (flipped && getAuthorizationsManager() != null) {
    flipped = isAllowed(fp);
  }
  // If custom strategy has been defined, delegate flipping to
  if (flipped && fp.getFlippingStrategy() != null) {
    flipped = fp.getFlippingStrategy().evaluate(featureID, getFeatureStore(), executionContext);
  }
  
  // Update current context
  currentExecutionContext.set(executionContext);
  
  // Any access is logged into audit system
  publishCheck(featureID, flipped);
  return flipped;
}

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

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

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

Bytes.toBytes(JsonUtils.flippingStrategyAsJson(fp.getFlippingStrategy())));

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

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

代码示例来源: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

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

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

String strategyColumn = null;
String expressionColumn = null;
if (fp.getFlippingStrategy() != null) {
  strategyColumn   = fp.getFlippingStrategy().getClass().getName();
  expressionColumn = MappingUtil.fromMap(fp.getFlippingStrategy().getInitParams());

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

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

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

/**
 * Create, update or delete Flipping Strategy
 */
private void updateFlippingStrategy(Feature fp) {
  Transaction tx2 = graphDb.beginTx();
  // Create or update FlippingStrategy (as provided)
  Map<String, Object> queryParameters = new HashMap<>();
  queryParameters.put("uid", fp.getUid());
  if (fp.getFlippingStrategy() != null) {
    Result flippingNode = graphDb.execute(QUERY_CYPHER_GET_FLIPPINGSTRATEGY, queryParameters);
    if (flippingNode.hasNext()) {
      graphDb.execute(createUpdateFlippingStrategy(fp));
    } else {
      graphDb.execute(createQueryFlippingStrategy(fp));
    }
  } else {
    // Delete flipping strategy if exist (as null)
    graphDb.execute(QUERY_CYPHER_DELETE_STRATEGY_FEATURE, queryParameters);
  }
  tx2.success();
}

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

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

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

/** {@inheritDoc} */
@Override
public void create(Feature fp) {
  if (fp == null) {
    throw new IllegalArgumentException("Feature cannot be null nor empty");
  }
  if (exist(fp.getUid())) {
    throw new FeatureAlreadyExistException(fp.getUid());
  }
  Transaction tx = graphDb.beginTx();
  // Create core
  graphDb.execute(createQueryNewCoreFeature(fp));
  // Create Flipping Strategy
  if (fp.getFlippingStrategy() != null) {
    graphDb.execute(createQueryFlippingStrategy(fp));
  }
  // Create Group
  if (fp.getGroup() != null && !"".equals(fp.getGroup())) {
    addToGroup(fp.getUid(), fp.getGroup());
  }
  tx.success();
  // Create Properties
  if (fp.getCustomProperties() != null && fp.getCustomProperties().size() > 0) {
    for (String pName : fp.getCustomProperties().keySet()) {
      createProperty(fp.getProperty(pName), fp.getUid());
    }
  }
}

相关文章