Search in sources :

Example 1 with DataComplexProcessor

use of com.linkedin.data.transform.DataComplexProcessor in project rest.li by linkedin.

the class TestPatchOnData method testImplicitSetOperationInPatchIsNotSupported.

@Test
public void testImplicitSetOperationInPatchIsNotSupported() throws JsonParseException, IOException, DataProcessingException {
    DataComplexProcessor processor = new DataComplexProcessor(new Patch(), //command $set should be used
    dataMapFromString("{ \"a\": 1 }"), dataMapFromString("{}"));
    boolean thrown = false;
    try {
        processor.run(false);
    } catch (DataProcessingException e) {
        thrown = true;
    }
    if (!thrown)
        fail("expected DataProcessingException to be thrown");
}
Also used : DataComplexProcessor(com.linkedin.data.transform.DataComplexProcessor) DataProcessingException(com.linkedin.data.transform.DataProcessingException) Test(org.testng.annotations.Test)

Example 2 with DataComplexProcessor

use of com.linkedin.data.transform.DataComplexProcessor in project rest.li by linkedin.

the class TestPatchOnData method testMergingSimpleTypeValueWithComplexPatchNotSupported.

@Test
public void testMergingSimpleTypeValueWithComplexPatchNotSupported() throws JsonParseException, IOException, DataProcessingException {
    DataComplexProcessor processor = new DataComplexProcessor(new Patch(), //command $set should be used
    dataMapFromString("{ \"a\": { \"b\": 1} }"), dataMapFromString("{\"a\": 1}"));
    boolean thrown = false;
    try {
        processor.run(false);
    } catch (DataProcessingException e) {
        thrown = true;
    }
    if (!thrown)
        fail("expected DataProcessingException to be thrown");
}
Also used : DataComplexProcessor(com.linkedin.data.transform.DataComplexProcessor) DataProcessingException(com.linkedin.data.transform.DataProcessingException) Test(org.testng.annotations.Test)

Example 3 with DataComplexProcessor

use of com.linkedin.data.transform.DataComplexProcessor in project rest.li by linkedin.

the class TestPatchOnData method testSetAndBeBranchAtSameTime.

@Test
public void testSetAndBeBranchAtSameTime() throws JsonParseException, IOException, DataProcessingException {
    DataComplexProcessor processor = new DataComplexProcessor(new Patch(), dataMapFromString(//command $set should be used
    "{ \"b\": { \"$set\": { \"b\": 1} }, \"$set\": {\"b\": 1} }"), dataMapFromString("{\"a\": 1}"));
    boolean thrown = false;
    try {
        processor.run(false);
    } catch (DataProcessingException e) {
        thrown = true;
    }
    if (!thrown)
        fail("expected DataProcessingException to be thrown");
}
Also used : DataComplexProcessor(com.linkedin.data.transform.DataComplexProcessor) DataProcessingException(com.linkedin.data.transform.DataProcessingException) Test(org.testng.annotations.Test)

Example 4 with DataComplexProcessor

use of com.linkedin.data.transform.DataComplexProcessor in project rest.li by linkedin.

the class TestFilterOnData method genericFilterTest.

protected void genericFilterTest(DataMap data, DataMap filter, DataMap expected, String description) throws DataProcessingException {
    String dataBefore = data.toString();
    DataComplexProcessor processor = new DataComplexProcessor(new Filter(), filter, data);
    processor.run(false);
    assertEquals(data, expected, "The following test failed: \n" + description + "\nData: " + dataBefore + "\nFilter: " + filter + "\nExpected: " + expected + "\nActual result: " + data);
}
Also used : TestUtil.dataMapFromString(com.linkedin.data.TestUtil.dataMapFromString) DataComplexProcessor(com.linkedin.data.transform.DataComplexProcessor)

Example 5 with DataComplexProcessor

use of com.linkedin.data.transform.DataComplexProcessor in project rest.li by linkedin.

the class MaskTree method addOperation.

/**
 * Add an operation to this {@link MaskTree}, given a path indicating the field to which the operation
 * applies and a {@link MaskOperation} representing the operation to be applied.
 * @param path the path of the field to which the operation applies
 * @param op the MaskOperation to be performed on the field
 */
public void addOperation(PathSpec path, MaskOperation op) {
    List<String> segments = path.getPathComponents();
    Map<String, Object> attributes = path.getPathAttributes();
    final DataMap fieldMask = new DataMap();
    // map variable contains DataMap, into which current segment will be put
    DataMap map = fieldMask;
    for (int ii = 0; ii < segments.size() - 1; ++ii) {
        String segment = Escaper.escapePathSegment(segments.get(ii));
        DataMap childMap = new DataMap();
        map.put(segment, childMap);
        map = childMap;
    }
    String lastSegment = Escaper.escapePathSegment(segments.get(segments.size() - 1));
    Object start = attributes.get(PathSpec.ATTR_ARRAY_START);
    Object count = attributes.get(PathSpec.ATTR_ARRAY_COUNT);
    if (start != null || count != null) {
        DataMap childMap = new DataMap();
        map.put(lastSegment, childMap);
        if (start != null) {
            childMap.put(FilterConstants.START, start);
        }
        if (count != null) {
            childMap.put(FilterConstants.COUNT, count);
        }
    } else {
        map.put(lastSegment, op.getRepresentation());
    }
    // compose existing tree with mask for specific field
    try {
        new DataComplexProcessor(new MaskComposition(), fieldMask, _representation).run(false);
    } catch (DataProcessingException e) {
        throw new IllegalStateException("error while building mask tree", e);
    }
}
Also used : MaskComposition(com.linkedin.data.transform.filter.MaskComposition) DataComplexProcessor(com.linkedin.data.transform.DataComplexProcessor) DataMap(com.linkedin.data.DataMap) DataProcessingException(com.linkedin.data.transform.DataProcessingException)

Aggregations

DataComplexProcessor (com.linkedin.data.transform.DataComplexProcessor)27 Test (org.testng.annotations.Test)19 DataProcessingException (com.linkedin.data.transform.DataProcessingException)17 DataMap (com.linkedin.data.DataMap)15 Patch (com.linkedin.data.transform.patch.Patch)6 TestUtil.dataMapFromString (com.linkedin.data.TestUtil.dataMapFromString)5 PatchTree (com.linkedin.data.transform.patch.request.PatchTree)4 Group (com.linkedin.restli.examples.groups.api.Group)4 Message (com.linkedin.data.message.Message)2 DataList (com.linkedin.data.DataList)1 SimpleDataElement (com.linkedin.data.element.SimpleDataElement)1 ValidationOptions (com.linkedin.data.schema.validation.ValidationOptions)1 ValidationResult (com.linkedin.data.schema.validation.ValidationResult)1 RecordTemplate (com.linkedin.data.template.RecordTemplate)1 MaskComposition (com.linkedin.data.transform.filter.MaskComposition)1 PatchRequest (com.linkedin.restli.common.PatchRequest)1