Search in sources :

Example 36 with CompoundKey

use of com.linkedin.restli.common.CompoundKey in project rest.li by linkedin.

the class GroupMembershipsResource3 method toGroupMembership.

// This is a hack for the sample resource. So as not to write a separate persistence for this resource,
// convert from and to GroupMembership.
private static GroupMembership toGroupMembership(ComplexKeyGroupMembership complexKeyMembership) {
    GroupMembership groupMembership = new GroupMembership(complexKeyMembership.data());
    GroupMembershipKey complexKey = complexKeyMembership.getId();
    CompoundKey compoundKey = new CompoundKey().append(GROUP_ID, complexKey.getGroupID()).append(MEMBER_ID, complexKey.getMemberID());
    groupMembership.setId(URIParamUtils.encodeKeyForBody(compoundKey, true, AllProtocolVersions.BASELINE_PROTOCOL_VERSION));
    groupMembership.setMemberID(complexKey.getMemberID());
    groupMembership.setGroupID(complexKey.getGroupID());
    return groupMembership;
}
Also used : CompoundKey(com.linkedin.restli.common.CompoundKey) GroupMembershipKey(com.linkedin.restli.examples.groups.api.GroupMembershipKey) GroupMembership(com.linkedin.restli.examples.groups.api.GroupMembership) ComplexKeyGroupMembership(com.linkedin.restli.examples.groups.api.ComplexKeyGroupMembership)

Example 37 with CompoundKey

use of com.linkedin.restli.common.CompoundKey in project rest.li by linkedin.

the class GroupMembershipsResource3 method complexKeyToCompoundKey.

private static CompoundKey complexKeyToCompoundKey(ComplexResourceKey<GroupMembershipKey, GroupMembershipParam> id) {
    GroupMembershipKey key = id.getKey();
    CompoundKey compoundKey = new CompoundKey();
    compoundKey.append(GROUP_ID, key.getGroupID(GetMode.NULL));
    compoundKey.append(MEMBER_ID, key.getMemberID(GetMode.NULL));
    return compoundKey;
}
Also used : CompoundKey(com.linkedin.restli.common.CompoundKey) GroupMembershipKey(com.linkedin.restli.examples.groups.api.GroupMembershipKey)

Example 38 with CompoundKey

use of com.linkedin.restli.common.CompoundKey in project rest.li by linkedin.

the class TestGroupsClient method buildCompoundKey.

private static CompoundKey buildCompoundKey(int memberID, int groupID) {
    CompoundKey compoundKey = new CompoundKey();
    compoundKey.append("memberID", memberID);
    compoundKey.append("groupID", groupID);
    return compoundKey;
}
Also used : CompoundKey(com.linkedin.restli.common.CompoundKey)

Example 39 with CompoundKey

use of com.linkedin.restli.common.CompoundKey in project rest.li by linkedin.

the class ArgumentUtils method parseCompoundKey.

/**
   * The method parses out runtime-typesafe simple keys for the compound key based on the
   * provided key set for the resource.
   *
   *
   * @param urlString a string representation of the compound key.
   * @param keys a set of {@link com.linkedin.restli.server.Key} objects specifying
   *          names and types of the constituent simple keys
   * @return a runtime-typesafe CompoundKey
   * @throws IllegalArgumentException if there are unexpected key parts in the urlString that are not in keys,
   *         or any error in {@link ProtocolVersion} 1.0
   * @throws PathSegmentSyntaxException if the given string is not a valid encoded compound key
   */
public static CompoundKey parseCompoundKey(final String urlString, final Collection<Key> keys, final ProtocolVersion version) throws IllegalArgumentException, PathSegmentSyntaxException {
    if (urlString == null || urlString.trim().isEmpty()) {
        return null;
    }
    if (version.compareTo(AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion()) >= 0) {
        return parseCompoundKeyV2(urlString, keys);
    } else {
        //There are two compound key syntaxes potentially in use by clients, depending on the version
        //of rest.li being used.  The syntaxes use different delimiters: ";" and ":" for the legacy
        //syntax, and "&" and "=" for the newer syntax.  When parsing compound keys, we do not
        //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) {
            throw new IllegalArgumentException(currentParseError.toString());
        } else {
            return currentParsedKey == null ? legacyParsedKey : currentParsedKey;
        }
    }
}
Also used : CompoundKey(com.linkedin.restli.common.CompoundKey)

Example 40 with CompoundKey

use of com.linkedin.restli.common.CompoundKey in project rest.li by linkedin.

the class TestMockBatchCreateIdResponseFactory method provideKeys.

@DataProvider
public Object[][] provideKeys() {
    Greeting g1 = buildGreeting(1L);
    Greeting g2 = buildGreeting(2L);
    Greeting g3 = buildGreeting(3L);
    return new Object[][] { new Object[] { new Long[] { 1L, 2L, 3L } }, new Object[] { new MyCustomString[] { new MyCustomString("1"), new MyCustomString("2"), new MyCustomString("3") } }, new Object[] { new CompoundKey[] { buildCompoundKey("c1", 1), buildCompoundKey("c2", 2), buildCompoundKey("c3", 3) } }, new Object[] { new ComplexResourceKey<?, ?>[] { new ComplexResourceKey<Greeting, Greeting>(g1, g1), new ComplexResourceKey<Greeting, Greeting>(g2, g2), new ComplexResourceKey<Greeting, Greeting>(g3, g3) } } };
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) MyCustomString(com.linkedin.restli.common.MyCustomString) CompoundKey(com.linkedin.restli.common.CompoundKey) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) DataProvider(org.testng.annotations.DataProvider)

Aggregations

CompoundKey (com.linkedin.restli.common.CompoundKey)94 Test (org.testng.annotations.Test)48 HashMap (java.util.HashMap)26 DataProvider (org.testng.annotations.DataProvider)20 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)17 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)16 GroupMembership (com.linkedin.restli.examples.groups.api.GroupMembership)15 ResourceModel (com.linkedin.restli.internal.server.model.ResourceModel)14 AfterTest (org.testng.annotations.AfterTest)13 BeforeTest (org.testng.annotations.BeforeTest)13 DataMap (com.linkedin.data.DataMap)12 RestLiTestHelper.buildResourceModel (com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel)12 Key (com.linkedin.restli.server.Key)11 Followed (com.linkedin.restli.server.twitter.TwitterTestDataModels.Followed)10 HashSet (java.util.HashSet)10 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)9 TestRecord (com.linkedin.restli.client.test.TestRecord)9 BatchUpdateResult (com.linkedin.restli.server.BatchUpdateResult)9 AsyncFollowsAssociativeResource (com.linkedin.restli.server.twitter.AsyncFollowsAssociativeResource)9 EmptyRecord (com.linkedin.restli.common.EmptyRecord)8