Skip to content

Commit

Permalink
Prend en compte le SRID dans l'API
Browse files Browse the repository at this point in the history
Issue: #199341
Change-Id: I77705345f90ce9dba52c29568a23c204f5428729
  • Loading branch information
Emilie Genton committed Jan 8, 2024
1 parent 61a5155 commit 26bc4ff
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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);
}
Expand All @@ -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())
Expand All @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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"})
Expand All @@ -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);
}

Expand Down

0 comments on commit 26bc4ff

Please sign in to comment.