public boolean isRequired() { return property.getValidation() != null && property.getValidation().getRequired() != null && property.getValidation().getRequired(); }
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)); } }
@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 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()); }
.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());
protected CompletionStage<PropertyContext<?>> fillProposalsAndReturn(final PropertyContext<?> context, final UiSchema schema, final JsonSchema jsonSchema) { if (context.getProperty().getValidation() != null && context.getProperty().getValidation().getEnumValues() != null) { schema .setTitleMap(context.getProperty().getProposalDisplayNames() != null return nameValue; }).collect(toList()) : context.getProperty().getValidation().getEnumValues().stream().sorted().map(v -> { final UiSchema.NameValue nameValue = new UiSchema.NameValue(); nameValue.setName(v); return nameValue; }).collect(toList())); jsonSchema.setEnumValues(context.getProperty().getValidation().getEnumValues()); } else { final String actionName = context.getProperty().getMetadata().get("action::dynamic_values");
convertDefaultValue(type, defaultValue).ifPresent(jsonSchema::setDefaultValue); final PropertyValidation validation = context.getProperty().getValidation(); if (validation != null) { ofNullable(validation.getMin()).ifPresent(m -> jsonSchema.setMinimum(m.doubleValue()));
.orElseGet(() -> completedFuture(new LinkedHashMap<>())) .thenApply(potentialIdsAndNames -> { it.getValidation().setEnumValues(potentialIdsAndNames.keySet()); it.setProposalDisplayNames(potentialIdsAndNames); return 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())) .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); }); } }