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