private Stream<SimplePropertyDefinition> filterRoots(final Collection<SimplePropertyDefinition> props) { return ofNullable(props) .map(p -> p.stream().filter(it -> it.getName().equals(it.getPath()))) .orElseGet(Stream::empty); }
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 JsonObject unflatten(final String prefix, final Collection<SimplePropertyDefinition> definitions, final Map<String, String> config) { final List<SimplePropertyDefinition> defs = new ArrayList<>(definitions); defs.sort(comparing(SimplePropertyDefinition::getPath)); final JsonObjectBuilder json = factory.createObjectBuilder(); final Collection<String> matched = new HashSet<>(); new ArrayList<>(definitions) .stream() .filter(it -> it.getPath().equals(prefix + it.getName())) .peek(it -> matched.add(it.getPath())) .forEach(prop -> onProperty(prefix, definitions, config, json, prop)); // handle virtual *properties* ($xxx) which are not spec-ed, ex: foo.$maxBatchSize config .entrySet() .stream() .filter(it -> it.getKey().startsWith("$") && !it.getKey().contains(".")) .filter(it -> matched.add(prefix + it.getKey())) // if matched from the def (w/ type) don't override it .forEach(e -> json.add(e.getKey(), e.getValue())); return json.build(); }
private JsonArray onArrayObjectItem(final Collection<SimplePropertyDefinition> definitions, final Map<String, String> config, final SimplePropertyDefinition definition) { final List<SimplePropertyDefinition> objectOptions = definitions.stream().filter(it -> { final String leadingStr = definition.getPath() + "[]."; return it.getPath().startsWith(leadingStr) && it.getPath().indexOf('.', leadingStr.length() + 1) < 0; }).collect(toList()); if (objectOptions.isEmpty()) { throw new IllegalArgumentException( "Invalid model: " + definition + ", didn't find nested structure, available: " + definitions.stream().map(SimplePropertyDefinition::getPath).collect(toList())); } return config .entrySet() .stream() .filter(it -> it.getKey().startsWith(definition.getName() + '[')) .map(e -> new ArrayEntry(e, definition.getName()).index) .distinct() // sort by index .sorted(comparing(identity())) .map(index -> { final String itemPrefix = definition.getPath() + "[]."; final String configFilter = definition.getName() + "[" + index + "]."; return unflatten(itemPrefix, objectOptions, config .entrySet() .stream() .filter(sc -> sc.getKey().startsWith(configFilter)) .collect(toMap(sc -> sc.getKey().substring(configFilter.length()), Map.Entry::getValue))); }) .collect(toJsonArray()); }
/** * Converts a component form to a uiSpec. * * @param detail the component model. * @param context an optional custom context to propagate some parameters. * @return the uiSpec corresponding to the model. */ public CompletionStage<Ui> convert(final ComponentDetail detail, final String lang, final T context) { return convert(detail::getDisplayName, detail.getId()::getFamily, detail::getProperties, detail::getActions, p -> p.getName().equals(p.getPath()), context, lang); }
private void onProperty(final String prefix, final Collection<SimplePropertyDefinition> definitions, final Map<String, String> config, final JsonObjectBuilder json, final SimplePropertyDefinition definition) { final String name = definition.getName(); switch (getSwitchType(definition)) { case "OBJECT": { .entrySet() .stream() .filter(it -> it.getKey().startsWith(definition.getName() + '[')) .map(e -> new ArrayEntry(e, definition.getName()))
private void processObject(final Collection<SimplePropertyDefinition> definitions, final SimplePropertyDefinition prop, final Map<String, String> config, final JsonObjectBuilder json, final String name, final String currentPath) { final Map<String, String> subConfig = extractSubConfig(config, name); if (!subConfig.isEmpty()) { json.add(name, unflatten(currentPath, definitions, subConfig)); } else { new ArrayList<>(definitions) .stream() .filter(it -> isNested(it.getPath(), prop.getPath())) .forEach(p -> onProperty(currentPath, definitions, extractSubConfig(config, p.getName() + '.'), json, p)); } }
if ("object".equalsIgnoreCase(property.getType())) { final Map<String, Object> childDefaults = new HashMap<>(); defaults.put(property.getName(), childDefaults); final PropertiesConverter propertiesConverter = new PropertiesConverter(jsonb, childDefaults, properties); .ifPresent(value -> { 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 defaults.putIfAbsent("$" + property.getPath() + "_name", value); defaults.put(property.getName(), value);
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()); }
.getProperties() .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())) .collect(toList()); isRootProperty = p -> p.getPath().equals(def.getName()); } else { props = node.getProperties();
@CacheResult(cacheName = "org.talend.sdk.component.proxy.validation.jsonschema") public CompletionStage<JsonSchemaValidator> getValidator(final RequestContext context, final String formId) { return configurations.getDetails(context.language(), formId, context::findPlaceholder).thenCompose(config -> { final JsonSchema jsonSchema = new JsonSchema(); final JsonSchemaConverter converter = new JsonSchemaConverter(jsonb, jsonSchema, config.getProperties()); return CompletableFuture .allOf(config .getProperties() .stream() .filter(Objects::nonNull) .filter(p -> p.getName().equals(p.getPath())) .map(it -> new PropertyContext<>(it, context, LIGHT_CONTEXT_CONFIGURATION)) .map(CompletionStages::toStage) .map(converter::convert) .toArray(CompletableFuture[]::new)) .thenApply(r -> jsonSchema); }).thenApply(schema -> jsonb.fromJson(jsonb.toJson(schema), JsonObject.class)).thenApply(factory::newInstance); } }
} else { sortedProperties.sort(comparing(it -> { final int i = order.indexOf(it.getName()); if (i < 0) { return Integer.MAX_VALUE; jsonSchema, this.properties, actions, lang, customPropertyConverters); futures.add(converter.convert(propContext).thenApply(pc -> { final ListItem item = new ListItem(index, new String[] { definition.getName() }); item.getUiSchemas().addAll(schemas); return item;
rootJsonSchema.setProperties(new HashMap<>()); rootJsonSchema.getProperties().put(context.getProperty().getName(), jsonSchema);
.stream() .filter(this::isConfiguration) .filter(it -> !it.getName().equals(it.getPath()) /* root is the one we convert */) .map(ref -> { final Map<String, String> enrichedMetadata = new HashMap<>(ref.getMetadata()); + ref.getMetadata().get("configurationtype::name") + ")"); return new SimplePropertyDefinition(ref.getPath(), ref.getName(), ref.getDisplayName(), "STRING", null, new PropertyValidation(true, null, null, null, null, null, null, null, null, emptySet()),
.get(it) .getValueType() == JsonValue.ValueType.OBJECT && node.getProperties().stream().noneMatch(prop -> prop.getName().equals(it))) .collect(Collector .of(builderFactory::createObjectBuilder,
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)); } }
.buildProperties(singletonList(c.getMeta()), loader, locale, null) .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()))
@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); }); } }