Package com.linkedin.restli.common

Examples of com.linkedin.restli.common.CompoundKey


  public GroupMembership save(GroupMembership membership)
  {
    int groupID = membership.getGroupID();
    int memberID = membership.getMemberID();

    CompoundKey key = buildKey(groupID, memberID);
    membership.setId(URIParamUtils.encodeKeyForBody(key, true, AllProtocolVersions.BASELINE_PROTOCOL_VERSION));

    _data.put(key, membership);
    return membership;
  }
View Full Code Here


          parseComplexKey(currentResource, context, currentPathSegment);
          currentLevel = ResourceLevel.ENTITY;
        }
        else if (currentResource.getKeyClass() == CompoundKey.class)
        {
          CompoundKey compoundKey;
          try
          {
            compoundKey = parseCompoundKey(currentCollectionResource, context, currentPathSegment);
          }
          catch (IllegalArgumentException e)
          {
            throw new RoutingException(String.format("Malformed Compound Key: '%s'", currentPathSegment),
                                       HttpStatus.S_400_BAD_REQUEST.getCode(),
                                       e);
          }

          if (compoundKey != null
              && compoundKey.getPartKeys().containsAll(currentResource.getKeyNames()))
          {
            // full match on key parts means that we are targeting a unique entity
            currentLevel = ResourceLevel.ENTITY;
          }
        }
View Full Code Here

  private static CompoundKey parseCompoundKey(final ResourceModel resource,
                                              final ServerResourceContext context,
                                              final String pathSegment)
{
   CompoundKey compoundKey;
   try
   {
     compoundKey =
       ArgumentUtils.parseCompoundKey(pathSegment, resource.getKeys(),
                                      context.getRestliProtocolVersion());
   }
   catch (PathSegmentSyntaxException e)
   {
     throw new RoutingException(String.format("input %s is not a Compound key", pathSegment),
                                HttpStatus.S_400_BAD_REQUEST.getCode(),
                                e);
   }
   catch (IllegalArgumentException e)
   {
     throw new RoutingException(String.format("input %s is not a Compound key", pathSegment),
                                HttpStatus.S_400_BAD_REQUEST.getCode(),
                                e);
   }


    for (String simpleKeyName : compoundKey.getPartKeys())
    {
      context.getPathKeys().append(simpleKeyName, compoundKey.getPart(simpleKeyName));
    }
    context.getPathKeys().append(resource.getKeyName(), compoundKey);
    return compoundKey;
  }
View Full Code Here

          {
            log.warn("Invalid structure of key '" + compoundKey.toString() + "', skipping key.");
            context.getBatchKeyErrors().put(compoundKey.toString(), new RestLiServiceException(HttpStatus.S_400_BAD_REQUEST));
            continue;
          }
          CompoundKey finalKey;
          try
          {
            finalKey = ArgumentUtils.dataMapToCompoundKey((DataMap) compoundKey, resource.getKeys());
          }
          catch (IllegalArgumentException e)
View Full Code Here

{
  @DataProvider(name = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "testData")
  public Object[][] dataProvider()
  {
    Map<CompoundKey, Foo> results = new HashMap<CompoundKey, Foo>();
    CompoundKey c1 = new CompoundKey().append("a", "a1").append("b", 1);
    CompoundKey c2 = new CompoundKey().append("a", "a2").append("b", 2);
    CompoundKey c3 = new CompoundKey().append("a", "a3").append("b", 3);
    Foo record1 = new Foo().setStringField("record1");
    Foo record2 = new Foo().setStringField("record2");
    results.put(c1, record1);
    results.put(c2, record2);
View Full Code Here

    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

    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

  @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

      //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

    }
  }

  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

TOP

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

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.