Search in sources :

Example 1 with DuplicatedEventTypeNameException

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);
    }
}
Also used : InternalNakadiException(org.zalando.nakadi.exceptions.InternalNakadiException) DuplicatedEventTypeNameException(org.zalando.nakadi.exceptions.DuplicatedEventTypeNameException) EventType(org.zalando.nakadi.domain.EventType) DuplicatedEventTypeNameException(org.zalando.nakadi.exceptions.DuplicatedEventTypeNameException) NoSuchEventTypeException(org.zalando.nakadi.exceptions.NoSuchEventTypeException) InternalNakadiException(org.zalando.nakadi.exceptions.InternalNakadiException)

Example 2 with DuplicatedEventTypeNameException

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);
    }
}
Also used : InternalNakadiException(org.zalando.nakadi.exceptions.InternalNakadiException) DuplicatedEventTypeNameException(org.zalando.nakadi.exceptions.DuplicatedEventTypeNameException) EventType(org.zalando.nakadi.domain.EventType) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) DateTime(org.joda.time.DateTime) DuplicateKeyException(org.springframework.dao.DuplicateKeyException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with DuplicatedEventTypeNameException

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)));
}
Also used : DuplicatedEventTypeNameException(org.zalando.nakadi.exceptions.DuplicatedEventTypeNameException) EventTypeBase(org.zalando.nakadi.domain.EventTypeBase) Problem(org.zalando.problem.Problem) ThrowableProblem(org.zalando.problem.ThrowableProblem) TestUtils.invalidProblem(org.zalando.nakadi.utils.TestUtils.invalidProblem) Test(org.junit.Test)

Aggregations

DuplicatedEventTypeNameException (org.zalando.nakadi.exceptions.DuplicatedEventTypeNameException)3 EventType (org.zalando.nakadi.domain.EventType)2 InternalNakadiException (org.zalando.nakadi.exceptions.InternalNakadiException)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 DateTime (org.joda.time.DateTime)1 Test (org.junit.Test)1 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)1 Transactional (org.springframework.transaction.annotation.Transactional)1 EventTypeBase (org.zalando.nakadi.domain.EventTypeBase)1 NoSuchEventTypeException (org.zalando.nakadi.exceptions.NoSuchEventTypeException)1 TestUtils.invalidProblem (org.zalando.nakadi.utils.TestUtils.invalidProblem)1 Problem (org.zalando.problem.Problem)1 ThrowableProblem (org.zalando.problem.ThrowableProblem)1