Search in sources :

Example 1 with ModelVisitor

use of org.talend.sdk.component.runtime.visitor.ModelVisitor in project component-runtime by Talend.

the class ComponentValidator method validateModel.

private void validateModel(final AnnotationFinder finder, final List<Class<?>> components, final Set<String> errors) {
    errors.addAll(components.stream().filter(c -> componentMarkers().filter(c::isAnnotationPresent).count() > 1).map(i -> i + " has conflicting component annotations, ensure it has a single one").collect(toList()));
    final ModelVisitor modelVisitor = new ModelVisitor();
    final ModelListener noop = new ModelListener() {
    };
    errors.addAll(components.stream().map(c -> {
        try {
            modelVisitor.visit(c, noop, configuration.isValidateComponent());
            return null;
        } catch (final RuntimeException re) {
            return re.getMessage();
        }
    }).filter(Objects::nonNull).collect(toList()));
    // limited config types
    errors.addAll(finder.findAnnotatedFields(Structure.class).stream().filter(f -> !ParameterizedType.class.isInstance(f.getGenericType()) || (!isListString(f) && !isMapString(f))).map(f -> f.getDeclaringClass() + "#" + f.getName() + " uses @Structure but is not a List<String> nor a Map<String, String>").collect(toList()));
}
Also used : AnnotationFinder(org.apache.xbean.finder.AnnotationFinder) Version(org.talend.sdk.component.api.component.Version) Internationalized(org.talend.sdk.component.api.internationalization.Internationalized) HealthCheck(org.talend.sdk.component.api.service.healthcheck.HealthCheck) Collectors.toMap(java.util.stream.Collectors.toMap) ARRAY(org.talend.sdk.component.runtime.manager.ParameterMeta.Type.ARRAY) Map(java.util.Map) DynamicValues(org.talend.sdk.component.api.service.completion.DynamicValues) Method(java.lang.reflect.Method) Collectors.toSet(java.util.stream.Collectors.toSet) ParameterMeta(org.talend.sdk.component.runtime.manager.ParameterMeta) AsyncValidation(org.talend.sdk.component.api.service.asyncvalidation.AsyncValidation) ENUM(org.talend.sdk.component.runtime.manager.ParameterMeta.Type.ENUM) Collection(java.util.Collection) Set(java.util.Set) Collectors.joining(java.util.stream.Collectors.joining) Serializable(java.io.Serializable) DataSet(org.talend.sdk.component.api.configuration.type.DataSet) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) Documentation(org.talend.sdk.component.api.meta.Documentation) Proposable(org.talend.sdk.component.api.configuration.action.Proposable) Modifier(java.lang.reflect.Modifier) Function.identity(java.util.function.Function.identity) Service(org.talend.sdk.component.api.service.Service) Constructors.findConstructor(org.talend.sdk.component.runtime.manager.reflect.Constructors.findConstructor) Stream.empty(java.util.stream.Stream.empty) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) DiscoverSchema(org.talend.sdk.component.api.service.schema.DiscoverSchema) Icon(org.talend.sdk.component.api.component.Icon) Option(org.talend.sdk.component.api.configuration.Option) ModelListener(org.talend.sdk.component.runtime.visitor.ModelListener) DataStore(org.talend.sdk.component.api.configuration.type.DataStore) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ResourceBundle(java.util.ResourceBundle) ParameterModelService(org.talend.sdk.component.runtime.manager.reflect.ParameterModelService) Structure(org.talend.sdk.component.api.configuration.ui.widget.Structure) Stream.concat(java.util.stream.Stream.concat) Request(org.talend.sdk.component.api.service.http.Request) OBJECT(org.talend.sdk.component.runtime.manager.ParameterMeta.Type.OBJECT) Optional.ofNullable(java.util.Optional.ofNullable) Stream.of(java.util.stream.Stream.of) ModelVisitor(org.talend.sdk.component.runtime.visitor.ModelVisitor) Field(java.lang.reflect.Field) File(java.io.File) HttpClientFactoryImpl(org.talend.sdk.component.runtime.manager.service.HttpClientFactoryImpl) Collectors.toList(java.util.stream.Collectors.toList) AbstractMap(java.util.AbstractMap) Checkable(org.talend.sdk.component.api.configuration.action.Checkable) ParameterizedType(java.lang.reflect.ParameterizedType) Data(lombok.Data) ActionType(org.talend.sdk.component.api.service.ActionType) ModelVisitor(org.talend.sdk.component.runtime.visitor.ModelVisitor) ModelListener(org.talend.sdk.component.runtime.visitor.ModelListener) Objects(java.util.Objects) Structure(org.talend.sdk.component.api.configuration.ui.widget.Structure)

Example 2 with ModelVisitor

use of org.talend.sdk.component.runtime.visitor.ModelVisitor in project component-runtime by Talend.

the class ModelVisitorTest method visit.

private List<String> visit(final Class<?> type) {
    final ModelVisitor visitor = new ModelVisitor();
    final List<String> tracker = new ArrayList<>();
    Stream.of(type.getClasses()).sorted(Comparator.comparing(Class::getName)).forEach(nested -> visitor.visit(nested, new ModelListener() {

        @Override
        public void onPartitionMapper(final Class<?> type, final PartitionMapper partitionMapper) {
            tracker.add("@PartitionMapper(" + type.getName() + ")");
        }

        @Override
        public void onEmitter(final Class<?> type, final Emitter emitter) {
            tracker.add("@Emitter(" + type.getName() + ")");
        }

        @Override
        public void onProcessor(final Class<?> type, final Processor processor) {
            tracker.add("@Processor(" + type.getName() + ")");
        }
    }, true));
    return tracker;
}
Also used : PartitionMapper(org.talend.sdk.component.api.input.PartitionMapper) Emitter(org.talend.sdk.component.api.input.Emitter) Processor(org.talend.sdk.component.api.processor.Processor) ModelVisitor(org.talend.sdk.component.runtime.visitor.ModelVisitor) ArrayList(java.util.ArrayList) ModelListener(org.talend.sdk.component.runtime.visitor.ModelListener)

Aggregations

ArrayList (java.util.ArrayList)2 File (java.io.File)1 Serializable (java.io.Serializable)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 Modifier (java.lang.reflect.Modifier)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 AbstractMap (java.util.AbstractMap)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional.ofNullable (java.util.Optional.ofNullable)1 ResourceBundle (java.util.ResourceBundle)1 Set (java.util.Set)1 Function.identity (java.util.function.Function.identity)1 Collectors.groupingBy (java.util.stream.Collectors.groupingBy)1 Collectors.joining (java.util.stream.Collectors.joining)1 Collectors.toList (java.util.stream.Collectors.toList)1