private boolean isConfiguration(final SimplePropertyDefinition it) { return it.getMetadata().containsKey("configurationtype::name") && it.getMetadata().containsKey("configurationtype::type"); }
public boolean isCredential() { return Boolean.parseBoolean(definition.getMetadata().get("ui::credential")); } }
public Optional<SimplePropertyDefinition> findFormId(final ConfigTypeNode node) { return node .getProperties() .stream() .filter(p -> "true".equals(p.getMetadata().get("proxyserver::formId"))) .findFirst(); }
private Stream<UiSchema.Trigger> createValidationTrigger(final SimplePropertyDefinition property) { return ofNullable(property.getMetadata().get("action::validation")) .flatMap(v -> actions .stream() .filter(a -> actionMatch(v, a) && "validation".equals(a.getType())) .findFirst()) .map(ref -> Stream.of(toTrigger(properties, property, ref))) .orElseGet(Stream::empty); }
private Stream<UiSchema.Trigger> createOtherActions(final SimplePropertyDefinition property) { return property .getMetadata() .entrySet() .stream() .filter(it -> it.getKey().startsWith("action::") && !isBuiltInAction(it.getKey())) .map(v -> actions .stream() .filter(a -> matchAction(v, a)) .findFirst() .map(ref -> toTrigger(properties, property, ref)) .orElse(null)) .filter(Objects::nonNull); }
private Stream<UiSchema.Trigger> createSuggestionTriggers(final SimplePropertyDefinition property) { return ofNullable(property.getMetadata().get("action::suggestions")) .flatMap(v -> actions .stream() .filter(a -> actionMatch(v, a) && "suggestions".equals(a.getType())) .findFirst()) .map(ref -> Stream .of(toTrigger(properties, property, ref)) .peek(trigger -> trigger.setOnEvent("focus"))) .orElseGet(Stream::empty); }
private Stream<UiSchema.Trigger> createBuiltInSuggestionTriggers(final SimplePropertyDefinition property) { return ofNullable( property.getMetadata().get("action::built_in_suggestable")) .map(ref -> Stream .of(toTrigger(properties, property, new ActionReference("builtin_client", ref, "built_in_suggestable", null, emptyList()))) .peek(trigger -> { trigger.setOnEvent("focus"); trigger.setRemote(false); })) .orElseGet(Stream::empty); }
private void enrichTriggers(final ConfigTypeNode it, final String appended) { it.getProperties().forEach(prop -> { final Map<String, String> metadata = prop.getMetadata(); metadata .keySet() .stream() .filter(k -> k.startsWith("action::") && k.split("::").length == 2) .forEach(act -> { final String key = act + "::parameters"; final String originalValue = metadata.get(key); final Map<String, String> newMetadata = new HashMap<>(metadata); final String newValue = (originalValue == null || originalValue.trim().isEmpty() ? ("action::healthcheck".equals(act) || "action::schema".equals(act) ? prop.getPath() + "," : "") + appended : (originalValue + ',' + appended)); newMetadata.put(key, newValue); prop.setMetadata(newMetadata); }); }); }
private Patch forLang(final ResourceBundle bundle, final JsonProvider provider) { return patchPerLang.computeIfAbsent(bundle.getLocale().getLanguage(), k -> { final List<SimplePropertyDefinition> prependProperties = withTranslations(bundle, base.prependProperties); final List<SimplePropertyDefinition> appendProperties = withTranslations(bundle, base.appendProperties); return new Patch(prependProperties, appendProperties, Stream .of(prependProperties, appendProperties) .filter(Objects::nonNull) .flatMap(Collection::stream) .filter(it -> "true".equalsIgnoreCase(it.getMetadata().get("proxyserver::formId")) && !it.getPath().contains("${index}")) .findFirst() .map(it -> provider.createPointer('/' + it.getPath().replace('.', '/'))) .orElse(null)); }); }
.getProperties() .stream() .filter(it -> it.getMetadata().containsKey("definition::parameter::index")) .sorted(comparing(it -> Integer.parseInt(it.getMetadata().get("definition::parameter::index")))) .iterator(); return ofNullable(parameters).map(params -> Stream.of(params.split(",")).flatMap(paramRef -> {
@Override public CompletionStage<PropertyContext<?>> convert(final CompletionStage<PropertyContext<?>> cs) { return cs.thenApply(context -> { final UiSchema schema = newUiSchema(context); final String codeLang = context.getProperty().getMetadata().get("ui::code::value"); schema.setWidget("code"); schema.setOptions(singletonMap("language", codeLang)); return context; }); } }
protected UiSchema.Trigger toTrigger(final Collection<SimplePropertyDefinition> properties, final SimplePropertyDefinition prop, final ActionReference ref) { final UiSchema.Trigger trigger = new UiSchema.Trigger(); trigger .setAction(prop .getMetadata() .entrySet() .stream() .filter(it -> matchAction(it, ref)) .findFirst() .map(Map.Entry::getValue) .orElseGet(ref::getName)); trigger.setFamily(ref.getFamily()); trigger.setType(ref.getType()); trigger .setParameters(toParams(properties, prop, ref, prop.getMetadata().get("action::" + ref.getType() + "::parameters"))); return trigger; }
private List<SimplePropertyDefinition> withTranslations(final ResourceBundle bundle, final Collection<SimplePropertyDefinition> props) { return props .stream() .map(p -> new SimplePropertyDefinition(p.getPath(), findTranslation(bundle, p.getName()), findTranslation(bundle, p.getDisplayName()), p.getType(), p.getDefaultValue(), p.getValidation(), ofNullable(p.getMetadata()) .map(m -> m .entrySet() .stream() .collect(toMap(Map.Entry::getKey, e -> findTranslation(bundle, e.getValue())))) .orElse(null), findTranslation(bundle, p.getPlaceholder()), ofNullable(p.getProposalDisplayNames()) .map(proposals -> proposals .entrySet() .stream() .collect(toMap(Map.Entry::getKey, e -> findTranslation(bundle, e.getValue()), (a, b) -> { throw new IllegalArgumentException("can't happen"); }, LinkedHashMap::new))) .orElse(null))) .collect(toList()); }
.filter(p -> "OUT".equals(p.getMetadata().get("ui::structure::type"))) .findFirst() .ifPresent(schemaBinding -> addGuessSchemaButton(root, schemaBinding, buttons)); addHealthCheck(root, buttons); addUpdate(root).ifPresent(button -> { final String name = root.getProperty().getMetadata().get("action::update::after"); if (name == null) { buttons.add(button);
.map(prop -> new SimplePropertyDefinition(def.getName() + prop.getPath().substring(root.length()), prop.getName(), prop.getDisplayName(), prop.getType(), prop.getDefaultValue(), prop.getValidation(), prop.getMetadata(), prop.getPlaceholder(), prop.getProposalDisplayNames())) .collect(toList());
private Optional<UiSchema> addUpdate(final PropertyContext<?> root) { final SimplePropertyDefinition property = root.getProperty(); return ofNullable(property.getMetadata().get("action::update")) .flatMap(v -> (actions == null ? Stream.<ActionReference> empty() : actions.stream()) .filter(a -> a.getName().equals(v) && "update".equals(a.getType())) .findFirst()) .map(action -> { final UiSchema.Trigger trigger = toTrigger(properties, root.getProperty(), action); final String path = property.getPath(); trigger .setOptions(singletonList(new UiSchema.Option.Builder() .withPath(path.endsWith("[]") ? path.substring(0, path.length() - "[]".length()) : path) .withType(property.getType().toLowerCase(ROOT)) .build())); final UiSchema button = new UiSchema(); button .setTitle(action.getDisplayName() == null ? action.getName() + " (" + action.getType() + ')' : action.getDisplayName()); button.setWidget("button"); button.setTriggers(singletonList(trigger)); return button; }); }
final String actionName = context.getProperty().getMetadata().get("action::dynamic_values"); if (client != null && actionName != null) { final CompletionStage<List<UiSchema.NameValue>> pairs =
jsonSchema.setEnumValues(context.getProperty().getValidation().getEnumValues()); } else { final String actionName = context.getProperty().getMetadata().get("action::dynamic_values"); if (client != null && actionName != null) { final CompletionStage<List<UiSchema.NameValue>> pairs =
private void normalize(final SimplePropertyDefinition prop) { if (prop.getProposalDisplayNames() != null) { if (prop.getValidation() == null) { prop.setValidation(new PropertyValidation()); } if (prop.getValidation().getEnumValues() == null) { prop.getValidation().setEnumValues(prop.getProposalDisplayNames().keySet()); } } else if (prop.getValidation() != null && prop.getValidation().getEnumValues() != null && prop.getProposalDisplayNames() == null) { prop .setProposalDisplayNames(prop .getValidation() .getEnumValues() .stream() .collect(toMap(identity(), identity(), (a, b) -> { throw new IllegalArgumentException("Conflict is not possible here"); }, LinkedHashMap::new))); } if (prop.getMetadata() == null) { prop.setMetadata(emptyMap()); } if (prop.getName() == null) { prop.setName(prop.getPath().substring(prop.getPath().lastIndexOf('.') + 1)); } }
protected UiSchema newOrphanSchema(final PropertyContext<?> ctx) { final UiSchema schema = new UiSchema(); schema.setTitle(ctx.getProperty().getDisplayName()); schema.setKey(ctx.getProperty().getPath()); if (ctx.isRequired()) { schema.setRequired(ctx.isRequired()); } schema.setPlaceholder(ctx.getProperty().getPlaceholder()); if (ctx.getConfiguration().isIncludeDocumentationMetadata()) { schema.setDescription(ctx.getProperty().getMetadata().get("documentation::value")); } if (actions != null) { final List<UiSchema.Trigger> triggers = Stream .concat(Stream .concat(Stream .concat(createValidationTrigger(ctx.getProperty()), createOtherActions(ctx.getProperty())), createSuggestionTriggers(ctx.getProperty())), createBuiltInSuggestionTriggers(ctx.getProperty())) .collect(toList()); if (!triggers.isEmpty()) { schema.setTriggers(triggers); } } schema.setCondition(createCondition(ctx)); return schema; }