Search in sources :

Example 1 with ParserException

use of com.hortonworks.registries.common.exception.ParserException in project registry by hortonworks.

the class AbstractStorable method getSchema.

/**
 * Default implementation that will generate schema by reading all the field names in the class and use its
 * define type to convert to the Schema type.
 *
 * @return the schema
 */
@JsonIgnore
public Schema getSchema() {
    Map<String, Class> fieldNamesToTypes = ReflectionHelper.getFieldNamesToTypes(this.getClass());
    List<Schema.Field> fields = new ArrayList<>();
    for (Map.Entry<String, Class> entry : fieldNamesToTypes.entrySet()) {
        try {
            getField(entry.getKey(), entry.getValue()).ifPresent(field -> {
                fields.add(field);
                LOG.trace("getSchema: Adding {}", field);
            });
        } catch (NoSuchFieldException | NoSuchMethodException | InvocationTargetException | IllegalAccessException | ParserException e) {
            throw new StorageException(e);
        }
    }
    return Schema.of(fields);
}
Also used : ParserException(com.hortonworks.registries.common.exception.ParserException) ArrayList(java.util.ArrayList) InvocationTargetException(java.lang.reflect.InvocationTargetException) Field(java.lang.reflect.Field) HashMap(java.util.HashMap) Map(java.util.Map) StorageException(com.hortonworks.registries.storage.exception.StorageException) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore)

Example 2 with ParserException

use of com.hortonworks.registries.common.exception.ParserException in project streamline by hortonworks.

the class UDFCatalogResource method getArgTypes.

private List<String> getArgTypes(Class<?> clazz, String methodname, int argStartIndex) {
    Method addMethod = findMethod(clazz, methodname);
    if (addMethod == null) {
        return Collections.emptyList();
    }
    final Class<?>[] params = addMethod.getParameterTypes();
    List<String> argTypes = new ArrayList<>();
    for (int i = argStartIndex; i < params.length; i++) {
        final Class<?> arg = params[i];
        try {
            argTypes.add(Schema.fromJavaType(arg).toString());
        } catch (ParserException ex) {
            Collection<Schema.Type> types = Collections2.filter(Arrays.asList(Schema.Type.values()), new Predicate<Schema.Type>() {

                public boolean apply(Schema.Type input) {
                    return arg.isAssignableFrom(input.getJavaType());
                }
            });
            if (types.isEmpty()) {
                LOG.error("Could not find a compatible type in schema for {} argument types", addMethod);
                return Collections.emptyList();
            } else {
                argTypes.add(Joiner.on("|").join(types));
            }
        }
    }
    return argTypes;
}
Also used : ParserException(com.hortonworks.registries.common.exception.ParserException) Schema(com.hortonworks.registries.common.Schema) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) Predicate(com.google.common.base.Predicate) MediaType(javax.ws.rs.core.MediaType) Collection(java.util.Collection)

Aggregations

ParserException (com.hortonworks.registries.common.exception.ParserException)2 ArrayList (java.util.ArrayList)2 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)1 Predicate (com.google.common.base.Predicate)1 Schema (com.hortonworks.registries.common.Schema)1 StorageException (com.hortonworks.registries.storage.exception.StorageException)1 Field (java.lang.reflect.Field)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 MediaType (javax.ws.rs.core.MediaType)1