AnsweredAssumed Answered

Handle BusinessException in activiti process

Question asked by rafaelduqueestrada on Dec 12, 2014
Latest reply on Jul 11, 2017 by saoussen
I'm searching for good solutions about to handle business exceptions inside of activiti process.

I noticed that, any exception throws inside the process execution is encapsulated as ActivitiException.

For example:

1- Process definition:


    <process id="processParametro">
        <startEvent id="iniciarProcessoParametro"/>
        <sequenceFlow sourceRef="iniciarProcessoParametro" targetRef="criarParametro"/>
        <serviceTask id="criarParametro"
                     name="Incluir Parametro"
                     activiti:expression="${parametroService.create(nomeParametro, descricaoParametro)}"
                     activiti:resultVariable="parametroCriado"/>
        <sequenceFlow sourceRef="criarParametro" targetRef="finalizarProcessoParametro"/>
        <endEvent id="finalizarProcessoParametro"/>
    </process>


2- The method create inside ParametroService class:


    @Transactional(readOnly = false)
    public Parametro create(String nome, String descricao) {
        Parametro parametro = parametroRepository.findByNome(nome);
        if (parametro != null){
            throw new BusinessException("domain.parametro.business.exception.nome.duplicado");
        }
        Parametro parametro = new Parametro(nome, descricao, SituacaoParametroEnum.PENDENTE_ATIVACAO.asDomain());
        return parametroRepository.save(parametro);
    }


If the method parametroRepository.findByNome(nome) return a parametro = null, the BusinessException will be thrown. But, the exception I'm receving in my client is ActivitiException.
I'm thinking to get a BusinessException inside the ActivitiException, but I think it isn't  a good design.

Someone has a better solution?

Outcomes