Skip to content

Commit

Permalink
Fix: code Smell for IrisApi and new request for WS Pays
Browse files Browse the repository at this point in the history
  • Loading branch information
JeromeMBourgeois committed Feb 8, 2024
1 parent dbf9a9a commit 5edb099
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 28 deletions.
14 changes: 3 additions & 11 deletions src/main/java/fr/insee/rmes/api/geo/territoire/IrisApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,15 @@
public class IrisApi extends AbstractGeoApi {
private static final String CODE_PATTERN = "/{code:}";
private static final String LITTERAL_PARAMETER_TYPE_DESCRIPTION = "Filtre sur le type de territoire renvoyé.";
private static final String LITTERAL_PARAMETER_NAME_DESCRIPTION = "Filtre sur le nom des communes renvoyées" ;

private static final String LITTERAL_RESPONSE_DESCRIPTION = "Iris";
private static final String LITTERAL_ID_OPERATION = "getcogiris";
private static final String LITTERAL_CODE_EXAMPLE = "010040101";

private static final String LITTERAL_CODE_HISTORY_EXAMPLE = "010040101";
private static final String LITTERAL_PARAMETER_DATE_DESCRIPTION =
"Filtre pour renvoyer l'Iris active à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')";
private static final String LITTERAL_OPERATION_SUMMARY =
"Informations sur un Iris identifié par son code (neuf chiffres pour la métropole ou 2A/2B plus 7 chiffres pour la Corse)";

private static final String LITTERAL_DATE_EXAMPLE = "2020-01-01";

public IrisApi() {
// Constructeur par défaut
Expand Down Expand Up @@ -79,7 +75,6 @@ public Response getByCode(
@Parameter(hidden = true) @HeaderParam(HttpHeaders.ACCEPT) String header,
@Parameter(
description = LITTERAL_PARAMETER_DATE_DESCRIPTION,
required = false,
schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam(
value = Constants.PARAMETER_DATE) String date) {

Expand Down Expand Up @@ -128,12 +123,12 @@ else if (hasIrisDescendant) {
GeoQueries.getIrisByCodeAndDate(code, this.formatValidParameterDateIfIsNull(date))),
header,
territoire);
} else if (code.matches("^(?=.{9}$)(?!.*0000$).*$") && !hasIrisDescendant ) {
} else if (code.matches("^(?=.{9}$)(?!.*0000$).*$") ) {
return Response.status(Response.Status.NOT_FOUND).entity("").build();
} else {
territoire = new Commune(code);
try {
Response responseInitial = this.generateResponseATerritoireByCode(
this.generateResponseATerritoireByCode(
sparqlUtils.executeSparqlQuery(
GeoQueries.getIrisByCodeAndDate(code, this.formatValidParameterDateIfIsNull(date))),
header,
Expand Down Expand Up @@ -189,11 +184,10 @@ public Response getListe(
@Parameter(hidden = true) @HeaderParam(HttpHeaders.ACCEPT) String header,
@Parameter(
description = "Filtre pour renvoyer les Iris ou faux-Iris à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')" + LITTERAL_PARAMETER_DATE_WITH_HISTORY,
required = false,
schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam(
value = Constants.PARAMETER_DATE) String date,
@Parameter(description = "les Iris (et pseudo-iris) des collectivités d'outre-mer",
required = false,
required = true,
schema = @Schema(type = Constants.TYPE_BOOLEAN, allowableValues = {"true","false"},example="false", defaultValue = "false"))
@QueryParam(
value = Constants.PARAMETER_STRING) Boolean com
Expand Down Expand Up @@ -237,12 +231,10 @@ public Response getAscendants(
@Parameter(hidden = true) @HeaderParam(HttpHeaders.ACCEPT) String header,
@Parameter(
description = "Filtre pour renvoyer les territoires contenant l'iris actif à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')",
required = false,
schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam(
value = Constants.PARAMETER_DATE) String date,
@Parameter(
description = LITTERAL_PARAMETER_TYPE_DESCRIPTION,
required = false,
schema = @Schema(type = Constants.TYPE_STRING)) @QueryParam(
value = Constants.PARAMETER_TYPE) String typeTerritoire) {

Expand Down
29 changes: 12 additions & 17 deletions src/main/java/fr/insee/rmes/queries/geo/GeoQueries.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package fr.insee.rmes.queries.geo;

import fr.insee.rmes.config.Configuration;
import fr.insee.rmes.modeles.geo.EnumTypeGeographie;
import fr.insee.rmes.queries.Queries;
import fr.insee.rmes.utils.Constants;
Expand Down Expand Up @@ -497,22 +496,18 @@ private static Map<String, Object> buildCodeAndDateAndFilterParams(String code,
}

public static String getCountry(String code) {
return "SELECT ?uri ?intitule ?intituleEntier \n"
+ "FROM <http://rdf.insee.fr/graphes/geo/cog> \n"
+ "WHERE { \n"
+ "?uri rdf:type igeo:Etat . \n"
+ "?uri igeo:codeINSEE '"
+ code
+ "' . \n"
+ "?uri igeo:nom ?intitule . \n"
+ "?uri igeo:nomEntier ?intituleEntier . \n"
// Ensure that is not the dbpedia URI
+ "FILTER (REGEX(STR(?uri), '"
+ Configuration.getBaseHost()
+ "')) \n"
+ "FILTER (lang(?intitule) = 'fr') \n"
+ "FILTER (lang(?intituleEntier) = 'fr') \n"
+ "}";
return String.format(
"SELECT ?uri ?intitule ?intituleEntier ?code \n"
+ "FROM <http://rdf.insee.fr/graphes/geo/cog> \n"
+ "WHERE { \n"
+ " ?urilong a igeo:Pays ; \n"
+ " igeo:codeINSEE \"%s\" ; \n"
+ " igeo:nom ?intitule; \n"
+ " owl:sameAs ?uri; \n"
+ " igeo:nomLong ?intituleEntier . \n"
+ " BIND(\"%s\" AS ?code)\n"
+ " FILTER (REGEX(STR(?uri), \"http://id.insee.fr\")) \n"
+ "}", code, code);
}


Expand Down

0 comments on commit 5edb099

Please sign in to comment.