Search in sources :

Example 61 with DataMap

use of com.linkedin.data.DataMap in project rest.li by linkedin.

the class ResourceModelEncoder method buildResourceSchema.

/**
   * @param resourceModel {@link ResourceModel} to build the schema for
   * @return {@link ResourceSchema} for the provided resource model
   */
public ResourceSchema buildResourceSchema(final ResourceModel resourceModel) {
    ResourceSchema rootNode = new ResourceSchema();
    switch(resourceModel.getResourceType()) {
        case ACTIONS:
            appendActionsModel(rootNode, resourceModel);
            break;
        case SIMPLE:
            appendSimple(rootNode, resourceModel);
            break;
        default:
            appendCollection(rootNode, resourceModel);
            break;
    }
    final DataMap customAnnotation = resourceModel.getCustomAnnotationData();
    if (!customAnnotation.isEmpty()) {
        rootNode.setAnnotations(new CustomAnnotationContentSchemaMap(customAnnotation));
    }
    return rootNode;
}
Also used : ResourceSchema(com.linkedin.restli.restspec.ResourceSchema) CustomAnnotationContentSchemaMap(com.linkedin.restli.restspec.CustomAnnotationContentSchemaMap) DataMap(com.linkedin.data.DataMap)

Example 62 with DataMap

use of com.linkedin.data.DataMap in project rest.li by linkedin.

the class BatchCreateArgumentBuilder method extractRequestData.

@Override
public RestLiRequestData extractRequestData(RoutingResult routingResult, RestRequest request) {
    Class<? extends RecordTemplate> valueClass = ArgumentUtils.getValueClass(routingResult);
    DataMap dataMap = DataMapUtils.readMap(request);
    @SuppressWarnings({ "unchecked", "rawtypes" }) CollectionRequest<RecordTemplate> collectionRequest = new CollectionRequest(dataMap, valueClass);
    return new RestLiRequestDataImpl.Builder().batchEntities(collectionRequest.getElements()).build();
}
Also used : CollectionRequest(com.linkedin.restli.common.CollectionRequest) RecordTemplate(com.linkedin.data.template.RecordTemplate) DataMap(com.linkedin.data.DataMap)

Example 63 with DataMap

use of com.linkedin.data.DataMap in project rest.li by linkedin.

the class BatchPatchArgumentBuilder method extractRequestData.

@SuppressWarnings("unchecked")
@Override
public RestLiRequestData extractRequestData(RoutingResult routingResult, RestRequest request) {
    DataMap dataMap = DataMapUtils.readMap(request);
    Set<?> ids = routingResult.getContext().getPathKeys().getBatchIds();
    @SuppressWarnings({ "rawtypes" }) Map inputMap = ArgumentBuilder.buildBatchRequestMap(routingResult, dataMap, PatchRequest.class, ids, ProtocolVersionUtil.extractProtocolVersion(request.getHeaders()));
    final RestLiRequestDataImpl.Builder builder = new RestLiRequestDataImpl.Builder();
    if (inputMap != null) {
        builder.batchKeyEntityMap(inputMap);
    }
    return builder.build();
}
Also used : RestLiRequestDataImpl(com.linkedin.restli.server.RestLiRequestDataImpl) DataMap(com.linkedin.data.DataMap) Map(java.util.Map) DataMap(com.linkedin.data.DataMap)

Example 64 with DataMap

use of com.linkedin.data.DataMap in project rest.li by linkedin.

the class BatchUpdateArgumentBuilder method extractRequestData.

@SuppressWarnings("unchecked")
@Override
public RestLiRequestData extractRequestData(RoutingResult routingResult, RestRequest request) {
    Class<? extends RecordTemplate> valueClass = ArgumentUtils.getValueClass(routingResult);
    DataMap dataMap = DataMapUtils.readMap(request);
    Set<?> ids = routingResult.getContext().getPathKeys().getBatchIds();
    @SuppressWarnings({ "rawtypes" }) Map inputMap = ArgumentBuilder.buildBatchRequestMap(routingResult, dataMap, valueClass, ids, ProtocolVersionUtil.extractProtocolVersion(request.getHeaders()));
    final RestLiRequestDataImpl.Builder builder = new RestLiRequestDataImpl.Builder();
    if (inputMap != null) {
        builder.batchKeyEntityMap(inputMap);
    }
    return builder.build();
}
Also used : RestLiRequestDataImpl(com.linkedin.restli.server.RestLiRequestDataImpl) DataMap(com.linkedin.data.DataMap) Map(java.util.Map) DataMap(com.linkedin.data.DataMap)

Example 65 with DataMap

use of com.linkedin.data.DataMap in project rest.li by linkedin.

the class TestRestLiFilterResponseContextFactory method testFromResult.

@Test
public void testFromResult() throws Exception {
    DataMap dataMap = new DataMap();
    dataMap.put("foo", "bar");
    Map<String, String> headers = Maps.newHashMap();
    headers.put("x", "y");
    RecordTemplate entity1 = new Foo(dataMap);
    RestLiResponseDataImpl responseData = new RestLiResponseDataImpl(HttpStatus.S_200_OK, headers, Collections.<HttpCookie>emptyList());
    responseData.setResponseEnvelope(new GetResponseEnvelope(entity1, responseData));
    when(_responseHandler.buildRestLiResponseData(_restRequest, _routingResult, entity1)).thenReturn(responseData);
    FilterResponseContext responseContext = _filterResponseContextFactory.fromResult(entity1);
    assertEquals(responseContext.getResponseData(), responseData);
    verify(_responseHandler).buildRestLiResponseData(_restRequest, _routingResult, entity1);
}
Also used : FilterResponseContext(com.linkedin.restli.server.filter.FilterResponseContext) RecordTemplate(com.linkedin.data.template.RecordTemplate) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

DataMap (com.linkedin.data.DataMap)471 Test (org.testng.annotations.Test)238 DataList (com.linkedin.data.DataList)130 ByteString (com.linkedin.data.ByteString)110 HashMap (java.util.HashMap)56 TestUtil.dataMapFromString (com.linkedin.data.TestUtil.dataMapFromString)49 RecordDataSchema (com.linkedin.data.schema.RecordDataSchema)47 TestUtil.dataSchemaFromString (com.linkedin.data.TestUtil.dataSchemaFromString)46 DataSchema (com.linkedin.data.schema.DataSchema)45 Map (java.util.Map)45 ArrayList (java.util.ArrayList)31 MaskTree (com.linkedin.data.transform.filter.request.MaskTree)23 PathSpec (com.linkedin.data.schema.PathSpec)21 RecordTemplate (com.linkedin.data.template.RecordTemplate)21 DataProvider (org.testng.annotations.DataProvider)20 HashSet (java.util.HashSet)19 ArrayDataSchema (com.linkedin.data.schema.ArrayDataSchema)18 PatchTree (com.linkedin.data.transform.patch.request.PatchTree)18 CompoundKey (com.linkedin.restli.common.CompoundKey)18 IOException (java.io.IOException)18