diff --git a/cadastrapp/pom.xml b/cadastrapp/pom.xml index 142bcf4a..b5803e51 100644 --- a/cadastrapp/pom.xml +++ b/cadastrapp/pom.xml @@ -20,7 +20,7 @@ 5.3.8 6.0.0.Alpha7 5.1.2.Final - 24.0 + 25.2 3.0.0-RC1 2.3.2 2.10.5 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 c246006b..bbb663ca 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/ImageParcelleController.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/service/ImageParcelleController.java @@ -11,6 +11,7 @@ import java.io.File; import java.io.IOException; import java.io.Serializable; +import java.io.ByteArrayOutputStream; import java.net.URL; import java.net.URLEncoder; import java.nio.charset.Charset; @@ -58,6 +59,8 @@ import org.opengis.referencing.operation.TransformException; 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.MediaType; import org.springframework.http.ResponseEntity; @@ -98,7 +101,7 @@ public class ImageParcelleController extends CadController { * @return Response with noContent in case of error, png otherwise */ @RequestMapping(path = "/getImageBordereau", produces = {MediaType.IMAGE_PNG_VALUE}, method= {RequestMethod.GET}) - public ResponseEntity createImageBordereauParcellaire( + public ResponseEntity createImageBordereauParcellaire( @RequestParam() String parcelle, @RequestParam(defaultValue = "0", name ="basemapindex", required = false) int baseMapIndex, @RequestParam(defaultValue = "1446DE", name ="fillcolor", required = false) String styleFillColor, @@ -107,7 +110,7 @@ public ResponseEntity createImageBordereauParcellaire( @RequestParam(defaultValue = "2", name ="strokewidth", required = false) int styleStrokeWidth) { // Create empty reponse for default value - ResponseEntity response = new ResponseEntity(HttpStatus.NO_CONTENT); + ResponseEntity response = new ResponseEntity(HttpStatus.NO_CONTENT); final int parcelleIdLength = Integer.parseInt(CadastrappPlaceHolder.getProperty("parcelleId.length")); @@ -145,15 +148,21 @@ public ResponseEntity createImageBordereauParcellaire( try { dataStore = dsf.createDataStore(connectionParameters); + // check all typeName, geo_parcelle are sometimes visibile in geoserver but not here + // redeploy in geoserver is needed + if(logger.isDebugEnabled()){ + logger.debug("Datastore name "+ dataStore.getTypeNames()); + for (String typeName : dataStore.getTypeNames()) { + logger.debug("Type name : " + typeName); + } + } + SimpleFeatureSource source; - String cadastreWFSLayerNameOri = CadastrappPlaceHolder.getProperty("cadastre.wfs.layer.name"); - - // remove this if not using gt-wfs-ng anymore - // using ng extension : need to be changed by_ - String cadastreWFSLayerName = cadastreWFSLayerNameOri.replaceFirst(":", "_"); + String cadastreWFSLayerName = CadastrappPlaceHolder.getProperty("cadastre.wfs.layer.name"); String cadastreLayerIdParcelle = CadastrappPlaceHolder.getProperty("cadastre.layer.idParcelle"); + logger.debug("Cadastre WFS LayerName "+ cadastreWFSLayerName); source = dataStore.getFeatureSource(cadastreWFSLayerName); // Make sure source have been found before making request filter @@ -288,15 +297,14 @@ public ResponseEntity createImageBordereauParcellaire( if(plotLayerWmsUrl != null && !plotLayerWmsUrl.isEmpty()){ wmsCadastralLayer = createWebMapServer(plotLayerWmsUrl,plotLayerWmsUsername, plotLayerWmsPassword ); - cadastreWFSLayerNameOri = CadastrappPlaceHolder.getProperty("parcelle.wms.layer.name"); //TODO see if specific SRS and format are needed - requestCadastralLayer = createAndConfigureMapRequest(wmsCadastralLayer, cadastralLayerFormat, cadastreWFSLayerNameOri, pdfImagePixelSize, cadastreSRS, bounds); + requestCadastralLayer = createAndConfigureMapRequest(wmsCadastralLayer, cadastralLayerFormat, cadastreWFSLayerName, pdfImagePixelSize, cadastreSRS, bounds); cadastreLayerIdParcelle = CadastrappPlaceHolder.getProperty("parcelle.wms.layer.id"); } logger.debug("Create feature image from WMS"); - StyledLayerDescriptor sld = generateSLD(cadastreWFSLayerNameOri, cadastreLayerIdParcelle, parcelle, styleFillColor, styleFillOpacity, styleStrokeColor, styleStrokeWidth); + StyledLayerDescriptor sld = generateSLD(cadastreWFSLayerName, cadastreLayerIdParcelle, parcelle, styleFillColor, styleFillOpacity, styleStrokeColor, styleStrokeWidth); SLDTransformer styleTransform = new SLDTransformer(); styleTransform.setEncoding(Charset.forName("UTF-8")); @@ -373,14 +381,16 @@ public ResponseEntity createImageBordereauParcellaire( g2.dispose(); - // Get temp folder from properties file - final String tempFolder = CadastrappPlaceHolder.getProperty("tempFolder"); - - File file = new File(tempFolder + File.separator + "BP-" + parcelle + ".png"); - file.deleteOnExit(); - ImageIO.write(finalImage, "png", file); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ImageIO.write(finalImage, "png", baos); + byte[] bytes = baos.toByteArray(); + + // Create response + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.IMAGE_PNG); + headers.setContentDispositionFormData("filename", "BP-" + parcelle + ".png"); - response = new ResponseEntity(file, HttpStatus.OK); + response = new ResponseEntity(bytes, headers, HttpStatus.OK); } else { logger.info("No plots corresponding on WFS server"); } 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 1cd5cef9..a6422250 100644 --- a/cadastrapp/src/test/java/org/georchestra/cadastrapp/service/ImageParcelleControllerTest.java +++ b/cadastrapp/src/test/java/org/georchestra/cadastrapp/service/ImageParcelleControllerTest.java @@ -34,7 +34,7 @@ public void testCreateImageBordereauParcellaire() { ImageParcelleController imageParcelleController = new ImageParcelleController(); - ResponseEntity response = imageParcelleController.createImageBordereauParcellaire("2014630103000AO0351", 0, "#1446DE", (float) 0.50, "#10259E",2); + ResponseEntity response = imageParcelleController.createImageBordereauParcellaire("2014630103000AO0351", 0, "#1446DE", (float) 0.50, "#10259E",2); }