From b9871fb40bdb74db7d09aafe331f71dc3230f2be Mon Sep 17 00:00:00 2001 From: "ronny.soutart" Date: Wed, 9 Dec 2020 14:46:53 +1100 Subject: [PATCH 1/3] feat(commune): WIP --- .gitignore | 4 +- .../adriens/opt/tempsattente/sdk/Agence.java | 191 +++++++++++++++++- .../adriens/opt/tempsattente/sdk/Agences.java | 163 +++++++++------ .../opt/tempsattente/sdk/AgenceTest.java | 16 +- .../opt/tempsattente/sdk/AgencesTest.java | 20 +- 5 files changed, 321 insertions(+), 73 deletions(-) diff --git a/.gitignore b/.gitignore index 3579cd9..88e2e13 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ /nbproject/ -/target/ \ No newline at end of file +/target/ +.idea/ +tempsattente-sdk.iml diff --git a/src/main/java/com/github/adriens/opt/tempsattente/sdk/Agence.java b/src/main/java/com/github/adriens/opt/tempsattente/sdk/Agence.java index d3f2eed..ad53ab8 100644 --- a/src/main/java/com/github/adriens/opt/tempsattente/sdk/Agence.java +++ b/src/main/java/com/github/adriens/opt/tempsattente/sdk/Agence.java @@ -27,6 +27,15 @@ public class Agence { private double coordonneeY; private long coordonneeXPrecise; private long coordonneeYPrecise; + private String commune; + private String type; + private String codeESirius; + private String codePostal; + private String lieuDitOuTribu; + private String localite; + private String idRefloc; + private String codePostalRefloc; + private String localiteRefloc; /** * Default constructor. @@ -39,6 +48,15 @@ public Agence() { this.coordonneeY = 0; this.coordonneeXPrecise = 0; this.coordonneeYPrecise = 0; + this.commune = ""; + this.type = ""; + this.codeESirius = ""; + this.codePostal = ""; + this.lieuDitOuTribu = ""; + this.localite = ""; + this.idRefloc = ""; + this.codePostalRefloc = ""; + this.localiteRefloc = ""; } /** @@ -52,7 +70,7 @@ public Agence() { * @param coordonneeXPrecise the precise X coordinate of the agency. * @param coordonneeYPrecise the precise Y coordinate of the agency. */ - public Agence(int idAgence, String designation, long realMaxWaitingTimeMs, double coordonneeX, double coordonneeY, long coordonneeXPrecise, long coordonneeYPrecise) { + public Agence(int idAgence, String designation, long realMaxWaitingTimeMs, double coordonneeX, double coordonneeY, long coordonneeXPrecise, long coordonneeYPrecise, String commune, String type, String codeESirius, String codePostal, String lieuDitOuTribu, String localite, String idRefloc, String codePostalRefloc, String localiteRefloc) { this.idAgence = idAgence; this.designation = designation; this.realMaxWaitingTimeMs = realMaxWaitingTimeMs; @@ -60,6 +78,15 @@ public Agence(int idAgence, String designation, long realMaxWaitingTimeMs, doubl this.coordonneeY = coordonneeY; this.coordonneeXPrecise = coordonneeXPrecise; this.coordonneeYPrecise = coordonneeYPrecise; + this.commune = commune; + this.type = type; + this.codeESirius = codeESirius; + this.codePostal = codePostal; + this.lieuDitOuTribu = lieuDitOuTribu; + this.localite = localite; + this.idRefloc = idRefloc; + this.codePostalRefloc = codePostalRefloc; + this.localiteRefloc = localiteRefloc; } /** @@ -125,6 +152,87 @@ public long getCoordonneeYPrecise() { return this.coordonneeYPrecise; } + /** + * Return the commune of the agency. + * + * @return the commune of the agency. + */ + public String getCommune() { + return this.commune; + } + + /** + * Return the type of the agency. + * + * @return the type of the agency. + */ + public String getType() { + return this.type; + } + + /** + * Return the Esirius code of the agency. + * + * @return the Esirius code of the agency. + */ + public String getCodeESirius() { + return this.codeESirius; + } + + /** + * Return the postal code of the agency. + * + * @return the postal code of the agency. + */ + public String getCodePostal() { + return this.codePostal; + } + + /** + * Return the locality or tribe of the agency. + * + * @return the locality or tribe of the agency. + */ + public String getLieuDitOuTribu() { + return this.lieuDitOuTribu; + } + + /** + * Return the locality of the agency. + * + * @return the locality of the agency. + */ + public String getLocalite() { + return this.localite; + } + + /** + * Return the refloc id of the agency. + * + * @return the refloc id of the agency. + */ + public String getIdRefloc() { + return this.idRefloc; + } + + /** + * Return the refloc postal code of the agency. + * + * @return the refloc postal code of the agency. + */ + public String getCodePostalRefloc() { + return this.codePostalRefloc; + } + + /** + * Return the refloc locality of the agency. + * + * @return the refloc locality of the agency. + */ + public String getLocaliteRefloc() { + return this.localiteRefloc; + } + /** * Set the agency's ID number. * @@ -187,6 +295,78 @@ public void setCoordonneeYPrecise(long coordonneeYPrecise) { this.coordonneeYPrecise = coordonneeYPrecise; } + /** + * Set the commune of the agency. + * @param commune the type of the agency. + */ + public void setCommune(String commune) { + this.commune = commune; + } + + /** + * Set the type of the agency. + * @param type the type of the agency. + */ + public void setType(String type) { + this.type = type; + } + + /** + * Set the Esirius code of the agency. + * @param codeESirius the Esirius code of the agency. + */ + public void setCodeESirius(String codeESirius) { + this.codeESirius = codeESirius; + } + + /** + * Set the postal code of the agency. + * @param codePostal the postal code of the agency. + */ + public void setCodePostal(String codePostal) { + this.codePostal = codePostal; + } + + /** + * Set the locality or tribe of the agency. + * @param lieuDitOuTribu the locality or tribe of the agency. + */ + public void setLieuDitOuTribu(String lieuDitOuTribu) { + this.lieuDitOuTribu = lieuDitOuTribu; + } + + /** + * Set the locality of the agency. + * @param localite the locality of the agency. + */ + public void setLocalite(String localite) { + this.localite = localite; + } + + /** + * Set the refloc id of the agency. + * @param idRefloc the refloc id of the agency. + */ + public void setIdRefloc(String idRefloc) { + this.idRefloc = idRefloc; + } + + /** + * Set the refloc postal code of the agency. + * @param codePostalRefloc the refloc postal code of the agency. + */ + public void setCodePostalRefloc(String codePostalRefloc) { + this.codePostalRefloc = codePostalRefloc; + } + + /** + * Set the refloc locality of the agency. + * @param localiteRefloc the refloc locality of the agency. + */ + public void setLocaliteRefloc(String localiteRefloc) { + this.localiteRefloc = localiteRefloc; + } + /** * Return the agency with the ID number in parameter. * @@ -228,6 +408,15 @@ public String toString() { + ", coordonneeY: " + this.coordonneeY + ", coordonneeXPrecise: " + this.coordonneeXPrecise + ", coordonneeYPrecise: " + this.coordonneeYPrecise + + ", commune: " + this.commune + + ", type: " + this.type + + ", codeESirius: " + this.codeESirius + + ", codePostal: " + this.codePostal + + ", lieuDitOuTribu: " + this.lieuDitOuTribu + + ", localite: " + this.localite + + ", idRefloc: " + this.idRefloc + + ", codePostalRefloc: " + this.codePostalRefloc + + ", localiteRefloc: " + this.localiteRefloc + ">"; } diff --git a/src/main/java/com/github/adriens/opt/tempsattente/sdk/Agences.java b/src/main/java/com/github/adriens/opt/tempsattente/sdk/Agences.java index a365ab8..46cb3ff 100644 --- a/src/main/java/com/github/adriens/opt/tempsattente/sdk/Agences.java +++ b/src/main/java/com/github/adriens/opt/tempsattente/sdk/Agences.java @@ -15,6 +15,10 @@ import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.HashMap; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,6 +42,8 @@ public class Agences { */ public static final String BASE_URL = "https://open-data.opt.nc/agences/_search?size=1000"; + private static final String HYPHEN_SEPARATOR = "------------------------------------------------------------"; + /** * Locations enumeration. */ @@ -75,7 +81,8 @@ public static enum Commune { MARE, POINDIMIE, PONERIHOUEN, - VOH; + VOH, + TONTOUTA } @@ -124,8 +131,9 @@ public static String getUrl(Commune commune) { if ("POINDIMIE".equals(commune.name())) url = "&q=localiteRefloc:(POINDIMIE)"; if ("PONERIHOUEN".equals(commune.name())) url = "&q=localiteRefloc:(PONERIHOUEN)"; if ("VOH".equals(commune.name())) url = "&q=localiteRefloc:(VOH)"; + if ("TONTOUTA".equals(commune.name())) url = "&q=localiteRefloc:(TONTOUTA)"; - logger.info("------------------------------------------------------------"); + logger.info(HYPHEN_SEPARATOR); return url; } @@ -175,6 +183,7 @@ public static ArrayList getCommunesNames() { commune_map.put(Commune.POINDIMIE, "poindimie"); commune_map.put(Commune.PONERIHOUEN, "ponerihouen"); commune_map.put(Commune.VOH, "voh"); + commune_map.put(Commune.TONTOUTA, "tontouta"); for (Commune commune : Commune.values()) { logger.info("Ajout de la commune : " + commune_map.get(commune)); @@ -182,7 +191,7 @@ public static ArrayList getCommunesNames() { } logger.info("" + commune_name.size() + " communes ajoutées."); - logger.info("------------------------------------------------------------"); + logger.info(HYPHEN_SEPARATOR); return commune_name; } @@ -231,25 +240,26 @@ public static Commune getCommune(String communeName) { commune.put("poindimie", Commune.POINDIMIE); commune.put("ponerihouen", Commune.PONERIHOUEN); commune.put("voh", Commune.VOH); + commune.put("tontouta", Commune.TONTOUTA); if (communeName == null) { logger.error("<" + communeName + "> ne correspond à aucune commune."); - logger.info("------------------------------------------------------------"); + logger.info(HYPHEN_SEPARATOR); return null; } if ("".equals(communeName)) { logger.error("<" + communeName + "> ne correspond à aucune commune."); - logger.info("------------------------------------------------------------"); + logger.info(HYPHEN_SEPARATOR); return null; } if (commune.containsKey(StringUtils.stripAccents(communeName.toLowerCase()))) { logger.info("correspondance trouvée pour <" + communeName + "> : <" + commune.get(StringUtils.stripAccents(communeName.toLowerCase())) + ">"); - logger.info("------------------------------------------------------------"); + logger.info(HYPHEN_SEPARATOR); return commune.get(communeName); } else { logger.error("" + communeName + " ne correspond à aucune commune."); - logger.info("------------------------------------------------------------"); + logger.info(HYPHEN_SEPARATOR); return null; } } @@ -266,12 +276,36 @@ public static ArrayList getAgences() throws IOException { ArrayList listeAgences = new ArrayList<>(); + logger.info("Recherche de l'URL : "); + URL url = new URL(BASE_URL); + + logger.info("Recupération des données des agences : "); + + ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + JsonNode jsonNode = mapper.readValue(url, JsonNode.class); + int total = jsonNode.get("hits").get("total").asInt(); + + ArrayList ids = new ArrayList<>(); + + for (int i = 0; i < total; i++) { + JsonNode nodeAgency = jsonNode.get("hits").get("hits").get(i).get("_source"); + ids.add(nodeAgency.get("id").asInt()); + } + for (Commune value : Commune.values()) { ArrayList listeAgences_commune = Agences.getAgences(value); listeAgences.addAll(listeAgences_commune); } - logger.info("------------------------------------------------------------"); + for (Integer id : ids) { + List agence = listeAgences.stream().filter(a -> a.getIdAgence() == id).collect(Collectors.toList()); + if (agence.isEmpty()) { + logger.error("Agence {} absent de la liste", id); + } + + } + + logger.info(HYPHEN_SEPARATOR); return listeAgences; } @@ -284,7 +318,7 @@ public static ArrayList getAgences() throws IOException { */ public static ArrayList getAgences(Commune commune) throws IOException { - logger.info("Récupération de la liste des agences de <" + commune + ">"); + logger.info("Récupération de la liste des agences de <{}>", commune); ArrayList listeAgences = new ArrayList<>(); ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); @@ -301,66 +335,64 @@ public static ArrayList getAgences(Commune commune) throws IOException { JsonNode jsonNode = mapper.readValue(url, JsonNode.class); int total = jsonNode.get("hits").get("total").asInt(); - logger.info("" + total + " résultats trouvés."); + logger.info("{} résultats trouvés.", total); for (int i = 0; i < total; i++) { try { - int idAgence = jsonNode.get("hits").get("hits").get(i).get("_source").get("id").asInt(); - String designation = jsonNode.get("hits").get("hits").get(i).get("_source").get("designation").asText(); - long realMaxWaitingTimeMs = ConvertToMillis(jsonNode.get("hits").get("hits").get(i).get("_source").get("borneEsirius").get("realMaxWaitingTime").asText()); - String coordonneesXY = jsonNode.get("hits").get("hits").get(i).get("_source").get("coordonneesXyRefloc").asText(); - JsonNode nodeCoordonneesXYPrecises = jsonNode.get("hits").get("hits").get(i).get("_source").get("coordonneesXyPrecisesRefloc"); + Agence agence = new Agence(); + JsonNode nodeAgency = jsonNode.get("hits").get("hits").get(i).get("_source"); + String[] coordonneesXY = Agences.getCoordonneesXY(nodeAgency.get("coordonneesXyRefloc")); + + agence.setCommune(commune.toString()); + agence.setIdAgence(nodeAgency.get("id").asInt()); + agence.setDesignation(nodeAgency.get("designation").asText()); + agence.setType(nodeAgency.get("type").asText()); + agence.setCodeESirius(nodeAgency.get("codeESirius").asText()); + agence.setIdRefloc(nodeAgency.get("idRefloc").asText()); + agence.setCodePostalRefloc(nodeAgency.get("codePostalRefloc").asText()); + agence.setCodePostal(nodeAgency.get("codePostal").asText()); + agence.setLieuDitOuTribu(nodeAgency.get("lieuDitOuTribu").asText()); + agence.setLocaliteRefloc(nodeAgency.get("localiteRefloc").asText()); + agence.setLocalite(nodeAgency.get("localite").asText()); + + if (coordonneesXY != null) { + agence.setCoordonneeX(Double.parseDouble(coordonneesXY[0])); + agence.setCoordonneeY(Double.parseDouble(coordonneesXY[1])); + } - String[] tcoordonneesXY = coordonneesXY.split(";"); - double coordonneeX = Double.parseDouble(tcoordonneesXY[0]); - double coordonneeY = Double.parseDouble(tcoordonneesXY[1]); + try { + agence.setRealMaxWaitingTimeMs(ConvertToMillis(nodeAgency.get("borneEsirius").get("realMaxWaitingTime").asText())); + } catch (Exception e) { + logger.warn("Le temps d'attente maximum de l'agence <{}> est introuvable...", agence.getDesignation(), e); + } - long[] tCoordonneesXYPrecises = Agences.getCoordonneesXYPrecises(nodeCoordonneesXYPrecises); - long coordonneeXPrecise = tCoordonneesXYPrecises[0]; - long coordonneeYPrecise = tCoordonneesXYPrecises[1]; + try { + long[] coordonneesXYPrecises = Agences.getCoordonneesXYPrecises(nodeAgency.get("coordonneesXyPrecisesRefloc")); + + if (coordonneesXYPrecises != null) { + agence.setCoordonneeXPrecise(coordonneesXYPrecises[0]); + agence.setCoordonneeXPrecise(coordonneesXYPrecises[1]); + } + } catch (Exception e) { + logger.warn("Les coordonnées X et Y précises de l'agence <{}> sont introuvables...", agence.getDesignation(), e); + } - Agence agence = new Agence(idAgence, designation, realMaxWaitingTimeMs, coordonneeX, coordonneeY, coordonneeXPrecise, coordonneeYPrecise); listeAgences.add(agence); - logger.info("Agence : " + agence.toString()); + logger.info("Agence : {}", agence.toString()); } catch (Exception e) { - - int idAgence = jsonNode.get("hits").get("hits").get(i).get("_source").get("id").asInt(); - String designation = jsonNode.get("hits").get("hits").get(i).get("_source").get("designation").asText(); - String coordonneesXY = jsonNode.get("hits").get("hits").get(i).get("_source").get("coordonneesXyRefloc").asText(); - JsonNode nodeCoordonneesXYPrecises = jsonNode.get("hits").get("hits").get(i).get("_source").get("coordonneesXyPrecisesRefloc"); - - logger.warn("Le temps d'attente maximum de l'agence <" + designation + "> est introuvable..."); - - String[] tcoordonneesXY = coordonneesXY.split(";"); - double coordonneeX = Double.parseDouble(tcoordonneesXY[0]); - double coordonneeY = Double.parseDouble(tcoordonneesXY[1]); - - try { - long[] tCoordonneesXYPrecises = Agences.getCoordonneesXYPrecises(nodeCoordonneesXYPrecises); - long coordonneeXPrecise = tCoordonneesXYPrecises[0]; - long coordonneeYPrecise = tCoordonneesXYPrecises[1]; - - Agence agence = new Agence(idAgence, designation, 0, coordonneeX, coordonneeY, coordonneeXPrecise, coordonneeYPrecise); - listeAgences.add(agence); - - logger.info("Agence : " + agence.toString()); - - } catch (Exception ex) { - logger.warn("Les coordonnées X et Y précises de l'agence <" + designation + "> sont introuvables..."); - - Agence agence = new Agence(idAgence, designation, 0, coordonneeX, coordonneeY, 0, 0); - listeAgences.add(agence); - - logger.info("Agence : " + agence.toString()); - } - + logger.warn("Erreur lors de la récupération des informations...", e); } } - logger.info("------------------------------------------------------------"); + if (listeAgences.size() != total) + logger.warn("Erreur compteurs agences pour la comunne : {}", commune.toString()); + else + logger.info("Compteurs agences OK pour la comunne : {}", commune.toString()); + + logger.info(HYPHEN_SEPARATOR); return listeAgences; } @@ -376,10 +408,21 @@ public static long ConvertToMillis(String duree) { LocalTime duree_localTime = LocalTime.parse(duree, DateTimeFormatter.ISO_LOCAL_TIME); long millis = ChronoUnit.MILLIS.between(LocalTime.MIN, duree_localTime); - logger.info("------------------------------------------------------------"); + logger.info(HYPHEN_SEPARATOR); return millis; } + /** + * Return the X and Y coordinates of the agency converted as string. + * + * @param nodeCoordonnesXY the node where the coordinate data is + * located. + * @return a array of the X and Y coordinates of the agency as String. + */ + public static String[] getCoordonneesXY(JsonNode nodeCoordonnesXY) { + return nodeCoordonnesXY == null ? null : nodeCoordonnesXY.asText().split(";"); + } + /** * Return the precise X and Y coordinates of the agency converted as long. * @@ -388,23 +431,23 @@ public static long ConvertToMillis(String duree) { * @return a array of the precise X and Y coordinates of the agency as long. */ public static long[] getCoordonneesXYPrecises(JsonNode nodeCoordonnesXYPrecises) { - logger.info("------------------------------------------------------------"); + logger.info(HYPHEN_SEPARATOR); if (nodeCoordonnesXYPrecises.isNull()) { logger.info("coordonneesXyPrecises null"); - logger.info("------------------------------------------------------------"); + logger.info(HYPHEN_SEPARATOR); return null; } else { String strCoordonneesXYPrecises = nodeCoordonnesXYPrecises.asText(); if ("".equals(strCoordonneesXYPrecises)) { logger.info("coordonneesXyPrecises vide"); - logger.info("------------------------------------------------------------"); + logger.info(HYPHEN_SEPARATOR); return null; } else { logger.info("coordonneesXyPrecises récupérées. conversion..."); String[] tStrCoordonneesXYPrecises = strCoordonneesXYPrecises.split(","); long[] tCoordonneesXYPrecises = {Long.parseLong(tStrCoordonneesXYPrecises[0]), Long.parseLong(tStrCoordonneesXYPrecises[1])}; - logger.info("------------------------------------------------------------"); + logger.info(HYPHEN_SEPARATOR); return tCoordonneesXYPrecises; } } diff --git a/src/test/java/com/github/adriens/opt/tempsattente/sdk/AgenceTest.java b/src/test/java/com/github/adriens/opt/tempsattente/sdk/AgenceTest.java index 9f3ff99..f6e2077 100644 --- a/src/test/java/com/github/adriens/opt/tempsattente/sdk/AgenceTest.java +++ b/src/test/java/com/github/adriens/opt/tempsattente/sdk/AgenceTest.java @@ -32,7 +32,7 @@ public AgenceTest() { public void testGetIdAgence() { System.out.println("\ngetIdAgence_TEST"); - Agence instance = new Agence(123456, "designationTEST", 0, 0, 0, 0, 0); + Agence instance = new Agence(123456, "designationTEST", 0, 0, 0, 0, 0, "", "", "", "", "", "", "", "", ""); int expResult = 123456; int result = instance.getIdAgence(); @@ -63,7 +63,7 @@ public void testSetIdAgence() { public void testGetDesignation() { System.out.println("\ngetDesignation_TEST"); - Agence instance = new Agence(123456, "designationTEST", 0, 0, 0, 0, 0); + Agence instance = new Agence(123456, "designationTEST", 0, 0, 0, 0, 0, "", "", "", "", "", "", "", "", ""); String expResult = "designationTEST"; String result = instance.getDesignation(); @@ -94,7 +94,7 @@ public void testSetDesignation() { public void testGetRealMaxWaitingTime() { System.out.println("\ngetRealMaxWaitingTime_TEST"); - Agence instance = new Agence(123456, "designationTEST", Agences.ConvertToMillis("00:00:52"), 0, 0, 0, 0); + Agence instance = new Agence(123456, "designationTEST", Agences.ConvertToMillis("00:00:52"), 0, 0, 0, 0, "", "", "", "", "", "", "", "", ""); long expResult = Agences.ConvertToMillis("00:00:52"); long result = instance.getRealMaxWaitingTimeMs(); @@ -124,7 +124,7 @@ public void testSetRealMaxWaitingTime() { public void testGetCoordonneeX() { System.out.println("\ngetCoordonneeX_TEST"); - Agence instance = new Agence(123456, "designationTEST", 0, 422331.96350000054, 0, 0, 0); + Agence instance = new Agence(123456, "designationTEST", 0, 422331.96350000054, 0, 0, 0, "", "", "", "", "", "", "", "", ""); double expResult = 422331.96350000054; double result = instance.getCoordonneeX(); @@ -154,7 +154,7 @@ public void testSetCoordonneeX() { public void testGetCoordonneeY() { System.out.println("\ngetCoordonneeY_TEST"); - Agence instance = new Agence(123456, "designationTEST", 0, 0, 242663.05560000055, 0, 0); + Agence instance = new Agence(123456, "designationTEST", 0, 0, 242663.05560000055, 0, 0, "", "", "", "", "", "", "", "", ""); double expResult = 242663.05560000055; double result = instance.getCoordonneeY(); @@ -184,7 +184,7 @@ public void testSetCoordonneeY() { public void testGetCoordonneeXPrecise() { System.out.println("\ngetCoordonneeXPrecise_TEST"); - Agence instance = new Agence(123456, "designationTEST", 0, 0, 0, 422655, 0); + Agence instance = new Agence(123456, "designationTEST", 0, 0, 0, 422655, 0, "", "", "", "", "", "", "", "", ""); long expResult = 422655; long result = instance.getCoordonneeXPrecise(); @@ -214,7 +214,7 @@ public void testSetCoordonneeXPrecise() { public void testGetCoordonneeYPrecise() { System.out.println("\ngetCoordonneeYPrecise_TEST"); - Agence instance = new Agence(123456, "designationTEST", 0, 0, 0, 0, 242977); + Agence instance = new Agence(123456, "designationTEST", 0, 0, 0, 0, 242977, "", "", "", "", "", "", "", "", ""); long expResult = 242977; long result = instance.getCoordonneeYPrecise(); @@ -287,7 +287,7 @@ public void testToString() { double coordonneeY = 242663.05560000055; long coordonneeXPrecise = 422655; long coordonneeYPrecise = 242977; - Agence instance = new Agence(123456, "designationTEST", Agences.ConvertToMillis("00:00:52"), 422331.96350000054, 242663.05560000055, 422655, 242977); + Agence instance = new Agence(123456, "designationTEST", Agences.ConvertToMillis("00:00:52"), 422331.96350000054, 242663.05560000055, 422655, 242977, "", "", "", "", "", "", "", "", ""); String expResult = "Agence " + idAgence + " Date: Thu, 10 Dec 2020 09:20:50 +1100 Subject: [PATCH 2/3] feat(agences): Additional infos in Agence entity #16 --- .../adriens/opt/tempsattente/sdk/Agences.java | 50 +----- .../opt/tempsattente/sdk/AgenceTest.java | 146 +++++++++++++++++- .../opt/tempsattente/sdk/AgencesTest.java | 1 - 3 files changed, 149 insertions(+), 48 deletions(-) diff --git a/src/main/java/com/github/adriens/opt/tempsattente/sdk/Agences.java b/src/main/java/com/github/adriens/opt/tempsattente/sdk/Agences.java index 46cb3ff..0746609 100644 --- a/src/main/java/com/github/adriens/opt/tempsattente/sdk/Agences.java +++ b/src/main/java/com/github/adriens/opt/tempsattente/sdk/Agences.java @@ -93,9 +93,6 @@ public static enum Commune { * @return the url as text. */ public static String getUrl(Commune commune) { - - logger.info("Récupération de l'url de la commune: <" +commune+ ">"); - String url = ""; if ("BOULOUPARIS".equals(commune.name())) url = "&q=localiteRefloc:(BOULOUPARIS)"; @@ -133,7 +130,7 @@ public static String getUrl(Commune commune) { if ("VOH".equals(commune.name())) url = "&q=localiteRefloc:(VOH)"; if ("TONTOUTA".equals(commune.name())) url = "&q=localiteRefloc:(TONTOUTA)"; - logger.info(HYPHEN_SEPARATOR); + logger.info("Récupération de l'url de la commune: <{}> : {}", commune, BASE_URL + url); return url; } @@ -276,35 +273,11 @@ public static ArrayList getAgences() throws IOException { ArrayList listeAgences = new ArrayList<>(); - logger.info("Recherche de l'URL : "); - URL url = new URL(BASE_URL); - - logger.info("Recupération des données des agences : "); - - ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - JsonNode jsonNode = mapper.readValue(url, JsonNode.class); - int total = jsonNode.get("hits").get("total").asInt(); - - ArrayList ids = new ArrayList<>(); - - for (int i = 0; i < total; i++) { - JsonNode nodeAgency = jsonNode.get("hits").get("hits").get(i).get("_source"); - ids.add(nodeAgency.get("id").asInt()); - } - for (Commune value : Commune.values()) { ArrayList listeAgences_commune = Agences.getAgences(value); listeAgences.addAll(listeAgences_commune); } - for (Integer id : ids) { - List agence = listeAgences.stream().filter(a -> a.getIdAgence() == id).collect(Collectors.toList()); - if (agence.isEmpty()) { - logger.error("Agence {} absent de la liste", id); - } - - } - logger.info(HYPHEN_SEPARATOR); return listeAgences; } @@ -328,10 +301,7 @@ public static ArrayList getAgences(Commune commune) throws IOException { return listeAgences; } - logger.info("Recherche de l'URL : "); URL url = new URL("" + BASE_URL + Agences.getUrl(commune)); - - logger.info("Recupération des données des agences : "); JsonNode jsonNode = mapper.readValue(url, JsonNode.class); int total = jsonNode.get("hits").get("total").asInt(); @@ -364,7 +334,7 @@ public static ArrayList getAgences(Commune commune) throws IOException { try { agence.setRealMaxWaitingTimeMs(ConvertToMillis(nodeAgency.get("borneEsirius").get("realMaxWaitingTime").asText())); } catch (Exception e) { - logger.warn("Le temps d'attente maximum de l'agence <{}> est introuvable...", agence.getDesignation(), e); + logger.warn("Le temps d'attente maximum de l'agence <{}> est introuvable...", agence.getDesignation()); } try { @@ -375,23 +345,17 @@ public static ArrayList getAgences(Commune commune) throws IOException { agence.setCoordonneeXPrecise(coordonneesXYPrecises[1]); } } catch (Exception e) { - logger.warn("Les coordonnées X et Y précises de l'agence <{}> sont introuvables...", agence.getDesignation(), e); + logger.warn("Les coordonnées X et Y précises de l'agence <{}> sont introuvables...", agence.getDesignation()); } listeAgences.add(agence); - - logger.info("Agence : {}", agence.toString()); + logger.info("Agence <{}> : {}", agence.getIdAgence(), agence.toString()); } catch (Exception e) { logger.warn("Erreur lors de la récupération des informations...", e); } } - if (listeAgences.size() != total) - logger.warn("Erreur compteurs agences pour la comunne : {}", commune.toString()); - else - logger.info("Compteurs agences OK pour la comunne : {}", commune.toString()); - logger.info(HYPHEN_SEPARATOR); return listeAgences; } @@ -408,7 +372,6 @@ public static long ConvertToMillis(String duree) { LocalTime duree_localTime = LocalTime.parse(duree, DateTimeFormatter.ISO_LOCAL_TIME); long millis = ChronoUnit.MILLIS.between(LocalTime.MIN, duree_localTime); - logger.info(HYPHEN_SEPARATOR); return millis; } @@ -431,23 +394,18 @@ public static String[] getCoordonneesXY(JsonNode nodeCoordonnesXY) { * @return a array of the precise X and Y coordinates of the agency as long. */ public static long[] getCoordonneesXYPrecises(JsonNode nodeCoordonnesXYPrecises) { - logger.info(HYPHEN_SEPARATOR); - if (nodeCoordonnesXYPrecises.isNull()) { logger.info("coordonneesXyPrecises null"); - logger.info(HYPHEN_SEPARATOR); return null; } else { String strCoordonneesXYPrecises = nodeCoordonnesXYPrecises.asText(); if ("".equals(strCoordonneesXYPrecises)) { logger.info("coordonneesXyPrecises vide"); - logger.info(HYPHEN_SEPARATOR); return null; } else { logger.info("coordonneesXyPrecises récupérées. conversion..."); String[] tStrCoordonneesXYPrecises = strCoordonneesXYPrecises.split(","); long[] tCoordonneesXYPrecises = {Long.parseLong(tStrCoordonneesXYPrecises[0]), Long.parseLong(tStrCoordonneesXYPrecises[1])}; - logger.info(HYPHEN_SEPARATOR); return tCoordonneesXYPrecises; } } diff --git a/src/test/java/com/github/adriens/opt/tempsattente/sdk/AgenceTest.java b/src/test/java/com/github/adriens/opt/tempsattente/sdk/AgenceTest.java index f6e2077..0184dc5 100644 --- a/src/test/java/com/github/adriens/opt/tempsattente/sdk/AgenceTest.java +++ b/src/test/java/com/github/adriens/opt/tempsattente/sdk/AgenceTest.java @@ -273,6 +273,123 @@ public void testGetAgenceBadID() { } } + /** + * Test of getCommune(testCommune) method, of class Agence. + */ + @Test + public void testGetSetCommune() { + String commune = "testCommune"; + + Agence agence = new Agence(); + agence.setCommune(commune); + + assertEquals(commune, agence.getCommune(), "Commune non modifiée."); + } + + /** + * Test of getType(testType) method, of class Agence. + */ + @Test + public void testGetSetType() { + String type = "testType"; + + Agence agence = new Agence(); + agence.setType(type); + + assertEquals(type, agence.getType(), "Type non modifiée."); + } + + /** + * Test of getCodeESirius(testCodeESirius) method, of class Agence. + */ + @Test + public void testGetSetCodeESirius() { + String codeESirius = "testCodeESirius"; + + Agence agence = new Agence(); + agence.setCodeESirius(codeESirius); + + assertEquals(codeESirius, agence.getCodeESirius(), "CodeESirius non modifiée."); + } + + /** + * Test of getCodePostale(testCodePostale) method, of class Agence. + */ + @Test + public void testGetSetCodePostal() { + String codePostal = "testCodePostal"; + + Agence agence = new Agence(); + agence.setCodePostal(codePostal); + + assertEquals(codePostal, agence.getCodePostal(), "CodePostal non modifiée."); + } + + /** + * Test of getlieuDitOuTribu(testLieuDitOuTribu) method, of class Agence. + */ + @Test + public void testGetSetLieuDitOuTribu() { + String lieuDitOuTribu = "testCodeESirius"; + + Agence agence = new Agence(); + agence.setLieuDitOuTribu(lieuDitOuTribu); + + assertEquals(lieuDitOuTribu, agence.getLieuDitOuTribu(), "LieuDitOuTribu non modifiée."); + } + + /** + * Test of getLocalite(testLocalite) method, of class Agence. + */ + @Test + public void testGetSetLocalite() { + String localite = "testLocalite"; + + Agence agence = new Agence(); + agence.setLocalite(localite); + + assertEquals(localite, agence.getLocalite(), "Localite non modifiée."); + } + + /** + * Test of getIdRefloc(testIdRefloc) method, of class Agence. + */ + @Test + public void testGetSetIdRefloc() { + String idRefloc = "testIdRefloc"; + + Agence agence = new Agence(); + agence.setIdRefloc(idRefloc); + + assertEquals(idRefloc, agence.getIdRefloc(), "IdRefloc non modifiée."); + } + + /** + * Test of getCodePostalRefloc(testCodePostalRefloc) method, of class Agence. + */ + @Test + public void testGetSetCodePostalRefloc() { + String codePostalRefloc = "testCodePostalRefloc"; + + Agence agence = new Agence(); + agence.setCodePostalRefloc(codePostalRefloc); + + assertEquals(codePostalRefloc, agence.getCodePostalRefloc(), "CodePostalRefloc non modifiée."); + } + + /** + * Test of getLocaliteRefloc(testLocaliteRefloc) method, of class Agence. + */ + @Test + public void testGetSetLocaliteRefloc() { + String localiteRefloc = "testCodePostalRefloc"; + + Agence agence = new Agence(); + agence.setLocaliteRefloc(localiteRefloc); + + assertEquals(localiteRefloc, agence.getLocaliteRefloc(), "LocaliteRefloc non modifiée."); + } + /** * Test of toString method, of class Agence. */ @@ -287,7 +404,25 @@ public void testToString() { double coordonneeY = 242663.05560000055; long coordonneeXPrecise = 422655; long coordonneeYPrecise = 242977; - Agence instance = new Agence(123456, "designationTEST", Agences.ConvertToMillis("00:00:52"), 422331.96350000054, 242663.05560000055, 422655, 242977, "", "", "", "", "", "", "", "", ""); + String commune = "communeTEST"; + String type = "typeTEST"; + String codeESirius = "codeESiriusTEST"; + String codePostal = "codePostalTEST"; + String lieuDitOuTribu = "lieuDitOuTribuTEST"; + String localite = "localiteTEST"; + String idRefloc = "idReflocTEST"; + String codePostalRefloc = "codePostalReflocTEST"; + String localiteRefloc = "localiteReflocTEST"; + Agence instance = new Agence( + 123456, + "designationTEST", + Agences.ConvertToMillis("00:00:52"), + 422331.96350000054, + 242663.05560000055, + 422655, + 242977, + commune, type, codeESirius, codePostal, lieuDitOuTribu, + localite, idRefloc, codePostalRefloc, localiteRefloc); String expResult = "Agence " + idAgence + " "; String result = instance.toString(); diff --git a/src/test/java/com/github/adriens/opt/tempsattente/sdk/AgencesTest.java b/src/test/java/com/github/adriens/opt/tempsattente/sdk/AgencesTest.java index 22038bb..686c7a6 100644 --- a/src/test/java/com/github/adriens/opt/tempsattente/sdk/AgencesTest.java +++ b/src/test/java/com/github/adriens/opt/tempsattente/sdk/AgencesTest.java @@ -6,7 +6,6 @@ package com.github.adriens.opt.tempsattente.sdk; import java.io.IOException; -import java.net.MalformedURLException; import java.net.URL; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; From 9f41eda7f8ea3cd72d5f71446aa58e95ba4011bc Mon Sep 17 00:00:00 2001 From: HakumenNC Date: Thu, 10 Dec 2020 09:21:50 +1100 Subject: [PATCH 3/3] build(pom): Upgrade version 1.9 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e8d6936..a667ecc 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.adriens.github.opt.tempsattente tempsattente-sdk - 1.9-SNAPSHOT + 1.9 jar UTF-8