public Observable<AsyncQueryResult> call(final GenericQueryResponse response) {
final Observable<AsyncQueryRow> rows = response.rows().map(new Func1<ByteBuf, AsyncQueryRow>() {
@Override
public AsyncQueryRow call(ByteBuf byteBuf) {
try {
JsonObject value = JSON_OBJECT_TRANSCODER.byteBufToJsonObject(byteBuf);
return new DefaultAsyncQueryRow(value);
} catch (Exception e) {
throw new TranscodingException("Could not decode View Info.", e);
}
}
});
final Observable<JsonObject> info = response.info().map(new Func1<ByteBuf, JsonObject>() {
@Override
public JsonObject call(ByteBuf byteBuf) {
try {
return JSON_OBJECT_TRANSCODER.byteBufToJsonObject(byteBuf);
} catch (Exception e) {
throw new TranscodingException("Could not decode View Info.", e);
}
}
});
if (response.status().isSuccess()) {
return Observable.just((AsyncQueryResult) new DefaultAsyncQueryResult(rows, info, null,
response.status().isSuccess()));
} else {
return response.info().map(new Func1<ByteBuf, AsyncQueryResult>() {
@Override
public AsyncQueryResult call(ByteBuf byteBuf) {
try {
JsonObject error = JSON_OBJECT_TRANSCODER.byteBufToJsonObject(byteBuf);
return new DefaultAsyncQueryResult(rows, info, error, response.status().isSuccess());
} catch (Exception e) {
throw new TranscodingException("Could not decode View Info.", e);
}