use of net.osmand.server.api.repo.PremiumUserFilesRepository.UserFile 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));
}
use of net.osmand.server.api.repo.PremiumUserFilesRepository.UserFile in project OsmAnd-tools by osmandapp.
the class UserdataController method migrateData.
@PostMapping(value = "/backup-storage")
@ResponseBody
public ResponseEntity<String> migrateData(@RequestParam(name = "storageid", required = true) String storageId, @RequestParam(name = "deviceid", required = true) int deviceId, @RequestParam(name = "accessToken", required = true) String accessToken) throws IOException, SQLException {
if (!storageService.hasStorageProviderById(storageId)) {
return error(400, "Storage id is not configured");
}
PremiumUserDevice dev = checkToken(deviceId, accessToken);
if (dev == null) {
return tokenNotValid();
}
Iterable<UserFile> lst = filesRepository.findAllByUserid(dev.userid);
for (UserFile fl : lst) {
if (fl != null && fl.filesize > 0) {
String newStorage = storageService.backupData(storageId, userFolder(fl), storageFileName(fl), fl.storage, fl.data);
if (newStorage != null) {
fl.storage = newStorage;
filesRepository.save(fl);
}
}
}
return ok();
}
use of net.osmand.server.api.repo.PremiumUserFilesRepository.UserFile in project OsmAnd-tools by osmandapp.
the class UserdataController method remapFilenames.
@PostMapping(value = "/remap-filenames")
@ResponseBody
public ResponseEntity<String> remapFilenames(@RequestParam(name = "deviceid", required = true) int deviceId, @RequestParam(name = "accessToken", required = true) String accessToken) throws IOException, SQLException {
PremiumUserDevice dev = checkToken(deviceId, accessToken);
if (dev == null) {
return tokenNotValid();
}
// remap needs to happen to all users & temporarily service should find files by both names (download)
Iterable<UserFile> lst = filesRepository.findAllByUserid(dev.userid);
for (UserFile fl : lst) {
if (fl != null && fl.filesize > 0) {
storageService.remapFileNames(fl.storage, userFolder(fl), oldStorageFileName(fl), storageFileName(fl));
}
}
return ok();
}
use of net.osmand.server.api.repo.PremiumUserFilesRepository.UserFile in project OsmAnd-tools by osmandapp.
the class UserdataController method delete.
@PostMapping(value = "/delete-file")
@ResponseBody
public ResponseEntity<String> delete(@RequestParam(name = "name", required = true) String name, @RequestParam(name = "type", required = true) String type, @RequestParam(name = "deviceid", required = true) int deviceId, @RequestParam(name = "accessToken", required = true) String accessToken, @RequestParam(name = "clienttime", required = false) Long clienttime) throws IOException {
PremiumUserDevice dev = checkToken(deviceId, accessToken);
if (dev == null) {
return tokenNotValid();
}
UserFile usf = new PremiumUserFilesRepository.UserFile();
usf.name = name;
usf.type = type;
usf.updatetime = new Date();
usf.userid = dev.userid;
usf.deviceid = deviceId;
usf.data = null;
usf.filesize = -1l;
usf.zipfilesize = -1l;
if (clienttime != null) {
usf.clienttime = new Date(clienttime.longValue());
}
filesRepository.saveAndFlush(usf);
return ok();
}
Aggregations