Created
August 6, 2013 00:30
-
-
Save marciojrtorres/6160942 to your computer and use it in GitHub Desktop.
Um método longo demais para fazer um Pedido
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PedidoService { | |
public Pedido fazPedido(Carrinho carrinho) { | |
if (carrinho.getItens().size() == 0) { | |
throw new IllegalArgumentException("Carrinho Vazio"); | |
} | |
if (carrinho.getFormaPagamento() == null) { | |
throw new IllegalArgumentException( | |
"Forma Pagamento não selecionada"); | |
} | |
if (carrinho.getFormaPagamento() == CARTAO_CREDITO) { | |
Cliente cliente = carrinho.getCliente(); | |
SegurCredWS sc = new SegurCredWS(); | |
sc.checaCredito(cliente.getCPF().replace(".", | |
"").replace("-",".")); | |
if (!sc.getSituacao().equals(Situacao.OK)) { | |
throw new NoCreditException( | |
"Cliente não tem crédito liberado"); | |
} | |
} | |
EstoqueService estoqueService = new EstoqueService(); | |
for (Item item : carrinho.getItens()) { | |
if (estoqueService.getQuantidadeEstoque( | |
item.getProduto().getCodigo()) < item.getQuantidade()) { | |
throw new SemEstoqueParaItem(item); | |
} | |
} | |
// ... mais 30 linhas de transação | |
Pedido pedido = new Pedido(); | |
pedido.setItens(carrinho.getItens()); | |
pedido.setCliente(carrinho.getCliente()); | |
pedido.setFormaPagamento(carrinho.getFormaPagamento()); | |
PedidoDAO pedidoDAO = new PedidoDAO(); | |
pedidoDAO.salva(pedido); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment