Search in sources :

Example 56 with PathSegment

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;
}
Also used : PathSegment(javax.ws.rs.core.PathSegment) ServiceTreeNode(org.ovirt.engine.api.rsdl.ServiceTreeNode)

Example 57 with PathSegment

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);
}
Also used : PathSegment(javax.ws.rs.core.PathSegment) Current(org.ovirt.engine.api.restapi.invocation.Current)

Example 58 with PathSegment

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;
}
Also used : ArrayList(java.util.ArrayList) PathSegment(javax.ws.rs.core.PathSegment) UriInfo(javax.ws.rs.core.UriInfo)

Example 59 with PathSegment

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();
}
Also used : PathSegment(javax.ws.rs.core.PathSegment) UriBuilder(javax.ws.rs.core.UriBuilder)

Example 60 with PathSegment

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;
}
Also used : PathSegment(javax.ws.rs.core.PathSegment) Map(java.util.Map) HashMap(java.util.HashMap) MultivaluedMap(javax.ws.rs.core.MultivaluedMap)

Aggregations

PathSegment (javax.ws.rs.core.PathSegment)67 UriInfo (javax.ws.rs.core.UriInfo)19 Test (org.junit.Test)18 ArrayList (java.util.ArrayList)12 Map (java.util.Map)11 UriBuilder (javax.ws.rs.core.UriBuilder)11 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)10 VFSContainer (org.olat.core.util.vfs.VFSContainer)10 VFSItem (org.olat.core.util.vfs.VFSItem)10 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)10 Response (javax.ws.rs.core.Response)9 HashMap (java.util.HashMap)7 List (java.util.List)7 SystemItemFilter (org.olat.core.util.vfs.filters.SystemItemFilter)7 WebApplicationException (javax.ws.rs.WebApplicationException)6 MetadataMap (org.apache.cxf.jaxrs.impl.MetadataMap)6 URL (java.net.URL)5 TreeMap (java.util.TreeMap)5 UUID (java.util.UUID)5 OutputStream (java.io.OutputStream)4