diff --git a/storage/logs/teh.log b/storage/logs/teh.log index db39ba8..dfcf45c 100644 --- a/storage/logs/teh.log +++ b/storage/logs/teh.log @@ -1,34 +1,20 @@ -{"@timestamp":"2024-10-02T07:04:55.293627400Z","log.level":"INFO","process.pid":9376,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"Starting StorageApplicationTests using Java 17.0.7 with PID 9376 (started by devuser in C:\\Users\\devuser\\Documents\\code\\teh\\storage)","ecs.version":"8.11"} -{"@timestamp":"2024-10-02T07:04:55.299040500Z","log.level":"INFO","process.pid":9376,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"No active profile set, falling back to 1 default profile: \"default\"","ecs.version":"8.11"} -{"@timestamp":"2024-10-02T07:04:57.188504200Z","log.level":"INFO","process.pid":9376,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"Started StorageApplicationTests in 2.342 seconds (process running for 3.454)","ecs.version":"8.11"} -{"@timestamp":"2024-10-02T07:56:38.064241800Z","log.level":"INFO","process.pid":22060,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"Starting StorageApplicationTests using Java 17.0.7 with PID 22060 (started by devuser in C:\\Users\\devuser\\Documents\\code\\teh\\storage)","ecs.version":"8.11"} -{"@timestamp":"2024-10-02T07:56:38.074240900Z","log.level":"INFO","process.pid":22060,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"No active profile set, falling back to 1 default profile: \"default\"","ecs.version":"8.11"} -{"@timestamp":"2024-10-02T07:56:39.837714500Z","log.level":"INFO","process.pid":22060,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"Started StorageApplicationTests in 2.217 seconds (process running for 3.283)","ecs.version":"8.11"} -{"@timestamp":"2024-10-02T08:16:48.125170400Z","log.level":"INFO","process.pid":22288,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"Starting StorageApplicationTests using Java 17.0.7 with PID 22288 (started by devuser in C:\\Users\\devuser\\Documents\\code\\teh\\storage)","ecs.version":"8.11"} -{"@timestamp":"2024-10-02T08:16:48.130286200Z","log.level":"INFO","process.pid":22288,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"No active profile set, falling back to 1 default profile: \"default\"","ecs.version":"8.11"} -{"@timestamp":"2024-10-02T08:16:49.021858900Z","log.level":"INFO","process.pid":22288,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.services.FileServiceImpl","message":"Создание директории root(), для хранения файлов: C:\\Users\\devuser\\Documents\\code\\teh\\storage\\uploads","ecs.version":"8.11"} -{"@timestamp":"2024-10-02T08:16:49.918673Z","log.level":"INFO","process.pid":22288,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"Started StorageApplicationTests in 2.226 seconds (process running for 3.275)","ecs.version":"8.11"} -{"@timestamp":"2024-10-02T09:36:42.081332700Z","log.level":"INFO","process.pid":7404,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"Starting StorageApplicationTests using Java 17.0.7 with PID 7404 (started by devuser in C:\\Users\\devuser\\Documents\\code\\teh\\storage)","ecs.version":"8.11"} -{"@timestamp":"2024-10-02T09:36:42.087332900Z","log.level":"INFO","process.pid":7404,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"No active profile set, falling back to 1 default profile: \"default\"","ecs.version":"8.11"} -{"@timestamp":"2024-10-02T09:36:42.976191Z","log.level":"INFO","process.pid":7404,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.services.FileServiceImpl","message":"Создание директории root(), для хранения файлов: C:\\Users\\devuser\\Documents\\code\\teh\\storage\\uploads","ecs.version":"8.11"} -{"@timestamp":"2024-10-02T09:36:43.854858Z","log.level":"INFO","process.pid":7404,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"Started StorageApplicationTests in 2.274 seconds (process running for 3.386)","ecs.version":"8.11"} -{"@timestamp":"2024-10-02T09:47:09.155604200Z","log.level":"INFO","process.pid":12256,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"Starting StorageApplicationTests using Java 17.0.7 with PID 12256 (started by devuser in C:\\Users\\devuser\\Documents\\code\\teh\\storage)","ecs.version":"8.11"} -{"@timestamp":"2024-10-02T09:47:09.160578900Z","log.level":"INFO","process.pid":12256,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"No active profile set, falling back to 1 default profile: \"default\"","ecs.version":"8.11"} -{"@timestamp":"2024-10-02T09:47:10.112966Z","log.level":"INFO","process.pid":12256,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.services.FileServiceImpl","message":"Создание директории root(), для хранения файлов: C:\\Users\\devuser\\Documents\\code\\teh\\storage\\uploads","ecs.version":"8.11"} -{"@timestamp":"2024-10-02T09:47:10.955370200Z","log.level":"INFO","process.pid":12256,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"Started StorageApplicationTests in 2.251 seconds (process running for 3.423)","ecs.version":"8.11"} -{"@timestamp":"2024-10-02T09:54:50.824390600Z","log.level":"INFO","process.pid":21356,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"Starting StorageApplicationTests using Java 17.0.7 with PID 21356 (started by devuser in C:\\Users\\devuser\\Documents\\code\\teh\\storage)","ecs.version":"8.11"} -{"@timestamp":"2024-10-02T09:54:50.833390800Z","log.level":"INFO","process.pid":21356,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"No active profile set, falling back to 1 default profile: \"default\"","ecs.version":"8.11"} -{"@timestamp":"2024-10-02T09:54:51.886224900Z","log.level":"INFO","process.pid":21356,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.services.FileServiceImpl","message":"Создание директории root(), для хранения файлов: C:\\Users\\devuser\\Documents\\code\\teh\\storage\\uploads","ecs.version":"8.11"} -{"@timestamp":"2024-10-02T09:54:52.798015700Z","log.level":"INFO","process.pid":21356,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"Started StorageApplicationTests in 2.506 seconds (process running for 3.64)","ecs.version":"8.11"} -{"@timestamp":"2024-10-02T10:19:00.457454300Z","log.level":"INFO","process.pid":4544,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"Starting StorageApplicationTests using Java 17.0.7 with PID 4544 (started by devuser in C:\\Users\\devuser\\Documents\\code\\teh\\storage)","ecs.version":"8.11"} -{"@timestamp":"2024-10-02T10:19:00.463454800Z","log.level":"INFO","process.pid":4544,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"No active profile set, falling back to 1 default profile: \"default\"","ecs.version":"8.11"} -{"@timestamp":"2024-10-02T10:19:01.350682300Z","log.level":"INFO","process.pid":4544,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.services.FileServiceImpl","message":"Создание директории root(), для хранения файлов: C:\\Users\\devuser\\Documents\\code\\teh\\storage\\uploads","ecs.version":"8.11"} -{"@timestamp":"2024-10-02T10:19:02.167066Z","log.level":"INFO","process.pid":4544,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"Started StorageApplicationTests in 2.11 seconds (process running for 3.226)","ecs.version":"8.11"} -{"@timestamp":"2024-10-02T11:13:53.815353Z","log.level":"INFO","process.pid":19852,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"Starting StorageApplicationTests using Java 17.0.7 with PID 19852 (started by devuser in C:\\Users\\devuser\\Documents\\code\\teh\\storage)","ecs.version":"8.11"} -{"@timestamp":"2024-10-02T11:13:53.822362600Z","log.level":"INFO","process.pid":19852,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"No active profile set, falling back to 1 default profile: \"default\"","ecs.version":"8.11"} -{"@timestamp":"2024-10-02T11:13:54.776505500Z","log.level":"INFO","process.pid":19852,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.services.FileServiceImpl","message":"Создание директории root(), для хранения файлов: C:\\Users\\devuser\\Documents\\code\\teh\\storage\\uploads","ecs.version":"8.11"} -{"@timestamp":"2024-10-02T11:13:55.719635700Z","log.level":"INFO","process.pid":19852,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"Started StorageApplicationTests in 2.36 seconds (process running for 3.438)","ecs.version":"8.11"} -{"@timestamp":"2024-10-02T11:14:51.073276100Z","log.level":"INFO","process.pid":14552,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"Starting StorageApplicationTests using Java 17.0.7 with PID 14552 (started by devuser in C:\\Users\\devuser\\Documents\\code\\teh\\storage)","ecs.version":"8.11"} -{"@timestamp":"2024-10-02T11:14:51.081408400Z","log.level":"INFO","process.pid":14552,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"No active profile set, falling back to 1 default profile: \"default\"","ecs.version":"8.11"} -{"@timestamp":"2024-10-02T11:14:51.975885900Z","log.level":"INFO","process.pid":14552,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.services.FileServiceImpl","message":"Создание директории root(), для хранения файлов: C:\\Users\\devuser\\Documents\\code\\teh\\storage\\uploads","ecs.version":"8.11"} -{"@timestamp":"2024-10-02T11:14:52.898326Z","log.level":"INFO","process.pid":14552,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"Started StorageApplicationTests in 2.25 seconds (process running for 3.275)","ecs.version":"8.11"} +{"@timestamp":"2024-10-04T06:27:42.600672400Z","log.level":"INFO","process.pid":2900,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"Starting StorageApplicationTests using Java 17.0.7 with PID 2900 (started by devuser in C:\\Users\\devuser\\Documents\\code\\teh\\storage)","ecs.version":"8.11"} +{"@timestamp":"2024-10-04T06:27:42.615661400Z","log.level":"INFO","process.pid":2900,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"No active profile set, falling back to 1 default profile: \"default\"","ecs.version":"8.11"} +{"@timestamp":"2024-10-04T06:27:43.718190500Z","log.level":"INFO","process.pid":2900,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.services.FileServiceImpl","message":"Создание директории root(), для хранения файлов: C:\\Users\\devuser\\Documents\\code\\teh\\storage\\uploads","ecs.version":"8.11"} +{"@timestamp":"2024-10-04T06:27:44.607871100Z","log.level":"INFO","process.pid":2900,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"Started StorageApplicationTests in 2.504 seconds (process running for 3.707)","ecs.version":"8.11"} +{"@timestamp":"2024-10-04T06:40:06.507724800Z","log.level":"INFO","process.pid":2708,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"Starting StorageApplicationTests using Java 17.0.7 with PID 2708 (started by devuser in C:\\Users\\devuser\\Documents\\code\\teh\\storage)","ecs.version":"8.11"} +{"@timestamp":"2024-10-04T06:40:06.513725300Z","log.level":"INFO","process.pid":2708,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"No active profile set, falling back to 1 default profile: \"default\"","ecs.version":"8.11"} +{"@timestamp":"2024-10-04T06:40:07.417589400Z","log.level":"INFO","process.pid":2708,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.services.FileServiceImpl","message":"Создание директории root(), для хранения файлов: C:\\Users\\devuser\\Documents\\code\\teh\\storage\\uploads","ecs.version":"8.11"} +{"@timestamp":"2024-10-04T06:40:08.215709900Z","log.level":"INFO","process.pid":2708,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"Started StorageApplicationTests in 2.172 seconds (process running for 3.22)","ecs.version":"8.11"} +{"@timestamp":"2024-10-04T08:07:08.615820200Z","log.level":"INFO","process.pid":1224,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"Starting StorageApplicationTests using Java 17.0.7 with PID 1224 (started by devuser in C:\\Users\\devuser\\Documents\\code\\teh\\storage)","ecs.version":"8.11"} +{"@timestamp":"2024-10-04T08:07:08.623816900Z","log.level":"INFO","process.pid":1224,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"No active profile set, falling back to 1 default profile: \"default\"","ecs.version":"8.11"} +{"@timestamp":"2024-10-04T08:07:09.699513300Z","log.level":"INFO","process.pid":1224,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.services.FileServiceImpl","message":"Создание директории root(), для хранения файлов: C:\\Users\\devuser\\Documents\\code\\teh\\storage\\uploads","ecs.version":"8.11"} +{"@timestamp":"2024-10-04T08:07:10.538898200Z","log.level":"INFO","process.pid":1224,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"Started StorageApplicationTests in 2.426 seconds (process running for 3.467)","ecs.version":"8.11"} +{"@timestamp":"2024-10-04T09:52:46.502781700Z","log.level":"INFO","process.pid":10932,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"Starting StorageApplicationTests using Java 17.0.7 with PID 10932 (started by devuser in C:\\Users\\devuser\\Documents\\code\\teh\\storage)","ecs.version":"8.11"} +{"@timestamp":"2024-10-04T09:52:46.508889300Z","log.level":"INFO","process.pid":10932,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"No active profile set, falling back to 1 default profile: \"default\"","ecs.version":"8.11"} +{"@timestamp":"2024-10-04T09:52:47.514067200Z","log.level":"INFO","process.pid":10932,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.services.FileServiceImpl","message":"Создание директории root(), для хранения файлов: C:\\Users\\devuser\\Documents\\code\\teh\\storage\\uploads","ecs.version":"8.11"} +{"@timestamp":"2024-10-04T09:52:48.356986700Z","log.level":"INFO","process.pid":10932,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"Started StorageApplicationTests in 2.364 seconds (process running for 3.506)","ecs.version":"8.11"} +{"@timestamp":"2024-10-04T10:48:18.065697600Z","log.level":"INFO","process.pid":19152,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"Starting StorageApplicationTests using Java 17.0.7 with PID 19152 (started by devuser in C:\\Users\\devuser\\Documents\\code\\teh\\storage)","ecs.version":"8.11"} +{"@timestamp":"2024-10-04T10:48:18.071923300Z","log.level":"INFO","process.pid":19152,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"No active profile set, falling back to 1 default profile: \"default\"","ecs.version":"8.11"} +{"@timestamp":"2024-10-04T10:48:18.936503100Z","log.level":"INFO","process.pid":19152,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.services.FileServiceImpl","message":"Создание директории root(), для хранения файлов: C:\\Users\\devuser\\Documents\\code\\teh\\storage\\uploads","ecs.version":"8.11"} +{"@timestamp":"2024-10-04T10:48:19.816968700Z","log.level":"INFO","process.pid":19152,"process.thread.name":"main","service.name":"face","service.version":"1","service.environment":"Production","service.node.name":"Primary","log.logger":"gsp.technologies.storage.StorageApplicationTests","message":"Started StorageApplicationTests in 2.229 seconds (process running for 3.279)","ecs.version":"8.11"} diff --git a/storage/logs/teh.log.2024-10-02.0.gz b/storage/logs/teh.log.2024-10-02.0.gz new file mode 100644 index 0000000..1bf8428 Binary files /dev/null and b/storage/logs/teh.log.2024-10-02.0.gz differ diff --git a/storage/src/main/java/gsp/technologies/storage/controllers/api/ApiController.java b/storage/src/main/java/gsp/technologies/storage/controllers/api/ApiController.java index 3ab5fb6..fa872f4 100644 --- a/storage/src/main/java/gsp/technologies/storage/controllers/api/ApiController.java +++ b/storage/src/main/java/gsp/technologies/storage/controllers/api/ApiController.java @@ -169,7 +169,8 @@ public class ApiController { } @GetMapping("/files/xlsx") - public String getXlsxPage(Model model, + public @ResponseBody + ResponseEntity getXlsxPage(Model model, @RequestParam(name = "filename", required = true) String filename, @RequestParam(name = "pageNumber", defaultValue = "0") String pageNumber, @RequestParam(name = "pageSize", defaultValue = "10") String pageSize) { @@ -178,16 +179,16 @@ public class ApiController { LOG.info("pageNumber: {}", pageNumber); LOG.info("pageSize: {}", pageSize); - Xlsx xlsx = new Xlsx(filename); - - XlsxPage page = xlsx.page(Integer.parseInt(pageSize), Integer.parseInt(pageNumber)); + try { + String path = fs.loadAsResource(filename).getFile().getPath(); - /** - * проверить обработку xlsx на больших данных - */ - model.addAttribute("page", page); - - return "view-xlsx"; + Xlsx xlsx = new Xlsx(path); + XlsxPage page = xlsx.page(Integer.parseInt(pageSize), Integer.parseInt(pageNumber)); + return ResponseEntity.ok(page); + } catch (IOException e) { + LOG.info("Error: {}", e.getMessage()); + return ResponseEntity.badRequest().body(null); + } } } diff --git a/storage/src/main/java/gsp/technologies/storage/models/xlsx/SheetHandler.java b/storage/src/main/java/gsp/technologies/storage/models/xlsx/SheetHandler.java new file mode 100644 index 0000000..a0dc926 --- /dev/null +++ b/storage/src/main/java/gsp/technologies/storage/models/xlsx/SheetHandler.java @@ -0,0 +1,34 @@ +package gsp.technologies.storage.models.xlsx; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; + +public class SheetHandler extends DefaultHandler{ + private boolean isCellValue; + private String cellValue; + + @Override + public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException { + if ("c".equals(name)) { + String cellType = attributes.getValue("t"); + isCellValue = "s".equals(cellType); + } + cellValue = ""; + } + + @Override + public void endElement(String uri, String localName, String name) throws SAXException { + if (isCellValue && "v".equals(name)) { + System.out.println(cellValue); + } + } + + @Override + public void characters(char[] ch, int start, int length) throws SAXException { + if (isCellValue) { + cellValue += new String(ch, start, length); + } + } + +} diff --git a/storage/src/main/java/gsp/technologies/storage/models/xlsx/Xlsx.java b/storage/src/main/java/gsp/technologies/storage/models/xlsx/Xlsx.java index 7a24036..5cd02a2 100644 --- a/storage/src/main/java/gsp/technologies/storage/models/xlsx/Xlsx.java +++ b/storage/src/main/java/gsp/technologies/storage/models/xlsx/Xlsx.java @@ -1,14 +1,15 @@ package gsp.technologies.storage.models.xlsx; +import java.io.File; import java.io.FileInputStream; import java.io.IOException; -import java.io.InputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.xssf.usermodel.XSSFSheet; @@ -26,8 +27,8 @@ public class Xlsx { this.metadata = metadata; } - public Xlsx(String filename){ - this.metadata = new FileMetadata(filename); + public Xlsx(String path){ + this.metadata = new FileMetadata(path); } public XlsxPage page(int pageSize, int pageNumber) { @@ -35,24 +36,82 @@ public class Xlsx { .pageSize(pageSize) .pageNumber(pageNumber) .metadata(metadata) + .offset(0) + .headerLine(0) + .last(this.isLast(pageSize, pageNumber)) + .first(this.isFirst(pageSize, pageNumber)) + .hasNext(this.hasNext(pageSize, pageNumber)) + .hasPrevious(this.hasPrevious(pageSize, pageNumber)) .content(this.content(pageSize, pageNumber)) .totalLines(this.totalLines()) + .totalPages(this.totalPages(pageSize)) .build(); } + /** + * Проверяет, есть ли следующая страница + * + * @param pageSize + * @param pageNumber + * @return true - есть следующая страница, false - нет + */ + private boolean hasPrevious(int pageSize, int pageNumber) { + if (pageNumber > 0) { + return true; + } + return false; + } + + private boolean hasNext(int pageSize, int pageNumber) { + if (pageNumber < totalPages(pageSize)) { + return true; + } + return false; + } + + private boolean isFirst(int pageSize, int pageNumber) { + if (pageNumber == 0) { + return true; + } + return false; + } + + private boolean isLast(int pageSize, int pageNumber) { + if (pageNumber == totalPages(pageSize) - 1) { + return true; + } + return false; + } + + private int totalPages(int pageSize) { + return (int) Math.ceil(totalLines() / (double) pageSize); + } + + /** + * Возвращает содержимое документа в виде Map> + * ! работает на малых объемах данных + * TODO: ! в перспективе разработать SAX парсер + * + * @param pageSize + * @param pageNumber + * @return + */ Map> content(int pageSize, int pageNumber) { Map> map = new HashMap<>(); - try (InputStream is = new FileInputStream(metadata.getPath())) { - XSSFWorkbook wb = new XSSFWorkbook(is); + + File file = new File(metadata.getPath()); + LOG.info("размер файла: " + metadata.getSize()); + LOG.info("Страница: " + pageNumber); + try (FileInputStream is = new FileInputStream(metadata.getPath())) { + XSSFWorkbook wb = new XSSFWorkbook(file); XSSFSheet sheet = wb.getSheetAt(0); - int numberOfRows = sheet.getPhysicalNumberOfRows(); + int numberOfRows = sheet.getPhysicalNumberOfRows(); int startRow = pageNumber * pageSize; int endRow = Math.min(startRow + pageSize, numberOfRows); for (int j = startRow; j < endRow; j++) { Row row = sheet.getRow(j); - // do something with the row List cells = new ArrayList<>(); if (row == null) continue; //пустая строка @@ -61,11 +120,10 @@ public class Xlsx { Cell cell = cellIterator.next(); cells.add(new XlsxCell(cell)); } - map.put(j, cells); } wb.close(); - } catch (IOException e) { + } catch (IOException | InvalidFormatException e) { LOG.info("IOException: " + e.getMessage()); } return map; @@ -77,32 +135,14 @@ public class Xlsx { */ public Integer totalLines() { int count = 0; - try (InputStream is = new FileInputStream(metadata.getPath())) { + try (FileInputStream is = new FileInputStream(metadata.getPath())) { XSSFWorkbook wb = new XSSFWorkbook(is); XSSFSheet sheet = wb.getSheetAt(0); // count = sheet.getLastRowNum(); count = sheet.getPhysicalNumberOfRows(); - - - // Iterator rowIterator = sheet.rowIterator(); - // while (rowIterator.hasNext()) { - // Row row = rowIterator.next(); - // Iterator cellIterator = row.cellIterator(); - // while (cellIterator.hasNext()) { - // Cell cell = cellIterator.next(); - // // Use cell object to read data from the current cell - // } - // count++; - // } - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + LOG.info("IOException: " + e.getMessage()); } return count; } - - - - }