-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from InseeFr/acceptance
Acceptance
- Loading branch information
Showing
9 changed files
with
248 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
src/main/java/fr/insee/rmes/api/geo/territoire/CirconscriptionTerritorialeApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
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.CirconscriptionTerritoriale; | ||
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 CirconscriptionTerritorialeApi extends AbstractGeoApi { | ||
|
||
private static Logger logger = LogManager.getLogger(CirconscriptionTerritorialeApi.class); | ||
private static final String CODE_PATTERNCIRCO_TER = "/{code: " + ConstGeoApi.PATTERN_CIRCO_TER + "}"; | ||
private static final String LITTERAL_ID_OPERATION = "getcogdistrict"; | ||
private static final String LITTERAL_OPERATION_SUMMARY = | ||
"Informations sur une circonscription territoriale identifiée par son code (cinq caractères)"; | ||
private static final String LITTERAL_RESPONSE_DESCRIPTION = "circonscription territoriale d'une collectivité d'outre-mer"; | ||
private static final String LITTERAL_PARAMETER_DATE_DESCRIPTION = | ||
"Filtre pour renvoyer la circonscription territoriale 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 = "98611"; | ||
|
||
|
||
@Path(ConstGeoApi.PATH_CIRCO_TER + CODE_PATTERNCIRCO_TER) | ||
@GET | ||
@Produces({ | ||
MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML | ||
}) | ||
@Operation( | ||
operationId = LITTERAL_ID_OPERATION, | ||
summary = LITTERAL_OPERATION_SUMMARY, | ||
responses = { | ||
@ApiResponse( | ||
content = @Content(schema = @Schema(implementation = CirconscriptionTerritoriale.class)), | ||
description = LITTERAL_RESPONSE_DESCRIPTION) | ||
}) | ||
public Response getByCode( | ||
@Parameter( | ||
description = ConstGeoApi.PATTERN_CIRCO_TER_DESCRIPTION, | ||
required = true, | ||
schema = @Schema( | ||
pattern = ConstGeoApi.PATTERN_CIRCO_TER, | ||
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.getCirconscriptionTerritorialeByCodeAndDate(code, this.formatValidParameterDateIfIsNull(date))), | ||
header, | ||
new CirconscriptionTerritoriale(code)); | ||
} | ||
} | ||
|
||
@Path(ConstGeoApi.PATH_CIRCO_TER + CODE_PATTERNCIRCO_TER + 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 la circonscription territoriale", | ||
responses = { | ||
@ApiResponse( | ||
content = @Content(schema = @Schema(type = ARRAY, implementation = Territoire.class)), | ||
description = LITTERAL_RESPONSE_DESCRIPTION) | ||
}) | ||
public Response getAscendants( | ||
@Parameter( | ||
description = ConstGeoApi.PATTERN_CIRCO_TER_DESCRIPTION, | ||
required = true, | ||
schema = @Schema( | ||
pattern = ConstGeoApi.PATTERN_CIRCO_TER, | ||
type = Constants.TYPE_STRING, example="98611")) @PathParam(Constants.CODE) String code, | ||
@Parameter(hidden = true) @HeaderParam(HttpHeaders.ACCEPT) String header, | ||
@Parameter( | ||
description = "Filtre pour renvoyer les territoires contenant la circonscription territoriale 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 circonscription territoriale {}", code); | ||
|
||
if ( ! this.verifyParametersTypeAndDateAreValid(typeTerritoire, date)) { | ||
return this.generateBadRequestResponse(); | ||
} | ||
else { | ||
return this | ||
.generateResponseListOfTerritoire( | ||
sparqlUtils | ||
.executeSparqlQuery( | ||
GeoQueries | ||
.getAscendantsCirconscriptionTerritoriale( | ||
code, | ||
this.formatValidParameterDateIfIsNull(date), | ||
this.formatValidParametertypeTerritoireIfIsNull(typeTerritoire))), | ||
header, | ||
Territoires.class, | ||
Territoire.class); | ||
} | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/java/fr/insee/rmes/modeles/geo/territoire/CirconscriptionTerritoriale.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
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 = "CirconscriptionTerritoriale") | ||
@JacksonXmlRootElement(localName = "CirconscriptionTerritoriale") | ||
@XmlAccessorType(XmlAccessType.FIELD) | ||
@Schema(description = "Objet représentant une circonscription territoriale") | ||
|
||
public class CirconscriptionTerritoriale extends Territoire { | ||
|
||
public CirconscriptionTerritoriale() { | ||
this.type = EnumTypeGeographie.CIRCONSCRIPTION_TERRITORIALE.getTypeObjetGeo(); | ||
this.intituleSansArticle = new IntituleSansArticle(); | ||
} | ||
|
||
public CirconscriptionTerritoriale(String code) { | ||
this.type = EnumTypeGeographie.CIRCONSCRIPTION_TERRITORIALE.getTypeObjetGeo(); | ||
this.code = code; | ||
this.intituleSansArticle = new IntituleSansArticle(); | ||
} | ||
|
||
public CirconscriptionTerritoriale( | ||
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); | ||
} | ||
|
||
|
||
|
||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/fr/insee/rmes/modeles/geo/territoires/CirconscriptionsTerritoriales.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
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.CirconscriptionTerritoriale; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
|
||
@JacksonXmlRootElement(localName = "CirconscriptionsTerritoriales") | ||
@XmlAccessorType(XmlAccessType.FIELD) | ||
@Schema(name = "CirconscriptionsTerritoriales", description = "Tableau représentant les circonscriptions territoriales") | ||
|
||
public class CirconscriptionsTerritoriales extends Territoires { | ||
|
||
private List<CirconscriptionTerritoriale> circonscriptionsTerritoriales = null; | ||
|
||
public CirconscriptionsTerritoriales() {} | ||
|
||
public CirconscriptionsTerritoriales(List<CirconscriptionTerritoriale> circonscriptionsTerritoriales) { | ||
this.circonscriptionsTerritoriales = circonscriptionsTerritoriales; | ||
} | ||
|
||
@JacksonXmlProperty(isAttribute = true, localName = "CirconscriptionTerritoriale") | ||
@JacksonXmlElementWrapper(useWrapping = false) | ||
public List<CirconscriptionTerritoriale> getCirconscriptionsTerritoriales() { | ||
return circonscriptionsTerritoriales; | ||
} | ||
|
||
public void setCirconscriptionsTerritoriales(List<CirconscriptionTerritoriale> circonscriptionsTerritoriales) { | ||
this.circonscriptionsTerritoriales = circonscriptionsTerritoriales; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters