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
target/
lib/

17
pom.xml
View file

@ -1,12 +1,13 @@
<?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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.1</version>
<relativePath/> <!-- lookup parent from repository -->
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>ru.redrise</groupId>
<artifactId>marinesco</artifactId>
@ -59,7 +60,8 @@
</dependency>
<!-- https://mvnrepository.com/artifact/org.thymeleaf.extras/thymeleaf-extras-springsecurity6 -->
<!--
https://mvnrepository.com/artifact/org.thymeleaf.extras/thymeleaf-extras-springsecurity6 -->
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity6</artifactId>
@ -71,6 +73,13 @@
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
@ -90,4 +99,4 @@
</plugins>
</build>
</project>
</project>

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.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";
}
}

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:
web-allow-others: true
trace: false
marinesco:
library:
filesLocation: "./lib"

View file

@ -4,7 +4,7 @@
<head>
<title>Marinesco - Application settings</title>
<link rel="icon" href="/favicon.svg" type="image/svg+xml">
<link rel="alternate icon" href="/favicon.png" type="image/png">
<link rel="alternate icon" href="/favicon.png" type="image/png">
<link rel="stylesheet" th:href="@{/styles/styles.css}" />
</head>
@ -12,8 +12,13 @@
<div class="page">
<div th:replace="~{fragments/header :: 'header'}"></div>
<div class="container base">
<span 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>
<span
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 th:replace="~{fragments/footer :: 'footer'}"></div>