use of com.linkedin.data.transform.DataProcessingException 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();
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));
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);
}
}
use of com.linkedin.data.transform.DataProcessingException 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");
}
use of com.linkedin.data.transform.DataProcessingException 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.DataProcessingException 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.DataProcessingException 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");
}
Aggregations