Search in sources :

Example 91 with PathSpec

use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.

the class ProjectionUtil method createPathSpecMap.

private static DataMap createPathSpecMap(Set<PathSpec> paths) {
    final DataMap pathSpecMap = new DataMap();
    for (PathSpec p : paths) {
        final List<String> components = p.getPathComponents();
        DataMap currentMap = pathSpecMap;
        for (int i = 0; i < components.size(); ++i) {
            final String currentComponent = components.get(i);
            final Object currentValue = currentMap.get(currentComponent);
            if (i < components.size() - 1) {
                if (currentValue instanceof DataMap) {
                    @SuppressWarnings("unchecked") final DataMap valueMap = (DataMap) currentValue;
                    currentMap = valueMap;
                } else {
                    final DataMap newMap = new DataMap();
                    currentMap.put(currentComponent, newMap);
                    currentMap = newMap;
                }
            } else if (currentValue == null) {
                currentMap.put(currentComponent, Null.getInstance());
            }
        }
    }
    return pathSpecMap;
}
Also used : PathSpec(com.linkedin.data.schema.PathSpec) DataMap(com.linkedin.data.DataMap)

Example 92 with PathSpec

use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.

the class TestPathSpec method testNestedFieldPathSpec.

@Test
public void testNestedFieldPathSpec() {
    PathSpec p = RecordTest.fields().recordField().location();
    Assert.assertEquals(p.toString(), "/recordField/location");
}
Also used : PathSpec(com.linkedin.data.schema.PathSpec) Test(org.testng.annotations.Test)

Example 93 with PathSpec

use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.

the class TestPathSpec method testUnionPathSpec.

@Test
public void testUnionPathSpec() {
    PathSpec p = UnionTest.fields().unionWithInline().RecordInUnion().a();
    Assert.assertEquals(p.toString(), "/unionWithInline/com.linkedin.pegasus.generator.test.RecordInUnion/a");
    p = UnionTest.fields().unionWithoutNull().RecordBar().location();
    Assert.assertEquals(p.toString(), "/unionWithoutNull/com.linkedin.pegasus.generator.test.RecordBar/location");
    p = UnionTest.fields().unionWithNull().Null();
    Assert.assertEquals(p.toString(), "/unionWithNull/null");
    // Test path specs for Union member with aliases
    p = UnionTest.fields().unionWithAliases().MemRecord().location();
    Assert.assertEquals(p.toString(), "/unionWithAliases/memRecord/location");
    p = UnionTest.fields().unionWithAliases().MemArray();
    Assert.assertEquals(p.toString(), "/unionWithAliases/memArray");
    p = UnionTest.fields().unionWithAliases().MemMap();
    Assert.assertEquals(p.toString(), "/unionWithAliases/memMap");
    p = UnionTest.fields().unionWithAliases().Null();
    Assert.assertEquals(p.toString(), "/unionWithAliases/null");
}
Also used : PathSpec(com.linkedin.data.schema.PathSpec) Test(org.testng.annotations.Test)

Example 94 with PathSpec

use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.

the class TestPathSpec method testArrayRangePathSpec.

@Test
public void testArrayRangePathSpec() {
    PathSpec p = ArrayTest.fields().intArray(10, 5);
    Assert.assertEquals(p.toString(), "/intArray?start=10&count=5");
    p = ArrayTest.fields().recordInlineArray(null, 2);
    Assert.assertEquals(p.toString(), "/recordInlineArray?count=2");
    p = ArrayTest.fields().unionArray(8, null);
    Assert.assertEquals(p.toString(), "/unionArray?start=8");
    p = ArrayTest.fields().stringArray(null, null);
    Assert.assertEquals(p.toString(), "/stringArray");
}
Also used : PathSpec(com.linkedin.data.schema.PathSpec) Test(org.testng.annotations.Test)

Example 95 with PathSpec

use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.

the class TestPathSpec method testSelfReferencePathSpec.

@Test
public void testSelfReferencePathSpec() {
    PathSpec p = AliasTest.fields().a1().a1().a1().a1();
    Assert.assertEquals(p.toString(), "/a1/a1/a1/a1");
}
Also used : PathSpec(com.linkedin.data.schema.PathSpec) Test(org.testng.annotations.Test)

Aggregations

PathSpec (com.linkedin.data.schema.PathSpec)101 Test (org.testng.annotations.Test)74 MaskTree (com.linkedin.data.transform.filter.request.MaskTree)40 DataMap (com.linkedin.data.DataMap)31 HashSet (java.util.HashSet)16 RecordTemplate (com.linkedin.data.template.RecordTemplate)11 Map (java.util.Map)10 Set (java.util.Set)10 PatchTree (com.linkedin.data.transform.patch.request.PatchTree)9 HashMap (java.util.HashMap)8 DataList (com.linkedin.data.DataList)7 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)7 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)7 List (java.util.List)7 ByteString (com.linkedin.data.ByteString)6 DataSchema (com.linkedin.data.schema.DataSchema)5 MaskOperation (com.linkedin.data.transform.filter.request.MaskOperation)5 Foo (com.linkedin.pegasus.generator.examples.Foo)5 RequestContext (com.linkedin.r2.message.RequestContext)5 ServerResourceContext (com.linkedin.restli.internal.server.ServerResourceContext)5