-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
01bbf4b
commit 83f77fa
Showing
12 changed files
with
349 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package Georef; | ||
|
||
import Georef.entidadesMolde.*; | ||
|
||
import java.io.IOException; | ||
|
||
//interfaz para traer los datos de la api porque podria ser implementada con distintas bibliotecas | ||
public interface APIGeorefAdapter { | ||
|
||
ListadoDeProvincias listaProvincias() throws IOException; | ||
|
||
ListadoDeMunicipios listaMunicipios(int provinciaId) throws IOException; | ||
|
||
ListadoDeDepartamentos listaDepartamentos(int provinciaId) throws IOException; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package Georef; | ||
|
||
import Georef.entidadesMolde.*; | ||
import retrofit2.Call; | ||
import retrofit2.http.GET; | ||
import retrofit2.http.Query; | ||
|
||
//interfaz que utiliza retrofit para matchear con la api, se definen las request http que pueden ir a georef despues de la url base | ||
public interface GeorefService { | ||
|
||
//falta departamentos | ||
|
||
@GET("provincias") | ||
Call<ListadoDeProvincias> provincias(); | ||
|
||
@GET("provincias") | ||
Call<ListadoDeProvincias> provincias (@Query("campos") String campos); | ||
|
||
@GET("municipios") | ||
Call<ListadoDeMunicipios> municipios (@Query("provincia") int provinciaId); | ||
|
||
@GET("departamentos") | ||
Call<ListadoDeDepartamentos> departamentos (@Query("provincia") int provinciaId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package Georef; | ||
|
||
import Georef.entidadesMolde.*; | ||
|
||
import java.io.IOException; | ||
|
||
//la clase posta a la que voy a llamar para traer las listas de departamentos, municipios y provincias | ||
public class ServicioGeoref { | ||
private static ServicioGeoref instancia = null; | ||
private APIGeorefAdapter adapter; | ||
|
||
//seteo retrofit como default | ||
private ServicioGeoref() { | ||
adapter = new ServicioGeorefRetrofitAdapter(); | ||
} | ||
|
||
//pero si quiero puedo cambiar Retrofit por otra biblioteca | ||
public void setAdapter(APIGeorefAdapter adapter) { | ||
this.adapter = adapter; | ||
} | ||
|
||
public static ServicioGeoref instancia(){ | ||
if(instancia== null){ | ||
instancia = new ServicioGeoref(); | ||
} | ||
return instancia; | ||
} | ||
|
||
public ListadoDeProvincias listaProvincias() { | ||
try { | ||
return this.adapter.listaProvincias(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public ListadoDeMunicipios listaMunicipios(int provinciaId) { | ||
try { | ||
return this.adapter.listaMunicipios(provinciaId); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public ListadoDeDepartamentos listaDepartamentos(int provinciaId) { | ||
try { | ||
return this.adapter.listaDepartamentos(provinciaId); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package Georef; | ||
|
||
import Georef.entidadesMolde.*; | ||
import retrofit2.Call; | ||
import retrofit2.Response; | ||
import retrofit2.Retrofit; | ||
import retrofit2.converter.gson.GsonConverterFactory; | ||
|
||
import java.io.IOException; | ||
|
||
//clase que trae los datos de la api con retrofit | ||
public class ServicioGeorefRetrofitAdapter implements APIGeorefAdapter { | ||
private static final int maximaCantidadRegistrosDefault = 200; | ||
private final String urlApi = "https://apis.datos.gob.ar/georef/api/"; | ||
private final Retrofit retrofit; | ||
|
||
public ServicioGeorefRetrofitAdapter() { | ||
this.retrofit = new Retrofit.Builder() | ||
.baseUrl(urlApi) | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.build(); | ||
} | ||
|
||
//falta listaDepartamentos() | ||
|
||
@Override | ||
public ListadoDeProvincias listaProvincias() throws IOException { | ||
GeorefService georefservice = this.retrofit.create(GeorefService.class); | ||
Call<ListadoDeProvincias> requestProvincias = georefservice.provincias(); | ||
Response<ListadoDeProvincias> responseProvincias = requestProvincias.execute(); | ||
return responseProvincias.body(); | ||
} | ||
|
||
@Override | ||
public ListadoDeMunicipios listaMunicipios(int provinciaId) throws IOException { | ||
GeorefService georefservice = this.retrofit.create(GeorefService.class); | ||
Call<ListadoDeMunicipios> requestMunicipios = georefservice.municipios(provinciaId); | ||
Response<ListadoDeMunicipios> responseMunicipios = requestMunicipios.execute(); | ||
return responseMunicipios.body(); | ||
} | ||
|
||
@Override | ||
public ListadoDeDepartamentos listaDepartamentos(int provinciaId) throws IOException { | ||
GeorefService georefservice = this.retrofit.create(GeorefService.class); | ||
Call<ListadoDeDepartamentos> requestDepartamentos = georefservice.departamentos(provinciaId); | ||
Response<ListadoDeDepartamentos> responseDepartamentos = requestDepartamentos.execute(); | ||
return responseDepartamentos.body(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package Georef.entidadesMolde; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public class Departamento { | ||
|
||
public String nombre; | ||
public int id; | ||
public Municipio municipio; | ||
|
||
public Departamento() { | ||
} | ||
|
||
public Departamento(String nombre, int id, Municipio municipio) { | ||
this.nombre = nombre; | ||
this.id = id; | ||
this.municipio = municipio; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
ENTREGA 3/src/Georef/entidadesMolde/ListadoDeDepartamentos.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package Georef.entidadesMolde; | ||
|
||
import java.util.List; | ||
|
||
public class ListadoDeDepartamentos { | ||
//atributos en publico porque son clasees molde que va utilizar Retrofit después | ||
public int cantidad; | ||
public int incio; | ||
public Parametro parametros; | ||
public int total; | ||
public List<Departamento> departamentos; | ||
|
||
private class Parametro { | ||
public List<String> campos; | ||
public int max; | ||
public List<String> provincia; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
ENTREGA 3/src/Georef/entidadesMolde/ListadoDeMunicipios.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package Georef.entidadesMolde; | ||
|
||
import java.util.List; | ||
|
||
public class ListadoDeMunicipios { | ||
//atributos en publico porque son clasees molde que va utilizar Retrofit después | ||
public int cantidad; | ||
public int incio; | ||
public Parametro parametros; | ||
public int total; | ||
public List<Municipio> municipios; | ||
|
||
private class Parametro { | ||
public List<String> campos; | ||
public int max; | ||
public List<String> provincia; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
ENTREGA 3/src/Georef/entidadesMolde/ListadoDeProvincias.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package Georef.entidadesMolde; | ||
|
||
import java.util.List; | ||
|
||
public class ListadoDeProvincias { | ||
//atributos en publico porque son clasees molde que va utilizar Retrofit después | ||
public int cantidad; | ||
public int incio; | ||
public Parametro parametros; | ||
public int total; | ||
public List<Provincia> provincias; | ||
|
||
//los query params que puedo pedir | ||
private class Parametro { | ||
public List<String> campos; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package Georef.entidadesMolde; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public class Municipio { | ||
|
||
public String nombre; | ||
public int id; | ||
public Provincia provincia; | ||
|
||
public Municipio() { | ||
} | ||
|
||
public Municipio(String nombre, int id, Provincia provincia) { | ||
this.nombre = nombre; | ||
this.id = id; | ||
this.provincia = provincia; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package Georef.entidadesMolde; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public class Provincia { | ||
public int id; | ||
public String nombre; | ||
|
||
public Provincia() { | ||
} | ||
|
||
public Provincia(int id, String nombre) { | ||
this.id = id; | ||
this.nombre = nombre; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
|
||
import Georef.ServicioGeoref; | ||
import Georef.ServicioGeorefRetrofitAdapter; | ||
import Georef.entidadesMolde.*; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
|
||
|
||
|
||
public class GeorefTest { | ||
ListadoDeProvincias listaProvinciasArgentina; | ||
ListadoDeMunicipios listaMunicipiosDeBuenosAires; | ||
ListadoDeDepartamentos listaDepartamentosDeBuenosAires; | ||
|
||
@BeforeEach | ||
public void init() throws IOException { | ||
ServicioGeoref servicioGeoref = ServicioGeoref.instancia(); | ||
servicioGeoref.setAdapter(new ServicioGeorefRetrofitAdapter()); | ||
listaProvinciasArgentina = servicioGeoref.listaProvincias(); | ||
listaMunicipiosDeBuenosAires = servicioGeoref.listaMunicipios(06); | ||
listaDepartamentosDeBuenosAires = servicioGeoref.listaDepartamentos(06); | ||
} | ||
|
||
@Test | ||
@DisplayName("Listado Provincias de Argentina") | ||
public void listadoProvincias() { | ||
for (Provincia provincia : listaProvinciasArgentina.provincias) { | ||
System.out.println(provincia.nombre); | ||
} | ||
Assertions.assertTrue(true); | ||
} | ||
|
||
//falta ver por que solo me trae algunos municipios | ||
@Test | ||
@DisplayName("Listado Municipios de Buenos Aires") | ||
public void listadoMunicipiosBsAs() { | ||
for (Municipio municipio : listaMunicipiosDeBuenosAires.municipios) { | ||
System.out.println(municipio.nombre); | ||
} | ||
Assertions.assertTrue(true); | ||
} | ||
|
||
//falta ver por que solo me trae algunos deptos | ||
@Test | ||
@DisplayName("Listado Departamentos de Buenos Aires") | ||
public void listadoDepartamentosBsAs() { | ||
for (Departamento departamento : listaDepartamentosDeBuenosAires.departamentos) { | ||
System.out.println(departamento.nombre); | ||
} | ||
Assertions.assertTrue(true); | ||
} | ||
} |