Skip to content

Instantly share code, notes, and snippets.

@marciojrtorres
Created August 6, 2013 00:30
Show Gist options
  • Save marciojrtorres/6160942 to your computer and use it in GitHub Desktop.
Save marciojrtorres/6160942 to your computer and use it in GitHub Desktop.
Um método longo demais para fazer um Pedido
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