Commit 6c907007 by Antonio Rueda

Revisión general de código y eliminación de código de estructuras de datos

parent 3696f1fa
......@@ -50,13 +50,7 @@
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package es.ujaen.dae.ujacoin.app;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.ApplicationContext;
/**
*
* @author admin
* Clase principal
* @author ajrueda
*/
@SpringBootApplication(scanBasePackages={"es.ujaen.dae.ujacoin.servicios", "es.ujaen.dae.ujacoin.repositorios"})
@SpringBootApplication(scanBasePackages={
"es.ujaen.dae.ujacoin.servicios",
"es.ujaen.dae.ujacoin.repositorios"
})
@EntityScan(basePackages="es.ujaen.dae.ujacoin.entidades")
public class UjaCoinApp {
public static void main(String[] args) throws Exception {
// Creación de servidor
SpringApplication servidor = new SpringApplication(UjaCoinApp.class);
ApplicationContext context = servidor.run(args);
SpringApplication.run(UjaCoinApp.class, args);
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package es.ujaen.dae.ujacoin.entidades.movimientos;
import es.ujaen.dae.ujacoin.entidades.Tarjeta;
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package es.ujaen.dae.ujacoin.entidades.movimientos;
import java.io.Serializable;
......@@ -13,8 +8,8 @@ import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.PastOrPresent;
import javax.validation.constraints.Positive;
/**
* Clase que representa un movimiento en cuenta
......@@ -28,6 +23,7 @@ public abstract class Movimiento implements Serializable {
int id;
/** Fecha del movimiento */
@NotNull
@PastOrPresent
LocalDateTime fechaHora;
/** Importe del movimiento. Los valores negativos representan retiradas de dinero */
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package es.ujaen.dae.ujacoin.entidades.movimientos;
import es.ujaen.dae.ujacoin.entidades.Tarjeta;
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package es.ujaen.dae.ujacoin.entidades.movimientos;
import es.ujaen.dae.ujacoin.entidades.Cuenta;
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package es.ujaen.dae.ujacoin.entidades.movimientos;
import es.ujaen.dae.ujacoin.entidades.Cuenta;
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package es.ujaen.dae.ujacoin.excepciones;
/**
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package es.ujaen.dae.ujacoin.excepciones;
/**
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package es.ujaen.dae.ujacoin.excepciones;
/**
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package es.ujaen.dae.ujacoin.excepciones;
/**
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package es.ujaen.dae.ujacoin.excepciones;
/**
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package es.ujaen.dae.ujacoin.excepciones;
/**
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package es.ujaen.dae.ujacoin.objetosvalor;
/**
* Simple random token for autorization
* NO SE USA EN EL PROYECTO POR EL MOMENTO
* @author ajrueda
*/
/*
public class Token {
public final long id;
public Token() { id = 0; }
private Token(long id) {
this.id = id;
}
public static Token generarAleatorio() {
return new Token(new Random().nextLong());
}
}
*/
\ No newline at end of file
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package es.ujaen.dae.ujacoin.servicios;
import es.ujaen.dae.ujacoin.excepciones.TarjetaYaRegistrada;
......@@ -22,7 +18,6 @@ import es.ujaen.dae.ujacoin.repositorios.RepositorioClientes;
import es.ujaen.dae.ujacoin.repositorios.RepositorioCuentas;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
......@@ -43,11 +38,6 @@ import org.springframework.validation.annotation.Validated;
@Service
@Validated
public class ServicioUjaCoin {
/** Mapa con la lista de clientes ordenada por DNI */
// Map<String, Cliente> clientes;
/** Mapa con la lista de cuentas ordenada por número */
// Map<String, Cuenta> cuentas;
@Autowired
RepositorioClientes repositorioClientes;
......@@ -55,8 +45,6 @@ public class ServicioUjaCoin {
RepositorioCuentas repositorioCuentas;
public ServicioUjaCoin() {
// clientes = new TreeMap<>();
// cuentas = new TreeMap<>();
}
/**
......@@ -65,14 +53,6 @@ public class ServicioUjaCoin {
* @return la cuenta asociada al cliente
*/
public Cuenta altaCliente(@NotNull @Valid Cliente cliente) {
/*
if (clientes.containsKey(cliente.getDni())) {
throw new ClienteYaRegistrado();
}
// Registrar cliente
clientes.put(cliente.getDni(), cliente);
*/
if (repositorioClientes.buscar(cliente.getDni()).isPresent()) {
throw new ClienteYaRegistrado();
}
......@@ -80,9 +60,7 @@ public class ServicioUjaCoin {
repositorioClientes.guardar(cliente);
// Crear y registrar cuenta
Cuenta cuenta = crearCuenta(cliente);
//cuentas.put(cuenta.getNum(), cuenta);
Cuenta cuenta = crearCuenta(cliente);
repositorioCuentas.guardar(cuenta);
return cuenta;
......@@ -96,7 +74,6 @@ public class ServicioUjaCoin {
*/
@Transactional
public Optional<Cliente> loginCliente(@NotBlank String dni, @NotBlank String clave) {
//return Optional.ofNullable(clientes.get(dni)).filter((cliente)->cliente.claveValida(clave));
Optional<Cliente> clienteLogin = repositorioClientes.buscar(dni)
.filter((cliente)->cliente.claveValida(clave));
......@@ -111,11 +88,9 @@ public class ServicioUjaCoin {
* @return la cuenta creada
*/
public Cuenta crearCuenta(@NotBlank String dni) {
// Cliente cliente = Optional.ofNullable(clientes.get(dni)).orElseThrow(ClienteNoRegistrado::new);
Cliente cliente = repositorioClientes.buscar(dni).orElseThrow(ClienteNoRegistrado::new);
Cuenta cuenta = crearCuenta(cliente);
// cuentas.put(cuenta.getNum(), cuenta);
repositorioCuentas.guardar(cuenta);
return cuenta;
......@@ -128,7 +103,6 @@ public class ServicioUjaCoin {
*/
// @Transactional
public void registrarTarjeta(@NotBlank String dni, @NotNull @Valid Tarjeta tarjeta) {
// Cliente cliente = Optional.ofNullable(clientes.get(dni)).orElseThrow(ClienteNoRegistrado::new);
Cliente cliente = repositorioClientes.buscar(dni).orElseThrow(ClienteNoRegistrado::new);
cliente.verTarjeta(tarjeta.getNum()).ifPresent(x -> { throw new TarjetaYaRegistrada(); } );
......@@ -145,7 +119,6 @@ public class ServicioUjaCoin {
*/
@Transactional
public List<Cuenta> verCuentas(@NotBlank String dni) {
//Cliente cliente = Optional.ofNullable(clientes.get(dni)).orElseThrow(ClienteNoRegistrado::new);
Cliente cliente = repositorioClientes.buscar(dni).orElseThrow(ClienteNoRegistrado::new);
// Precargar a memoria la relación lazy de cuentas del cliente antes de devolver
......@@ -159,9 +132,7 @@ public class ServicioUjaCoin {
* @param dni el DNI del cliente
* @return la lista de tarjetas
*/
public List<Tarjeta> verTarjetas(@NotBlank String dni) {
// Cliente cliente = Optional.ofNullable(clientes.get(dni)).orElseThrow(ClienteNoRegistrado::new);
public List<Tarjeta> verTarjetas(@NotBlank String dni) {
Cliente cliente = repositorioClientes.buscar(dni).orElseThrow(ClienteNoRegistrado::new);
return cliente.verTarjetas(); // Relación eager, no hay que hacer nada
}
......@@ -174,9 +145,6 @@ public class ServicioUjaCoin {
*/
@Transactional
public void ingreso(@NotBlank String numCuenta, @NotBlank String numTarjeta, @Positive float importe) {
// Cuenta cuenta = Optional.ofNullable(cuentas.get(numCuenta))
// .orElseThrow(CuentaNoRegistrada::new);
Cuenta cuenta = repositorioCuentas.buscarYBloquear(numCuenta)
.orElseThrow(CuentaNoRegistrada::new);
......@@ -194,9 +162,6 @@ public class ServicioUjaCoin {
*/
@Transactional
public void reintegro(@NotBlank String numCuenta, @NotBlank String numTarjeta, @Positive float importe) {
//Cuenta cuenta = Optional.ofNullable(cuentas.get(numCuenta))
// .orElseThrow(CuentaNoRegistrada::new);
Cuenta cuenta = repositorioCuentas.buscarYBloquear(numCuenta)
.orElseThrow(CuentaNoRegistrada::new);
......@@ -214,15 +179,9 @@ public class ServicioUjaCoin {
*/
@Transactional
public void transferencia(@NotBlank String numCuentaOrigen, @NotBlank String numCuentaDestino, @Positive float importe) {
// Cuenta cuentaOrigen = Optional.ofNullable(cuentas.get(numCuentaOrigen))
// .orElseThrow(CuentaNoRegistrada::new);
Cuenta cuentaOrigen = repositorioCuentas.buscarYBloquear(numCuentaOrigen)
.orElseThrow(CuentaNoRegistrada::new);
// Cuenta cuentaDestino = Optional.ofNullable(cuentas.get(numCuentaDestino))
// .orElseThrow(CuentaNoRegistrada::new);
Cuenta cuentaDestino = repositorioCuentas.buscarYBloquear(numCuentaDestino)
.orElseThrow(CuentaNoRegistrada::new);
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package es.ujaen.dae.ujacoin.util;
import java.security.MessageDigest;
......@@ -10,8 +5,8 @@ import java.security.NoSuchAlgorithmException;
import java.util.Base64;
/**
*
* @author admin
* Codificador sencillo para contraseñas basado en Md5 (no seguro)
* @author ajrueda
*/
public class CodificadorMd5 {
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package es.ujaen.dae.ujacoin.util;
/**
*
* Recopilación de expresiones regulares para validación
* @author ajrueda
*/
public class ExprReg {
private ExprReg() {}
private ExprReg() {
}
public static final String DNI = "\\d{8}[A-HJ-NP-TV-Z]";
public static final String TLF = "^(\\+34|0034|34)?[6789]\\d{8}$";
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package es.ujaen.dae.ujacoin.entidades;
import java.time.LocalDate;
......@@ -15,7 +10,7 @@ import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
/**
* Test para clase Cliente
* Test unitario para clase Cliente
* @author ajrueda
*/
public class ClienteTest {
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package es.ujaen.dae.ujacoin.entidades;
import es.ujaen.dae.ujacoin.entidades.movimientos.Ingreso;
......@@ -14,7 +9,7 @@ import org.assertj.core.api.Assertions;
import org.junit.Test;
/**
*
* Test unitario para clase Cuenta
* @author ajrueda
*/
public class CuentaTest {
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package es.ujaen.dae.ujacoin.servicios;
import javax.persistence.EntityManager;
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package es.ujaen.dae.ujacoin.servicios;
import es.ujaen.dae.ujacoin.entidades.Cliente;
......@@ -27,10 +22,9 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.orm.ObjectOptimisticLockingFailureException;
/**
*
* Test de integración de la aplicación
* @author ajrueda
*/
// @Disabled
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment