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