Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support several flavours #402

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
Expand All @@ -29,7 +30,7 @@ public void shouldCreateXmlReportsInGivenDirectory() throws Exception {

int numberOfThreads = 4;

List<Future<ValidationResult>> futureResult = startValidation(fileToValidate, numberOfThreads);
List<Future<List<ValidationResult>>> futureResult = startValidation(fileToValidate, numberOfThreads);
List<ValidationResult> validationResults = getValidationResult(futureResult);

boolean isExpectedResults = compareResultsFromDifferentThreads(validationResults);
Expand All @@ -52,21 +53,21 @@ private boolean compareResultsFromDifferentThreads(List<ValidationResult> valida
return isExpectedResults;
}

private List<ValidationResult> getValidationResult(List<Future<ValidationResult>> results) throws InterruptedException, java.util.concurrent.ExecutionException {
private List<ValidationResult> getValidationResult(List<Future<List<ValidationResult>>> results) throws InterruptedException, java.util.concurrent.ExecutionException {
List<ValidationResult> validationResults = new ArrayList<>();
for (Future<ValidationResult> result : results) {
ValidationResult validationResult = result.get();
validationResults.add(validationResult);
for (Future<List<ValidationResult>> result : results) {
List<ValidationResult> validationResult = result.get();
validationResults.addAll(validationResult);
}
return validationResults;
}

private List<Future<ValidationResult>> startValidation(File fileToValidate, int numberOfThreads) {
List<Future<ValidationResult>> futureResult = new ArrayList<>();
private List<Future<List<ValidationResult>>> startValidation(File fileToValidate, int numberOfThreads) {
List<Future<List<ValidationResult>>> futureResult = new ArrayList<>();
ExecutorService executor = Executors.newFixedThreadPool(numberOfThreads);
for (int i = 0; i < numberOfThreads; i++) {
CallableValidatorForTest validator = new CallableValidatorForTest(fileToValidate);
Future<ValidationResult> submit = executor.submit(validator);
Future<List<ValidationResult>> submit = executor.submit(validator);
futureResult.add(submit);
}
return futureResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@

import java.io.File;
import java.io.FileInputStream;
import java.util.List;
import java.util.concurrent.Callable;

public class CallableValidatorForTest implements Callable<ValidationResult> {
public class CallableValidatorForTest implements Callable<List<ValidationResult>> {
private final File fileToValidate;

public CallableValidatorForTest(File fileToValidate) {
this.fileToValidate = fileToValidate;
}

@Override
public ValidationResult call() throws Exception {
ValidationResult result;
public List<ValidationResult> call() throws Exception {
List<ValidationResult> result;
try (FileInputStream fis = new FileInputStream(this.fileToValidate);
PDFAParser parser = Foundries.defaultInstance().createParser(fis);
PDFAValidator validator = Foundries.defaultInstance().createValidator(parser.getFlavour(), false)) {
result = validator.validate(parser);
result = validator.validateAll(parser);
}
return result;
}
Expand Down
8 changes: 6 additions & 2 deletions gui/src/main/java/org/verapdf/cli/VeraPdfCliProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.verapdf.cli.CliConstants.ExitCodes;
import org.verapdf.cli.commands.VeraCliArgParser;
import org.verapdf.core.VeraPDFException;
import org.verapdf.pdfa.results.ValidationResult;
import org.verapdf.policy.PolicyChecker;
import org.verapdf.processor.*;
import org.verapdf.processor.app.ConfigManager;
Expand Down Expand Up @@ -183,8 +184,11 @@ private ExitCodes processStream(final ItemDetails item, final InputStream toProc

if (result.isPdf() && !result.isEncryptedPdf()) {
ProcessorFactory.writeSingleResultReport(result, handler, processorConfig);
if (!result.getValidationResult().isCompliant()) {
retVal = ExitCodes.INVALID;
for (ValidationResult validationResult : result.getValidationResults()) {
if (!validationResult.isCompliant()) {
retVal = ExitCodes.INVALID;
break;
}
}
} else {
String message = String.format(
Expand Down
Loading