Search in sources :

Example 1 with UnknownPropertyException

use of com.thinkbiganalytics.metadata.modeshape.UnknownPropertyException in project kylo by Teradata.

the class NodeEntityMixin method getPropertyAsSet.

default <T> Set<T> getPropertyAsSet(String name, Class<T> objectType) {
    Object o = null;
    try {
        o = JcrPropertyUtil.getProperty(getNode(), name);
    } catch (UnknownPropertyException e) {
    }
    if (o != null) {
        if (o instanceof Collection) {
            // convert the objects to the correct type if needed
            if (JcrObject.class.isAssignableFrom(objectType)) {
                Set<T> objects = new HashSet<>();
                for (Object collectionObj : (Collection) o) {
                    T obj = null;
                    if (collectionObj instanceof Node) {
                        try {
                            obj = ConstructorUtils.invokeConstructor(objectType, (Node) collectionObj);
                        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e) {
                            obj = (T) collectionObj;
                        }
                    } else {
                        obj = (T) collectionObj;
                    }
                    objects.add(obj);
                }
                return objects;
            } else {
                return new HashSet<T>((Collection) o);
            }
        } else {
            Set<T> set = new HashSet<>();
            if (JcrObject.class.isAssignableFrom(objectType) && o instanceof Node) {
                T obj = null;
                try {
                    obj = ConstructorUtils.invokeConstructor(objectType, (Node) o);
                    set.add((T) obj);
                } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e) {
                }
                set.add(obj);
            } else {
                set.add((T) o);
            }
            return set;
        }
    }
    return new HashSet<T>();
}
Also used : Node(javax.jcr.Node) UnknownPropertyException(com.thinkbiganalytics.metadata.modeshape.UnknownPropertyException) InvocationTargetException(java.lang.reflect.InvocationTargetException) JcrObject(com.thinkbiganalytics.metadata.modeshape.common.JcrObject) Collection(java.util.Collection) JcrObject(com.thinkbiganalytics.metadata.modeshape.common.JcrObject) HashSet(java.util.HashSet)

Aggregations

UnknownPropertyException (com.thinkbiganalytics.metadata.modeshape.UnknownPropertyException)1 JcrObject (com.thinkbiganalytics.metadata.modeshape.common.JcrObject)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Node (javax.jcr.Node)1