use of org.talend.sdk.component.api.service.completion.Values 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