Examples of CompoundKey


Examples of com.linkedin.restli.common.CompoundKey

    Assert.assertEquals(response.getErrors(), errorResponses);
  }

  private CompoundKey buildCompoundKey(String part1, int part2)
  {
    return new CompoundKey().append("part1", part1).append("part2", part2);
  }
View Full Code Here

Examples of com.linkedin.restli.common.CompoundKey

  }

  @Test
  public void testCompoundKey()
  {
    CompoundKey c1 = buildCompoundKey("c1", 1);
    CompoundKey c2 = buildCompoundKey("c2", 2);
    CompoundKey c3 = buildCompoundKey("c3", 3);

    Map<CompoundKey, Greeting> recordTemplates = new HashMap<CompoundKey, Greeting>();
    recordTemplates.put(c1, buildGreeting(1L));
    recordTemplates.put(c2, buildGreeting(2L));
View Full Code Here

Examples of com.linkedin.restli.common.CompoundKey

  public Map<Integer, GroupMembership> batchGetByGroup(int groupID, Set<Integer> memberIDs)
  {
    Map<Integer, GroupMembership> result = new HashMap<Integer, GroupMembership>();
    for (Map.Entry<CompoundKey, GroupMembership> entry : _data.entrySet())
    {
      CompoundKey key = entry.getKey();
      if(key.getPartAsInt(GROUP_ID) == groupID &&
         memberIDs.contains(key.getPartAsInt(MEMBER_ID)))
      {
        result.put(key.getPartAsInt(MEMBER_ID), entry.getValue());
      }
    }
    return result;
  }
View Full Code Here

Examples of com.linkedin.restli.common.CompoundKey

  public Map<Integer, GroupMembership> batchGetByMember(int memberID, Set<Integer> groupIDs)
  {
    Map<Integer, GroupMembership> result = new HashMap<Integer, GroupMembership>();
    for (Map.Entry<CompoundKey, GroupMembership> entry : _data.entrySet())
    {
      CompoundKey key = entry.getKey();
      if(key.getPartAsInt(MEMBER_ID) == memberID &&
              groupIDs.contains(key.getPartAsInt(GROUP_ID)))
      {
        result.put(key.getPartAsInt(GROUP_ID), entry.getValue());
      }
    }
    return result;
  }
View Full Code Here

Examples of com.linkedin.restli.common.CompoundKey

    return result;
  }

  private static CompoundKey buildKey(int groupID, int memberID)
  {
    return new CompoundKey().append(GROUP_ID, groupID).append(MEMBER_ID, memberID);
  }
View Full Code Here

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

Examples of com.linkedin.restli.common.CompoundKey

          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

Examples of com.linkedin.restli.common.CompoundKey

  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

Examples of com.linkedin.restli.common.CompoundKey

          {
            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

Examples of com.linkedin.restli.common.CompoundKey

{
  @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
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.