mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2024-12-21 19:08:24 +01:00
apply local
This commit is contained in:
parent
f2b701e3e3
commit
0fb0cb8bca
@ -8,13 +8,14 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
|
||||||
import jakarta.annotation.PostConstruct;
|
import jakarta.annotation.PostConstruct;
|
||||||
import stirling.software.SPDF.config.ConfigInitializer;
|
import stirling.software.SPDF.config.ConfigInitializer;
|
||||||
import stirling.software.SPDF.utils.GeneralUtils;
|
import stirling.software.SPDF.utils.GeneralUtils;
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
|
|
||||||
//@EnableScheduling
|
@EnableScheduling
|
||||||
public class SPdfApplication {
|
public class SPdfApplication {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -68,6 +68,7 @@ public class ApiDocService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isValidOperation(String operationName, Map<String, Object> parameters) {
|
public boolean isValidOperation(String operationName, Map<String, Object> parameters) {
|
||||||
|
System.out.println(apiDocumentation);
|
||||||
if (!apiDocumentation.containsKey(operationName)) {
|
if (!apiDocumentation.containsKey(operationName)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipInputStream;
|
import java.util.zip.ZipInputStream;
|
||||||
@ -64,16 +66,14 @@ public class PipelineController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ObjectMapper objectMapper;
|
private ObjectMapper objectMapper;
|
||||||
|
|
||||||
final String jsonFileName = "pipelineConfig.json";
|
|
||||||
final String watchedFoldersDir = "./pipeline/watchedFolders/";
|
final String watchedFoldersDir = "./pipeline/watchedFolders/";
|
||||||
final String finishedFoldersDir = "./pipeline/finishedFolders/";
|
final String finishedFoldersDir = "./pipeline/finishedFolders/";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ApiDocService apiDocService;
|
private ApiDocService apiDocService;
|
||||||
|
|
||||||
@Scheduled(fixedRate = 25000)
|
@Scheduled(fixedRate = 60000)
|
||||||
public void scanFolders() {
|
public void scanFolders() {
|
||||||
logger.info("Scanning folders...");
|
|
||||||
Path watchedFolderPath = Paths.get(watchedFoldersDir);
|
Path watchedFolderPath = Paths.get(watchedFoldersDir);
|
||||||
if (!Files.exists(watchedFolderPath)) {
|
if (!Files.exists(watchedFolderPath)) {
|
||||||
try {
|
try {
|
||||||
@ -113,19 +113,31 @@ public class PipelineController {
|
|||||||
|
|
||||||
private void handleDirectory(Path dir) throws Exception {
|
private void handleDirectory(Path dir) throws Exception {
|
||||||
logger.info("Handling directory: {}", dir);
|
logger.info("Handling directory: {}", dir);
|
||||||
Path jsonFile = dir.resolve(jsonFileName);
|
|
||||||
Path processingDir = dir.resolve("processing"); // Directory to move files during processing
|
Path processingDir = dir.resolve("processing"); // Directory to move files during processing
|
||||||
if (!Files.exists(processingDir)) {
|
if (!Files.exists(processingDir)) {
|
||||||
Files.createDirectory(processingDir);
|
Files.createDirectory(processingDir);
|
||||||
logger.info("Created processing directory: {}", processingDir);
|
logger.info("Created processing directory: {}", processingDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Files.exists(jsonFile)) {
|
Path jsonFile;
|
||||||
|
Optional<Path> jsonFileOptional;
|
||||||
|
// Find any JSON file in the directory
|
||||||
|
try (Stream<Path> paths = Files.list(dir)) {
|
||||||
|
jsonFileOptional = paths
|
||||||
|
.filter(file -> file.toString().endsWith(".json"))
|
||||||
|
.findFirst();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (jsonFileOptional.isPresent()) {
|
||||||
|
jsonFile = jsonFileOptional.get();
|
||||||
// Read JSON file
|
// Read JSON file
|
||||||
String jsonString;
|
String jsonString;
|
||||||
try {
|
try {
|
||||||
jsonString = new String(Files.readAllBytes(jsonFile));
|
jsonString = new String(Files.readAllBytes(jsonFile));
|
||||||
logger.info("Read JSON file: {}", jsonFile);
|
logger.info("Reading JSON file: {}", jsonFile);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error("Error reading JSON file: {}", jsonFile, e);
|
logger.error("Error reading JSON file: {}", jsonFile, e);
|
||||||
return;
|
return;
|
||||||
@ -265,6 +277,8 @@ public class PipelineController {
|
|||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
logger.warn("No .JSON settings file found. No processing will happen for dir {}.", dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,4 +26,11 @@ public class ApiEndpoint {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ApiEndpoint [name=" + name + ", parameters=" + parameters + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user