use of org.talend.sdk.component.api.service.schema.Schema in project component-runtime by Talend.
the class TaCoKitGuessSchema method guessSchemaThroughAction.
public boolean guessSchemaThroughAction() {
if (action == null || action.isEmpty()) {
return false;
}
final ServiceMeta.ActionMeta actionRef = componentManager.findPlugin(plugin).orElseThrow(() -> new IllegalArgumentException("No component " + plugin)).get(ContainerComponentRegistry.class).getServices().stream().flatMap(s -> s.getActions().stream()).filter(a -> a.getFamily().equals(family) && a.getAction().equals(action) && a.getType().equals(type)).findFirst().orElseThrow(() -> new IllegalArgumentException("No action " + family + "#" + type + "#" + action));
final Object schemaResult = actionRef.getInvoker().apply(buildActionConfig(actionRef, configuration));
if (schemaResult instanceof Schema) {
Collection<Schema.Entry> entries = Schema.class.cast(schemaResult).getEntries();
if (entries == null || entries.isEmpty()) {
log.info("No column found by guess schema action");
return false;
}
for (Schema.Entry entry : entries) {
String name = entry.getName();
Type entryType = entry.getType();
if (entryType == null) {
entryType = Type.STRING;
}
String typeName;
switch(entryType) {
case BOOLEAN:
typeName = javaTypesManager.BOOLEAN.getId();
break;
case DOUBLE:
typeName = javaTypesManager.DOUBLE.getId();
break;
case INT:
typeName = javaTypesManager.INTEGER.getId();
break;
default:
typeName = javaTypesManager.STRING.getId();
break;
}
append(str, name, typeName);
}
return true;
} else {
log.error("Result of built-in guess schema action is not an instance of TaCoKit Schema");
return false;
}
}
use of org.talend.sdk.component.api.service.schema.Schema in project component-runtime by Talend.
the class Generator method sample.
private static String sample(final Class<?> returnedType) {
if (returnedType == Values.class) {
final Values list = new Values();
list.setItems(new ArrayList<>());
final Values.Item item = new Values.Item();
item.setId("value");
item.setLabel("label");
list.getItems().add(item);
return new MapperBuilder().setPretty(false).build().writeObjectAsString(list);
}
if (returnedType == HealthCheckStatus.class) {
final HealthCheckStatus status = new HealthCheckStatus();
status.setStatus(HealthCheckStatus.Status.KO);
status.setComment("Something went wrong");
return new MapperBuilder().setPretty(false).build().writeObjectAsString(status);
}
if (returnedType == Schema.class) {
final Schema.Entry entry = new Schema.Entry();
entry.setName("column1");
entry.setType(Type.STRING);
final Schema schema = new Schema();
schema.setEntries(new ArrayList<>());
schema.getEntries().add(entry);
return new MapperBuilder().setPretty(false).build().writeObjectAsString(schema);
}
if (returnedType == ValidationResult.class) {
final ValidationResult status = new ValidationResult();
status.setStatus(ValidationResult.Status.KO);
status.setComment("Something went wrong");
return new MapperBuilder().setPretty(false).build().writeObjectAsString(status);
}
return "{\n" + Stream.of(returnedType.getDeclaredFields()).map(f -> " \"" + f.getName() + "\": " + createSample(f.getType())).collect(joining("\n")) + "\n}";
}
Aggregations