Search in sources :

Example 16 with RecordTemplate

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;
}
Also used : DataList(com.linkedin.data.DataList) RecordTemplate(com.linkedin.data.template.RecordTemplate) DataMap(com.linkedin.data.DataMap)

Example 17 with RecordTemplate

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;
}
Also used : DataList(com.linkedin.data.DataList) RecordTemplate(com.linkedin.data.template.RecordTemplate) DataMap(com.linkedin.data.DataMap)

Example 18 with RecordTemplate

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;
}
Also used : DataList(com.linkedin.data.DataList) RecordTemplate(com.linkedin.data.template.RecordTemplate) DataMap(com.linkedin.data.DataMap)

Example 19 with RecordTemplate

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);
}
Also used : RecordTemplate(com.linkedin.data.template.RecordTemplate) DataMap(com.linkedin.data.DataMap) QueryParamsDataMap(com.linkedin.restli.internal.common.QueryParamsDataMap)

Example 20 with RecordTemplate

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);
}
Also used : CompoundKey(com.linkedin.restli.common.CompoundKey) DataMap(com.linkedin.data.DataMap) DataSchema(com.linkedin.data.schema.DataSchema) TyperefDataSchema(com.linkedin.data.schema.TyperefDataSchema) TyperefDataSchema(com.linkedin.data.schema.TyperefDataSchema) RecordTemplate(com.linkedin.data.template.RecordTemplate)

Aggregations

RecordTemplate (com.linkedin.data.template.RecordTemplate)59 DataMap (com.linkedin.data.DataMap)23 Test (org.testng.annotations.Test)23 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)10 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)9 DataList (com.linkedin.data.DataList)8 DynamicRecordTemplate (com.linkedin.data.template.DynamicRecordTemplate)8 ArrayList (java.util.ArrayList)8 PathSpec (com.linkedin.data.schema.PathSpec)7 TestRecord (com.linkedin.restli.client.test.TestRecord)7 AnyRecord (com.linkedin.restli.internal.server.methods.AnyRecord)7 FilterResponseContext (com.linkedin.restli.server.filter.FilterResponseContext)7 BeforeTest (org.testng.annotations.BeforeTest)7 ByteString (com.linkedin.data.ByteString)6 RestResponseBuilder (com.linkedin.r2.message.rest.RestResponseBuilder)6 EmptyRecord (com.linkedin.restli.common.EmptyRecord)6 RequestExecutionReport (com.linkedin.restli.server.RequestExecutionReport)6 RequestExecutionReportBuilder (com.linkedin.restli.server.RequestExecutionReportBuilder)6 RestLiResponseAttachments (com.linkedin.restli.server.RestLiResponseAttachments)6 RoutingException (com.linkedin.restli.server.RoutingException)6