Search in sources :

Example 41 with RestClientResponseException

use of org.springframework.web.client.RestClientResponseException in project sic by belluccifranco.

the class PedidosGUI method btn_NuevoPedidoActionPerformed.

//GEN-LAST:event_chk_FechaItemStateChanged
private void btn_NuevoPedidoActionPerformed(java.awt.event.ActionEvent evt) {
    //GEN-FIRST:event_btn_NuevoPedidoActionPerformed
    try {
        if (this.existeClienteDisponible()) {
            PuntoDeVentaGUI gui_puntoDeVenta = new PuntoDeVentaGUI();
            Pedido pedido = new Pedido();
            pedido.setObservaciones("Los precios se encuentran sujetos a modificaciones.");
            gui_puntoDeVenta.setPedido(pedido);
            gui_puntoDeVenta.setModal(true);
            gui_puntoDeVenta.setLocationRelativeTo(this);
            gui_puntoDeVenta.setVisible(true);
            this.buscar();
        } else {
            String mensaje = ResourceBundle.getBundle("Mensajes").getString("mensaje_sin_cliente");
            JOptionPane.showInternalMessageDialog(this, mensaje, "Error", JOptionPane.ERROR_MESSAGE);
        }
    } catch (RestClientResponseException ex) {
        JOptionPane.showMessageDialog(this, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    } catch (ResourceAccessException ex) {
        LOGGER.error(ex.getMessage());
        JOptionPane.showMessageDialog(this, ResourceBundle.getBundle("Mensajes").getString("mensaje_error_conexion"), "Error", JOptionPane.ERROR_MESSAGE);
    }
}
Also used : RenglonPedido(sic.modelo.RenglonPedido) Pedido(sic.modelo.Pedido) EstadoPedido(sic.modelo.EstadoPedido) RestClientResponseException(org.springframework.web.client.RestClientResponseException) ResourceAccessException(org.springframework.web.client.ResourceAccessException)

Example 42 with RestClientResponseException

use of org.springframework.web.client.RestClientResponseException in project sic by belluccifranco.

the class PedidosGUI method buscar.

public void buscar() {
    this.cambiarEstadoEnabled(false);
    pb_Filtro.setIndeterminate(true);
    SwingWorker<List<Pedido>, Void> worker = new SwingWorker<List<Pedido>, Void>() {

        @Override
        protected List<Pedido> doInBackground() throws Exception {
            String URI = "/pedidos/busqueda/criteria?idEmpresa=" + EmpresaActiva.getInstance().getEmpresa().getId_Empresa();
            if (chk_Fecha.isSelected()) {
                URI += "&desde=" + dc_FechaDesde.getDate().getTime();
                URI += "&hasta=" + dc_FechaHasta.getDate().getTime();
            }
            if (chk_NumeroPedido.isSelected()) {
                URI += "&nroPedido=" + Long.valueOf(txt_NumeroPedido.getText());
            }
            if (chk_Cliente.isSelected()) {
                URI += "&idCliente=" + ((Cliente) cmb_Cliente.getSelectedItem()).getId_Cliente();
            }
            if (chk_Vendedor.isSelected()) {
                URI += "&idUsuario=" + ((Usuario) cmb_Vendedor.getSelectedItem()).getId_Usuario();
            }
            pedidos = new ArrayList(Arrays.asList(RestClient.getRestTemplate().getForObject(URI, Pedido[].class)));
            cambiarEstadoEnabled(true);
            cargarResultadosAlTable();
            return pedidos;
        }

        @Override
        protected void done() {
            pb_Filtro.setIndeterminate(false);
            try {
                if (get().isEmpty()) {
                    JOptionPane.showInternalMessageDialog(getParent(), ResourceBundle.getBundle("Mensajes").getString("mensaje_busqueda_sin_resultados"), "Aviso", JOptionPane.INFORMATION_MESSAGE);
                }
            } catch (InterruptedException ex) {
                String msjError = "La tarea que se estaba realizando fue interrumpida. Intente nuevamente.";
                LOGGER.error(msjError + " - " + ex.getMessage());
                JOptionPane.showInternalMessageDialog(getParent(), msjError, "Error", JOptionPane.ERROR_MESSAGE);
                cambiarEstadoEnabled(true);
            } catch (ExecutionException ex) {
                if (ex.getCause() instanceof RestClientResponseException) {
                    JOptionPane.showMessageDialog(getParent(), ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
                } else if (ex.getCause() instanceof ResourceAccessException) {
                    LOGGER.error(ex.getMessage());
                    JOptionPane.showMessageDialog(getParent(), ResourceBundle.getBundle("Mensajes").getString("mensaje_error_conexion"), "Error", JOptionPane.ERROR_MESSAGE);
                } else {
                    String msjError = "Se produjo un error en la ejecución de la tarea solicitada. Intente nuevamente.";
                    LOGGER.error(msjError + " - " + ex.getMessage());
                    JOptionPane.showInternalMessageDialog(getParent(), msjError, "Error", JOptionPane.ERROR_MESSAGE);
                }
                cambiarEstadoEnabled(true);
            }
        }
    };
    worker.execute();
}
Also used : Usuario(sic.modelo.Usuario) RenglonPedido(sic.modelo.RenglonPedido) Pedido(sic.modelo.Pedido) EstadoPedido(sic.modelo.EstadoPedido) ArrayList(java.util.ArrayList) ResourceAccessException(org.springframework.web.client.ResourceAccessException) SwingWorker(javax.swing.SwingWorker) ArrayList(java.util.ArrayList) List(java.util.List) RestClientResponseException(org.springframework.web.client.RestClientResponseException) ExecutionException(java.util.concurrent.ExecutionException) Cliente(sic.modelo.Cliente)

Example 43 with RestClientResponseException

use of org.springframework.web.client.RestClientResponseException in project sic by belluccifranco.

the class PedidosGUI method btn_eliminarPedidoActionPerformed.

//GEN-LAST:event_bnt_modificaPedidoActionPerformed
private void btn_eliminarPedidoActionPerformed(java.awt.event.ActionEvent evt) {
    //GEN-FIRST:event_btn_eliminarPedidoActionPerformed
    try {
        if (tbl_Pedidos.getSelectedRow() != -1) {
            long nroPedido = (long) tbl_Pedidos.getValueAt(tbl_Pedidos.getSelectedRow(), 2);
            Pedido pedido = Arrays.asList(RestClient.getRestTemplate().getForObject("/pedidos/busqueda/criteria?nroPedido=" + nroPedido + "&idEmpresa=" + EmpresaActiva.getInstance().getEmpresa().getId_Empresa(), Pedido[].class)).get(0);
            if (pedido.getEstado() == EstadoPedido.CERRADO) {
                JOptionPane.showInternalMessageDialog(this, ResourceBundle.getBundle("Mensajes").getString("mensaje_pedido_facturado"), "Error", JOptionPane.ERROR_MESSAGE);
            } else if (pedido.getEstado() == EstadoPedido.ACTIVO) {
                JOptionPane.showInternalMessageDialog(this, ResourceBundle.getBundle("Mensajes").getString("mensaje_pedido_procesado"), "Error", JOptionPane.ERROR_MESSAGE);
            } else if (this.existeClienteDisponible()) {
                int respuesta = JOptionPane.showConfirmDialog(this, "¿Esta seguro que desea eliminar el pedido seleccionado?", "Eliminar", JOptionPane.YES_NO_OPTION);
                if (respuesta == JOptionPane.YES_OPTION) {
                    RestClient.getRestTemplate().delete("/pedidos/" + pedido.getId_Pedido());
                    this.buscar();
                }
            } else {
                String mensaje = ResourceBundle.getBundle("Mensajes").getString("mensaje_sin_cliente");
                JOptionPane.showInternalMessageDialog(this, mensaje, "Error", JOptionPane.ERROR_MESSAGE);
            }
        }
    } catch (RestClientResponseException ex) {
        JOptionPane.showMessageDialog(this, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    } catch (ResourceAccessException ex) {
        LOGGER.error(ex.getMessage());
        JOptionPane.showMessageDialog(this, ResourceBundle.getBundle("Mensajes").getString("mensaje_error_conexion"), "Error", JOptionPane.ERROR_MESSAGE);
    }
}
Also used : RenglonPedido(sic.modelo.RenglonPedido) Pedido(sic.modelo.Pedido) EstadoPedido(sic.modelo.EstadoPedido) RestClientResponseException(org.springframework.web.client.RestClientResponseException) ResourceAccessException(org.springframework.web.client.ResourceAccessException)

Example 44 with RestClientResponseException

use of org.springframework.web.client.RestClientResponseException in project sic by belluccifranco.

the class PedidosGUI method lanzarReportePedido.

private void lanzarReportePedido(long idPedido) {
    if (Desktop.isDesktopSupported()) {
        try {
            byte[] reporte = RestClient.getRestTemplate().getForObject("/pedidos/" + idPedido + "/reporte", byte[].class);
            File f = new File(System.getProperty("user.home") + "/Pedido.pdf");
            Files.write(f.toPath(), reporte);
            Desktop.getDesktop().open(f);
        } catch (IOException ex) {
            LOGGER.error(ex.getMessage());
            JOptionPane.showMessageDialog(this, ResourceBundle.getBundle("Mensajes").getString("mensaje_error_IOException"), "Error", JOptionPane.ERROR_MESSAGE);
        } catch (RestClientResponseException ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        } catch (ResourceAccessException ex) {
            LOGGER.error(ex.getMessage());
            JOptionPane.showMessageDialog(this, ResourceBundle.getBundle("Mensajes").getString("mensaje_error_conexion"), "Error", JOptionPane.ERROR_MESSAGE);
        }
    } else {
        JOptionPane.showMessageDialog(this, ResourceBundle.getBundle("Mensajes").getString("mensaje_error_plataforma_no_soportada"), "Error", JOptionPane.ERROR_MESSAGE);
    }
}
Also used : IOException(java.io.IOException) RestClientResponseException(org.springframework.web.client.RestClientResponseException) File(java.io.File) ResourceAccessException(org.springframework.web.client.ResourceAccessException)

Example 45 with RestClientResponseException

use of org.springframework.web.client.RestClientResponseException in project sic by belluccifranco.

the class ProveedoresGUI method cargarComboBoxLocalidadesDeLaProvincia.

private void cargarComboBoxLocalidadesDeLaProvincia(Provincia provSeleccionada) {
    cmb_Localidad.removeAllItems();
    try {
        List<Localidad> Localidades = new ArrayList(Arrays.asList(RestClient.getRestTemplate().getForObject("/localidades/provincias/" + provSeleccionada.getId_Provincia(), Localidad[].class)));
        Localidad localidadTodas = new Localidad();
        localidadTodas.setNombre("Todas");
        cmb_Localidad.addItem(localidadTodas);
        Localidades.stream().forEach((l) -> {
            cmb_Localidad.addItem(l);
        });
    } catch (RestClientResponseException ex) {
        JOptionPane.showMessageDialog(this, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    } catch (ResourceAccessException ex) {
        LOGGER.error(ex.getMessage());
        JOptionPane.showMessageDialog(this, ResourceBundle.getBundle("Mensajes").getString("mensaje_error_conexion"), "Error", JOptionPane.ERROR_MESSAGE);
    }
}
Also used : ArrayList(java.util.ArrayList) RestClientResponseException(org.springframework.web.client.RestClientResponseException) Localidad(sic.modelo.Localidad) ResourceAccessException(org.springframework.web.client.ResourceAccessException)

Aggregations

RestClientResponseException (org.springframework.web.client.RestClientResponseException)69 ResourceAccessException (org.springframework.web.client.ResourceAccessException)68 ArrayList (java.util.ArrayList)23 Point (java.awt.Point)9 Pais (sic.modelo.Pais)9 Provincia (sic.modelo.Provincia)9 RenglonFactura (sic.modelo.RenglonFactura)9 EstadoPedido (sic.modelo.EstadoPedido)8 Localidad (sic.modelo.Localidad)8 Pedido (sic.modelo.Pedido)8 RenglonPedido (sic.modelo.RenglonPedido)8 IOException (java.io.IOException)6 FormaDePago (sic.modelo.FormaDePago)6 File (java.io.File)5 Producto (sic.modelo.Producto)5 Proveedor (sic.modelo.Proveedor)5 List (java.util.List)4 ExecutionException (java.util.concurrent.ExecutionException)4 SwingWorker (javax.swing.SwingWorker)4 Rubro (sic.modelo.Rubro)4