@Test void one() { final Map<String, String> metadata = new HashMap<>(); metadata.put("tcomp::condition::if::target", "the_target"); metadata.put("tcomp::condition::if::value", "a,b,c"); metadata.put("tcomp::condition::if::negate", "false"); metadata.put("tcomp::condition::if::evaluationStrategy", "DEFAULT"); final VisibilityService.ConditionGroup conditionGroup = service .build(new ParameterMeta(null, String.class, ParameterMeta.Type.STRING, "foo", "foo", null, emptyList(), emptyList(), metadata, false)); assertTrue(conditionGroup.isVisible(Json.createObjectBuilder().add("the_target", "a").build())); assertTrue(conditionGroup.isVisible(Json.createObjectBuilder().add("the_target", "c").build())); assertFalse(conditionGroup.isVisible(Json.createObjectBuilder().build())); }
public ConditionGroup build(final ParameterMeta param) { final boolean and = "AND".equalsIgnoreCase(param.getMetadata().getOrDefault("tcomp::condition::ifs::operator", "AND")); return new ConditionGroup(param .getMetadata() .entrySet() .stream() .filter(meta -> meta.getKey().startsWith("tcomp::condition::if::target")) .map(meta -> { final String[] split = meta.getKey().split("::"); final String index = split.length == 5 ? "::" + split[split.length - 1] : ""; final String valueKey = "tcomp::condition::if::value" + index; final String negateKey = "tcomp::condition::if::negate" + index; final String evaluationStrategyKey = "tcomp::condition::if::evaluationStrategy" + index; final String absoluteTargetPath = pathResolver.resolveProperty(param.getPath(), meta.getValue()); return new Condition(toPointer(absoluteTargetPath), Boolean.parseBoolean(param.getMetadata().getOrDefault(negateKey, "false")), param.getMetadata().getOrDefault(evaluationStrategyKey, "DEFAULT").toUpperCase(ROOT), param.getMetadata().getOrDefault(valueKey, "true").split(",")); }) .collect(toList()), and ? stream -> stream.allMatch(i -> i) : stream -> stream.anyMatch(i -> i)); }
VisibilityService { public ConditionGroup build(final ParameterMeta param) { final boolean and = "AND".equalsIgnoreCase(param.getMetadata().getOrDefault("tcomp::condition::ifs::operator", "AND")); return new ConditionGroup(param .getMetadata() .entrySet() .stream() .filter(meta -> meta.getKey().startsWith("tcomp::condition::if::target")) .map(meta -> { final String[] split = meta.getKey().split("::"); final String index = split.length == 5 ? "::" + split[split.length - 1] : ""; final String valueKey = "tcomp::condition::if::value" + index; final String negateKey = "tcomp::condition::if::negate" + index; final String evaluationStrategyKey = "tcomp::condition::if::evaluationStrategy" + index; final String absoluteTargetPath = pathResolver.resolveProperty(param.getPath(), meta.getValue()); return new Condition(toPointer(absoluteTargetPath), Boolean.parseBoolean(param.getMetadata().getOrDefault(negateKey, "false")), param.getMetadata().getOrDefault(evaluationStrategyKey, "DEFAULT").toUpperCase(ROOT), param.getMetadata().getOrDefault(valueKey, "true").split(",")); }) .collect(toList()), and ? stream -> stream.allMatch(i -> i) : stream -> stream.anyMatch(i -> i)); } }
VisibilityService { public ConditionGroup build(final ParameterMeta param) { final boolean and = "AND".equalsIgnoreCase(param.getMetadata().getOrDefault("tcomp::condition::ifs::operator", "AND")); return new ConditionGroup(param .getMetadata() .entrySet() .stream() .filter(meta -> meta.getKey().startsWith("tcomp::condition::if::target")) .map(meta -> { final String[] split = meta.getKey().split("::"); final String index = split.length == 5 ? "::" + split[split.length - 1] : ""; final String valueKey = "tcomp::condition::if::value" + index; final String negateKey = "tcomp::condition::if::negate" + index; final String evaluationStrategyKey = "tcomp::condition::if::evaluationStrategy" + index; final String absoluteTargetPath = pathResolver.resolveProperty(param.getPath(), meta.getValue()); return new Condition(toPointer(absoluteTargetPath), Boolean.parseBoolean(param.getMetadata().getOrDefault(negateKey, "false")), param.getMetadata().getOrDefault(evaluationStrategyKey, "DEFAULT").toUpperCase(ROOT), param.getMetadata().getOrDefault(valueKey, "true").split(",")); }) .collect(toList()), and ? stream -> stream.allMatch(i -> i) : stream -> stream.anyMatch(i -> i)); }  }
VisibilityService { public ConditionGroup build(final ParameterMeta param) { final boolean and = "AND".equalsIgnoreCase(param.getMetadata().getOrDefault("tcomp::condition::ifs::operator", "AND")); return new ConditionGroup(param .getMetadata() .entrySet() .stream() .filter(meta -> meta.getKey().startsWith("tcomp::condition::if::target")) .map(meta -> { final String[] split = meta.getKey().split("::"); final String index = split.length == 5 ? "::" + split[split.length - 1] : ""; final String valueKey = "tcomp::condition::if::value" + index; final String negateKey = "tcomp::condition::if::negate" + index; final String evaluationStrategyKey = "tcomp::condition::if::evaluationStrategy" + index; final String absoluteTargetPath = pathResolver.resolveProperty(param.getPath(), meta.getValue()); return new Condition(toPointer(absoluteTargetPath), Boolean.parseBoolean(param.getMetadata().getOrDefault(negateKey, "false")), param.getMetadata().getOrDefault(evaluationStrategyKey, "DEFAULT").toUpperCase(ROOT), param.getMetadata().getOrDefault(valueKey, "true").split(",")); }) .collect(toList()), and ? stream -> stream.allMatch(i -> i) : stream -> stream.anyMatch(i -> i)); }  ConditionGroup build(final ParameterMeta param); }
VisibilityService { public ConditionGroup build(final ParameterMeta param) { final boolean and = "AND".equalsIgnoreCase(param.getMetadata().getOrDefault("tcomp::condition::ifs::operator", "AND")); return new ConditionGroup(param .getMetadata() .entrySet() .stream() .filter(meta -> meta.getKey().startsWith("tcomp::condition::if::target")) .map(meta -> { final String[] split = meta.getKey().split("::"); final String index = split.length == 5 ? "::" + split[split.length - 1] : ""; final String valueKey = "tcomp::condition::if::value" + index; final String negateKey = "tcomp::condition::if::negate" + index; final String evaluationStrategyKey = "tcomp::condition::if::evaluationStrategy" + index; final String absoluteTargetPath = pathResolver.resolveProperty(param.getPath(), meta.getValue()); return new Condition(toPointer(absoluteTargetPath), Boolean.parseBoolean(param.getMetadata().getOrDefault(negateKey, "false")), param.getMetadata().getOrDefault(evaluationStrategyKey, "DEFAULT").toUpperCase(ROOT), param.getMetadata().getOrDefault(valueKey, "true").split(",")); }) .collect(toList()), and ? stream -> stream.allMatch(i -> i) : stream -> stream.anyMatch(i -> i)); }  ConditionGroup build(final ParameterMeta param);  }