Search in sources :

Example 1 with UserFilesResults

use of net.osmand.server.controllers.pub.UserdataController.UserFilesResults in project OsmAnd-tools by osmandapp.

the class MapApiController method listFiles.

@GetMapping(value = "/list-files")
@ResponseBody
public ResponseEntity<String> listFiles(@RequestParam(name = "name", required = false) String name, @RequestParam(name = "type", required = false) String type, @RequestParam(name = "allVersions", required = false, defaultValue = "false") boolean allVersions) throws IOException, SQLException {
    PremiumUserDevice dev = checkUser();
    if (dev == null) {
        return tokenNotValid();
    }
    UserFilesResults res = userdataController.generateFiles(dev.userid, name, type, allVersions, true);
    for (UserFileNoData nd : res.uniqueFiles) {
        String ext = nd.name.substring(nd.name.lastIndexOf('.') + 1);
        if (nd.type.equalsIgnoreCase("gpx") && ext.equalsIgnoreCase("gpx") && !analysisPresent(ANALYSIS, nd.details)) {
            GPXTrackAnalysis analysis = null;
            Optional<UserFile> of = userFilesRepository.findById(nd.id);
            UserFile uf = of.get();
            if (uf != null) {
                try {
                    InputStream in = uf.data != null ? new ByteArrayInputStream(uf.data) : userdataController.getInputStream(uf);
                    if (in != null) {
                        GPXFile gpxFile = GPXUtilities.loadGPXFile(new GZIPInputStream(in));
                        if (gpxFile != null) {
                            analysis = getAnalysis(uf, gpxFile);
                        }
                    }
                } catch (RuntimeException e) {
                }
                saveAnalysis(ANALYSIS, uf, analysis);
                nd.details = uf.details.deepCopy();
            }
        }
        if (analysisPresent(ANALYSIS, nd.details)) {
            nd.details.get(ANALYSIS).getAsJsonObject().remove("speedData");
            nd.details.get(ANALYSIS).getAsJsonObject().remove("elevationData");
        }
        if (analysisPresent(SRTM_ANALYSIS, nd.details)) {
            nd.details.get(SRTM_ANALYSIS).getAsJsonObject().remove("speedData");
            nd.details.get(SRTM_ANALYSIS).getAsJsonObject().remove("elevationData");
        }
    }
    return ResponseEntity.ok(gson.toJson(res));
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) UserFilesResults(net.osmand.server.controllers.pub.UserdataController.UserFilesResults) ByteArrayInputStream(java.io.ByteArrayInputStream) UserFile(net.osmand.server.api.repo.PremiumUserFilesRepository.UserFile) GZIPInputStream(java.util.zip.GZIPInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) GPXTrackAnalysis(net.osmand.GPXUtilities.GPXTrackAnalysis) GPXFile(net.osmand.GPXUtilities.GPXFile) PremiumUserDevice(net.osmand.server.api.repo.PremiumUserDevicesRepository.PremiumUserDevice) UserFileNoData(net.osmand.server.api.repo.PremiumUserFilesRepository.UserFileNoData) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with UserFilesResults

use of net.osmand.server.controllers.pub.UserdataController.UserFilesResults in project OsmAnd-tools by osmandapp.

the class AdminController method searchSubscription.

@PostMapping(path = { "/search-subscription" })
public String searchSubscription(Model model, @RequestParam(required = true) String orderId, final RedirectAttributes redirectAttrs) throws JsonProcessingException {
    SupporterDeviceSubscription deviceSub = new SupporterDeviceSubscription();
    deviceSub.sku = "not found";
    deviceSub.orderId = "none";
    deviceSub.valid = false;
    if (emailSender.isEmail(orderId)) {
        PremiumUser pu = usersRepository.findByEmail(orderId);
        if (pu != null) {
            deviceSub.sku = orderId + " (pro email)";
            List<SupporterDeviceSubscription> ls = subscriptionsRepository.findByOrderId(pu.orderid);
            if (ls != null && ls.size() > 0) {
                deviceSub = ls.get(0);
            }
            if (deviceSub != null) {
                UserFilesResults ufs = userDataController.generateFiles(pu.id, null, null, true, false);
                ufs.allFiles.clear();
                ufs.uniqueFiles.clear();
                deviceSub.payload = gson.toJson(ufs);
            }
        }
    } else {
        List<SupporterDeviceSubscription> ls = subscriptionsRepository.findByOrderId(orderId);
        if (ls != null && ls.size() > 0) {
            deviceSub = ls.get(0);
        }
    }
    redirectAttrs.addFlashAttribute("subscriptions", Collections.singleton(deviceSub));
    return "redirect:info#audience";
}
Also used : SupporterDeviceSubscription(net.osmand.server.api.repo.DeviceSubscriptionsRepository.SupporterDeviceSubscription) UserFilesResults(net.osmand.server.controllers.pub.UserdataController.UserFilesResults) PremiumUser(net.osmand.server.api.repo.PremiumUsersRepository.PremiumUser) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

UserFilesResults (net.osmand.server.controllers.pub.UserdataController.UserFilesResults)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 GPXFile (net.osmand.GPXUtilities.GPXFile)1 GPXTrackAnalysis (net.osmand.GPXUtilities.GPXTrackAnalysis)1 SupporterDeviceSubscription (net.osmand.server.api.repo.DeviceSubscriptionsRepository.SupporterDeviceSubscription)1 PremiumUserDevice (net.osmand.server.api.repo.PremiumUserDevicesRepository.PremiumUserDevice)1 UserFile (net.osmand.server.api.repo.PremiumUserFilesRepository.UserFile)1 UserFileNoData (net.osmand.server.api.repo.PremiumUserFilesRepository.UserFileNoData)1 PremiumUser (net.osmand.server.api.repo.PremiumUsersRepository.PremiumUser)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1