public Set<ActionReference> getActionReference(final Stream<ParameterMeta> parameters, final String familyName, final FamilyBundle familyBundle) { return parameters .flatMap(p -> p.getMetadata().entrySet().stream()) .filter(e -> e.getKey().startsWith(ActionParameterEnricher.META_PREFIX)) .map(e -> { final String type = e.getKey().substring(ActionParameterEnricher.META_PREFIX.length()); return new ActionReference(familyName, e.getValue(), type, familyBundle.actionDisplayName(type, e.getValue()).orElse(e.getValue()), null); }) .collect(toSet()); }
private boolean actionMatch(final String name, final ActionReference action) { return deParameterize(action.getName()).equals(deParameterize(name)); }
private boolean matchAction(final Map.Entry<String, String> v, final ActionReference a) { return actionMatch(v.getValue(), a) && v.getKey().substring("action::".length()).equals(a.getType()); }
private Collection<ActionReference> findActions(final String family, final Set<ActionReference> actions, final Container container, final Locale locale, final FamilyBundle familyBundle) { final ContainerComponentRegistry registry = container.get(ContainerComponentRegistry.class); return registry .getServices() .stream() .flatMap(s -> s.getActions().stream()) .filter(s -> s.getFamily().equals(family)) .filter(s -> actions .stream() .anyMatch(e -> s.getFamily().equals(e.getFamily()) && s.getType().equals(e.getType()) && s.getAction().equals(e.getName()))) .map(s -> new ActionReference(s.getFamily(), s.getAction(), s.getType(), familyBundle.actionDisplayName(s.getType(), s.getAction()).orElse(s.getAction()), propertiesService .buildProperties(s.getParameters(), container.getLoader(), locale, null) .collect(toList()))) .collect(toList()); }
protected List<UiSchema.Parameter> toParams(final Collection<SimplePropertyDefinition> properties, final SimplePropertyDefinition prop, final ActionReference ref, final String parameters) { final Iterator<SimplePropertyDefinition> expectedProperties = ref .getProperties() .stream() .filter(it -> it.getMetadata().containsKey("definition::parameter::index")) && properties.stream().noneMatch(p -> p.getPath().equals(propertiesPrefix))) { throw new IllegalArgumentException("No resolved parameters for " + prop.getPath() + " in " + ref.getFamily() + "/" + ref.getType() + "/" + ref.getName());
actions .stream() .filter(a -> a.getName().equals(schemaActionName) && "schema".equals(a.getType())) .findFirst() .ifPresent(ref -> { .stream() .filter(nested -> ref .getName() .equals(nested.getMetadata().get("configurationtype::name")) && "dataset".equals(nested.getMetadata().get("configurationtype::type"))) final UiSchema.Parameter parameter = new UiSchema.Parameter(); parameter .setKey(ofNullable(ref.getProperties()) .orElse(Collections.emptyList()) .stream() .setTitle(ref.getDisplayName() == null || ref.getName().equals(ref.getDisplayName()) ? "Guess Schema" : ref.getDisplayName()); button.setWidget("button"); button.setTriggers(singletonList(trigger));
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; }); }
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 void addHealthCheck(final PropertyContext<?> root, final Collection<UiSchema> items) { ofNullable(root.getProperty().getMetadata().get("action::healthcheck")) .flatMap(v -> (actions == null ? Stream.<ActionReference> empty() : actions.stream()) .filter(a -> a.getName().equals(v) && "healthcheck".equals(a.getType())) .findFirst()) .ifPresent(ref -> { .equals(nested.getMetadata().get("configurationtype::type")) && ref .getName() .equals(nested .getMetadata() final UiSchema.Parameter parameter = new UiSchema.Parameter(); parameter .setKey(ofNullable(ref.getProperties()) .orElse(Collections.emptyList()) .stream() .setTitle(ref.getDisplayName() == null || ref.getName().equals(ref.getDisplayName()) ? "Validate Connection" : ref.getDisplayName()); button.setWidget("button"); button.setTriggers(singletonList(trigger));
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 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); }