private Stream<ParameterMeta> findNestedDataSets(final Collection<ParameterMeta> options, final String name) { return options .stream() .filter(it -> "dataset".equals(it.getMetadata().get("tcomp::configurationtype::type")) && name.equals(it.getMetadata().get("tcomp::configurationtype::name"))); }
private boolean isRequired(final ParameterMeta parameterMeta) { return Boolean.parseBoolean(parameterMeta.getMetadata().getOrDefault("tcomp::validation::required", "false")); }
private static boolean isConfiguration(final ParameterMeta parameterMeta) { return parameterMeta.getMetadata().keySet().stream().anyMatch(m -> m.startsWith("tcomp::configurationtype::")); }
public Set<ActionReference> getActionReference(final Stream<ParameterMeta> parameters, final String familyName, final FamilyBundle familyBundle) { return parameters .flatMap(p -> p.getMetadata().entrySet().stream()) .filter(e -> e.getKey().startsWith(ActionParameterEnricher.META_PREFIX)) .map(e -> { final String type = e.getKey().substring(ActionParameterEnricher.META_PREFIX.length()); return new ActionReference(familyName, e.getValue(), type, familyBundle.actionDisplayName(type, e.getValue()).orElse(e.getValue()), null); }) .collect(toSet()); }
private Stream<ParameterMeta> getNestedConfigType(final ParameterMeta parameterMeta) { return concat( (parameterMeta.getJavaType() instanceof Class && parameterMeta .getMetadata() .keySet() .stream() .anyMatch(k -> k.startsWith("tcomp::configurationtype::"))) ? Stream.of(parameterMeta) : Stream.empty(), ofNullable(parameterMeta.getNestedParameters()) .map(Collection::stream) .orElseGet(Stream::empty) .flatMap(this::getNestedConfigType)); }
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)); }
private String findDocumentation(final ParameterMeta p) { final String inline = p.getMetadata().get("documentation"); if (inline != null) { if (inline.startsWith("resource:")) { final InputStream stream = Thread .currentThread() .getContextClassLoader() .getResourceAsStream(inline.substring("resource:".length())); if (stream != null) { try (final BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8))) { return reader.lines().collect(joining("\n")); } catch (final IOException e) { throw new IllegalArgumentException("Bad resource: '" + inline + "'", e); } } else { throw new IllegalArgumentException("No resource: '" + inline + "'"); } } return inline; } return p.getName() + " configuration"; }
private String getLayoutType(final ParameterMeta root) { if (root == null) { return "tcomp::ui::gridlayout::Advanced::value"; } final String rootLayoutType = root .getMetadata() .keySet() .stream() .filter(k -> k.contains("tcomp::ui") && (k.contains("layout") || k.contains("optionsorder"))) .map(k -> k.split("::")) .filter(s -> s.length > 2) .map(s -> s[2]) .findFirst() .orElse("default"); switch (rootLayoutType.toLowerCase(Locale.ROOT)) { case "verticallayout": return "tcomp::ui::verticallayout"; case "horizontallayout": return "tcomp::ui::horizontallayout"; case "autolayout": return "tcomp::ui::autolayout"; case "optionsorder": return "tcomp::ui::optionsorder"; case "default": return null; case "gridlayout": default: return "tcomp::ui::gridlayout::Advanced::value"; } }
final String layoutType = paramBuilder.getLayoutType(); if (layoutType == null) { root.getMetadata().put("tcomp::ui::gridlayout::Advanced::value", maxBatchSize.getName()); root .getMetadata() .put("tcomp::ui::gridlayout::Main::value", root .map(ParameterMeta::getName) .collect(joining("|"))); } else if (!root.getMetadata().containsKey(layoutType)) { root .getMetadata() .put(layoutType, layoutType.contains("gridlayout") ? maxBatchSize.getName() : "true"); } else if (layoutType.contains("gridlayout")) { final String oldLayout = root.getMetadata().get(layoutType); root.getMetadata().put(layoutType, maxBatchSize.getName() + "|" + oldLayout);
.getMetadata() .entrySet() .stream() .getMetadata() .entrySet() .stream()
private String toAsciidoctor(final ParameterMeta p, final DefaultValueInspector.Instance instance, final ParameterBundle parent) { final ParameterBundle bundle = findBundle(p); return "|" + bundle.displayName(parent).orElse(p.getName()) + '|' + bundle.documentation(parent).orElseGet(() -> findDocumentation(p)) + '|' + ofNullable(findDefault(p, instance)).orElse("-") + '|' + renderConditions(p.getPath(), p.getMetadata()) + '|' + p.getPath(); }
.filter(it -> flatten(it.getValue()) .noneMatch(prop -> "dataset" .equals(prop.getMetadata().get("tcomp::configurationtype::type")))) .map(it -> "The component " + it.getKey().getName() + " is missing a dataset in its configuration (see @DataSet)") ds, ofNullable(ds.getPackage()).map(Package::getName).orElse(""), true, context); if (flatten(dataset) .noneMatch(prop -> "datastore".equals(prop.getMetadata().get("tcomp::configurationtype::type")))) { return "The dataset " + ds.getName() + " is missing a datastore reference in its configuration (see @DataStore)";
private ParameterMeta translate(final ParameterMeta config, final int replacedPrefixLen, final String newPrefix) { return new ParameterMeta(config.getSource(), config.getJavaType(), config.getType(), newPrefix + config.getPath().substring(replacedPrefixLen), config.getPath().length() == replacedPrefixLen ? newPrefix : config.getName(), config.getI18nPackages(), config .getNestedParameters() .stream() .map(it -> translate(it, replacedPrefixLen, newPrefix)) .collect(toList()), config.getProposals(), config.getMetadata(), config.isLogMissingResourceBundle()); } }
final String type = p.getType().name(); final boolean isEnum = p.getType() == ParameterMeta.Type.ENUM; PropertyValidation validation = propertyValidationService.map(p.getMetadata()); if (isEnum) { if (validation == null) { final Map<String, String> sanitizedMetadata = ofNullable(p.getMetadata()) .map(m -> m .entrySet()
if (Boolean.parseBoolean(meta.getMetadata().get("tcomp::validation::required")) && value == JsonValue.NULL) { errors.add(MESSAGES.required(meta.getPath())); final Map<String, String> metadata = meta.getMetadata();
private Config createConfig(final String plugin, final ComponentManager.AllServices services, final ParameterMeta config, final String familyName, final String familyIcon, final MigrationHandlerFactory migrationHandlerFactory) { final Config c = new Config(); c.setIcon(familyIcon); c.setKey(getKey(familyName, config.getMetadata())); c.setMeta(translate(config, config.getPath().length(), "configuration")); c .setId(IdGenerator .get(plugin, c.getKey().getFamily(), c.getKey().getConfigType(), c.getKey().getConfigName())); if (Class.class.isInstance(config.getJavaType())) { final Class<?> clazz = Class.class.cast(config.getJavaType()); final Version version = clazz.getAnnotation(Version.class); if (version != null) { c.setVersion(version.value()); if (version.migrationHandler() != MigrationHandler.class) { c .setMigrationHandler(migrationHandlerFactory .findMigrationHandler(singletonList(c.getMeta()), clazz, services)); } } else { c.setVersion(-1); } } if (c.getMigrationHandler() == null) { c.setMigrationHandler((v, d) -> d); } return c; }