public boolean isRequired() { return property.getValidation() != null && property.getValidation().getRequired() != null && property.getValidation().getRequired(); }
/** * 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); }
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())); }
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 Optional<SimplePropertyDefinition> findFormId(final ConfigTypeNode node) { return node .getProperties() .stream() .filter(p -> "true".equals(p.getMetadata().get("proxyserver::formId"))) .findFirst(); }
public String findIcon(final String family, final ComponentIndices componentIndices) { return componentIndices .getComponents() .stream() .filter(component -> component.getId().getFamilyId().equals(family)) .findFirst() .orElseThrow(() -> new WebApplicationException(Response .status(HTTP_INTERNAL_ERROR) .entity(new ProxyErrorPayload("UNEXPECTED", "No icon found for this configuration family " + family)) .header(ErrorProcessor.Constants.HEADER_TALEND_COMPONENT_SERVER_ERROR, false) .build())) .getIconFamily() .getIcon(); }
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); }
@Override public CompletionStage<PropertyContext<?>> convert(final CompletionStage<PropertyContext<?>> cs) { return cs.thenApply(context -> { jsonSchema.setType("string"); if (context.getProperty().getValidation() == null || context.getProperty().getValidation().getEnumValues() == null) { jsonSchema.setEnumValues(emptyList()); } else { jsonSchema.setEnumValues(context.getProperty().getValidation().getEnumValues()); } return context; }); } }
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 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; } }
public List<ConfigTypeNode> findChildren(final String formId, final ConfigTypeNodes nodes) { return nodes .getNodes() .values() .stream() .filter(node -> node.getParentId() != null && node.getParentId().equals(formId)) .sorted(comparing(ConfigTypeNode::getDisplayName).thenComparing(ConfigTypeNode::getName)) .collect(toList()); } }
private boolean isConfiguration(final SimplePropertyDefinition it) { return it.getMetadata().containsKey("configurationtype::name") && it.getMetadata().containsKey("configurationtype::type"); }
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 actionMatch(final String name, final ActionReference action) { return deParameterize(action.getName()).equals(deParameterize(name)); }
private CompletionStage<NewForm> toNewForm(final String family, final UiSpecContext context, final ConfigTypeNode node, final String refId, final ConfigTypeNode parentFormSpec) { return self .getNewForm(context, node.getId()) .thenCompose(newForm -> handleReferences(family, context, node, refId, parentFormSpec, newForm)); }
public ConfigTypeNode enforceFormIdInTriggersIfPresent(final ConfigTypeNode it) { final Optional<SimplePropertyDefinition> idPropOpt = findFormId(it); if (!idPropOpt.isPresent()) { enrichTriggers(it, "$formId"); return it; } // H: we assume the id uses a simple path (no array etc), should be the case generally final String idProp = idPropOpt.get().getPath(); enrichTriggers(it, idProp + ",$formId\n\n"); return it; }
private String getSwitchType(final SimplePropertyDefinition def) { return ofNullable(def.getType()).orElse("IGNORE").toUpperCase(ROOT); }
public boolean isCredential() { return Boolean.parseBoolean(definition.getMetadata().get("ui::credential")); } }
protected void setupUiSchema(final PropertyContext<?> context, final UiSchema schema) { schema.setWidget("datalist"); schema.setRestricted("ENUM".equalsIgnoreCase(context.getProperty().getType())); } }