Skip to content

Commit 2138a30

Browse files
authored
Merge pull request #3 from uo287568/HU4-PedidosDelTransportista
Hu4 pedidos del transportista
2 parents a552369 + 08e5cdc commit 2138a30

15 files changed

+400
-49
lines changed

src/main/java/giis/demo/tkrun/EnvioDisplayDTO.java

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
package giis.demo.tkrun;
2-
/**
3-
* Cada una de las filas que muestran al usuario las carreras y su estado
4-
* IMPORTANTE: Cuando se usan los componentes de Apache Commons DbUtils debe
5-
* mantenerse de forma estricta el convenio de capitalización de Java:
6-
* - Capitalizar todas las palabras que forman un identificador
7-
* excepto la primera letra de nombres de métodos y variables.
8-
* - No utilizar subrayados
9-
* Seguir tambien estos mismos criterios en los nombres de tablas y campos de la BD
10-
*/
2+
113
public class EnvioDisplayDTO {
124
private String nref;
135
private String nombreEmisor;

src/main/java/giis/demo/tkrun/EnvioEntity.java

-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
package giis.demo.tkrun;
22

3-
/**
4-
* Datos del modelo de dominio de cada una de las carreras
5-
* IMPORTANTE: Cuando se usan los componentes de Apache Commons DbUtils debe
6-
* mantenerse de forma estricta el convenio de capitalización de Java:
7-
* - Capitalizar todas las palabras que forman un identificador
8-
* excepto la primera letra de nombres de métodos y variables.
9-
* - No utilizar subrayados
10-
* Seguir tambien estos mismos criterios en los nombres de tablas y campos de la BD
11-
*/
123
public class EnvioEntity {
134
private String nref;
145
private String nombreEmisor;

src/main/java/giis/demo/tkrun/EnviosController.java

-6
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@
55
import javax.swing.JOptionPane;
66
import giis.demo.util.SwingUtil;
77

8-
/**
9-
* Controlador para la funcionalidad de visualizacion de carreras para la inscripcion.
10-
* Es el punto de entrada de esta pantalla que se invocará:
11-
* -instanciando el controlador con la vista y el modelo
12-
* -ejecutando initController que instalara los manejadores de eventos
13-
*/
148
public class EnviosController {
159
private EnviosModel model;
1610
private EnviosView view;

src/main/java/giis/demo/tkrun/EnviosModel.java

+1-12
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
11
package giis.demo.tkrun;
22

33
import giis.demo.util.Database;
4-
/**
5-
* Acceso a los datos de carreras e inscripciones,
6-
* utilizado como modelo para el ejemplo de swing y para las pruebas unitarias y de interfaz de usuario.
7-
*
8-
* <br/>En los metodos de este ejemplo toda la logica de negocio se realiza mediante una unica query sql por lo que siempre
9-
* se utilizan los metodos de utilidad en la clase Database que usan apache commons-dbutils y controlan la conexion.
10-
* En caso de que en un mismo metodo se realicen diferentes queries se deberia controlar la conexion desde esta clase
11-
* (ver como ejemplo la implementacion en Database).
12-
*
13-
* <br/>Si utilizase algún otro framework para manejar la persistencia, la funcionalidad proporcionada por esta clase sería la asignada
14-
* a los Servicios, Repositorios y DAOs.
15-
*/
4+
165
public class EnviosModel {
176

187
private Database db=new Database();

src/main/java/giis/demo/tkrun/EnviosView.java

-9
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@
1414
import javax.swing.JTextArea;
1515
import java.awt.Color;
1616

17-
/**
18-
* Vista de la pantalla que muestra las carreras activas y permite interactuar con ellas.
19-
* <br/>Se ha generado con WindowBulder y modificado para ser conforme a MVC teniendo en cuenta:
20-
* - Se elimina main (es invocada desde CarrerasMain) y se incluye Title en el frame
21-
* - No se incluye ningun handler de eventos pues estos van en el controlador
22-
* - Las tablas se encierran en JOptionPane para que se puedan visualizar las cabeceras
23-
* - Se asinga nombre a las tablas si se van a automatizar la ejecucion de pruebas
24-
* - Incluye al final los metodos adicionales necesarios para acceder al UI desde el controlador
25-
*/
2617
public class EnviosView {
2718

2819
private JFrame frmRegistroenvos;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package giis.demo.tkrun;
2+
3+
public class PedidosTransportistaDisplayDTO {
4+
private int id;
5+
private int nref;
6+
private String nombreEmisor;
7+
private String correoEmisor;
8+
private String direccionEmisor;
9+
private String direccionReceptor;
10+
private String fechaEntrega;
11+
public PedidosTransportistaDisplayDTO() {}
12+
public PedidosTransportistaDisplayDTO(int id, int nref, String nombreEmisor, String correoEmisor,
13+
String direccionEmisor, String direccionReceptor, String fechaEntrega) {
14+
super();
15+
this.id = id;
16+
this.nref = nref;
17+
this.nombreEmisor = nombreEmisor;
18+
this.correoEmisor = correoEmisor;
19+
this.direccionEmisor = direccionEmisor;
20+
this.direccionReceptor = direccionReceptor;
21+
this.fechaEntrega = fechaEntrega;
22+
}
23+
public int getId() {
24+
return id;
25+
}
26+
public int getNref() {
27+
return nref;
28+
}
29+
public String getNombreEmisor() {
30+
return nombreEmisor;
31+
}
32+
public String getCorreoEmisor() {
33+
return correoEmisor;
34+
}
35+
public String getDireccionEmisor() {
36+
return direccionEmisor;
37+
}
38+
public String getDireccionReceptor() {
39+
return direccionReceptor;
40+
}
41+
public String getFechaEntrega() {
42+
return fechaEntrega;
43+
}
44+
public void setId(int id) {
45+
this.id = id;
46+
}
47+
public void setNref(int nref) {
48+
this.nref = nref;
49+
}
50+
public void setNombreEmisor(String nombreEmisor) {
51+
this.nombreEmisor = nombreEmisor;
52+
}
53+
public void setCorreoEmisor(String correoEmisor) {
54+
this.correoEmisor = correoEmisor;
55+
}
56+
public void setDireccionEmisor(String direccionEmisor) {
57+
this.direccionEmisor = direccionEmisor;
58+
}
59+
public void setDireccionReceptor(String direccionReceptor) {
60+
this.direccionReceptor = direccionReceptor;
61+
}
62+
public void setFechaEntrega(String fechaEntrega) {
63+
this.fechaEntrega = fechaEntrega;
64+
}
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package giis.demo.tkrun;
2+
3+
public class PedidosTransportistaEntity {
4+
private int id;
5+
private int nref;
6+
private String nombreEmisor;
7+
private String correoEmisor;
8+
private String direccionEmisor;
9+
private String direccionReceptor;
10+
private String fechaEntrega;
11+
12+
public int getId() {
13+
return id;
14+
}
15+
public int getNref() {
16+
return nref;
17+
}
18+
public String getNombreEmisor() {
19+
return nombreEmisor;
20+
}
21+
public String getCorreoEmisor() {
22+
return correoEmisor;
23+
}
24+
public String getDireccionEmisor() {
25+
return direccionEmisor;
26+
}
27+
public String getDireccionReceptor() {
28+
return direccionReceptor;
29+
}
30+
public String getFechaEntrega() {
31+
return fechaEntrega;
32+
}
33+
public void setId(int id) {
34+
this.id = id;
35+
}
36+
public void setNref(int nref) {
37+
this.nref = nref;
38+
}
39+
public void setNombreEmisor(String nombreEmisor) {
40+
this.nombreEmisor = nombreEmisor;
41+
}
42+
public void setCorreoEmisor(String correoEmisor) {
43+
this.correoEmisor = correoEmisor;
44+
}
45+
public void setDireccionEmisor(String direccionEmisor) {
46+
this.direccionEmisor = direccionEmisor;
47+
}
48+
public void setDireccionReceptor(String direccionReceptor) {
49+
this.direccionReceptor = direccionReceptor;
50+
}
51+
public void setFechaEntrega(String fechaEntrega) {
52+
this.fechaEntrega = fechaEntrega;
53+
}
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package giis.demo.tkrun;
2+
3+
import java.util.List;
4+
5+
import javax.swing.JOptionPane;
6+
import javax.swing.table.TableModel;
7+
8+
import giis.demo.util.SwingUtil;
9+
10+
public class TransportistaController {
11+
private TransportistaModel model;
12+
private TransportistaView view;
13+
14+
public TransportistaController(TransportistaModel transportistaModel, TransportistaView transportistaView) {
15+
this.model = transportistaModel;
16+
this.view = transportistaView;
17+
//no hay inicializacion especifica del modelo, solo de la vista
18+
this.initView();
19+
}
20+
21+
public void initController() {
22+
view.getBtSalir().addActionListener(e -> SwingUtil.exceptionWrapper(() -> view.reset()));
23+
view.getBtBuscar().addActionListener(e -> buscarTransportista());
24+
}
25+
26+
private void buscarTransportista() {
27+
String id = view.getTfID().getText();
28+
if(comprobarID(id)) {
29+
int numID = Integer.parseInt(id);
30+
TransportistaDisplayDTO transportista = model.getTransportista(numID);
31+
if(validarTransportista(transportista,numID)) {
32+
getListaPedidos(numID);
33+
}
34+
}
35+
36+
}
37+
38+
private void getListaPedidos(int numID) {
39+
List<PedidosTransportistaDisplayDTO> pedidos = model.getPedidosTransportista(numID);
40+
TableModel tmodel = SwingUtil.getTableModelFromPojos(pedidos, new String[] {"nref", "nombreEmisor", "correoEmisor","direccionEmisor","direccionReceptor","fechaEntrega"});
41+
view.getTbPedidos().setModel(tmodel);
42+
SwingUtil.autoAdjustColumns(view.getTbPedidos());
43+
}
44+
45+
private boolean validarTransportista(TransportistaDisplayDTO transportista, int numID) {
46+
if (transportista==null) {
47+
JOptionPane.showMessageDialog(null, "No existe un transportista \ncon el ID: " + numID);
48+
return false;
49+
} else return true;
50+
}
51+
52+
private boolean comprobarID(String id) {
53+
try {
54+
if(id.isBlank() || Integer.parseInt(id) <= 0) {
55+
JOptionPane.showMessageDialog(null, "Formato de ID inválido");
56+
return false;
57+
} else return true;
58+
} catch (NumberFormatException e) {
59+
JOptionPane.showMessageDialog(null, "Formato de ID inválido");
60+
return false;
61+
}
62+
}
63+
64+
public void initView() {
65+
view.getFrame().setVisible(true);
66+
}
67+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package giis.demo.tkrun;
2+
3+
public class TransportistaDisplayDTO {
4+
private int id;
5+
public TransportistaDisplayDTO() {}
6+
public TransportistaDisplayDTO(int id) {
7+
super();
8+
this.id = id;
9+
}
10+
public int getId() {
11+
return id;
12+
}
13+
public void setId(int id) {
14+
this.id = id;
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package giis.demo.tkrun;
2+
3+
public class TransportistaEntity {
4+
private int id;
5+
6+
public int getId() {
7+
return id;
8+
}
9+
public void setId(int id) {
10+
this.id = id;
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package giis.demo.tkrun;
2+
3+
import java.util.List;
4+
5+
import giis.demo.util.Database;
6+
/**
7+
* Acceso a los datos de carreras e inscripciones,
8+
* utilizado como modelo para el ejemplo de swing y para las pruebas unitarias y de interfaz de usuario.
9+
*
10+
* <br/>En los metodos de este ejemplo toda la logica de negocio se realiza mediante una unica query sql por lo que siempre
11+
* se utilizan los metodos de utilidad en la clase Database que usan apache commons-dbutils y controlan la conexion.
12+
* En caso de que en un mismo metodo se realicen diferentes queries se deberia controlar la conexion desde esta clase
13+
* (ver como ejemplo la implementacion en Database).
14+
*
15+
* <br/>Si utilizase algún otro framework para manejar la persistencia, la funcionalidad proporcionada por esta clase sería la asignada
16+
* a los Servicios, Repositorios y DAOs.
17+
*/
18+
public class TransportistaModel {
19+
20+
private Database db=new Database();
21+
22+
public TransportistaDisplayDTO getTransportista(int id) {
23+
String sql = "select * from transportistas where id=?";
24+
List<TransportistaDisplayDTO> transportistas = db.executeQueryPojo(TransportistaDisplayDTO.class, sql, id);
25+
if(transportistas.isEmpty()) {
26+
return null;
27+
}
28+
return transportistas.get(0);
29+
}
30+
31+
public List<PedidosTransportistaDisplayDTO> getPedidosTransportista(int numID) {
32+
String sql = "select * from pedidosTransportista where id=? order by fechaEntrega";
33+
List<PedidosTransportistaDisplayDTO> pedidos = db.executeQueryPojo(PedidosTransportistaDisplayDTO.class, sql, numID);
34+
return pedidos;
35+
}
36+
37+
38+
39+
}

0 commit comments

Comments
 (0)