apply local

This commit is contained in:
Anthony Stirling 2023-12-25 20:51:32 +00:00
parent f2b701e3e3
commit 0fb0cb8bca
4 changed files with 31 additions and 8 deletions

View File

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

View File

@ -68,6 +68,7 @@ public class ApiDocService {
}
public boolean isValidOperation(String operationName, Map<String, Object> parameters) {
System.out.println(apiDocumentation);
if (!apiDocumentation.containsKey(operationName)) {
return false;
}

View File

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

View File

@ -26,4 +26,11 @@ public class ApiEndpoint {
}
return true;
}
@Override
public String toString() {
return "ApiEndpoint [name=" + name + ", parameters=" + parameters + "]";
}
}