From 26bc4ff90d5b906f9aa90b000a508675783ffd3e Mon Sep 17 00:00:00 2001 From: Emilie Genton Date: Fri, 15 Dec 2023 08:45:44 +0100 Subject: [PATCH] Prend en compte le SRID dans l'API Issue: #199341 Change-Id: I77705345f90ce9dba52c29568a23c204f5428729 --- .../sdis83/remocra/repository/IncomingRepository.java | 10 +++++----- .../remocra/repository/NumeroUtilRepository.java | 7 +++++-- .../fr/sdis83/remocra/repository/PeiRepository.java | 4 ++-- .../java/fr/sdis83/remocra/util/GlobalConstants.java | 5 ++++- .../java/fr/sdis83/remocra/web/s/OpenApiEndpoint.java | 10 ++++++++++ 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/api-remocra/api/src/main/java/fr/sdis83/remocra/repository/IncomingRepository.java b/api-remocra/api/src/main/java/fr/sdis83/remocra/repository/IncomingRepository.java index 6182f7fd7..85a47c738 100644 --- a/api-remocra/api/src/main/java/fr/sdis83/remocra/repository/IncomingRepository.java +++ b/api-remocra/api/src/main/java/fr/sdis83/remocra/repository/IncomingRepository.java @@ -10,8 +10,8 @@ import static fr.sdis83.remocra.db.model.incoming.Tables.TOURNEE; import static fr.sdis83.remocra.db.model.remocra.Tables.COMMUNE; import static fr.sdis83.remocra.db.model.remocra.Tables.VOIE; -import static fr.sdis83.remocra.util.GlobalConstants.SRID_2154; import static fr.sdis83.remocra.util.GlobalConstants.SRID_4326; +import static fr.sdis83.remocra.util.GlobalConstants.SRID_PARAM; import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.io.ParseException; @@ -70,7 +70,7 @@ public int insertPei( + "'), " + SRID_4326 + "), " - + SRID_2154 + + SRID_PARAM + ")")) .set(NEW_HYDRANT.CODE_NEW_HYDRANT, code) .set(NEW_HYDRANT.ID_COMMUNE, idCommune) @@ -97,7 +97,7 @@ public Geometry getGeometrieWithCoordonnnees(Double longitude, Double latitude) Geometry geometry = null; try { geometry = fromText.read(wkt); - geometry.setSRID(SRID_2154); + geometry.setSRID(SRID_PARAM); } catch (ParseException e) { throw new RuntimeException("Not a WKT string:" + wkt); } @@ -118,7 +118,7 @@ public Long getCommuneWithGeometrie(Geometry geometrie) { "ST_CONTAINS({0}, st_transform(st_setsrid(ST_GeomFromText({1}), " + SRID_4326 + "), " - + SRID_2154 + + SRID_PARAM + "))", COMMUNE.GEOMETRIE, geometrie.toText()) @@ -133,7 +133,7 @@ public String getVoie(Geometry geometrie) { "ST_CONTAINS({0}, st_transform(st_setsrid(ST_GeomFromText({1}), " + SRID_4326 + "), " - + SRID_2154 + + SRID_PARAM + "))", VOIE.GEOMETRIE, geometrie.toText()) diff --git a/api-remocra/api/src/main/java/fr/sdis83/remocra/repository/NumeroUtilRepository.java b/api-remocra/api/src/main/java/fr/sdis83/remocra/repository/NumeroUtilRepository.java index 4b9778e42..a89352c5c 100755 --- a/api-remocra/api/src/main/java/fr/sdis83/remocra/repository/NumeroUtilRepository.java +++ b/api-remocra/api/src/main/java/fr/sdis83/remocra/repository/NumeroUtilRepository.java @@ -5,6 +5,7 @@ import fr.sdis83.remocra.db.model.remocra.tables.pojos.Commune; import fr.sdis83.remocra.db.model.remocra.tables.pojos.Hydrant; import fr.sdis83.remocra.db.model.remocra.tables.pojos.ZoneSpeciale; +import fr.sdis83.remocra.util.GlobalConstants; import javax.inject.Inject; import org.apache.commons.lang3.ArrayUtils; import org.jooq.DSLContext; @@ -568,8 +569,10 @@ public static ZoneSpeciale computeZoneSpeciale(Hydrant hydrant) { .select(ZONE_SPECIALE.fields()) .from(ZONE_SPECIALE) .where( - "ST_Contains({0}, st_pointfromtext({1},2154))", - ZONE_SPECIALE.GEOMETRIE, hydrant.getGeometrie().toString()) + "ST_Contains({0}, st_pointfromtext({1},{2}))", + ZONE_SPECIALE.GEOMETRIE, + hydrant.getGeometrie().toString(), + GlobalConstants.SRID_PARAM) .limit(1) .fetchOneInto(ZoneSpeciale.class); } catch (Exception e) { diff --git a/api-remocra/api/src/main/java/fr/sdis83/remocra/repository/PeiRepository.java b/api-remocra/api/src/main/java/fr/sdis83/remocra/repository/PeiRepository.java index eb0b2103b..7b20a9de0 100644 --- a/api-remocra/api/src/main/java/fr/sdis83/remocra/repository/PeiRepository.java +++ b/api-remocra/api/src/main/java/fr/sdis83/remocra/repository/PeiRepository.java @@ -18,7 +18,7 @@ import static fr.sdis83.remocra.db.model.remocra.Tables.TYPE_HYDRANT_NIVEAU; import static fr.sdis83.remocra.db.model.remocra.Tables.TYPE_RESEAU_ALIMENTATION; import static fr.sdis83.remocra.db.model.remocra.Tables.TYPE_RESEAU_CANALISATION; -import static fr.sdis83.remocra.util.GlobalConstants.SRID_2154; +import static fr.sdis83.remocra.util.GlobalConstants.SRID_PARAM; import static fr.sdis83.remocra.util.GlobalConstants.TypeHydrant; import com.fasterxml.jackson.core.JsonProcessingException; @@ -519,7 +519,7 @@ public Long insertHydrant( "ST_setsrid(ST_GeomFromText(st_asText('" + geometry + "')), " - + SRID_2154 + + SRID_PARAM + ")")) .set(HYDRANT.ORGANISME, h.getOrganisme()) .set(HYDRANT.UTILISATEUR_MODIFICATION, h.getUtilisateurModification()) diff --git a/api-remocra/api/src/main/java/fr/sdis83/remocra/util/GlobalConstants.java b/api-remocra/api/src/main/java/fr/sdis83/remocra/util/GlobalConstants.java index 4da05dc91..d078e7e1c 100644 --- a/api-remocra/api/src/main/java/fr/sdis83/remocra/util/GlobalConstants.java +++ b/api-remocra/api/src/main/java/fr/sdis83/remocra/util/GlobalConstants.java @@ -87,7 +87,7 @@ public String getLibelle() { } } - public static final Integer SRID_2154 = 2154; + public static Integer SRID_PARAM = 2154; public static final Integer SRID_4326 = 4326; public static final String DOSSIER_DOC_HYDRANT = "DOSSIER_DOC_HYDRANT"; @@ -112,4 +112,7 @@ public String getTypeDocument() { public static final String PARAMETRE_CARACTERISTIQUE_PIBI = "CARACTERISTIQUE_PIBI"; public static final String PARAMETRE_CARACTERISTIQUE_PENA = "CARACTERISTIQUE_PENA"; + + // Clé du paramètre SRID stocké dans la table remocra.parametre + public static final String CLE_SRID = "SRID"; } diff --git a/api-remocra/api/src/main/java/fr/sdis83/remocra/web/s/OpenApiEndpoint.java b/api-remocra/api/src/main/java/fr/sdis83/remocra/web/s/OpenApiEndpoint.java index 1d0f4afa5..b3dd133ba 100644 --- a/api-remocra/api/src/main/java/fr/sdis83/remocra/web/s/OpenApiEndpoint.java +++ b/api-remocra/api/src/main/java/fr/sdis83/remocra/web/s/OpenApiEndpoint.java @@ -1,8 +1,11 @@ package fr.sdis83.remocra.web.s; +import fr.sdis83.remocra.repository.ParametreRepository; +import fr.sdis83.remocra.util.GlobalConstants; import io.swagger.v3.jaxrs2.integration.resources.BaseOpenApiResource; import io.swagger.v3.oas.annotations.Operation; import javax.annotation.security.PermitAll; +import javax.inject.Inject; import javax.servlet.ServletConfig; import javax.ws.rs.GET; import javax.ws.rs.Path; @@ -21,6 +24,8 @@ public class OpenApiEndpoint extends BaseOpenApiResource { @Context Application app; + @Inject ParametreRepository parametreRepository; + @GET @Path("openapi.{type:json|yaml}") @Produces({MediaType.APPLICATION_JSON, "application/yaml"}) @@ -29,6 +34,11 @@ public class OpenApiEndpoint extends BaseOpenApiResource { public Response getOpenApi( @Context HttpHeaders headers, @Context UriInfo uriInfo, @PathParam("type") String type) throws Exception { + // Au lancement de l'API on charge le SRID renseigné dans la base + GlobalConstants.SRID_PARAM = + Integer.valueOf( + parametreRepository.getParametre(GlobalConstants.CLE_SRID).getValeurParametre()); + return super.getOpenApi(headers, config, app, uriInfo, type); }