Search in sources :

Example 1 with CursorConversionException

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());
}
Also used : CursorConversionException(org.zalando.nakadi.exceptions.runtime.CursorConversionException) NakadiCursor(org.zalando.nakadi.domain.NakadiCursor) ShiftedNakadiCursor(org.zalando.nakadi.domain.ShiftedNakadiCursor) InternalNakadiException(org.zalando.nakadi.exceptions.InternalNakadiException) MyNakadiRuntimeException1(org.zalando.nakadi.exceptions.runtime.MyNakadiRuntimeException1) EventType(org.zalando.nakadi.domain.EventType) InvalidCursorException(org.zalando.nakadi.exceptions.InvalidCursorException) NotFoundException(org.zalando.nakadi.exceptions.NotFoundException) ServiceUnavailableException(org.zalando.nakadi.exceptions.ServiceUnavailableException) NoSuchEventTypeException(org.zalando.nakadi.exceptions.NoSuchEventTypeException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 EventType (org.zalando.nakadi.domain.EventType)1 NakadiCursor (org.zalando.nakadi.domain.NakadiCursor)1 ShiftedNakadiCursor (org.zalando.nakadi.domain.ShiftedNakadiCursor)1 InternalNakadiException (org.zalando.nakadi.exceptions.InternalNakadiException)1 InvalidCursorException (org.zalando.nakadi.exceptions.InvalidCursorException)1 NoSuchEventTypeException (org.zalando.nakadi.exceptions.NoSuchEventTypeException)1 NotFoundException (org.zalando.nakadi.exceptions.NotFoundException)1 ServiceUnavailableException (org.zalando.nakadi.exceptions.ServiceUnavailableException)1 CursorConversionException (org.zalando.nakadi.exceptions.runtime.CursorConversionException)1 MyNakadiRuntimeException1 (org.zalando.nakadi.exceptions.runtime.MyNakadiRuntimeException1)1