Add mock for inpx rescan

This commit is contained in:
Dmitry Isaenko 2024-01-05 23:53:28 +03:00
parent 443ba9fea9
commit 7f66f20b53
7 changed files with 82 additions and 8 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
postgres/docker-compose.yml postgres/docker-compose.yml
target/ target/
lib/

15
pom.xml
View file

@ -1,12 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.1</version> <version>3.2.1</version>
<relativePath/> <!-- lookup parent from repository --> <relativePath /> <!-- lookup parent from repository -->
</parent> </parent>
<groupId>ru.redrise</groupId> <groupId>ru.redrise</groupId>
<artifactId>marinesco</artifactId> <artifactId>marinesco</artifactId>
@ -59,7 +60,8 @@
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.thymeleaf.extras/thymeleaf-extras-springsecurity6 --> <!--
https://mvnrepository.com/artifact/org.thymeleaf.extras/thymeleaf-extras-springsecurity6 -->
<dependency> <dependency>
<groupId>org.thymeleaf.extras</groupId> <groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity6</artifactId> <artifactId>thymeleaf-extras-springsecurity6</artifactId>
@ -71,6 +73,13 @@
<artifactId>h2</artifactId> <artifactId>h2</artifactId>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
</dependencies> </dependencies>
<build> <build>

View file

@ -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;
}
}

View file

@ -7,6 +7,8 @@ import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import ru.redrise.marinesco.library.InpxScanner;
//@Slf4j //@Slf4j
@Controller @Controller
@RequestMapping("/settings") @RequestMapping("/settings")
@ -15,9 +17,12 @@ public class SettingsController {
private KeyValueRepository keyValueRepository; private KeyValueRepository keyValueRepository;
private ApplicationSettings applicationSettings; private ApplicationSettings applicationSettings;
public SettingsController(KeyValueRepository keyValueRepository, ApplicationSettings applicationSettings){ private InpxScanner inpxScanner;
public SettingsController(KeyValueRepository keyValueRepository, ApplicationSettings applicationSettings, InpxScanner inpxScanner){
this.keyValueRepository = keyValueRepository; this.keyValueRepository = keyValueRepository;
this.applicationSettings = applicationSettings; this.applicationSettings = applicationSettings;
this.inpxScanner = inpxScanner;
} }
@GetMapping @GetMapping
@ -39,4 +44,11 @@ public class SettingsController {
return "redirect:/settings"; return "redirect:/settings";
} }
@GetMapping("/rescan")
public String rescan(){
inpxScanner.reScan();
return "redirect:/settings";
}
} }

View file

@ -0,0 +1,9 @@
{
"properties": [
{
"name": "marinesco.library.filesLocation",
"type": "java.lang.String",
"description": "All library files location"
}
]
}

View file

@ -21,3 +21,6 @@ spring:
settings: settings:
web-allow-others: true web-allow-others: true
trace: false trace: false
marinesco:
library:
filesLocation: "./lib"

View file

@ -12,8 +12,13 @@
<div class="page"> <div class="page">
<div th:replace="~{fragments/header :: 'header'}"></div> <div th:replace="~{fragments/header :: 'header'}"></div>
<div class="container base"> <div class="container base">
<span th:text="${'New users registration is now ' + (allowRegistration ? 'enabled. ' : 'disabled. ' )}"></span> <span
<a th:href="${'/settings/allow_registration/' + !allowRegistration }" th:text="${'Click here to ' + (allowRegistration ? 'disable' : 'enable' )}"></a> th:text="${'New users registration is now ' + (allowRegistration ? 'enabled. ' : 'disabled. ' )}"></span>
<a th:href="${'/settings/allow_registration/' + !allowRegistration }"
th:text="${'Click here to ' + (allowRegistration ? 'disable' : 'enable' )}"></a>
<p>
<a href="/settings/rescan" th:text="Click to rescan library"></a>
</p>
</div> </div>
</div> </div>
<div th:replace="~{fragments/footer :: 'footer'}"></div> <div th:replace="~{fragments/footer :: 'footer'}"></div>