use of org.zalando.nakadi.exceptions.runtime.CursorConversionException in project nakadi by zalando.
the class CursorOperationsController method getDistance.
@RequestMapping(path = "/event-types/{eventTypeName}/cursor-distances", method = RequestMethod.POST)
public ResponseEntity<?> getDistance(@PathVariable("eventTypeName") final String eventTypeName, @Valid @RequestBody final ValidListWrapper<CursorDistance> queries) throws InternalNakadiException, NoSuchEventTypeException {
final EventType eventType = eventTypeRepository.findByName(eventTypeName);
authorizationValidator.authorizeStreamRead(eventType);
queries.getList().forEach(query -> {
try {
final NakadiCursor initialCursor = cursorConverter.convert(eventTypeName, query.getInitialCursor());
final NakadiCursor finalCursor = cursorConverter.convert(eventTypeName, query.getFinalCursor());
final Long distance = cursorOperationsService.calculateDistance(initialCursor, finalCursor);
query.setDistance(distance);
} catch (InternalNakadiException | ServiceUnavailableException e) {
throw new MyNakadiRuntimeException1("problem calculating cursors distance", e);
} catch (final NoSuchEventTypeException e) {
throw new NotFoundException("event type not found", e);
} catch (final InvalidCursorException e) {
throw new CursorConversionException("problem converting cursors", e);
}
});
return status(OK).body(queries.getList());
}
Aggregations