diff --git a/src/main/java/stirling/software/SPDF/SPdfApplication.java b/src/main/java/stirling/software/SPDF/SPdfApplication.java index 5dd7fed3..aab480ba 100644 --- a/src/main/java/stirling/software/SPDF/SPdfApplication.java +++ b/src/main/java/stirling/software/SPDF/SPdfApplication.java @@ -8,13 +8,14 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.core.env.Environment; +import org.springframework.scheduling.annotation.EnableScheduling; import jakarta.annotation.PostConstruct; import stirling.software.SPDF.config.ConfigInitializer; import stirling.software.SPDF.utils.GeneralUtils; @SpringBootApplication -//@EnableScheduling +@EnableScheduling public class SPdfApplication { @Autowired diff --git a/src/main/java/stirling/software/SPDF/controller/api/pipeline/ApiDocService.java b/src/main/java/stirling/software/SPDF/controller/api/pipeline/ApiDocService.java index 23acba8a..b0deb586 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/pipeline/ApiDocService.java +++ b/src/main/java/stirling/software/SPDF/controller/api/pipeline/ApiDocService.java @@ -68,6 +68,7 @@ public class ApiDocService { } public boolean isValidOperation(String operationName, Map parameters) { + System.out.println(apiDocumentation); if (!apiDocumentation.containsKey(operationName)) { return false; } diff --git a/src/main/java/stirling/software/SPDF/controller/api/pipeline/PipelineController.java b/src/main/java/stirling/software/SPDF/controller/api/pipeline/PipelineController.java index 8c1c1def..1c1c8d80 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/pipeline/PipelineController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/pipeline/PipelineController.java @@ -18,6 +18,8 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -64,16 +66,14 @@ public class PipelineController { @Autowired private ObjectMapper objectMapper; - final String jsonFileName = "pipelineConfig.json"; final String watchedFoldersDir = "./pipeline/watchedFolders/"; final String finishedFoldersDir = "./pipeline/finishedFolders/"; @Autowired private ApiDocService apiDocService; - @Scheduled(fixedRate = 25000) + @Scheduled(fixedRate = 60000) public void scanFolders() { - logger.info("Scanning folders..."); Path watchedFolderPath = Paths.get(watchedFoldersDir); if (!Files.exists(watchedFolderPath)) { try { @@ -113,19 +113,31 @@ public class PipelineController { private void handleDirectory(Path dir) throws Exception { logger.info("Handling directory: {}", dir); - Path jsonFile = dir.resolve(jsonFileName); + Path processingDir = dir.resolve("processing"); // Directory to move files during processing if (!Files.exists(processingDir)) { Files.createDirectory(processingDir); logger.info("Created processing directory: {}", processingDir); } - - if (Files.exists(jsonFile)) { + + Path jsonFile; + Optional jsonFileOptional; + // Find any JSON file in the directory + try (Stream paths = Files.list(dir)) { + jsonFileOptional = paths + .filter(file -> file.toString().endsWith(".json")) + .findFirst(); + } + + + + if (jsonFileOptional.isPresent()) { + jsonFile = jsonFileOptional.get(); // Read JSON file String jsonString; try { jsonString = new String(Files.readAllBytes(jsonFile)); - logger.info("Read JSON file: {}", jsonFile); + logger.info("Reading JSON file: {}", jsonFile); } catch (IOException e) { logger.error("Error reading JSON file: {}", jsonFile, e); return; @@ -265,6 +277,8 @@ public class PipelineController { throw e; } } + } else { + logger.warn("No .JSON settings file found. No processing will happen for dir {}.", dir); } } diff --git a/src/main/java/stirling/software/SPDF/model/ApiEndpoint.java b/src/main/java/stirling/software/SPDF/model/ApiEndpoint.java index 4590455d..d2a1de52 100644 --- a/src/main/java/stirling/software/SPDF/model/ApiEndpoint.java +++ b/src/main/java/stirling/software/SPDF/model/ApiEndpoint.java @@ -26,4 +26,11 @@ public class ApiEndpoint { } return true; } + + @Override + public String toString() { + return "ApiEndpoint [name=" + name + ", parameters=" + parameters + "]"; + } + + } \ No newline at end of file