use of org.zalando.nakadi.exceptions.runtime.DuplicatedSubscriptionException in project nakadi by zalando.
the class SubscriptionDbRepository method createSubscription.
public Subscription createSubscription(final SubscriptionBase subscriptionBase) throws InconsistentStateException, DuplicatedSubscriptionException, RepositoryProblemException {
try {
final String newId = uuidGenerator.randomUUID().toString();
final String keyFieldsHash = hashGenerator.generateSubscriptionKeyFieldsHash(subscriptionBase);
final DateTime createdAt = new DateTime(DateTimeZone.UTC);
final Subscription subscription = new Subscription(newId, createdAt, subscriptionBase);
jdbcTemplate.update("INSERT INTO zn_data.subscription (s_id, s_subscription_object, s_key_fields_hash) " + "VALUES (?, ?::JSONB, ?)", subscription.getId(), jsonMapper.writer().writeValueAsString(subscription), keyFieldsHash);
return subscription;
} catch (final JsonProcessingException e) {
throw new InconsistentStateException("Serialization problem during persistence of event type", e);
} catch (final DuplicateKeyException e) {
throw new DuplicatedSubscriptionException("Subscription with the same key properties already exists", e);
} catch (final DataAccessException e) {
throw new RepositoryProblemException("Error occurred when running database request", e);
}
}
Aggregations