use of org.ovirt.engine.api.rsdl.ServiceTreeNode in project ovirt-engine by oVirt.
the class ResourceLocator method locateResource.
/**
* Get the Resource class corresponding to the provided href
* Assumption: href is of a location, not an action
* (e.g: .../vms/{id} - good, .../vms/{id}/start - bad).
* Another assumption is that href is not empty.
*/
public BaseBackendResource locateResource(String href) throws Exception {
href = removePrefix(href);
ServiceTreeCrawler crawler = new ServiceTreeCrawler(Arrays.asList(href.split("/")));
BaseBackendResource resource = BackendApiResource.getInstance();
ServiceTreeNode node = null;
while (crawler.hasNext()) {
node = crawler.next();
if (node.isCollection()) {
// collection context
// getSubResource()
Method method = resource.getClass().getMethod(node.getGetter());
resource = (BaseBackendResource) method.invoke(resource);
} else {
// single entity context
// getSubResource(String id)
Method method = resource.getClass().getMethod(node.getGetter(), String.class);
resource = (BaseBackendResource) method.invoke(resource, crawler.getCurrentPathSegment());
}
}
return resource;
}
use of org.ovirt.engine.api.rsdl.ServiceTreeNode in project ovirt-engine by oVirt.
the class UsageFinder method getUsageLink.
private String getUsageLink(UriInfo uriInfo, String httpMethod) {
List<PathSegment> pathSegments = uriInfo.getPathSegments();
ServiceTreeNode node = ServiceTree.getTree();
// step into the Service tree according to the URL.
for (PathSegment pathSegment : pathSegments) {
node = step(node, pathSegment);
}
// check whether the last step in the URL represent an 'action'.
PathSegment lastPathSegment = pathSegments.get(pathSegments.size() - 1);
// Get the prefix of the link, with or without 's' appended to the
// entity name, according to whether this action is on a single entity
// or on the collection context, e.g:
// .../apidoc#services/vm/methods/start //action on *vm*
// .../apidoc#services/vms/methods/add //action on *vms*
// .../apidoc#services/vm/methods/update //action on *vm*
// .../apidoc#services/vm/methods/remove //action on *vm*
String link = getLinkPrefix(node);
if (isAction(node, lastPathSegment.getPath())) {
link += camelCaseToUnderscore(getAction(node, lastPathSegment.getPath()));
} else {
link += getMethodName(httpMethod);
}
return link;
}
use of org.ovirt.engine.api.rsdl.ServiceTreeNode in project ovirt-engine by oVirt.
the class AbstractBackendResource method getSubCollections.
/**
* Returns an array with the names of subcollections of this resource,
* e.g, for BackendVmResource: ["affinitylabels", "applications", "cdroms",
* "diskattachments", "graphicsconsoles", "hostdevices", "katelloerrata"...]
*/
protected String[] getSubCollections() {
Set<Class<?>> interfaces = getInterfaces();
List<String> subCollections = new ArrayList<>();
for (Class<?> clazz : interfaces) {
ServiceTreeNode node = getRequiredNode(clazz);
if (node != null) {
addSubCollections(node, subCollections);
}
}
return subCollections.toArray(new String[0]);
}
Aggregations