Package com.linkedin.restli.server

Examples of com.linkedin.restli.server.ResourceContext


    }
    else
    {
      descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(model, 2, params);
    }
    ResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContext(keyName, keyValue, null);
    RoutingResult routingResult;
    if (key != null)
    {
      routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 4, context, 2);
    }
View Full Code Here


    }
    else
    {
      descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(model, 1, params);
    }
    ResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContext(keyName, keyValue, null);
    RoutingResult routingResult;
    if (key != null)
    {
      routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 3, context, 2);
    }
View Full Code Here

        null,
        Parameter.ParamType.POST,
        false,
        new AnnotationSet(new Annotation[]{}));
    ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(model, param);
    ResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContext(null, null, null);
    RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 2, context, 1);

    RestLiArgumentBuilder argumentBuilder = new CreateArgumentBuilder();
    RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, request);
    Object[] args = argumentBuilder.buildArguments(requestData, routingResult);
View Full Code Here

  {
    URI uri = URI.create(stringUri);
    Map<String, String> headers = new HashMap<String, String>(1);
    headers.put(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, version.toString());

    ResourceContext context = new ResourceContextImpl(new PathKeysImpl(),
                                                      new MockRequest(uri, headers),
                                                      new RequestContext());
    final MaskTree rootEntityMask = context.getProjectionMask();
    Assert.assertEquals(rootEntityMask.toString(), "{locale=1, state=1}");

    final MaskTree metadataMask = context.getMetadataProjectionMask();
    Assert.assertEquals(metadataMask.toString(), "{region=1, city=1}");

    final MaskTree pagingMask = context.getPagingProjectionMask();
    Assert.assertEquals(pagingMask.toString(), "{start=1, links=1}");
  }
View Full Code Here

  {
    URI uri = URI.create(stringUri);
    Map<String, String> headers = new HashMap<String, String>(1);
    headers.put(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, version.toString());

    ResourceContext context = new ResourceContextImpl(new PathKeysImpl(),
                                                      new MockRequest(uri, headers),
                                                      new RequestContext());
    final MaskTree rootEntityMask = context.getProjectionMask();
    Assert.assertEquals(rootEntityMask.toString(), "{location={longitude=1, latitude=1}, locale=1, state=1}");

    final MaskTree metadataMask = context.getMetadataProjectionMask();
    Assert.assertEquals(metadataMask.toString(), "{region=1, profile={weight=1, height=1}, city=1}");

    //Note the lack of a test with paging here. This is because paging (CollectionMetadata) has a LinkArray which
    //requires a wildcard path spec in the URI. That behavior is inconsistent with the other projections in this test,
    //therefore it will be included in the subsequent test.
View Full Code Here

  {
    URI uri = URI.create(stringUri);
    Map<String, String> headers = new HashMap<String, String>(1);
    headers.put(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, version.toString());

    ResourceContext context = new ResourceContextImpl(new PathKeysImpl(),
                                                      new MockRequest(uri, headers),
                                                      new RequestContext());
    final MaskTree rootEntityMask = context.getProjectionMask();
    Assert.assertEquals(rootEntityMask.toString(), "{d={$*={f=1, e=1}}, b={$*={c=1}}, a={$*=1}}");

    final MaskTree metadataMask = context.getMetadataProjectionMask();
    Assert.assertEquals(metadataMask.toString(), "{baz={$*={a=1}}, foo={$*={b=1, c=1, a=1}}, bar={$*=1}}");

    final MaskTree pagingMask = context.getPagingProjectionMask();
    Assert.assertEquals(pagingMask.toString(), "{total=1, count=1, links={$*={rel=1}}}");
  }
View Full Code Here

    else
    {
      record = (RecordTemplate) result;
      status = HttpStatus.S_200_OK;
    }
    final ResourceContext resourceContext = routingResult.getContext();
    final DataMap data = RestUtils.projectFields(record.data(), resourceContext.getProjectionMode(),
        resourceContext.getProjectionMask());
    return new AugmentedRestLiResponseData.Builder(routingResult.getResourceMethod().getMethodType()).headers(headers)
                                                                                                     .status(status)
                                                                                                     .entity(new AnyRecord(data))
                                                                                                     .build();
  }
View Full Code Here

                          ProtocolVersion protocolVersion,
                          Map<String, Foo> expectedTransformedResult,
                          Map<String, ErrorResponse> expectedErrors,
                          Map<Object, RestLiServiceException> expectedExceptionsWithUntypedKey)
  {
    ResourceContext mockContext = getMockResourceContext(protocolVersion, expectedExceptionsWithUntypedKey);
    ResourceMethodDescriptor mockDescriptor = getMockResourceMethodDescriptor();
    RoutingResult routingResult = new RoutingResult(mockContext, mockDescriptor);

    Map<String, String> headers = getHeaders();
View Full Code Here

  @Test(dataProvider = "exceptionTestData")
  public void testBuilderExceptions(Object results, String expectedErrorMessage)
  {
    // Protocol version doesn't matter here
    ResourceContext mockContext = getMockResourceContext(null, null);
    ResourceMethodDescriptor mockDescriptor = getMockResourceMethodDescriptor();
    RoutingResult routingResult = new RoutingResult(mockContext, mockDescriptor);

    Map<String, String> headers = getHeaders();
View Full Code Here

                                                                     final RecordTemplate customMetadata,
                                                                     final Integer totalResults,
                                                                     final Map<String, String> headers)
  {
    //Extract the resource context that contains projection information for root object entities, metadata and paging.
    final ResourceContext resourceContext = routingResult.getContext();

    //Calculate paging metadata and apply projection
    final CollectionMetadata paging =
        RestUtils.buildMetadata(request.getURI(), resourceContext, routingResult.getResourceMethod(),
                                elements, pageIncrement, totalResults);

    //PagingMetadata cannot be null at this point so we skip the null check. Notice here that we are using automatic
    //intentionally since resource methods cannot explicitly project paging. However, it should be noted that client
    //resource methods have the option of selectively setting the total to null. This happens if a client decides
    //that they want the total in the paging response, which the resource method will see in their paging path spec,
    //and then specify total when they create CollectionResult. Restli will then also subsequently separately project
    //paging using this same path spec.
    //Note that there is no chance of potential data loss here:
    //If the client decides they don't want total in their paging response, then the resource method will
    //see the lack of total in their paging path spec and then decide to set total to null. We will then also exclude it
    //when we project paging.
    //If the client decides they want total in their paging response, then the resource method will see total in their
    //paging path spec and then decide to set total to a non null value. We will then also include it when we project
    //paging.
    final RecordTemplate anyRecord = new AnyRecord(RestUtils.projectFields(paging.data(),
        ProjectionMode.AUTOMATIC, resourceContext.getPagingProjectionMask()));
    final CollectionMetadata projectedPaging = new CollectionMetadata(anyRecord.data());

    //For root object entities
    List<AnyRecord> processedElements = new ArrayList<AnyRecord>(elements.size());
    for (RecordTemplate entry : elements)
    {
      //We don't permit null elements in our lists. If so, this is a developer error.
      if (entry == null)
      {
        throw new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR,
            "Unexpected null encountered. Null element inside of a List returned by the resource method: " + routingResult
                .getResourceMethod());
      }
      processedElements.add(new AnyRecord(RestUtils
          .projectFields(entry.data(), resourceContext.getProjectionMode(), resourceContext.getProjectionMask())));
    }

    //Now for custom metadata
    final AnyRecord projectedCustomMetadata;
    if (customMetadata != null)
    {
      projectedCustomMetadata = new AnyRecord(RestUtils
          .projectFields(customMetadata.data(), resourceContext.getMetadataProjectionMode(),
              resourceContext.getMetadataProjectionMask()));
    }
    else
    {
      projectedCustomMetadata = null;
    }
View Full Code Here

TOP

Related Classes of com.linkedin.restli.server.ResourceContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.