From 7f66f20b53d23f95fd593a711449110eb2bb0996 Mon Sep 17 00:00:00 2001 From: Dmitry Isaenko Date: Fri, 5 Jan 2024 23:53:28 +0300 Subject: [PATCH] Add mock for inpx rescan --- .gitignore | 1 + pom.xml | 17 ++++++--- .../marinesco/library/InpxScanner.java | 35 +++++++++++++++++++ .../settings/SettingsController.java | 14 +++++++- ...itional-spring-configuration-metadata.json | 9 +++++ src/main/resources/application.yml | 3 ++ src/main/resources/templates/settings.html | 11 ++++-- 7 files changed, 82 insertions(+), 8 deletions(-) create mode 100644 src/main/java/ru/redrise/marinesco/library/InpxScanner.java create mode 100644 src/main/resources/META-INF/additional-spring-configuration-metadata.json diff --git a/.gitignore b/.gitignore index 0364181..627b66f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ postgres/docker-compose.yml target/ +lib/ \ No newline at end of file diff --git a/pom.xml b/pom.xml index bdf7d03..1fb3a06 100644 --- a/pom.xml +++ b/pom.xml @@ -1,12 +1,13 @@ - 4.0.0 org.springframework.boot spring-boot-starter-parent 3.2.1 - + ru.redrise marinesco @@ -59,7 +60,8 @@ - + org.thymeleaf.extras thymeleaf-extras-springsecurity6 @@ -71,6 +73,13 @@ h2 runtime + + + org.springframework.boot + spring-boot-configuration-processor + true + + @@ -90,4 +99,4 @@ - + \ No newline at end of file diff --git a/src/main/java/ru/redrise/marinesco/library/InpxScanner.java b/src/main/java/ru/redrise/marinesco/library/InpxScanner.java new file mode 100644 index 0000000..46587f2 --- /dev/null +++ b/src/main/java/ru/redrise/marinesco/library/InpxScanner.java @@ -0,0 +1,35 @@ +package ru.redrise.marinesco.library; + +import java.util.stream.Stream; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.core.io.FileSystemResource; +import org.springframework.stereotype.Component; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Component +@ConfigurationProperties(prefix = "marinesco.library") +public class InpxScanner { + + private String filesLocation = ""; + + private FileSystemResource inpxFile; + + public void reScan() { + inpxFile = new FileSystemResource(filesLocation); + + //todo + Stream.of(inpxFile.getFile().listFiles()) + .forEach(file -> log.info(file.toString())); + } + + public String getFilesLocation(){ + return filesLocation; + } + + public void setFilesLocation(String location){ + filesLocation = location; + } +} diff --git a/src/main/java/ru/redrise/marinesco/settings/SettingsController.java b/src/main/java/ru/redrise/marinesco/settings/SettingsController.java index 7049255..cacc1c8 100644 --- a/src/main/java/ru/redrise/marinesco/settings/SettingsController.java +++ b/src/main/java/ru/redrise/marinesco/settings/SettingsController.java @@ -7,6 +7,8 @@ import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; +import ru.redrise.marinesco.library.InpxScanner; + //@Slf4j @Controller @RequestMapping("/settings") @@ -15,9 +17,12 @@ public class SettingsController { private KeyValueRepository keyValueRepository; private ApplicationSettings applicationSettings; - public SettingsController(KeyValueRepository keyValueRepository, ApplicationSettings applicationSettings){ + private InpxScanner inpxScanner; + + public SettingsController(KeyValueRepository keyValueRepository, ApplicationSettings applicationSettings, InpxScanner inpxScanner){ this.keyValueRepository = keyValueRepository; this.applicationSettings = applicationSettings; + this.inpxScanner = inpxScanner; } @GetMapping @@ -39,4 +44,11 @@ public class SettingsController { return "redirect:/settings"; } + + @GetMapping("/rescan") + public String rescan(){ + inpxScanner.reScan(); + + return "redirect:/settings"; + } } diff --git a/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/src/main/resources/META-INF/additional-spring-configuration-metadata.json new file mode 100644 index 0000000..304a859 --- /dev/null +++ b/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -0,0 +1,9 @@ +{ + "properties": [ + { + "name": "marinesco.library.filesLocation", + "type": "java.lang.String", + "description": "All library files location" + } + ] +} \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 15da86f..4e53fab 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -21,3 +21,6 @@ spring: settings: web-allow-others: true trace: false +marinesco: + library: + filesLocation: "./lib" \ No newline at end of file diff --git a/src/main/resources/templates/settings.html b/src/main/resources/templates/settings.html index 2b3ee11..e581f47 100644 --- a/src/main/resources/templates/settings.html +++ b/src/main/resources/templates/settings.html @@ -4,7 +4,7 @@ Marinesco - Application settings - + @@ -12,8 +12,13 @@
- - + + +

+ +