use of com.linkedin.data.template.RecordTemplate in project rest.li by linkedin.
the class BatchCreateIdEntityResponse method generateDataMap.
private static DataMap generateDataMap(List<? extends RecordTemplate> elements) {
DataMap dataMap = new DataMap();
DataList listElements = new DataList();
for (RecordTemplate recordTemplate : elements) {
CreateIdEntityStatus<?, ?> status = (CreateIdEntityStatus) recordTemplate;
CheckedUtil.addWithoutChecking(listElements, status.data());
}
dataMap.put(CollectionResponse.ELEMENTS, listElements);
return dataMap;
}
use of com.linkedin.data.template.RecordTemplate in project rest.li by linkedin.
the class BatchCreateIdResponse method generateDataMap.
private static DataMap generateDataMap(List<? extends RecordTemplate> elements) {
DataMap dataMap = new DataMap();
DataList listElements = new DataList();
for (RecordTemplate recordTemplate : elements) {
CheckedUtil.addWithoutChecking(listElements, recordTemplate.data());
}
dataMap.put(CollectionResponse.ELEMENTS, listElements);
return dataMap;
}
use of com.linkedin.data.template.RecordTemplate in project rest.li by linkedin.
the class BatchCreateResponse method generateDataMap.
private static DataMap generateDataMap(List<? extends RecordTemplate> elements) {
DataMap dataMap = new DataMap();
DataList listElements = new DataList();
for (RecordTemplate recordTemplate : elements) {
listElements.add(recordTemplate.data());
}
dataMap.put(CollectionResponse.ELEMENTS, listElements);
return dataMap;
}
use of com.linkedin.data.template.RecordTemplate in project rest.li by linkedin.
the class ComplexResourceKey method buildFromDataMap.
/**
* Build complex key instance from an untyped datamap representing a complex key as
* defined in {@link QueryParamsDataMap}
*
* @param keyDataMap untyped DataMap - all primitive values are represented as strings.
* @param complexKeyType type of {@link ComplexResourceKey}
* @return {@link ComplexResourceKey} initialized with id and param values specified in
* the input DataMap
*/
public static ComplexResourceKey<RecordTemplate, RecordTemplate> buildFromDataMap(DataMap keyDataMap, ComplexKeySpec<?, ?> complexKeyType) {
// Copy in case the original is immutable
keyDataMap = new DataMap(keyDataMap);
// Separate key from its parameters (those are under "params" key in the total map)
DataMap paramsDataMap = (DataMap) keyDataMap.remove(COMPLEX_KEY_PARAMS);
if (paramsDataMap == null) {
paramsDataMap = new DataMap();
}
RecordTemplate key = validateDataMap(keyDataMap, complexKeyType.getKeyType());
RecordTemplate params = validateDataMap(paramsDataMap, complexKeyType.getParamsType());
return new ComplexResourceKey<RecordTemplate, RecordTemplate>(key, params);
}
use of com.linkedin.data.template.RecordTemplate in project rest.li by linkedin.
the class ResponseUtils method convertKey.
public static Object convertKey(String rawKey, TypeSpec<?> keyType, Map<String, CompoundKey.TypeInfo> keyParts, ComplexKeySpec<?, ?> complexKeyType, ProtocolVersion version) {
Class<?> keyBindingClass = keyType.getType();
Object result;
if (TyperefInfo.class.isAssignableFrom(keyType.getType())) {
TyperefDataSchema schema = (TyperefDataSchema) keyType.getSchema();
if (!schema.getDereferencedDataSchema().isPrimitive()) {
throw new IllegalArgumentException("Typeref must reference a primitive type when used as a key type.");
}
// Coerce the raw key string to the referenced primitive type.
DataSchema.Type dereferencedType = schema.getDereferencedType();
Class<?> primitiveClass = DataSchemaUtil.dataSchemaTypeToPrimitiveDataSchemaClass(dereferencedType);
result = ValueConverter.coerceString(rawKey, primitiveClass);
// Identify the binding class for the typeref.
keyBindingClass = CustomTypeUtil.getJavaCustomTypeClassFromSchema(schema);
if (keyBindingClass == null) {
keyBindingClass = primitiveClass;
}
} else if (CompoundKey.class.isAssignableFrom(keyType.getType())) {
DataMap keyDataMap;
if (version.compareTo(AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion()) >= 0) {
try {
keyDataMap = (DataMap) URIElementParser.parse(rawKey);
} catch (PathSegment.PathSegmentSyntaxException e) {
throw new IllegalStateException(rawKey + " is not a valid value for the resource key", e);
}
} else {
keyDataMap = parseKey(rawKey);
}
result = CompoundKey.fromValues(keyDataMap, keyParts);
} else if (ComplexResourceKey.class.isAssignableFrom(keyType.getType())) {
try {
ComplexResourceKey<RecordTemplate, RecordTemplate> complexResourceKey = ComplexResourceKey.parseString(rawKey, complexKeyType, version);
result = QueryParamsDataMap.fixUpComplexKeySingletonArray(complexResourceKey);
} catch (PathSegment.PathSegmentSyntaxException e) {
throw new IllegalStateException(rawKey + " is not a valid value for the resource key", e);
}
} else {
try {
result = ValueConverter.coerceString(rawKey, keyType.getType());
} catch (IllegalArgumentException e) {
throw new IllegalStateException(rawKey + " is not a valid value for resource key type " + keyType.getType().getName(), e);
}
}
return DataTemplateUtil.coerceOutput(result, keyBindingClass);
}
Aggregations