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);
}
}
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;
}
Aggregations