Skip to content

Commit

Permalink
chore(QTDI-1056): update formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
ozhelezniak-talend committed Dec 20, 2024
1 parent 6fd711d commit f7c1c1e
Show file tree
Hide file tree
Showing 79 changed files with 3,061 additions and 2,893 deletions.
692 changes: 399 additions & 293 deletions build/talend_java_eclipse_formatter.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -61,28 +61,28 @@ public CompletionStage<PropertyContext<?>> convert(final CompletionStage<Propert
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));
of(context
.findDirectChild(properties)
.filter(nested -> new PropertyContext<>(nested, context.getRootContext(),
context.getConfiguration()).isRequired())
.map(SimplePropertyDefinition::getName)
.collect(toSet())).filter(s -> !s.isEmpty()).ifPresent(jsonSchema::setRequired);
return CompletableFuture
.completedFuture(context)
.thenCompose(c -> postHandling(context, jsonSchema, type));
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));
of(context
.findDirectChild(properties)
.filter(nested -> new PropertyContext<>(nested, context.getRootContext(),
context.getConfiguration()).isRequired())
.map(SimplePropertyDefinition::getName)
.collect(toSet())).filter(s -> !s.isEmpty()).ifPresent(jsonSchema::setRequired);
return CompletableFuture
.completedFuture(context)
.thenCompose(c -> postHandling(context, jsonSchema, type));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,67 +92,72 @@ public CompletionStage<PropertyContext<?>> convert(final CompletionStage<Propert
final String type = property.getType().toLowerCase(Locale.ROOT);
final Map<String, String> metadata = property.getMetadata();
switch (type) {
case "object":
return convertObject(context, metadata, null, idGenerator);
case "boolean":
includedProperties.add(property);
return new ToggleWidgetConverter(schemas, properties, actions, jsonSchema, lang)
.convert(CompletableFuture.completedFuture(context));
case "enum":
includedProperties.add(property);
return new DataListWidgetConverter(schemas, properties, actions, client, family,
jsonSchema, lang).convert(CompletableFuture.completedFuture(context));
case "number":
includedProperties.add(property);
return new NumberWidgetConverter(schemas, properties, actions, jsonSchema, lang)
.convert(CompletableFuture.completedFuture(context));
case "array":
includedProperties.add(property);
final String nestedPrefix = property.getPath() + "[].";
final int from = nestedPrefix.length();
final Collection<SimplePropertyDefinition> nested = properties
.stream()
.filter(prop -> prop.getPath().startsWith(nestedPrefix)
&& prop.getPath().indexOf('.', from) < 0)
.collect(toList());
if (!nested.isEmpty()) {
return new ObjectArrayWidgetConverter(schemas, properties, actions, family, client,
gridLayoutFilter, jsonSchema, lang, customConverters, metadata, idGenerator)
case "object":
return convertObject(context, metadata, null, idGenerator);
case "boolean":
includedProperties.add(property);
return new ToggleWidgetConverter(schemas, properties, actions, jsonSchema, lang)
.convert(CompletableFuture.completedFuture(context));
}
return new MultiSelectWidgetConverter(schemas, properties, actions, client, family,
jsonSchema, lang).convert(CompletableFuture.completedFuture(context));
case "string":
default:
if (property.getPath().endsWith("[]")) {
return CompletableFuture.completedFuture(context);
}
includedProperties.add(property);
if ("true".equalsIgnoreCase(metadata.get("ui::credential"))) {
return new CredentialWidgetConverter(schemas, properties, actions, jsonSchema, lang)
.convert(CompletableFuture.completedFuture(context));
} else if (metadata.containsKey("ui::code::value")) {
return new CodeWidgetConverter(schemas, properties, actions, jsonSchema, lang)
.convert(CompletableFuture.completedFuture(context));
} else if (metadata.containsKey("action::suggestions")
|| metadata.containsKey("action::built_in_suggestable")) {
return new SuggestionWidgetConverter(schemas, properties, actions, jsonSchema, lang)
.convert(CompletableFuture.completedFuture(context));
} else if (metadata.containsKey("action::dynamic_values")) {
case "enum":
includedProperties.add(property);
return new DataListWidgetConverter(schemas, properties, actions, client, family,
jsonSchema, lang).convert(CompletableFuture.completedFuture(context));
} else if (metadata.containsKey("ui::textarea")
&& Boolean.valueOf(metadata.get("ui::textarea"))) {
return new TextAreaWidgetConverter(schemas, properties, actions, jsonSchema, lang)
case "number":
includedProperties.add(property);
return new NumberWidgetConverter(schemas, properties, actions, jsonSchema, lang)
.convert(CompletableFuture.completedFuture(context));
} else if (metadata.containsKey("ui::datetime")) {
return new DateTimeConverter(schemas, properties, actions, jsonSchema, lang,
metadata.get("ui::datetime"))
case "array":
includedProperties.add(property);
final String nestedPrefix = property.getPath() + "[].";
final int from = nestedPrefix.length();
final Collection<SimplePropertyDefinition> nested = properties
.stream()
.filter(prop -> prop.getPath().startsWith(nestedPrefix)
&& prop.getPath().indexOf('.', from) < 0)
.collect(toList());
if (!nested.isEmpty()) {
return new ObjectArrayWidgetConverter(schemas, properties, actions, family,
client,
gridLayoutFilter, jsonSchema, lang, customConverters, metadata,
idGenerator)
.convert(CompletableFuture.completedFuture(context));
}
return new MultiSelectWidgetConverter(schemas, properties, actions, client, family,
jsonSchema, lang).convert(CompletableFuture.completedFuture(context));
case "string":
default:
if (property.getPath().endsWith("[]")) {
return CompletableFuture.completedFuture(context);
}
includedProperties.add(property);
if ("true".equalsIgnoreCase(metadata.get("ui::credential"))) {
return new CredentialWidgetConverter(schemas, properties, actions, jsonSchema,
lang)
.convert(CompletableFuture.completedFuture(context));
} else if (metadata.containsKey("ui::code::value")) {
return new CodeWidgetConverter(schemas, properties, actions, jsonSchema, lang)
.convert(CompletableFuture.completedFuture(context));
} else if (metadata.containsKey("action::suggestions")
|| metadata.containsKey("action::built_in_suggestable")) {
return new SuggestionWidgetConverter(schemas, properties, actions, jsonSchema,
lang)
.convert(CompletableFuture.completedFuture(context));
} else if (metadata.containsKey("action::dynamic_values")) {
return new DataListWidgetConverter(schemas, properties, actions, client, family,
jsonSchema, lang).convert(CompletableFuture.completedFuture(context));
} else if (metadata.containsKey("ui::textarea")
&& Boolean.valueOf(metadata.get("ui::textarea"))) {
return new TextAreaWidgetConverter(schemas, properties, actions, jsonSchema,
lang)
.convert(CompletableFuture.completedFuture(context));
} else if (metadata.containsKey("ui::datetime")) {
return new DateTimeConverter(schemas, properties, actions, jsonSchema, lang,
metadata.get("ui::datetime"))
.convert(CompletableFuture.completedFuture(context));
}

return new TextWidgetConverter(schemas, properties, actions, jsonSchema, lang)
.convert(CompletableFuture.completedFuture(context));
}

return new TextWidgetConverter(schemas, properties, actions, jsonSchema, lang)
.convert(CompletableFuture.completedFuture(context));
}
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,15 +347,15 @@ protected Map<String, Collection<Object>> createCondition(final PropertyContext<
}

switch (conditions.size()) {
case 0:
return null;
case 1:
return conditions.iterator().next();
default:
final String operator = ofNullable(ctx.getProperty().getMetadata().get("condition::ifs::operator"))
.orElse("AND")
.toLowerCase(ROOT);
return new UiSchema.ConditionBuilder().withOperator(operator).withValues(conditions).build();
case 0:
return null;
case 1:
return conditions.iterator().next();
default:
final String operator = ofNullable(ctx.getProperty().getMetadata().get("condition::ifs::operator"))
.orElse("AND")
.toLowerCase(ROOT);
return new UiSchema.ConditionBuilder().withOperator(operator).withValues(conditions).build();
}
}

Expand All @@ -373,26 +373,26 @@ private static Map<String, Collection<Object>> getUiScopeCondition(final boolean
protected Map<String, Collection<Object>> toCondition(final String path, final String strategy, final Object value,
final SimplePropertyDefinition def) {
switch (strategy) {
case "length":
return new UiSchema.ConditionBuilder()
.withOperator("===")
.withVar(path + ".length")
.withValue(String.class.isInstance(value) ? Integer.parseInt(String.valueOf(value)) : value)
.build();
case "contains":
case "contains(lowercase=true)":
final UiSchema.ConditionValuesBuilder in = new UiSchema.ConditionBuilder().withOperator("in");
final Object val =
strategy.endsWith("(lowercase=true)") ? String.class.cast(value).toLowerCase(ROOT) : value;
if (def != null && "array".equalsIgnoreCase(def.getType())) {
in.withVar(path).withValue(val).up();
} else {
in.withValue(val).withVar(path).up();
}
return in.build();
case "default":
default:
return new UiSchema.ConditionBuilder().withOperator("===").withVar(path).withValue(value).build();
case "length":
return new UiSchema.ConditionBuilder()
.withOperator("===")
.withVar(path + ".length")
.withValue(String.class.isInstance(value) ? Integer.parseInt(String.valueOf(value)) : value)
.build();
case "contains":
case "contains(lowercase=true)":
final UiSchema.ConditionValuesBuilder in = new UiSchema.ConditionBuilder().withOperator("in");
final Object val =
strategy.endsWith("(lowercase=true)") ? String.class.cast(value).toLowerCase(ROOT) : value;
if (def != null && "array".equalsIgnoreCase(def.getType())) {
in.withVar(path).withValue(val).up();
} else {
in.withValue(val).withVar(path).up();
}
return in.build();
case "default":
default:
return new UiSchema.ConditionBuilder().withOperator("===").withVar(path).withValue(value).build();
}
}

Expand All @@ -401,14 +401,14 @@ protected Function<String, Object> findStringValueMapper(final SimplePropertyDef
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;
case "boolean":
return Boolean::parseBoolean;
case "number":
return Double::parseDouble;

// assume object and array are not supported
default:
return s -> s;
}
}

Expand Down
Loading

0 comments on commit f7c1c1e

Please sign in to comment.