@Override
    public List<GrokPattern> saveAll(Collection<GrokPattern> patterns,
                                     ImportStrategy importStrategy) throws ValidationException {

        if (importStrategy == ABORT_ON_CONFLICT) {
            for (GrokPattern pattern : loadAll()) {
                final boolean patternExists = patterns.stream().anyMatch(p -> p.name().equals(pattern.name()));
                if (patternExists) {
                    throw new ValidationException("Grok pattern " + pattern.name() + " already exists");
                }
            }
        }
        validateAllOrThrow(patterns, importStrategy);

        final List<GrokPattern> grokPatterns = patterns.stream()
                .map(this::uncheckedSave)
                .collect(Collectors.toList());

        final Set<String> patternNames = grokPatterns.stream()
                .map(GrokPattern::name)
                .collect(Collectors.toSet());

        if (!patternNames.isEmpty()) {
            clusterBus.post(GrokPatternsUpdatedEvent.create(patternNames));
        }

        return grokPatterns;
    }
@Test
    public void saveAll() throws Exception {
        Collection<GrokPattern> patterns = ImmutableList.of(GrokPattern.create("1", ".*"),
                GrokPattern.create("2", ".+"));
        final List<GrokPattern> saved = service.saveAll(patterns, ABORT_ON_CONFLICT);
        assertThat(saved).hasSize(2);

        // should fail because already exists
        assertThatThrownBy(() -> service.saveAll(patterns, ABORT_ON_CONFLICT))
                .isInstanceOf(ValidationException.class);

        // should add the patterns again
        service.saveAll(patterns, REPLACE_ON_CONFLICT);
        assertThat(service.loadAll()).hasSize(4);

        // replaced all patterns
        service.saveAll(patterns, DROP_ALL_EXISTING);
        assertThat(service.loadAll()).hasSize(2);
    }