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");
}
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;
}
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;
}
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")));
}
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()));
}
Aggregations