Search in sources :

Example 21 with DataProcessingException

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

the class TestPatchOnData method testDeleteAndBeBranchAtSameTime.

@Test
public void testDeleteAndBeBranchAtSameTime() throws JsonParseException, IOException, DataProcessingException {
    DataComplexProcessor processor = new DataComplexProcessor(new Patch(), dataMapFromString(//command $set should be used
    "{ \"b\": { \"$set\": { \"b\": 1} }, \"$delete\": [\"b\"] }"), 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 22 with DataProcessingException

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

the class TestPatchOnData method testDeleteAndSetSameField.

@Test
public void testDeleteAndSetSameField() throws JsonParseException, IOException, DataProcessingException {
    DataComplexProcessor processor = new DataComplexProcessor(new Patch(), dataMapFromString(//command $set should be used
    "{ \"$set\": { \"b\": 1}, \"$delete\": [\"b\"] }"), 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 23 with DataProcessingException

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

the class GroupMembershipsResource2 method batchUpdate.

@Override
public BatchUpdateResult<CompoundKey, GroupMembership> batchUpdate(BatchPatchRequest<CompoundKey, GroupMembership> patches) {
    Map<CompoundKey, UpdateResponse> results = new HashMap<CompoundKey, UpdateResponse>();
    for (Map.Entry<CompoundKey, PatchRequest<GroupMembership>> entry : patches.getData().entrySet()) {
        CompoundKey key = entry.getKey();
        PatchRequest<GroupMembership> patch = entry.getValue();
        GroupMembership groupMembership = _app.getMembershipMgr().get(key);
        if (groupMembership == null) {
            results.put(key, new UpdateResponse(HttpStatus.S_404_NOT_FOUND));
        } else {
            try {
                PatchApplier.applyPatch(groupMembership, patch);
                _app.getMembershipMgr().save(groupMembership);
                results.put(key, new UpdateResponse(HttpStatus.S_204_NO_CONTENT));
            } catch (DataProcessingException e) {
                results.put(key, new UpdateResponse(HttpStatus.S_400_BAD_REQUEST));
            }
        }
    }
    return new BatchUpdateResult<CompoundKey, GroupMembership>(results);
}
Also used : UpdateResponse(com.linkedin.restli.server.UpdateResponse) BatchUpdateResult(com.linkedin.restli.server.BatchUpdateResult) HashMap(java.util.HashMap) CompoundKey(com.linkedin.restli.common.CompoundKey) GroupMembership(com.linkedin.restli.examples.groups.api.GroupMembership) PatchRequest(com.linkedin.restli.common.PatchRequest) BatchPatchRequest(com.linkedin.restli.server.BatchPatchRequest) HashMap(java.util.HashMap) Map(java.util.Map) DataProcessingException(com.linkedin.data.transform.DataProcessingException)

Example 24 with DataProcessingException

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

the class GroupsResource2 method update.

@Override
public UpdateResponse update(Integer id, PatchRequest<Group> patch) {
    Group group = get(id);
    try {
        PatchApplier.applyPatch(group, patch);
    } catch (DataProcessingException e) {
        return new UpdateResponse(HttpStatus.S_400_BAD_REQUEST);
    }
    boolean wasUpdated = getGroupMgr().update(id, group);
    return new UpdateResponse(wasUpdated ? HttpStatus.S_204_NO_CONTENT : HttpStatus.S_404_NOT_FOUND);
}
Also used : Group(com.linkedin.restli.examples.groups.api.Group) UpdateResponse(com.linkedin.restli.server.UpdateResponse) DataProcessingException(com.linkedin.data.transform.DataProcessingException)

Example 25 with DataProcessingException

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

the class PhotoResource method update.

// allow partial update to an existing photo
@Override
public UpdateResponse update(Long key, PatchRequest<Photo> patchRequest) {
    final Photo p = _db.getData().get(key);
    if (p == null) {
        return new UpdateResponse(HttpStatus.S_404_NOT_FOUND);
    }
    try {
        PatchApplier.applyPatch(p, patchRequest);
    } catch (DataProcessingException e) {
        return new UpdateResponse(HttpStatus.S_400_BAD_REQUEST);
    }
    // photo's id and URN should not be changed
    p.setId(key);
    p.setUrn(String.valueOf(key));
    _db.getData().put(key, p);
    return new UpdateResponse(HttpStatus.S_202_ACCEPTED);
}
Also used : UpdateResponse(com.linkedin.restli.server.UpdateResponse) Photo(com.linkedin.restli.example.Photo) DataProcessingException(com.linkedin.data.transform.DataProcessingException)

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