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