@ApiOperation(value = "Create a processing rule from rule builder", notes = "")
    @POST
    @RequiresPermissions(PipelineRestPermissions.PIPELINE_RULE_CREATE)
    @AuditEvent(type = PipelineProcessorAuditEventTypes.RULE_CREATE)
    public RuleBuilderDto createFromBuilder(@ApiParam(name = "rule", required = true) @NotNull RuleBuilderDto ruleBuilderDto) {
        try {
            validatorService.validateAndFailFast(ruleBuilderDto);
        } catch (IllegalArgumentException exception) {
            throw new BadRequestException(exception.getMessage());
        }

        RuleSource ruleSource = toRuleSource(ruleBuilderDto, false);
        final RuleSource stored = ruleResource.createFromParser(ruleSource);
        return ruleBuilderDto.toBuilder()
                .id(stored.id())
                .build();
    }
@Test
    public void ruleParsedAndStoredByRuleResource() {
        when(ruleBuilderService.generateRuleSource(any(), any(RuleBuilder.class), anyBoolean()))
                .thenReturn("rulesource");
        when(ruleResource.createFromParser(any())).thenReturn(RuleSource.builder().id("new_id").source("rulesource").build());
        RuleBuilder ruleBuilder = RuleBuilder.builder().build();
        when(ruleBuilderService.generateTitles(any())).thenReturn(ruleBuilder);
        RuleBuilderDto toSave = RuleBuilderDto.builder()
                .title("title")
                .ruleBuilder(ruleBuilder)
                .build();
        final RuleBuilderDto saved = ruleBuilderResource.createFromBuilder(toSave);
        assertThat(saved.id()).isEqualTo("new_id");
        verify(ruleResource).createFromParser(any());
    }