diff --git a/README.md b/README.md index 15901fe..de6ea57 100644 --- a/README.md +++ b/README.md @@ -55,9 +55,12 @@ Des Weiteren werden Hydranten und Routen unterstützt: Da in der Regel keine POIs oder Bushaltestellen auf der Karte gebraucht werden, werden diese Styles standardmäßig deaktiviert, dieses Verhalten kann aber überschrieben werden: * showPois (optional, default = false) + +Für den Fall, dass die Karte abgespeichert werden soll, kann auch ein Identifier für den Dateinamen angegeben werden: +* identifier (optional, default = ) Beispiel: -```http://localhost:8080/generic?lat=49.64703345265409&lng=10.566260347368512&size=640x640&scale=2&zoom=15&maptype=roadmap&showRoute=true&showHydrants=true``` +```http://localhost:8080/generic?lat=49.64703345265409&lng=10.566260347368512&size=640x640&scale=2&zoom=15&maptype=roadmap&showRoute=true&showHydrants=true&identifier=abc``` ### Health check Bietet eine Monitoringschnittstelle zur Überwachung und zum Prüfen der Konfiguration. diff --git a/src/main/java/com/fe2/api/InputController.java b/src/main/java/com/fe2/api/InputController.java index 0186736..c0eed2f 100644 --- a/src/main/java/com/fe2/api/InputController.java +++ b/src/main/java/com/fe2/api/InputController.java @@ -70,9 +70,10 @@ public ResponseEntity route(@RequestParam(value = "lat") double lat, public ResponseEntity generic(@RequestParam MultiValueMap parameters, @RequestParam(value="showHydrants", defaultValue = "false") boolean showHydrants, @RequestParam(value="showRoute", defaultValue = "false") boolean showRoute, - @RequestParam(value="showPois", defaultValue = "false") boolean showPois) + @RequestParam(value="showPois", defaultValue = "false") boolean showPois, + @RequestParam(value="identifier") Optional identifier) { - return mapGenerator.generateMap(parameters, showHydrants, showRoute, showPois); + return mapGenerator.generateGenericMap(parameters, showHydrants, showRoute, showPois, identifier); } } diff --git a/src/main/java/com/fe2/service/MapGenerator.java b/src/main/java/com/fe2/service/MapGenerator.java index 3c5c5a3..f4dc834 100644 --- a/src/main/java/com/fe2/service/MapGenerator.java +++ b/src/main/java/com/fe2/service/MapGenerator.java @@ -8,9 +8,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.util.MultiValueMap; -import org.springframework.util.StreamUtils; -import java.io.InputStream; import java.net.URL; import java.nio.file.Path; import java.util.Optional; @@ -86,7 +84,7 @@ public ResponseEntity generateMap(final String endpoint, final double la .body(image); } - public ResponseEntity generateMap(final MultiValueMap parameters, boolean showHydrants, boolean showRoute, boolean showPois) + public ResponseEntity generateGenericMap(final MultiValueMap parameters, boolean showHydrants, boolean showRoute, boolean showPois, Optional identifier) { URL url; try { @@ -96,6 +94,11 @@ public ResponseEntity generateMap(final MultiValueMap pa return generateErrorResponse("ERROR: Exception generating URL: " + e.getMessage()); } + String filename = "generic"; + if (identifier.isPresent()) { + filename += "_" + identifier.get(); + } + byte[] image; try { image = imageRetriever.downloadImage(url); @@ -104,6 +107,16 @@ public ResponseEntity generateMap(final MultiValueMap pa return generateErrorResponse("ERROR: Exception downloading image: " + e.getMessage()); } + try { + if (configuration.isImageStoringEnabled()) { + Path outputFile = FileHelper.getFullOutputFilePath(configuration.getOutputFolder(), filename, configuration.getOutputFormat()); + FileHelper.writeToFile(image, outputFile); + } + } + catch (Exception e) { + return generateErrorResponse("ERROR: Exception storing image: " + e.getMessage()); + } + return ResponseEntity .ok() .contentType(FileHelper.getMediaType(configuration.getOutputFormat()))