formats
This commit is contained in:
parent
d83bd1ae94
commit
39045df785
5 changed files with 201 additions and 194 deletions
|
@ -102,8 +102,9 @@ public class SecurityConfiguration {
|
|||
|| trimmedUri.startsWith("/images/")
|
||||
|| trimmedUri.startsWith("/public/")
|
||||
|| trimmedUri.startsWith("/css/")
|
||||
|| trimmedUri.startsWith("/js/") ||
|
||||
trimmedUri.startsWith("/api/v1/info/status");
|
||||
|| trimmedUri.startsWith("/js/")
|
||||
|| trimmedUri.startsWith(
|
||||
"/api/v1/info/status");
|
||||
})
|
||||
.permitAll()
|
||||
.anyRequest()
|
||||
|
|
|
@ -49,19 +49,13 @@ public class PipelineProcessor {
|
|||
@Autowired(required = false)
|
||||
private UserServiceInterface userService;
|
||||
|
||||
@Autowired
|
||||
private ServletContext servletContext;
|
||||
|
||||
|
||||
|
||||
@Autowired private ServletContext servletContext;
|
||||
|
||||
private String getApiKeyForUser() {
|
||||
if (userService == null)
|
||||
return "";
|
||||
if (userService == null) return "";
|
||||
return userService.getApiKeyForUser(Role.INTERNAL_API_USER.getRoleId());
|
||||
}
|
||||
|
||||
|
||||
private String getBaseUrl() {
|
||||
String contextPath = servletContext.getContextPath();
|
||||
String port = SPdfApplication.getPort();
|
||||
|
@ -69,9 +63,8 @@ public class PipelineProcessor {
|
|||
return "http://localhost:" + port + contextPath + "/";
|
||||
}
|
||||
|
||||
|
||||
|
||||
List<Resource> runPipelineAgainstFiles(List<Resource> outputFiles, PipelineConfig config) throws Exception {
|
||||
List<Resource> runPipelineAgainstFiles(List<Resource> outputFiles, PipelineConfig config)
|
||||
throws Exception {
|
||||
|
||||
ByteArrayOutputStream logStream = new ByteArrayOutputStream();
|
||||
PrintStream logPrintStream = new PrintStream(logStream);
|
||||
|
@ -82,7 +75,10 @@ public class PipelineProcessor {
|
|||
String operation = pipelineOperation.getOperation();
|
||||
boolean isMultiInputOperation = apiDocService.isMultiInput(operation);
|
||||
|
||||
logger.info("Running operation: {} isMultiInputOperation {}", operation, isMultiInputOperation);
|
||||
logger.info(
|
||||
"Running operation: {} isMultiInputOperation {}",
|
||||
operation,
|
||||
isMultiInputOperation);
|
||||
Map<String, Object> parameters = pipelineOperation.getParameters();
|
||||
String inputFileExtension = "";
|
||||
|
||||
|
@ -105,14 +101,14 @@ public class PipelineProcessor {
|
|||
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
|
||||
body.add("fileInput", file);
|
||||
|
||||
|
||||
for (Entry<String, Object> entry : parameters.entrySet()) {
|
||||
body.add(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
ResponseEntity<byte[]> response = sendWebRequest(url, body);
|
||||
|
||||
// If the operation is filter and the response body is null or empty, skip this
|
||||
// If the operation is filter and the response body is null or empty, skip
|
||||
// this
|
||||
// file
|
||||
if (operation.startsWith("filter-")
|
||||
&& (response.getBody() == null || response.getBody().length == 0)) {
|
||||
|
@ -126,22 +122,26 @@ public class PipelineProcessor {
|
|||
continue;
|
||||
}
|
||||
processOutputFiles(operation, file.getFilename(), response, newOutputFiles);
|
||||
|
||||
}
|
||||
|
||||
if (!hasInputFileType) {
|
||||
logPrintStream.println(
|
||||
"No files with extension " + inputFileExtension + " found for operation " + operation);
|
||||
"No files with extension "
|
||||
+ inputFileExtension
|
||||
+ " found for operation "
|
||||
+ operation);
|
||||
hasErrors = true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
// Filter and collect all files that match the inputFileExtension
|
||||
List<Resource> matchingFiles = outputFiles.stream()
|
||||
.filter(file -> file.getFilename().endsWith(finalInputFileExtension))
|
||||
List<Resource> matchingFiles =
|
||||
outputFiles.stream()
|
||||
.filter(
|
||||
file ->
|
||||
file.getFilename()
|
||||
.endsWith(finalInputFileExtension))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// Check if there are matching files
|
||||
|
@ -162,20 +162,28 @@ public class PipelineProcessor {
|
|||
|
||||
// Handle the response
|
||||
if (response.getStatusCode().equals(HttpStatus.OK)) {
|
||||
processOutputFiles(operation, matchingFiles.get(0).getFilename(), response, newOutputFiles);
|
||||
processOutputFiles(
|
||||
operation,
|
||||
matchingFiles.get(0).getFilename(),
|
||||
response,
|
||||
newOutputFiles);
|
||||
} else {
|
||||
// Log error if the response status is not OK
|
||||
logPrintStream.println("Error in multi-input operation: " + response.getBody());
|
||||
logPrintStream.println(
|
||||
"Error in multi-input operation: " + response.getBody());
|
||||
hasErrors = true;
|
||||
}
|
||||
} else {
|
||||
logPrintStream.println("No files with extension " + inputFileExtension + " found for multi-input operation " + operation);
|
||||
logPrintStream.println(
|
||||
"No files with extension "
|
||||
+ inputFileExtension
|
||||
+ " found for multi-input operation "
|
||||
+ operation);
|
||||
hasErrors = true;
|
||||
}
|
||||
}
|
||||
logPrintStream.close();
|
||||
outputFiles = newOutputFiles;
|
||||
|
||||
}
|
||||
if (hasErrors) {
|
||||
logger.error("Errors occurred during processing. Log: {}", logStream.toString());
|
||||
|
|
|
@ -33,7 +33,6 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
|||
@Tag(name = "General", description = "General APIs")
|
||||
public class GeneralWebController {
|
||||
|
||||
|
||||
@GetMapping("/pipeline")
|
||||
@Hidden
|
||||
public String pipelineForm(Model model) {
|
||||
|
@ -44,8 +43,8 @@ public class GeneralWebController {
|
|||
|
||||
if (new File("./pipeline/defaultWebUIConfigs/").exists()) {
|
||||
try (Stream<Path> paths = Files.walk(Paths.get("./pipeline/defaultWebUIConfigs/"))) {
|
||||
List<Path> jsonFiles = paths
|
||||
.filter(Files::isRegularFile)
|
||||
List<Path> jsonFiles =
|
||||
paths.filter(Files::isRegularFile)
|
||||
.filter(p -> p.toString().endsWith(".json"))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
|
@ -55,11 +54,17 @@ public class GeneralWebController {
|
|||
}
|
||||
|
||||
for (String config : pipelineConfigs) {
|
||||
Map<String, Object> jsonContent = new ObjectMapper().readValue(config, new TypeReference<Map<String, Object>>(){});
|
||||
Map<String, Object> jsonContent =
|
||||
new ObjectMapper()
|
||||
.readValue(config, new TypeReference<Map<String, Object>>() {});
|
||||
|
||||
String name = (String) jsonContent.get("name");
|
||||
if (name == null || name.length() < 1) {
|
||||
String filename = jsonFiles.get(pipelineConfigs.indexOf(config)).getFileName().toString();
|
||||
String filename =
|
||||
jsonFiles
|
||||
.get(pipelineConfigs.indexOf(config))
|
||||
.getFileName()
|
||||
.toString();
|
||||
name = filename.substring(0, filename.lastIndexOf('.'));
|
||||
}
|
||||
Map<String, String> configWithName = new HashMap<>();
|
||||
|
@ -71,9 +76,6 @@ public class GeneralWebController {
|
|||
pipelineConfigsWithNames.add(configWithName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -91,9 +93,6 @@ public class GeneralWebController {
|
|||
return "pipeline";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@GetMapping("/merge-pdfs")
|
||||
@Hidden
|
||||
public String mergePdfForm(Model model) {
|
||||
|
|
|
@ -11,6 +11,5 @@ public class RequestUriUtils {
|
|||
|| requestURI.startsWith("/pdfjs/")
|
||||
|| requestURI.endsWith(".svg")
|
||||
|| requestURI.startsWith("/api/v1/info/status");
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue