use of javax.ws.rs.core.PathSegment 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 javax.ws.rs.core.PathSegment 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);
}
use of javax.ws.rs.core.PathSegment in project ovirt-engine by oVirt.
the class UsageFinderTest method mockUri.
private UriInfo mockUri(String... strings) throws URISyntaxException {
UriInfo uriInfoMock = mock(UriInfo.class);
List<PathSegment> pathSegments = new ArrayList<>();
for (String s : strings) {
PathSegment segment = mock(PathSegment.class);
when(segment.getPath()).thenReturn(s);
pathSegments.add(segment);
}
when(uriInfoMock.getPathSegments()).thenReturn(pathSegments);
return uriInfoMock;
}
use of javax.ws.rs.core.PathSegment in project Payara by payara.
the class CompositeResource method getParentUri.
private URI getParentUri(boolean isCollectionChild) throws Exception {
List<PathSegment> pathSegments = this.uriInfo.getPathSegments();
// go up a level to get to the parent
int count = pathSegments.size() - 1;
if (isCollectionChild) {
// collection children have the url pattern .../foos/id/myfoo. need to go up another level
count--;
}
// [0] = 'javaservice', which is a resource
if (count <= 0) {
// top level resource
return null;
}
UriBuilder bldr = this.uriInfo.getBaseUriBuilder();
for (int i = 0; i < count; i++) {
bldr.path(pathSegments.get(i).getPath());
}
return bldr.build();
}
use of javax.ws.rs.core.PathSegment in project ovirt-engine by oVirt.
the class AbstractBackendBaseTest method addMatrixParameterExpectations.
protected UriInfo addMatrixParameterExpectations(UriInfo mockUriInfo, Map<String, String> parameters) {
MultivaluedMap<String, String> matrixParams = new SimpleMultivaluedMap<>();
for (Map.Entry<String, String> entry : parameters.entrySet()) {
matrixParams.putSingle(entry.getKey(), entry.getValue());
}
PathSegment segment = mock(PathSegment.class);
when(segment.getMatrixParameters()).thenReturn(matrixParams);
when(mockUriInfo.getPathSegments()).thenReturn(Collections.singletonList(segment));
return mockUriInfo;
}
Aggregations