diff --git a/src/main/java/fr/insee/rmes/api/geo/AbstractGeoApi.java b/src/main/java/fr/insee/rmes/api/geo/AbstractGeoApi.java index aa780a8a..b592c5e8 100644 --- a/src/main/java/fr/insee/rmes/api/geo/AbstractGeoApi.java +++ b/src/main/java/fr/insee/rmes/api/geo/AbstractGeoApi.java @@ -80,6 +80,16 @@ protected boolean verifyParameterDateIsRightWithHistory(String date) { protected String formatValidParameterDateIfIsNull(String date) { return (date != null) ? date : DateUtils.getDateTodayStringFormat(); } + + protected String formatValidParameterFiltreIfIsNull(String filtreNom) { + return (filtreNom != null) ? filtreNom : "*"; + } + + protected Boolean formatValidParameterBooleanIfIsNull(Boolean bool) { + return (bool != null) ? bool : false; + } + + protected Response generateStatusResponse(boolean objectIsFound, Object o, String header) { if (objectIsFound) { diff --git a/src/main/java/fr/insee/rmes/api/geo/ConstGeoApi.java b/src/main/java/fr/insee/rmes/api/geo/ConstGeoApi.java index 88f5127a..25ebf7d6 100644 --- a/src/main/java/fr/insee/rmes/api/geo/ConstGeoApi.java +++ b/src/main/java/fr/insee/rmes/api/geo/ConstGeoApi.java @@ -19,6 +19,9 @@ public class ConstGeoApi { public static final String PATH_COMMUNE_ASSOCIEE = PATH_SEPARATOR + "communeAssociee"; public static final String PATH_COMMUNE_DELEGUEE = PATH_SEPARATOR + "communeDeleguee"; public static final String PATH_ARRONDISSEMENT_MUNICIPAL = PATH_SEPARATOR + "arrondissementMunicipal"; + public static final String PATH_COM= PATH_SEPARATOR + "collectiviteDOutreMer"; + public static final String PATH_DISTRICT= PATH_SEPARATOR + "district"; + public static final String PATH_LISTE_COM= PATH_SEPARATOR +"collectivitesDOutreMer"; public static final String PATH_LISTE_COMMUNE = PATH_SEPARATOR + "communes"; public static final String PATH_LISTE_PAYS = PATH_SEPARATOR + "pays"; @@ -31,7 +34,7 @@ public class ConstGeoApi { public static final String PATH_LISTE_ZONE_EMPLOI = PATH_SEPARATOR + "zonesDEmploi2020"; public static final String PATH_LISTE_AIRE_ATTRACTION = PATH_SEPARATOR + "airesDAttractionDesVilles2020"; public static final String PATH_LISTE_UNITE_URBAINE = PATH_SEPARATOR + "unitesUrbaines2020"; - + public static final String PATH_LISTE_DISTRICT = PATH_SEPARATOR + "districts"; public static final String PATH_ASCENDANT = PATH_SEPARATOR + "ascendants"; public static final String PATH_DESCENDANT = PATH_SEPARATOR + "descendants"; @@ -41,6 +44,8 @@ public class ConstGeoApi { public static final String PATTERN_COMMUNE = "[0-9][0-9AB][0-9]{3}"; + public static final String PATTERN_COM ="9[78][1-9]"; + public static final String PATTERN_DISTRICT ="9[78][1-9]{3}"; public static final String PATTERN_PAYS = "99[0-9]{3}"; public static final String PATTERN_REGION = "[0-9]{2}"; public static final String PATTERN_ZONE_EMPLOI = "[0-9]{4}"; @@ -51,8 +56,10 @@ public class ConstGeoApi { public static final String PATTERN_ARRONDISSEMENT_MUNICIPAL = ""; public static final String PATTERN_COMMUNE_DESCRIPTION = "Code de la commune (cinq caractères)"; + public static final String PATTERN_COM_DESCRIPTION= "Code de la collectivité d'outre-mer (trois caractères)"; public static final String PATTERN_COMMUNE_ASSOCIEE_DESCRIPTION = "Code de la commune associée (cinq caractères)"; public static final String PATTERN_COMMUNE_DELEGUEE_DESCRIPTION = "Code de la commune déléguée (cinq caractères)"; + public static final String PATTERN_DISTRICT_DESCRIPTION = "Code du district (cinq caractères)"; public static final String PATTERN_ZONE_EMPLOI_DESCRIPTION = "Code de la zone d'emploi (quatre chiffres)"; public static final String PATTERN_UNITE_URBAINE_DESCRIPTION = "Code de l'unité urbaine (cinq chiffres)"; public static final String PATTERN_AIRE_ATTRACTION_DESCRIPTION = "Code de l'aire d'attraction (trois chiffres)"; diff --git a/src/main/java/fr/insee/rmes/api/geo/territoire/AireAttractionApi.java b/src/main/java/fr/insee/rmes/api/geo/territoire/AireAttractionApi.java index 5dc186ff..fd65767d 100644 --- a/src/main/java/fr/insee/rmes/api/geo/territoire/AireAttractionApi.java +++ b/src/main/java/fr/insee/rmes/api/geo/territoire/AireAttractionApi.java @@ -108,7 +108,7 @@ public Response getDescendants( required = true, schema = @Schema( pattern = ConstGeoApi.PATTERN_AIRE_ATTRACTION, - type = Constants.TYPE_STRING, example="062")) @PathParam(Constants.CODE) String code, + type = Constants.TYPE_STRING, example="002")) @PathParam(Constants.CODE) String code, @Parameter(hidden = true) @HeaderParam(HttpHeaders.ACCEPT) String header, @Parameter( description = "Filtre pour renvoyer les territoires inclus dans l'aire d'attraction active à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')", diff --git a/src/main/java/fr/insee/rmes/api/geo/territoire/CollectivitesDOutreMerAPI.java b/src/main/java/fr/insee/rmes/api/geo/territoire/CollectivitesDOutreMerAPI.java new file mode 100644 index 00000000..011968a1 --- /dev/null +++ b/src/main/java/fr/insee/rmes/api/geo/territoire/CollectivitesDOutreMerAPI.java @@ -0,0 +1,188 @@ +package fr.insee.rmes.api.geo.territoire; + +import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import fr.insee.rmes.api.geo.AbstractGeoApi; +import fr.insee.rmes.api.geo.ConstGeoApi; +import fr.insee.rmes.modeles.geo.territoire.CollectiviteDOutreMer; +import fr.insee.rmes.modeles.geo.territoire.Commune; +import fr.insee.rmes.modeles.geo.territoire.Territoire; +import fr.insee.rmes.modeles.geo.territoires.CollectivitesDOutreMer; +import fr.insee.rmes.modeles.geo.territoires.Territoires; +import fr.insee.rmes.queries.geo.GeoQueries; +import fr.insee.rmes.utils.Constants; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.tags.Tag; + + + @Path(ConstGeoApi.PATH_GEO) + @Tag(name = ConstGeoApi.TAG_NAME, description = ConstGeoApi.TAG_DESCRIPTION) + + public class CollectivitesDOutreMerAPI extends AbstractGeoApi { + + + + private static Logger logger = LogManager.getLogger(CollectivitesDOutreMerAPI.class); + private static final String CODE_PATTERNCOM = "/{code: " + ConstGeoApi.PATTERN_COM + "}"; + private static final String LITTERAL_ID_OPERATION = "getcogcom"; + private static final String LITTERAL_OPERATION_SUMMARY = + "Informations sur une collectivité d'outre-mer identifiée par son code (cinq caractères)"; + private static final String LITTERAL_RESPONSE_DESCRIPTION = "collectivité d'outre-mer"; + private static final String LITTERAL_PARAMETER_DATE_DESCRIPTION = + "Filtre pour renvoyer la collectivite d'outre-mer active à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')"; + private static final String LITTERAL_PARAMETER_TYPE_DESCRIPTION = "Filtre sur le type de territoire renvoyé."; + private static final String LITTERAL_CODE_EXAMPLE = "986"; + + + + @Path(ConstGeoApi.PATH_LISTE_COM) + @GET + @Produces({ + MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML + }) + + @Operation( + operationId = LITTERAL_ID_OPERATION + ConstGeoApi.ID_OPERATION_LISTE, + summary = "Informations sur toutes les collectivités d'outre-mer actives à la date donnée. Par défaut, c’est la date courante.", + responses = { + @ApiResponse( + content = @Content(schema = @Schema(type = ARRAY, implementation = Commune.class)), + description = LITTERAL_RESPONSE_DESCRIPTION) + }) + + public Response getListe( + @Parameter(hidden = true) @HeaderParam(HttpHeaders.ACCEPT) String header, + @Parameter( + description = "Filtre pour renvoyer les collectivités d'outre-mer actives à 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) + + { + + logger.debug("Received GET request for all collectivités d'outre-mer"); + + if ( ! this.verifyParameterDateIsRightWithHistory(date)) { + return this.generateBadRequestResponse(); + } + else { + return this + .generateResponseListOfTerritoire( + sparqlUtils.executeSparqlQuery(GeoQueries.getListCollectivitesDOutreMer(this.formatValidParameterDateIfIsNull(date))), + header, + CollectivitesDOutreMer.class, + CollectiviteDOutreMer.class ); + } + } + + + @Path(ConstGeoApi.PATH_COM + CODE_PATTERNCOM) + @GET + @Produces({ + MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML + }) + @Operation( + operationId = LITTERAL_ID_OPERATION, + summary = LITTERAL_OPERATION_SUMMARY, + responses = { + @ApiResponse( + content = @Content(schema = @Schema(implementation = CollectiviteDOutreMer.class)), + description = LITTERAL_RESPONSE_DESCRIPTION) + }) + public Response getByCode( + @Parameter( + description = ConstGeoApi.PATTERN_COM_DESCRIPTION, + required = true, + schema = @Schema( + pattern = ConstGeoApi.PATTERN_COM, + type = Constants.TYPE_STRING, example=LITTERAL_CODE_EXAMPLE)) @PathParam(Constants.CODE) String code, + @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) { + + logger.debug("Received GET request for collectivite d'outre-mer {}", code); + + if ( ! this.verifyParameterDateIsRightWithoutHistory(date)) { + return this.generateBadRequestResponse(); + } + else { + return this + .generateResponseATerritoireByCode( + sparqlUtils + .executeSparqlQuery( + GeoQueries.getCollectiviteDOutreMerByCodeAndDate(code, this.formatValidParameterDateIfIsNull(date))), + header, + new CollectiviteDOutreMer(code)); + } + } + + + @Path(ConstGeoApi.PATH_COM + CODE_PATTERNCOM + ConstGeoApi.PATH_DESCENDANT) + @GET + @Produces({ + MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML + }) + @Operation( + operationId = LITTERAL_ID_OPERATION + ConstGeoApi.ID_OPERATION_DESCENDANTS, + summary = "Informations concernant les territoires inclus dans la collectivite d'outre-mer", + responses = { + @ApiResponse( + content = @Content(schema = @Schema(type = ARRAY, implementation = Territoire.class)), + description = LITTERAL_RESPONSE_DESCRIPTION) + }) + public Response getDescendants( + @Parameter( + description = "code de la collectivité d'outre-mer (3 caractères)", + required = true, + schema = @Schema( + pattern = ConstGeoApi.PATTERN_COM, + type = Constants.TYPE_STRING, example=LITTERAL_CODE_EXAMPLE)) @PathParam(Constants.CODE) String code, + @Parameter(hidden = true) @HeaderParam(HttpHeaders.ACCEPT) String header, + @Parameter( + description ="Filtre pour renvoyer les territoires inclus dans la collectivité d'outre-mer active à 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+ "(Commune ou District)", + required = false, + schema = @Schema(type = Constants.TYPE_STRING)) @QueryParam( + value = Constants.PARAMETER_TYPE) String typeTerritoire, + @Parameter( + description = "Filtre sur le nom du ou des territoires renvoyés", + required = false, + schema = @Schema(type = Constants.TYPE_STRING)) @QueryParam( + value = Constants.PARAMETER_FILTRE) String filtreNom) { + + logger.debug("Received GET request for descendants of collectivite d'outre-mer {}", code); + + if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, date)) { + return this.generateBadRequestResponse(); + } + else { + return this.generateResponseListOfTerritoire( + sparqlUtils.executeSparqlQuery(GeoQueries.getDescendantsCollectiviteDOutreMer(code, + this.formatValidParameterDateIfIsNull(date), + this.formatValidParametertypeTerritoireIfIsNull(typeTerritoire), + this.formatValidParameterFiltreIfIsNull(filtreNom))), + header, Territoires.class, Territoire.class); + } + } + + } diff --git a/src/main/java/fr/insee/rmes/api/geo/territoire/CommuneApi.java b/src/main/java/fr/insee/rmes/api/geo/territoire/CommuneApi.java index cf9f81de..687ed759 100644 --- a/src/main/java/fr/insee/rmes/api/geo/territoire/CommuneApi.java +++ b/src/main/java/fr/insee/rmes/api/geo/territoire/CommuneApi.java @@ -46,9 +46,9 @@ public class CommuneApi extends AbstractGeoApi { private static final String LITTERAL_PARAMETER_DATE_DESCRIPTION = "Filtre pour renvoyer la commune active à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')"; 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 de la commune" ; private static final String LITTERAL_CODE_EXAMPLE = "14475"; - + private static final String LITTERAL_PARAMETER_COM_DESCRIPTION="Sélectionner \"true\" pour inclure les collectivités d’outre-mer"; @Path(ConstGeoApi.PATH_COMMUNE + CODE_PATTERN) @GET @@ -112,7 +112,7 @@ public Response getAscendants( required = true, schema = @Schema( pattern = ConstGeoApi.PATTERN_COMMUNE, - type = Constants.TYPE_STRING, example=LITTERAL_CODE_EXAMPLE)) @PathParam(Constants.CODE) String code, + type = Constants.TYPE_STRING, example="73035")) @PathParam(Constants.CODE) String code, @Parameter(hidden = true) @HeaderParam(HttpHeaders.ACCEPT) String header, @Parameter( description = "Filtre pour renvoyer les territoires contenant la commune active à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')", @@ -218,7 +218,19 @@ public Response getListe( description = "Filtre pour renvoyer les communes actives à 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) { + value = Constants.PARAMETER_DATE) String date, + @Parameter( + description = LITTERAL_PARAMETER_NAME_DESCRIPTION, + required = false, + schema = @Schema(type = Constants.TYPE_STRING, example="Bonnay")) @QueryParam( + value = Constants.PARAMETER_FILTRE) String filtreNom, + @Parameter(description = LITTERAL_PARAMETER_COM_DESCRIPTION, + required = false, + schema = @Schema(type = Constants.TYPE_BOOLEAN, allowableValues = {"true","false"},example="false", defaultValue = "false")) + @QueryParam( + value = Constants.PARAMETER_STRING) Boolean com + ) + { logger.debug("Received GET request for all communes"); @@ -229,7 +241,7 @@ public Response getListe( return this .generateResponseListOfTerritoire( sparqlUtils - .executeSparqlQuery(GeoQueries.getListCommunes(this.formatValidParameterDateIfIsNull(date))), + .executeSparqlQuery(GeoQueries.getListCommunes(this.formatValidParameterDateIfIsNull(date), this.formatValidParameterFiltreIfIsNull(filtreNom),this.formatValidParameterBooleanIfIsNull(com))), header, Communes.class, Commune.class); diff --git a/src/main/java/fr/insee/rmes/api/geo/territoire/DepartementApi.java b/src/main/java/fr/insee/rmes/api/geo/territoire/DepartementApi.java index 7dd4ba01..44e8ea6e 100644 --- a/src/main/java/fr/insee/rmes/api/geo/territoire/DepartementApi.java +++ b/src/main/java/fr/insee/rmes/api/geo/territoire/DepartementApi.java @@ -42,7 +42,7 @@ public class DepartementApi extends AbstractGeoApi { "Informations sur un departement identifié par son code (deux ou trois caractères)"; private static final String LITTERAL_RESPONSE_DESCRIPTION = "Departement"; 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 territoires renvoyés" ; private static final String LITTERAL_CODE_EXAMPLE = "22"; private static final String LITTERAL_DATE_EXAMPLE = "1950-01-01"; @@ -170,7 +170,12 @@ public Response getDescendants( description = LITTERAL_PARAMETER_TYPE_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING)) @QueryParam( - value = Constants.PARAMETER_TYPE) String typeTerritoire) { + value = Constants.PARAMETER_TYPE) String typeTerritoire, + @Parameter( + description = LITTERAL_PARAMETER_NAME_DESCRIPTION, + required = false, + schema = @Schema(type = Constants.TYPE_STRING)) @QueryParam( + value = Constants.PARAMETER_FILTRE) String filtreNom) { logger.debug("Received GET request for descendants of departement {}", code); @@ -186,7 +191,7 @@ public Response getDescendants( .getDescendantsDepartement( code, this.formatValidParameterDateIfIsNull(date), - this.formatValidParametertypeTerritoireIfIsNull(typeTerritoire))), + this.formatValidParametertypeTerritoireIfIsNull(typeTerritoire),this.formatValidParameterFiltreIfIsNull(filtreNom))), header, Territoires.class, Territoire.class); diff --git a/src/main/java/fr/insee/rmes/api/geo/territoire/DistrictApi.java b/src/main/java/fr/insee/rmes/api/geo/territoire/DistrictApi.java new file mode 100644 index 00000000..66b3b665 --- /dev/null +++ b/src/main/java/fr/insee/rmes/api/geo/territoire/DistrictApi.java @@ -0,0 +1,142 @@ +package fr.insee.rmes.api.geo.territoire; + +import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import fr.insee.rmes.api.geo.AbstractGeoApi; +import fr.insee.rmes.api.geo.ConstGeoApi; +import fr.insee.rmes.modeles.geo.territoire.District; +import fr.insee.rmes.modeles.geo.territoire.Territoire; +import fr.insee.rmes.modeles.geo.territoires.Territoires; +import fr.insee.rmes.queries.geo.GeoQueries; +import fr.insee.rmes.utils.Constants; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.tags.Tag; + + + @Path(ConstGeoApi.PATH_GEO) + @Tag(name = ConstGeoApi.TAG_NAME, description = ConstGeoApi.TAG_DESCRIPTION) + + + +public class DistrictApi extends AbstractGeoApi { + + private static Logger logger = LogManager.getLogger(DistrictApi.class); + private static final String CODE_PATTERNDISTRICT = "/{code: " + ConstGeoApi.PATTERN_DISTRICT + "}"; + private static final String LITTERAL_ID_OPERATION = "getcogdistrict"; + private static final String LITTERAL_OPERATION_SUMMARY = + "Informations sur un district identifiée par son code (cinq caractères)"; + private static final String LITTERAL_RESPONSE_DESCRIPTION = "district d'une collectivité d'outre-mer"; + private static final String LITTERAL_PARAMETER_DATE_DESCRIPTION = + "Filtre pour renvoyer le district actif à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')"; + private static final String LITTERAL_PARAMETER_TYPE_DESCRIPTION = "Filtre sur le type de territoire renvoyé."; + private static final String LITTERAL_CODE_EXAMPLE = "98411"; + + @Path(ConstGeoApi.PATH_DISTRICT + CODE_PATTERNDISTRICT) + @GET + @Produces({ + MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML + }) + @Operation( + operationId = LITTERAL_ID_OPERATION, + summary = LITTERAL_OPERATION_SUMMARY, + responses = { + @ApiResponse( + content = @Content(schema = @Schema(implementation = District.class)), + description = LITTERAL_RESPONSE_DESCRIPTION) + }) + public Response getByCode( + @Parameter( + description = ConstGeoApi.PATTERN_DISTRICT_DESCRIPTION, + required = true, + schema = @Schema( + pattern = ConstGeoApi.PATTERN_DISTRICT, + type = Constants.TYPE_STRING, example=LITTERAL_CODE_EXAMPLE)) @PathParam(Constants.CODE) String code, + @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) { + + logger.debug("Received GET request for collectivite d'outre-mer {}", code); + + if ( ! this.verifyParameterDateIsRightWithoutHistory(date)) { + return this.generateBadRequestResponse(); + } + else { + return this + .generateResponseATerritoireByCode( + sparqlUtils + .executeSparqlQuery( + GeoQueries.getDistrictByCodeAndDate(code, this.formatValidParameterDateIfIsNull(date))), + header, + new District(code)); + } + } + + @Path(ConstGeoApi.PATH_DISTRICT + CODE_PATTERNDISTRICT + ConstGeoApi.PATH_ASCENDANT) + @GET + @Produces({ + MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML + }) + @Operation( + operationId = LITTERAL_ID_OPERATION + ConstGeoApi.ID_OPERATION_ASCENDANTS, + summary = "Informations concernant les territoires qui contiennent le district", + responses = { + @ApiResponse( + content = @Content(schema = @Schema(type = ARRAY, implementation = Territoire.class)), + description = LITTERAL_RESPONSE_DESCRIPTION) + }) + public Response getAscendants( + @Parameter( + description = ConstGeoApi.PATTERN_DISTRICT_DESCRIPTION, + required = true, + schema = @Schema( + pattern = ConstGeoApi.PATTERN_DISTRICT, + type = Constants.TYPE_STRING, example="98411")) @PathParam(Constants.CODE) String code, + @Parameter(hidden = true) @HeaderParam(HttpHeaders.ACCEPT) String header, + @Parameter( + description = "Filtre pour renvoyer les territoires contenant le district 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) { + + logger.debug("Received GET request for ascendants of district {}", code); + + if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, date)) { + return this.generateBadRequestResponse(); + } + else { + return this + .generateResponseListOfTerritoire( + sparqlUtils + .executeSparqlQuery( + GeoQueries + .getAscendantsDistrict( + code, + this.formatValidParameterDateIfIsNull(date), + this.formatValidParametertypeTerritoireIfIsNull(typeTerritoire))), + header, + Territoires.class, + Territoire.class); + } + } +} diff --git a/src/main/java/fr/insee/rmes/api/geo/territoire/RegionApi.java b/src/main/java/fr/insee/rmes/api/geo/territoire/RegionApi.java index b1f6acfd..580e2615 100644 --- a/src/main/java/fr/insee/rmes/api/geo/territoire/RegionApi.java +++ b/src/main/java/fr/insee/rmes/api/geo/territoire/RegionApi.java @@ -44,7 +44,7 @@ public class RegionApi extends AbstractGeoApi { private static final String LITTERAL_PARAMETER_DATE_DESCRIPTION = "Filtre pour renvoyer la region active à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')"; 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 territoires renvoyés" ; private static final String LITTERAL_CODE_EXAMPLE = "06"; private static final String LITTERAL_CODE_HISTORY_EXAMPLE = "44"; @@ -120,7 +120,12 @@ public Response getDescendants( description = LITTERAL_PARAMETER_TYPE_DESCRIPTION, required = false, schema = @Schema(type = Constants.TYPE_STRING)) @QueryParam( - value = Constants.PARAMETER_TYPE) String typeTerritoire) { + value = Constants.PARAMETER_TYPE) String typeTerritoire, + @Parameter( + description = LITTERAL_PARAMETER_NAME_DESCRIPTION, + required = false, + schema = @Schema(type = Constants.TYPE_STRING)) @QueryParam( + value = Constants.PARAMETER_FILTRE) String filtreNom) { logger.debug("Received GET request for descendants of region {}", code); @@ -136,7 +141,7 @@ public Response getDescendants( .getDescendantsRegion( code, this.formatValidParameterDateIfIsNull(date), - this.formatValidParametertypeTerritoireIfIsNull(typeTerritoire))), + this.formatValidParametertypeTerritoireIfIsNull(typeTerritoire),this.formatValidParameterFiltreIfIsNull(filtreNom))), header, Territoires.class, Territoire.class); diff --git a/src/main/java/fr/insee/rmes/modeles/geo/EnumTypeGeographie.java b/src/main/java/fr/insee/rmes/modeles/geo/EnumTypeGeographie.java index cf7905ac..4985ca58 100644 --- a/src/main/java/fr/insee/rmes/modeles/geo/EnumTypeGeographie.java +++ b/src/main/java/fr/insee/rmes/modeles/geo/EnumTypeGeographie.java @@ -7,10 +7,12 @@ import fr.insee.rmes.modeles.geo.territoire.Arrondissement; import fr.insee.rmes.modeles.geo.territoire.ArrondissementMunicipal; import fr.insee.rmes.modeles.geo.territoire.Canton; +import fr.insee.rmes.modeles.geo.territoire.CollectiviteDOutreMer; import fr.insee.rmes.modeles.geo.territoire.Commune; import fr.insee.rmes.modeles.geo.territoire.CommuneAssociee; import fr.insee.rmes.modeles.geo.territoire.CommuneDeleguee; import fr.insee.rmes.modeles.geo.territoire.Departement; +import fr.insee.rmes.modeles.geo.territoire.District; import fr.insee.rmes.modeles.geo.territoire.Region; import fr.insee.rmes.modeles.geo.territoire.Territoire; import fr.insee.rmes.modeles.geo.territoire.UniteUrbaine; @@ -19,10 +21,12 @@ import fr.insee.rmes.modeles.geo.territoires.Arrondissements; import fr.insee.rmes.modeles.geo.territoires.ArrondissementsMunicipaux; import fr.insee.rmes.modeles.geo.territoires.Cantons; +import fr.insee.rmes.modeles.geo.territoires.CollectivitesDOutreMer; import fr.insee.rmes.modeles.geo.territoires.Communes; import fr.insee.rmes.modeles.geo.territoires.CommunesAssociees; import fr.insee.rmes.modeles.geo.territoires.CommunesDeleguees; import fr.insee.rmes.modeles.geo.territoires.Departements; +import fr.insee.rmes.modeles.geo.territoires.Districts; import fr.insee.rmes.modeles.geo.territoires.Regions; import fr.insee.rmes.modeles.geo.territoires.Territoires; import fr.insee.rmes.modeles.geo.territoires.UnitesUrbaines; @@ -36,13 +40,14 @@ public enum EnumTypeGeographie { DEPARTEMENT("Departement", Departement.class,Departements.class, "prefecture"), ARRONDISSEMENT("Arrondissement", Arrondissement.class,Arrondissements.class, "sousPrefecture"), CANTON("Canton", Canton.class,Cantons.class,Constants.NONE), + COLLECTIVITE_D_OUTRE_MER("CollectiviteDOutreMer", CollectiviteDOutreMer.class,CollectivitesDOutreMer.class, Constants.NONE), COMMUNE_DELEGUEE("CommuneDeleguee", CommuneDeleguee.class,CommunesDeleguees.class,Constants.NONE), COMMUNE_ASSOCIEE("CommuneAssociee", CommuneAssociee.class,CommunesAssociees.class,Constants.NONE), ARRONDISSEMENT_MUNICIPAL("ArrondissementMunicipal",ArrondissementMunicipal.class,ArrondissementsMunicipaux.class, Constants.NONE), ZONE_EMPLOI("ZoneDEmploi2020", ZoneEmploi.class,ZonesEmploi.class,Constants.NONE), AIRE_ATTRACTION("AireDAttractionDesVilles2020",AireAttraction.class,AiresAttraction.class,Constants.NONE), - UNITE_URBAINE("UniteUrbaine2020", UniteUrbaine.class,UnitesUrbaines.class,Constants.NONE); - + UNITE_URBAINE("UniteUrbaine2020", UniteUrbaine.class,UnitesUrbaines.class,Constants.NONE), + DISTRICT("District",District.class,Districts.class,Constants.NONE); private String typeObjetGeo; private Class classNameOfGeoType; diff --git a/src/main/java/fr/insee/rmes/modeles/geo/territoire/CollectiviteDOutreMer.java b/src/main/java/fr/insee/rmes/modeles/geo/territoire/CollectiviteDOutreMer.java new file mode 100644 index 00000000..ce4c3497 --- /dev/null +++ b/src/main/java/fr/insee/rmes/modeles/geo/territoire/CollectiviteDOutreMer.java @@ -0,0 +1,93 @@ +package fr.insee.rmes.modeles.geo.territoire; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; + +import fr.insee.rmes.modeles.geo.EnumTypeGeographie; +import fr.insee.rmes.modeles.geo.IntituleSansArticle; +import io.swagger.v3.oas.annotations.media.Schema; + +@XmlRootElement(name = "CollectiviteDOutreMER") +@JacksonXmlRootElement(localName = "CollectiviteDOutreMer") +@XmlAccessorType(XmlAccessType.FIELD) +@Schema(description = "Objet représentant une collectivite d'outre-mer") + +public class CollectiviteDOutreMer extends Territoire { + + // No-args constructor needed for JAXB + public CollectiviteDOutreMer() { + this.type = EnumTypeGeographie.COLLECTIVITE_D_OUTRE_MER.getTypeObjetGeo(); + this.intituleSansArticle = new IntituleSansArticle(); + } + + public CollectiviteDOutreMer(String code) { + this.type = EnumTypeGeographie.COLLECTIVITE_D_OUTRE_MER.getTypeObjetGeo(); + this.code = code; + this.intituleSansArticle = new IntituleSansArticle(); + } + + public CollectiviteDOutreMer( + String code, + String uri, + String intitule, + String type, + String dateCreation, + String dateSuppression, + IntituleSansArticle intituleSansArticle, + String chefLieu) { + super(code, uri, intitule, type, dateCreation, dateSuppression, intituleSansArticle, chefLieu); + } + + @Override + @JacksonXmlProperty(isAttribute = true) + @Schema(example = "98735") + public String getCode() { + return code; + } + + @Override + @JacksonXmlProperty(isAttribute = true) + @Schema(example = "http://id.insee.fr/geo/commune/98735") + public String getUri() { + return uri; + } + + @Override + @JacksonXmlProperty(localName = "Intitule") + @JsonProperty(value = "intitule") + @Schema(example = "Papeete") + public String getIntitule() { + return intitule; + } + + @Override + @JacksonXmlProperty(localName = "Type") + @Schema(example = "Commune") + public String getType() { + return type; + } + + @Override + @JacksonXmlProperty(localName = "DateCreation") + @Schema( + description = "Date de création de la commune/district si il/elle n’existait pas au premier COG du 1er janvier 1943", + example = "1943-01-01") + public String getDateCreation() { + return dateCreation; + } + + @Override + @JacksonXmlProperty(localName = "DateSuppression") + @Schema(description = "Date de suppression de la commune/district si il/elle a été supprimé(e). ", example = "2019-01-01") + public String getDateSuppression() { + return dateSuppression; + } + + + +} diff --git a/src/main/java/fr/insee/rmes/modeles/geo/territoire/District.java b/src/main/java/fr/insee/rmes/modeles/geo/territoire/District.java new file mode 100644 index 00000000..d889fe11 --- /dev/null +++ b/src/main/java/fr/insee/rmes/modeles/geo/territoire/District.java @@ -0,0 +1,93 @@ +package fr.insee.rmes.modeles.geo.territoire; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; + +import fr.insee.rmes.modeles.geo.EnumTypeGeographie; +import fr.insee.rmes.modeles.geo.IntituleSansArticle; +import io.swagger.v3.oas.annotations.media.Schema; + +@XmlRootElement(name = "District") +@JacksonXmlRootElement(localName = "District") +@XmlAccessorType(XmlAccessType.FIELD) +@Schema(description = "Objet représentant un district") +public class District extends Territoire { + + // No-args constructor needed for JAXB + public District() { + this.type = EnumTypeGeographie.DISTRICT.getTypeObjetGeo(); + this.intituleSansArticle = new IntituleSansArticle(); + } + + public District(String code) { + this.type = EnumTypeGeographie.DISTRICT.getTypeObjetGeo(); + this.code = code; + this.intituleSansArticle = new IntituleSansArticle(); + } + + public District( + String code, + String uri, + String intitule, + String type, + String dateCreation, + String dateSuppression, + IntituleSansArticle intituleSansArticle, + String typeArticle) { + super(code, uri, intitule, type, dateCreation, dateSuppression, intituleSansArticle); + this.setTypeArticle(typeArticle); + } + + @Override + @JacksonXmlProperty(isAttribute = true) + @Schema(example = "98412") + public String getCode() { + return code; + } + + @Override + @JacksonXmlProperty(isAttribute = true) + @Schema(example = "http://id.insee.fr/geo/district/78c18c16-2d63-486d-9ff0-e36e76a95718") /*to do changer adresse */ + public String getUri() { + return uri; + } + + @Override + @JacksonXmlProperty(localName = "Intitule") + @JsonProperty(value = "intitule") + @Schema(example = "Archipel des Kerguelen") + public String getIntitule() { + return intitule; + } + + @Override + @JacksonXmlProperty(localName = "Type") + @Schema(example = "District") + public String getType() { + return type; + } + + @Override + @JacksonXmlProperty(localName = "DateCreation") + @Schema( + description = "Date de création du district s'il n’existait pas au premier COG du 1er janvier 1943", + example = "1943-01-01") + public String getDateCreation() { + return dateCreation; + } + + @Override + @JacksonXmlProperty(localName = "DateSuppression") + @Schema(description = "Date de suppression du district s'il a été supprimée. ", example = "2019-01-01") + public String getDateSuppression() { + return dateSuppression; + } + + + +} diff --git a/src/main/java/fr/insee/rmes/modeles/geo/territoires/CollectivitesDOutreMer.java b/src/main/java/fr/insee/rmes/modeles/geo/territoires/CollectivitesDOutreMer.java new file mode 100644 index 00000000..af76055b --- /dev/null +++ b/src/main/java/fr/insee/rmes/modeles/geo/territoires/CollectivitesDOutreMer.java @@ -0,0 +1,45 @@ +package fr.insee.rmes.modeles.geo.territoires; + + +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; + +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; + +import fr.insee.rmes.modeles.geo.territoire.CollectiviteDOutreMer; +import io.swagger.v3.oas.annotations.media.Schema; + +@JacksonXmlRootElement(localName = "CollectivitesDOutreMer") +@XmlAccessorType(XmlAccessType.FIELD) +@Schema(name = "CollectivitesDOutreMer", description = "Tableau représentant les collectivites d'outre-mer") + +public class CollectivitesDOutreMer extends Territoires{ + + private List collectivitesDOutreMer = null; + + public CollectivitesDOutreMer() {} + + public CollectivitesDOutreMer(List collectivitesDOutreMer) { + this.collectivitesDOutreMer = collectivitesDOutreMer; + } + + @JacksonXmlProperty(isAttribute = true, localName = "collectiviteDOutreMer") + @JacksonXmlElementWrapper(useWrapping = false) + public List getCollectivitesDOutreMer() { + return collectivitesDOutreMer; + } + + public void setCommunes(List collectivitesDOutreMer) { + this.collectivitesDOutreMer = collectivitesDOutreMer; + } + +} + + + + + diff --git a/src/main/java/fr/insee/rmes/modeles/geo/territoires/Districts.java b/src/main/java/fr/insee/rmes/modeles/geo/territoires/Districts.java new file mode 100644 index 00000000..7707782a --- /dev/null +++ b/src/main/java/fr/insee/rmes/modeles/geo/territoires/Districts.java @@ -0,0 +1,40 @@ +package fr.insee.rmes.modeles.geo.territoires; + + +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; + +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; + +import fr.insee.rmes.modeles.geo.territoire.District; +import io.swagger.v3.oas.annotations.media.Schema; + +@JacksonXmlRootElement(localName = "Districts") +@XmlAccessorType(XmlAccessType.FIELD) +@Schema(name = "Districts", description = "Tableau représentant les districts") + +public class Districts extends Territoires { + + private List districts = null; + + public Districts() {} + + public Districts(List districts) { + this.districts = districts; + } + + @JacksonXmlProperty(isAttribute = true, localName = "District") + @JacksonXmlElementWrapper(useWrapping = false) + public List getDistricts() { + return districts; + } + + public void setDistricts(List districts) { + this.districts = districts; + } + +} diff --git a/src/main/java/fr/insee/rmes/queries/geo/GeoQueries.java b/src/main/java/fr/insee/rmes/queries/geo/GeoQueries.java index c1d64895..60f04ab1 100644 --- a/src/main/java/fr/insee/rmes/queries/geo/GeoQueries.java +++ b/src/main/java/fr/insee/rmes/queries/geo/GeoQueries.java @@ -18,6 +18,10 @@ public class GeoQueries extends Queries { private static final String TYPE_ORIGINE = "typeOrigine"; private static final String PREVIOUS = "previous"; private static final String QUERIES_FOLDER = "geographie/"; + private static final String FILTRE = "filtreNom"; + private static final String COM = "com"; + + /* IDENTIFICATION */ public static String getZoneEmploiByCodeAndDate(String code, String date) { @@ -35,11 +39,19 @@ public static String getAireAttractionByCodeAndDate(String code, String date) { public static String getCommuneByCodeAndDate(String code, String date) { return getTerritoire(code, date, EnumTypeGeographie.COMMUNE); } + + public static String getCollectiviteDOutreMerByCodeAndDate(String code,String date) { + return getTerritoireFiltre(code, date,"*", EnumTypeGeographie.COLLECTIVITE_D_OUTRE_MER,true); + } public static String getDepartementByCodeAndDate(String code, String date) { return getTerritoire(code, date, EnumTypeGeographie.DEPARTEMENT); } - + + public static String getDistrictByCodeAndDate(String code,String date) { + return getTerritoireFiltre(code, date,"*",EnumTypeGeographie.DISTRICT,true); + } + public static String getRegionByCodeAndDate(String code, String date) { return getTerritoire(code, date, EnumTypeGeographie.REGION); } @@ -61,10 +73,14 @@ public static String getArrondissementmunicipalByCodeAndDate(String code, String } /* LIST */ - public static String getListCommunes(String date) { - return getTerritoire(Constants.NONE, date, EnumTypeGeographie.COMMUNE); - } + public static String getListCommunes(String date,String filtreNom,boolean com) { + return getTerritoireFiltre(Constants.NONE, date,filtreNom, EnumTypeGeographie.COMMUNE,com); + } + public static String getListCollectivitesDOutreMer(String date) { + return getTerritoire(Constants.NONE, date, EnumTypeGeographie.COLLECTIVITE_D_OUTRE_MER); + } + public static String getListDepartements(String date) { return getTerritoire(Constants.NONE, date, EnumTypeGeographie.DEPARTEMENT); } @@ -103,56 +119,64 @@ public static String getListCommunesDeleguees(String date) { /* ASCENDANT */ public static String getAscendantsCommune(String code, String date, String type) { - return getAscendantOrDescendantsQuery(code, date, type, EnumTypeGeographie.COMMUNE, true); + return getAscendantOrDescendantsQuery(code, date, type, EnumTypeGeographie.COMMUNE,Constants.ABSENT,Constants.NONE, true); } public static String getAscendantsDepartement(String code, String date, String type) { - return getAscendantOrDescendantsQuery(code, date, type, EnumTypeGeographie.DEPARTEMENT, true); + return getAscendantOrDescendantsQuery(code, date, type, EnumTypeGeographie.DEPARTEMENT,Constants.ABSENT,Constants.NONE, true); + } + + public static String getAscendantsDistrict(String code, String date, String type) { + return getAscendantOrDescendantsQuery(code, date, type, EnumTypeGeographie.DISTRICT,Constants.ABSENT,Constants.NONE,true); } public static String getAscendantsCommuneDeleguee(String code, String date, String type) { - return getAscendantOrDescendantsQuery(code, date, type, EnumTypeGeographie.COMMUNE_DELEGUEE, true); + return getAscendantOrDescendantsQuery(code, date, type, EnumTypeGeographie.COMMUNE_DELEGUEE,Constants.ABSENT,Constants.NONE, true); } public static String getAscendantsCommuneAssociee(String code, String date, String type) { - return getAscendantOrDescendantsQuery(code, date, type, EnumTypeGeographie.COMMUNE_ASSOCIEE, true); + return getAscendantOrDescendantsQuery(code, date, type, EnumTypeGeographie.COMMUNE_ASSOCIEE,Constants.ABSENT,Constants.NONE, true); } public static String getAscendantsArrondissementMunicipal(String code, String date, String type) { - return getAscendantOrDescendantsQuery(code, date, type, EnumTypeGeographie.ARRONDISSEMENT_MUNICIPAL, true); + return getAscendantOrDescendantsQuery(code, date, type, EnumTypeGeographie.ARRONDISSEMENT_MUNICIPAL,Constants.ABSENT,Constants.NONE, true); } public static String getAscendantsArrondissement(String code, String date, String type) { - return getAscendantOrDescendantsQuery(code, date, type, EnumTypeGeographie.ARRONDISSEMENT, true); + return getAscendantOrDescendantsQuery(code, date, type, EnumTypeGeographie.ARRONDISSEMENT,Constants.ABSENT,Constants.NONE, true); } /* DESCENDANT */ public static String getDescendantsCommune(String code, String date, String type) { - return getAscendantOrDescendantsQuery(code, date, type, EnumTypeGeographie.COMMUNE, false); + return getAscendantOrDescendantsQuery(code, date, type, EnumTypeGeographie.COMMUNE,Constants.ABSENT,Constants.NONE, false); + } + + public static String getDescendantsCollectiviteDOutreMer(String code, String date, String type,String filtreNom) { + return getAscendantOrDescendantsQuery(code, date, type, EnumTypeGeographie.COLLECTIVITE_D_OUTRE_MER, filtreNom,Constants.NONE,false); } public static String getDescendantsZoneEmploi(String code, String date, String type) { - return getAscendantOrDescendantsQuery(code, date, type, EnumTypeGeographie.ZONE_EMPLOI, false); + return getAscendantOrDescendantsQuery(code, date, type, EnumTypeGeographie.ZONE_EMPLOI,Constants.ABSENT,Constants.NONE, false); } public static String getDescendantsAireAttraction(String code, String date, String type) { - return getAscendantOrDescendantsQuery(code, date, type, EnumTypeGeographie.AIRE_ATTRACTION, false); + return getAscendantOrDescendantsQuery(code, date, type, EnumTypeGeographie.AIRE_ATTRACTION,Constants.ABSENT,Constants.NONE, false); } public static String getDescendantsUniteUrbaine(String code, String date, String type) { - return getAscendantOrDescendantsQuery(code, date, type, EnumTypeGeographie.UNITE_URBAINE, false); + return getAscendantOrDescendantsQuery(code, date, type, EnumTypeGeographie.UNITE_URBAINE,Constants.ABSENT,Constants.NONE, false); } - public static String getDescendantsDepartement(String code, String date, String type) { - return getAscendantOrDescendantsQuery(code, date, type, EnumTypeGeographie.DEPARTEMENT, false); + public static String getDescendantsDepartement(String code, String date, String type,String filtreNom) { + return getAscendantOrDescendantsQuery(code, date, type, EnumTypeGeographie.DEPARTEMENT,filtreNom,Constants.NONE, false); } - public static String getDescendantsRegion(String code, String date, String type) { - return getAscendantOrDescendantsQuery(code, date, type, EnumTypeGeographie.REGION, false); + public static String getDescendantsRegion(String code, String date, String type,String filtreNom) { + return getAscendantOrDescendantsQuery(code, date, type, EnumTypeGeographie.REGION,filtreNom,Constants.NONE, false); } public static String getDescendantsArrondissement(String code, String date, String type) { - return getAscendantOrDescendantsQuery(code, date, type, EnumTypeGeographie.ARRONDISSEMENT, false); + return getAscendantOrDescendantsQuery(code, date, type, EnumTypeGeographie.ARRONDISSEMENT, Constants.ABSENT,Constants.NONE,false); } // NEXT @@ -267,17 +291,29 @@ private static String getAllProjectionQuery( return buildRequest(QUERIES_FOLDER, "getAllProjectionByTypeDate.ftlh", params); } + + private static String getAscendantOrDescendantsQuery( String code, String date, String type, EnumTypeGeographie typeOrigine, + String filtreNom, + String com, boolean ascendant) { Map params = buildCodeAndDateParams(code, date); params.put(TYPE, type); params.put(TYPE_ORIGINE, typeOrigine.getTypeObjetGeo()); + params.put(FILTRE, filtreNom); + params.put(COM,com); params.put(ASCENDANT, String.valueOf(ascendant)); +// +// if (EnumTypeGeographie.DISTRICT.equals(typeOrigine)) { +// return buildRequest(QUERIES_FOLDER, "getAscendantsOrDescendantsByCodeTypeDateDistrict.ftlh", params); +// } +// else { return buildRequest(QUERIES_FOLDER, "getAscendantsOrDescendantsByCodeTypeDate.ftlh", params); + // } } private static String getPreviousOrNextQuery( @@ -292,10 +328,7 @@ private static String getPreviousOrNextQuery( } private static String getTerritoire(String code, String date, EnumTypeGeographie typeGeo) { - Map params = buildCodeAndDateParams(code, date); - params.put("territoire", typeGeo.getTypeObjetGeo()); - params.put("chefLieu", typeGeo.getChefLieuPredicate()); - return buildRequest(QUERIES_FOLDER, "getTerritoireByCodeAndDate.ftlh", params); + return getTerritoireFiltre(code,date,Constants.ABSENT,typeGeo,false); } private static Map buildCodeAndDateParams(String code, String date) { @@ -304,6 +337,27 @@ private static Map buildCodeAndDateParams(String code, String da params.put(DATE, date); return params; } + + + private static String getTerritoireFiltre(String code, String date, String filtreNom, EnumTypeGeographie typeGeo,boolean com) { + Map params = buildCodeAndDateAndFilterParams(code, date, filtreNom,com); + params.put("territoire", typeGeo.getTypeObjetGeo()); + params.put("chefLieu", typeGeo.getChefLieuPredicate()); +// if (EnumTypeGeographie.DISTRICT.equals(typeGeo)) { +// return buildRequest(QUERIES_FOLDER, "getTerritoireByCodeAndDateDistrict.ftlh", params); +// } else { + return buildRequest(QUERIES_FOLDER, "getTerritoireByCodeDateNomcommune.ftlh", params); + // } + } + + private static Map buildCodeAndDateAndFilterParams(String code, String date, String filtreNom, boolean com) { + Map params = new HashMap<>(); + params.put(CODE, code); + params.put(DATE, date); + params.put(FILTRE, filtreNom); + params.put(COM, String.valueOf(com)); + return params; + } public static String getCountry(String code) { return "SELECT ?uri ?intitule ?intituleEntier \n" diff --git a/src/main/java/fr/insee/rmes/utils/Constants.java b/src/main/java/fr/insee/rmes/utils/Constants.java index 49eb9811..d517bc32 100644 --- a/src/main/java/fr/insee/rmes/utils/Constants.java +++ b/src/main/java/fr/insee/rmes/utils/Constants.java @@ -5,10 +5,14 @@ public class Constants { public static final String NONE = "none"; public static final String TYPE_STRING = "string"; public static final String CODE = "code"; + public static final String TYPE_BOOLEAN = "boolean"; public static final String FORMAT_DATE = "date"; public static final String PARAMETER_DATE = "date"; public static final String PARAMETER_DATE_PROJECTION = "dateProjection"; public static final String PARAMETER_TYPE = "type"; + public static final String PARAMETER_FILTRE="filtreNom"; + public static final String PARAMETER_STRING="com"; + public static final String ABSENT="*"; private Constants() {} } diff --git a/src/main/resources/request/geographie/getAscendantsOrDescendantsByCodeTypeDate.ftlh b/src/main/resources/request/geographie/getAscendantsOrDescendantsByCodeTypeDate.ftlh index 5f4c01a0..0c926632 100644 --- a/src/main/resources/request/geographie/getAscendantsOrDescendantsByCodeTypeDate.ftlh +++ b/src/main/resources/request/geographie/getAscendantsOrDescendantsByCodeTypeDate.ftlh @@ -43,6 +43,18 @@ FROM ?evenementSuppression igeo:suppression ?uri ; igeo:date ?dateSuppression. } +<#if filtreNom !='*'> + BIND('${filtreNom}' AS ?query). + # Formattage du nom avec article pour comparaison non polluée par majuscules et accents + BIND (REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(LCASE(?intitule), "[àáâãäåaaa]", "a"), "ç", "c"), "[èééêë]", "e"), "[ìíîïì]", "i"), "[óôõö]", "o"), "[ùúûü]", "u"), "ÿ", "y"), "[œ]", "oe"), "[-_\']", " "), "[^a-z0-9() ]", ""), "[ ]{2,}", " ") AS ?formattedNom) . + # Formattage du nom sans article pour comparaison non polluée par majuscules et accents + BIND (REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(LCASE(?intituleSansArticle), "[àáâãäåaaa]", "a"), "ç", "c"), "[èééêë]", "e"), "[ìíîïì]", "i"), "[óôõö]", "o"), "[ùúûü]", "u"), "ÿ", "y"), "[œ]", "oe"), "[-_']", " "), "[^a-z0-9() ]", ""), "[ ]{2,}", " ") AS ?formattedNomSansArticle) . + # Formattage de la chaîne utilisateur pour comparaison non polluée par majuscules et accents (avec recodage saint/sainte et sur/sous). Ajout d’un ^ au début pour chercher les nom qui commencent par la chaîne utilisateur + BIND (CONCAT("^", REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(LCASE(?query), "[àáâãäåaaa]", "a"), "ç", "c"), "[èééêë]", "e"), "[ìíîïì]", "i"), "[óôõö]", "o"), "[ùúûü]", "u"), "ÿ", "y"), "[œ]", "oe"), "([^/]+)[/]", "$1-sur-"),"([^\\\\]+)[\\\\]", "$1-sous-"), "[-_']", " "),"[^a-z0-9() ]", ""), "[ ]{2,}", " "), "^st(e)? ", "saint$1 "), "") AS ?formattedQuery) . + # Filtrage par comparaison de la chaîne utilisateur formatée avec le nom formaté avec et sans article + FILTER (REGEX(?formattedNom, ?formattedQuery) || REGEX(?formattedNomSansArticle, ?formattedQuery)) + ## Fin du filtre sur le libellé ## + FILTER(!BOUND(?dateCreation) || ?dateCreation <= '${date}'^^xsd:date) FILTER(!BOUND(?dateSuppression) || ?dateSuppression > '${date}'^^xsd:date) diff --git a/src/main/resources/request/geographie/getAscendantsOrDescendantsByCodeTypeDateCOM.ftlh b/src/main/resources/request/geographie/getAscendantsOrDescendantsByCodeTypeDateCOM.ftlh new file mode 100644 index 00000000..ce6f9185 --- /dev/null +++ b/src/main/resources/request/geographie/getAscendantsOrDescendantsByCodeTypeDateCOM.ftlh @@ -0,0 +1,46 @@ +SELECT ?uri ?code ?type ?typeArticle ?intitule ?intituleSansArticle ?dateCreation ?dateSuppression ?chefLieu +WHERE { + { + SELECT DISTINCT ?uri ?type ?code ?typeArticle ?intitule ?intituleSansArticle?cheflieu ?dateCreation ?dateSuppression ?dateCreationParent ?dateSuppressionParent + WHERE { + ?parent a igeo:${typeOrigine} ; + igeo:codeINSEE '${code}' ; + (^igeo:subdivisionDirecteDe)+ ?ressource . + ?ressource a ?typeRDF; +<#if type != 'none'> + a igeo:${type}; + + igeo:codeINSEE ?code ; + igeo:codeArticle ?typeArticle ; + igeo:nom ?intitule ; + igeo:nomSansArticle ?intituleSansArticle . + BIND(?typeRDF AS ?type). + FILTER(STR(?type) in("http://rdf.insee.fr/def/geo#Commune" , "http://rdf.insee.fr/def/geo#District") ) + BIND(STR(?ressource) AS ?uri). + OPTIONAL {?ressource ((igeo:sousPrefecture|igeo:prefecture|igeo:prefectureDeRegion)/igeo:codeINSEE) ?cheflieu.} + OPTIONAL {?parent (^igeo:creation/igeo:date) ?dateCreationParent.} + OPTIONAL {?parent (^igeo:suppression/igeo:date) ?dateSuppressionParent.} + OPTIONAL {?ressource (^igeo:creation/igeo:date) ?dateCreation.} + OPTIONAL {?ressource (^igeo:suppression/igeo:date) ?dateSuppression.} +<#if filtreNom !='*'> + # ## Début du filtre sur le libellé ## + # La chaîne utilisateur dans une variable query + BIND('${filtreNom}' AS ?query). + # Formattage du nom avec article pour comparaison non polluée par majuscules et accents + BIND (REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(LCASE(?intitule), "[àáâãäåaaa]", "a"), "ç", "c"), "[èééêë]", "e"), "[ìíîïì]", "i"), "[óôõö]", "o"), "[ùúûü]", "u"), "ÿ", "y"), "[œ]", "oe"), "[-_\']", " "), "[^a-z0-9() ]", ""), "[ ]{2,}", " ") AS ?formattedNom) . + # Formattage du nom sans article pour comparaison non polluée par majuscules et accents + BIND (REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(LCASE(?intituleSansArticle), "[àáâãäåaaa]", "a"), "ç", "c"), "[èééêë]", "e"), "[ìíîïì]", "i"), "[óôõö]", "o"), "[ùúûü]", "u"), "ÿ", "y"), "[œ]", "oe"), "[-_']", " "), "[^a-z0-9() ]", ""), "[ ]{2,}", " ") AS ?formattedNomSansArticle) . + # Formattage de la chaîne utilisateur pour comparaison non polluée par majuscules et accents (avec recodage saint/sainte et sur/sous). Ajout d’un ^ au début pour chercher les nom qui commencent par la chaîne utilisateur + BIND (CONCAT("^", REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(LCASE(?query), "[àáâãäåaaa]", "a"), "ç", "c"), "[èééêë]", "e"), "[ìíîïì]", "i"), "[óôõö]", "o"), "[ùúûü]", "u"), "ÿ", "y"), "[œ]", "oe"), "([^/]+)[/]", "$1-sur-"),"([^\\\\]+)[\\\\]", "$1-sous-"), "[-_']", " "),"[^a-z0-9() ]", ""), "[ ]{2,}", " "), "^st(e)? ", "saint$1 "), "") AS ?formattedQuery) . + # Filtrage par comparaison de la chaîne utilisateur formatée avec le nom formaté avec et sans article + FILTER (REGEX(?formattedNom, ?formattedQuery) || REGEX(?formattedNomSansArticle, ?formattedQuery)) + ## Fin du filtre sur le libellé ## + + } + } + FILTER(!BOUND(?dateCreationParent) || ?dateCreationParent <= '${date}'^^xsd:date) + FILTER(!BOUND(?dateSuppressionParent) || ?dateSuppressionParent > '${date}'^^xsd:date) + FILTER(!BOUND(?dateCreation) || ?dateCreation <= '${date}'^^xsd:date) + FILTER(!BOUND(?dateSuppression) || ?dateSuppression > '${date}'^^xsd:date) +} +ORDER BY ?type ?code \ No newline at end of file diff --git a/src/main/resources/request/geographie/getAscendantsOrDescendantsByCodeTypeDateDistrict.ftlh b/src/main/resources/request/geographie/getAscendantsOrDescendantsByCodeTypeDateDistrict.ftlh new file mode 100644 index 00000000..9be5faf7 --- /dev/null +++ b/src/main/resources/request/geographie/getAscendantsOrDescendantsByCodeTypeDateDistrict.ftlh @@ -0,0 +1,30 @@ +SELECT ?uri ?code ?type ?typeArticle ?intitule ?intituleSansArticle ?dateCreation ?dateSuppression ?chefLieu +WHERE { + { + SELECT DISTINCT ?uri ?type ?code ?typeArticle ?intitule ?intituleSansArticle?cheflieu ?dateCreation ?dateSuppression ?dateCreationParent ?dateSuppressionParent + WHERE { + ?parent a igeo:District ; + igeo:codeINSEE '${code}' . + + ?ressource a ?typeRDF; + igeo:codeINSEE ?code ; + igeo:codeArticle ?typeArticle ; + igeo:nom ?intitule ; + igeo:nomSansArticle ?intituleSansArticle . + BIND(?typeRDF AS ?type). + FILTER(STR(?type) in("http://rdf.insee.fr/def/geo#CollectiviteDOutreMer") ) + FILTER(?code in(substr('${code}',1,3))) + BIND(STR(?ressource) AS ?uri). + OPTIONAL {?ressource ((igeo:sousPrefecture|igeo:prefecture|igeo:prefectureDeRegion)/igeo:codeINSEE) ?cheflieu.} + OPTIONAL {?parent (^igeo:creation/igeo:date) ?dateCreationParent.} + OPTIONAL {?parent (^igeo:suppression/igeo:date) ?dateSuppressionParent.} + OPTIONAL {?ressource (^igeo:creation/igeo:date) ?dateCreation.} + OPTIONAL {?ressource (^igeo:suppression/igeo:date) ?dateSuppression.} + } + } + FILTER(!BOUND(?dateCreationParent) || ?dateCreationParent <= '2022-01-20'^^xsd:date) + FILTER(!BOUND(?dateSuppressionParent) || ?dateSuppressionParent > '2022-01-20'^^xsd:date) + FILTER(!BOUND(?dateCreation) || ?dateCreation <= '2022-01-20'^^xsd:date) + FILTER(!BOUND(?dateSuppression) || ?dateSuppression > '2022-01-20'^^xsd:date) +} +ORDER BY ?type ?code \ No newline at end of file diff --git a/src/main/resources/request/geographie/getTerritoireByCodeAndDateDistrict.ftlh b/src/main/resources/request/geographie/getTerritoireByCodeAndDateDistrict.ftlh new file mode 100644 index 00000000..8262b94e --- /dev/null +++ b/src/main/resources/request/geographie/getTerritoireByCodeAndDateDistrict.ftlh @@ -0,0 +1,34 @@ +SELECT ?uri ?type ?code ?typeArticle ?intitule ?intituleSansArticle ?cheflieu ?dateCreation ?dateSuppression + +WHERE { + BIND(substr('${code}',1,3) as ?com). + { + SELECT DISTINCT ?uri ?type ?code ?typeArticle ?intitule ?intituleSansArticle ?cheflieu ?dateCreation ?dateSuppression ?dateCreationParent ?dateSuppressionParent + + WHERE { + + ?parent a igeo:CollectiviteDOutreMer ; + igeo:codeINSEE ?com ; + (^igeo:subdivisionDirecteDe)+ ?ressource . + ?ressource a ?typeRDF; + igeo:codeINSEE '${code}' ; + igeo:codeArticle ?typeArticle ; + igeo:nom ?intitule ; + igeo:nomSansArticle ?intituleSansArticle . + BIND(?typeRDF AS ?type). + BIND('${code}' as ?code) . + FILTER(STR(?type) in("http://rdf.insee.fr/def/geo#District") ) + BIND(STR(?ressource) AS ?uri). + OPTIONAL {?ressource ((igeo:sousPrefecture|igeo:prefecture|igeo:prefectureDeRegion)/igeo:codeINSEE) ?cheflieu.} + OPTIONAL {?parent (^igeo:creation/igeo:date) ?dateCreationParent.} + OPTIONAL {?parent (^igeo:suppression/igeo:date) ?dateSuppressionParent.} + OPTIONAL {?ressource (^igeo:creation/igeo:date) ?dateCreation.} + OPTIONAL {?ressource (^igeo:suppression/igeo:date) ?dateSuppression.} + } + } + FILTER(!BOUND(?dateCreationParent) || ?dateCreationParent <= '2022-01-12'^^xsd:date) + FILTER(!BOUND(?dateSuppressionParent) || ?dateSuppressionParent > '2022-01-12'^^xsd:date) + FILTER(!BOUND(?dateCreation) || ?dateCreation <= '2022-01-12'^^xsd:date) + FILTER(!BOUND(?dateSuppression) || ?dateSuppression > '2022-01-12'^^xsd:date) +} +ORDER BY ?type ?code \ No newline at end of file diff --git a/src/main/resources/request/geographie/getTerritoireByCodeDateNomcommune.ftlh b/src/main/resources/request/geographie/getTerritoireByCodeDateNomcommune.ftlh new file mode 100644 index 00000000..4c0fc948 --- /dev/null +++ b/src/main/resources/request/geographie/getTerritoireByCodeDateNomcommune.ftlh @@ -0,0 +1,66 @@ +SELECT DISTINCT ?uri ?code ?typeArticle ?intitule ?intituleSansArticle ?dateCreation ?dateSuppression ?chefLieu +FROM + WHERE { + + ?uri a igeo:${territoire} ; + igeo:codeArticle ?typeArticle ; + igeo:nom ?intitule ; + igeo:nomSansArticle ?intituleSansArticle . + +<#if com != "true"> + ?uri (igeo:subdivisionDirecteDe)+ . + + +<#if code != "none"> + ?uri igeo:codeINSEE '${code}' . + BIND('${code}' as ?code) +<#else> + ?uri igeo:codeINSEE ?code . + + + OPTIONAL { + ?evenementCreation igeo:creation ?uri ; + igeo:date ?dateCreation . + } + OPTIONAL { + ?evenementSuppression igeo:suppression ?uri ; + igeo:date ?dateSuppression. + } + +<#if chefLieu != "none"> + OPTIONAL { + ?uri igeo:${chefLieu} ?chefLieuRDF . + ?chefLieuRDF igeo:codeINSEE ?chefLieu. + OPTIONAL { + ?evenementCreationChefLieu igeo:creation ?chefLieuRDF ; + igeo:date ?dateCreationChefLieu . + } + OPTIONAL { + ?evenementSuppressionChefLieu igeo:suppression ?chefLieuRDF ; + igeo:date ?dateSuppressionChefLieu. + } + + <#if date != "*"> + FILTER(!BOUND(?dateCreationChefLieu) || ?dateCreationChefLieu <= '${date}'^^xsd:date) + FILTER(!BOUND(?dateSuppressionChefLieu) || ?dateSuppressionChefLieu > '${date}'^^xsd:date) + + + } + +<#if filtreNom != "*"> + BIND( '${filtreNom}' AS ?query). + BIND (REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(LCASE(?intitule), "[àáâãäåaaa]", "a"), "ç", "c"), "[èééêë]", "e"), "[ìíîïì]", "i"), "[óôõö]", "o"), "[ùúûü]", "u"), "ÿ", "y"), "[œ]", "oe"), "[-_\']", " "), "[^a-z0-9() ]", ""), "[ ]{2,}", " ") AS ?formattedNom) . + BIND (REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(LCASE(?intituleSansArticle), "[àáâãäåaaa]", "a"), "ç", "c"), "[èééêë]", "e"), "[ìíîïì]", "i"), "[óôõö]", "o"), "[ùúûü]", "u"), "ÿ", "y"), "[œ]", "oe"), "[-_']", " "), "[^a-z0-9() ]", ""), "[ ]{2,}", " ") AS ?formattedNomSansArticle) . + BIND (CONCAT("^", REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(LCASE(?query), "[àáâãäåaaa]", "a"), "ç", "c"), "[èééêë]", "e"), "[ìíîïì]", "i"), "[óôõö]", "o"), "[ùúûü]", "u"), "ÿ", "y"), "[œ]", "oe"), "([^/]+)[/]", "$1-sur-"),"([^\\\\]+)[\\\\]", "$1-sous-"), "[-_']", " "),"[^a-z0-9() ]", ""), "[ ]{2,}", " "), "^st(e)? ", "saint$1 "), "") AS ?formattedQuery) . + FILTER (REGEX(?formattedNom, ?formattedQuery) || REGEX(?formattedNomSansArticle, ?formattedQuery)) + + +<#if date != "*"> + FILTER(!BOUND(?dateCreation) || ?dateCreation <= '${date}'^^xsd:date) + FILTER(!BOUND(?dateSuppression) || ?dateSuppression > '${date}'^^xsd:date) + + + + } + ORDER BY ?code + \ No newline at end of file diff --git a/src/main/resources/rmes-api.properties b/src/main/resources/rmes-api.properties index 1fb14bc3..484a8c65 100644 --- a/src/main/resources/rmes-api.properties +++ b/src/main/resources/rmes-api.properties @@ -3,12 +3,13 @@ fr.insee.rmes.api.log.configuration = log4j2.xml # database # fr.insee.rmes.api.sparqlEndpoint = http://dvrmessnczlht01.ad.insee.intra/sparql -fr.insee.rmes.api.sparqlEndpoint = http://qfrmessnczlht01.ad.insee.intra/sparql -fr.insee.rmes.api.baseHost = http://id.insee.fr +#fr.insee.rmes.api.sparqlEndpoint = http://qfrmessnczlht01.ad.insee.intra/sparql +fr.insee.rmes.api.sparqlEndpoint = http://localhost:7200/repositories/geographie +fr.insee.rmes.api.baseHost = http://localhost:7200/ # files storage # physical place -fr.insee.rmes.api.storage.document = C:/temp/metadata-api +fr.insee.rmes.api.storage.document = C:/Temp/metadata-api # just the short name after physical place for documents fr.insee.rmes.api.fileStorage = /storage/documents/ diff --git a/src/test/java/fr/insee/rmes/api/geo/pseudointegrationtest/CommuneApiIntegrationTest.java b/src/test/java/fr/insee/rmes/api/geo/pseudointegrationtest/CommuneApiIntegrationTest.java index 714ab561..eb0e8eb7 100644 --- a/src/test/java/fr/insee/rmes/api/geo/pseudointegrationtest/CommuneApiIntegrationTest.java +++ b/src/test/java/fr/insee/rmes/api/geo/pseudointegrationtest/CommuneApiIntegrationTest.java @@ -55,7 +55,7 @@ public void givengetCommune_whenCorrectRequest_With_XML_Header_thenResponseIsOk( public void givengetListeCommunes_whenCorrectRequest_With_JSON_Header_thenResponseIsOk() { when(mockSparqlUtils.executeSparqlQuery(anyString())) .thenReturn(ConstantForIntegration.COMMUNE_MOCK_SERVER_RETURN_LISTE); - Response response = geoApi.getListe(MediaType.APPLICATION_JSON, null); + Response response = geoApi.getListe(MediaType.APPLICATION_JSON, null,"*", null); assertEquals(Status.OK.getStatusCode(), response.getStatus()); assertEquals(ConstantForIntegration.COMMUNE_EXPECTED_RESPONSE_LISTE_TOP_JSON, response.getEntity()); } @@ -64,7 +64,7 @@ public void givengetListeCommunes_whenCorrectRequest_With_JSON_Header_thenRespon public void givengetListeCommunes_whenCorrectRequest_With_XML_Header_thenResponseIsOk() { when(mockSparqlUtils.executeSparqlQuery(anyString())) .thenReturn(ConstantForIntegration.COMMUNE_MOCK_SERVER_RETURN_LISTE); - Response response = geoApi.getListe(MediaType.APPLICATION_XML, null); + Response response = geoApi.getListe(MediaType.APPLICATION_XML, null,null, null); assertEquals(Status.OK.getStatusCode(), response.getStatus()); assertEquals(ConstantForIntegration.COMMUNE_EXPECTED_RESPONSE_LISTE_TOP_XML, response.getEntity()); } diff --git a/src/test/java/fr/insee/rmes/api/geo/pseudointegrationtest/DepartementApiIntegrationTest.java b/src/test/java/fr/insee/rmes/api/geo/pseudointegrationtest/DepartementApiIntegrationTest.java index 736f1465..cd683ceb 100644 --- a/src/test/java/fr/insee/rmes/api/geo/pseudointegrationtest/DepartementApiIntegrationTest.java +++ b/src/test/java/fr/insee/rmes/api/geo/pseudointegrationtest/DepartementApiIntegrationTest.java @@ -86,20 +86,20 @@ public void givengetAscendantsDepartements_whenCorrectRequest_With_XML_Header_th assertEquals(ConstantForIntegration.DEPARTEMENT_EXPECTED_RESPONSE_ASCENDANTS_XML, response.getEntity()); } - @Test + @Test /*modifier suite a changement du nombre de variables */ public void givengetDescendantsDepartements_whenCorrectRequest_With_JSON_Header_thenResponseIsOk() { when(mockSparqlUtils.executeSparqlQuery(anyString())) .thenReturn(ConstantForIntegration.DEPARTEMENT_MOCK_SERVER_RETURN_DESCENDANTS); - Response response = geoApi.getDescendants(CODE, MediaType.APPLICATION_JSON, null, null); + Response response = geoApi.getDescendants(CODE, MediaType.APPLICATION_JSON, null, null, null); assertEquals(Status.OK.getStatusCode(), response.getStatus()); assertEquals(ConstantForIntegration.DEPARTEMENT_EXPECTED_RESPONSE_DESCENDANTS_JSON, response.getEntity()); } - @Test + @Test /*modifier suite a changement du nombre de variables */ public void givengetDescendantsDepartements_whenCorrectRequest_With_XML_Header_thenResponseIsOk() { when(mockSparqlUtils.executeSparqlQuery(anyString())) .thenReturn(ConstantForIntegration.DEPARTEMENT_MOCK_SERVER_RETURN_DESCENDANTS); - Response response = geoApi.getDescendants(CODE, MediaType.APPLICATION_XML, null, null); + Response response = geoApi.getDescendants(CODE, MediaType.APPLICATION_XML, null, null, null); assertEquals(Status.OK.getStatusCode(), response.getStatus()); assertEquals(ConstantForIntegration.DEPARTEMENT_EXPECTED_RESPONSE_DESCENDANTS_XML, response.getEntity()); } diff --git a/src/test/java/fr/insee/rmes/api/geo/pseudointegrationtest/RegionApiIntegrationTest.java b/src/test/java/fr/insee/rmes/api/geo/pseudointegrationtest/RegionApiIntegrationTest.java index d1809400..393c5462 100644 --- a/src/test/java/fr/insee/rmes/api/geo/pseudointegrationtest/RegionApiIntegrationTest.java +++ b/src/test/java/fr/insee/rmes/api/geo/pseudointegrationtest/RegionApiIntegrationTest.java @@ -71,7 +71,7 @@ public void givengetListeRegions_whenCorrectRequest_With_XML_Header_thenResponse public void givengetDescendantsRegions_whenCorrectRequest_With_JSON_Header_thenResponseIsOk() { when(mockSparqlUtils.executeSparqlQuery(anyString())) .thenReturn(ConstantForIntegration.REGION_MOCK_SERVER_RETURN_DESCENDANTS); - Response response = geoApi.getDescendants(CODE, MediaType.APPLICATION_JSON, null, null); + Response response = geoApi.getDescendants(CODE, MediaType.APPLICATION_JSON, null, null, null); assertEquals(Status.OK.getStatusCode(), response.getStatus()); assertEquals(ConstantForIntegration.REGION_EXPECTED_RESPONSE_DESCENDANTS_JSON, response.getEntity()); } @@ -80,7 +80,7 @@ public void givengetDescendantsRegions_whenCorrectRequest_With_JSON_Header_thenR public void givengetDescendantsRegions_whenCorrectRequest_With_XML_Header_thenResponseIsOk() { when(mockSparqlUtils.executeSparqlQuery(anyString())) .thenReturn(ConstantForIntegration.REGION_MOCK_SERVER_RETURN_DESCENDANTS); - Response response = geoApi.getDescendants(CODE, MediaType.APPLICATION_XML, null, null); + Response response = geoApi.getDescendants(CODE, MediaType.APPLICATION_XML, null, null, null); assertEquals(Status.OK.getStatusCode(), response.getStatus()); assertEquals(ConstantForIntegration.REGION_EXPECTED_RESPONSE_DESCENDANTS_XML, response.getEntity()); } diff --git a/src/test/java/fr/insee/rmes/api/geo/territoire/CommuneApiTest.java b/src/test/java/fr/insee/rmes/api/geo/territoire/CommuneApiTest.java index 0ec62554..73777f1e 100644 --- a/src/test/java/fr/insee/rmes/api/geo/territoire/CommuneApiTest.java +++ b/src/test/java/fr/insee/rmes/api/geo/territoire/CommuneApiTest.java @@ -287,7 +287,7 @@ void givenGetCommuneDescendants_WhenCorrectRequest_thenParameterTypeIsBad() { Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } - @Test + @Test void givenGetListeCommune_whenCorrectRequest_andHeaderContentIsJson_thenResponseIsOk() { // Mock @@ -295,11 +295,11 @@ void givenGetListeCommune_whenCorrectRequest_andHeaderContentIsJson_thenResponse list.add(new Commune()); // Call method - geoApi.getListe(MediaType.APPLICATION_JSON, null); + geoApi.getListe(MediaType.APPLICATION_JSON, null, null, null); /*modifier suite a changement du nombre de variables */ verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } - @Test + @Test void givenGetListeCommune_whenCorrectRequest_andHeaderContentIsXml_thenResponseIsOk() { // Mock @@ -307,7 +307,7 @@ void givenGetListeCommune_whenCorrectRequest_andHeaderContentIsXml_thenResponseI list.add(new Commune()); // Call method - geoApi.getListe(MediaType.APPLICATION_XML, null); + geoApi.getListe(MediaType.APPLICATION_XML, null, null, null); /*modifier suite a changement du nombre de variables */ verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -318,11 +318,11 @@ void givenGetListeCommune_WhenCorrectRequest_thenResponseIsNotFound() { this.mockUtilsMethodsThenReturnListOfPojo(Boolean.FALSE); // Call method header content = xml - Response response = geoApi.getListe(MediaType.APPLICATION_XML, null); + Response response = geoApi.getListe(MediaType.APPLICATION_XML, null, null, null);/*modifier suite a changement du nombre de variables */ Assertions.assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus()); // Call method header content = json - response = geoApi.getListe(MediaType.APPLICATION_JSON, null); + response = geoApi.getListe(MediaType.APPLICATION_JSON, null, null, null);/*modifier suite a changement du nombre de variables */ Assertions.assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus()); verify(mockResponseUtils, never()).produceResponse(Mockito.any(), Mockito.any()); @@ -338,7 +338,7 @@ void givenGetListeCommune_WhenCorrectRequest_thenParameterDateIsRight(String dat list.add(new Commune()); // Call method header content = xml - geoApi.getListe(MediaType.APPLICATION_XML, date); + geoApi.getListe(MediaType.APPLICATION_XML, date, date, Boolean.TRUE);/*modifier suite a changement du nombre de variables */ verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -346,7 +346,7 @@ void givenGetListeCommune_WhenCorrectRequest_thenParameterDateIsRight(String dat void givenGetListeCommune_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getListe(MediaType.APPLICATION_XML, "nimportequoi"); + Response response = geoApi.getListe(MediaType.APPLICATION_XML, "nimportequoi", null, null);/*modifier suite a changement du nombre de variables */ Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } diff --git a/src/test/java/fr/insee/rmes/api/geo/territoire/DepartementApiTest.java b/src/test/java/fr/insee/rmes/api/geo/territoire/DepartementApiTest.java index f82fc0cc..f5da0fb5 100644 --- a/src/test/java/fr/insee/rmes/api/geo/territoire/DepartementApiTest.java +++ b/src/test/java/fr/insee/rmes/api/geo/territoire/DepartementApiTest.java @@ -256,7 +256,7 @@ void givenGetDepartementDescendants_whenCorrectRequest_andHeaderContentIsJson_th list.add(new Departement()); // Call method - geoApi.getDescendants("something", MediaType.APPLICATION_JSON, null, null); + geoApi.getDescendants("something", MediaType.APPLICATION_JSON, null, null, null);/*modifier suite a changement du nombre de variables */ verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -268,7 +268,7 @@ void givenGetDepartementDescendants_whenCorrectRequest_andHeaderContentIsXml_the list.add(new Departement()); // Call method - geoApi.getDescendants("something", MediaType.APPLICATION_XML, null, null); + geoApi.getDescendants("something", MediaType.APPLICATION_XML, null, null, null);/*modifier suite a changement du nombre de variables */ verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -279,11 +279,11 @@ void givenGetDepartementDescendants_WhenCorrectRequest_thenResponseIsNotFound() this.mockUtilsMethodsThenReturnListOfPojo(Boolean.FALSE); // Call method header content = xml - Response response = geoApi.getDescendants("something", MediaType.APPLICATION_JSON, null, null); + Response response = geoApi.getDescendants("something", MediaType.APPLICATION_JSON, null, null, null);/*modifier suite a changement du nombre de variables */ Assertions.assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus()); // Call method header content = json - response = geoApi.getDescendants("something", MediaType.APPLICATION_XML, null, null); + response = geoApi.getDescendants("something", MediaType.APPLICATION_XML, null, null, null);/*modifier suite a changement du nombre de variables */ Assertions.assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus()); verify(mockResponseUtils, never()).produceResponse(Mockito.any(), Mockito.any()); @@ -297,7 +297,7 @@ void givenGetDepartementDescendants_WhenCorrectRequest_thenParameterDateIsRight( list.add(new Departement()); // Call method header content = xml - geoApi.getDescendants("something", MediaType.APPLICATION_XML, "2000-01-01", null); + geoApi.getDescendants("something", MediaType.APPLICATION_XML, "2000-01-01", null, null);/*modifier suite a changement du nombre de variables */ verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -305,7 +305,7 @@ void givenGetDepartementDescendants_WhenCorrectRequest_thenParameterDateIsRight( void givenGetDepartementDescendants_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getDescendants("something", MediaType.APPLICATION_XML, "nimportequoi", null); + Response response = geoApi.getDescendants("something", MediaType.APPLICATION_XML, "nimportequoi", null, null);/*modifier suite a changement du nombre de variables */ Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -317,7 +317,7 @@ void givenGetDepartementDescendants_WhenCorrectRequest_thenParameterTypeIsNull() list.add(new Departement()); // Call method header content = xml - geoApi.getDescendants("something", MediaType.APPLICATION_XML, null, null); + geoApi.getDescendants("something", MediaType.APPLICATION_XML, null, null, null);/*modifier suite a changement du nombre de variables */ verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -330,7 +330,7 @@ void givenGetDepartementDescendants_WhenCorrectRequest_thenParameterTypeIsRight( // Call method header content = xml geoApi - .getDescendants("something", MediaType.APPLICATION_XML, null, EnumTypeGeographie.COMMUNE.getTypeObjetGeo()); + .getDescendants("something", MediaType.APPLICATION_XML, null, EnumTypeGeographie.COMMUNE.getTypeObjetGeo(), null);/*modifier suite a changement du nombre de variables */ verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -338,7 +338,7 @@ void givenGetDepartementDescendants_WhenCorrectRequest_thenParameterTypeIsRight( void givenGetDepartementDescendants_WhenCorrectRequest_thenParameterTypeIsBad() { // Call method header content = xml - Response response = geoApi.getDescendants("something", MediaType.APPLICATION_XML, null, "unTypeQuelconque"); + Response response = geoApi.getDescendants("something", MediaType.APPLICATION_XML, null, "unTypeQuelconque", null);/*modifier suite a changement du nombre de variables */ Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } diff --git a/src/test/java/fr/insee/rmes/api/geo/territoire/RegionApiTest.java b/src/test/java/fr/insee/rmes/api/geo/territoire/RegionApiTest.java index 4f0d22b3..875bec02 100644 --- a/src/test/java/fr/insee/rmes/api/geo/territoire/RegionApiTest.java +++ b/src/test/java/fr/insee/rmes/api/geo/territoire/RegionApiTest.java @@ -175,7 +175,7 @@ void givenGetRegionDescendants_whenCorrectRequest_andHeaderContentIsJson_thenRes list.add(new Region()); // Call method - geoApi.getDescendants("something", MediaType.APPLICATION_JSON, null, null); + geoApi.getDescendants("something", MediaType.APPLICATION_JSON, null, null, null); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -187,7 +187,7 @@ void givenGetRegionDescendants_whenCorrectRequest_andHeaderContentIsXml_thenResp list.add(new Region()); // Call method - geoApi.getDescendants("something", MediaType.APPLICATION_XML, null, null); + geoApi.getDescendants("something", MediaType.APPLICATION_XML, null, null, null); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -198,11 +198,11 @@ void givenGetRegionDescendants_WhenCorrectRequest_thenResponseIsNotFound() { this.mockUtilsMethodsThenReturnListOfPojo(Boolean.FALSE); // Call method header content = xml - Response response = geoApi.getDescendants("something", MediaType.APPLICATION_JSON, null, null); + Response response = geoApi.getDescendants("something", MediaType.APPLICATION_JSON, null, null, null); Assertions.assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus()); // Call method header content = json - response = geoApi.getDescendants("something", MediaType.APPLICATION_XML, null, null); + response = geoApi.getDescendants("something", MediaType.APPLICATION_XML, null, null, null); Assertions.assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus()); verify(mockResponseUtils, never()).produceResponse(Mockito.any(), Mockito.any()); @@ -216,7 +216,7 @@ void givenGetRegionDescendants_WhenCorrectRequest_thenParameterDateIsRight() { list.add(new Region()); // Call method header content = xml - geoApi.getDescendants("something", MediaType.APPLICATION_XML, "2000-01-01", null); + geoApi.getDescendants("something", MediaType.APPLICATION_XML, "2000-01-01", null, null); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -224,7 +224,7 @@ void givenGetRegionDescendants_WhenCorrectRequest_thenParameterDateIsRight() { void givenGetRegionDescendants_WhenCorrectRequest_thenParameterDateIsBad() { // Call method header content = xml - Response response = geoApi.getDescendants("something", MediaType.APPLICATION_XML, "nimportequoi", null); + Response response = geoApi.getDescendants("something", MediaType.APPLICATION_XML, "nimportequoi", null, null); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); } @@ -236,7 +236,7 @@ void givenGetRegionDescendants_WhenCorrectRequest_thenParameterTypeIsNull() { list.add(new Region()); // Call method header content = xml - geoApi.getDescendants("something", MediaType.APPLICATION_XML, null, null); + geoApi.getDescendants("something", MediaType.APPLICATION_XML, null, null, null); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -253,7 +253,7 @@ void givenGetRegionDescendants_WhenCorrectRequest_thenParameterTypeIsRight() { "something", MediaType.APPLICATION_XML, null, - EnumTypeGeographie.ARRONDISSEMENT.getTypeObjetGeo()); + EnumTypeGeographie.ARRONDISSEMENT.getTypeObjetGeo(), null); verify(mockResponseUtils, times(1)).produceResponse(Mockito.any(), Mockito.any()); } @@ -261,7 +261,7 @@ void givenGetRegionDescendants_WhenCorrectRequest_thenParameterTypeIsRight() { void givenGetRegionDescendants_WhenCorrectRequest_thenParameterTypeIsBad() { // Call method header content = xml - Response response = geoApi.getDescendants("something", MediaType.APPLICATION_XML, null, "unTypeQuelconque"); + Response response = geoApi.getDescendants("something", MediaType.APPLICATION_XML, null, "unTypeQuelconque", null); Assertions.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus()); }