Examples of CompoundKey


Examples of com.linkedin.restli.common.CompoundKey

    RequestBuilder<? extends Request<BatchKVResponse<CompoundKey, UpdateStatus>>> batchUpdateRequest = builders.batchUpdate().input(key, new Greeting().setId(1).setMessage("foo")).getBuilder();
    BatchKVResponse<CompoundKey, UpdateStatus> response = REST_CLIENT.sendRequest(batchUpdateRequest).getResponse().getEntity();

    Assert.assertEquals(response.getResults().keySet().size(), 1);
    CompoundKey expected = new CompoundKey();
    expected.append("dateId", new Date(date));
    expected.append("longId", new CustomLong(lo));
    Assert.assertEquals(response.getResults().keySet().iterator().next(), expected);
  }
View Full Code Here

Examples of com.linkedin.restli.common.CompoundKey

    RequestBuilder<? extends Request<BatchKVResponse<CompoundKey, UpdateStatus>>> batchUpdateRequest = builders.batchUpdate().input(key, new Greeting().setId(1).setMessage("foo")).getBuilder();
    BatchKVResponse<CompoundKey, UpdateStatus> response = REST_CLIENT.sendRequest(batchUpdateRequest).getResponse().getEntity();

    Assert.assertEquals(1, response.getResults().keySet().size());
    CompoundKey expected = new CompoundKey();
    expected.append("birthday", new Date(date));
    expected.append("age", new CustomNonNegativeLong(lo));
    CompoundKey result = response.getResults().keySet().iterator().next();
    Assert.assertEquals(result, expected);
  }
View Full Code Here

Examples of com.linkedin.restli.common.CompoundKey

  @Test(dataProvider = "testData")
  public void testBuilder(ProtocolVersion protocolVersion, String location, String id)
      throws URISyntaxException
  {
    CompoundKey compoundKey = new CompoundKey().append("a", "a").append("b", 1);
    CreateResponse createResponse = new CreateResponse(compoundKey);
    IdResponse<CompoundKey> idResponse = new IdResponse<CompoundKey>(compoundKey);
    RestRequest restRequest = new RestRequestBuilder(new URI("/foo")).build();
    Map<String, String> headers = getHeaders(protocolVersion);
    // the headers passed in are modified
View Full Code Here

Examples of com.linkedin.restli.common.CompoundKey

      //know which syntax the client used, and we cannot rely on correct percent-encoding of
      //delimiter characters for both syntaxes.  Therefore we simulate parsing using each syntax in
      //turn, and choose the best match.
      StringBuilder legacyParseError = new StringBuilder();
      StringBuilder currentParseError = new StringBuilder();
      CompoundKey legacyParsedKey = parseCompoundKey(urlString,
                                                     keys,
                                                     legacyParseError,
                                                     LEGACY_SIMPLE_KEY_DELIMETER_PATTERN,
                                                     LEGACY_KEY_VALUE_DELIMETER_PATTERN);
      CompoundKey currentParsedKey = parseCompoundKey(urlString,
                                                      keys,
                                                      currentParseError,
                                                      SIMPLE_KEY_DELIMETER_PATTERN,
                                                      KEY_VALUE_DELIMETER_PATTERN);
      if (legacyParsedKey != null && currentParsedKey != null)
      {
        boolean legacy = legacyParsedKey.getNumParts() > currentParsedKey.getNumParts();
        _log.warn("Ambiguous compound key syntax, using heuristic decision for '{}', legacy: {}",
                  urlString, String.valueOf(legacy));
        return legacy ? legacyParsedKey : currentParsedKey;
      }
      else if (legacyParsedKey == null && currentParsedKey == null)
View Full Code Here

Examples of com.linkedin.restli.common.CompoundKey

    }
  }

  public static CompoundKey dataMapToCompoundKey(DataMap dataMap, Collection<Key> keys) throws IllegalArgumentException
  {
    CompoundKey compoundKey = new CompoundKey();
    for (Key key : keys)
    {
      String name = key.getName();

      // may be a partial compound key
      String value = dataMap.getString(name);
      if (value != null)
      {
        dataMap.remove(name);
        compoundKey.append(name, convertSimpleValue(value, key.getDataSchema(), key.getType()));
      }
    }
    if (!dataMap.isEmpty())
    {
      StringBuilder errorMessageBuilder = new StringBuilder();
View Full Code Here

Examples of com.linkedin.restli.common.CompoundKey

                                             final Pattern simpleKeyDelimiterPattern,
                                             final Pattern keyValueDelimiterPattern)
          throws RoutingException
  {
    String[] simpleKeys = simpleKeyDelimiterPattern.split(urlString.trim());
    CompoundKey compoundKey = new CompoundKey();
    for (String simpleKey : simpleKeys)
    {
      String[] nameValuePair = keyValueDelimiterPattern.split(simpleKey.trim());
      if (simpleKey.trim().length() == 0 || nameValuePair.length != 2)
      {
        errorMessageBuilder.append("Bad key format '");
        errorMessageBuilder.append(urlString);
        errorMessageBuilder.append("'");
        return null;
      }

      // Simple key names and values are URL-encoded prior to being included in the URL on
      // the client, to prevent collision with any of the delimiter characters (bulk,
      // compound key and simple key-value). So, must decode them
      String name;
      try
      {
        name = URLDecoder.decode(nameValuePair[0], RestConstants.DEFAULT_CHARSET_NAME);
      }
      catch (UnsupportedEncodingException e)
      {
        //should not happen, since we are using "UTF-8" as the encoding
        throw new RestLiInternalException(e);
      }
      // Key is not found in the set defined for the resource
      Key currentKey = getKeyWithName(keys, name);
      if (currentKey == null)
      {
        errorMessageBuilder.append("Unknown key part named '");
        errorMessageBuilder.append(name);
        errorMessageBuilder.append("'");
        return null;
      }

      String decodedStringValue;
      try
      {
        decodedStringValue =
                URLDecoder.decode(nameValuePair[1], RestConstants.DEFAULT_CHARSET_NAME);
      }
      catch (UnsupportedEncodingException e)
      {
        //should not happen, since we are using "UTF-8" as the encoding
        throw new RestLiInternalException(e);
      }

      compoundKey.append(name, convertSimpleValue(decodedStringValue, currentKey.getDataSchema(), currentKey.getType()));
    }
    return compoundKey;
  }
View Full Code Here

Examples of com.linkedin.restli.common.CompoundKey

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

Examples of com.linkedin.restli.common.CompoundKey

  @DataProvider(name = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "routingAssociationResourceBatch")
  public Object[][] routingAssociationResourceBatch()
  {

    CompoundKey key1 = new CompoundKey();
    key1.append("followeeID", 1L);
    key1.append("followerID", 1L);

    CompoundKey key2 = new CompoundKey();
    key2.append("followeeID", 3L);
    key2.append("followerID", 1L);

    CompoundKey key3 = new CompoundKey();
    key3.append("followeeID", 2L);
    key3.append("followerID", 1L);

    // for reference.
    CompoundKey key2Mismatch = new CompoundKey();
    key2Mismatch.append("followeeID", 3L);
    key2Mismatch.append("followerID", 1L);
    key2Mismatch.append("badKey", 5L);

    CompoundKey key2Partial = new CompoundKey();
    key2Partial.append("followeeID", 3L);

    return new Object[][]
      {
        { "/follows?ids=followerID:1;followeeID:1&ids=followerID:1;followeeID:3&ids=followerID:1;followeeID:2", // legacy
          AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(),
View Full Code Here

Examples of com.linkedin.restli.common.CompoundKey

  @DataProvider(name = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "nKeyAssociationRoutingBatch")
  public Object[][] nKeyAssociationRoutingBatch()
  {

    CompoundKey key1 = new CompoundKey();
    key1.append("foo", "1,1").append("bar", "1:2");
    CompoundKey key2 = new CompoundKey();
    key2.append("foo", "2,1").append("bar", "2;2");

    Set<CompoundKey> keys = new HashSet<CompoundKey>();
    keys.add(key1);
    keys.add(key2);
View Full Code Here

Examples of com.linkedin.restli.common.CompoundKey

  @Test
  public void testBuilderException()
      throws URISyntaxException
  {
    CompoundKey compoundKey = new CompoundKey().append("a", "a").append("b", 1);
    CreateResponse createResponse = new CreateResponse(compoundKey, null);
    RestRequest restRequest = new RestRequestBuilder(new URI("/foo")).build();
    ProtocolVersion protocolVersion = AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion();
    Map<String, String> headers = getHeaders(protocolVersion);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.