Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Antonio Rueda
/
UJACoin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
6c907007
authored
Dec 11, 2020
by
Antonio Rueda
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Revisión general de código y eliminación de código de estructuras de datos
parent
3696f1fa
Hide whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
21 additions
and
185 deletions
pom.xml
src/main/java/es/ujaen/dae/ujacoin/app/UjaCoinApp.java
src/main/java/es/ujaen/dae/ujacoin/entidades/movimientos/Ingreso.java
src/main/java/es/ujaen/dae/ujacoin/entidades/movimientos/Movimiento.java
src/main/java/es/ujaen/dae/ujacoin/entidades/movimientos/Reintegro.java
src/main/java/es/ujaen/dae/ujacoin/entidades/movimientos/TransferenciaEmitida.java
src/main/java/es/ujaen/dae/ujacoin/entidades/movimientos/TransferenciaRecibida.java
src/main/java/es/ujaen/dae/ujacoin/excepciones/ClienteNoRegistrado.java
src/main/java/es/ujaen/dae/ujacoin/excepciones/ClienteYaRegistrado.java
src/main/java/es/ujaen/dae/ujacoin/excepciones/CuentaNoRegistrada.java
src/main/java/es/ujaen/dae/ujacoin/excepciones/SaldoInsuficienteParaOperacion.java
src/main/java/es/ujaen/dae/ujacoin/excepciones/TarjetaNoRegistrada.java
src/main/java/es/ujaen/dae/ujacoin/excepciones/TarjetaYaRegistrada.java
src/main/java/es/ujaen/dae/ujacoin/objetosvalor/Token.java
src/main/java/es/ujaen/dae/ujacoin/servicios/ServicioUjaCoin.java
src/main/java/es/ujaen/dae/ujacoin/util/CodificadorMd5.java
src/main/java/es/ujaen/dae/ujacoin/util/ExprReg.java
src/test/java/es/ujaen/dae/ujacoin/entidades/ClienteTest.java
src/test/java/es/ujaen/dae/ujacoin/entidades/CuentaTest.java
src/test/java/es/ujaen/dae/ujacoin/servicios/ServicioLimpiadoBaseDatos.java
src/test/java/es/ujaen/dae/ujacoin/servicios/ServicioUjaCoinTest.java
pom.xml
View file @
6c907007
...
...
@@ -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>
...
...
src/main/java/es/ujaen/dae/ujacoin/app/UjaCoinApp.java
View file @
6c907007
/*
* 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 a
dmin
*
Clase principal
* @author a
jrueda
*/
@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
);
}
}
src/main/java/es/ujaen/dae/ujacoin/entidades/movimientos/Ingreso.java
View file @
6c907007
/*
* 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
;
...
...
src/main/java/es/ujaen/dae/ujacoin/entidades/movimientos/Movimiento.java
View file @
6c907007
/*
* 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 */
...
...
src/main/java/es/ujaen/dae/ujacoin/entidades/movimientos/Reintegro.java
View file @
6c907007
/*
* 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
;
...
...
src/main/java/es/ujaen/dae/ujacoin/entidades/movimientos/TransferenciaEmitida.java
View file @
6c907007
/*
* 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
;
...
...
src/main/java/es/ujaen/dae/ujacoin/entidades/movimientos/TransferenciaRecibida.java
View file @
6c907007
/*
* 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
;
...
...
src/main/java/es/ujaen/dae/ujacoin/excepciones/ClienteNoRegistrado.java
View file @
6c907007
/*
* 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
;
/**
...
...
src/main/java/es/ujaen/dae/ujacoin/excepciones/ClienteYaRegistrado.java
View file @
6c907007
/*
* 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
;
/**
...
...
src/main/java/es/ujaen/dae/ujacoin/excepciones/CuentaNoRegistrada.java
View file @
6c907007
/*
* 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
;
/**
...
...
src/main/java/es/ujaen/dae/ujacoin/excepciones/SaldoInsuficienteParaOperacion.java
View file @
6c907007
/*
* 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
;
/**
...
...
src/main/java/es/ujaen/dae/ujacoin/excepciones/TarjetaNoRegistrada.java
View file @
6c907007
/*
* 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
;
/**
...
...
src/main/java/es/ujaen/dae/ujacoin/excepciones/TarjetaYaRegistrada.java
View file @
6c907007
/*
* 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
;
/**
...
...
src/main/java/es/ujaen/dae/ujacoin/objetosvalor/Token.java
deleted
100644 → 0
View file @
3696f1fa
/*
* 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
src/main/java/es/ujaen/dae/ujacoin/servicios/ServicioUjaCoin.java
View file @
6c907007
/*
* 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
);
...
...
src/main/java/es/ujaen/dae/ujacoin/util/CodificadorMd5.java
View file @
6c907007
/*
* 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 a
dmin
*
Codificador sencillo para contraseñas basado en Md5 (no seguro)
* @author a
jrueda
*/
public
class
CodificadorMd5
{
...
...
src/main/java/es/ujaen/dae/ujacoin/util/ExprReg.java
View file @
6c907007
/*
* 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}$"
;
...
...
src/test/java/es/ujaen/dae/ujacoin/entidades/ClienteTest.java
View file @
6c907007
/*
* 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
{
...
...
src/test/java/es/ujaen/dae/ujacoin/entidades/CuentaTest.java
View file @
6c907007
/*
* 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
{
...
...
src/test/java/es/ujaen/dae/ujacoin/servicios/ServicioLimpiadoBaseDatos.java
View file @
6c907007
/*
* 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
;
...
...
src/test/java/es/ujaen/dae/ujacoin/servicios/ServicioUjaCoinTest.java
View file @
6c907007
/*
* 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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment