Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e8568bc
Merge pull request #43 from InseeFr/main
MichaelC67 Dec 14, 2021
4a812a3
Merge pull request #45 from InseeFr/main
MichaelC67 Dec 14, 2021
dd52dca
Merge pull request #47 from InseeFr/main
SophieMar Dec 15, 2021
69ba650
Merge pull request #49 from InseeFr/main
JeromeMBourgeois Dec 20, 2021
29eb8aa
Merge pull request #50 from InseeFr/main
JeromeMBourgeois Dec 20, 2021
fbb63e8
Bump log4j-core from 2.17.0 to 2.17.1
dependabot[bot] Jan 4, 2022
189f380
list communes V2
JeromeMBourgeois Jan 5, 2022
137b8ad
Service collectiviteDOutreMer + modification requete getTerritoireByC…
JeromeMBourgeois Jan 6, 2022
3f281e7
Service CollectiviteDOutreMer by code
JeromeMBourgeois Jan 7, 2022
f31c9cd
Service collectiviteDOutreMer descendant + MAJ ftlh
JeromeMBourgeois Jan 10, 2022
d4b900f
Ajout District et Ajout filtre sur le service departement/code/descen…
JeromeMBourgeois Jan 12, 2022
ccebd10
corrections diverses
JeromeMBourgeois Jan 13, 2022
d61ef13
Update getAscendantsOrDescendantsByCodeTypeDateCOM.ftlh
JeromeMBourgeois Jan 13, 2022
849d4d7
Update CollectivitesDOutreMerAPI.java
JeromeMBourgeois Jan 13, 2022
e46a790
Update DepartementApi.java
JeromeMBourgeois Jan 13, 2022
fbbf380
update COM field and modify sparql query
JeromeMBourgeois Jan 17, 2022
814cd5d
Fix
JeromeMBourgeois Jan 19, 2022
d330a8f
feat : Add District services
JeromeMBourgeois Jan 20, 2022
e614236
Simplify requests
alicela Jan 20, 2022
e63b94e
Change param to boolean
alicela Jan 20, 2022
ac07051
Merge pull request #52 from JeromeMBourgeois/GEO
JeromeMBourgeois Jan 20, 2022
e93b6ee
fix : update service list COM
JeromeMBourgeois Jan 21, 2022
265843d
Merge pull request #53 from JeromeMBourgeois/GEO
JeromeMBourgeois Jan 21, 2022
8f09ab6
Update queries to disable auto-escaping on the name of the territory
JeromeMBourgeois Jan 31, 2022
3b87b28
Merge pull request #54 from JeromeMBourgeois/GEO
JeromeMBourgeois Jan 31, 2022
f80cfac
update query getTerritoireByCodeDateNomCommune
JeromeMBourgeois Feb 2, 2022
2d6a89c
Update getTerritoireByCodeDateNomcommune.ftlh
JeromeMBourgeois Feb 3, 2022
cb7b6d1
Merge pull request #55 from JeromeMBourgeois/GEO
JeromeMBourgeois Feb 3, 2022
667cc10
Merge pull request #51 from InseeFr/dependabot/maven/org.apache.loggi…
JeromeMBourgeois Feb 8, 2022
e13cf18
update version
JeromeMBourgeois Feb 8, 2022
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
3 changes: 3 additions & 0 deletions metadataapi-changeLog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
3.1.0 : Ajout des services des collectivités d'Outre-mer (Geo)
3.0.5 : Montée de version log4J
3.0.4 : Montée de version log4J
3.0.3 : Correction des régressions sur l'encodage des retours XML (documentation sims notamment)
3.0.2 : Correction de l'encodage des retours XML (documentation sims notamment) et logs
3.0.1 : Changement des properties pour correspondre à ce qui a été défini en production
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<packaging>war</packaging>
<name>Implementation of the RMéS metadata API</name>

<version>3.0.5</version>
<version>3.1.0</version>

<properties>
<title>API RM\u00e9S</title>
Expand All @@ -19,7 +19,7 @@
<jersey.version>2.29.1</jersey.version>
<jackson.version>2.10.1</jackson.version>
<jakarta.version>4.0.3</jakarta.version>
<log.version>2.17.0</log.version>
<log.version>2.17.1</log.version>
<swagger.version>2.0.10</swagger.version>
<junit.version>5.7.0</junit.version>
<maven-surefire-plugin.version>3.0.0-M5</maven-surefire-plugin.version>
Expand Down
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 = "988";



@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