Search in sources :

Example 41 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 42 with PathSpec

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

the class TestPathSpec method testMapWildcardPathSpec.

@Test
public void testMapWildcardPathSpec() {
    PathSpec p = MapTest.fields().recordInlineMap().values().f();
    Assert.assertEquals(p.toString(), "/recordInlineMap/*/f");
}
Also used : PathSpec(com.linkedin.data.schema.PathSpec) Test(org.testng.annotations.Test)

Example 43 with PathSpec

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

the class TestPathSpec method testMapWildcardPathSpec.

@Test
public void testMapWildcardPathSpec() {
    PathSpec p = MapTest.fields().recordInlineMap().values().f();
    Assert.assertEquals(p.toString(), "/recordInlineMap/*/f");
}
Also used : PathSpec(com.linkedin.data.schema.PathSpec) Test(org.testng.annotations.Test)

Example 44 with PathSpec

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

the class TestPathSpec method testArrayWildcardPathSpec.

@Test
public void testArrayWildcardPathSpec() {
    PathSpec p = ArrayTest.fields().recordInlineArray().items().f();
    Assert.assertEquals(p.toString(), "/recordInlineArray/*/f");
}
Also used : PathSpec(com.linkedin.data.schema.PathSpec) Test(org.testng.annotations.Test)

Example 45 with PathSpec

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

the class GeneratePatchMethodInterceptor method interpretSetModeAndSet.

private void interpretSetModeAndSet(String propertyName, Object arg, SetMode setMode) {
    PathSpec pathSpec = new PathSpec(_pathSpec.getPathComponents(), propertyName);
    boolean doSet = false;
    switch(setMode) {
        case DISALLOW_NULL:
            if (arg == null)
                throw new NullPointerException("Cannot set field " + pathSpec + " on " + _schema.getFullName() + " to null");
            doSet = true;
            break;
        case IGNORE_NULL:
            if (arg != null)
                doSet = true;
            break;
        case REMOVE_IF_NULL:
            doSet = true;
            break;
        case REMOVE_OPTIONAL_IF_NULL:
            if (_schema.getField(propertyName).getOptional())
                doSet = true;
            else if (arg == null)
                throw new IllegalArgumentException("Cannot remove mandatory field " + pathSpec + " on " + _schema.getFullName());
            break;
    }
    if (doSet) {
        PatchOperation patchOp = arg == null ? PatchOpFactory.REMOVE_FIELD_OP : PatchOpFactory.setFieldOp(coerceSetValue(arg));
        _patchTree.addOperation(pathSpec, patchOp);
    }
}
Also used : PatchOperation(com.linkedin.data.transform.patch.request.PatchOperation) PathSpec(com.linkedin.data.schema.PathSpec)

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