Go to most recent revision | Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 106 | espaco | 1 | package br.com.ec.domain.service.categoria.impl; |
| 2 | |||
| 3 | import java.util.List; |
||
| 4 | |||
| 5 | import org.springframework.beans.factory.annotation.Autowired; |
||
| 6 | import org.springframework.stereotype.Service; |
||
| 7 | |||
| 8 | import br.com.ec.domain.model.Categoria; |
||
| 9 | import br.com.ec.domain.model.IndicadorDRE; |
||
| 10 | import br.com.ec.domain.service.categoria.CategoriaService; |
||
| 11 | import br.com.ec.infrastructure.repository.CategoriaRepository; |
||
| 12 | import br.edu.cesmac.core.exception.NegocioException; |
||
| 13 | import br.edu.cesmac.core.generic.AbstractService; |
||
| 14 | import br.edu.cesmac.core.generic.GenericRepository; |
||
| 15 | import br.edu.cesmac.core.validador.Validador; |
||
| 16 | |||
| 17 | @Service |
||
| 18 | public class CategoriaServiceImpl extends AbstractService<Categoria> implements CategoriaService { |
||
| 19 | |||
| 20 | private CategoriaRepository categoriaRepository; |
||
| 21 | |||
| 22 | @Autowired |
||
| 23 | public CategoriaServiceImpl(Validador validador, CategoriaRepository categoriaRepository) { |
||
| 24 | super(validador); |
||
| 25 | this.categoriaRepository = categoriaRepository; |
||
| 26 | } |
||
| 27 | |||
| 28 | @Override |
||
| 29 | protected GenericRepository<Categoria> getRepository() { |
||
| 30 | return categoriaRepository; |
||
| 31 | } |
||
| 32 | |||
| 33 | @Override |
||
| 34 | protected void regrasNegocioCadastrar(Categoria categoria) { |
||
| 35 | categoria.setAtivo(true); |
||
| 36 | } |
||
| 37 | |||
| 38 | @Override |
||
| 39 | protected void regrasNegocioExcluir(Categoria categoria) { |
||
| 40 | if (categoriaRepository.verificarSeCategoriaTemFilhas(categoria)) { |
||
| 41 | throw new NegocioException("Categoria possui filhas. Não pode ser excluída"); |
||
| 42 | } |
||
| 43 | if (categoriaRepository.verificarSeJaExisteContaVinculadaCategoria(categoria)) { |
||
| 44 | throw new NegocioException("Categoria vinculada a uma conta. Não pode ser excluída"); |
||
| 45 | } |
||
| 46 | super.regrasNegocioExcluir(categoria); |
||
| 47 | } |
||
| 48 | |||
| 49 | @Override |
||
| 50 | public List<Categoria> consultarCategoriasPaiAtivas(String tipoCategoria) { |
||
| 51 | return categoriaRepository.consultarCategoriasPaiAtivas(tipoCategoria); |
||
| 52 | } |
||
| 53 | |||
| 54 | @Override |
||
| 55 | public List<Categoria> consultarCategoriasFilhasAtivas(Categoria categoriaPai, String tipoCategoria) { |
||
| 56 | return categoriaRepository.consultarCategoriasFilhasAtivas(categoriaPai, tipoCategoria); |
||
| 57 | } |
||
| 58 | |||
| 59 | @Override |
||
| 60 | public List<Categoria> consultarCategoriasDRE(IndicadorDRE indicadorDRE) { |
||
| 61 | return categoriaRepository.consultarCategoriasDRE(indicadorDRE); |
||
| 62 | } |
||
| 63 | |||
| 64 | } |