Search in sources :

Example 1 with DataProcessingException

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

Example 2 with DataProcessingException

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");
}
Also used : DataComplexProcessor(com.linkedin.data.transform.DataComplexProcessor) DataMap(com.linkedin.data.DataMap) DataProcessingException(com.linkedin.data.transform.DataProcessingException) Test(org.testng.annotations.Test)

Example 3 with DataProcessingException

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");
}
Also used : DataComplexProcessor(com.linkedin.data.transform.DataComplexProcessor) DataProcessingException(com.linkedin.data.transform.DataProcessingException) Test(org.testng.annotations.Test)

Example 4 with DataProcessingException

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");
}
Also used : DataComplexProcessor(com.linkedin.data.transform.DataComplexProcessor) DataProcessingException(com.linkedin.data.transform.DataProcessingException) Test(org.testng.annotations.Test)

Example 5 with DataProcessingException

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");
}
Also used : DataComplexProcessor(com.linkedin.data.transform.DataComplexProcessor) DataProcessingException(com.linkedin.data.transform.DataProcessingException) Test(org.testng.annotations.Test)

Aggregations

DataProcessingException (com.linkedin.data.transform.DataProcessingException)26 DataComplexProcessor (com.linkedin.data.transform.DataComplexProcessor)16 Test (org.testng.annotations.Test)13 DataMap (com.linkedin.data.DataMap)10 UpdateResponse (com.linkedin.restli.server.UpdateResponse)10 PatchRequest (com.linkedin.restli.common.PatchRequest)3 Message (com.linkedin.data.message.Message)2 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)2 GroupMembership (com.linkedin.restli.examples.groups.api.GroupMembership)2 BatchPatchRequest (com.linkedin.restli.server.BatchPatchRequest)2 BatchUpdateResult (com.linkedin.restli.server.BatchUpdateResult)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 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 Patch (com.linkedin.data.transform.patch.Patch)1 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)1