Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
DAE-Ujapack
/
Ujapack
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
de867cc3
authored
Oct 26, 2020
by
=
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Commit final
parent
105c6e02
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
87 additions
and
3 deletions
src/main/java/es/ujaen/dae/Ujapack/UjapackApplication.java
src/main/java/es/ujaen/dae/beans/ServicioUjaPackImpl.java
src/main/java/es/ujaen/dae/interfaces/ServicioUjaPack.java
src/test/java/es/ujaen/dae/Ujapack/entidades/EnvioTest.java
src/main/java/es/ujaen/dae/Ujapack/UjapackApplication.java
View file @
de867cc3
...
...
@@ -4,6 +4,7 @@ import com.google.gson.Gson;
import
com.google.gson.JsonArray
;
import
com.google.gson.JsonElement
;
import
com.google.gson.JsonObject
;
import
es.ujaen.dae.beans.ServicioUjaPackImpl
;
import
es.ujaen.dae.entidades.Envio
;
import
es.ujaen.dae.entidades.PuntodeControl
;
import
es.ujaen.dae.entidades.TipoPunto
;
...
...
@@ -73,11 +74,15 @@ public class UjapackApplication {
pc
.
setProvincias
(
provincias
);
puntosdecontrol
.
put
(
id
,
pc
);
/**Aqui es id y no idPr porque aqui se añaden especificamente los centros logisticos, no oficinas
por lo que se toma dicho id. */
//System.out.println(pc.toString());
}
puntosdecontrol
.
forEach
((
k
,
v
)
->
System
.
out
.
println
(
"Clave del punto de control: "
+
k
+
"Valor asociado: "
+
v
));
ServicioUjaPackImpl
servi
=
new
ServicioUjaPackImpl
();
servi
.
crearEnvio
(
"Juan"
,
"Maria"
,
"Jaen"
,
"Jaen"
,
0
,
0
,
0
,
0
);
//Test manuales
/*
//Prueba del metodo Calcular ruta y calcular importe
Envio e = new Envio("Jose","Maria","Castellon","Islas Baleares",0.5f,20.4f,20.4f,20.4f);
...
...
@@ -93,6 +98,7 @@ public class UjapackApplication {
System.out.println(v);
e.Pasos(e);
//Fin de prueba del metodo calcular ruta. Esto debe pasarse a un test propio
*/
}
...
...
src/main/java/es/ujaen/dae/beans/ServicioUjaPackImpl.java
View file @
de867cc3
...
...
@@ -4,13 +4,25 @@
* and open the template in the editor.
*/
package
es
.
ujaen
.
dae
.
beans
;
import
com.google.gson.Gson
;
import
com.google.gson.JsonArray
;
import
com.google.gson.JsonElement
;
import
com.google.gson.JsonObject
;
import
es.ujaen.dae.entidades.Envio
;
import
es.ujaen.dae.entidades.HoraEnvios
;
import
es.ujaen.dae.entidades.PuntodeControl
;
import
es.ujaen.dae.entidades.TipoPunto
;
import
static
es
.
ujaen
.
dae
.
entidades
.
TipoPunto
.
CentroLogistico
;
import
static
es
.
ujaen
.
dae
.
entidades
.
TipoPunto
.
Oficina
;
import
es.ujaen.dae.interfaces.ServicioUjaPack
;
import
java.io.BufferedReader
;
import
java.io.FileNotFoundException
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.Set
;
import
org.springframework.stereotype.Component
;
...
...
@@ -24,6 +36,7 @@ public class ServicioUjaPackImpl implements ServicioUjaPack{
private
String
oficinaOrigen
;
//Creo que estos dos atributos son innecesarios
private
String
oficinaDestino
;
//Creo que estos dos atributos son innecesarios
private
ArrayList
<
Envio
>
envios
;
private
HashMap
<
Integer
,
PuntodeControl
>
json
;
...
...
@@ -36,6 +49,58 @@ public class ServicioUjaPackImpl implements ServicioUjaPack{
*/
public
ServicioUjaPackImpl
(){
this
.
envios
=
new
ArrayList
<>();
this
.
json
=
new
HashMap
<>();
}
private
HashMap
<
Integer
,
PuntodeControl
>
lecturaJson
(){
HashMap
<
Integer
,
PuntodeControl
>
puntosdecontrol
=
new
HashMap
<>();
int
idPr
=
11
;
//Id para las provincias, se usa para darle un identificador a cada una de las oficinas.
String
fichero
=
""
;
try
(
BufferedReader
br
=
new
BufferedReader
(
new
FileReader
(
"redujapackPr.json"
))){
String
linea
;
while
((
linea
=
br
.
readLine
())!=
null
){
fichero
+=
linea
;
}
}
catch
(
FileNotFoundException
e
){
System
.
out
.
println
(
e
.
getMessage
());
}
catch
(
IOException
e
){
System
.
out
.
println
(
e
.
getMessage
());
}
JsonObject
obj
=
new
Gson
().
fromJson
(
fichero
,
JsonObject
.
class
);
Set
<
String
>
centrosLCla
=
obj
.
keySet
();
//Se guardan las claves de los centros logísticos.
for
(
String
centro
:
centrosLCla
){
ArrayList
<
String
>
provincias
=
new
ArrayList
<>();
ArrayList
<
Integer
>
conexiones
=
new
ArrayList
<>();
JsonObject
centroJson
=
obj
.
getAsJsonObject
(
centro
);
int
id
=
Integer
.
parseInt
(
centro
);
//Id para especidificamente los centros logísticos.
String
nombre
=
centroJson
.
get
(
"nombre"
).
getAsString
();
String
localizacion
=
centroJson
.
get
(
"localizacion"
).
getAsString
();
JsonArray
provinciasArr
=
centroJson
.
getAsJsonArray
(
"provincias"
);
for
(
JsonElement
prov
:
provinciasArr
){
provincias
.
add
(
prov
.
getAsString
());
PuntodeControl
pc2
=
new
PuntodeControl
(
prov
.
getAsString
(),
prov
.
getAsString
(),
Oficina
,
nombre
);
puntosdecontrol
.
put
(
idPr
,
pc2
);
pc2
.
setConexiones
(
conexiones
);
idPr
++;
}
JsonArray
conexionesArr
=
centroJson
.
getAsJsonArray
(
"conexiones"
);
for
(
JsonElement
con
:
conexionesArr
){
conexiones
.
add
(
con
.
getAsInt
());
}
PuntodeControl
pc
=
new
PuntodeControl
(
nombre
,
localizacion
,
CentroLogistico
,
nombre
);
pc
.
setConexiones
(
conexiones
);
pc
.
setProvincias
(
provincias
);
puntosdecontrol
.
put
(
id
,
pc
);
}
return
puntosdecontrol
;
}
...
...
@@ -101,7 +166,10 @@ public class ServicioUjaPackImpl implements ServicioUjaPack{
*/
@Override
public
Envio
crearEnvio
(
String
remitente
,
String
destinatario
,
String
origen
,
String
destino
,
float
peso
,
float
alto
,
float
largo
,
float
ancho
){
return
new
Envio
(
remitente
,
destinatario
,
origen
,
destino
,
peso
,
alto
,
largo
,
ancho
);
Envio
e
=
new
Envio
(
remitente
,
destinatario
,
origen
,
destino
,
peso
,
alto
,
largo
,
ancho
);
e
.
calcularRuta
(
json
,
e
);
e
.
calcularImporte
(
e
);
return
e
;
}
...
...
@@ -123,6 +191,13 @@ public class ServicioUjaPackImpl implements ServicioUjaPack{
}
}
}
/**
* @return the json
*/
public
HashMap
<
Integer
,
PuntodeControl
>
getJson
()
{
return
json
;
}
...
...
src/main/java/es/ujaen/dae/interfaces/ServicioUjaPack.java
View file @
de867cc3
...
...
@@ -8,6 +8,7 @@ package es.ujaen.dae.interfaces;
import
es.ujaen.dae.entidades.Envio
;
import
es.ujaen.dae.entidades.PuntodeControl
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
/**
*
...
...
@@ -26,4 +27,5 @@ public interface ServicioUjaPack {
public
void
notificar
(
int
id
);
}
src/test/java/es/ujaen/dae/Ujapack/entidades/EnvioTest.java
View file @
de867cc3
...
...
@@ -25,6 +25,7 @@ public class EnvioTest {
Envio
e
=
new
Envio
(
"Jose"
,
"Maria"
,
"Castellon"
,
"Islas Baleares"
,
0.5f
,
20.4f
,
20.4f
,
20.4f
);
Assertions
.
assertNotNull
(
e
.
calcularImporte
(
e
));
}
}
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