Skip to content
Merged

Geo #52

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/main/java/fr/insee/rmes/api/geo/AbstractGeoApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/fr/insee/rmes/api/geo/ConstGeoApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
Expand All @@ -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}";
Expand All @@ -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)";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')",
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}

}
22 changes: 17 additions & 5 deletions src/main/java/fr/insee/rmes/api/geo/territoire/CommuneApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')",
Expand Down Expand Up @@ -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");

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand Down
Loading