コード例 #1
0
  @Override
  public boolean isActive(FeatureState state, FeatureUser user) {

    if (user != null && Strings.isNotBlank(user.getName())) {

      String percentageAsString = state.getParameter(PARAM_PERCENTAGE);
      try {

        int percentage = Integer.valueOf(percentageAsString);

        if (percentage > 0) {
          int hashCode = Math.abs(calculateHashCode(user, state.getFeature()));
          return (hashCode % 100) < percentage;
        }

      } catch (NumberFormatException e) {
        log.error(
            "Invalid gradual rollout percentage for feature "
                + state.getFeature().name()
                + ": "
                + percentageAsString);
      }
    }

    return false;
  }
コード例 #2
0
  @Override
  public int doStartTag() throws JspException {
    boolean inverse = false;
    if (name.startsWith("!")) {
      inverse = true;
      name = name.substring(1);
    }

    boolean isActive = isFeatureActive();

    if (inverse) {
      isActive = !isActive;
    }

    if (Strings.isNotBlank(var)) {
      pageContext.setAttribute(var, isActive, PageContext.PAGE_SCOPE);
    }

    return isActive ? Tag.EVAL_BODY_INCLUDE : Tag.SKIP_BODY;
  }
コード例 #3
0
 protected boolean isFeatureActive() {
   if (Strings.isNotBlank(name)) {
     return featureManager.isActive(new NamedFeature(name));
   }
   return false;
 }
コード例 #4
0
 @Override
 public boolean isValid(String value) {
   return Strings.isNotBlank(value) && languages.contains(value);
 }
コード例 #5
0
 @Override
 public String getDescription() {
   return "The script language to use. Your system seems to support the following languages: "
       + Strings.join(languages, ", ");
 }