Package com.linkedin.data.template

Examples of com.linkedin.data.template.RecordTemplate


      {
        _infoMap.addRestSpecInfo(CompatibilityInfo.Type.ARRAY_MISSING_ELEMENT, _infoPath, prevKey);
      }
      else
      {
        final RecordTemplate currElement = currArray.get(currIndex);
        currRemainder.remove(prevKey);

        _infoPath.push(prevKey);
        checkRecordTemplate(prevElement, currElement);
        _infoPath.pop();
View Full Code Here


        Object[] args = invocation.getArguments();
        FilterRequestContext requestContext = (FilterRequestContext) args[0];
        requestContext.getFilterScratchpad().put(spKey, spValue);
        if (requestContext.getMethodType() == ResourceMethod.CREATE)
        {
          RecordTemplate entity = requestContext.getRequestData().getEntity();
          if (entity != null && entity instanceof Greeting)
          {
            Greeting greeting = (Greeting) entity;
            if (greeting.hasTone())
            {
              Tone tone = greeting.getTone();
              if (tone == Tone.INSULTING)
              {
                throw new RestLiServiceException(REQ_FILTER_ERROR_STATUS, REQ_FILTER_ERROR_MESSAGE);
              }
              greeting.setTone(mapToneForIncomingRequest(tone));
            }
          }
        }
        return null;
      }
    }).when(_requestFilter).onRequest(any(FilterRequestContext.class));
    List<RequestFilter> reqFilters = Arrays.asList(_requestFilter);

    List<ResponseFilter> respFilters = null;
    if (responseFilter)
    {
      reset(_responseFilter);
      doAnswer(new Answer<Object>()
      {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable
        {
          Object[] args = invocation.getArguments();
          FilterRequestContext requestContext = (FilterRequestContext) args[0];
          FilterResponseContext responseContext = (FilterResponseContext) args[1];
          // Verify the scratch pad value.
          assertTrue(requestContext.getFilterScratchpad().get(spKey) == spValue);
          RecordTemplate entity = responseContext.getResponseData().getEntityResponse();
          if (entity != null && requestContext.getMethodType() == ResourceMethod.GET
              && responseContext.getHttpStatus() == HttpStatus.S_200_OK)
          {
            Greeting greeting = new Greeting(entity.data());
            if (greeting.hasTone())
            {
              greeting.setTone(mapToneForOutgoingResponse(greeting.getTone()));
              responseContext.getResponseData().setEntityResponse(greeting);
            }
View Full Code Here

  @Override
  public AugmentedRestLiResponseData buildRestLiResponseData(RestRequest request, RoutingResult routingResult,
                                                             Object result, Map<String, String> headers)
  {
    final RecordTemplate record;
    final HttpStatus status;
    if (result instanceof GetResult)
    {
      final GetResult<?> getResult = (GetResult<?>) result;
      record = getResult.getValue();
      status = getResult.getStatus();
    }
    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

  @Test
  public void testEntity()
  {
    DataMap data = new DataMap();
    RecordTemplate record = new Foo(data);
    PartialRestResponse response = new PartialRestResponse.Builder().entity(record).build();
    assertEquals(response.getEntity(), record);
    assertTrue(response.hasData());
    assertEquals(response.getDataMap(), data);
  }
View Full Code Here

  }

  @Override
  public RestLiRequestData extractRequestData(RoutingResult routingResult, RestRequest request)
  {
    RecordTemplate record = ArgumentBuilder.extractEntity(request, PatchRequest.class);
    RestLiRequestDataImpl.Builder builder = new RestLiRequestDataImpl.Builder().entity(record);
    if (ArgumentUtils.hasResourceKey(routingResult))
    {
      builder.key(ArgumentUtils.getResourceKey(routingResult));
    }
View Full Code Here

  }

  @Override
  public RestLiRequestData extractRequestData(RoutingResult routingResult, RestRequest request)
  {
    RecordTemplate record = ArgumentBuilder.extractEntity(request, ArgumentUtils.getValueClass(routingResult));
    RestLiRequestDataImpl.Builder builder = new RestLiRequestDataImpl.Builder().entity(record);
    if (ArgumentUtils.hasResourceKey(routingResult))
    {
      Object keyValue = ArgumentUtils.getResourceKey(routingResult);
      builder.key(keyValue);
View Full Code Here

    //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)
    {
View Full Code Here

    for (Object key : mergedKeys)
    {
      final EntityResponse<RecordTemplate> entityResponse;

      final RecordTemplate entityTemplate = entities.get(key);
      if (entityTemplate == null)
      {
        entityResponse = new EntityResponse<RecordTemplate>(null);
      }
      else
      {
        @SuppressWarnings("unchecked")
        final Class<RecordTemplate> entityClass = (Class<RecordTemplate>) entityTemplate.getClass();
        entityResponse = new EntityResponse<RecordTemplate>(entityClass);

        final DataMap projectedData =
            RestUtils.projectFields(entityTemplate.data(), context.getProjectionMode(), context.getProjectionMask());
        CheckedUtil.putWithoutChecking(entityResponse.data(), EntityResponse.ENTITY, projectedData);
      }

      entityResponse.setStatus(statuses.get(key), SetMode.IGNORE_NULL);
      entityResponse.setError(errors.get(key), SetMode.IGNORE_NULL);
View Full Code Here

  }

  @Override
  public RestLiRequestData extractRequestData(RoutingResult routingResult, RestRequest request)
  {
    RecordTemplate inputEntity = ArgumentBuilder.extractEntity(request, ArgumentUtils.getValueClass(routingResult));
    return new RestLiRequestDataImpl.Builder().entity(inputEntity).build();
  }
View Full Code Here

  @Test
  public void testOnSuccessWithFiltersSuccessful() throws Exception
  {
    String result = "foo";
    RequestExecutionReport executionReport = new RequestExecutionReportBuilder().build();
    final RecordTemplate entityFromApp = Foo.createFoo("Key", "One");
    final Map<String, String> headersFromApp = Maps.newHashMap();
    headersFromApp.put("Key", "Input");
    final RecordTemplate entityFromFilter1 = Foo.createFoo("Key", "Two");
    final RecordTemplate entityFromFilter2 = Foo.createFoo("Key", "Three");
    final Map<String, String> headersFromFilters = Maps.newHashMap();
    headersFromFilters.put("Key", "Output");
    AugmentedRestLiResponseData appResponseData =
        new AugmentedRestLiResponseData.Builder(ResourceMethod.GET).status(HttpStatus.S_200_OK).headers(headersFromApp)
                                                    .entity(entityFromApp).build();
View Full Code Here

TOP

Related Classes of com.linkedin.data.template.RecordTemplate

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.