Source:
public void delete(final String eventTypeName, final Client client) throws EventTypeDeletionException, ForbiddenAccessException, NoEventTypeException, UnableProcessException { Closeable deletionCloser = null; try { deletionCloser = timelineSync.workWithEventType(eventTypeName, nakadiSettings.getTimelineWaitTimeoutMs()); final Optional<EventType> eventTypeOpt = eventTypeRepository.findByNameO(eventTypeName); if (!eventTypeOpt.isPresent()) { throw new NoEventTypeException("EventType \"" + eventTypeName + "\" does not exist."); } final EventType eventType = eventTypeOpt.get(); if (!client.idMatches(eventType.getOwningApplication())) { throw new ForbiddenAccessException("You don't have access to event type " + eventTypeName); } final List<Subscription> subscriptions = subscriptionRepository.listSubscriptions( ImmutableSet.of(eventTypeName), Optional.empty(), 0, 1); if (!subscriptions.isEmpty()) { throw new UnableProcessException("Can't remove event type " + eventTypeName + ", as it has subscriptions"); } final Multimap<TopicRepository, String> topicsToDelete = transactionTemplate.execute(action -> { return deleteEventType(eventTypeName); }); for (final TopicRepository topicRepository : topicsToDelete.keySet()) { for (final String topic : topicsToDelete.get(topicRepository)) { try { topicRepository.deleteTopic(topic); } catch (TopicDeletionException e) { LOG.info("Could not delete topic " + topic); } } } } catch (final InterruptedException e) { Thread.currentThread().interrupt(); LOG.error("Failed to wait for timeline switch", e); throw new EventTypeUnavailableException("Event type " + eventTypeName + " is currently in maintenance, please repeat request"); } catch (final TimeoutException e) { LOG.error("Failed to wait for timeline switch", e); throw new EventTypeUnavailableException("Event type "+ eventTypeName + " is currently in maintenance, please repeat request"); } catch (final NakadiException e) { LOG.error("Error deleting event type " + eventTypeName, e); throw new EventTypeDeletionException("Failed to delete event type " + eventTypeName); } finally { try { if (deletionCloser != null) { deletionCloser.close(); } } catch (final IOException e) { LOG.error("Exception occurred when releasing usage of event-type", e); } } }

Target:
public void delete(final String eventTypeName, final Client client) throws EventTypeDeletionException, ForbiddenAccessException, NoEventTypeException, UnableProcessException { Closeable deletionCloser = null; Multimap<TopicRepository, String> topicsToDelete = null; try { deletionCloser = timelineSync.workWithEventType(eventTypeName, nakadiSettings.getTimelineWaitTimeoutMs()); final Optional<EventType> eventTypeOpt = eventTypeRepository.findByNameO(eventTypeName); if (!eventTypeOpt.isPresent()) { throw new NoEventTypeException("EventType \"" + eventTypeName + "\" does not exist."); } final EventType eventType = eventTypeOpt.get(); if (!client.idMatches(eventType.getOwningApplication())) { throw new ForbiddenAccessException("You don't have access to event type " + eventTypeName); } final List<Subscription> subscriptions = subscriptionRepository.listSubscriptions( ImmutableSet.of(eventTypeName), Optional.empty(), 0, 1); if (!subscriptions.isEmpty()) { throw new UnableProcessException("Can't remove event type " + eventTypeName + ", as it has subscriptions"); } topicsToDelete = transactionTemplate.execute(action -> { return deleteEventType(eventTypeName); }); } catch (final InterruptedException e) { Thread.currentThread().interrupt(); LOG.error("Failed to wait for timeline switch", e); throw new EventTypeUnavailableException("Event type " + eventTypeName + " is currently in maintenance, please repeat request"); } catch (final TimeoutException e) { LOG.error("Failed to wait for timeline switch", e); throw new EventTypeUnavailableException("Event type "+ eventTypeName + " is currently in maintenance, please repeat request"); } catch (final NakadiException e) { LOG.error("Error deleting event type " + eventTypeName, e); throw new EventTypeDeletionException("Failed to delete event type " + eventTypeName); } finally { try { if (deletionCloser != null) { deletionCloser.close(); } } catch (final IOException e) { LOG.error("Exception occurred when releasing usage of event-type", e); } } if (topicsToDelete != null) { for (final TopicRepository topicRepository : topicsToDelete.keySet()) { for (final String topic : topicsToDelete.get(topicRepository)) { try { topicRepository.deleteTopic(topic); } catch (TopicDeletionException e) { LOG.info("Could not delete topic " + topic, e); } } } } }