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;
}
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;
}
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;
}
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;
}
}
}
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) } } };
}
Aggregations