use of net.osmand.server.api.repo.PremiumUserFilesRepository.UserFileNoData in project OsmAnd-tools by osmandapp.
the class UserdataController method generateFiles.
public UserFilesResults generateFiles(int userId, String name, String type, boolean allVersions, boolean details) {
List<UserFileNoData> fl = details ? filesRepository.listFilesByUseridWithDetails(userId, name, type) : filesRepository.listFilesByUserid(userId, name, type);
UserFilesResults res = new UserFilesResults();
res.maximumAccountSize = MAXIMUM_ACCOUNT_SIZE;
res.uniqueFiles = new ArrayList<>();
if (allVersions) {
res.allFiles = new ArrayList<>();
}
res.userid = userId;
Set<String> fileIds = new TreeSet<String>();
for (UserFileNoData sf : fl) {
String fileId = sf.type + "____" + sf.name;
if (sf.filesize >= 0) {
res.totalFileVersions++;
res.totalZipSize += sf.zipSize;
res.totalFileSize += sf.filesize;
}
if (fileIds.add(fileId)) {
if (sf.filesize >= 0) {
res.totalFiles++;
res.uniqueFiles.add(sf);
}
}
if (allVersions) {
res.allFiles.add(sf);
}
}
return res;
}
use of net.osmand.server.api.repo.PremiumUserFilesRepository.UserFileNoData 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));
}
Aggregations