Package com.linkedin.restli.common

Examples of com.linkedin.restli.common.ResourceSpec


  }

  @Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "simpleSubResourceAction1")
  public void testBuilderPathKeys19(ProtocolVersion version, String expectedUri)
  {
    ResourceSpec resourceSpec = getResourceSpecForBuilderPathKeys();
    String[] expectedResourcePath = new String[] {"foo", "bar"};

    Request<TestRecord> request = new ActionRequestBuilder<Void, TestRecord>(SUBRESOURCE_SIMPLE_SUB_URI, TestRecord.class, resourceSpec, RestliRequestOptions.DEFAULT_OPTIONS)
      .name("action").pathKey("key1", 1).build();
    testUriGeneration(request, expectedUri, version);
View Full Code Here


  }

  @Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "simpleSubResourceAction2")
  public void testBuilderPathKeys20(ProtocolVersion version, String expectedUri)
  {
    ResourceSpec resourceSpec = getResourceSpecForBuilderPathKeys();
    String[] expectedResourcePath = new String[] {"foo", "bar"};

    Request<TestRecord> request = new ActionRequestBuilder<Void, TestRecord>(
      SUBRESOURCE_SIMPLE_SUB_URI, TestRecord.class, resourceSpec, RestliRequestOptions.DEFAULT_OPTIONS).name("action")
      .pathKey("key1", "http://example.com/images/1.png")
View Full Code Here

  private void addPathKeys(AbstractRequestBuilder<?, ?, ?> builder)
  {
    for (Map.Entry<ResourceSchema, ResourceSpec> entry : _parentResources.entrySet())
    {
      ResourceSchema resourceSchema = entry.getKey();
      ResourceSpec resourceSpec = entry.getValue();
      if (resourceSpec.getKeyType() != null)
      {
        switch(toResourceKeyType(resourceSpec.getKeyType().getType()))
        {
          case PRIMITIVE:
          case COMPLEX:
            String keyName = resourceSchema.getCollection().getIdentifier().getName();
            builder.pathKey(keyName, generateKey(resourceSpec, resourceSchema, null));
            break;
          case COMPOUND:
            // old assocKey version
            Map<String, CompoundKey.TypeInfo> keyParts = resourceSpec.getKeyParts();
            for (Map.Entry<String, CompoundKey.TypeInfo> infoEntry : keyParts.entrySet())
            {
              String key = infoEntry.getKey();
              CompoundKey.TypeInfo typeInfo = infoEntry.getValue();
              builder.pathKey(key, _dataGenerator.buildData(key, typeInfo.getBinding().getSchema()));
            }
            // new key version
            String assocKeyName = resourceSchema.getAssociation().getIdentifier();
            builder.pathKey(assocKeyName, generateKey(resourceSpec, resourceSchema, null));
            break;
          case NONE:
            break;
          default:
            throw new IllegalStateException("Unrecognized key type: " + resourceSpec.getKeyType().getType());
        }
      }
    }
  }
View Full Code Here

  {
    CollectionRequest mockCollectionRequest = EasyMock.createMock(CollectionRequest.class);
    EasyMock.expect(mockCollectionRequest.getElements()).andReturn(Collections.emptyList()).once();
    EasyMock.expect(mockRequest.getInputRecord()).andReturn(mockCollectionRequest).times(2);
    EasyMock.replay(mockCollectionRequest);
    ResourceSpec resourceSpec = new ResourceSpecImpl(Collections.<ResourceMethod> emptySet(),
                                                     Collections.<String, DynamicRecordMetadata> emptyMap(),
                                                     Collections.<String, DynamicRecordMetadata> emptyMap(),
                                                     null,
                                                     null,
                                                     null,
View Full Code Here

    ResourceMethod method = ResourceMethod.GET;
    RecordTemplate input = new RecordTemplateWithPrimitiveKey().setBody("foo").setId(1L);
    Map<String, String> headers = new HashMap<String, String>();
    headers.put("foo", "bar");
    RestResponseDecoder decoder = new EntityResponseDecoder(GetRequest.class);
    ResourceSpec resourceSpec = buildResourceSpec();
    Map<String, Object> queryParams = new HashMap<String, Object>();
    queryParams.put("foo", "bar");
    String methodName = "baz";
    String baseUriTemplate = BASE_URI_TEMPLATE;
    Map<String, Object> pathKeys = new HashMap<String, Object>();
    pathKeys.put("foo", "bar");
    RestliRequestOptions requestOptions = RestliRequestOptions.DEFAULT_OPTIONS;

    Request request1 = new Request(method,
                                   input,
                                   headers,
                                   decoder,
                                   resourceSpec,
                                   queryParams,
                                   methodName,
                                   baseUriTemplate,
                                   pathKeys,
                                   requestOptions);

    Request request2 = new Request(ResourceMethod.ACTION,
                                   input,
                                   headers,
                                   decoder,
                                   resourceSpec,
                                   queryParams,
                                   methodName,
                                   baseUriTemplate,
                                   pathKeys,
                                   requestOptions);
    data.add(Arrays.asList(request1, request2, false));

    Request request3 = new Request(method,
                           new RecordTemplateWithPrimitiveKey().setBody("bar"),
                           headers,
                           decoder,
                           resourceSpec,
                           queryParams,
                           methodName,
                           baseUriTemplate,
                           pathKeys,
                           requestOptions);
    data.add(Arrays.asList(request1, request3, false));

    Request request4 = new Request(method,
                                   input,
                                   Collections.singletonMap("FOO", "BAR"),
                                   decoder,
                                   resourceSpec,
                                   queryParams,
                                   methodName,
                                   baseUriTemplate,
                                   pathKeys,
                                   requestOptions);
    data.add(Arrays.asList(request1, request4, false));

    ResourceSpec resourceSpec1 = new ResourceSpecImpl(EnumSet.of(ResourceMethod.GET,
                                                                 ResourceMethod.PARTIAL_UPDATE,
                                                                 ResourceMethod.UPDATE),
                                                      null,
                                                      null,
                                                      Long.class,
View Full Code Here

   * @param <T>
   */
  @SuppressWarnings({"unchecked", "rawtypes"})
  public static <T> DataMap transform(Request<T> request, ProtocolVersion version)
  {
    ResourceSpec resourceSpec = request.getResourceSpec();
    switch (request.getMethod())
    {
      case BATCH_UPDATE:
        return CollectionRequestUtil.
            convertToBatchRequest((CollectionRequest<KeyValueRecord>) request.getInputRecord(),
                                  resourceSpec.getKeyType(),
                                  resourceSpec.getComplexKeyType(),
                                  resourceSpec.getKeyParts(),
                                  resourceSpec.getValueType(),
                                  version).data();
      case BATCH_PARTIAL_UPDATE:
        return CollectionRequestUtil.
            convertToBatchRequest((CollectionRequest<KeyValueRecord>) request.getInputRecord(),
                                  resourceSpec.getKeyType(),
                                  resourceSpec.getComplexKeyType(),
                                  resourceSpec.getKeyParts(),
                                  new TypeSpec<PatchRequest>(PatchRequest.class),
                                  version).data();
      default:
        return request.getInputRecord().data();
    }
View Full Code Here

   */
  public static <K, V extends RecordTemplate> BatchGetEntityRequest<K, V> batch(List<BatchGetEntityRequest<K, V>> requests,
                                                                                boolean batchFields)
  {
    final BatchGetEntityRequest<K, V> firstRequest = requests.get(0);
    final ResourceSpec firstResourceSpec = firstRequest.getResourceSpec();
    final Map<String, Object> batchQueryParams = BatchGetRequestUtil.getBatchQueryParam(requests, batchFields);

    return new BatchGetEntityRequest<K, V>(firstRequest.getHeaders(),
                                           firstRequest.getResponseDecoder(),
                                           batchQueryParams,
View Full Code Here

    URI uri = new URI("greetings/1");
    ResourceMethod method = ResourceMethod.GET;
    RecordTemplate inputRecord = null;
    Map<String, String> headers = Collections.emptyMap();
    RestResponseDecoder<Greeting> decoder = new EntityResponseDecoder<Greeting>(Greeting.class);
    ResourceSpec resourceSpec = new ResourceSpecImpl(EnumSet.of(method),
                                                     null,
                                                     null,
                                                     Long.class,
                                                     Greeting.class,
                                                     Collections.<String, Object>emptyMap());
View Full Code Here

    if (expectedInput != null)
    {
      RecordTemplate inputRecordTemplate;
      if (request instanceof BatchUpdateRequest)
      {
        ResourceSpec resourceSpec = request.getResourceSpec();

        CollectionRequest inputRecord = (CollectionRequest)request.getInputRecord();

        inputRecordTemplate = CollectionRequestUtil.convertToBatchRequest(inputRecord,
                                                                          resourceSpec.getKeyType(),
                                                                          resourceSpec.getComplexKeyType(),
                                                                          resourceSpec.getKeyParts(),
                                                                          resourceSpec.getValueType());
      }
      else
      {
        inputRecordTemplate = request.getInputRecord();
      }
View Full Code Here

    if (expectedInput != null)
    {
      RecordTemplate inputRecordTemplate;
      if (request instanceof BatchUpdateRequest)
      {
        ResourceSpec resourceSpec = request.getResourceSpec();

        CollectionRequest inputRecord = (CollectionRequest)request.getInputRecord();

        inputRecordTemplate = CollectionRequestUtil.convertToBatchRequest(inputRecord,
                                                                          resourceSpec.getKeyType(),
                                                                          resourceSpec.getComplexKeyType(),
                                                                          resourceSpec.getKeyParts(),
                                                                          resourceSpec.getValueType());
      }
      else
      {
        inputRecordTemplate = request.getInputRecord();
      }
View Full Code Here

TOP

Related Classes of com.linkedin.restli.common.ResourceSpec

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.