file drop support
- Add a folder where you can drop Zip files which will then be extracted on the fly and ingsted. - CsvReaderSettings now contain TagMatcher that are applied to the first line and can be used to extract additional tags. - Update to jdk 16 so that we can have records.
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
package org.lucares.pdbui;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.lucares.pdbui.domain.FileDropConfig;
|
||||
import org.lucares.pdbui.domain.FileDropSettings;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
@Component
|
||||
public class FileDropConfigProvider {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(FileDropConfigProvider.class);
|
||||
|
||||
private final FileDropConfig config;
|
||||
|
||||
public FileDropConfigProvider(@Value("${path.fileDropConfig}") final String fileDropConfig)
|
||||
throws JsonParseException, JsonMappingException, IOException {
|
||||
final Path configPath = Path.of(fileDropConfig);
|
||||
|
||||
if (Files.exists(configPath)) {
|
||||
|
||||
final ObjectMapper objectMapper = new ObjectMapper();
|
||||
config = objectMapper.readValue(configPath.toFile(), FileDropConfig.class);
|
||||
LOGGER.info("File drop config: {}", objectMapper.writeValueAsString(config));
|
||||
} else {
|
||||
config = new FileDropConfig();
|
||||
}
|
||||
}
|
||||
|
||||
public FileDropConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public Optional<CsvReaderSettings> provideCsvReaderSettings(final String file) {
|
||||
for (final FileDropSettings settings : config.getSettings()) {
|
||||
final AntPathMatcher antPathMatcher = new AntPathMatcher();
|
||||
if (antPathMatcher.match(settings.match(), file)) {
|
||||
|
||||
final Map<String, String> variables = antPathMatcher.extractUriTemplateVariables(settings.match(),
|
||||
file);
|
||||
|
||||
System.out.println("match found " + file + " regex: " + settings.match() + " " + variables);
|
||||
final CsvReaderSettings csvSettings = settings.csvSettings();
|
||||
csvSettings.putAdditionalTag(variables);
|
||||
return Optional.of(csvSettings);
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public static void main(final String[] args) {
|
||||
final Matcher matcher = Pattern.compile("(?<source>.+)/(?<pod>.+)/(?<host>[^/]+)/performance.*.csv")
|
||||
.matcher("web/vapsales01/0f5230761bb8a260e/performance.2020-10-05_000200_2.csv");
|
||||
if (matcher.find()) {
|
||||
System.out.println("match found");
|
||||
} else {
|
||||
System.out.println("not found");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user