Search in sources :

Example 1 with Stream.of

use of java.util.stream.Stream.of in project component-runtime by Talend.

the class ComponentValidator method validateInternationalization.

private void validateInternationalization(final AnnotationFinder finder, final List<Class<?>> components, final Set<String> errors) {
    errors.addAll(components.stream().map(this::validateComponentResourceBundle).filter(Objects::nonNull).collect(toList()));
    errors.addAll(finder.findAnnotatedFields(Option.class).stream().map(Field::getType).filter(Class::isEnum).distinct().flatMap(enumType -> Stream.of(enumType.getFields()).filter(f -> Modifier.isStatic(f.getModifiers()) && Modifier.isFinal(f.getModifiers())).filter(f -> {
        final ResourceBundle bundle = ofNullable(findResourceBundle(enumType)).orElseGet(() -> findResourceBundle(f.getDeclaringClass()));
        final String key = enumType.getSimpleName() + "." + f.getName() + "._displayName";
        return bundle == null || !bundle.containsKey(key);
    }).map(f -> "Missing key " + enumType.getSimpleName() + "." + f.getName() + "._displayName in " + enumType + " resource bundle")).collect(toSet()));
    for (final Class<?> i : finder.findAnnotatedClasses(Internationalized.class)) {
        final ResourceBundle resourceBundle = findResourceBundle(i);
        if (resourceBundle != null) {
            final Collection<String> keys = of(i.getMethods()).filter(m -> m.getDeclaringClass() != Object.class).map(m -> i.getName() + "." + m.getName()).collect(toSet());
            errors.addAll(keys.stream().filter(k -> !resourceBundle.containsKey(k)).map(k -> "Missing key " + k + " in " + i + " resource bundle").collect(toList()));
            errors.addAll(resourceBundle.keySet().stream().filter(k -> k.startsWith(i.getName() + ".") && !keys.contains(k)).map(k -> "Key " + k + " from " + i + " is no more used").collect(toList()));
        } else {
            errors.add("No resource bundle for " + i);
        }
    }
}
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) Objects(java.util.Objects) Option(org.talend.sdk.component.api.configuration.Option) ResourceBundle(java.util.ResourceBundle)

Aggregations

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 ArrayList (java.util.ArrayList)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