From 8dff1af94fa2d594ac1c947eb2417505bdc98681 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20J=C3=A9go?= Date: Tue, 14 Sep 2021 21:59:59 +0200 Subject: [PATCH] Update all libs to last stable compatible version Change CXF to Spring MVC, that's why most of the java class and configuration had to be updated Use MDC possibilities for CNIL level and filtering authorisation (roles and org) Geotools update made the code slightly change for image generation All in one commit because there were dependencies beetween libraries --- cadastrapp/pom.xml | 225 +++++------------- .../CadastrappControllerConfig.java | 30 +++ .../configuration/CadastrappPlaceHolder.java | 8 +- .../cadastrapp/helper/BatimentHelper.java | 6 +- .../cadastrapp/helper/ProprietaireHelper.java | 9 +- .../providers/CadastrappInterceptor.java | 60 +++++ .../providers/PreReponseFilter.java | 33 --- .../providers/PreRequestFilter.java | 39 --- .../repository/ObjectRequestRepository.java | 2 +- .../repository/RequestRepository.java | 2 +- .../repository/UserRequestRepository.java | 2 +- .../service/BatimentController.java | 41 ++-- .../cadastrapp/service/CadController.java | 41 ++-- .../service/CoProprietaireController.java | 138 ++++++----- .../cadastrapp/service/CommuneController.java | 30 +-- .../service/ConfigurationController.java | 18 +- .../cadastrapp/service/DatadirController.java | 36 +-- .../service/HabitationController.java | 36 ++- .../service/ImageParcelleController.java | 65 +++-- .../service/InfoBulleController.java | 74 +++--- .../service/ParcelleController.java | 178 +++++++------- .../service/ProprietaireController.java | 121 ++++------ .../service/RequestInformationController.java | 51 ++-- .../cadastrapp/service/SectionController.java | 36 +-- .../service/UniteCadastraleController.java | 55 ++--- .../cadastrapp/service/VoieController.java | 28 +-- .../constants/CadastrappConstants.java | 5 + .../service/export/CSVExportController.java | 38 +-- .../pdf/BordereauParcellaireController.java | 64 ++--- .../pdf/BordereauParcellaireHelper.java | 13 +- .../service/pdf/DemandeController.java | 122 +++++----- .../pdf/ReleveProprieteController.java | 72 +++--- .../service/pdf/ReleveProprieteHelper.java | 13 +- .../service/pdf/RequestPDFController.java | 38 +-- cadastrapp/src/main/webapp/WEB-INF/beans.xml | 147 +++++------- cadastrapp/src/main/webapp/WEB-INF/web.xml | 52 ++-- .../cadastrapp/service/CadControllerTest.java | 4 +- .../service/ImageParcelleControllerTest.java | 7 +- cadastrapp/src/test/resources/test-config.xml | 50 +--- 39 files changed, 895 insertions(+), 1094 deletions(-) create mode 100644 cadastrapp/src/main/java/org/georchestra/cadastrapp/configuration/CadastrappControllerConfig.java create mode 100644 cadastrapp/src/main/java/org/georchestra/cadastrapp/providers/CadastrappInterceptor.java delete mode 100644 cadastrapp/src/main/java/org/georchestra/cadastrapp/providers/PreReponseFilter.java delete mode 100644 cadastrapp/src/main/java/org/georchestra/cadastrapp/providers/PreRequestFilter.java diff --git a/cadastrapp/pom.xml b/cadastrapp/pom.xml index 93698b91..142bcf4a 100644 --- a/cadastrapp/pom.xml +++ b/cadastrapp/pom.xml @@ -12,18 +12,18 @@ Web application for cadastre management over Georchestra UTF-8 - 1.8.6 - 1.7.25 + 2.12.3 + 1.7.30 1.2.3 1.7.25 - 9.4-1205-jdbc4 - 3.0.4 - 4.3.24.RELEASE - 4.1.7.Final - 4.0.1.Final - 9.2 - 2.0.17 - 2.3.0 + 42.2.20.jre7 + 5.3.8 + 6.0.0.Alpha7 + 5.1.2.Final + 24.0 + 3.0.0-RC1 + 2.3.2 + 2.10.5 @@ -52,28 +52,18 @@ - org.apache.cxf - cxf-rt-frontend-jaxrs - ${cxf.version} - - - org.apache.cxf - cxf-rt-rs-client - ${cxf.version} - - - org.codehaus.jackson - jackson-core-asl + com.fasterxml.jackson.core + jackson-core ${jackson.version} - org.codehaus.jackson - jackson-mapper-asl + com.fasterxml.jackson.core + jackson-databind ${jackson.version} - org.codehaus.jackson - jackson-jaxrs + com.fasterxml.jackson.jaxrs + jackson-jaxrs-json-provider ${jackson.version} @@ -92,6 +82,11 @@ spring-web ${spring.version} + + org.springframework + spring-webmvc + ${spring.version} + org.springframework @@ -116,7 +111,7 @@ - org.hibernate + org.hibernate.orm hibernate-core ${hibernate-version} compile @@ -144,7 +139,7 @@ - org.hibernate + org.hibernate.orm hibernate-entitymanager ${hibernate-version} compile @@ -180,7 +175,7 @@ - org.hibernate + org.hibernate.orm hibernate-ehcache ${hibernate-version} compile @@ -228,13 +223,13 @@ org.apache.commons commons-lang3 - 3.6 + 3.11 org.apache.xmlgraphics fop - 2.3 + 2.6 net.sf.supercsv @@ -281,7 +276,7 @@ junit junit - 4.12 + 4.13.1 test @@ -300,13 +295,29 @@ provided javax.servlet javax.servlet-api - 3.0.1 + 3.1.0 org.apache.pdfbox pdfbox ${pdfbox.version} + + + io.springfox + springfox-swagger2 + ${springfox.version} + + + io.springfox + springfox-swagger-ui + ${springfox.version} + + + io.springfox + springfox-spring-webmvc + ${springfox.version} + @@ -339,7 +350,7 @@ org.eclipse.jetty jetty-maven-plugin - 9.2.11.v20150529 + 9.4.41.v20210516 /cadastrapp/ @@ -360,56 +371,23 @@ org.apache.maven.plugins maven-javadoc-plugin 2.10.3 - - - - org.apache.cxf - cxf-java2wadl-plugin - 3.0.0 - - - org.apache.maven.plugins maven-compiler-plugin - 1.7 - 1.7 + 1.8 + 1.8 - org.apache.maven.plugins - maven-war-plugin - 3.2.3 - - - - target/site - - - target/generated - apidocs - - - - + maven-dependency-plugin + 3.1.2 + - - maven-javadoc-plugin - - - build-javadocs - generate-sources - - javadoc - - - - - + org.codehaus.mojo exec-maven-plugin 1.6.0 @@ -452,7 +430,7 @@ maven-assembly-plugin - 3.2.0 + 3.3.0 addon-assembly.xml @@ -468,52 +446,10 @@ - - org.apache.cxf - cxf-java2wadl-plugin - ${cxf.version} - - - - parsejavadoc - generate-sources - - parsejavadoc - - - - process-classes - process-classes - - java2wadl - - - - org.georchestra.cadastrapp.service.BatimentController - org.georchestra.cadastrapp.service.CommuneController - org.georchestra.cadastrapp.service.ParcelleController - org.georchestra.cadastrapp.service.ProprietaireController - org.georchestra.cadastrapp.service.CoProprietaireController - org.georchestra.cadastrapp.service.SectionController - org.georchestra.cadastrapp.service.InfoBulleController - org.georchestra.cadastrapp.service.UniteCadastraleController - org.georchestra.cadastrapp.service.VoieController - org.georchestra.cadastrapp.service.pdf.BordereauParcellaireController - org.georchestra.cadastrapp.service.pdf.ReleveProprieteController - org.georchestra.cadastrapp.service.pdf.DemandeController - org.georchestra.cadastrapp.service.DatadirController - - org.apache.cxf.maven_plugin.javatowadl.ResourceMapJavaDocProvider - true - - - - pl.project13.maven git-commit-id-plugin - 3.0.1 + 4.0.3 @@ -656,57 +592,6 @@ - - rpmPackage - - - - org.apache.maven.plugins - maven-war-plugin - - - org.codehaus.mojo - rpm-maven-plugin - 2.1.3 - - - generate-rpm - - rpm - - - - - georchestra-${project.artifactId} - UTF-8 - Applications/Internet - ${rpm.gpg.key} - - - /usr/share/lib/georchestra-${project.artifactId} - - - ${project.build.directory} - - cadastrapp.war - - - - - - / - - - ${basedir}/src/deb/resources - - - - - - - - - docker @@ -719,7 +604,7 @@ com.spotify docker-maven-plugin - 0.3.8 + 1.2.2 ${dockerImageName} ${project.basedir}/src/docker @@ -739,7 +624,7 @@ com.google.guava guava - 19.0 + 30.1.1-jre diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/configuration/CadastrappControllerConfig.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/configuration/CadastrappControllerConfig.java new file mode 100644 index 00000000..a21beb8f --- /dev/null +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/configuration/CadastrappControllerConfig.java @@ -0,0 +1,30 @@ +package org.georchestra.cadastrapp.configuration; + +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.ServletRegistration; + +import org.springframework.web.WebApplicationInitializer; +import org.springframework.web.context.ContextLoaderListener; +import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; +import org.springframework.web.context.support.GenericWebApplicationContext; +import org.springframework.web.servlet.DispatcherServlet; + +public class CadastrappControllerConfig implements WebApplicationInitializer { + + @Override + public void onStartup(ServletContext sc) throws ServletException { + AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext(); + + root.refresh(); + root.setServletContext(sc); + + sc.addListener(new ContextLoaderListener(root)); + + DispatcherServlet dv = new DispatcherServlet(new GenericWebApplicationContext()); + + ServletRegistration.Dynamic appServlet = sc.addServlet("cadastrapp", dv); + appServlet.setLoadOnStartup(1); + appServlet.addMapping("/services/*"); + } +} diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/configuration/CadastrappPlaceHolder.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/configuration/CadastrappPlaceHolder.java index 7389e625..b67a78ee 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/configuration/CadastrappPlaceHolder.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/configuration/CadastrappPlaceHolder.java @@ -10,7 +10,13 @@ import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; - +/** + * + * CadastrappPlaceHolder + * + * @author Pierre Jégo / pierre.jego@jdev.fr + * + */ public class CadastrappPlaceHolder extends PropertyPlaceholderConfigurer { private static Map propertiesMap; diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/helper/BatimentHelper.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/helper/BatimentHelper.java index 36d6b0b1..8eeeba3b 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/helper/BatimentHelper.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/helper/BatimentHelper.java @@ -3,8 +3,6 @@ import java.util.List; import java.util.Map; -import javax.ws.rs.core.HttpHeaders; - import org.georchestra.cadastrapp.service.CadController; import org.slf4j.Logger; @@ -26,7 +24,7 @@ public final class BatimentHelper extends CadController { * * @return buildings information on this plot */ - public List> getBuildings(String parcelle, HttpHeaders headers ){ + public List> getBuildings(String parcelle){ logger.debug("infoOngletBatiment - parcelle : " + parcelle); @@ -36,7 +34,7 @@ public List> getBuildings(String parcelle, HttpHeaders heade queryBuilder.append(databaseSchema); queryBuilder.append(".proprietebatie pb "); queryBuilder.append(" where pb.parcelle = ? "); - queryBuilder.append(addAuthorizationFiltering(headers, "pb.")); + queryBuilder.append(addAuthorizationFiltering("pb.")); queryBuilder.append(" ORDER BY pb.dnubat"); JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/helper/ProprietaireHelper.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/helper/ProprietaireHelper.java index e2424539..c1411f69 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/helper/ProprietaireHelper.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/helper/ProprietaireHelper.java @@ -4,8 +4,6 @@ import java.util.List; import java.util.Map; -import javax.ws.rs.core.HttpHeaders; - import org.georchestra.cadastrapp.service.CadController; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -21,16 +19,15 @@ public final class ProprietaireHelper extends CadController { * * @param parcelleList plots list * @param isAddressConcat true to display address in only on field address, false to display each dlign - * @param headers A leaste level CNIL1 form http headers * @return information list of owner whith address field concat in one field (if isAddressConcat is true) */ - public List> getProprietairesByParcelles(HttpHeaders headers, List parcelleList, boolean isAddressConcat) { + public List> getProprietairesByParcelles(List parcelleList, boolean isAddressConcat) { // Init list to return response even if nothing in it. List> proprietaires = new ArrayList>(); // User need to be at least CNIL1 level - if (getUserCNILLevel(headers)>0){ + if (getUserCNILLevel()>0){ if(parcelleList != null && !parcelleList.isEmpty()){ @@ -49,7 +46,7 @@ public List> getProprietairesByParcelles(HttpHeaders headers queryBuilder.append(".proprietaire_parcelle proparc "); queryBuilder.append(createWhereInQuery(parcelleList.size(), "proparc.parcelle")); queryBuilder.append(" and prop.comptecommunal = proparc.comptecommunal"); - queryBuilder.append(addAuthorizationFiltering(headers, "prop.")); + queryBuilder.append(addAuthorizationFiltering("prop.")); queryBuilder.append(" ORDER BY prop.dnulp, prop.app_nom_usage "); JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/providers/CadastrappInterceptor.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/providers/CadastrappInterceptor.java new file mode 100644 index 00000000..16b59a28 --- /dev/null +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/providers/CadastrappInterceptor.java @@ -0,0 +1,60 @@ +package org.georchestra.cadastrapp.providers; + +import org.apache.commons.lang3.StringUtils; +import org.georchestra.cadastrapp.service.constants.CadastrappConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.slf4j.MDC; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.stereotype.Component; +import org.springframework.web.servlet.HandlerInterceptor; +import org.springframework.web.servlet.ModelAndView; + +/** + * Log all request + * @author Pierre Jégo + * + */ +@Component +public class CadastrappInterceptor implements HandlerInterceptor { + + final Logger logger = LoggerFactory.getLogger(CadastrappInterceptor.class); + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) + throws Exception { + + final String rolesList = request.getHeader(CadastrappConstants.HTTP_HEADER_ROLES); + final String userName = request.getHeader(CadastrappConstants.HTTP_HEADER_USERNAME); + final String org = request.getHeader(CadastrappConstants.HTTP_HEADER_ORGANISME); + + // Add contexte information, used in logs and to limit access to data + MDC.put(CadastrappConstants.HTTP_HEADER_USERNAME, userName); + MDC.put(CadastrappConstants.HTTP_HEADER_ROLES, rolesList); + MDC.put(CadastrappConstants.HTTP_HEADER_ORGANISME, org); + MDC.put("uri", request.getRequestURI()); + + logger.info("Incoming request"); + + if(logger.isDebugEnabled()){ + logger.debug("Parameter list : " + StringUtils.join(request.getParameterMap())); + } + return true; + } + + + @Override + public void postHandle( HttpServletRequest request, HttpServletResponse response, + Object handler, ModelAndView modelAndView) throws Exception { + + logger.info("Response"); + MDC.remove(CadastrappConstants.HTTP_HEADER_USERNAME); + MDC.remove(CadastrappConstants.HTTP_HEADER_ROLES); + MDC.remove(CadastrappConstants.HTTP_HEADER_ORGANISME); + MDC.remove("uri"); + } + +} diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/providers/PreReponseFilter.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/providers/PreReponseFilter.java deleted file mode 100644 index ea3b7c07..00000000 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/providers/PreReponseFilter.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.georchestra.cadastrapp.providers; - -import java.io.IOException; - -import javax.ws.rs.container.ContainerRequestContext; -import javax.ws.rs.container.ContainerResponseContext; -import javax.ws.rs.container.ContainerResponseFilter; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.slf4j.MDC; - -/** - * Log all request - * @author gfi - * - */ -public class PreReponseFilter implements ContainerResponseFilter { - - final Logger logger = LoggerFactory.getLogger(PreReponseFilter.class); - - @Override - public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException { - - logger.info("Sending response"); - - MDC.remove("user"); - MDC.remove("roles"); - MDC.remove("uri"); - - } - -} \ No newline at end of file diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/providers/PreRequestFilter.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/providers/PreRequestFilter.java deleted file mode 100644 index b98d3dec..00000000 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/providers/PreRequestFilter.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.georchestra.cadastrapp.providers; - -import java.io.IOException; - -import javax.ws.rs.container.ContainerRequestContext; -import javax.ws.rs.container.ContainerRequestFilter; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.slf4j.MDC; - -/** - * Log all request - * @author gfi - * - */ -public class PreRequestFilter implements ContainerRequestFilter { - - final Logger logger = LoggerFactory.getLogger(PreRequestFilter.class); - - @Override - public void filter(ContainerRequestContext requestContext) throws IOException { - - String rolesList = requestContext.getHeaderString("sec-roles"); - String org = requestContext.getHeaderString("sec-org"); - String userName = requestContext.getHeaderString("sec-username"); - MDC.put("user", userName); - MDC.put("org", org); - MDC.put("roles", rolesList); - MDC.put("uri", requestContext.getUriInfo().getPath()); - - logger.info("Incoming request"); - - if(logger.isDebugEnabled()){ - logger.debug("Parameter list : " + requestContext.getUriInfo().getQueryParameters()); - } - - } -} diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/repository/ObjectRequestRepository.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/repository/ObjectRequestRepository.java index e53bae7d..e2ef81b8 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/repository/ObjectRequestRepository.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/repository/ObjectRequestRepository.java @@ -7,7 +7,7 @@ /** * - * @author gfi + * @author Pierre Jégo * * Repository to get InformationRequest for database * diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/repository/RequestRepository.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/repository/RequestRepository.java index 65e73265..22f45b1b 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/repository/RequestRepository.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/repository/RequestRepository.java @@ -10,7 +10,7 @@ /** * - * @author gfi + * @author Pierre jego * * Repository to get InformationRequest for database * diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/repository/UserRequestRepository.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/repository/UserRequestRepository.java index ef964ef1..fb8cf13a 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/repository/UserRequestRepository.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/repository/UserRequestRepository.java @@ -6,7 +6,7 @@ /** * - * @author gfi + * @author Pierre Jégo * * Repository to get UserRequest for database */ diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/BatimentController.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/BatimentController.java index 507a8a74..16f161f2 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/BatimentController.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/BatimentController.java @@ -4,20 +4,18 @@ import java.util.List; import java.util.Map; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MediaType; - import org.georchestra.cadastrapp.helper.BatimentHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + public class BatimentController extends CadController { @@ -25,10 +23,8 @@ public class BatimentController extends CadController { @Autowired BatimentHelper batimentHelper; - - @GET - @Path("/getBatiments") - @Produces(MediaType.APPLICATION_JSON) + + @RequestMapping(path ="/getBatiments", produces = {MediaType.APPLICATION_JSON_VALUE}, method= {RequestMethod.GET}) /** * getBuildingsDetails * Returns information about batiment dnubat on given parcell @@ -39,12 +35,12 @@ public class BatimentController extends CadController { * * @return JSON list */ - public List> getBuildingsDetails(@Context HttpHeaders headers, - @QueryParam("parcelle") String parcelle, - @QueryParam("dnubat") String dnubat){ + public @ResponseBody List> getBuildingsDetails( + @RequestParam("parcelle") String parcelle, + @RequestParam("dnubat") String dnubat){ List> batiments = new ArrayList>(); - if (getUserCNILLevel(headers) == 0) { + if (getUserCNILLevel() == 0) { logger.info("User does not have enough rights to see information about batiment"); } else if(parcelle != null && !parcelle.isEmpty() @@ -81,10 +77,7 @@ else if(parcelle != null && !parcelle.isEmpty() return batiments; } - - @GET - @Path("/getBatimentsByParcelle") - @Produces(MediaType.APPLICATION_JSON) + @RequestMapping(path = "/getBatimentsByParcelle" , produces = {MediaType.APPLICATION_JSON_VALUE}, method= {RequestMethod.GET}) /** * Returns all building from given plot * @@ -93,16 +86,16 @@ else if(parcelle != null && !parcelle.isEmpty() * * @return JSON list compose with all dnubat from this plot, list is empy if no data, or if user doesn't have rights */ - public List> getBuildingsByParcelle(@Context HttpHeaders headers, - @QueryParam("parcelle") String parcelle){ + public @ResponseBody List> getBuildingsByParcelle( + @RequestParam String parcelle){ List> batiments = new ArrayList>(); - if (getUserCNILLevel(headers) == 0) { + if (getUserCNILLevel() == 0) { logger.info("User does not have enough rights to see information about buildings"); } else if(parcelle != null && !parcelle.isEmpty()) { - batiments = batimentHelper.getBuildings(parcelle, headers); + batiments = batimentHelper.getBuildings(parcelle); } else{ logger.info(" Missing input parameter "); diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/CadController.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/CadController.java index c16aa8d7..5f64014a 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/CadController.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/CadController.java @@ -7,16 +7,17 @@ import javax.annotation.Resource; import javax.sql.DataSource; -import javax.ws.rs.core.HttpHeaders; import org.georchestra.cadastrapp.configuration.CadastrappPlaceHolder; +import org.georchestra.cadastrapp.service.constants.CadastrappConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.slf4j.MDC; import org.springframework.jdbc.core.JdbcTemplate; /** * - * @author gfi + * @author pierre jego * */ public class CadController { @@ -43,8 +44,7 @@ public class CadController { protected final String ACCES_ERROR_LOG = "User does not have rights to see thoses informations"; protected final String EMPTY_REQUEST_LOG = "Parcelle Id List is empty nothing to search"; - - + /** * */ @@ -106,14 +106,12 @@ protected boolean checkAreMandatoryParametersValid(List mandatoryList) { * @param headers httpheader information, here we need sec-roles information * @return 0 if user doesnot have any specific right, 1 for CNILLEVEL 1 et 2 for CNILLEVEL 2 */ - protected int getUserCNILLevel(HttpHeaders headers) { + protected int getUserCNILLevel() { int cnilLevel = 0; - + String rolesList = MDC.get(CadastrappConstants.HTTP_HEADER_ROLES); + logger.debug(" Check user CNIL Level "); - - // Get CNIL Group information - String rolesList = headers.getHeaderString("sec-roles"); logger.debug(" Get user roles informations : " + rolesList); if (rolesList!=null && rolesList.contains(cnil2RoleName)) { cnilLevel = 2; @@ -125,27 +123,20 @@ protected int getUserCNILLevel(HttpHeaders headers) { return cnilLevel; } - /** - * Filter information depending on groups information - * - * - * @param headers to search groups filtering - * @return an SQL condition to add to initial query - */ - protected String addAuthorizationFiltering(HttpHeaders headers) { - return addAuthorizationFiltering(headers, ""); + protected String addAuthorizationFiltering() { + return addAuthorizationFiltering(""); } - + /** * Filter information depending on groups information * - * - * @param headers to search groups filtering * @param tableAlias table alias for original request to add to the condition * * @return query to complete user right */ - protected String addAuthorizationFiltering(HttpHeaders headers, String tableAlias) { + protected String addAuthorizationFiltering(String tableAlias) { + + logger.debug("Check user geographical limitation "); List> limitations; List communes = new ArrayList(); @@ -153,15 +144,15 @@ protected String addAuthorizationFiltering(HttpHeaders headers, String tableAlia StringBuilder queryFilter = new StringBuilder(); - String usernameString = headers.getHeaderString("sec-username"); + String usernameString = MDC.get(CadastrappConstants.HTTP_HEADER_USERNAME); if (usernameString == null){ logger.debug("Not checking geographical limitation, anonymous user"); return queryFilter.toString(); } // get org in header - String orgString = headers.getHeaderString("sec-org"); + String orgString = MDC.get(CadastrappConstants.HTTP_HEADER_ORGANISME); // get roles in heade - String roleListString = headers.getHeaderString("sec-roles"); + String roleListString = MDC.get(CadastrappConstants.HTTP_HEADER_ROLES); // merge org+roles to get groups list List groupsList = new ArrayList(); diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/CoProprietaireController.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/CoProprietaireController.java index 69dcef7b..97c205af 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/CoProprietaireController.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/CoProprietaireController.java @@ -15,18 +15,6 @@ import java.util.List; import java.util.Map; -import javax.ws.rs.DefaultValue; -import javax.ws.rs.FormParam; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.ResponseBuilder; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; @@ -40,6 +28,7 @@ import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; +import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; import org.apache.fop.apps.FOPException; import org.apache.fop.apps.Fop; @@ -53,6 +42,20 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Controller; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +import org.georchestra.cadastrapp.service.constants.CadastrappConstants; /** * Service to get co owners information @@ -60,6 +63,7 @@ * @author pierre jego * */ +@Controller public class CoProprietaireController extends CadController { static final Logger logger = LoggerFactory.getLogger(CoProprietaireController.class); @@ -70,9 +74,7 @@ public class CoProprietaireController extends CadController { @Autowired ProprieteHelper proprieteHelper; - @Path("/getCoProprietaireList") - @GET - @Produces(MediaType.APPLICATION_JSON) + @RequestMapping(path ="/getCoProprietaireList", produces = {MediaType.APPLICATION_JSON_VALUE}, method= {RequestMethod.GET}) /** * * /getCoProprietaireList @@ -85,18 +87,18 @@ public class CoProprietaireController extends CadController { * * @throws SQLException */ - public List> getCoProprietairesList(@Context HttpHeaders headers, - @QueryParam("parcelle") String parcelle, - @QueryParam("comptecommunal") String comptecommunal, - @QueryParam("cgocommune") String cgocommune, - @QueryParam("ddenom") String ddenom, - @DefaultValue("0") @QueryParam("details") int details) throws SQLException { + public @ResponseBody List> getCoProprietairesList( + @RequestParam(required= false) String parcelle, + @RequestParam(required= false) String comptecommunal, + @RequestParam(required= false) String cgocommune, + @RequestParam(required= false) String ddenom, + @RequestParam(defaultValue= "0", required= false) int details) throws SQLException { List> coProprietaires = new ArrayList>(); List queryParams = new ArrayList(); // only for CNIL1 and CNIL2 - if (getUserCNILLevel(headers) > 0 && cgocommune != null && cgocommune.length() >0) { + if (getUserCNILLevel() > 0 && cgocommune != null && cgocommune.length() >0) { boolean isParamValid = false; @@ -135,7 +137,7 @@ public List> getCoProprietairesList(@Context HttpHeaders hea if(isParamValid){ queryCoProprietaireBuilder.append("and prop.comptecommunal = proparc.comptecommunal "); - queryCoProprietaireBuilder.append(addAuthorizationFiltering(headers, "prop.")); + queryCoProprietaireBuilder.append(addAuthorizationFiltering("prop.")); JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); coProprietaires = jdbcTemplate.queryForList(queryCoProprietaireBuilder.toString(), queryParams.toArray()); } @@ -144,25 +146,23 @@ public List> getCoProprietairesList(@Context HttpHeaders hea return coProprietaires; } - @Path("/getCoProprietaire") - @GET - @Produces(MediaType.APPLICATION_JSON) + @RequestMapping(path = "/getCoProprietaire", produces = {MediaType.APPLICATION_JSON_VALUE}, method= {RequestMethod.GET}) /** * getCoProprietaire * * @param parcelle * @return */ - public Map getCoProprietaire(@QueryParam("parcelle") String parcelle, - @DefaultValue("0") @QueryParam("start") int start, - @DefaultValue("25") @QueryParam("limit") int limit, @Context HttpHeaders headers) { + public @ResponseBody Map getCoProprietaire(@RequestParam String parcelle, + @RequestParam(defaultValue= "0", required= false) int start, + @RequestParam(defaultValue= "25", required= false) int limit) { logger.debug("get Co Proprietaire - parcelle : " + parcelle); Map finalResult = new HashMap(); List> result = new ArrayList>(); - if (getUserCNILLevel(headers) > 0) { + if (getUserCNILLevel() > 0) { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); @@ -173,7 +173,7 @@ public Map getCoProprietaire(@QueryParam("parcelle") String parc queryCount.append(".co_propriete_parcelle propar, "); queryCount.append(databaseSchema); queryCount.append(".proprietaire p where propar.parcelle = ? and p.comptecommunal = propar.comptecommunal "); - queryCount.append(addAuthorizationFiltering(headers, "p.")); + queryCount.append(addAuthorizationFiltering("p.")); queryCount.append(" ) as temp;"); int resultCount = jdbcTemplate.queryForObject(queryCount.toString(), new Object[] {parcelle}, Integer.class); @@ -193,7 +193,7 @@ public Map getCoProprietaire(@QueryParam("parcelle") String parc queryBuilder.append(databaseSchema); queryBuilder.append(".proprietaire p where propar.parcelle = ? "); queryBuilder.append(" and p.comptecommunal = propar.comptecommunal "); - queryBuilder.append(addAuthorizationFiltering(headers, "p.")); + queryBuilder.append(addAuthorizationFiltering("p.")); queryBuilder.append(" ORDER BY p.app_nom_usage "); queryBuilder.append(" LIMIT ?"); queryBuilder.append(" OFFSET ?"); @@ -210,10 +210,7 @@ public Map getCoProprietaire(@QueryParam("parcelle") String parc } - - @POST - @Path("/exportCoProprietaireByParcelles") - @Produces("text/csv") + @RequestMapping(path = "/exportCoProprietaireByParcelles", produces = {"text/csv;charset=utf-8"}, method= {RequestMethod.POST}) /** * Create a csv file from given parcelles id * @@ -224,18 +221,17 @@ public Map getCoProprietaire(@QueryParam("parcelle") String parc * * @throws SQLException */ - public Response exportProprietaireByParcelles( - @Context HttpHeaders headers, - @FormParam("parcelles") String parcelles) throws SQLException { + public ResponseEntity exportProprietaireByParcelles( + @RequestParam String parcelles) throws SQLException { // Create empty content - ResponseBuilder response = Response.noContent(); + ResponseEntity response = new ResponseEntity<>(HttpStatus.NO_CONTENT); // User need to be at least CNIL1 level - if (getUserCNILLevel(headers)>0){ + if (getUserCNILLevel()>0){ String entete = "proprio_id;droit_reel_libelle;denomination_usage;parcelles;civilite;nom_usage;prenom_usage;denomination_naissance;nom_naissance;prenom_naissance;adresse_ligne3;adresse_ligne4;adresse_ligne5;adresse_ligne6;forme_juridique"; - if(getUserCNILLevel(headers)>1){ + if(getUserCNILLevel()>1){ entete = entete + ";lieu_naissance; date_naissance"; } @@ -252,7 +248,7 @@ public Response exportProprietaireByParcelles( queryBuilder.append("select prop.comptecommunal, ccodro_lib, app_nom_usage, string_agg(parcelle, ','), ccoqua_lib, dnomus, dprnus, ddenom, dnomlp, dprnlp, dlign3, dlign4, dlign5, dlign6, dformjur "); // If user is CNIL2 add birth information - if(getUserCNILLevel(headers)>1){ + if(getUserCNILLevel()>1){ queryBuilder.append(", dldnss, jdatnss "); } queryBuilder.append("from "); @@ -262,10 +258,10 @@ public Response exportProprietaireByParcelles( queryBuilder.append(".co_propriete_parcelle proparc "); queryBuilder.append(createWhereInQuery(parcelleList.length, "proparc.parcelle")); queryBuilder.append(" and prop.comptecommunal = proparc.comptecommunal "); - queryBuilder.append(addAuthorizationFiltering(headers)); + queryBuilder.append(addAuthorizationFiltering()); queryBuilder.append("GROUP BY prop.comptecommunal, ccodro_lib, app_nom_usage, ccoqua_lib, dnomus, dprnus, ddenom, dnomlp, dprnlp, dlign3, dlign4, dlign5, dlign6, dformjur"); // If user is CNIL2 add birth information - if(getUserCNILLevel(headers)>1){ + if(getUserCNILLevel()>1){ queryBuilder.append(", dldnss, jdatnss "); } queryBuilder.append(" ORDER BY prop.comptecommunal"); @@ -280,8 +276,9 @@ public Response exportProprietaireByParcelles( file = exportHelper.createCSV(coproprietaires, entete); // build csv response - response = Response.ok((Object) file); - response.header("Content-Disposition", "attachment; filename=" + file.getName()); + HttpHeaders headers = new HttpHeaders(); + headers.setContentDispositionFormData("filename", file.getName()); + response = new ResponseEntity<>(FileUtils.readFileToByteArray(file), headers, HttpStatus.OK); }catch (IOException e) { logger.error("Error while creating CSV files ", e); } finally { @@ -298,12 +295,10 @@ public Response exportProprietaireByParcelles( logger.info("User does not have rights to see thoses informations"); } - return response.build(); + return response; } - @POST - @Path("/exportLotsAsCSV") - @Produces("text/csv") + @RequestMapping(path = "/exportLotsAsCSV", produces = {"text/csv;charset=utf-8"}, method= {RequestMethod.POST}) /** * Create a csv file from given plot and building id * @@ -315,14 +310,14 @@ public Response exportProprietaireByParcelles( * * @throws SQLException */ - public Response exportLotsAsSCV( - @Context HttpHeaders headers, - @FormParam("parcelle") String parcelle, @FormParam("dnubat") String dnubat) throws SQLException { + public ResponseEntity exportLotsAsSCV( + @RequestParam String parcelle, + @RequestParam String dnubat) throws SQLException { // Create empty content - ResponseBuilder response = Response.noContent(); + ResponseEntity response = new ResponseEntity<>(HttpStatus.NO_CONTENT); - if(getUserCNILLevel(headers)>0){ + if(getUserCNILLevel()>0){ logger.debug("Input parameters are : " + parcelle + " - " + dnubat); String entete = "parcelle_num;numero_local;batiment;numero_lot;part_lot;total_lot;logement;dependance;local_commercial;type_proprietaire;compte_communal;nom_proprietaire;adresse"; @@ -335,8 +330,9 @@ public Response exportLotsAsSCV( file = exportHelper.createCSV(bundleResults, entete); // build csv response - response = Response.ok((Object) file); - response.header("Content-Disposition", "attachment; filename=" + file.getName()); + HttpHeaders headers = new HttpHeaders(); + headers.setContentDispositionFormData("filename", file.getName()); + response = new ResponseEntity<>(FileUtils.readFileToByteArray(file), headers, HttpStatus.OK); }catch (IOException e) { logger.error("Error while creating CSV files ", e); } finally { @@ -348,12 +344,10 @@ public Response exportLotsAsSCV( logger.info("User does not have rights to see thoses informations"); } - return response.build(); + return response; } - @POST - @Path("/exportLotsAsPDF") - @Produces("application/pdf") + @RequestMapping(path = "/exportLotsAsPDF" , produces = {MediaType.APPLICATION_PDF_VALUE}, method= {RequestMethod.POST}) /** * Create a pdf file from given plot and building id * @@ -365,14 +359,14 @@ public Response exportLotsAsSCV( * * @throws SQLException */ - public Response exportLotsAsPDF( - @Context HttpHeaders headers, - @FormParam("parcelle") String parcelle, @FormParam("dnubat") String dnubat) throws SQLException { + public ResponseEntity exportLotsAsPDF( + @RequestParam String parcelle, + @RequestParam String dnubat) throws SQLException { // Create empty content - ResponseBuilder response = Response.noContent(); + ResponseEntity response = new ResponseEntity<>(HttpStatus.NO_CONTENT); - if(getUserCNILLevel(headers)>0){ + if(getUserCNILLevel()>0){ logger.debug("Input parameters are : " + parcelle + " - " + dnubat); final String xslTemplate = "xsl/lots.xsl"; @@ -457,11 +451,13 @@ public Response exportLotsAsPDF( transformerPDF.transform(src, res); out.close(); - + // Create response - response = Response.ok((Object) pdfResult); - response.header("Content-Disposition", "attachment; filename=" + pdfResult.getName()); + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_PDF); + headers.setContentDispositionFormData("filename", pdfResult.getName()); + response = new ResponseEntity<>(FileUtils.readFileToByteArray(pdfResult), headers, HttpStatus.OK); } catch (JAXBException jaxbException) { logger.warn("Error during converting object to xml : " + jaxbException); } catch (TransformerException transformerException) { @@ -503,6 +499,6 @@ public Response exportLotsAsPDF( logger.info("User does not have rights to see thoses informations"); } - return response.build(); + return response; } } diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/CommuneController.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/CommuneController.java index fdf73e90..c1e65ba8 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/CommuneController.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/CommuneController.java @@ -4,27 +4,24 @@ import java.util.List; import java.util.Map; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.HttpHeaders; - -import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Controller; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +@Controller public class CommuneController extends CadController{ final static Logger logger = LoggerFactory.getLogger(CommuneController.class); - @Path("/getCommune/") - @GET - @Produces("application/json") + @RequestMapping(path = "/getCommune/", produces = {MediaType.APPLICATION_JSON_VALUE}, method= {RequestMethod.GET}) /** * /getCommune * @@ -41,10 +38,9 @@ public class CommuneController extends CadController{ * * @throws SQLException */ - public List> getCommunesList( - @Context HttpHeaders headers, - @QueryParam("libcom") String libCom, - @QueryParam("cgocommune") String cgoCommune){ + public @ResponseBody List> getCommunesList( + @RequestParam(name= "libcom", required= false) String libCom, + @RequestParam(name= "cgocommune", required= false) String cgoCommune){ List> communes = new ArrayList>(); List queryParams = new ArrayList(); @@ -86,7 +82,7 @@ public List> getCommunesList( } if(isSearchFiltered){ - queryBuilder.append(addAuthorizationFiltering(headers)); + queryBuilder.append(addAuthorizationFiltering()); } queryBuilder.append(" order by libcom "); diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/ConfigurationController.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/ConfigurationController.java index c0c36796..ebd581c8 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/ConfigurationController.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/ConfigurationController.java @@ -3,30 +3,28 @@ import java.util.HashMap; import java.util.Map; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; - import org.georchestra.cadastrapp.configuration.CadastrappPlaceHolder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; +@Controller public class ConfigurationController { final static Logger logger = LoggerFactory.getLogger(ConfigurationController.class); - - @GET - @Path("/getConfiguration") - @Produces(MediaType.APPLICATION_JSON) + @RequestMapping(path = "/getConfiguration", produces = {MediaType.APPLICATION_JSON_VALUE}, method= {RequestMethod.GET}) /** * Returns server configuration witch is common to client side * * @return JSON list */ - public Map getConfiguration(){ + public @ResponseBody Map getConfiguration(){ Map configuration = new HashMap(); diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/DatadirController.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/DatadirController.java index 6d502487..130c085e 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/DatadirController.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/DatadirController.java @@ -5,17 +5,20 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; import java.io.File; import java.io.FileInputStream; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - - +@Controller public class DatadirController extends CadController { static final Logger logger = LoggerFactory.getLogger(DatadirController.class); @@ -102,31 +105,34 @@ private String imageToString(String nameImage){ * * @return Response that contain File */ - @POST - @Path("/getImageFromDataDir") - public Response getBaseMapPreview(@RequestParam("imageName") String imageName) { + @RequestMapping(path = "/getImageFromDataDir", produces = {MediaType.TEXT_PLAIN_VALUE}, method= {RequestMethod.POST}) + public ResponseEntity getBaseMapPreview(@RequestParam("imageName") String imageName) { + String encodedImage; String encodedErrorImage; - // use to find mime type try{ // return image as data base64 encodedImage = imageToString(imageName); + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.TEXT_PLAIN); + if(encodedImage != null){ - return Response.ok(encodedImage,MediaType.TEXT_PLAIN).build(); + return new ResponseEntity(encodedImage, headers, HttpStatus.OK); } else { // return image error as data base64 encodedErrorImage = imageToString("error.png"); if(encodedErrorImage != null){ logger.error("File not exist or fail to encode file : display error image"); - return Response.ok(encodedErrorImage,MediaType.TEXT_PLAIN).build(); + return new ResponseEntity(encodedErrorImage, headers, HttpStatus.OK); } else { - return Response.status(Response.Status.NOT_FOUND).entity("Image not found for : " + imageName).build(); + return ResponseEntity.status(HttpStatus.NOT_FOUND).body(("Image not found for : " + imageName)); } } } catch (Exception e){ - // response with bad request error - return Response.status(Response.Status.BAD_REQUEST).entity(e).build(); + // response with bad request error + logger.error("Error while getting image from datadir", e); + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage()); } } diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/HabitationController.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/HabitationController.java index 2c5d5b91..a6db6f60 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/HabitationController.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/HabitationController.java @@ -5,17 +5,19 @@ import java.util.List; import java.util.Map; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MediaType; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.http.MediaType; import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +import org.georchestra.cadastrapp.service.constants.CadastrappConstants; /** * HabitationController @@ -25,35 +27,31 @@ * @author pierre * */ +@Controller public class HabitationController extends CadController { static final Logger logger = LoggerFactory.getLogger(HabitationController.class); - - @GET - @Path("/getHabitationDetails") - @Produces(MediaType.APPLICATION_JSON) + @RequestMapping(path = "/getHabitationDetails", produces = {MediaType.APPLICATION_JSON_VALUE}, method= {RequestMethod.GET}) /** * Returns information about habitation * - * @param headers HttpHeaders http headers used - * information will only be return if user is CNIL2 * @param annee String corresponding to year of wanted information (normally only current year available) * @param invar String id habitation * * @return Map containing informations from article 40 50 and 60, * empty list if missing input parameter or if user doesn't have privilege */ - public Map getHabitationDetails(@Context HttpHeaders headers, - @QueryParam("annee") String annee, - @QueryParam("invar") String invar){ + public @ResponseBody Map getHabitationDetails( + @RequestParam String annee, + @RequestParam String invar){ Map habitationDesc = new HashMap(); List queryParams = new ArrayList(); queryParams.add(annee); queryParams.add(invar); - if (getUserCNILLevel(headers) == 0) { + if (getUserCNILLevel() == 0) { logger.info("User needs does not have enough rights to see habitation details"); } else if(annee != null && invar != null) @@ -74,7 +72,7 @@ else if(annee != null && invar != null) * @param queryParams List composed with year and invar information * @return List> */ - private List> getArticle40Details(List queryParams){ + private @ResponseBody List> getArticle40Details(List queryParams){ logger.debug("getArticle40Details"); StringBuilder queryBuilder = new StringBuilder(); diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/ImageParcelleController.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/ImageParcelleController.java index 1ff94b18..d36f28c9 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/ImageParcelleController.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/ImageParcelleController.java @@ -18,41 +18,38 @@ import java.util.Map; import javax.imageio.ImageIO; -import javax.ws.rs.DefaultValue; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.ResponseBuilder; import javax.xml.transform.TransformerException; import org.georchestra.cadastrapp.configuration.CadastrappPlaceHolder; +import org.geotools.data.DataStore; import org.geotools.data.ows.HTTPClient; -import org.geotools.data.ows.Layer; import org.geotools.data.ows.SimpleHttpClient; import org.geotools.data.simple.SimpleFeatureCollection; import org.geotools.data.simple.SimpleFeatureIterator; import org.geotools.data.simple.SimpleFeatureSource; -import org.geotools.data.wfs.impl.WFSContentDataStore; -import org.geotools.data.wfs.impl.WFSDataStoreFactory; -import org.geotools.data.wms.WebMapServer; -import org.geotools.data.wms.request.GetMapRequest; -import org.geotools.data.wms.response.GetMapResponse; +import org.geotools.data.wfs.WFSDataStoreFactory; import org.geotools.factory.CommonFactoryFinder; import org.geotools.filter.text.cql2.CQL; import org.geotools.filter.text.cql2.CQLException; import org.geotools.geometry.jts.JTS; import org.geotools.ows.ServiceException; +import org.geotools.ows.wms.Layer; +import org.geotools.ows.wms.WebMapServer; +import org.geotools.ows.wms.request.GetMapRequest; +import org.geotools.ows.wms.response.GetMapResponse; import org.geotools.styling.FeatureTypeStyle; import org.geotools.styling.Fill; import org.geotools.styling.NamedLayer; import org.geotools.styling.PolygonSymbolizer; import org.geotools.styling.Rule; -import org.geotools.styling.SLDTransformer; import org.geotools.styling.Stroke; import org.geotools.styling.Style; import org.geotools.styling.StyledLayerDescriptor; +import org.geotools.xml.styling.SLDTransformer; +import org.locationtech.jts.geom.Coordinate; +import org.locationtech.jts.geom.Envelope; +import org.locationtech.jts.geom.Geometry; +import org.locationtech.jts.geom.Point; import org.opengis.filter.Filter; import org.opengis.filter.FilterFactory2; import org.opengis.feature.simple.SimpleFeature; @@ -61,18 +58,21 @@ import org.opengis.referencing.operation.TransformException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -import com.vividsolutions.jts.geom.Coordinate; -import com.vividsolutions.jts.geom.Envelope; -import com.vividsolutions.jts.geom.Geometry; -import com.vividsolutions.jts.geom.Point; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; /** * Image Parcelle Controller * - * @author gfi + * @author pierre jego * */ +@Controller public class ImageParcelleController extends CadController { static final Logger logger = LoggerFactory.getLogger(ImageParcelleController.class); @@ -100,18 +100,17 @@ public class ImageParcelleController extends CadController { * @param baseMapIndex corresponding of the wanted index in cadastrapp.properties * @return Response with noContent in case of error, png otherwise */ - @GET - @Path("/getImageBordereau") - @Produces("image/png") - public Response createImageBordereauParcellaire(@QueryParam("parcelle") String parcelle, - @DefaultValue("0") @QueryParam("basemapindex") int baseMapIndex, - @DefaultValue("1446DE") @QueryParam("fillcolor") String styleFillColor, - @DefaultValue("0.50") @QueryParam("fillopacity") float styleFillOpacity, - @DefaultValue("10259E") @QueryParam("strokecolor") String styleStrokeColor, - @DefaultValue("2") @QueryParam("strokewidth") int styleStrokeWidth) { + @RequestMapping(path = "/getImageBordereau", produces = {MediaType.IMAGE_PNG_VALUE}, method= {RequestMethod.GET}) + public ResponseEntity createImageBordereauParcellaire( + @RequestParam() String parcelle, + @RequestParam(defaultValue = "0", name ="basemapindex", required = false) int baseMapIndex, + @RequestParam(defaultValue = "1446DE", name ="fillcolor", required = false) String styleFillColor, + @RequestParam(defaultValue = "0.50", name ="fillopacity", required = false) float styleFillOpacity, + @RequestParam(defaultValue = "10259E", name ="strokecolor", required = false) String styleStrokeColor, + @RequestParam(defaultValue = "2", name ="strokewidth", required = false) int styleStrokeWidth) { // Create empty reponse for default value - ResponseBuilder response = Response.noContent(); + ResponseEntity response = new ResponseEntity(HttpStatus.NO_CONTENT); final int parcelleIdLength = Integer.parseInt(CadastrappPlaceHolder.getProperty("parcelleId.length")); @@ -143,7 +142,7 @@ public Response createImageBordereauParcellaire(@QueryParam("parcelle") String p } WFSDataStoreFactory dsf = new WFSDataStoreFactory(); - WFSContentDataStore dataStore; + DataStore dataStore; try { dataStore = dsf.createDataStore(connectionParameters); @@ -383,7 +382,7 @@ public Response createImageBordereauParcellaire(@QueryParam("parcelle") String p file.deleteOnExit(); ImageIO.write(finalImage, "png", file); - response = Response.ok((Object) file); + response = new ResponseEntity(file, HttpStatus.OK); } else { logger.info("No plots corresponding on WFS server"); } @@ -401,7 +400,7 @@ public Response createImageBordereauParcellaire(@QueryParam("parcelle") String p logger.info("No image can be generated with given input parameters"); } - return response.build(); + return response; } /** diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/InfoBulleController.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/InfoBulleController.java index d4c371df..089e864e 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/InfoBulleController.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/InfoBulleController.java @@ -5,32 +5,29 @@ import java.util.List; import java.util.Map; -import javax.ws.rs.DefaultValue; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MediaType; +import org.georchestra.cadastrapp.service.constants.CadastrappConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.dao.EmptyResultDataAccessException; +import org.springframework.http.MediaType; import org.springframework.jdbc.core.JdbcTemplate; - - +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.ResponseBody; + +@Controller public class InfoBulleController extends CadController { final static Logger logger = LoggerFactory.getLogger(InfoBulleController.class); - @Path("/getInfoBulle") - @GET - @Produces(MediaType.APPLICATION_JSON) + @RequestMapping(path = "/getInfoBulle", produces = {MediaType.APPLICATION_JSON_VALUE}, method= {RequestMethod.GET}) /** - * - * @param headers / headers from request used to filter search using LDAP Roles to display only information about parcelle from available cgocommune * * @param parcelle id parcelle * @param infocadastrale 1 to get additional information, 0 to avoid getting additional information (default value 1 if not set) @@ -40,44 +37,38 @@ public class InfoBulleController extends CadController { * * @throws SQLException */ - public Map getInfoBulle( - @Context HttpHeaders headers, - @QueryParam("parcelle") String parcelle, - @DefaultValue("1") @QueryParam("infocadastrale") int infocadastrale, - @DefaultValue("1") @QueryParam("infouf") int infouf) throws SQLException { + public @ResponseBody Map getInfoBulle( + @RequestParam String parcelle, + @RequestParam(defaultValue = "1", required = false) int infocadastrale, + @RequestParam(defaultValue = "1", required = false) int infouf) throws SQLException { Map informations = null; if(infocadastrale == 0 && infouf == 1){ - informations = getInfoBulleUniteFonciere(headers, parcelle); + informations = getInfoBulleUniteFonciere(parcelle); }else if (infocadastrale == 1 && infouf == 0){ - informations = getInfoBulleParcelle(headers, parcelle); + informations = getInfoBulleParcelle(parcelle); }else if (infocadastrale == 0 && infouf == 0){ logger.warn("No information can be serve"); }else{ - informations = getInfoBulleParcelle(headers, parcelle); - informations.putAll(getInfoBulleUniteFonciere(headers, parcelle)); + informations = getInfoBulleParcelle(parcelle); + informations.putAll(getInfoBulleUniteFonciere(parcelle)); } return informations; } - @Path("/getInfobulleParcelle") - @GET - @Produces("application/json") + @RequestMapping(path = "/getInfobulleParcelle", produces = {MediaType.APPLICATION_JSON_VALUE}, method= {RequestMethod.GET}) /** - * - * @param headers / headers from request used to filter search using LDAP Roles to display only information about parcelle from available cgocommune * * @param parcelle id parcelle * @return Data from parcelle view to be display in popup in JSON format * * @throws SQLException */ - public Map getInfoBulleParcelle( - @Context HttpHeaders headers, - @QueryParam("parcelle") String parcelle) throws SQLException { + public @ResponseBody Map getInfoBulleParcelle( + @RequestParam("parcelle") String parcelle) throws SQLException { Map informations = null; @@ -98,7 +89,7 @@ public Map getInfoBulleParcelle( JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); informations = jdbcTemplate.queryForMap(queryBuilder.toString(), parcelle); - if(getUserCNILLevel(headers)>0){ + if(getUserCNILLevel()>0){ List> proprietaires = null; @@ -110,7 +101,7 @@ public Map getInfoBulleParcelle( queryProprietaireBuilder.append(databaseSchema); queryProprietaireBuilder.append(".proprietaire prop "); queryProprietaireBuilder.append(" where proparc.parcelle = ? and proparc.comptecommunal = prop.comptecommunal "); - queryProprietaireBuilder.append(addAuthorizationFiltering(headers, "prop.")); + queryProprietaireBuilder.append(addAuthorizationFiltering("prop.")); queryProprietaireBuilder.append(" LIMIT 9"); JdbcTemplate jdbcTemplateProp = new JdbcTemplate(dataSource); @@ -129,21 +120,16 @@ public Map getInfoBulleParcelle( return informations; } - @Path("/getInfoUniteFonciere") - @GET - @Produces(MediaType.APPLICATION_JSON) + @RequestMapping(path = "/getInfoUniteFonciere", produces = {MediaType.APPLICATION_JSON_VALUE}, method= {RequestMethod.GET}) /** - * - * @param headers / headers from request used to filter search using LDAP Roles to display only information about parcelle from available cgocommune - * + * * @param parcelle id parcelle * @return Data from parcelle view to be display in popup in JSON format * * @throws SQLException */ - public Map getInfoBulleUniteFonciere( - @Context HttpHeaders headers, - @QueryParam("parcelle") String parcelle) throws SQLException { + public @ResponseBody Map getInfoBulleUniteFonciere( + @RequestParam("parcelle") String parcelle) throws SQLException { Map informations = new HashMap(); @@ -163,7 +149,7 @@ public Map getInfoBulleUniteFonciere( // filter on geographical limitation only if search is filtered if(isSearchFiltered){ - queryBuilder.append(addAuthorizationFiltering(headers, "p.")); + queryBuilder.append(addAuthorizationFiltering("p.")); } queryBuilder.append("GROUP BY uf.uf, uf.comptecommunal;"); diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/ParcelleController.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/ParcelleController.java index fb58a9df..53fbfc3b 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/ParcelleController.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/ParcelleController.java @@ -10,35 +10,39 @@ import java.util.List; import java.util.Map; -import javax.ws.rs.Consumes; -import javax.ws.rs.DefaultValue; -import javax.ws.rs.FormParam; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.ResponseBuilder; - -import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; -import org.codehaus.jackson.map.ObjectMapper; -import org.codehaus.jackson.map.ObjectWriter; import org.georchestra.cadastrapp.model.pdf.ExtFormResult; import org.georchestra.cadastrapp.service.export.ExportHelper; +import org.georchestra.cadastrapp.service.constants.CadastrappConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Controller; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; + +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; /** * Parcelle controller expose all rest service for plots information */ +@Api( description="Récupération des informations de parcelles") +@Controller public class ParcelleController extends CadController { static final Logger logger = LoggerFactory.getLogger(ParcelleController.class); @@ -46,48 +50,33 @@ public class ParcelleController extends CadController { @Autowired ExportHelper exportHelper; - @GET - @Path("/getParcelle") - @Produces(MediaType.APPLICATION_JSON) + @ApiOperation(value = "Récupère la liste des parcelles") + @RequestMapping(path = "/getParcelle", produces = {MediaType.APPLICATION_JSON_VALUE}, method = { RequestMethod.GET, RequestMethod.POST }) /** * Works like {@link #getParcelle} */ - public List> getParcelleGET(@Context HttpHeaders headers, @QueryParam("parcelle") final List parcelleList, @DefaultValue("0") @QueryParam("details") int details, @QueryParam("cgocommune") String cgoCommune, @QueryParam("ccopre") String ccopre, @QueryParam("ccosec") String ccosec, @QueryParam("dnupla") String dnupla, - @QueryParam("dnvoiri") String dnvoiri, @QueryParam("dlindic") String dindic, @QueryParam("cconvo") String cconvo, @QueryParam("dvoilib") String dvoilib, @QueryParam("comptecommunal") final List comptecommunalList, @DefaultValue("0") @QueryParam("unitefonciere") int uf) throws SQLException { - - return getParcelle(headers, parcelleList, details, cgoCommune, ccopre, ccosec, dnupla, dnvoiri, dindic, cconvo, dvoilib, comptecommunalList, uf); - } - - @POST - @Path("/getParcelle") - @Produces(MediaType.APPLICATION_JSON) - /** - * Works like {@link #getParcelle} - */ - public List> getParcellePOST(@Context HttpHeaders headers, - @FormParam("parcelle") final List parcelleList, - @DefaultValue("0") @FormParam("details") int details, - @FormParam("cgocommune") String cgoCommune, - @FormParam("ccopre") String ccopre, - @FormParam("ccosec") String ccosec, - @FormParam("dnupla") String dnupla, - @FormParam("dnvoiri") String dnvoiri, - @FormParam("dlindic") String dindic, - @FormParam("cconvo") String cconvo, - @FormParam("dvoilib") String dvoilib, - @FormParam("comptecommunal") final List comptecommunalList, - @DefaultValue("0") @FormParam("unitefonciere") int uf) throws SQLException { - - return getParcelle(headers, parcelleList, details, cgoCommune, ccopre, ccosec, dnupla, dnvoiri, dindic, cconvo, dvoilib, comptecommunalList, uf); - + public @ResponseBody List> getParcelleEntrypoint( + @RequestParam(name = "parcelle", required = false) final List parcelleList, + @RequestParam(defaultValue = "0", required = false) int details, + @RequestParam(name ="cgocommune", required = false) String cgoCommune, + @RequestParam(required = false) String ccopre, + @RequestParam(required = false) String ccosec, + @RequestParam(required = false) String dnupla, + @RequestParam(required = false) String dnvoiri, + @RequestParam(name = "dlindic", required = false) String dindic, + @RequestParam(required = false) String cconvo, + @RequestParam(required = false) String dvoilib, + @RequestParam(name = "comptecommunal", required = false) final List comptecommunalList, + @RequestParam(name = "unitefonciere", defaultValue = "0", required = false) int uf) throws SQLException { + + return getParcelle(parcelleList, details, cgoCommune, ccopre, ccosec, dnupla, dnvoiri, dindic, cconvo, dvoilib, comptecommunalList, uf); } - + /** * * getParcelle * - * @param headers http headers, used to get ldap role information about the user group * @param parcelleList * could be LIST if one or more element, if only one in the list, * this element could contains list of parcelleids separated by @@ -118,7 +107,7 @@ public List> getParcellePOST(@Context HttpHeaders headers, * * @throws SQLException */ - private List> getParcelle(HttpHeaders headers,final List parcelleList, int details,String cgoCommune, + private List> getParcelle(final List parcelleList, int details,String cgoCommune, String ccopre, String ccosec, String dnupla, String dnvoiri, String dindic, String cconvo, String dvoilib, final List comptecommunalList, int uf) throws SQLException { List> parcellesResult = new ArrayList>(); @@ -127,17 +116,17 @@ private List> getParcelle(HttpHeaders headers,final List parsedParcelleList = prepareParcelleList(parcelleList); - parcellesResult = getParcellesById(parsedParcelleList, details, getUserCNILLevel(headers)); + parcellesResult = getParcellesById(parsedParcelleList, details, getUserCNILLevel()); // Search by Proprietaire } else if (comptecommunalList != null && !comptecommunalList.isEmpty()) { - parcellesResult = getParcellesByProprietaire(comptecommunalList, details, getUserCNILLevel(headers)); + parcellesResult = getParcellesByProprietaire(comptecommunalList, details, getUserCNILLevel()); // Search by unitefonciere } else if (uf != 0) { - parcellesResult = getParcellesByUniteFonciere(uf, details, getUserCNILLevel(headers)); + parcellesResult = getParcellesByUniteFonciere(uf, details, getUserCNILLevel()); // Search by attributes } else { @@ -380,17 +369,18 @@ private String createSelectParcelleQuery(int details) { /** * Service witch use csv file as input * - * @param headers http headers information + * @param roleList fromhttp headers information * @param fileContent * parcelleId separated by space, ',' or ';' * * @return Json data, with corresponding parcelleId information * */ - @POST - @Path("/fromParcellesFile") - @Consumes(MediaType.MULTIPART_FORM_DATA) - public Response getFromParcellesFile(@Context HttpHeaders headers, @FormParam("filePath") String fileContent) { + @RequestMapping(path = "/fromParcellesFile", consumes = {"multipart/form-data" }, method = {RequestMethod.POST }) + public ResponseEntity getFromParcellesFile( + @RequestParam(name = "filePath") String fileContent) { + + ResponseEntity response = new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); // space, , or ; String delimitersRegex = "[\\s\\;\\,\\n]"; @@ -425,7 +415,7 @@ public Response getFromParcellesFile(@Context HttpHeaders headers, @FormParam("f // Avoid make request if no parcelle id is given if (parcelleList != null && !parcelleList.isEmpty()) { - parcellesResult = getParcellesById(parcelleList, 0, getUserCNILLevel(headers)); + parcellesResult = getParcellesById(parcelleList, 0, getUserCNILLevel()); } else { logger.warn("No information given to create csv"); } @@ -434,32 +424,37 @@ public Response getFromParcellesFile(@Context HttpHeaders headers, @FormParam("f // success=true) ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); String json = ow.writeValueAsString(new ExtFormResult(true, parcellesResult)); - return Response.ok(json, MediaType.TEXT_HTML).build(); + + // Create response + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.TEXT_HTML); + response = new ResponseEntity<>(json, headers, HttpStatus.OK); } catch (IOException e) { logger.error("Error while trying to read input data ", e); - return Response.serverError().build(); } catch (SQLException e) { logger.error("Error while trying to get information from database ", e); - return Response.serverError().build(); } + return response; } /** * Get export of parcelle for given comptecommunal * - * @param headers + * @param rolesList * make sure user have CNIL level * @param details 1 to have detailed information * @param city cgocommune information from form * @param fileContent file content * @return form validation */ - @POST - @Path("/fromProprietairesFile") - @Consumes(MediaType.MULTIPART_FORM_DATA) - public Response getFromProprietairesFile(@Context HttpHeaders headers, @DefaultValue("0") @FormParam("details") int details, @FormParam("cgocommune") String city, @FormParam("filePath") String fileContent) { + @RequestMapping(path = "/fromProprietairesFile", consumes = {"multipart/form-data"}, method = {RequestMethod.POST }) + public ResponseEntity getFromProprietairesFile( + @RequestParam(defaultValue = "0", required = false) int details, + @RequestParam(name = "filePath") String fileContent) { + + ResponseEntity response = new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); if (logger.isDebugEnabled()) { logger.debug("csv content : " + fileContent); @@ -493,7 +488,7 @@ public Response getFromProprietairesFile(@Context HttpHeaders headers, @DefaultV // Avoid call without parameter if (proprietaireList != null && !proprietaireList.isEmpty()) { - ownersResult = getParcellesByProprietaire(proprietaireList, details, getUserCNILLevel(headers)); + ownersResult = getParcellesByProprietaire(proprietaireList, details, getUserCNILLevel()); } else { logger.warn("No information given to get CompteCommunal information"); } @@ -501,21 +496,24 @@ public Response getFromProprietairesFile(@Context HttpHeaders headers, @DefaultV // les forms ExtJs attendent du JSON sous format TEXT/HTML... (avec success=true) ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); String json = ow.writeValueAsString(new ExtFormResult(true, ownersResult)); - return Response.ok(json, MediaType.TEXT_HTML).build(); + + // Create response + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.TEXT_HTML); + response = new ResponseEntity<>(json, headers, HttpStatus.OK); + } catch (IOException e) { logger.error("Error while trying to read input data ", e); - return Response.serverError().build(); } + return response; } - @GET - @Path("/getDnuplaList") - @Produces("application/json") + @ResponseBody + @RequestMapping(path = "/getDnuplaList", produces = {MediaType.APPLICATION_JSON_VALUE}, method = { RequestMethod.GET}) /** * Return only dnupla list from a section of a commune * - * @param headers http headers, used to get ldap role information about the user group * @param cgocommune code commune INSEE * @param ccopre prefix de section * @param ccosec code de section @@ -523,7 +521,10 @@ public Response getFromProprietairesFile(@Context HttpHeaders headers, @DefaultV * * @throws SQLException */ - public List> getDnuplaList(@Context HttpHeaders headers, @QueryParam("cgocommune") String cgoCommune, @QueryParam("ccopre") String ccopre, @QueryParam("ccosec") String ccosec) throws SQLException { + public List> getDnuplaList( + @RequestParam(name= "cgocommune", required= false) String cgoCommune, + @RequestParam(required= false) String ccopre, + @RequestParam(required= false) String ccosec) throws SQLException { List> dnuplaList = null; List queryParams = new ArrayList(); @@ -543,26 +544,22 @@ public List> getDnuplaList(@Context HttpHeaders headers, @Qu return dnuplaList; } - - @POST - @Path("/exportParcellesAsCSV") - @Produces("text/csv") + + @RequestMapping(path = "/exportParcellesAsCSV", produces = {"text/csv;charset=utf-8"}, method = {RequestMethod.POST }) /** * Create a csv file from given parcelles id * - * @param headers Used to filter displayed information * @param parcelles list of parcelle separated by a coma * * @return csv containing list of owners * * @throws SQLException */ - public Response exportParcellesAsSCV( - @Context HttpHeaders headers, - @FormParam("parcelles") String parcelles) throws SQLException { + public ResponseEntity exportParcellesAsSCV( + @RequestParam String parcelles) throws SQLException { // Create empty content - ResponseBuilder response = Response.noContent(); + ResponseEntity response = new ResponseEntity<>(HttpStatus.NO_CONTENT); String entete = "parcelle; commune;voie_adr;voie_adr_cplmt;voie_type;voie_nom;section_prefixe;section;parcelle_num;contenance"; @@ -575,15 +572,18 @@ public Response exportParcellesAsSCV( logger.debug("Nb of parcelles to search in : " + parcelleList.size()); // Get value from database - List> parcellesResult = getParcellesById(parcelleList, 0, getUserCNILLevel(headers)); + List> parcellesResult = getParcellesById(parcelleList, 0, getUserCNILLevel()); File file = null; try{ file = exportHelper.createCSV(parcellesResult, entete); // build csv response - response = Response.ok((Object) file); - response.header("Content-Disposition", "attachment; filename=" + file.getName()); + // build csv response + HttpHeaders headers = new HttpHeaders(); + headers.setContentDispositionFormData("filename", file.getName()); + response = new ResponseEntity<>(FileUtils.readFileToByteArray(file), headers, HttpStatus.OK); + }catch (IOException e) { logger.error("Error while creating CSV files ", e); } finally { @@ -597,7 +597,7 @@ public Response exportParcellesAsSCV( logger.info("Parcelle Id List is empty nothing to search"); } - return response.build(); + return response; } } diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/ProprietaireController.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/ProprietaireController.java index f23e36fc..14cea02b 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/ProprietaireController.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/ProprietaireController.java @@ -8,28 +8,27 @@ import java.util.List; import java.util.Map; -import javax.ws.rs.DefaultValue; -import javax.ws.rs.FormParam; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.ResponseBuilder; - +import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; import org.georchestra.cadastrapp.configuration.CadastrappPlaceHolder; import org.georchestra.cadastrapp.helper.ProprietaireHelper; import org.georchestra.cadastrapp.service.export.ExportHelper; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +@Controller public class ProprietaireController extends CadController{ static final Logger logger = LoggerFactory.getLogger(ProprietaireController.class); @@ -41,9 +40,7 @@ public class ProprietaireController extends CadController{ @Autowired ProprietaireHelper proprietaireHelper; - @GET - @Path("/getProprietaire") - @Produces(MediaType.APPLICATION_JSON) + @RequestMapping(path = "/getProprietaire", produces = {MediaType.APPLICATION_JSON_VALUE}, method= {RequestMethod.GET}) /** * This will return information about owners in JSON format * @@ -74,16 +71,15 @@ public class ProprietaireController extends CadController{ * * @throws SQLException */ - public List> getProprietairesList( - @Context HttpHeaders headers, - @QueryParam("dnomlp") String dnomlp, - @QueryParam("cgocommune") String cgocommune, - @QueryParam("dnupro") final List dnuproList, - @QueryParam("comptecommunal") String compteCommunal, - @QueryParam("globalname") String globalName, - @QueryParam("ddenom") String ddenom, - @DefaultValue("false") @QueryParam("birthsearch") boolean isBirthSearch, - @DefaultValue("0") @QueryParam("details") int details + public @ResponseBody List> getProprietairesList( + @RequestParam(required = false) String dnomlp, + @RequestParam(required = false) String cgocommune, + @RequestParam(name= "dnupro", required = false) final List dnuproList, + @RequestParam(name= "comptecommunal", required = false) String compteCommunal, + @RequestParam(name= "globalname", required = false) String globalName, + @RequestParam(required = false) String ddenom, + @RequestParam(defaultValue = "0", name ="birthsearch", required = false) boolean isBirthSearch, + @RequestParam(defaultValue = "0", required = false) int details ) throws SQLException { // Init list to return response even if nothing in it. @@ -92,13 +88,13 @@ public List> getProprietairesList( logger.info("details : " + details); // User need to be at least CNIL1 level - if (getUserCNILLevel(headers)>0){ + if (getUserCNILLevel()>0){ int cgoCommuneLength = Integer.parseInt(CadastrappPlaceHolder.getProperty("cgoCommune.length")); - // No search if all parameters are null or dnomlpPariel less than n char + // No search if all parameters are null or dnomlp ddenom less than n char // when searching by dnupro, cgocommune is mandatory - // when searching bu dnomlp, cgocommune is mandatory + // when searching by dnomlp, cgocommune is mandatory if((dnomlp != null && !dnomlp.isEmpty() && minNbCharForSearch <= dnomlp.length() && cgocommune!=null && cgoCommuneLength == cgocommune.length()) || (globalName != null && !globalName.isEmpty() && minNbCharForSearch <= globalName.length() && cgocommune!=null && cgoCommuneLength == cgocommune.length()) || (ddenom != null && !ddenom.isEmpty() && minNbCharForSearch <= ddenom.length() && cgocommune!=null && cgoCommuneLength == cgocommune.length()) @@ -162,7 +158,7 @@ else if(details == 1){ isWhereAdded = createEqualsClauseRequest(isWhereAdded, queryBuilder, "comptecommunal", compteCommunal, queryParams); - queryBuilder.append(addAuthorizationFiltering(headers)); + queryBuilder.append(addAuthorizationFiltering()); if(details != 2){ queryBuilder.append("order by app_nom_usage, app_nom_naissance limit 25 "); @@ -182,15 +178,10 @@ else if(details == 1){ return proprietaires; } - - @GET - @Path("/getProprietairesByParcelles") - @Produces("application/json") + @RequestMapping(path = "/getProprietairesByParcelles", produces = {MediaType.APPLICATION_JSON_VALUE}, method= {RequestMethod.GET}) /** * This will return information about owners in JSON format * - * - * @param headers headers from request used to filter search using LDAP Roles * @param parcelleList * * @@ -198,22 +189,17 @@ else if(details == 1){ * * @throws SQLException */ - public List> getProprietairesByParcelle( - @Context HttpHeaders headers, - @QueryParam("parcelles") List parcelleList + public @ResponseBody List> getProprietairesByParcelle( + @RequestParam("parcelles") List parcelleList ) throws SQLException { - return proprietaireHelper.getProprietairesByParcelles(headers, parcelleList, true); + return proprietaireHelper.getProprietairesByParcelles(parcelleList, true); } - @GET - @Path("/getProprietairesByInfoParcelles") - @Produces("application/json") + @RequestMapping(path = "/getProprietairesByInfoParcelles", produces = {MediaType.APPLICATION_JSON_VALUE}, method= {RequestMethod.GET}) /** * This will return information about co-owners in JSON format * - * - * @param headers headers from request used to filter search using LDAP Roles * @param commune * @param section containing ccopre+ccosec * @param numero @@ -223,19 +209,18 @@ public List> getProprietairesByParcelle( * * @throws SQLException */ - public List> getProprietairesByInfoParcelle( - @Context HttpHeaders headers, - @QueryParam("commune") String commune, - @QueryParam("section") String section, - @QueryParam("numero") String numero, - @QueryParam("ddenom") String ddenom + public @ResponseBody List> getProprietairesByInfoParcelle( + @RequestParam(required = false) String commune, + @RequestParam(required = false) String section, + @RequestParam(required = false) String numero, + @RequestParam(required = false) String ddenom ) throws SQLException { // Init list to return response even if nothing in it. List> proprietaires = new ArrayList>();; // User need to be at least CNIL1 level - if (getUserCNILLevel(headers)>0){ + if (getUserCNILLevel()>0){ // if search by dnuproList or comptecommunal // directly search in view parcelle @@ -280,32 +265,28 @@ public List> getProprietairesByInfoParcelle( return proprietaires; } - - @POST - @Path("/exportProprietaireByParcelles") - @Produces("text/csv") + @RequestMapping(path = "/exportProprietaireByParcelles", produces = {"text/csv"}, method= {RequestMethod.POST}) /** * Create a csv file from given parcelles id * - * @param headers Used to filter displayed information + * @param rolesList Used to filter displayed information * @param parcelles list of parcelle separated by a coma * * @return csv containing list of owners * * @throws SQLException */ - public Response exportProprietaireByParcelles( - @Context HttpHeaders headers, - @FormParam("parcelles") String parcelles) throws SQLException { + public ResponseEntity exportProprietaireByParcelles( + @RequestParam String parcelles) throws SQLException { // Create empty content - ResponseBuilder response = Response.noContent(); + ResponseEntity response = new ResponseEntity(HttpStatus.NO_CONTENT); // User need to be at least CNIL1 level - if (getUserCNILLevel(headers)>0){ + if (getUserCNILLevel()>0){ String entete = "proprio_id;droit_reel_libelle;denomination_usage;parcelles;civilite;nom_usage;prenom_usage;denomination_naissance;nom_naissance;prenom_naissance;adresse_ligne3;adresse_ligne4;adresse_ligne5;adresse_ligne6;forme_juridique"; - if(getUserCNILLevel(headers)>1){ + if(getUserCNILLevel()>1){ entete = entete + ";lieu_naissance; date_naissance"; } @@ -322,7 +303,7 @@ public Response exportProprietaireByParcelles( queryBuilder.append("select prop.comptecommunal, ccodro_lib, app_nom_usage, string_agg(parcelle, ','), ccoqua_lib, dnomus, dprnus, ddenom, dnomlp, dprnlp, dlign3, dlign4, dlign5, dlign6, dformjur "); // If user is CNIL2 add birth information - if(getUserCNILLevel(headers)>1){ + if(getUserCNILLevel()>1){ queryBuilder.append(", dldnss, jdatnss "); } queryBuilder.append("from "); @@ -332,10 +313,10 @@ public Response exportProprietaireByParcelles( queryBuilder.append(".proprietaire_parcelle proparc "); queryBuilder.append(createWhereInQuery(parcelleList.length, "proparc.parcelle")); queryBuilder.append(" and prop.comptecommunal = proparc.comptecommunal "); - queryBuilder.append(addAuthorizationFiltering(headers)); + queryBuilder.append(addAuthorizationFiltering()); queryBuilder.append("GROUP BY prop.comptecommunal, ccodro_lib, app_nom_usage, ccoqua_lib, dnomus, dprnus, ddenom, dnomlp, dprnlp, dlign3, dlign4, dlign5, dlign6, dformjur"); // If user is CNIL2 add birth information - if(getUserCNILLevel(headers)>1){ + if(getUserCNILLevel()>1){ queryBuilder.append(", dldnss, jdatnss "); } queryBuilder.append(" ORDER BY prop.comptecommunal"); @@ -348,8 +329,10 @@ public Response exportProprietaireByParcelles( file = exportHelper.createCSV(proprietaires, entete); // build csv response - response = Response.ok((Object) file); - response.header("Content-Disposition", "attachment; filename=" + file.getName()); + HttpHeaders headers = new HttpHeaders(); + headers.setContentDispositionFormData("filename", file.getName()); + response = new ResponseEntity(FileUtils.readFileToByteArray(file), headers, HttpStatus.OK); + }catch (IOException e) { logger.error("Error while creating CSV files ", e); } finally { @@ -366,7 +349,7 @@ public Response exportProprietaireByParcelles( logger.info(ACCES_ERROR_LOG); } - return response.build(); + return response; } } diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/RequestInformationController.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/RequestInformationController.java index 4188e9d5..84a1c754 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/RequestInformationController.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/RequestInformationController.java @@ -10,14 +10,6 @@ import java.util.Map; import java.util.Set; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MediaType; - import org.georchestra.cadastrapp.model.request.InformationRequest; import org.georchestra.cadastrapp.model.request.ObjectRequest; import org.georchestra.cadastrapp.model.request.UserRequest; @@ -27,7 +19,15 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; - +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +@Controller public class RequestInformationController { final static Logger logger = LoggerFactory.getLogger(RequestInformationController.class); @@ -52,9 +52,7 @@ public class RequestInformationController { @Autowired UserRequestRepository userRepository; - @GET - @Path("/checkRequestLimitation") - @Produces(MediaType.APPLICATION_JSON) + @RequestMapping(path = "/checkRequestLimitation", produces = {MediaType.APPLICATION_JSON_VALUE}, method= {RequestMethod.GET}) /** * /checkRequestLimitation * @@ -68,7 +66,9 @@ public class RequestInformationController { * * @throws SQLException */ - public Map checkRequestLimitation(@QueryParam("cni") String cni, @QueryParam("type") String type, @Context HttpHeaders headers) throws SQLException { + public @ResponseBody Map checkRequestLimitation( + @RequestParam String cni, + @RequestParam String type) throws SQLException { Map result = new HashMap(); @@ -124,9 +124,7 @@ public Map checkRequestLimitation(@QueryParam("cni") String cni, return result; } - @GET - @Path("/saveInformationRequest") - @Produces(MediaType.APPLICATION_JSON) + @RequestMapping(path = "/saveInformationRequest", produces = {MediaType.APPLICATION_JSON_VALUE}, method= { RequestMethod.GET}) /** * /** * /saveInformationRequest @@ -167,10 +165,23 @@ public Map checkRequestLimitation(@QueryParam("cni") String cni, * * @throws SQLException */ - public Map saveInformationRequest(@QueryParam("cni") String cni, @QueryParam("type") String type, @QueryParam("adress") String adress, @QueryParam("commune") String commune, @QueryParam("codepostal") String codePostal, @QueryParam("firstname") String firstname, @QueryParam("lastname") String lastname, @QueryParam("mail") String mail, - @QueryParam("comptecommunaux") List compteCommunaux, @QueryParam("parcelleIds") List parcelleIds, @QueryParam("proprietaires") List proprietaires, @QueryParam("parcelles") List parcelles, @QueryParam("coproprietes") List coProprietes, @QueryParam("proprietaireLots") List lotCoproprietes, @QueryParam("askby") int askby, @QueryParam("responseby") int responseby, @Context HttpHeaders headers) throws SQLException { - - // todo recheck value + public @ResponseBody Map saveInformationRequest( + @RequestParam("cni") String cni, + @RequestParam("type") String type, + @RequestParam(name= "adress", required= false) String adress, + @RequestParam(name= "commune", required= false) String commune, + @RequestParam(name= "codepostal", required= false) String codePostal, + @RequestParam(name= "firstname", required= false) String firstname, + @RequestParam(name= "lastname", required= false) String lastname, + @RequestParam(name= "mail", required= false) String mail, + @RequestParam(name= "comptecommunaux", required= false) List compteCommunaux, + @RequestParam(name= "parcelleIds", required= false) List parcelleIds, + @RequestParam(name= "proprietaires", required= false) List proprietaires, + @RequestParam(name= "parcelles", required= false) List parcelles, + @RequestParam(name= "coproprietes", required= false) List coProprietes, + @RequestParam(name= "proprietaireLots", required= false) List lotCoproprietes, + @RequestParam(name= "askby", required= false) int askby, + @RequestParam(name= "responseby", required= false) int responseby) throws SQLException { Map resultInformation = new HashMap(); String result = "KO"; diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/SectionController.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/SectionController.java index cc5da5d8..bdc4893d 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/SectionController.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/SectionController.java @@ -1,30 +1,30 @@ package org.georchestra.cadastrapp.service; + import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import java.util.Map; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MediaType; +import org.georchestra.cadastrapp.service.constants.CadastrappConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.http.MediaType; import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RequestHeader; - +@Controller public class SectionController extends CadController { final static Logger logger = LoggerFactory.getLogger(SectionController.class); - - @GET - @Path("/getSection") - @Produces(MediaType.APPLICATION_JSON) + + @RequestMapping(path = "/getSection", produces = {MediaType.APPLICATION_JSON_VALUE}, method= { RequestMethod.GET}) /** * /getSection * @@ -41,11 +41,11 @@ public class SectionController extends CadController { * * @throws SQLException */ - public List> getSectionList( - @Context HttpHeaders headers, - @QueryParam("cgocommune") String cgoCommune, - @QueryParam("ccopre") String ccopre, - @QueryParam("ccosec") String ccosec) throws SQLException { + public @ResponseBody List> getSectionList( + @RequestHeader(value=CadastrappConstants.HTTP_HEADER_ROLES, required = false) String rolesList, + @RequestParam(name= "cgocommune") String cgoCommune, + @RequestParam(required = false) String ccopre, + @RequestParam(required = false) String ccosec) throws SQLException { // Create empty List to send empty reponse if SQL value is empty. (List instead of null in http response) List> sections = new ArrayList>(); @@ -72,7 +72,7 @@ public List> getSectionList( isWhereAdded = createLikeClauseRequest(isWhereAdded, queryBuilder, "ccopre", ccopre, queryParams); isWhereAdded = createLikeClauseRequest(isWhereAdded, queryBuilder, "ccosec", ccosec, queryParams); if(isSearchFiltered){ - queryBuilder.append(addAuthorizationFiltering(headers)); + queryBuilder.append(addAuthorizationFiltering(rolesList)); } queryBuilder.append(" ORDER BY ccopre, ccosec "); diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/UniteCadastraleController.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/UniteCadastraleController.java index b9805f45..77041f3d 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/UniteCadastraleController.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/UniteCadastraleController.java @@ -4,22 +4,22 @@ import java.util.List; import java.util.Map; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MediaType; - import org.georchestra.cadastrapp.helper.BatimentHelper; import org.georchestra.cadastrapp.helper.ProprietaireHelper; +import org.georchestra.cadastrapp.service.constants.CadastrappConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RequestHeader; - +@Controller public class UniteCadastraleController extends CadController { final static Logger logger = LoggerFactory.getLogger(UniteCadastraleController.class); @@ -30,15 +30,12 @@ public class UniteCadastraleController extends CadController { @Autowired ProprietaireHelper proprietaireHelper; - @Path("/getFIC") - @GET - @Produces(MediaType.APPLICATION_JSON) + @RequestMapping(path = "/getFIC", produces = {MediaType.APPLICATION_JSON_VALUE}, method = { RequestMethod.GET }) /** * TODO change this to 5 separated services * * Return all information need to fill cadastre information panel * - * @param headers used to verify user group to check CNIL level and geographic limitation * @param parcelle Id Parcelle unique in all country exemple : 2014630103000AP0025 * @param part (for 0 to 5) * 0 -> Parcelle Information @@ -48,9 +45,9 @@ public class UniteCadastraleController extends CadController { * 4 - > Historical information * @return Json object corresponding on wanted part */ - public List> getInformationCadastrale(@Context HttpHeaders headers, - @QueryParam("parcelle") String parcelle, - @QueryParam("onglet") int onglet) { + public @ResponseBody List> getInformationCadastrale( + @RequestParam String parcelle, + @RequestParam int onglet) { logger.debug(" parcelle : " + parcelle + " onglet : " + onglet); @@ -58,33 +55,33 @@ public List> getInformationCadastrale(@Context HttpHeaders h switch (onglet) { case 0: - information = infoOngletParcelle(parcelle, headers); + information = infoOngletParcelle(parcelle); break; case 1: // Get information about plot owner List parcelles = new ArrayList(); parcelles.add(parcelle); - information = proprietaireHelper.getProprietairesByParcelles(headers, parcelles, false); + information = proprietaireHelper.getProprietairesByParcelles(parcelles, false); logger.warn("Deprecated service, use getProprietairesByParcelle instead"); break; case 2: - if (getUserCNILLevel(headers)>1){ - information = batimentHelper.getBuildings(parcelle, headers); + if (getUserCNILLevel()>1){ + information = batimentHelper.getBuildings(parcelle); } else{ logger.info("User does not have enough right to see information about batiment"); } break; case 3: - if (getUserCNILLevel(headers)>1){ - information = infoOngletSubdivision(parcelle, headers); + if (getUserCNILLevel()>1){ + information = infoOngletSubdivision(parcelle); } else{ logger.info("User does not have enough right to see information about subdivision"); } break; case 4: - information = infoOngletHistorique(parcelle, headers); + information = infoOngletHistorique(parcelle); break; default: logger.error(" No values to return for onglet : " + onglet); @@ -100,11 +97,10 @@ public List> getInformationCadastrale(@Context HttpHeaders h * infoOngletParcelle * * @param String parcelle / Id Parcelle exemple : 2014630103000AP0025 - * @param HttpHeaders headers * * @return List> */ - private List> infoOngletParcelle(String parcelle, HttpHeaders headers){ + private List> infoOngletParcelle(String parcelle){ logger.debug("infoOngletParcelle - parcelle : " + parcelle); @@ -130,11 +126,10 @@ private List> infoOngletParcelle(String parcelle, HttpHeader * call to this method should only be done by CNIL2 level user with geographical rights * * @param String parcelle / Id Parcelle exemple : 2014630103000AP0025 - * @param HttpHeaders headers * * @return List> containing Lettre indicative, Contenance, Code Nature de culture et Revenu au 01/01 */ - private List> infoOngletSubdivision(String parcelle, HttpHeaders headers ){ + private List> infoOngletSubdivision(String parcelle){ logger.debug("infoOngletSubdivision - parcelle : " + parcelle); @@ -145,7 +140,7 @@ private List> infoOngletSubdivision(String parcelle, HttpHea subDivisionqueryBuilder.append(databaseSchema); subDivisionqueryBuilder.append(".proprietenonbatie pnb "); subDivisionqueryBuilder.append(" where pnb.parcelle = ? "); - subDivisionqueryBuilder.append(addAuthorizationFiltering(headers, "pnb.")); + subDivisionqueryBuilder.append(addAuthorizationFiltering("pnb.")); // init jdbc template JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); @@ -161,7 +156,7 @@ private List> infoOngletSubdivision(String parcelle, HttpHea * @param HttpHeaders headers * @return List> */ - private List> infoOngletHistorique(String parcelle, HttpHeaders headers){ + private List> infoOngletHistorique(String parcelle){ logger.debug("infoOngletHistorique - parcelle : " + parcelle); @@ -174,7 +169,7 @@ private List> infoOngletHistorique(String parcelle, HttpHead queryBuilder.append(databaseSchema); queryBuilder.append(".prop_type_filiation prop "); queryBuilder.append("where p.parcelle = ? and p.type_filiation = prop.filiation "); - queryBuilder.append(addAuthorizationFiltering(headers, "p.")); + queryBuilder.append(addAuthorizationFiltering("p.")); JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); return jdbcTemplate.queryForList(queryBuilder.toString(), parcelle); diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/VoieController.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/VoieController.java index 8da2035c..7fe20772 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/VoieController.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/VoieController.java @@ -5,25 +5,23 @@ import java.util.List; import java.util.Map; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; - import org.georchestra.cadastrapp.configuration.CadastrappPlaceHolder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.http.MediaType; import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; - +@Controller public class VoieController extends CadController { final static Logger logger = LoggerFactory.getLogger(VoieController.class); - - @GET - @Path("/getVoie") - @Produces(MediaType.APPLICATION_JSON) + + @RequestMapping(path ="/getVoie", produces = {MediaType.APPLICATION_JSON_VALUE}, method = { RequestMethod.GET}) /** * /getVoie * @@ -41,9 +39,9 @@ public class VoieController extends CadController { * * @throws SQLException */ - public List> getVoie( - @QueryParam("cgocommune") String cgoCommune, - @QueryParam("dvoilib") String dvoilib) throws SQLException { + public @ResponseBody List> getVoie( + @RequestParam(name= "cgocommune") String cgoCommune, + @RequestParam(name= "dvoilib") String dvoilib) throws SQLException { List> voies = new ArrayList>(); List queryParams = new ArrayList(); @@ -70,7 +68,7 @@ public List> getVoie( voies = jdbcTemplate.queryForList(queryBuilder.toString(), queryParams.toArray()); } else{ - logger.info("Missing mandatory parameter cgocommune and dvoilib to launch request"); + logger.info("Error in mandatory parameter cgocommune or dvoilib to launch request"); } return voies; diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/constants/CadastrappConstants.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/constants/CadastrappConstants.java index f63060d7..7b574044 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/constants/CadastrappConstants.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/constants/CadastrappConstants.java @@ -90,5 +90,10 @@ private CadastrappConstants() { //message erreur public static final String GENERATING_PICTURE_ERROR = "Problème lors de la création de l'image du bordereau."; + //header groups + public static final String HTTP_HEADER_ROLES = "sec-roles"; + public static final String HTTP_HEADER_ORGANISME = "sec-org"; + public static final String HTTP_HEADER_USERNAME = "sec-username"; + } diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/export/CSVExportController.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/export/CSVExportController.java index cb85fdbd..cde33fd8 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/export/CSVExportController.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/export/CSVExportController.java @@ -6,18 +6,20 @@ import java.util.Date; import java.util.List; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.ResponseBuilder; - import org.georchestra.cadastrapp.configuration.CadastrappPlaceHolder; import org.georchestra.cadastrapp.service.CadController; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - +import org.springframework.http.ContentDisposition; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; + +@Controller public class CSVExportController extends CadController { static final Logger logger = LoggerFactory.getLogger(CSVExportController.class); @@ -35,12 +37,10 @@ public class CSVExportController extends CadController { * same number of value, the corresponding line won't be added to * csv */ - @GET - @Path("/exportAsCsv") - @Produces({ "text/csv" }) - public Response cSVExport(@QueryParam("data") List values) { + @RequestMapping(path = "/exportAsCsv", produces = "text/csv", method= {RequestMethod.GET}) + public ResponseEntity cSVExport(@RequestParam(name = "data") List values) { - ResponseBuilder response = Response.serverError(); + ResponseEntity response = new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); if (values != null && !values.isEmpty()) { @@ -77,8 +77,14 @@ public Response cSVExport(@QueryParam("data") List values) { fileWriter.flush(); fileWriter.close(); - response = Response.ok((Object) file); - response.header("Content-Disposition", "attachment; filename=" + file.getName()); + ContentDisposition contentDisposition = ContentDisposition.builder("attachment") + .filename(file.getName()) + .build(); + + HttpHeaders headers = new HttpHeaders(); + headers.setContentDisposition(contentDisposition); + + response = new ResponseEntity(file, headers, HttpStatus.OK); } catch (IOException e) { logger.error("Error while creating CSV files ", e); @@ -89,7 +95,7 @@ public Response cSVExport(@QueryParam("data") List values) { } } - return response.build(); + return response; } } diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/pdf/BordereauParcellaireController.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/pdf/BordereauParcellaireController.java index 68dfdff1..ae2c12e3 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/pdf/BordereauParcellaireController.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/pdf/BordereauParcellaireController.java @@ -12,15 +12,6 @@ import java.util.Date; import java.util.List; -import javax.ws.rs.DefaultValue; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.ResponseBuilder; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; @@ -46,7 +37,17 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; - +import org.springframework.http.ContentDisposition; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; + +@Controller public class BordereauParcellaireController extends CadController { final static Logger logger = LoggerFactory.getLogger(BordereauParcellaireController.class); @@ -61,7 +62,6 @@ public class BordereauParcellaireController extends CadController { * data is retrieved from database and a FO is created using the xsl template. * Once the fo file is create we then create the PDF file * - * @param headers, use for CNIL level limitation * @param parcelleList, list of parcelleId you want to export * @param personalData, 0 no owners information * 1 owners information in page @@ -73,19 +73,17 @@ public class BordereauParcellaireController extends CadController { * @param baseMapIndex corresponding of the wanted index in cadastrapp.properties * @return BP pdf */ - @GET - @Path("/createBordereauParcellaire") - @Produces("application/pdf") - public Response createBordereauParcellaire(@Context HttpHeaders headers, - @QueryParam("parcelle") final List parcelleList, - @DefaultValue("0") @QueryParam("personaldata") int personalData, - @DefaultValue("0") @QueryParam("basemapindex") int baseMapIndex, - @DefaultValue("#1446DE") @QueryParam("fillcolor") String styleFillColor, - @DefaultValue("0.50") @QueryParam("opacity") float styleFillOpacity, - @DefaultValue("#10259E") @QueryParam("strokecolor") String styleStrokeColor, - @DefaultValue("2") @QueryParam("strokewidth") int styleStrokeWidth) { - - ResponseBuilder response = Response.noContent(); + @RequestMapping(path = "/createBordereauParcellaire", produces ={MediaType.APPLICATION_PDF_VALUE}, method= {RequestMethod.GET}) + public ResponseEntity createBordereauParcellaire( + @RequestParam(name= "parcelle") final List parcelleList, + @RequestParam(name= "personaldata", defaultValue = "0", required= false) int personalData, + @RequestParam(name= "basemapindex", defaultValue = "0", required= false) int baseMapIndex, + @RequestParam(name= "fillcolor", defaultValue = "#1446DE", required= false) String styleFillColor, + @RequestParam(name= "opacity", defaultValue = "0.50", required= false) float styleFillOpacity, + @RequestParam(name= "strokecolor", defaultValue = "#10259E", required= false) String styleStrokeColor, + @RequestParam(name= "strokewidth", defaultValue = "2", required= false) int styleStrokeWidth) { + + ResponseEntity response = new ResponseEntity(HttpStatus.NO_CONTENT); // Check if parcelle list is not empty if (parcelleList != null && !parcelleList.isEmpty()) { @@ -148,7 +146,7 @@ public Response createBordereauParcellaire(@Context HttpHeaders headers, plotsStyle.setStrokeWidth(styleStrokeWidth); // Get bordereau parcellaire information - BordereauParcellaire bordereauParcellaire = bordereauParcellaireHelper.getBordereauParcellaireInformation(newParcelleList, personalData, headers, false, plotsStyle, baseMapIndex); + BordereauParcellaire bordereauParcellaire = bordereauParcellaireHelper.getBordereauParcellaireInformation(newParcelleList, personalData, false, plotsStyle, baseMapIndex); File xmlfile = null; File foFile = null; OutputStream foOutPutStream = null; @@ -190,11 +188,16 @@ public Response createBordereauParcellaire(@Context HttpHeaders headers, transformerPDF.transform(src, res); out.close(); - - // Create response - response = Response.ok((Object) pdfResult); - response.header("Content-Disposition", "attachment; filename=" + pdfResult.getName()); + ContentDisposition contentDisposition = ContentDisposition.builder("attachment") + .filename(pdfResult.getName()) + .build(); + + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_PDF); + headers.setContentDisposition(contentDisposition); + + response = new ResponseEntity(pdfResult, headers, HttpStatus.OK); } catch (JAXBException jaxbException) { logger.warn("Error during converting object to xml : " + jaxbException); } catch (TransformerException transformerException) { @@ -231,8 +234,7 @@ public Response createBordereauParcellaire(@Context HttpHeaders headers, } else { logger.warn("Required parameter missing"); } - return response.build(); + return response; } - } diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/pdf/BordereauParcellaireHelper.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/pdf/BordereauParcellaireHelper.java index 55c125d3..ad865866 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/pdf/BordereauParcellaireHelper.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/pdf/BordereauParcellaireHelper.java @@ -13,7 +13,6 @@ import java.util.List; import java.util.Map; -import javax.ws.rs.core.HttpHeaders; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; @@ -60,7 +59,6 @@ public final class BordereauParcellaireHelper extends CadController{ /** * Get all information from database for all parcelle list * - * @param headers use for CNIL level limitation * @param isCoPro get copro BP information if true * @param parcelleList * List of parcelle id, like @@ -70,14 +68,13 @@ public final class BordereauParcellaireHelper extends CadController{ * * @return BordereauParcellaire witch contains list of parcelle */ - public BordereauParcellaire getBordereauParcellaireInformation(List parcelleList, int personalData, HttpHeaders headers, boolean isCoPro) { - return getBordereauParcellaireInformation(parcelleList, personalData, headers, isCoPro, null, 0); + public BordereauParcellaire getBordereauParcellaireInformation(List parcelleList, int personalData, boolean isCoPro) { + return getBordereauParcellaireInformation(parcelleList, personalData, isCoPro, null, 0); } /** * Get all information from database for all parcelle list * - * @param headers use for CNIL level limitation * @param isCoPro get copro BP information if true * @param parcelleList * List of parcelle id, like @@ -89,7 +86,7 @@ public BordereauParcellaire getBordereauParcellaireInformation(List parc * * @return BordereauParcellaire witch contains list of parcelle */ - public BordereauParcellaire getBordereauParcellaireInformation(List parcelleList, int personalData, HttpHeaders headers, boolean isCoPro, Style plotStyle, int baseMapIndex) { + public BordereauParcellaire getBordereauParcellaireInformation(List parcelleList, int personalData, boolean isCoPro, Style plotStyle, int baseMapIndex) { BordereauParcellaire bordereauParcellaire = new BordereauParcellaire(); @@ -142,7 +139,7 @@ public BordereauParcellaire getBordereauParcellaireInformation(List parc logger.debug("Parcelle information : " + parcelle); - if (personalData > 0 && getUserCNILLevel(headers)>0) { + if (personalData > 0 && getUserCNILLevel()>0) { List proprietaires = new ArrayList(); String tableName = (isCoPro)?tableCoProprietaire:tableProprietaire; @@ -157,7 +154,7 @@ public BordereauParcellaire getBordereauParcellaireInformation(List parc queryBuilderProprietaire.append(tableName); queryBuilderProprietaire.append(" proparc "); queryBuilderProprietaire.append("where proparc.parcelle = ? and prop.comptecommunal = proparc.comptecommunal"); - queryBuilderProprietaire.append(addAuthorizationFiltering(headers)); + queryBuilderProprietaire.append(addAuthorizationFiltering()); List> proprietairesResult = jdbcTemplate.queryForList(queryBuilderProprietaire.toString(), row.get("parcelle")); diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/pdf/DemandeController.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/pdf/DemandeController.java index ef833807..577fd256 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/pdf/DemandeController.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/pdf/DemandeController.java @@ -7,15 +7,6 @@ import java.util.List; import java.util.Map; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.ResponseBuilder; - import org.apache.pdfbox.io.MemoryUsageSetting; import org.apache.pdfbox.multipdf.PDFMergerUtility; import org.georchestra.cadastrapp.configuration.CadastrappPlaceHolder; @@ -30,7 +21,17 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; - +import org.springframework.http.ContentDisposition; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; + +@Controller public class DemandeController extends CadController { static final Logger logger = LoggerFactory.getLogger(DemandeController.class); @@ -53,12 +54,11 @@ public class DemandeController extends CadController { * @return pdf demande resume * @throws IOException if an input or output exception occured */ - @GET - @Path("/createDemandeFromObj") - @Produces("application/pdf") - public Response createDemandeFromObj(@Context HttpHeaders headers, @QueryParam("requestid") long requestId) throws IOException { + @RequestMapping(path = "/createDemandeFromObj", produces ={MediaType.APPLICATION_PDF_VALUE}, method= {RequestMethod.GET}) + public ResponseEntity createDemandeFromObj( + @RequestParam(name="requestid") long requestId) throws IOException { - ResponseBuilder response = Response.noContent(); + ResponseEntity response = new ResponseEntity<>(HttpStatus.NO_CONTENT); List listPdfPath = new ArrayList(); @@ -82,22 +82,22 @@ public Response createDemandeFromObj(@Context HttpHeaders headers, @QueryParam(" if(objReq.getType() == CadastrappConstants.CODE_DEMANDEUR_COMPTE_COMMUNAL){ //if BP if("1".equals(objReq.getBp())){ - listPdfPath.add(createBordereauParcellaireByCC(objReq.getComptecommunal(),null, headers, false)); + listPdfPath.add(createBordereauParcellaireByCC(objReq.getComptecommunal(),null, false)); } //if RP if("1".equals(objReq.getRp())){ - listPdfPath.add(createReleveProprieteByCC(objReq.getComptecommunal(), headers,isMinimal)); + listPdfPath.add(createReleveProprieteByCC(objReq.getComptecommunal(), isMinimal)); } }else if(objReq.getType() == CadastrappConstants.CODE_DEMANDEUR_PARCELLE_ID){ //if BP if("1".equals(objReq.getBp())){ - listPdfPath.add(createBordereauParcellaireById(objReq.getParcelle(), headers)); + listPdfPath.add(createBordereauParcellaireById(objReq.getParcelle())); } //if RP if("1".equals(objReq.getRp())){ - listPdfPath.add(createReleveProprieteById(objReq.getParcelle(), headers, isMinimal)); + listPdfPath.add(createReleveProprieteById(objReq.getParcelle(), isMinimal)); } @@ -105,11 +105,11 @@ public Response createDemandeFromObj(@Context HttpHeaders headers, @QueryParam(" //if BP if("1".equals(objReq.getBp())){ - listPdfPath.add(createBordereauParcellaireByCC(objReq.getComptecommunal(),objReq.getParcelle(), headers, true)); + listPdfPath.add(createBordereauParcellaireByCC(objReq.getComptecommunal(),objReq.getParcelle(), true)); } //if RP if("1".equals(objReq.getRp())){ - listPdfPath.add(createReleveCoProprieteByCCandParcelle(objReq.getComptecommunal(),objReq.getParcelle(), headers,isMinimal)); + listPdfPath.add(createReleveCoProprieteByCCandParcelle(objReq.getComptecommunal(),objReq.getParcelle(), isMinimal)); } @@ -117,11 +117,11 @@ public Response createDemandeFromObj(@Context HttpHeaders headers, @QueryParam(" }else if(objReq.getType() == CadastrappConstants.CODE_DEMANDEUR_PARCELLE){ //if BP if("1".equals(objReq.getBp())){ - listPdfPath.add(createBordereauParcellaireByInfoParcelle(objReq.getCommune(),objReq.getSection(),objReq.getNumero(), headers)); + listPdfPath.add(createBordereauParcellaireByInfoParcelle(objReq.getCommune(),objReq.getSection(),objReq.getNumero())); } //if RP if("1".equals(objReq.getRp())){ - listPdfPath.add(createReleveProprieteByInfoParcelle(objReq.getCommune(),objReq.getSection(),objReq.getNumero(), headers,isMinimal)); + listPdfPath.add(createReleveProprieteByInfoParcelle(objReq.getCommune(),objReq.getSection(),objReq.getNumero(), isMinimal)); } @@ -129,21 +129,21 @@ public Response createDemandeFromObj(@Context HttpHeaders headers, @QueryParam(" //if BP if("1".equals(objReq.getBp())){ - listPdfPath.add(createBordereauParcellaireByInfoOwner(objReq.getCommune(),objReq.getProprietaire(), headers)); + listPdfPath.add(createBordereauParcellaireByInfoOwner(objReq.getCommune(),objReq.getProprietaire())); } //if RP if("1".equals(objReq.getRp())){ - listPdfPath.add(createReleveProprieteByInfoOwner(objReq.getCommune(),objReq.getProprietaire(), headers,isMinimal)); + listPdfPath.add(createReleveProprieteByInfoOwner(objReq.getCommune(),objReq.getProprietaire(), isMinimal)); } }else if(objReq.getType() == CadastrappConstants.CODE_DEMANDEUR_LOT_COPROPRIETE){ //if BP if("1".equals(objReq.getBp())){ - listPdfPath.add(createBordereauParcellaireLot(objReq.getCommune(),objReq.getSection(),objReq.getNumero(),objReq.getProprietaire(), headers)); + listPdfPath.add(createBordereauParcellaireLot(objReq.getCommune(),objReq.getSection(),objReq.getNumero(),objReq.getProprietaire())); } //if RP if("1".equals(objReq.getRp())){ - listPdfPath.add(createReleveProprieteByInfoLot(objReq.getCommune(),objReq.getSection(),objReq.getNumero(),objReq.getProprietaire(), headers,isMinimal)); + listPdfPath.add(createReleveProprieteByInfoLot(objReq.getCommune(),objReq.getSection(),objReq.getNumero(),objReq.getProprietaire(), isMinimal)); } } @@ -166,23 +166,29 @@ public Response createDemandeFromObj(@Context HttpHeaders headers, @QueryParam(" pdfResult.deleteOnExit(); - response = Response.ok((Object) pdfResult); - response.header("Content-Disposition", "attachment; filename=" + pdfResult.getName() + ".pdf"); + ContentDisposition contentDisposition = ContentDisposition.builder("attachment") + .filename(pdfResult.getName()) + .build(); + + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_PDF); + headers.setContentDisposition(contentDisposition); + + response = new ResponseEntity(pdfResult, headers, HttpStatus.OK); } } - return response.build(); + return response; } /** * Create RP using owner code CC * * @param compteCommunal owner ident - * @param headers http header containing restriction * @param isMinimal if true then only some information will be displayed * @return PDF File RP */ - private File createReleveProprieteByCC(String compteCommunal, HttpHeaders headers, boolean isMinimal) { + private File createReleveProprieteByCC(String compteCommunal, boolean isMinimal) { //Store field search if no data to display => inform on PDF file List fields = new ArrayList(); @@ -190,7 +196,7 @@ private File createReleveProprieteByCC(String compteCommunal, HttpHeaders header List compteCommIds = new ArrayList(); compteCommIds.add(compteCommunal); // Get Releve Propriete information - RelevePropriete relevePropriete = releveProprieteHelper.getReleveProprieteInformation(compteCommIds, headers, new String()); + RelevePropriete relevePropriete = releveProprieteHelper.getReleveProprieteInformation(compteCommIds, new String()); File pdf = null; //generate PDF @@ -209,11 +215,10 @@ private File createReleveProprieteByCC(String compteCommunal, HttpHeaders header * Create RP using parcelle id * * @param parcelle id parcelle - * @param headers http header containing restriction * @param isMinimal if true then only some information will be displayed * @return PDF File RP */ - private File createReleveProprieteById(String parcelle, HttpHeaders headers, boolean isMinimal) { + private File createReleveProprieteById(String parcelle, boolean isMinimal) { //Store field search if no data to display => inform on PDF file List fields = new ArrayList(); @@ -228,7 +233,7 @@ private File createReleveProprieteById(String parcelle, HttpHeaders headers, boo } // Get Releve Propriete information - RelevePropriete relevePropriete = releveProprieteHelper.getReleveProprieteInformation(compteCommunauxList, headers, parcelle); + RelevePropriete relevePropriete = releveProprieteHelper.getReleveProprieteInformation(compteCommunauxList, parcelle); File pdf = null; @@ -249,10 +254,9 @@ private File createReleveProprieteById(String parcelle, HttpHeaders headers, boo * Create borderau parcellaire using parcelle id * * @param parcelle id parcelle - * @param headers http header containing restriction * @return PDF File BP */ - private File createBordereauParcellaireById(String parcelle, HttpHeaders headers) { + private File createBordereauParcellaireById(String parcelle) { //Store field search if no data to display => inform on PDF file List fields = new ArrayList(); @@ -260,7 +264,7 @@ private File createBordereauParcellaireById(String parcelle, HttpHeaders headers parcellId.add(parcelle); // Get bordereau parcellaire information - BordereauParcellaire bordereauParcellaire = bordereauParcellaireHelper.getBordereauParcellaireInformation(parcellId, 1, headers,false); + BordereauParcellaire bordereauParcellaire = bordereauParcellaireHelper.getBordereauParcellaireInformation(parcellId, 1, false); File pdf = null; try { @@ -296,12 +300,11 @@ private File createBordereauParcellaireById(String parcelle, HttpHeaders headers * * @param comptecommunal * @param parcelleId - * @param headers http headers to test wrights * @param isCoPro boolean to check is request is a copropriete * * @return PDF file contening wanted Bordereau Parcellaire */ - private File createBordereauParcellaireByCC(String comptecommunal,String parcelleId, HttpHeaders headers, boolean isCoPro) { + private File createBordereauParcellaireByCC(String comptecommunal,String parcelleId, boolean isCoPro) { // Store field search if no data to display => inform on PDF file List fields = new ArrayList(); @@ -326,7 +329,7 @@ private File createBordereauParcellaireByCC(String comptecommunal,String parcell } // Get bordereau parcellaire information - BordereauParcellaire bordereauParcellaire = bordereauParcellaireHelper.getBordereauParcellaireInformation(parcellesId, 1, headers, isCoPro); + BordereauParcellaire bordereauParcellaire = bordereauParcellaireHelper.getBordereauParcellaireInformation(parcellesId, 1, isCoPro); try { //generate PDF if(bordereauParcellaire.isEmpty()){ @@ -357,11 +360,10 @@ private File createBordereauParcellaireByCC(String comptecommunal,String parcell * * @param compteCommunal * @param parcellaId - * @param headers * @param isMinimal * @return File PDF RP */ - private File createReleveCoProprieteByCCandParcelle(String compteCommunal, String parcelleId, HttpHeaders headers, boolean isMinimal) { + private File createReleveCoProprieteByCCandParcelle(String compteCommunal, String parcelleId, boolean isMinimal) { //Store field search if no data to display => inform on PDF file List fields = new ArrayList(); @@ -369,7 +371,7 @@ private File createReleveCoProprieteByCCandParcelle(String compteCommunal, Strin compteCommIds.add(compteCommunal); // Get Releve Propriete information - RelevePropriete relevePropriete = releveProprieteHelper.getReleveProprieteInformation(compteCommIds, headers, parcelleId); + RelevePropriete relevePropriete = releveProprieteHelper.getReleveProprieteInformation(compteCommIds, parcelleId); File pdf = null; //generate PDF @@ -391,10 +393,9 @@ private File createReleveCoProprieteByCCandParcelle(String compteCommunal, Strin * @param commune * @param section * @param numero - * @param headers * @return File PDF BP */ - private File createBordereauParcellaireByInfoParcelle(String commune, String section, String numero, HttpHeaders headers){ + private File createBordereauParcellaireByInfoParcelle(String commune, String section, String numero){ //Store field search if no data to display => inform on PDF file List fields = new ArrayList(); @@ -408,7 +409,7 @@ private File createBordereauParcellaireByInfoParcelle(String commune, String sec } // Get bordereau parcellaire information - BordereauParcellaire bordereauParcellaire = bordereauParcellaireHelper.getBordereauParcellaireInformation(parcellId, 1, headers,false); + BordereauParcellaire bordereauParcellaire = bordereauParcellaireHelper.getBordereauParcellaireInformation(parcellId, 1, false); File pdf = null; try { //generate PDF @@ -433,11 +434,10 @@ private File createBordereauParcellaireByInfoParcelle(String commune, String sec * @param commune * @param section * @param numero - * @param headers * @param isMinimal * @return File PDF RP */ - private File createReleveProprieteByInfoParcelle(String commune, String section,String numero, HttpHeaders headers, boolean isMinimal) { + private File createReleveProprieteByInfoParcelle(String commune, String section,String numero, boolean isMinimal) { List compteCommunauxList = new ArrayList(); //get compte communal by parcelle @@ -450,7 +450,7 @@ private File createReleveProprieteByInfoParcelle(String commune, String section, } // Get Releve Propriete information - RelevePropriete relevePropriete = releveProprieteHelper.getReleveProprieteInformation(compteCommunauxList, headers, idParcelle); + RelevePropriete relevePropriete = releveProprieteHelper.getReleveProprieteInformation(compteCommunauxList, idParcelle); //generate PDF File pdf = releveProprieteHelper.generatePDF(relevePropriete,isMinimal, false); @@ -464,10 +464,9 @@ private File createReleveProprieteByInfoParcelle(String commune, String section, * * @param commune * @param ownerName - * @param headers * @return */ - private File createBordereauParcellaireByInfoOwner(String commune, String ownerName, HttpHeaders headers){ + private File createBordereauParcellaireByInfoOwner(String commune, String ownerName){ //Store field search if no data to display => inform on PDF file List fields = new ArrayList(); @@ -481,7 +480,7 @@ private File createBordereauParcellaireByInfoOwner(String commune, String ownerN } // Get bordereau parcellaire information - BordereauParcellaire bordereauParcellaire = bordereauParcellaireHelper.getBordereauParcellaireInformation(parcellId, 1, headers,false); + BordereauParcellaire bordereauParcellaire = bordereauParcellaireHelper.getBordereauParcellaireInformation(parcellId, 1, false); File pdf = null; try { //generate PDF @@ -505,11 +504,10 @@ private File createBordereauParcellaireByInfoOwner(String commune, String ownerN * * @param commune * @param ownerName - * @param headers * @param isMinimal * @return File PDF RP */ - private File createReleveProprieteByInfoOwner(String commune, String ownerName, HttpHeaders headers, boolean isMinimal) { + private File createReleveProprieteByInfoOwner(String commune, String ownerName, boolean isMinimal) { List compteCommunauxList = new ArrayList(); //get compte communal by commune and owner @@ -521,7 +519,7 @@ private File createReleveProprieteByInfoOwner(String commune, String ownerName, } // Get Releve Propriete information - RelevePropriete relevePropriete = releveProprieteHelper.getReleveProprieteInformation(compteCommunauxList, headers, new String()); + RelevePropriete relevePropriete = releveProprieteHelper.getReleveProprieteInformation(compteCommunauxList, new String()); //generate PDF File pdf = releveProprieteHelper.generatePDF(relevePropriete,isMinimal, false); @@ -537,10 +535,9 @@ private File createReleveProprieteByInfoOwner(String commune, String ownerName, * @param section * @param numero * @param proprietaire - * @param headers * @return */ - private File createBordereauParcellaireLot(String commune, String section, String numero, String proprietaire, HttpHeaders headers) { + private File createBordereauParcellaireLot(String commune, String section, String numero, String proprietaire) { //Store field search if no data to display => inform on PDF file List fields = new ArrayList(); //get parcelle by commune,section,numero and proprietaire @@ -553,7 +550,7 @@ private File createBordereauParcellaireLot(String commune, String section, Strin } // Get bordereau parcellaire information - BordereauParcellaire bordereauParcellaire = bordereauParcellaireHelper.getBordereauParcellaireInformation(parcellId, 1, headers, false); + BordereauParcellaire bordereauParcellaire = bordereauParcellaireHelper.getBordereauParcellaireInformation(parcellId, 1, false); File pdf = null; try { @@ -578,11 +575,10 @@ private File createBordereauParcellaireLot(String commune, String section, Strin * @param section * @param numero * @param proprietaire - * @param headers * @param isMinimal * @return File PDF RP */ - private File createReleveProprieteByInfoLot(String commune, String section, String numero, String proprietaire, HttpHeaders headers, boolean isMinimal) { + private File createReleveProprieteByInfoLot(String commune, String section, String numero, String proprietaire, boolean isMinimal) { List compteCommunauxList = new ArrayList(); //get compte communal by parcelle commune,section,numero, and proprietaire List> compteCommunaux = releveProprieteHelper.getProprietaireByInfoLot(commune,section,numero,proprietaire); @@ -595,7 +591,7 @@ private File createReleveProprieteByInfoLot(String commune, String section, Stri } // Get Releve Propriete information - RelevePropriete relevePropriete = releveProprieteHelper.getReleveProprieteInformation(compteCommunauxList, headers, parcelleId); + RelevePropriete relevePropriete = releveProprieteHelper.getReleveProprieteInformation(compteCommunauxList, parcelleId); //generate PDF File pdf = releveProprieteHelper.generatePDF(relevePropriete,isMinimal, false); diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/pdf/ReleveProprieteController.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/pdf/ReleveProprieteController.java index 78ab809c..b487aa00 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/pdf/ReleveProprieteController.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/pdf/ReleveProprieteController.java @@ -13,15 +13,6 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.ResponseBuilder; - import org.georchestra.cadastrapp.configuration.CadastrappPlaceHolder; import org.georchestra.cadastrapp.model.pdf.CompteCommunal; import org.georchestra.cadastrapp.model.pdf.Proprietaire; @@ -38,8 +29,18 @@ import org.supercsv.io.CsvBeanWriter; import org.supercsv.io.ICsvBeanWriter; import org.supercsv.prefs.CsvPreference; +import org.springframework.http.ContentDisposition; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +@Controller public class ReleveProprieteController extends CadController { static final Logger logger = LoggerFactory.getLogger(ReleveProprieteController.class); @@ -50,17 +51,16 @@ public class ReleveProprieteController extends CadController { /** * Create a PDF using a list of comptecommunal * - * @param headers to verify CNIL level information * @param comptesCommunaux List of ids proprietaires * @param idParcelle plot id * @return pdf generated RP with database information */ - @GET - @Path("/createRelevePropriete") - @Produces("application/pdf") - public Response createRelevePDFPropriete(@Context HttpHeaders headers, @QueryParam("compteCommunal") List comptesCommunaux, @QueryParam("parcelleId") String idParcelle) { + @RequestMapping(path = "/createRelevePropriete", produces ={MediaType.APPLICATION_PDF_VALUE}, method= {RequestMethod.GET}) + public ResponseEntity createRelevePDFPropriete( + @RequestParam(name= "compteCommunal") List comptesCommunaux, + @RequestParam(name="parcelleId", required= false) String idParcelle) { - ResponseBuilder response = Response.noContent(); + ResponseEntity response = new ResponseEntity<>(HttpStatus.NO_CONTENT); logger.debug("Controller Parcelle ID (param) : "+idParcelle); @@ -72,36 +72,42 @@ public Response createRelevePDFPropriete(@Context HttpHeaders headers, @QueryPar comptesCommunaux = Arrays.asList(comptesCommunaux.get(0).split(",")); } // Get information about releve de propriete - RelevePropriete relevePropriete = releveProprieteHelper.getReleveProprieteInformation(comptesCommunaux, headers, idParcelle); + RelevePropriete relevePropriete = releveProprieteHelper.getReleveProprieteInformation(comptesCommunaux, idParcelle); File pdfResult = releveProprieteHelper.generatePDF(relevePropriete, false, false); // Create response - response = Response.ok((Object) pdfResult); - response.header("Content-Disposition", "attachment; filename=" + pdfResult.getName()); + ContentDisposition contentDisposition = ContentDisposition.builder("attachment") + .filename(pdfResult.getName()) + .build(); + + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_PDF); + headers.setContentDisposition(contentDisposition); + + response = new ResponseEntity(pdfResult, headers, HttpStatus.OK); } else { logger.warn("Required parameter missing"); } - return response.build(); + return response; } /** * Create a zip file, containint several csv using a list of comptecommunal * - * @param headers to verify CNIL level information * @param comptesCommunaux List of ids proprietaires * @param idParcelle plot id * @return zip containing csv file * @throws IOException if an input or output exception occured */ - @GET - @Path("/createReleveProprieteAsCSV") - @Produces("application/zip") - public Response createReleveCSVPropriete(@Context HttpHeaders headers, @QueryParam("compteCommunal") List comptesCommunaux, @QueryParam("parcelleId") String idParcelle) throws IOException { + @RequestMapping(path = "/createReleveProprieteAsCSV", produces = "application/zip", method= {RequestMethod.GET}) + public ResponseEntity createReleveCSVPropriete( + @RequestParam(name= "compteCommunal") List comptesCommunaux, + @RequestParam(name= "parcelleId", required= false) String idParcelle) throws IOException { - ResponseBuilder response = Response.noContent(); + ResponseEntity response = new ResponseEntity<>(HttpStatus.NO_CONTENT); String tempFolder = CadastrappPlaceHolder.getProperty("tempFolder"); @@ -115,7 +121,7 @@ public Response createReleveCSVPropriete(@Context HttpHeaders headers, @QueryPar comptesCommunaux = Arrays.asList(comptesCommunaux.get(0).split(",")); } // Get information about releve de propriete - RelevePropriete relevePropriete = releveProprieteHelper.getReleveProprieteInformation(comptesCommunaux, headers, idParcelle); + RelevePropriete relevePropriete = releveProprieteHelper.getReleveProprieteInformation(comptesCommunaux, idParcelle); // Define Date for all file name DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH_mm_ss_SSS"); @@ -368,15 +374,21 @@ public Response createReleveCSVPropriete(@Context HttpHeaders headers, @QueryPar } out.close(); - + // Create response - response = Response.ok((Object) finalZip); - response.header("Content-Disposition", "attachment; filename=" + zipFileName); + ContentDisposition contentDisposition = ContentDisposition.builder("attachment") + .filename(zipFileName) + .build(); + + HttpHeaders headers = new HttpHeaders(); + headers.setContentDisposition(contentDisposition); + + response = new ResponseEntity(finalZip, headers, HttpStatus.OK); } else { logger.warn("Required parameter missing"); } - return response.build(); + return response; } } diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/pdf/ReleveProprieteHelper.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/pdf/ReleveProprieteHelper.java index 77baf9ba..349e4a2d 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/pdf/ReleveProprieteHelper.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/pdf/ReleveProprieteHelper.java @@ -13,7 +13,6 @@ import java.util.List; import java.util.Map; -import javax.ws.rs.core.HttpHeaders; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; @@ -59,12 +58,11 @@ public final class ReleveProprieteHelper extends CadController { * Get propertie information using given imput from database * * @param idComptesCommunaux list composed with comptecommunalid - * @param headers HttpHeaders used to verify user privilege * @param idParcelle String plot id * * @return RelevePropriete fill with database information */ - public RelevePropriete getReleveProprieteInformation(List idComptesCommunaux, HttpHeaders headers, String idParcelle) { + public RelevePropriete getReleveProprieteInformation(List idComptesCommunaux, String idParcelle) { RelevePropriete relevePropriete = new RelevePropriete(); @@ -153,7 +151,7 @@ public RelevePropriete getReleveProprieteInformation(List idComptesCommu } // Display information only if at least CNIL level 1 or 2 - if (getUserCNILLevel(headers) > 0) { + if (getUserCNILLevel() > 0) { // Information sur les proprietaires List proprietaires = new ArrayList(); @@ -164,7 +162,7 @@ public RelevePropriete getReleveProprieteInformation(List idComptesCommu queryBuilderProprietaire.append(databaseSchema); queryBuilderProprietaire.append(".proprietaire prop "); queryBuilderProprietaire.append("where prop.comptecommunal = ? "); - queryBuilderProprietaire.append(addAuthorizationFiltering(headers)); + queryBuilderProprietaire.append(addAuthorizationFiltering()); queryBuilderProprietaire.append("order by prop.dnulp ASC "); logger.debug("Get owners information "); @@ -536,12 +534,11 @@ public List> getProprietaireByInfoLot(String commune, String * Create RP without parcelle id. * * @param comptesCommunaux owner id list - * @param headers http headers information to filter result * @return data for releve de propriete */ - public RelevePropriete getReleveProprieteInformation(List comptesCommunaux, HttpHeaders headers) { + public RelevePropriete getReleveProprieteInformation(List comptesCommunaux) { - return getReleveProprieteInformation(comptesCommunaux, headers, null); + return getReleveProprieteInformation(comptesCommunaux, null); } } diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/pdf/RequestPDFController.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/pdf/RequestPDFController.java index c089404a..a461d405 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/pdf/RequestPDFController.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/pdf/RequestPDFController.java @@ -10,14 +10,6 @@ import java.io.StringWriter; import java.util.Date; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.ResponseBuilder; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; @@ -31,6 +23,7 @@ import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; +import org.apache.commons.io.FileUtils; import org.apache.fop.apps.FOPException; import org.apache.fop.apps.Fop; import org.apache.fop.apps.FopFactory; @@ -41,7 +34,16 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; - +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; + +@Controller public class RequestPDFController{ static final Logger logger = LoggerFactory.getLogger(RequestPDFController.class); @@ -51,12 +53,10 @@ public class RequestPDFController{ @Autowired RequestRepository requestRepository; - @GET - @Path("/printPDFRequest") - @Produces("application/pdf") - public Response printPDFRequest(@Context HttpHeaders headers, @QueryParam("requestid") long requestId) { + @RequestMapping(path = "/printPDFRequest", produces = {MediaType.APPLICATION_PDF_VALUE}, method= {RequestMethod.GET}) + public ResponseEntity printPDFRequest(@RequestParam(name = "requestid") long requestId) { - ResponseBuilder response = Response.noContent(); + ResponseEntity response = new ResponseEntity<>(HttpStatus.NO_CONTENT); // Check if requestId exist if (requestId != 0) { @@ -142,8 +142,12 @@ public Response printPDFRequest(@Context HttpHeaders headers, @QueryParam("reque out.close(); // Create response - response = Response.ok((Object) pdfResult); - response.header("Content-Disposition", "attachment; filename=" + pdfResult.getName()); + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_PDF); + headers.setContentDispositionFormData("filename", pdfResult.getName()); + + response = new ResponseEntity<>(FileUtils.readFileToByteArray(pdfResult), headers, HttpStatus.OK); + //response.header("Content-Disposition", "attachment; filename=" + pdfResult.getName()); } catch (JAXBException jaxbException) { logger.warn("Error during converting object to xml", jaxbException); @@ -177,7 +181,7 @@ public Response printPDFRequest(@Context HttpHeaders headers, @QueryParam("reque } else { logger.warn("Required parameter missing"); } - return response.build(); + return response; } } diff --git a/cadastrapp/src/main/webapp/WEB-INF/beans.xml b/cadastrapp/src/main/webapp/WEB-INF/beans.xml index 7ece8b15..6dfbee51 100644 --- a/cadastrapp/src/main/webapp/WEB-INF/beans.xml +++ b/cadastrapp/src/main/webapp/WEB-INF/beans.xml @@ -1,27 +1,25 @@ - - - + - - - + + - + classpath:cadastrapp.properties @@ -34,39 +32,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -76,8 +41,7 @@ - + @@ -128,52 +92,51 @@ - + - + - - - - + + + + - - - - - - - - - + + + + + + + + + + + + + + + + + + true + + + + + + + + + + + + + + - - - - - - - - true - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/cadastrapp/src/main/webapp/WEB-INF/web.xml b/cadastrapp/src/main/webapp/WEB-INF/web.xml index 73e3872f..dcb7d80b 100644 --- a/cadastrapp/src/main/webapp/WEB-INF/web.xml +++ b/cadastrapp/src/main/webapp/WEB-INF/web.xml @@ -2,55 +2,57 @@ Cadastrapp Webapp supplémentaire pour la visualisation de données cadastrale dans georchestra - + contextConfigLocation WEB-INF/beans.xml - org.georchestra.cadastrapp.logging.ExternalConfigLoaderContextListener + + org.georchestra.cadastrapp.logging.ExternalConfigLoaderContextListener + org.springframework.web.context.ContextLoaderListener + - + org.georchestra.cadastrapp.context.CadastrappContextListener - - - - default - /apidocs/* - - - + + index.jsp - - - + + + - CXFServlet - org.apache.cxf.transport.servlet.CXFServlet + services + org.springframework.web.servlet.DispatcherServlet + + contextConfigLocation + + 1 + - CXFServlet + services /services/* - - + + - Connection Pool - jdbc/cadastrapp - javax.sql.DataSource - Container - - + Connection Pool + jdbc/cadastrapp + javax.sql.DataSource + Container + + diff --git a/cadastrapp/src/test/java/org/georchestra/cadastrapp/service/CadControllerTest.java b/cadastrapp/src/test/java/org/georchestra/cadastrapp/service/CadControllerTest.java index 7bcb964a..d3007df4 100644 --- a/cadastrapp/src/test/java/org/georchestra/cadastrapp/service/CadControllerTest.java +++ b/cadastrapp/src/test/java/org/georchestra/cadastrapp/service/CadControllerTest.java @@ -3,8 +3,6 @@ */ package org.georchestra.cadastrapp.service; -import static org.junit.Assert.*; - import java.util.ArrayList; import org.georchestra.cadastrapp.service.pdf.BordereauParcellaireHelper; @@ -18,7 +16,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** - * @author gfi + * @author Pierre Jégo * */ @RunWith(SpringJUnit4ClassRunner.class) diff --git a/cadastrapp/src/test/java/org/georchestra/cadastrapp/service/ImageParcelleControllerTest.java b/cadastrapp/src/test/java/org/georchestra/cadastrapp/service/ImageParcelleControllerTest.java index 6095827a..1cd5cef9 100644 --- a/cadastrapp/src/test/java/org/georchestra/cadastrapp/service/ImageParcelleControllerTest.java +++ b/cadastrapp/src/test/java/org/georchestra/cadastrapp/service/ImageParcelleControllerTest.java @@ -4,15 +4,16 @@ package org.georchestra.cadastrapp.service; -import javax.ws.rs.core.Response; +import java.io.File; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.http.ResponseEntity; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** - * @author gfi + * @author Pierre Jégo * */ //@RunWith(SpringJUnit4ClassRunner.class) @@ -33,7 +34,7 @@ public void testCreateImageBordereauParcellaire() { ImageParcelleController imageParcelleController = new ImageParcelleController(); - Response response = imageParcelleController.createImageBordereauParcellaire("2014630103000AO0351", 0, "#1446DE", (float) 0.50, "#10259E",2); + ResponseEntity response = imageParcelleController.createImageBordereauParcellaire("2014630103000AO0351", 0, "#1446DE", (float) 0.50, "#10259E",2); } diff --git a/cadastrapp/src/test/resources/test-config.xml b/cadastrapp/src/test/resources/test-config.xml index e48d9b39..d84a37b6 100644 --- a/cadastrapp/src/test/resources/test-config.xml +++ b/cadastrapp/src/test/resources/test-config.xml @@ -4,14 +4,14 @@ xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jpa="http://www.springframework.org/schema/data/jpa" - xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd - http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd + xmlns:mvc="http://www.springframework.org/schema/mvc" + xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd + http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd - http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd - http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd - http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd"> - - + http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.3.xsd + http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd + http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd + http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd"> @@ -31,42 +31,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -