Search in sources :

Example 1 with ArrayPropertyConverter

use of org.talend.sdk.component.form.internal.converter.impl.schema.ArrayPropertyConverter in project component-runtime by Talend.

the class JsonSchemaConverter method convert.

@Override
public CompletionStage<PropertyContext> convert(final CompletionStage<PropertyContext> cs) {
    return cs.thenCompose(context -> {
        final JsonSchema jsonSchema = new JsonSchema();
        jsonSchema.setTitle(context.getProperty().getDisplayName());
        final String type = context.getProperty().getType();
        switch(type.toLowerCase(ROOT)) {
            case "enum":
                return new EnumPropertyConverter(jsonSchema).convert(CompletableFuture.completedFuture(context)).thenCompose(c -> postHandling(context, jsonSchema, type));
            case "array":
                return new ArrayPropertyConverter(jsonb, jsonSchema, properties).convert(CompletableFuture.completedFuture(context)).thenCompose(c -> postHandling(context, jsonSchema, type));
            default:
                if (context.getProperty().getPath().endsWith("[]")) {
                    return CompletableFuture.completedFuture(context);
                }
                jsonSchema.setType(type.toLowerCase(ROOT));
                jsonSchema.setRequired(properties.stream().filter(context::isDirectChild).filter(nested -> new PropertyContext(nested).isRequired()).map(SimplePropertyDefinition::getName).collect(toSet()));
                return CompletableFuture.completedFuture(context).thenCompose(c -> postHandling(context, jsonSchema, type));
        }
    });
}
Also used : EnumPropertyConverter(org.talend.sdk.component.form.internal.converter.impl.schema.EnumPropertyConverter) Optional.ofNullable(java.util.Optional.ofNullable) Collection(java.util.Collection) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) PropertyContext(org.talend.sdk.component.form.internal.converter.PropertyContext) JsonSchema(org.talend.sdk.component.form.model.jsonschema.JsonSchema) ArrayPropertyConverter(org.talend.sdk.component.form.internal.converter.impl.schema.ArrayPropertyConverter) PropertyConverter(org.talend.sdk.component.form.internal.converter.PropertyConverter) ArrayList(java.util.ArrayList) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) TreeMap(java.util.TreeMap) SimplePropertyDefinition(org.talend.sdk.component.server.front.model.SimplePropertyDefinition) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Optional(java.util.Optional) PropertyValidation(org.talend.sdk.component.server.front.model.PropertyValidation) Jsonb(javax.json.bind.Jsonb) ROOT(java.util.Locale.ROOT) Comparator(java.util.Comparator) AllArgsConstructor(lombok.AllArgsConstructor) Collectors.toSet(java.util.stream.Collectors.toSet) SimplePropertyDefinition(org.talend.sdk.component.server.front.model.SimplePropertyDefinition) PropertyContext(org.talend.sdk.component.form.internal.converter.PropertyContext) JsonSchema(org.talend.sdk.component.form.model.jsonschema.JsonSchema) ArrayPropertyConverter(org.talend.sdk.component.form.internal.converter.impl.schema.ArrayPropertyConverter) EnumPropertyConverter(org.talend.sdk.component.form.internal.converter.impl.schema.EnumPropertyConverter)

Aggregations

ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ROOT (java.util.Locale.ROOT)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Optional.ofNullable (java.util.Optional.ofNullable)1 TreeMap (java.util.TreeMap)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletionStage (java.util.concurrent.CompletionStage)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 Jsonb (javax.json.bind.Jsonb)1 AllArgsConstructor (lombok.AllArgsConstructor)1 PropertyContext (org.talend.sdk.component.form.internal.converter.PropertyContext)1 PropertyConverter (org.talend.sdk.component.form.internal.converter.PropertyConverter)1 ArrayPropertyConverter (org.talend.sdk.component.form.internal.converter.impl.schema.ArrayPropertyConverter)1 EnumPropertyConverter (org.talend.sdk.component.form.internal.converter.impl.schema.EnumPropertyConverter)1