use of org.zalando.nakadi.exceptions.DuplicatedEventTypeNameException in project nakadi by zalando.
the class CachingEventTypeRepository method removeEventType.
@Override
public void removeEventType(final String name) throws InternalNakadiException, NoSuchEventTypeException {
final EventType original = this.repository.findByName(name);
this.repository.removeEventType(name);
try {
this.cache.removed(name);
} catch (Exception e) {
LOG.error("Failed to remove entry from cache '" + name + "'");
try {
this.repository.saveEventType(original);
} catch (DuplicatedEventTypeNameException e1) {
LOG.error("Failed to rollback db removal", e);
}
throw new InternalNakadiException("Failed to remove event type", e);
}
}
use of org.zalando.nakadi.exceptions.DuplicatedEventTypeNameException in project nakadi by zalando.
the class EventTypeDbRepository method saveEventType.
@Override
@Transactional
public EventType saveEventType(final EventTypeBase eventTypeBase) throws InternalNakadiException, DuplicatedEventTypeNameException {
try {
final DateTime now = new DateTime(DateTimeZone.UTC);
final EventType eventType = new EventType(eventTypeBase, "1.0.0", now, now);
jdbcTemplate.update("INSERT INTO zn_data.event_type (et_name, et_event_type_object) VALUES (?, ?::jsonb)", eventTypeBase.getName(), jsonMapper.writer().writeValueAsString(eventType));
insertEventTypeSchema(eventType);
return eventType;
} catch (final JsonProcessingException e) {
throw new InternalNakadiException("Serialization problem during persistence of event type", e);
} catch (final DuplicateKeyException e) {
throw new DuplicatedEventTypeNameException("EventType " + eventTypeBase.getName() + " already exists.", e);
}
}
use of org.zalando.nakadi.exceptions.DuplicatedEventTypeNameException in project nakadi by zalando.
the class EventTypeControllerTest method whenPostDuplicatedEventTypeReturn409.
@Test
public void whenPostDuplicatedEventTypeReturn409() throws Exception {
final Problem expectedProblem = Problem.valueOf(Response.Status.CONFLICT, "some-name");
doThrow(new DuplicatedEventTypeNameException("some-name")).when(eventTypeRepository).saveEventType(any(EventTypeBase.class));
postEventType(buildDefaultEventType()).andExpect(status().isConflict()).andExpect(content().contentType("application/problem+json")).andExpect(content().string(matchesProblem(expectedProblem)));
}
Aggregations