From 04fa580f54250164b0d8d199cf500cf8300d9c0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20J=C3=A9go?= Date: Mon, 21 Jun 2021 22:37:43 +0200 Subject: [PATCH] Issue-554 update all dependencies Change Jax-Rs for Spring Rest / Mvc Add Swagger dependencies --- .../org.eclipse.core.resources.prefs | 6 + .../.settings/org.eclipse.jdt.apt.core.prefs | 2 + .../.settings/org.eclipse.jdt.core.prefs | 9 + .../.settings/org.eclipse.m2e.core.prefs | 4 + cadastrapp/README.md | 16 +- cadastrapp/pom.xml | 43 ++--- .../CadastrappControllerConfig.java | 30 ++++ .../configuration/CadastrappPlaceHolder.java | 8 +- .../configuration/SwaggerConfig.java | 40 +++++ .../context/CadastrappContextListener.java | 2 +- .../cadastrapp/helper/BatimentHelper.java | 6 +- .../cadastrapp/helper/ProprietaireHelper.java | 10 +- .../providers/CadastrappInterceptor.java | 54 ++++++ .../providers/PreReponseFilter.java | 33 ---- .../providers/PreRequestFilter.java | 37 ----- .../repository/ObjectRequestRepository.java | 2 +- .../repository/RequestRepository.java | 2 +- .../repository/UserRequestRepository.java | 2 +- .../service/BatimentController.java | 40 ++--- .../cadastrapp/service/CadController.java | 24 +-- .../service/CoProprietaireController.java | 144 ++++++++-------- .../cadastrapp/service/CommuneController.java | 31 ++-- .../service/ConfigurationController.java | 15 +- .../cadastrapp/service/DatadirController.java | 36 ++-- .../service/HabitationController.java | 31 ++-- .../service/ImageParcelleController.java | 42 ++--- .../service/InfoBulleController.java | 62 ++++--- .../service/ProprietaireController.java | 117 +++++++------ .../service/RequestInformationController.java | 32 ++-- .../cadastrapp/service/SectionController.java | 32 ++-- .../service/UniteCadastraleController.java | 55 +++--- .../cadastrapp/service/VoieController.java | 22 ++- .../constants/CadastrappConstants.java | 3 + .../service/export/CSVExportController.java | 39 +++-- .../pdf/BordereauParcellaireController.java | 68 ++++---- .../pdf/BordereauParcellaireHelper.java | 15 +- .../service/pdf/DemandeController.java | 119 +++++++------ .../pdf/ReleveProprieteController.java | 76 +++++---- .../service/pdf/ReleveProprieteHelper.java | 12 +- .../service/pdf/RequestPDFController.java | 39 +++-- .../src/main/resources/cadastrapp.properties | 2 +- cadastrapp/src/main/webapp/WEB-INF/beans.xml | 157 +++++++----------- .../src/main/webapp/WEB-INF/jetty-env.xml | 6 +- cadastrapp/src/main/webapp/WEB-INF/web.xml | 17 -- .../cadastrapp/service/CadControllerTest.java | 4 +- .../service/ImageParcelleControllerTest.java | 7 +- cadastrapp/src/test/resources/test-config.xml | 50 +----- 47 files changed, 817 insertions(+), 786 deletions(-) create mode 100644 cadastrapp/.settings/org.eclipse.core.resources.prefs create mode 100644 cadastrapp/.settings/org.eclipse.jdt.apt.core.prefs create mode 100644 cadastrapp/.settings/org.eclipse.jdt.core.prefs create mode 100644 cadastrapp/.settings/org.eclipse.m2e.core.prefs create mode 100644 cadastrapp/src/main/java/org/georchestra/cadastrapp/configuration/CadastrappControllerConfig.java create mode 100644 cadastrapp/src/main/java/org/georchestra/cadastrapp/configuration/SwaggerConfig.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/.settings/org.eclipse.core.resources.prefs b/cadastrapp/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 00000000..29abf999 --- /dev/null +++ b/cadastrapp/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,6 @@ +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding//src/main/resources=UTF-8 +encoding//src/test/java=UTF-8 +encoding//src/test/resources=UTF-8 +encoding/=UTF-8 diff --git a/cadastrapp/.settings/org.eclipse.jdt.apt.core.prefs b/cadastrapp/.settings/org.eclipse.jdt.apt.core.prefs new file mode 100644 index 00000000..d4313d4b --- /dev/null +++ b/cadastrapp/.settings/org.eclipse.jdt.apt.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.apt.aptEnabled=false diff --git a/cadastrapp/.settings/org.eclipse.jdt.core.prefs b/cadastrapp/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..1b6e1ef2 --- /dev/null +++ b/cadastrapp/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,9 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.processAnnotations=disabled +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/cadastrapp/.settings/org.eclipse.m2e.core.prefs b/cadastrapp/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 00000000..f897a7f1 --- /dev/null +++ b/cadastrapp/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/cadastrapp/README.md b/cadastrapp/README.md index 1c713157..777a30df 100644 --- a/cadastrapp/README.md +++ b/cadastrapp/README.md @@ -16,18 +16,18 @@ This application is made to be installed behind GeOrchestra security proxy. To i -- As for gerochestra tomcat instance, you will have to create a new instance (choose a port not already use here we choose 8480 for http endpoint and 8405 to stop ``` - sudo tomcat6-instance-create -p 8480 -c 8405 /var/lib/tomcat-cadastrapp + sudo tomcat9-instance-create -p 8480 -c 8405 /var/lib/tomcat-cadastrapp ``` ### Init policy and service sudo mkdir /var/lib/tomcat-cadastrapp/conf/policy.d sudo touch /var/lib/tomcat-cadastrapp/conf/policy.d/empty.policy - sudo chown -R tomcat6:tomcat6 /var/lib/tomcat-cadastrapp - sudo cp /etc/init.d/tomcat6 /etc/init.d/tomcat-cadastrapp - sudo cp /etc/default/tomcat6 /etc/default/tomcat-cadastrapp + sudo chown -R tomcat:tomcat /var/lib/tomcat-cadastrapp + sudo cp /etc/init.d/tomcat9 /etc/init.d/tomcat-cadastrapp + sudo cp /etc/default/tomcat9 /etc/default/tomcat-cadastrapp Finally, edit the ```/etc/init.d/tomcat-cadastrapp``` script, find the following line: ``` -# Provides: tomcat6 +# Provides: tomcat9 ``` ... and replace it with: ``` @@ -44,12 +44,12 @@ JAVA_OPTS="-Djava.awt.headless=true -XX:+UseConcMarkSweepGC" And later add these lines (change the ```STOREPASSWORD``` string): ``` JAVA_OPTS="$JAVA_OPTS \ - -Xms1024m \ + -Xms256m \ -Xmx1024m \ -XX:MaxPermSize=256m" JAVA_OPTS="$JAVA_OPTS \ - -Djavax.net.ssl.trustStore=/etc/tomcat6/keystore \ + -Djavax.net.ssl.trustStore=/etc/georchestra/keystore \ -Djavax.net.ssl.trustStorePassword=STOREPASSWORD" ``` ### Configure connectors @@ -86,7 +86,7 @@ In ```/var/lib/tomcat-cadastrapp/conf/context.xml```, add a new ResourceLink at #### Add jar require for this datasource To be able to connect to postgresql database, tomcat will have to get postgresql client librairie in his classloader. -In tomcat6 instance, you will have to add ```postgresql-9.1-901-1.jdbc4.jar``` to ```/var/lib/tomcat-cadastrapp/lib``` folder (with a symlink) +In tomcat9 instance, you will have to add ```postgresql-42.2.22.jar``` to ```/var/lib/tomcat-cadastrapp/lib``` folder (with a symlink) ### Start the instance diff --git a/cadastrapp/pom.xml b/cadastrapp/pom.xml index 1993df47..ff3e1967 100644 --- a/cadastrapp/pom.xml +++ b/cadastrapp/pom.xml @@ -16,13 +16,12 @@ 1.7.30 1.2.3 1.7.25 - 9.4-1205-jdbc4 - 3.4.3 - 5.3.5 + 42.2.20.jre7 + 5.3.7 6.0.0.Alpha7 5.1.2.Final 24.0 - 2.0.23 + 3.0.0-RC1 2.3.2 @@ -51,16 +50,6 @@ - - org.apache.cxf - cxf-rt-frontend-jaxrs - ${cxf.version} - - - org.apache.cxf - cxf-rt-rs-client - ${cxf.version} - com.fasterxml.jackson.core jackson-core @@ -92,6 +81,11 @@ spring-web ${spring.version} + + org.springframework + spring-webmvc + ${spring.version} + org.springframework @@ -234,7 +228,7 @@ org.apache.xmlgraphics fop - 2.3 + 2.6 net.sf.supercsv @@ -308,9 +302,14 @@ ${pdfbox.version} - org.apache.cxf - cxf-rt-rs-service-description-swagger - 3.1.11 + io.springfox + springfox-swagger2 + 3.0.0 + + + io.springfox + springfox-swagger-ui + 3.0.0 @@ -344,7 +343,7 @@ org.eclipse.jetty jetty-maven-plugin - 9.2.11.v20150529 + 9.4.41.v20210516 /cadastrapp/ @@ -374,6 +373,10 @@ 1.8 + + maven-dependency-plugin + 3.1.2 + @@ -614,7 +617,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/configuration/SwaggerConfig.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/configuration/SwaggerConfig.java new file mode 100644 index 00000000..425e1c15 --- /dev/null +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/configuration/SwaggerConfig.java @@ -0,0 +1,40 @@ +package org.georchestra.cadastrapp.configuration; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import io.swagger.annotations.Contact; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc; + +@Configuration +@EnableSwagger2WebMvc +public class SwaggerConfig { + + @Bean + public Docket api(){ + return new Docket(DocumentationType.SWAGGER_2) + .select() + .apis(RequestHandlerSelectors.any()) + .paths(PathSelectors.regex("/api/.*")) + .build() + .apiInfo(apiInfo()); + } + + private ApiInfo apiInfo() { + return new ApiInfoBuilder() + .title("TITLE") + .description("DESCRIPTION") + .version("VERSION") + .termsOfServiceUrl("http://terms-of-services.url") + .license("LICENSE") + .licenseUrl("http://url-to-license.com") + .build(); + } + +} \ No newline at end of file diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/context/CadastrappContextListener.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/context/CadastrappContextListener.java index 7fe22516..757d262d 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/context/CadastrappContextListener.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/context/CadastrappContextListener.java @@ -17,7 +17,7 @@ * * Context listener specific for cadastrapp * - * @author pierrejego + * @author Pierre Jégo / pierre.jego@jdev.fr * */ public class CadastrappContextListener implements ServletContextListener{ 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..efca046d 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, String rolesList ){ 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(rolesList, "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..faaab3b9 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,16 @@ 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 + * @param rolesList 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(String rolesList, 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(rolesList)>0){ if(parcelleList != null && !parcelleList.isEmpty()){ @@ -49,7 +47,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(rolesList, "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..87b8d0e0 --- /dev/null +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/providers/CadastrappInterceptor.java @@ -0,0 +1,54 @@ +package org.georchestra.cadastrapp.providers; + +import org.apache.commons.lang3.StringUtils; +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 { + + String rolesList = request.getHeader("sec-roles"); + String userName = request.getHeader("sec-username"); + MDC.put("user", userName); + MDC.put("roles", rolesList); + 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("user"); + MDC.remove("roles"); + 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 992aa7f1..00000000 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/providers/PreRequestFilter.java +++ /dev/null @@ -1,37 +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 userName = requestContext.getHeaderString("sec-username"); - MDC.put("user", userName); - MDC.put("roles", rolesList); - MDC.put("uri", requestContext.getUriInfo().getPath()); - - logger.info("Incoming request"); - - if(logger.isDebugEnabled()){ - logger.debug("Parameter list : " + requestContext.getUriInfo().getQueryParameters()); - } - - } -} \ No newline at end of file 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..dc4b1fba 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,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.georchestra.cadastrapp.service.constants.CadastrappConstants; 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.GetMapping; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + public class BatimentController extends CadController { @@ -26,9 +25,8 @@ public class BatimentController extends CadController { @Autowired BatimentHelper batimentHelper; - @GET - @Path("/getBatiments") - @Produces(MediaType.APPLICATION_JSON) + @GetMapping + @RequestMapping(path ="/getBatiments", produces = {MediaType.APPLICATION_JSON_VALUE}) /** * getBuildingsDetails * Returns information about batiment dnubat on given parcell @@ -39,12 +37,12 @@ public class BatimentController extends CadController { * * @return JSON list */ - public List> getBuildingsDetails(@Context HttpHeaders headers, - @QueryParam("parcelle") String parcelle, - @QueryParam("dnubat") String dnubat){ + public List> getBuildingsDetails(@RequestHeader(CadastrappConstants.HTTP_HEADER_ROLES) String rolesList, + @RequestParam("parcelle") String parcelle, + @RequestParam("dnubat") String dnubat){ List> batiments = new ArrayList>(); - if (getUserCNILLevel(headers) == 0) { + if (getUserCNILLevel(rolesList) == 0) { logger.info("User does not have enough rights to see information about batiment"); } else if(parcelle != null && !parcelle.isEmpty() @@ -82,9 +80,8 @@ else if(parcelle != null && !parcelle.isEmpty() } - @GET - @Path("/getBatimentsByParcelle") - @Produces(MediaType.APPLICATION_JSON) + @GetMapping + @RequestMapping(path = "/getBatimentsByParcelle" , produces = {MediaType.APPLICATION_JSON_VALUE}) /** * Returns all building from given plot * @@ -93,16 +90,15 @@ 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 List> getBuildingsByParcelle(@RequestHeader(CadastrappConstants.HTTP_HEADER_ROLES) String rolesList, @RequestParam("parcelle") String parcelle){ List> batiments = new ArrayList>(); - if (getUserCNILLevel(headers) == 0) { + if (getUserCNILLevel(rolesList) == 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, rolesList); } 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 b6a1c869..0a151974 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/CadController.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/CadController.java @@ -6,7 +6,6 @@ import javax.annotation.Resource; import javax.sql.DataSource; -import javax.ws.rs.core.HttpHeaders; import org.georchestra.cadastrapp.configuration.CadastrappPlaceHolder; import org.slf4j.Logger; @@ -15,7 +14,7 @@ /** * - * @author gfi + * @author pierre jego * */ public class CadController { @@ -105,14 +104,11 @@ 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(String rolesList) { int cnilLevel = 0; 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; @@ -131,8 +127,8 @@ protected int getUserCNILLevel(HttpHeaders headers) { * @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(String rolesList) { + return addAuthorizationFiltering(rolesList, ""); } /** @@ -144,7 +140,7 @@ protected String addAuthorizationFiltering(HttpHeaders headers) { * * @return query to complete user right */ - protected String addAuthorizationFiltering(HttpHeaders headers, String tableAlias) { + protected String addAuthorizationFiltering(String rolesList, String tableAlias) { logger.debug("Check user geographical limitation "); @@ -153,13 +149,9 @@ protected String addAuthorizationFiltering(HttpHeaders headers, String tableAlia List deps = new ArrayList(); StringBuilder queryFilter = new StringBuilder(); - - // get roles list in header - // Example 'ROLE_MOD_LDAPADMIN,ROLE_EL_CMS,ROLE_SV_ADMIN' - String roleListString = headers.getHeaderString("sec-roles"); - logger.debug("user roleList : "+ roleListString); - if(roleListString!=null && !roleListString.isEmpty()){ + logger.debug("user roleList : "+ rolesList); + if(rolesList!=null && !rolesList.isEmpty()){ // set separator by default if not set if(roleSeparator.isEmpty()){ @@ -167,7 +159,7 @@ protected String addAuthorizationFiltering(HttpHeaders headers, String tableAlia } // Force to add the array of value in first place of a new Array - String[] roleList = roleListString.split(roleSeparator); + String[] roleList = rolesList.split(roleSeparator); // get commune list in database corresponding to this header StringBuilder queryBuilder = new StringBuilder(); 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..102f48bc 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,18 @@ 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.RequestParam; + +import org.georchestra.cadastrapp.service.constants.CadastrappConstants; /** * Service to get co owners information @@ -60,6 +61,7 @@ * @author pierre jego * */ +@Controller public class CoProprietaireController extends CadController { static final Logger logger = LoggerFactory.getLogger(CoProprietaireController.class); @@ -70,9 +72,8 @@ public class CoProprietaireController extends CadController { @Autowired ProprieteHelper proprieteHelper; - @Path("/getCoProprietaireList") - @GET - @Produces(MediaType.APPLICATION_JSON) + @RequestMapping(path ="/getCoProprietaireList", produces = {MediaType.APPLICATION_JSON_VALUE}) + @GetMapping /** * * /getCoProprietaireList @@ -85,18 +86,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 List> getCoProprietairesList(@RequestHeader(CadastrappConstants.HTTP_HEADER_ROLES) String rolesList, + @RequestParam String parcelle, + @RequestParam String comptecommunal, + @RequestParam String cgocommune, + @RequestParam String ddenom, + @RequestParam(defaultValue = "0") 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(rolesList) > 0 && cgocommune != null && cgocommune.length() >0) { boolean isParamValid = false; @@ -135,7 +136,7 @@ public List> getCoProprietairesList(@Context HttpHeaders hea if(isParamValid){ queryCoProprietaireBuilder.append("and prop.comptecommunal = proparc.comptecommunal "); - queryCoProprietaireBuilder.append(addAuthorizationFiltering(headers, "prop.")); + queryCoProprietaireBuilder.append(addAuthorizationFiltering(rolesList, "prop.")); JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); coProprietaires = jdbcTemplate.queryForList(queryCoProprietaireBuilder.toString(), queryParams.toArray()); } @@ -144,25 +145,25 @@ public List> getCoProprietairesList(@Context HttpHeaders hea return coProprietaires; } - @Path("/getCoProprietaire") - @GET - @Produces(MediaType.APPLICATION_JSON) + @RequestMapping(path = "/getCoProprietaire", produces = {MediaType.APPLICATION_JSON_VALUE}) + @GetMapping /** * 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 Map getCoProprietaire(@RequestParam String parcelle, + @RequestParam(defaultValue = "0") int start, + @RequestParam(defaultValue = "25") int limit, + @RequestHeader(CadastrappConstants.HTTP_HEADER_ROLES) String rolesList) { logger.debug("get Co Proprietaire - parcelle : " + parcelle); Map finalResult = new HashMap(); List> result = new ArrayList>(); - if (getUserCNILLevel(headers) > 0) { + if (getUserCNILLevel(rolesList) > 0) { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); @@ -173,7 +174,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(rolesList, "p.")); queryCount.append(" ) as temp;"); int resultCount = jdbcTemplate.queryForObject(queryCount.toString(), new Object[] {parcelle}, Integer.class); @@ -193,7 +194,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(rolesList, "p.")); queryBuilder.append(" ORDER BY p.app_nom_usage "); queryBuilder.append(" LIMIT ?"); queryBuilder.append(" OFFSET ?"); @@ -211,9 +212,8 @@ public Map getCoProprietaire(@QueryParam("parcelle") String parc } - @POST - @Path("/exportCoProprietaireByParcelles") - @Produces("text/csv") + @PostMapping + @RequestMapping(path = "/exportCoProprietaireByParcelles", produces = {"text/csv;charset=utf-8"}) /** * Create a csv file from given parcelles id * @@ -224,18 +224,18 @@ public Map getCoProprietaire(@QueryParam("parcelle") String parc * * @throws SQLException */ - public Response exportProprietaireByParcelles( - @Context HttpHeaders headers, - @FormParam("parcelles") String parcelles) throws SQLException { + public ResponseEntity exportProprietaireByParcelles( + @RequestHeader(CadastrappConstants.HTTP_HEADER_ROLES) String rolesList, + @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(rolesList)>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(rolesList)>1){ entete = entete + ";lieu_naissance; date_naissance"; } @@ -252,7 +252,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(rolesList)>1){ queryBuilder.append(", dldnss, jdatnss "); } queryBuilder.append("from "); @@ -262,10 +262,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(rolesList)); 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(rolesList)>1){ queryBuilder.append(", dldnss, jdatnss "); } queryBuilder.append(" ORDER BY prop.comptecommunal"); @@ -280,8 +280,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 +299,11 @@ 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") + @PostMapping + @RequestMapping(path = "/exportLotsAsCSV", produces = {"text/csv;charset=utf-8"}) /** * Create a csv file from given plot and building id * @@ -315,14 +315,15 @@ public Response exportProprietaireByParcelles( * * @throws SQLException */ - public Response exportLotsAsSCV( - @Context HttpHeaders headers, - @FormParam("parcelle") String parcelle, @FormParam("dnubat") String dnubat) throws SQLException { + public ResponseEntity exportLotsAsSCV( + @RequestHeader(CadastrappConstants.HTTP_HEADER_ROLES) String rolesList, + @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(rolesList)>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 +336,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 +350,11 @@ 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") + @PostMapping + @RequestMapping(path = "/exportLotsAsPDF" , produces = {MediaType.APPLICATION_PDF_VALUE}) /** * Create a pdf file from given plot and building id * @@ -365,14 +366,15 @@ public Response exportLotsAsSCV( * * @throws SQLException */ - public Response exportLotsAsPDF( - @Context HttpHeaders headers, - @FormParam("parcelle") String parcelle, @FormParam("dnubat") String dnubat) throws SQLException { + public ResponseEntity exportLotsAsPDF( + @RequestHeader(CadastrappConstants.HTTP_HEADER_ROLES) String rolesList, + @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(rolesList)>0){ logger.debug("Input parameters are : " + parcelle + " - " + dnubat); final String xslTemplate = "xsl/lots.xsl"; @@ -457,11 +459,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 +507,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..6c445ba5 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,26 @@ 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.GetMapping; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.georchestra.cadastrapp.service.constants.CadastrappConstants; +@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}) + @GetMapping /** * /getCommune * @@ -42,9 +41,9 @@ public class CommuneController extends CadController{ * @throws SQLException */ public List> getCommunesList( - @Context HttpHeaders headers, - @QueryParam("libcom") String libCom, - @QueryParam("cgocommune") String cgoCommune){ + @RequestHeader(CadastrappConstants.HTTP_HEADER_ROLES) String rolesList, + @RequestParam("libcom") String libCom, + @RequestParam("cgocommune") String cgoCommune){ List> communes = new ArrayList>(); List queryParams = new ArrayList(); @@ -86,7 +85,7 @@ public List> getCommunesList( } if(isSearchFiltered){ - queryBuilder.append(addAuthorizationFiltering(headers)); + queryBuilder.append(addAuthorizationFiltering(rolesList)); } 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..b384edf3 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/ConfigurationController.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/ConfigurationController.java @@ -3,24 +3,23 @@ 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.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +@Controller public class ConfigurationController { final static Logger logger = LoggerFactory.getLogger(ConfigurationController.class); - @GET - @Path("/getConfiguration") - @Produces(MediaType.APPLICATION_JSON) + @GetMapping + @RequestMapping(path = "/getConfiguration", produces = {MediaType.APPLICATION_JSON_VALUE}) /** * Returns server configuration witch is common to client side * 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..870210c2 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,19 @@ 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 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 +104,35 @@ private String imageToString(String nameImage){ * * @return Response that contain File */ - @POST - @Path("/getImageFromDataDir") - public Response getBaseMapPreview(@RequestParam("imageName") String imageName) { + @PostMapping + @RequestMapping(path = "/getImageFromDataDir", produces = {MediaType.TEXT_PLAIN_VALUE}) + 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..e56bf72f 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,17 @@ 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.georchestra.cadastrapp.service.constants.CadastrappConstants; /** * HabitationController @@ -25,14 +25,14 @@ * @author pierre * */ +@Controller public class HabitationController extends CadController { static final Logger logger = LoggerFactory.getLogger(HabitationController.class); - @GET - @Path("/getHabitationDetails") - @Produces(MediaType.APPLICATION_JSON) + @GetMapping + @RequestMapping(path = "/getHabitationDetails", produces = {MediaType.APPLICATION_JSON_VALUE}) /** * Returns information about habitation * @@ -44,16 +44,17 @@ public class HabitationController extends CadController { * @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 Map getHabitationDetails( + @RequestHeader(CadastrappConstants.HTTP_HEADER_ROLES) String rolesList, + @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(rolesList) == 0) { logger.info("User needs does not have enough rights to see habitation details"); } else if(annee != null && invar != null) 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 d3c75d34..615cd3d2 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/ImageParcelleController.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/ImageParcelleController.java @@ -18,13 +18,6 @@ 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; @@ -65,14 +58,23 @@ import org.opengis.referencing.operation.TransformException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RequestMapping; /** * Image Parcelle Controller * - * @author gfi + * @author pierre jego * */ +@Controller public class ImageParcelleController extends CadController { static final Logger logger = LoggerFactory.getLogger(ImageParcelleController.class); @@ -100,18 +102,18 @@ 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) { + @GetMapping + @RequestMapping(path = "/getImageBordereau", produces = {MediaType.IMAGE_PNG_VALUE}) + public ResponseEntity createImageBordereauParcellaire( + @RequestParam() String parcelle, + @RequestParam(defaultValue = "0", name ="basemapindex") int baseMapIndex, + @RequestParam(defaultValue = "1446DE", name ="fillcolor") String styleFillColor, + @RequestParam(defaultValue = "0.50", name ="fillopacity") float styleFillOpacity, + @RequestParam(defaultValue = "10259E", name ="strokecolor") String styleStrokeColor, + @RequestParam(defaultValue = "2", name ="strokewidth") 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")); @@ -383,7 +385,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 +403,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..a71946ac 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/InfoBulleController.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/InfoBulleController.java @@ -5,29 +5,27 @@ 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.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RequestHeader; - +@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}) + @GetMapping /** * * @param headers / headers from request used to filter search using LDAP Roles to display only information about parcelle from available cgocommune @@ -41,31 +39,30 @@ 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 { + @RequestHeader(CadastrappConstants.HTTP_HEADER_ROLES) String rolesList, + @RequestParam("parcelle") String parcelle, + @RequestParam(defaultValue = "1") int infocadastrale, + @RequestParam(defaultValue = "1")int infouf) throws SQLException { Map informations = null; if(infocadastrale == 0 && infouf == 1){ - informations = getInfoBulleUniteFonciere(headers, parcelle); + informations = getInfoBulleUniteFonciere(rolesList, parcelle); }else if (infocadastrale == 1 && infouf == 0){ - informations = getInfoBulleParcelle(headers, parcelle); + informations = getInfoBulleParcelle(rolesList, 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(rolesList, parcelle); + informations.putAll(getInfoBulleUniteFonciere(rolesList, parcelle)); } return informations; } - @Path("/getInfobulleParcelle") - @GET - @Produces("application/json") + @RequestMapping(path = "/getInfobulleParcelle", produces = {MediaType.APPLICATION_JSON_VALUE}) + @GetMapping /** * * @param headers / headers from request used to filter search using LDAP Roles to display only information about parcelle from available cgocommune @@ -76,8 +73,8 @@ public Map getInfoBulle( * @throws SQLException */ public Map getInfoBulleParcelle( - @Context HttpHeaders headers, - @QueryParam("parcelle") String parcelle) throws SQLException { + @RequestHeader(CadastrappConstants.HTTP_HEADER_ROLES) String rolesList, + @RequestParam("parcelle") String parcelle) throws SQLException { Map informations = null; @@ -98,7 +95,7 @@ public Map getInfoBulleParcelle( JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); informations = jdbcTemplate.queryForMap(queryBuilder.toString(), parcelle); - if(getUserCNILLevel(headers)>0){ + if(getUserCNILLevel(rolesList)>0){ List> proprietaires = null; @@ -110,7 +107,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(rolesList, "prop.")); queryProprietaireBuilder.append(" LIMIT 9"); JdbcTemplate jdbcTemplateProp = new JdbcTemplate(dataSource); @@ -129,9 +126,8 @@ public Map getInfoBulleParcelle( return informations; } - @Path("/getInfoUniteFonciere") - @GET - @Produces(MediaType.APPLICATION_JSON) + @RequestMapping(path = "/getInfoUniteFonciere", produces = {MediaType.APPLICATION_JSON_VALUE}) + @GetMapping /** * * @param headers / headers from request used to filter search using LDAP Roles to display only information about parcelle from available cgocommune @@ -142,8 +138,8 @@ public Map getInfoBulleParcelle( * @throws SQLException */ public Map getInfoBulleUniteFonciere( - @Context HttpHeaders headers, - @QueryParam("parcelle") String parcelle) throws SQLException { + @RequestHeader(CadastrappConstants.HTTP_HEADER_ROLES) String rolesList, + @RequestParam("parcelle") String parcelle) throws SQLException { Map informations = new HashMap(); @@ -163,7 +159,7 @@ public Map getInfoBulleUniteFonciere( // filter on geographical limitation only if search is filtered if(isSearchFiltered){ - queryBuilder.append(addAuthorizationFiltering(headers, "p.")); + queryBuilder.append(addAuthorizationFiltering(rolesList, "p.")); } queryBuilder.append("GROUP BY uf.uf, uf.comptecommunal;"); 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..892b284c 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,29 @@ 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.constants.CadastrappConstants; 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.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RequestHeader; + +@Controller public class ProprietaireController extends CadController{ static final Logger logger = LoggerFactory.getLogger(ProprietaireController.class); @@ -41,9 +42,8 @@ public class ProprietaireController extends CadController{ @Autowired ProprietaireHelper proprietaireHelper; - @GET - @Path("/getProprietaire") - @Produces(MediaType.APPLICATION_JSON) + @GetMapping + @RequestMapping(path = "/getProprietaire", produces = {MediaType.APPLICATION_JSON_VALUE}) /** * This will return information about owners in JSON format * @@ -75,15 +75,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 + @RequestHeader(CadastrappConstants.HTTP_HEADER_ROLES) String rolesList, + @RequestParam String dnomlp, + @RequestParam String cgocommune, + @RequestParam("dnupro") final List dnuproList, + @RequestParam("comptecommunal") String compteCommunal, + @RequestParam("globalname") String globalName, + @RequestParam String ddenom, + @RequestParam(defaultValue = "0", name ="birthsearch") boolean isBirthSearch, + @RequestParam(defaultValue = "0") int details ) throws SQLException { // Init list to return response even if nothing in it. @@ -92,7 +92,7 @@ public List> getProprietairesList( logger.info("details : " + details); // User need to be at least CNIL1 level - if (getUserCNILLevel(headers)>0){ + if (getUserCNILLevel(rolesList)>0){ int cgoCommuneLength = Integer.parseInt(CadastrappPlaceHolder.getProperty("cgoCommune.length")); @@ -162,7 +162,7 @@ else if(details == 1){ isWhereAdded = createEqualsClauseRequest(isWhereAdded, queryBuilder, "comptecommunal", compteCommunal, queryParams); - queryBuilder.append(addAuthorizationFiltering(headers)); + queryBuilder.append(addAuthorizationFiltering(rolesList)); if(details != 2){ queryBuilder.append("order by app_nom_usage, app_nom_naissance limit 25 "); @@ -183,9 +183,8 @@ else if(details == 1){ } - @GET - @Path("/getProprietairesByParcelles") - @Produces("application/json") + @GetMapping + @RequestMapping(path = "/getProprietairesByParcelles", produces = {MediaType.APPLICATION_JSON_VALUE}) /** * This will return information about owners in JSON format * @@ -199,16 +198,15 @@ else if(details == 1){ * @throws SQLException */ public List> getProprietairesByParcelle( - @Context HttpHeaders headers, - @QueryParam("parcelles") List parcelleList + @RequestHeader(CadastrappConstants.HTTP_HEADER_ROLES) String rolesList, + @RequestParam("parcelles") List parcelleList ) throws SQLException { - return proprietaireHelper.getProprietairesByParcelles(headers, parcelleList, true); + return proprietaireHelper.getProprietairesByParcelles(rolesList, parcelleList, true); } - @GET - @Path("/getProprietairesByInfoParcelles") - @Produces("application/json") + @GetMapping + @RequestMapping(path = "/getProprietairesByInfoParcelles", produces = {MediaType.APPLICATION_JSON_VALUE}) /** * This will return information about co-owners in JSON format * @@ -224,18 +222,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 + @RequestHeader(CadastrappConstants.HTTP_HEADER_ROLES) String rolesList, + @RequestParam("commune") String commune, + @RequestParam("section") String section, + @RequestParam("numero") String numero, + @RequestParam("ddenom") 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(rolesList)>0){ // if search by dnuproList or comptecommunal // directly search in view parcelle @@ -281,31 +279,30 @@ public List> getProprietairesByInfoParcelle( } - @POST - @Path("/exportProprietaireByParcelles") - @Produces("text/csv") + @PostMapping + @RequestMapping(path = "/exportProprietaireByParcelles", produces = {"text/csv"}) /** * 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( + @RequestHeader(CadastrappConstants.HTTP_HEADER_ROLES) String rolesList, + @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(rolesList)>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(rolesList)>1){ entete = entete + ";lieu_naissance; date_naissance"; } @@ -322,7 +319,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(rolesList)>1){ queryBuilder.append(", dldnss, jdatnss "); } queryBuilder.append("from "); @@ -332,10 +329,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(rolesList)); 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(rolesList)>1){ queryBuilder.append(", dldnss, jdatnss "); } queryBuilder.append(" ORDER BY prop.comptecommunal"); @@ -348,8 +345,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 +365,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..99a8269c 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,13 @@ 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.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +@Controller public class RequestInformationController { final static Logger logger = LoggerFactory.getLogger(RequestInformationController.class); @@ -52,9 +50,8 @@ public class RequestInformationController { @Autowired UserRequestRepository userRepository; - @GET - @Path("/checkRequestLimitation") - @Produces(MediaType.APPLICATION_JSON) + @GetMapping + @RequestMapping(path = "/checkRequestLimitation", produces = {MediaType.APPLICATION_JSON_VALUE}) /** * /checkRequestLimitation * @@ -68,7 +65,9 @@ public class RequestInformationController { * * @throws SQLException */ - public Map checkRequestLimitation(@QueryParam("cni") String cni, @QueryParam("type") String type, @Context HttpHeaders headers) throws SQLException { + public Map checkRequestLimitation( + @RequestParam String cni, + @RequestParam String type) throws SQLException { Map result = new HashMap(); @@ -124,9 +123,8 @@ public Map checkRequestLimitation(@QueryParam("cni") String cni, return result; } - @GET - @Path("/saveInformationRequest") - @Produces(MediaType.APPLICATION_JSON) + @GetMapping + @RequestMapping(path = "/saveInformationRequest", produces = {MediaType.APPLICATION_JSON_VALUE}) /** * /** * /saveInformationRequest @@ -167,8 +165,8 @@ 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 { + public Map saveInformationRequest(@RequestParam("cni") String cni, @RequestParam("type") String type, @RequestParam("adress") String adress, @RequestParam("commune") String commune, @RequestParam("codepostal") String codePostal, @RequestParam("firstname") String firstname, @RequestParam("lastname") String lastname, @RequestParam("mail") String mail, + @RequestParam("comptecommunaux") List compteCommunaux, @RequestParam("parcelleIds") List parcelleIds, @RequestParam("proprietaires") List proprietaires, @RequestParam("parcelles") List parcelles, @RequestParam("coproprietes") List coProprietes, @RequestParam("proprietaireLots") List lotCoproprietes, @RequestParam("askby") int askby, @RequestParam("responseby") int responseby) throws SQLException { // todo recheck value 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..22ae5840 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.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +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) + @GetMapping + @RequestMapping(path = "/getSection", produces = {MediaType.APPLICATION_JSON_VALUE}) /** * /getSection * @@ -42,10 +42,10 @@ 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 { + @RequestHeader(CadastrappConstants.HTTP_HEADER_ROLES) String rolesList, + @RequestParam("cgocommune") String cgoCommune, + @RequestParam("ccopre") String ccopre, + @RequestParam("ccosec") 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..b7de5a5d 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,21 @@ 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.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RequestHeader; - +@Controller public class UniteCadastraleController extends CadController { final static Logger logger = LoggerFactory.getLogger(UniteCadastraleController.class); @@ -30,9 +29,8 @@ public class UniteCadastraleController extends CadController { @Autowired ProprietaireHelper proprietaireHelper; - @Path("/getFIC") - @GET - @Produces(MediaType.APPLICATION_JSON) + @RequestMapping(path = "/getFIC", produces = {MediaType.APPLICATION_JSON_VALUE}) + @GetMapping /** * TODO change this to 5 separated services * @@ -48,9 +46,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 List> getInformationCadastrale(@RequestHeader(CadastrappConstants.HTTP_HEADER_ROLES) String rolesList, + @RequestParam("parcelle") String parcelle, + @RequestParam("onglet") int onglet) { logger.debug(" parcelle : " + parcelle + " onglet : " + onglet); @@ -58,33 +56,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(rolesList, parcelles, false); logger.warn("Deprecated service, use getProprietairesByParcelle instead"); break; case 2: - if (getUserCNILLevel(headers)>1){ - information = batimentHelper.getBuildings(parcelle, headers); + if (getUserCNILLevel(rolesList)>1){ + information = batimentHelper.getBuildings(parcelle, rolesList); } 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(rolesList)>1){ + information = infoOngletSubdivision(parcelle, rolesList); } else{ logger.info("User does not have enough right to see information about subdivision"); } break; case 4: - information = infoOngletHistorique(parcelle, headers); + information = infoOngletHistorique(parcelle, rolesList); break; default: logger.error(" No values to return for onglet : " + onglet); @@ -100,11 +98,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 +127,11 @@ 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 + * @param String rolesList * * @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, String rolesList){ logger.debug("infoOngletSubdivision - parcelle : " + parcelle); @@ -145,7 +142,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(rolesList, "pnb.")); // init jdbc template JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); @@ -161,7 +158,7 @@ private List> infoOngletSubdivision(String parcelle, HttpHea * @param HttpHeaders headers * @return List> */ - private List> infoOngletHistorique(String parcelle, HttpHeaders headers){ + private List> infoOngletHistorique(String parcelle, String rolesList){ logger.debug("infoOngletHistorique - parcelle : " + parcelle); @@ -174,7 +171,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(rolesList, "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..6ef49601 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.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; - +@Controller public class VoieController extends CadController { final static Logger logger = LoggerFactory.getLogger(VoieController.class); - @GET - @Path("/getVoie") - @Produces(MediaType.APPLICATION_JSON) + @GetMapping + @RequestMapping(path = "/getVoie", produces = {MediaType.APPLICATION_JSON_VALUE}) /** * /getVoie * @@ -42,8 +40,8 @@ public class VoieController extends CadController { * @throws SQLException */ public List> getVoie( - @QueryParam("cgocommune") String cgoCommune, - @QueryParam("dvoilib") String dvoilib) throws SQLException { + @RequestParam("cgocommune") String cgoCommune, + @RequestParam("dvoilib") String dvoilib) throws SQLException { List> voies = new ArrayList>(); List queryParams = new ArrayList(); 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..9812e42f 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,8 @@ 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"; + } 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..02461653 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.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + +@Controller public class CSVExportController extends CadController { static final Logger logger = LoggerFactory.getLogger(CSVExportController.class); @@ -35,12 +37,11 @@ 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) { + @GetMapping + @RequestMapping(path = "/exportAsCsv", produces = "text/csv" ) + 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 +78,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 +96,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..76ab6607 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; @@ -43,10 +34,22 @@ import org.georchestra.cadastrapp.model.pdf.BordereauParcellaire; import org.georchestra.cadastrapp.model.pdf.Style; import org.georchestra.cadastrapp.service.CadController; +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.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.GetMapping; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + +@Controller public class BordereauParcellaireController extends CadController { final static Logger logger = LoggerFactory.getLogger(BordereauParcellaireController.class); @@ -61,7 +64,7 @@ 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 rolesList, 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 +76,18 @@ 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(); + @GetMapping + @RequestMapping(path = "/createBordereauParcellaire", produces ={MediaType.APPLICATION_PDF_VALUE}) + public ResponseEntity createBordereauParcellaire(@RequestHeader(CadastrappConstants.HTTP_HEADER_ROLES) String rolesList, + @RequestParam("parcelle") final List parcelleList, + @RequestParam(name = "personaldata", defaultValue = "0") int personalData, + @RequestParam(name = "basemapindex", defaultValue = "0") int baseMapIndex, + @RequestParam(name = "fillcolor", defaultValue = "#1446DE") String styleFillColor, + @RequestParam(name = "opacity", defaultValue = "0.50") float styleFillOpacity, + @RequestParam(name = "strokecolor", defaultValue = "#10259E") String styleStrokeColor, + @RequestParam(name = "strokewidth", defaultValue = "2") int styleStrokeWidth) { + + ResponseEntity response = new ResponseEntity(HttpStatus.NO_CONTENT); // Check if parcelle list is not empty if (parcelleList != null && !parcelleList.isEmpty()) { @@ -148,7 +150,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, rolesList, false, plotsStyle, baseMapIndex); File xmlfile = null; File foFile = null; OutputStream foOutPutStream = null; @@ -190,11 +192,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 +238,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..69951dbe 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,7 @@ public final class BordereauParcellaireHelper extends CadController{ /** * Get all information from database for all parcelle list * - * @param headers use for CNIL level limitation + * @param rolesList use for CNIL level limitation * @param isCoPro get copro BP information if true * @param parcelleList * List of parcelle id, like @@ -70,14 +69,14 @@ 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, String rolesList, boolean isCoPro) { + return getBordereauParcellaireInformation(parcelleList, personalData, rolesList, isCoPro, null, 0); } /** * Get all information from database for all parcelle list * - * @param headers use for CNIL level limitation + * @param rolesList use for CNIL level limitation * @param isCoPro get copro BP information if true * @param parcelleList * List of parcelle id, like @@ -89,7 +88,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, String rolesList, boolean isCoPro, Style plotStyle, int baseMapIndex) { BordereauParcellaire bordereauParcellaire = new BordereauParcellaire(); @@ -142,7 +141,7 @@ public BordereauParcellaire getBordereauParcellaireInformation(List parc logger.debug("Parcelle information : " + parcelle); - if (personalData > 0 && getUserCNILLevel(headers)>0) { + if (personalData > 0 && getUserCNILLevel(rolesList)>0) { List proprietaires = new ArrayList(); String tableName = (isCoPro)?tableCoProprietaire:tableProprietaire; @@ -157,7 +156,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(rolesList)); 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..767da919 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.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + +@Controller public class DemandeController extends CadController { static final Logger logger = LoggerFactory.getLogger(DemandeController.class); @@ -53,12 +54,13 @@ 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 { + @GetMapping + @RequestMapping(path = "/createDemandeFromObj", produces ={MediaType.APPLICATION_PDF_VALUE}) + public ResponseEntity createDemandeFromObj( + @RequestHeader(CadastrappConstants.HTTP_HEADER_ROLES) String rolesList, + @RequestParam(name="requestid") long requestId) throws IOException { - ResponseBuilder response = Response.noContent(); + ResponseEntity response = new ResponseEntity<>(HttpStatus.NO_CONTENT); List listPdfPath = new ArrayList(); @@ -82,22 +84,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, rolesList, false)); } //if RP if("1".equals(objReq.getRp())){ - listPdfPath.add(createReleveProprieteByCC(objReq.getComptecommunal(), headers,isMinimal)); + listPdfPath.add(createReleveProprieteByCC(objReq.getComptecommunal(), rolesList,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(), rolesList)); } //if RP if("1".equals(objReq.getRp())){ - listPdfPath.add(createReleveProprieteById(objReq.getParcelle(), headers, isMinimal)); + listPdfPath.add(createReleveProprieteById(objReq.getParcelle(), rolesList, isMinimal)); } @@ -105,11 +107,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(), rolesList, true)); } //if RP if("1".equals(objReq.getRp())){ - listPdfPath.add(createReleveCoProprieteByCCandParcelle(objReq.getComptecommunal(),objReq.getParcelle(), headers,isMinimal)); + listPdfPath.add(createReleveCoProprieteByCCandParcelle(objReq.getComptecommunal(),objReq.getParcelle(), rolesList,isMinimal)); } @@ -117,11 +119,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(), rolesList)); } //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(), rolesList,isMinimal)); } @@ -129,21 +131,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(), rolesList)); } //if RP if("1".equals(objReq.getRp())){ - listPdfPath.add(createReleveProprieteByInfoOwner(objReq.getCommune(),objReq.getProprietaire(), headers,isMinimal)); + listPdfPath.add(createReleveProprieteByInfoOwner(objReq.getCommune(),objReq.getProprietaire(), rolesList,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(), rolesList)); } //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(), rolesList,isMinimal)); } } @@ -166,23 +168,30 @@ 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 rolesList 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, String rolesList, boolean isMinimal) { //Store field search if no data to display => inform on PDF file List fields = new ArrayList(); @@ -190,7 +199,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, rolesList, new String()); File pdf = null; //generate PDF @@ -209,11 +218,11 @@ private File createReleveProprieteByCC(String compteCommunal, HttpHeaders header * Create RP using parcelle id * * @param parcelle id parcelle - * @param headers http header containing restriction + * @param rolesList 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, String rolesList, boolean isMinimal) { //Store field search if no data to display => inform on PDF file List fields = new ArrayList(); @@ -228,7 +237,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, rolesList, parcelle); File pdf = null; @@ -249,10 +258,10 @@ private File createReleveProprieteById(String parcelle, HttpHeaders headers, boo * Create borderau parcellaire using parcelle id * * @param parcelle id parcelle - * @param headers http header containing restriction + * @param rolesList http header containing restriction * @return PDF File BP */ - private File createBordereauParcellaireById(String parcelle, HttpHeaders headers) { + private File createBordereauParcellaireById(String parcelle, String rolesList) { //Store field search if no data to display => inform on PDF file List fields = new ArrayList(); @@ -260,7 +269,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, rolesList,false); File pdf = null; try { @@ -301,7 +310,7 @@ private File createBordereauParcellaireById(String parcelle, HttpHeaders headers * * @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, String rolesList, boolean isCoPro) { // Store field search if no data to display => inform on PDF file List fields = new ArrayList(); @@ -326,7 +335,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, rolesList, isCoPro); try { //generate PDF if(bordereauParcellaire.isEmpty()){ @@ -361,7 +370,7 @@ private File createBordereauParcellaireByCC(String comptecommunal,String parcell * @param isMinimal * @return File PDF RP */ - private File createReleveCoProprieteByCCandParcelle(String compteCommunal, String parcelleId, HttpHeaders headers, boolean isMinimal) { + private File createReleveCoProprieteByCCandParcelle(String compteCommunal, String parcelleId, String rolesList, boolean isMinimal) { //Store field search if no data to display => inform on PDF file List fields = new ArrayList(); @@ -369,7 +378,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, rolesList, parcelleId); File pdf = null; //generate PDF @@ -394,7 +403,7 @@ private File createReleveCoProprieteByCCandParcelle(String compteCommunal, Strin * @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, String rolesList){ //Store field search if no data to display => inform on PDF file List fields = new ArrayList(); @@ -408,7 +417,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, rolesList,false); File pdf = null; try { //generate PDF @@ -437,7 +446,7 @@ private File createBordereauParcellaireByInfoParcelle(String commune, String sec * @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, String rolesList, boolean isMinimal) { List compteCommunauxList = new ArrayList(); //get compte communal by parcelle @@ -450,7 +459,7 @@ private File createReleveProprieteByInfoParcelle(String commune, String section, } // Get Releve Propriete information - RelevePropriete relevePropriete = releveProprieteHelper.getReleveProprieteInformation(compteCommunauxList, headers, idParcelle); + RelevePropriete relevePropriete = releveProprieteHelper.getReleveProprieteInformation(compteCommunauxList, rolesList, idParcelle); //generate PDF File pdf = releveProprieteHelper.generatePDF(relevePropriete,isMinimal, false); @@ -467,7 +476,7 @@ private File createReleveProprieteByInfoParcelle(String commune, String section, * @param headers * @return */ - private File createBordereauParcellaireByInfoOwner(String commune, String ownerName, HttpHeaders headers){ + private File createBordereauParcellaireByInfoOwner(String commune, String ownerName, String rolesList){ //Store field search if no data to display => inform on PDF file List fields = new ArrayList(); @@ -481,7 +490,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, rolesList,false); File pdf = null; try { //generate PDF @@ -509,7 +518,7 @@ private File createBordereauParcellaireByInfoOwner(String commune, String ownerN * @param isMinimal * @return File PDF RP */ - private File createReleveProprieteByInfoOwner(String commune, String ownerName, HttpHeaders headers, boolean isMinimal) { + private File createReleveProprieteByInfoOwner(String commune, String ownerName, String rolesList, boolean isMinimal) { List compteCommunauxList = new ArrayList(); //get compte communal by commune and owner @@ -521,7 +530,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, rolesList, new String()); //generate PDF File pdf = releveProprieteHelper.generatePDF(relevePropriete,isMinimal, false); @@ -540,7 +549,7 @@ private File createReleveProprieteByInfoOwner(String commune, String ownerName, * @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, String rolesList) { //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 +562,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, rolesList, false); File pdf = null; try { @@ -582,7 +591,7 @@ private File createBordereauParcellaireLot(String commune, String section, Strin * @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, String rolesList, 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 +604,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, rolesList, 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..d9671f05 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,20 @@ 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.GetMapping; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.georchestra.cadastrapp.service.constants.CadastrappConstants; +@Controller public class ReleveProprieteController extends CadController { static final Logger logger = LoggerFactory.getLogger(ReleveProprieteController.class); @@ -55,12 +58,14 @@ public class ReleveProprieteController extends CadController { * @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) { + @GetMapping + @RequestMapping(path = "/createRelevePropriete", produces ={MediaType.APPLICATION_PDF_VALUE}) + public ResponseEntity createRelevePDFPropriete( + @RequestHeader(CadastrappConstants.HTTP_HEADER_ROLES) String rolesList, + @RequestParam(name= "compteCommunal") List comptesCommunaux, + @RequestParam(name="parcelleId") String idParcelle) { - ResponseBuilder response = Response.noContent(); + ResponseEntity response = new ResponseEntity<>(HttpStatus.NO_CONTENT); logger.debug("Controller Parcelle ID (param) : "+idParcelle); @@ -72,18 +77,25 @@ 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, rolesList, 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; } @@ -96,12 +108,14 @@ public Response createRelevePDFPropriete(@Context HttpHeaders headers, @QueryPar * @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 { + @GetMapping + @RequestMapping(path = "/createReleveProprieteAsCSV", produces = "application/zip") + public ResponseEntity createReleveCSVPropriete( + @RequestHeader(CadastrappConstants.HTTP_HEADER_ROLES) String rolesList, + @RequestParam(name= "compteCommunal") List comptesCommunaux, + @RequestParam(name= "parcelleId") String idParcelle) throws IOException { - ResponseBuilder response = Response.noContent(); + ResponseEntity response = new ResponseEntity<>(HttpStatus.NO_CONTENT); String tempFolder = CadastrappPlaceHolder.getProperty("tempFolder"); @@ -115,7 +129,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, rolesList, idParcelle); // Define Date for all file name DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH_mm_ss_SSS"); @@ -368,15 +382,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..0bd5b696 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 rolesList, 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(rolesList) > 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(rolesList)); queryBuilderProprietaire.append("order by prop.dnulp ASC "); logger.debug("Get owners information "); @@ -539,9 +537,9 @@ public List> getProprietaireByInfoLot(String commune, String * @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, String rolesList) { - return getReleveProprieteInformation(comptesCommunaux, headers, null); + return getReleveProprieteInformation(comptesCommunaux, rolesList, 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..0ce56449 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.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + +@Controller public class RequestPDFController{ static final Logger logger = LoggerFactory.getLogger(RequestPDFController.class); @@ -51,12 +53,11 @@ public class RequestPDFController{ @Autowired RequestRepository requestRepository; - @GET - @Path("/printPDFRequest") - @Produces("application/pdf") - public Response printPDFRequest(@Context HttpHeaders headers, @QueryParam("requestid") long requestId) { + @GetMapping + @RequestMapping(path = "/printPDFRequest", produces = {MediaType.APPLICATION_PDF_VALUE}) + 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 +143,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 +182,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/resources/cadastrapp.properties b/cadastrapp/src/main/resources/cadastrapp.properties index 5f1dcb4e..764a8d5f 100644 --- a/cadastrapp/src/main/resources/cadastrapp.properties +++ b/cadastrapp/src/main/resources/cadastrapp.properties @@ -9,7 +9,7 @@ user.search.are.filtered=1 # Database schema name -schema.name=cadastrapp_qgis +schema.name=cadastrapp ## CNIL ROLE NAME for ldap group. Only Cnil 1 and Cnil 2 make some limitation cnil1RoleName=ROLE_EL_CAD_CNIL1 diff --git a/cadastrapp/src/main/webapp/WEB-INF/beans.xml b/cadastrapp/src/main/webapp/WEB-INF/beans.xml index 7ece8b15..b6aaac6d 100644 --- a/cadastrapp/src/main/webapp/WEB-INF/beans.xml +++ b/cadastrapp/src/main/webapp/WEB-INF/beans.xml @@ -1,27 +1,33 @@ - - - + - - - + + + + + + + + + + - + classpath:cadastrapp.properties @@ -34,39 +40,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -76,8 +49,7 @@ - + @@ -112,7 +84,7 @@ false false false - validate + create @@ -128,52 +100,51 @@ - + - + - - - - + + + + - - - - - - - - - + + + + + + + + + + + + + + + + + + true + + + + + + + + + + + + + + - - - - - - - - true - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/cadastrapp/src/main/webapp/WEB-INF/jetty-env.xml b/cadastrapp/src/main/webapp/WEB-INF/jetty-env.xml index f8866569..03d33265 100644 --- a/cadastrapp/src/main/webapp/WEB-INF/jetty-env.xml +++ b/cadastrapp/src/main/webapp/WEB-INF/jetty-env.xml @@ -6,10 +6,10 @@ jdbc/cadastrapp - www-data - www-data + pierre + vQn3gB2PbXjwm6KCkT9e cadastrapp - 127.0.0.1 + 51.83.74.234 5432 diff --git a/cadastrapp/src/main/webapp/WEB-INF/web.xml b/cadastrapp/src/main/webapp/WEB-INF/web.xml index 73e3872f..459fdce8 100644 --- a/cadastrapp/src/main/webapp/WEB-INF/web.xml +++ b/cadastrapp/src/main/webapp/WEB-INF/web.xml @@ -22,28 +22,11 @@ org.georchestra.cadastrapp.context.CadastrappContextListener - - - - default - /apidocs/* - index.jsp - - - - CXFServlet - org.apache.cxf.transport.servlet.CXFServlet - 1 - - - CXFServlet - /services/* - 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 6933eafa..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 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -