Search in sources :

Example 1 with QueryParams

use of net.osmand.obf.OsmGpxWriteContext.QueryParams in project OsmAnd-tools by osmandapp.

the class GpxController method downloadObf.

@RequestMapping(path = { "/download-obf" })
@ResponseBody
public ResponseEntity<Resource> downloadObf(@RequestParam(defaultValue = "", required = false) String gzip, HttpSession httpSession, HttpServletResponse resp) throws IOException, FactoryConfigurationError, XMLStreamException, SQLException, InterruptedException, XmlPullParserException {
    GPXSessionContext ctx = session.getGpxResources(httpSession);
    File tmpOsm = File.createTempFile("gpx_obf_" + httpSession.getId(), ".osm.gz");
    ctx.tempFiles.add(tmpOsm);
    List<File> files = new ArrayList<>();
    for (GPXSessionFile f : ctx.files) {
        files.add(f.file);
    }
    String sessionId = httpSession.getId();
    File tmpFolder = new File(tmpOsm.getParentFile(), sessionId);
    String fileName = "gpx_" + sessionId;
    QueryParams qp = new QueryParams();
    qp.osmFile = tmpOsm;
    qp.details = QueryParams.DETAILS_ELE_SPEED;
    OsmGpxWriteContext writeCtx = new OsmGpxWriteContext(qp);
    File targetObf = new File(tmpFolder.getParentFile(), fileName + IndexConstants.BINARY_MAP_INDEX_EXT);
    writeCtx.writeObf(files, tmpFolder, fileName, targetObf);
    ctx.tempFiles.add(targetObf);
    HttpHeaders headers = new HttpHeaders();
    headers.add(HttpHeaders.CONTENT_DISPOSITION, String.format("attachment; filename=\"gpx.obf\""));
    headers.add(HttpHeaders.CONTENT_TYPE, "application/octet-binary");
    return ResponseEntity.ok().headers(headers).body(new FileSystemResource(targetObf));
}
Also used : GPXSessionFile(net.osmand.server.controllers.pub.UserSessionResources.GPXSessionFile) HttpHeaders(org.springframework.http.HttpHeaders) GPXSessionContext(net.osmand.server.controllers.pub.UserSessionResources.GPXSessionContext) ArrayList(java.util.ArrayList) QueryParams(net.osmand.obf.OsmGpxWriteContext.QueryParams) FileSystemResource(org.springframework.core.io.FileSystemResource) GPXFile(net.osmand.GPXUtilities.GPXFile) GPXSessionFile(net.osmand.server.controllers.pub.UserSessionResources.GPXSessionFile) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) OsmGpxWriteContext(net.osmand.obf.OsmGpxWriteContext) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) StreamingResponseBody(org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

File (java.io.File)1 ArrayList (java.util.ArrayList)1 GPXFile (net.osmand.GPXUtilities.GPXFile)1 OsmGpxWriteContext (net.osmand.obf.OsmGpxWriteContext)1 QueryParams (net.osmand.obf.OsmGpxWriteContext.QueryParams)1 GPXSessionContext (net.osmand.server.controllers.pub.UserSessionResources.GPXSessionContext)1 GPXSessionFile (net.osmand.server.controllers.pub.UserSessionResources.GPXSessionFile)1 FileSystemResource (org.springframework.core.io.FileSystemResource)1 HttpHeaders (org.springframework.http.HttpHeaders)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1 MultipartFile (org.springframework.web.multipart.MultipartFile)1 StreamingResponseBody (org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody)1