Search in sources :

Example 51 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 52 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 53 with PathSpec

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

the class ProjectionUtil method validate.

private static Set<PathSpec> validate(DataMap filteredPathSpecs, Set<PathSpec> paths) {
    final Set<PathSpec> result = new HashSet<PathSpec>();
    for (PathSpec p : paths) {
        final List<String> components = p.getPathComponents();
        DataMap currentMap = filteredPathSpecs;
        boolean isPresent = true;
        for (int i = 0; i < components.size(); ++i) {
            final String currentComponent = components.get(i);
            final Object currentValue = currentMap.get(currentComponent);
            if (currentValue instanceof DataMap) {
                @SuppressWarnings("unchecked") final DataMap valueMap = (DataMap) currentValue;
                currentMap = valueMap;
            } else {
                isPresent = currentMap.containsKey(currentComponent);
                break;
            }
        }
        if (isPresent) {
            result.add(p);
        }
    }
    return result;
}
Also used : PathSpec(com.linkedin.data.schema.PathSpec) HashSet(java.util.HashSet) DataMap(com.linkedin.data.DataMap)

Example 54 with PathSpec

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

the class TestProjectionUtil method testPositiveSinglePath.

@Test
public void testPositiveSinglePath() {
    final MaskTree filter = new MaskTree();
    filter.addOperation(new PathSpec("foo", "bar", "baz"), MaskOperation.POSITIVE_MASK_OP);
    // ancestor nodes are considered present if matched in path
    Assert.assertTrue(ProjectionUtil.isPathPresent(filter, new PathSpec("foo")));
    Assert.assertTrue(ProjectionUtil.isPathPresent(filter, new PathSpec("foo", "bar")));
    Assert.assertTrue(ProjectionUtil.isPathPresent(filter, new PathSpec("foo", "bar", "baz")));
    // all matched child nodes are considered present
    Assert.assertTrue(ProjectionUtil.isPathPresent(filter, new PathSpec("foo", "bar", "baz", "xyz")));
    Assert.assertTrue(ProjectionUtil.isPathPresent(filter, new PathSpec("foo", "bar", "baz", "abc", "xyz")));
    Assert.assertFalse(ProjectionUtil.isPathPresent(filter, new PathSpec("xyz")));
    Assert.assertFalse(ProjectionUtil.isPathPresent(filter, new PathSpec("foo", "baz")));
    Assert.assertFalse(ProjectionUtil.isPathPresent(filter, new PathSpec("foo", "xyz")));
    Assert.assertFalse(ProjectionUtil.isPathPresent(filter, new PathSpec("foo", "bar", "xyz")));
}
Also used : MaskTree(com.linkedin.data.transform.filter.request.MaskTree) PathSpec(com.linkedin.data.schema.PathSpec) Test(org.testng.annotations.Test)

Example 55 with PathSpec

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

the class TestProjectionUtil method testEmptyPath.

@Test
public void testEmptyPath() {
    final MaskTree filter = new MaskTree();
    filter.addOperation(new PathSpec("foo"), MaskOperation.POSITIVE_MASK_OP);
    Assert.assertTrue(ProjectionUtil.isPathPresent(filter, new PathSpec()));
}
Also used : MaskTree(com.linkedin.data.transform.filter.request.MaskTree) PathSpec(com.linkedin.data.schema.PathSpec) Test(org.testng.annotations.Test)

Aggregations

PathSpec (com.linkedin.data.schema.PathSpec)79 Test (org.testng.annotations.Test)63 MaskTree (com.linkedin.data.transform.filter.request.MaskTree)31 DataMap (com.linkedin.data.DataMap)21 HashSet (java.util.HashSet)11 PatchTree (com.linkedin.data.transform.patch.request.PatchTree)9 DataList (com.linkedin.data.DataList)8 RecordTemplate (com.linkedin.data.template.RecordTemplate)7 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)7 ByteString (com.linkedin.data.ByteString)6 ArrayList (java.util.ArrayList)6 Foo (com.linkedin.pegasus.generator.examples.Foo)5 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)5 ResourceModel (com.linkedin.restli.internal.server.model.ResourceModel)5 RestLiResponseData (com.linkedin.restli.server.RestLiResponseData)5 RestLiTestHelper.buildResourceModel (com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel)5 AfterTest (org.testng.annotations.AfterTest)5 BeforeTest (org.testng.annotations.BeforeTest)5 TestRecord (com.linkedin.restli.client.test.TestRecord)4 List (java.util.List)4