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

added flag to not generate validation-report file #575

Merged
merged 3 commits into from
Feb 22, 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 @@ -56,7 +56,7 @@ public ValidationReporter(Path path, Path siardPackagePath) {

private void init(Path path, Path siardPackagePath) {
this.outputFile = path;
if (outputFile.toFile().exists()) {
if (outputFile != null && outputFile.toFile().exists()) {
try {
Files.createFile(outputFile);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class SIARDValidateFactory implements ValidateModuleFactory {
public static final String PARAMETER_ALLOWED = "allowed";
public static final String PARAMETER_REPORT = "report";
public static final String PARAMETER_SKIP_ADDITIONAL_CHECKS = "skip-additional-checks";
public static final String PARAMETER_NO_REPORT_FILE = "no-report-file";

private static final Parameter file = new Parameter().shortName("f").longName(PARAMETER_FILE)
.description("Path to SIARD2 archive file.").hasArgument(true).setOptionalArgument(false).required(true);
Expand All @@ -55,6 +56,11 @@ public class SIARDValidateFactory implements ValidateModuleFactory {
+ " The additional checks can be found at: https://github.com/keeps/db-preservation-toolkit/wiki/Validation#additional-checks ")
.hasArgument(false).valueIfSet("true").valueIfNotSet("false").required(false);

private static final Parameter noReportFile = new Parameter().shortName("nrf")
.longName(PARAMETER_NO_REPORT_FILE)
.description("The validation report file will not be generated.")
.hasArgument(false).valueIfSet("true").valueIfNotSet("false").required(false);

@Override
public String getModuleName() {
return "validate-siard";
Expand All @@ -72,7 +78,7 @@ public Parameters getImportParameters() {

@Override
public Parameters getSingleParameters() {
return new Parameters(Arrays.asList(allowed, report, skipAdditionalChecks), null);
return new Parameters(Arrays.asList(allowed, report, skipAdditionalChecks, noReportFile), null);
}

@Override
Expand All @@ -82,6 +88,7 @@ public Map<String, Parameter> getAllParameters() {
parameterHashMap.put(report.longName(), report);
parameterHashMap.put(allowed.longName(), allowed);
parameterHashMap.put(skipAdditionalChecks.longName(), skipAdditionalChecks);
parameterHashMap.put(noReportFile.longName(), noReportFile);

return parameterHashMap;
}
Expand All @@ -92,13 +99,19 @@ public ValidateModule buildModule(Map<Parameter, String> parameters, Reporter re
Path pReport;
Path pAllowUDTs = null;

if (parameters.get(report) != null) {
pReport = Paths.get(parameters.get(report));
boolean pNoReportFile = Boolean.parseBoolean(parameters.get(noReportFile));

if (!pNoReportFile) {
if (parameters.get(report) != null) {
pReport = Paths.get(parameters.get(report));
} else {
String name = Constants.DBPTK_VALIDATION_REPORTER_PREFIX + "-"
+ pFile.getFileName().toString().replaceFirst("[.][^.]+$", "") + "-"
+ new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()) + ".txt";
pReport = ConfigUtils.getReportsDirectory().resolve(name);
}
} else {
String name = Constants.DBPTK_VALIDATION_REPORTER_PREFIX + "-"
+ pFile.getFileName().toString().replaceFirst("[.][^.]+$", "") + "-"
+ new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()) + ".txt";
pReport = ConfigUtils.getReportsDirectory().resolve(name);
pReport = null;
}

if (parameters.get(allowed) != null) {
Expand All @@ -113,13 +126,14 @@ public ValidateModule buildModule(Map<Parameter, String> parameters, Reporter re
}

if (pAllowUDTs != null) {
String reportParam = pReport != null ? pReport.normalize().toAbsolutePath().toString() : null;
reporter.importModuleParameters(getModuleName(), PARAMETER_FILE, pFile.normalize().toAbsolutePath().toString(),
PARAMETER_ALLOWED, pAllowUDTs.normalize().toAbsolutePath().toString(), PARAMETER_REPORT,
pReport.normalize().toAbsolutePath().toString());
PARAMETER_ALLOWED, pAllowUDTs.normalize().toAbsolutePath().toString(), PARAMETER_REPORT, reportParam);
return new SIARDValidateModule(pFile, pReport, pAllowUDTs, pSkipAdditionalChecks);
} else {
String reportParam = pReport != null ? pReport.normalize().toAbsolutePath().toString() : null;
reporter.importModuleParameters(getModuleName(), PARAMETER_FILE, pFile.normalize().toAbsolutePath().toString(),
PARAMETER_REPORT, pReport.normalize().toAbsolutePath().toString());
PARAMETER_REPORT, reportParam);
return new SIARDValidateModule(pFile, pReport, pSkipAdditionalChecks);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@ public class SIARDValidateModule implements ValidateModule {
*/
public SIARDValidateModule(Path SIARDPackagePath, Path validationReporterPath, boolean skipAdditionalChecks) {
siardPackageNormalizedPath = SIARDPackagePath.toAbsolutePath().normalize();
validationReporter = new ValidationReporter(validationReporterPath.toAbsolutePath().normalize(),
siardPackageNormalizedPath);

validationReporter = new ValidationReporter(
validationReporterPath != null ? validationReporterPath.toAbsolutePath().normalize() : null,
siardPackageNormalizedPath
);
allowedUDTs = Collections.emptyList();
validatorPathStrategy = new ValidatorPathStrategyImpl();
zipFileManager = new ZipFileManager();
Expand Down
8 changes: 1 addition & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@
<version.java>1.8</version.java>
<projectLocalRepository>${project.basedir}/vendor-libs/repository</projectLocalRepository>
</properties>
<repositories>
<repository>
<id>KEEPS-Artifacts</id>
<name>KEEP Artifacts-releases</name>
<url>https://artifactory.keep.pt/keep</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>github</id>
Expand All @@ -44,6 +37,7 @@
<modules>
<module>dbptk-model</module>
<module>dbptk-core</module>
<module>dbptk-bindings</module>
<module>dbptk-modules</module>
</modules>
</profile>
Expand Down
Loading