Search in sources :

Example 6 with DataComplexProcessor

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

the class AbstractFilter method compose.

/**
 * Returns composition of two masks. This method does not modify any of the parameters
 * and returned mask is new object. Composition is achieved by invoking separate data
 * processing. If there was an error during mask composition, then null is returned.
 *
 * @param mask1 first mask
 * @param mask2 second mask
 * @return composed masks or null if there was an error during composition fast-fail
 *         mode
 */
private DataMap compose(String fieldName, DataMap mask1, DataMap mask2) {
    // precondition:
    assert mask2 != null;
    assert mask1 != null;
    try {
        final DataMap clone = mask1.copy();
        new DataComplexProcessor(new MaskComposition(), mask2, clone).run(true);
        return clone;
    } catch (CloneNotSupportedException e) {
        onError(fieldName, "could not clone mask: %1$s, exception: %2$s", mask1, e);
    } catch (DataProcessingException e) {
        onError(fieldName, "error composing mask %1$s with %2$s, exception: %3$s", mask1, mask2, e);
    }
    return null;
}
Also used : DataComplexProcessor(com.linkedin.data.transform.DataComplexProcessor) DataMap(com.linkedin.data.DataMap) DataProcessingException(com.linkedin.data.transform.DataProcessingException)

Example 7 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, Set<String> alwaysIncludedFields, String description) throws DataProcessingException {
    String dataBefore = data.toString();
    DataComplexProcessor processor = new DataComplexProcessor(new Filter(alwaysIncludedFields), filter, data);
    processor.run(false);
    assertEquals(data, expected, "The following test failed: \n" + description + "\nData: " + dataBefore + "\nFilter: " + filter + "\nAlwaysIncludedFields: " + alwaysIncludedFields + "\nExpected: " + expected + "\nActual result: " + data);
}
Also used : TestUtil.dataMapFromString(com.linkedin.data.TestUtil.dataMapFromString) DataComplexProcessor(com.linkedin.data.transform.DataComplexProcessor)

Example 8 with DataComplexProcessor

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

the class TestMaskCompositionOnData method genericCompositionTest.

private void genericCompositionTest(DataMap data1, DataMap data2, DataMap expected, String description) throws DataProcessingException, CloneNotSupportedException {
    String dataBefore = data1.toString();
    String data2Clone = data2.toString();
    DataComplexProcessor processor = new DataComplexProcessor(new MaskComposition(), data2, data1);
    processor.run(false);
    assertEquals(data1, expected, "The following test failed: \n" + description + "\nData1: " + dataBefore + "\nData2: " + data2 + "\nExpected: " + expected + "\nActual result: " + data1);
    assertEquals(data2.toString(), data2Clone, "Operation data should not be modified");
}
Also used : TestUtil.dataMapFromString(com.linkedin.data.TestUtil.dataMapFromString) DataComplexProcessor(com.linkedin.data.transform.DataComplexProcessor)

Example 9 with DataComplexProcessor

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

the class TestPatchOnData method genericPatchTest.

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

Example 10 with DataComplexProcessor

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

the class TestFilter method testErrorMessagesForArraysFastFail.

@Test
public void testErrorMessagesForArraysFastFail() throws JsonParseException, IOException, DataProcessingException {
    DataMap data = dataMapFromString("{ 'a': [1, 2, 3, 4, 5]}".replace('\'', '"'));
    DataMap filter = dataMapFromString("{ 'a': { '$*': { 'y': 1}}}".replace('\'', '"'));
    DataComplexProcessor processor = new DataComplexProcessor(new Filter(), filter, data);
    boolean thrown = false;
    try {
        processor.run(true);
    } catch (DataProcessingException e) {
        assertEquals(e.getMessages().size(), 1, "expected exactly 1 error in non fast fail mode");
        thrown = true;
    }
    assertEquals(thrown, true, "exception should have been thrown");
}
Also used : DataComplexProcessor(com.linkedin.data.transform.DataComplexProcessor) DataMap(com.linkedin.data.DataMap) DataProcessingException(com.linkedin.data.transform.DataProcessingException) Test(org.testng.annotations.Test)

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