Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

140 fix pays geo #156

Merged
merged 10 commits into from
Feb 20, 2025
2 changes: 1 addition & 1 deletion src/main/java/fr/insee/rmes/api/geo/ConstGeoApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class ConstGeoApi {
public static final String PATH_BASSINDEVIE= PATH_SEPARATOR + "bassinDeVie2022";
public static final String PATH_LISTE_IRIS = PATH_SEPARATOR + "iris";
public static final String PATH_LISTE_COMMUNE = PATH_SEPARATOR + "communes";
public static final String PATH_LISTE_PAYS = PATH_SEPARATOR + "pays";
public static final String PATH_LISTE_PAYS = PATH_SEPARATOR + "payss";
public static final String PATH_LISTE_CANTON = PATH_SEPARATOR + "cantons";
public static final String PATH_LISTE_REGION = PATH_SEPARATOR + "regions";
public static final String PATH_LISTE_DEPARTEMENT = PATH_SEPARATOR + "departements";
Expand Down
70 changes: 39 additions & 31 deletions src/main/java/fr/insee/rmes/api/geo/PaysApi.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.insee.rmes.api.geo;

import fr.insee.rmes.modeles.geo.territoire.AireDAttractionDesVilles2020;
import fr.insee.rmes.modeles.geo.territoires.PaysS;
import fr.insee.rmes.modeles.geo.territoire.Territoire;
import fr.insee.rmes.modeles.geo.territoires.Territoires;
Expand Down Expand Up @@ -32,51 +33,58 @@ public class PaysApi extends AbstractGeoApi {
private static final String LITTERAL_RESPONSE_DESCRIPTION = "Pays";
private static final String LITTERAL_PARAMETER_TYPE_DESCRIPTION = "Filtre sur le type de territoire renvoyé.";
private static final String LITTERAL_DATE_EXAMPLE = "2000-01-01";
private static final String LITTERAL_CODE_HISTORY_EXAMPLE = "44";
private static final String LITTERAL_CODE_HISTORY_EXAMPLE = "99309";



@Path(ConstGeoApi.PATH_PAYS + CODE_PATTERN)
@GET
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Operation(operationId = LITTERAL_ID_OPERATION, summary = LITTERAL_OPERATION_SUMMARY, responses = {
@ApiResponse(
content = @Content(schema = @Schema(implementation = Pays.class)),
description = LITTERAL_RESPONSE_DESCRIPTION)
@Produces({
MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML
})
@Operation(
operationId = LITTERAL_ID_OPERATION,
summary = LITTERAL_OPERATION_SUMMARY,
responses = {
@ApiResponse(
content = @Content(schema = @Schema(implementation = Pays.class)),
description = LITTERAL_RESPONSE_DESCRIPTION)
})
public Response getByCode(
@Parameter(
description = ConstGeoApi.PATTERN_PAYS_DESCRIPTION,
required = true,
schema = @Schema(
pattern = ConstGeoApi.PATTERN_PAYS,
type = Constants.TYPE_STRING, example = "99217")) @PathParam(Constants.CODE) String code,
@Parameter(hidden = true) @HeaderParam(HttpHeaders.ACCEPT) Header header) {
if (!isValidCode(code)) {
return Response.status(Status.BAD_REQUEST).entity("Invalid code").build();
type = Constants.TYPE_STRING, example="99132")) @PathParam(Constants.CODE) String code,
@Parameter(hidden = true) @HeaderParam(HttpHeaders.ACCEPT) String header,
@Parameter(
description = "Filtre pour renvoyer le pays 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) Date date) {
String dateString = null;
if (date !=null) {
dateString = date.getString();
}

Pays pays = new Pays(code);
String sanitizedCode = escapeSparql(code);
String csvResult = sparqlUtils.executeSparqlQuery(GeoQueries.getPays(sanitizedCode));
pays = (Pays) csvUtils.populatePOJO(csvResult, pays);

if (pays.getUri() == null) {
return Response.status(Status.NOT_FOUND).entity("").build();
} else {
String acceptHeader = sanitizeAndValidateHeader(header.getString());

if (acceptHeader == null) {
return Response.status(Status.BAD_REQUEST).entity("Invalid Accept header").build();
}
return Response.ok(responseUtils.produceResponse(pays, acceptHeader)).build();
if ( ! this.verifyParameterDateIsRightWithoutHistory(dateString)) {
return this.generateBadRequestResponse();
}
else {
return this
.generateResponseATerritoireByCode(
sparqlUtils
.executeSparqlQuery(
GeoQueries.getPaysByCodeAndDate(code, this.formatValidParameterDateIfIsNull(dateString))),
header,
new Pays(code));
}
}

@Path(ConstGeoApi.PATH_PAYS)
@GET
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Operation(operationId = LITTERAL_ID_OPERATION, summary = LITTERAL_OPERATION_SUMMARY, responses = {
@Operation(operationId = LITTERAL_ID_OPERATION, summary = "Informations sur tous les pays actifs à la date données. Par défaut c'est la date courante", responses = {
@ApiResponse(
content = @Content(schema = @Schema(implementation = PaysS.class)),
description = LITTERAL_RESPONSE_DESCRIPTION)
Expand Down Expand Up @@ -125,7 +133,7 @@ public Response getDescendants(
required = true,
schema = @Schema(
pattern = ConstGeoApi.PATTERN_PAYS,
type = Constants.TYPE_STRING, example="002")) @PathParam(Constants.CODE) String code,
type = Constants.TYPE_STRING, example="99132")) @PathParam(Constants.CODE) String code,
@Parameter(hidden = true) @HeaderParam(HttpHeaders.ACCEPT) String header,
@Parameter(
description = "Filtre pour renvoyer les territoires inclus dans le pays actif à la date donnée. Par défaut, c’est la date courante. (Format : 'AAAA-MM-JJ')",
Expand All @@ -135,7 +143,7 @@ public Response getDescendants(
@Parameter(
description = LITTERAL_PARAMETER_TYPE_DESCRIPTION,
required = false,
schema = @Schema(type = Constants.TYPE_STRING, example="ArrondissementMunicipal")) @QueryParam(
schema = @Schema(type = Constants.TYPE_STRING, example="Territoire")) @QueryParam(
value = Constants.PARAMETER_TYPE) String typeTerritoire) {
String dateString = null;
if (date !=null) {
Expand Down Expand Up @@ -179,12 +187,12 @@ public Response getSuivant(
required = true,
schema = @Schema(
pattern = ConstGeoApi.PATTERN_PAYS,
type = Constants.TYPE_STRING, example="41")) @PathParam(Constants.CODE) String code,
type = Constants.TYPE_STRING, example="99121")) @PathParam(Constants.CODE) String code,
@Parameter(hidden = true) @HeaderParam(HttpHeaders.ACCEPT) String header,
@Parameter(
description = "Filtre pour préciser le pays de départ. Par défaut, c’est la date courante qui est utilisée. (Format : 'AAAA-MM-JJ')",
required = false,
schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE, example=LITTERAL_DATE_EXAMPLE)) @QueryParam(
schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE, example="1950-01-01")) @QueryParam(
value = Constants.PARAMETER_DATE) Date date) {
String dateString = null;
if (date != null){
Expand Down Expand Up @@ -230,7 +238,7 @@ public Response getPrecedent(
@Parameter(
description = "Filtre pour préciser le pays de départ. Par défaut, c’est la date courante qui est utilisée. (Format : 'AAAA-MM-JJ')",
required = false,
schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE)) @QueryParam(
schema = @Schema(type = Constants.TYPE_STRING, format = Constants.FORMAT_DATE,example = "1963-01-01")) @QueryParam(
value = Constants.PARAMETER_DATE) Date date) {
String dateString = null;
if (date != null){
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/fr/insee/rmes/modeles/geo/EnumTypeGeographie.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ public enum EnumTypeGeographie {
INTERCOMMUNALITE("Intercommunalite",Intercommunalite.class,Intercommunalites.class,Constants.NONE),
BASSINDEVIE("BassinDeVie2022",BassinDeVie2022.class,BassinsDeVie2022.class,Constants.NONE),
IRIS("Iris", Iris.class,Iriss.class,Constants.NONE),
PAYS("Pays", Pays.class, PaysS.class,Constants.NONE);
PAYS("Pays", Pays.class, PaysS.class,Constants.NONE),
TERRITOIRE("Territoire",TerritoireNonAbstract.class,TerritoiresNonAbstract.class,Constants.NONE);


private String typeObjetGeo;
private Class<? extends Territoire> classNameOfGeoType;
Expand Down Expand Up @@ -74,16 +76,16 @@ public static Class<? extends Territoires> getPluralClassByType(String type) {
return optionalClass.isPresent() ? optionalClass.get().getClassPluralGeoType() : null;
}

private static Optional<EnumTypeGeographie> getOptionalEnumType(String type) {
private static Optional<EnumTypeGeographie> getOptionalEnumType(String type) {
return streamValuesTypeGeo().filter(s -> s.getTypeObjetGeo().equalsIgnoreCase(type)).findAny();
}

public static String getTypeObjetGeoIgnoreCase(String typeObjetGeo) {
Optional<EnumTypeGeographie> enumTypeGeographie =
EnumTypeGeographie
.streamValuesTypeGeo()
.filter(s -> s.getTypeObjetGeo().equalsIgnoreCase(typeObjetGeo))
.findFirst();
.streamValuesTypeGeo()
.filter(s -> s.getTypeObjetGeo().equalsIgnoreCase(typeObjetGeo))
.findFirst();
return enumTypeGeographie.isPresent() ? enumTypeGeographie.get().getTypeObjetGeo() : null;
}

Expand Down
93 changes: 73 additions & 20 deletions src/main/java/fr/insee/rmes/modeles/geo/territoire/Pays.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package fr.insee.rmes.modeles.geo.territoire;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlAttribute;
Expand All @@ -16,16 +18,32 @@
@JacksonXmlRootElement(localName = "Pays")
@XmlAccessorType(XmlAccessType.FIELD)
@Schema(description = "Objet représentant un pays")
@JsonIgnoreProperties({ "intituleSansArticle","typeArticle","intitule","inituleEntier"})
public class Pays extends Territoire {

@Schema(example = "99254")
@Schema(example = "99100")
private String code = null;
@Schema(example = "http://id.insee.fr/geo/pays/99254")
@Schema(example ="http://id.insee.fr/geo/pays/b7e3f0c9-b653-4a3e-904a-de63b80e108b")
private String uri = null;
@Schema(example = "CHYPRE")
private String intitule = null;
@Schema(example = "RÉPUBLIQUE DE CHYPRE")
private String intituleEntier = null;
@Schema(example = "France")
private String nom = null;
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@Schema(example = "République française")
private String nomLong = null;
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@Schema(example = "FR")
private String iso3166alpha2 = null;
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@Schema(example = "FRA")
private String iso3166alpha3 = null;
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@Schema(example = "250")
private String iso3166num = null;
@Schema(example = "1943-01-01")
private String dateCreation = null;
@Schema(example = "2025-12-12")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private String dateSuppresion = null;

public Pays() {} // No-args constructor needed for JAXB

Expand Down Expand Up @@ -53,25 +71,60 @@ public void setUri(String uri) {
this.uri = uri;
}

@XmlElement(name = "Intitule")
@JacksonXmlProperty(localName = "Intitule")
@JsonProperty(value = "intitule")
public String getIntitule() {
return intitule;

@XmlElement(name = "Nom")
@JacksonXmlProperty(localName = "Nom")
@JsonProperty(value = "nom")
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}

@XmlElement(name = "NomLong")
@JacksonXmlProperty(localName = "NomLong")
@JsonProperty(value = "nomLong")
public String getNomLong() {
return nomLong;
}

public void setNomLong(String nomLong) {
this.nomLong = nomLong;
}


@XmlElement(name = "Iso3166alpha2")
@JacksonXmlProperty(localName = "Iso3166alpha2")
@JsonProperty(value = "iso3166alpha2")
public String getIso3166alpha2() {
return iso3166alpha2;
}

public void setIso3166alpha2(String iso3166alpha2) {
this.iso3166alpha2 = iso3166alpha2;
}

public void setIntitule(String intitule) {
this.intitule = intitule;
@XmlElement(name = "Iso3166alpha3")
@JacksonXmlProperty(localName = "Iso3166alpha3")
@JsonProperty(value = "iso3166alpha3")
public String getIso3166alpha3() {
return iso3166alpha3;
}

@XmlElement(name = "IntituleEntier")
@JacksonXmlProperty(localName = "IntituleEntier")
@JsonProperty(value = "intituleEntier")
public String getIntituleEntier() {
return intituleEntier;
public void setIso3166alpha3(String iso3166alpha3) {
this.iso3166alpha3 = iso3166alpha3;
}

public void setIntituleEntier(String intituleEntier) {
this.intituleEntier = intituleEntier;
@XmlElement(name = "Iso3166num")
@JacksonXmlProperty(localName = "Iso3166num")
@JsonProperty(value = "iso3166num")
public String getIso3166num() {
return iso3166num;
}
public void setIso3166num(String iso3166num) {
this.iso3166num = iso3166num;
}


}
Loading