private Function<String, Object> findStringValueMapper(final SimplePropertyDefinition definition) { if (definition == null) { return s -> s; } switch (definition.getType().toLowerCase(ROOT)) { case "boolean": return Boolean::parseBoolean; case "number": return Double::parseDouble; // assume object and array are not supported default: return s -> s; } }
private String getSwitchType(final SimplePropertyDefinition def) { return ofNullable(def.getType()).orElse("IGNORE").toUpperCase(ROOT); }
public String findPropertyPrefixForEnrichingProperty(final String configurationType) { return ofNullable(getPatch(configurationType)) .filter(it -> it.base != null) .map(patch -> Stream .of(patch.base.prependProperties, patch.base.appendProperties) .filter(Objects::nonNull) .flatMap(Collection::stream) .filter(it -> "OBJECT".equalsIgnoreCase(it.getType()) && it.getName() != null && it.getName().equals(it.getPath())) .findFirst()) .flatMap(identity()) .map(SimplePropertyDefinition::getName) .orElse(null); }
private JsonValue onArrayPrimitive(final SimplePropertyDefinition itemDef, final ArrayEntry e) { final String value = e.entry.getValue(); switch (getSwitchType(itemDef)) { case "BOOLEAN": return Boolean.parseBoolean(value.trim()) ? JsonValue.TRUE : JsonValue.FALSE; case "NUMBER": return jsonp.createValue(Double.parseDouble(value.trim())); case "ENUM": case "STRING": return jsonp.createValue(value); default: throw new IllegalArgumentException("Unsupported structure in " + "array: " + itemDef.getType()); } }
protected void setupUiSchema(final PropertyContext<?> context, final UiSchema schema) { schema.setWidget("datalist"); schema.setRestricted("ENUM".equalsIgnoreCase(context.getProperty().getType())); } }
return cs.thenCompose(context -> { final SimplePropertyDefinition property = context.getProperty(); if ("object".equalsIgnoreCase(property.getType())) { final Map<String, Object> childDefaults = new HashMap<>(); defaults.put(property.getName(), childDefaults); if ("number".equalsIgnoreCase(property.getType())) { defaults.put(property.getName(), Double.parseDouble(value)); } else if ("boolean".equalsIgnoreCase(property.getType())) { defaults.put(property.getName(), Boolean.parseBoolean(value)); } else if ("array".equalsIgnoreCase(property.getType())) { defaults.put(property.getName(), jsonb.fromJson(value, Object[].class)); } else if ("object".equalsIgnoreCase(property.getType())) { defaults.put(property.getName(), jsonb.fromJson(value, Map.class)); } else { if ("string".equalsIgnoreCase(property.getType()) && property .getMetadata() .keySet()
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()); }
@Override public CompletionStage<PropertyContext<?>> convert(final CompletionStage<PropertyContext<?>> cs) { return cs.thenCompose(context -> { jsonSchema.setType(context.getProperty().getType().toLowerCase(ROOT)); final String prefix = context.getProperty().getPath() + "[]"; final List<SimplePropertyDefinition> arrayElements = .thenApply(done -> context); } else if (!arrayElements.isEmpty()) { // primitive final String type = arrayElements.get(0).getType(); final JsonSchema item = new JsonSchema(); item.setTitle(jsonSchema.getTitle());
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; }); }
.stream() .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()))
.setOptions(singletonList(new UiSchema.Option.Builder() .withPath(bindingProp.getPath().replace("[]", "")) .withType("array".equalsIgnoreCase(bindingProp.getType()) ? "array" : "object") .build())); if (trigger.getParameters() == null || trigger.getParameters().isEmpty()) {
.orElseGet(() -> { final SimplePropertyDefinition property = context.getProperty(); final String type = property.getType().toLowerCase(Locale.ROOT); final Map<String, String> metadata = property.getMetadata(); switch (type) {
final JsonSchema jsonSchema = new JsonSchema(); jsonSchema.setTitle(context.getProperty().getDisplayName()); final String type = context.getProperty().getType(); switch (type.toLowerCase(ROOT)) { case "enum":
private Map<String, Collection<Object>> toCondition(final String path, final String strategy, final Object value, final SimplePropertyDefinition def) { switch (strategy) { case "length": return new UiSchema.ConditionBuilder() .withOperator("===") .withVar(path + ".length") .withValue(String.class.isInstance(value) ? Integer.parseInt(String.valueOf(value)) : value) .build(); case "contains": case "contains(lowercase=true)": final UiSchema.ConditionValuesBuilder in = new UiSchema.ConditionBuilder().withOperator("in"); final Object val = strategy.endsWith("(lowercase=true)") ? String.class.cast(value).toLowerCase(ROOT) : value; if (def != null && "array".equalsIgnoreCase(def.getType())) { in.withVar(path).withValue(val).up(); } else { in.withValue(val).withVar(path).up(); } return in.build(); case "default": default: return new UiSchema.ConditionBuilder().withOperator("===").withVar(path).withValue(value).build(); } }
.map(p -> new SimplePropertyDefinition( forcedPrefix + p.getPath().substring(prefixLen), p.getName(), p.getDisplayName(), p.getType(), p.getDefaultValue(), p.getValidation(), p.getMetadata(), p.getPlaceholder(), p.getProposalDisplayNames())) .collect(toList()));
@Override public CompletionStage<PropertyContext<?>> convert(final CompletionStage<PropertyContext<?>> cs) { return cs.thenCompose(context -> { final UiSchema arraySchema = newUiSchema(context); final SimplePropertyDefinition original = context.getProperty(); arraySchema.setTitle(original.getDisplayName()); arraySchema.setItems(new ArrayList<>()); arraySchema.setItemWidget("collapsibleFieldset"); final UiSchemaConverter converter = new UiSchemaConverter(gridLayoutFilter, family, arraySchema.getItems(), new ArrayList<>(), client, jsonSchema, properties, actions, lang, customPropertyConverters); return converter .convertObject(new PropertyContext<>( new SimplePropertyDefinition(original.getPath() + "[]", original.getName(), null, original.getType(), original.getDefaultValue(), original.getValidation(), metaToPropagate, original.getPlaceholder(), original.getProposalDisplayNames()), context.getRootContext(), context.getConfiguration()), metaToPropagate, arraySchema); }); } }