Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package logica;
import excepciones.UsuarioNoExisteException;
import excepciones.UsuarioRepetidoException;
/**
* Controlador de usuarios.
* @author TProg2017
*
*/
public class ControladorUsuario implements IControladorUsuario {
public ControladorUsuario() {
}
public void registrarUsuario(String n, String ap, String ci) throws UsuarioRepetidoException {
ManejadorUsuario mu = ManejadorUsuario.getinstance();
Usuario u = mu.obtenerUsuario(ci);
if (u != null)
throw new UsuarioRepetidoException("El usuario " + ci + " ya esta registrado");
u = new Usuario(n, ap, ci);
mu.addUsuario(u);
}
public DataUsuario verInfoUsuario(String ci) throws UsuarioNoExisteException {
ManejadorUsuario mu = ManejadorUsuario.getinstance();
Usuario u = mu.obtenerUsuario(ci);
if (u != null)
return new DataUsuario(u.getNombre(), u.getApellido(), u.getCedulaIdentidad());
else
throw new UsuarioNoExisteException("El usuario " + ci + " no existe");
}
public DataUsuario[] getUsuarios() throws UsuarioNoExisteException {
ManejadorUsuario mu = ManejadorUsuario.getinstance();
Usuario[] usrs = mu.getUsuarios();
if (usrs != null) {
DataUsuario[] du = new DataUsuario[usrs.length];
Usuario usuario;
// Para separar lógica de presentación, no se deben devolver los Usuario,
// sino los DataUsuario
for (int i = 0; i < usrs.length; i++) {
usuario = usrs[i];
du[i] = new DataUsuario(usuario.getNombre(), usuario.getApellido(), usuario.getCedulaIdentidad());
}
return du;
} else
throw new UsuarioNoExisteException("No existen usuarios registrados");
}
}