Search in sources :

Example 1 with ActionableResource

use of org.ovirt.engine.api.model.ActionableResource in project ovirt-engine by oVirt.

the class LinkFollower method fetchData.

/**
 * For the provided single-entity type (e.g: Nic), follow the link represented by the
 * provided node. Do not follow child-links of this node.
 *
 * For example, for a Nic object and the tree:
 *
 *   vnicprofiles
 *        networkfilter
 *        qos
 *
 * This method fetches all vnicprofiles of this nic object and sets them in it. The method
 * then returns the fetched vnic-profiles. The child links networkfilter, qos are purposely ignored.
 */
private ActionableResource fetchData(BaseResource entity, LinksTreeNode link) {
    try {
        String element = underscoreToCamelCase(link.getElement());
        if (link.isFollowed()) {
            Method getter = ReflectionHelper.getGetter(entity, element);
            return (ActionableResource) getter.invoke(entity);
        } else {
            String href = getHref((BaseResource) entity, link.getElement());
            ActionableResource result = fetch(href);
            Method setter = ReflectionHelper.getSetter(entity, element);
            setter.invoke(entity, result);
            return result;
        }
    } catch (Exception e) {
        throw new IllegalStateException("Problem fetching '" + link.getElement() + "' from " + entity.getClass().getSimpleName(), e);
    }
}
Also used : ActionableResource(org.ovirt.engine.api.model.ActionableResource) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with ActionableResource

use of org.ovirt.engine.api.model.ActionableResource in project ovirt-engine by oVirt.

the class LinkFollower method fetchData.

/**
 * For the provided collection-type entity (e.g: Nics), follow the link represented by the
 * provided node. Do not follow child-links of this node.
 *
 * For example, for a Nics object:
 *
 *   nics [nic1, nic2]
 *
 * and the tree:
 *
 *   vnicprofiles
 *        networkfilter
 *        qos
 *
 * This method fetches all vnicprofiles of nic1, nic2, and sets them in these Nic objects.
 * The method will return the fetched vnic-profile objects. The child links networkfilter, qos
 * are purposely ignored.
 */
@SuppressWarnings("unchecked")
private List<ActionableResource> fetchData(BaseResources collectionEntity, LinksTreeNode node) {
    List<ActionableResource> results = new LinkedList<>();
    Method collectionGetter = EntityHelper.getCollectionGetter(collectionEntity);
    try {
        // get the actual list of entities in the collection-type, e.g for Nics get List<Nic>
        // (by invoking nics.getNics() using reflection)
        List<BaseResource> entities = (List<BaseResource>) collectionGetter.invoke(collectionEntity);
        // for each entity in the list, fetch link data.
        for (BaseResource entity : entities) {
            results.add(fetchData(entity, node));
        }
    } catch (Exception e) {
        throw new IllegalStateException("Problem following '" + node.getElement() + "' link in " + collectionEntity.getClass().getSimpleName() + " entity.", e);
    }
    return results;
}
Also used : BaseResource(org.ovirt.engine.api.model.BaseResource) ActionableResource(org.ovirt.engine.api.model.ActionableResource) List(java.util.List) LinkedList(java.util.LinkedList) Method(java.lang.reflect.Method) LinkedList(java.util.LinkedList) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 ActionableResource (org.ovirt.engine.api.model.ActionableResource)2 LinkedList (java.util.LinkedList)1 List (java.util.List)1 BaseResource (org.ovirt.engine.api.model.BaseResource)1