Skip to content

Commit

Permalink
Support image storing for generic api
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Zellner committed Mar 20, 2023
1 parent 64dbf17 commit 930ed95
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <empty>)

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.
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/fe2/api/InputController.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ public ResponseEntity<Object> route(@RequestParam(value = "lat") double lat,
public ResponseEntity<Object> generic(@RequestParam MultiValueMap<String, String> 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<String> identifier)
{
return mapGenerator.generateMap(parameters, showHydrants, showRoute, showPois);
return mapGenerator.generateGenericMap(parameters, showHydrants, showRoute, showPois, identifier);
}

}
19 changes: 16 additions & 3 deletions src/main/java/com/fe2/service/MapGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -86,7 +84,7 @@ public ResponseEntity<Object> generateMap(final String endpoint, final double la
.body(image);
}

public ResponseEntity<Object> generateMap(final MultiValueMap<String, String> parameters, boolean showHydrants, boolean showRoute, boolean showPois)
public ResponseEntity<Object> generateGenericMap(final MultiValueMap<String, String> parameters, boolean showHydrants, boolean showRoute, boolean showPois, Optional<String> identifier)
{
URL url;
try {
Expand All @@ -96,6 +94,11 @@ public ResponseEntity<Object> generateMap(final MultiValueMap<String, String> 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);
Expand All @@ -104,6 +107,16 @@ public ResponseEntity<Object> generateMap(final MultiValueMap<String, String> 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()))
Expand Down

0 comments on commit 930ed95

Please sign in to comment.