public Optional<SimplePropertyDefinition> findFormId(final ConfigTypeNode node) { return node .getProperties() .stream() .filter(p -> "true".equals(p.getMetadata().get("proxyserver::formId"))) .findFirst(); }
public CompletionStage<Map<String, String>> replaceReferences(final UiSpecContext context, final ConfigTypeNode detail, final Map<String, String> props) { return propertiesService.replaceReferences(context, detail.getProperties(), props); }
private boolean isNested(final ComparableConfigTypeNode o1, final ComparableConfigTypeNode o2) { return o1.delegate .getProperties() .stream() .allMatch(it -> o2 .getDelegate() .getProperties() .stream() .anyMatch(n -> n.getPath().equals(it.getPath()))); } }
public CompletionStage<Collection<SimplePropertyDefinition>> getConfigurationSpec(final String id) { return client .path("configurationtype/details") .queryParam("identifiers", id) .queryParam("language", "en") .request(APPLICATION_JSON_TYPE) .rx() .get(ConfigTypeNodes.class) .thenApply(list -> list.getNodes().values().iterator().next().getProperties()); }
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); }); }); }
public ConfigTypeNode enrich(final ConfigTypeNode node, final String lang) { return doEnrich(node.getConfigurationType(), lang, patch -> { final ConfigTypeNode copy = new ConfigTypeNode(node.getId(), node.getVersion(), node.getParentId(), node.getConfigurationType(), node.getName(), node.getDisplayName(), node.getEdges(), new ArrayList<>(), new ArrayList<>(node.getActions())); patch.doPatchProperties(copy.getProperties(), node.getProperties()); patch.appendBuiltInActions(copy.getActions()); return copy; }).orElse(node); }
node.getProperties().stream().map(SimplePropertyDefinition::getPath).collect(toSet()); rootProperties .removeIf(path -> node.getProperties().stream().anyMatch(p -> path.startsWith(p.getPath() + '.'))); if (rootProperties.isEmpty()) { log.warn("No root properties for configuration node {} (family={})", node.getId(), family); final String root = rootProperties.iterator().next(); final SimplePropertyDefinition def = node.getProperties().stream().filter(prop -> prop.getPath().equals(root)).findFirst().get(); props = node .getProperties() .stream() .map(prop -> new SimplePropertyDefinition(def.getName() + prop.getPath().substring(root.length()), isRootProperty = p -> p.getPath().equals(def.getName()); } else { props = node.getProperties(); isRootProperty = p -> rootProperties.contains(p.getPath());
@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); } }
.thenApply(node -> { final String propPrefix = node .getProperties() .stream() .filter(p -> p.getName().equals(p.getPath()))
@Override public int compareTo(final ComparableConfigTypeNode o) { if (o == null) { return -1; } if (o == this || delegate == o.getDelegate()) { return 0; } if (isNested(this, o)) { return -1; } if (isNested(o, this)) { return 1; } // just to sort globally final int myPropCount = delegate.getProperties().size(); final int otherPropCount = o.getDelegate().getProperties().size(); if (myPropCount == otherPropCount) { return delegate.getId().compareTo(o.getDelegate().getId()); } return myPropCount - otherPropCount; }
.thenApply(nodes -> configurationService.getFamilyOf(detail.getId(), nodes)) .thenCompose(familyNode -> filterProperties(familyNode.getName(), detail.getProperties(), context) .thenCompose(props -> replaceReferences(context, props, form.getProperties()).thenApply(nestedProps -> { final String root = detail .getProperties() .stream() .map(SimplePropertyDefinition::getPath)
final Map<String, String> configInstance = new HashMap<>(); final SimplePropertyDefinition refProp = node .getProperties() .stream() .filter(it -> it .filterProperties(family, node.getProperties(), context) .thenCompose(props -> propertiesService.replaceReferences(context, props, configInstance)) .thenApply(props -> { if (node.getProperties() != null && !node.getProperties().isEmpty()) { final Map<String, String> mergedWithDefaults = new HashMap<>(formatter.flatten(newForm.getProperties())); mergedWithDefaults.putAll(props); final JsonObject properties = formatter.unflatten(node.getProperties(), mergedWithDefaults); final JsonObject enrichedProperties = newForm .getProperties() .get(it) .getValueType() == JsonValue.ValueType.OBJECT && node.getProperties().stream().noneMatch(prop -> prop.getName().equals(it))) .collect(Collector .of(builderFactory::createObjectBuilder,
@Override public <T extends ConfigurationVisitor> CompletionStage<T> visit(final RequestContext context, final String formId, final Map<String, String> properties, final T visitor) { return client.getDetails(context.language(), formId, context::findPlaceholder).thenApply(config -> { new ConfigurationReader(properties, visitor, config.getProperties()).visit(); return visitor; }); } }
.collect(toJsonObject()); return onEditEvent .fireAsync(new OnEdit(id, requestContext, jsonb, enrichment, config.getProperties(), configurationFormatter.flatten(configuration)), notificationOptions) .thenCompose(OnEdit::getCompletionListener)
return onPersistEvent .fireAsync(new OnPersist(requestContext, jsonb, node.getId(), enrichment, node.getProperties(), configurationFormatter.flatten(configuration)), notificationOptions) .thenCompose(persist -> {
private CompletionStage<NewForm> createChildrenChooserForm(final UiSpecContext context, final List<ConfigTypeNode> childrenSpec, final ConfigTypeNode parentSpec, final String parentEntityId, final String selectedId, final ConfigTypeNodes nodes) { final ConfigTypeNode refChild = childrenSpec .stream() .filter(it -> it.getId().equals(selectedId)) .findFirst() .orElseGet(() -> childrenSpec.iterator().next()); final ConfigTypeNode family = configurationService.getFamilyOf(refChild.getId(), nodes); final ConfigTypeNode formModel = modelEnricherService.enrich(refChild, context.getLanguage()); formModel .getProperties() .add(createChildrenChooserProperty(childrenSpec, parentEntityId, context.getLanguage(), selectedId, modelEnricherService.findPropertyPrefixForEnrichingProperty(refChild.getConfigurationType()))); return componentClient .getAllComponents(context.getLanguage(), context.getPlaceholderProvider()) .thenCompose(components -> uiSpecService .convert(family.getName(), context.getLanguage(), formModel, context) .thenApply(ui -> new UiNode(ui, new Node(selectedId, refChild.getDisplayName(), family.getId(), family.getDisplayName(), ofNullable(family.getId()) .map(id -> configurationService.findIcon(id, components)) .orElse(null), emptyList(), null, refChild.getName())))) .thenApply(this::toNewFormResponse) .thenCompose( newForm -> handleReferences(configurationService.getFamilyOf(refChild.getId(), nodes).getName(), context, refChild, parentEntityId, parentSpec, newForm)); }
private CompletionStage<ConfigTypeNode> getEnrichedNode(final String id, final UiSpecContext context, final String family) { return getNode(id, context.getLanguage(), context.getPlaceholderProvider()) .thenApply(node -> modelEnricherService.enrich(node, context.getLanguage())) .thenCompose(node -> propertiesService .filterProperties(family, node.getProperties(), context) .thenApply(newProps -> { node.setProperties(newProps); return node; })); }
public CompletionStage<ConfigTypeNode> filterNestedConfigurations(final String family, final ConfigTypeNode node, final UiSpecContext context) { return propertiesService .filterProperties(family, node.getProperties(), context) .thenApply(props -> new ConfigTypeNode(node.getId(), node.getVersion(), node.getParentId(), node.getConfigurationType(), node.getName(), node.getDisplayName(), node.getEdges(), props, node.getActions())); }