use of org.ovirt.engine.api.restapi.invocation.Current in project ovirt-engine by oVirt.
the class UsageFinderTest method init.
@Before
public void init() {
Current current = new Current();
current.setRoot("http://localhost:8080");
current.setPrefix("/ovirt-engine/api");
CurrentManager.put(current);
usageFinder = new UsageFinder();
}
use of org.ovirt.engine.api.restapi.invocation.Current in project ovirt-engine by oVirt.
the class LinkHelper method addActions.
/**
* Adds the set of action links for an object
*
* @param model the object to add actions to
* @param collection the object to get implemented methods from
*/
public static <R extends ActionableResource> void addActions(R model, Object collection) {
Current current = CurrentManager.get();
String base = current.getPrefix() + current.getPath();
if (base != null) {
ActionsBuilder actionsBuilder = new ActionsBuilder(base, model.getClass(), collection.getClass());
model.setActions(actionsBuilder.build());
}
}
use of org.ovirt.engine.api.restapi.invocation.Current in project ovirt-engine by oVirt.
the class ParametersHelper method setParameter.
/**
* Set a parameter in the parameters map.
*/
public static void setParameter(String name, String value) {
Current current = CurrentManager.get();
if (current != null) {
Map<String, String> parameters = current.getParameters();
parameters.put(name, value);
}
}
use of org.ovirt.engine.api.restapi.invocation.Current in project ovirt-engine by oVirt.
the class RsdlLoader method loadRsdl.
/**
* Loads the RSDL object appropriate for the current request and converts it to the corresponding Java object. Note
* that the RSDL object will be of different classes in V3 and V4 of the API, that is why the class is passed as
* a parameter, to be able to use this method for both V3 and V4.
*
* @param clazz the class of the RSDL object
* @param <RSDL> the type of the RSDL object
*/
public static <RSDL> RSDL loadRsdl(Class<RSDL> clazz) throws IOException {
// Decide what version of the RSDL document to load:
Current current = CurrentManager.get();
String fileName = current.getApplicationMode() == ApplicationMode.GlusterOnly ? "rsdl_gluster.xml" : "rsdl.xml";
String resourcePath = String.format("/v%s/%s", current.getVersion(), fileName);
// Calculate the prefix that will be used in the "href" attributes:
String prefix = current.getAbsolutePath();
// Load the RSDL document into a DOM tree and then modify all the "href" attributes to include the prefix that
// has been previously calculated:
Document document;
try {
DocumentBuilder parser = SecureDocumentBuilderFactory.newDocumentBuilderFactory().newDocumentBuilder();
try (InputStream in = RsdlIOManager.class.getResourceAsStream(resourcePath)) {
document = parser.parse(in);
}
XPath xpath = XPathFactory.newInstance().newXPath();
NodeList nodes = (NodeList) xpath.evaluate("//@href", document, XPathConstants.NODESET);
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
String href = node.getNodeValue();
if (href.startsWith("?")) {
href = prefix + href;
} else {
href = prefix + "/" + href;
}
node.setNodeValue(href);
}
} catch (Exception exception) {
throw new IOException(exception);
}
// Create the RSDL object:
return JAXB.unmarshal(new DOMSource(document), clazz);
}
use of org.ovirt.engine.api.restapi.invocation.Current in project ovirt-engine by oVirt.
the class V3UsageFinder method isMatch.
private boolean isMatch(V3DetailedLink link, UriInfo uriInfo, String httpMethod) {
int baseUriLength = uriInfo.getBaseUri().getPath().length();
// e.g: [vms, {vm:id}, start]
Current current = CurrentManager.get();
int charsToTruncate = current.getVersionSource() == VersionSource.URL ? 0 : current.getVersion().length() + 2;
String[] linkPathSegments = link.getHref().substring(baseUriLength - charsToTruncate).split("/");
// e.g: [vms, f26b0918-8e16-4915-b1c2-7f39e568de23, start]
List<PathSegment> uriPathSegments = uriInfo.getPathSegments();
return isMatchLength(linkPathSegments, uriPathSegments) && isMatchPath(linkPathSegments, uriPathSegments) && isMatchRel(link.getRel(), httpMethod);
}
Aggregations