Search in sources :

Example 6 with PathKeys

use of com.linkedin.restli.server.PathKeys in project rest.li by linkedin.

the class TestRestLiRouting method testRoutingDetailsCollectionGet.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "routingDetailsCollectionEntity")
public void testRoutingDetailsCollectionGet(ProtocolVersion version, String uri) throws Exception {
    Map<String, ResourceModel> pathRootResourceMap = buildResourceModels(StatusCollectionResource.class);
    _router = new RestLiRouter(pathRootResourceMap);
    // #1 simple GET
    RestRequest request = createRequest(uri, "GET", version);
    RoutingResult result = _router.process(request, new RequestContext(), null);
    assertNotNull(result);
    ResourceMethodDescriptor resourceMethodDescriptor = result.getResourceMethod();
    assertNotNull(resourceMethodDescriptor);
    assertEquals(resourceMethodDescriptor.getType(), ResourceMethod.GET);
    assertNull(resourceMethodDescriptor.getActionName());
    assertNull(resourceMethodDescriptor.getFinderName());
    assertEquals(resourceMethodDescriptor.getMethod().getDeclaringClass(), StatusCollectionResource.class);
    assertEquals(resourceMethodDescriptor.getMethod().getName(), "get");
    assertEquals(resourceMethodDescriptor.getMethod().getParameterTypes(), new Class<?>[] { Long.class });
    assertEquals(resourceMethodDescriptor.getResourceModel().getName(), "statuses");
    assertNotNull(result.getContext());
    PathKeys keys = result.getContext().getPathKeys();
    assertEquals(keys.getAsLong("statusID"), new Long(1));
    assertNull(keys.getAsString("foo"));
}
Also used : RoutingResult(com.linkedin.restli.internal.server.RoutingResult) PathKeys(com.linkedin.restli.server.PathKeys) RestLiRouter(com.linkedin.restli.internal.server.RestLiRouter) RestRequest(com.linkedin.r2.message.rest.RestRequest) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RequestContext(com.linkedin.r2.message.RequestContext) Test(org.testng.annotations.Test)

Example 7 with PathKeys

use of com.linkedin.restli.server.PathKeys in project rest.li by linkedin.

the class RestLiAnnotationReader method buildPathKeysParam.

private static Parameter<?> buildPathKeysParam(final AnnotationSet annotations, final Class<?> paramType, final Class<?> paramAnnotationType) {
    if (!paramType.equals(PathKeys.class)) {
        throw new ResourceConfigException("Incorrect data type for param: @" + PathKeysParam.class.getSimpleName() + " or @" + Keys.class.getSimpleName() + " parameter annotation must be of type " + PathKeys.class.getName());
    }
    Optional optional = annotations.get(Optional.class);
    Parameter.ParamType parameter = null;
    if (paramAnnotationType.equals(Keys.class)) {
        parameter = Parameter.ParamType.PATH_KEYS;
    } else if (paramAnnotationType.equals(PathKeysParam.class)) {
        parameter = Parameter.ParamType.PATH_KEYS_PARAM;
    } else {
        throw new ResourceConfigException("Param Annotation type must be 'PathKeysParam' or the deprecated 'Keys' for PathKeys");
    }
    @SuppressWarnings({ "unchecked", "rawtypes" }) Parameter<?> param = new Parameter("", paramType, null, optional != null, new PathKeysImpl(), parameter, false, annotations);
    return param;
}
Also used : PathKeys(com.linkedin.restli.server.PathKeys) Optional(com.linkedin.restli.server.annotations.Optional) PathKeysParam(com.linkedin.restli.server.annotations.PathKeysParam) PathKeysImpl(com.linkedin.restli.internal.server.PathKeysImpl) ResourceConfigException(com.linkedin.restli.server.ResourceConfigException)

Example 8 with PathKeys

use of com.linkedin.restli.server.PathKeys in project rest.li by linkedin.

the class ComplexKeysSubResource method get.

@RestMethod.Get
public TwoPartKey get(String key) {
    PathKeys pathKeys = getContext().getPathKeys();
    ComplexResourceKey<TwoPartKey, TwoPartKey> keys = pathKeys.get("keys");
    return convert(keys);
}
Also used : PathKeys(com.linkedin.restli.server.PathKeys) TwoPartKey(com.linkedin.restli.examples.greetings.api.TwoPartKey)

Example 9 with PathKeys

use of com.linkedin.restli.server.PathKeys in project rest.li by linkedin.

the class AssociationsSubResource method get.

public Message get(String key) {
    PathKeys pathKeys = getContext().getPathKeys();
    String srcKey = pathKeys.getAsString("src");
    String destKey = pathKeys.getAsString("dest");
    Message message = new Message();
    message.setId(srcKey);
    message.setTone(Tone.FRIENDLY);
    message.setMessage(destKey);
    return message;
}
Also used : PathKeys(com.linkedin.restli.server.PathKeys) Message(com.linkedin.restli.examples.greetings.api.Message)

Example 10 with PathKeys

use of com.linkedin.restli.server.PathKeys in project rest.li by linkedin.

the class TestRestLiRouting method testRoutingDetailsAssociationBatchGet.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "routingDetailsAssociationBatch")
public void testRoutingDetailsAssociationBatchGet(ProtocolVersion version, String uri) throws Exception {
    Map<String, ResourceModel> pathRootResourceMap = buildResourceModels(FollowsAssociativeResource.class);
    _router = new RestLiRouter(pathRootResourceMap);
    RestRequest request = createRequest(uri, "GET", version);
    RoutingResult result = _router.process(request, new RequestContext(), null);
    assertNotNull(result);
    ResourceMethodDescriptor resourceMethodDescriptor = result.getResourceMethod();
    assertNotNull(resourceMethodDescriptor);
    assertEquals(resourceMethodDescriptor.getType(), ResourceMethod.BATCH_GET);
    assertNull(resourceMethodDescriptor.getActionName());
    assertNull(resourceMethodDescriptor.getFinderName());
    assertEquals(resourceMethodDescriptor.getMethod().getDeclaringClass(), FollowsAssociativeResource.class);
    assertEquals(resourceMethodDescriptor.getMethod().getName(), "batchGet");
    assertEquals(resourceMethodDescriptor.getMethod().getParameterTypes(), new Class<?>[] { Set.class });
    assertEquals(resourceMethodDescriptor.getResourceModel().getName(), "follows");
    assertNotNull(result.getContext());
    PathKeys keys = result.getContext().getPathKeys();
    assertNull(keys.getAsString("followerID"));
    assertNull(keys.getAsString("followeeID"));
    CompoundKey key1 = new CompoundKey();
    key1.append("followerID", 1L);
    key1.append("followeeID", 2L);
    CompoundKey key2 = new CompoundKey();
    key2.append("followerID", 3L);
    key2.append("followeeID", 4L);
    Set<CompoundKey> expectedBatchKeys = new HashSet<CompoundKey>();
    expectedBatchKeys.add(key1);
    expectedBatchKeys.add(key2);
    assertEquals(keys.getBatchIds().size(), 2);
    for (CompoundKey batchKey : keys.<CompoundKey>getBatchIds()) {
        assertTrue(expectedBatchKeys.contains(batchKey));
        expectedBatchKeys.remove(batchKey);
    }
    assertEquals(expectedBatchKeys.size(), 0);
}
Also used : RoutingResult(com.linkedin.restli.internal.server.RoutingResult) PathKeys(com.linkedin.restli.server.PathKeys) RestLiRouter(com.linkedin.restli.internal.server.RestLiRouter) RestRequest(com.linkedin.r2.message.rest.RestRequest) CompoundKey(com.linkedin.restli.common.CompoundKey) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RequestContext(com.linkedin.r2.message.RequestContext) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

PathKeys (com.linkedin.restli.server.PathKeys)15 Test (org.testng.annotations.Test)12 RestRequest (com.linkedin.r2.message.rest.RestRequest)11 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)11 ResourceModel (com.linkedin.restli.internal.server.model.ResourceModel)11 RequestContext (com.linkedin.r2.message.RequestContext)10 RestLiRouter (com.linkedin.restli.internal.server.RestLiRouter)10 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)10 CompoundKey (com.linkedin.restli.common.CompoundKey)2 Parameter (com.linkedin.restli.internal.server.model.Parameter)2 IntegerDataSchema (com.linkedin.data.schema.IntegerDataSchema)1 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)1 MyComplexKey (com.linkedin.restli.common.test.MyComplexKey)1 Message (com.linkedin.restli.examples.greetings.api.Message)1 TwoPartKey (com.linkedin.restli.examples.greetings.api.TwoPartKey)1 MutablePathKeys (com.linkedin.restli.internal.server.MutablePathKeys)1 PathKeysImpl (com.linkedin.restli.internal.server.PathKeysImpl)1 ServerResourceContext (com.linkedin.restli.internal.server.ServerResourceContext)1 Key (com.linkedin.restli.server.Key)1 ResourceConfigException (com.linkedin.restli.server.ResourceConfigException)1