stevedlawrence commented on a change in pull request #520:
URL: https://github.com/apache/daffodil/pull/520#discussion_r608058402
##########
File path: daffodil-cli/src/main/scala/org/apache/daffodil/Main.scala
##########
@@ -347,6 +351,7 @@ class CLIConf(arguments: Array[String]) extends
scallop.ScallopConf(arguments)
val parser = opt[File](short = 'P', argName = "file", descr = "use a
previously saved parser.")
val output = opt[String](argName = "file", descr = "write output to a
given file. If not given or is -, output is written to stdout.")
val validate: ScallopOption[ValidationMode.Type] =
opt[ValidationMode.Type](short = 'V', default = Some(ValidationMode.Off),
argName = "mode", descr = "the validation mode. 'on', 'limited', 'off', or a
validator plugin name.")
+ val valOutput = opt[File]("validate_output", descr = "path to file to
write raw validation output.")
Review comment:
I would reccomend changing the name to ``val validateOutput`` and
removing the "validate_output" string. Scallop will then autogenerate a the
long option that is consistent with others (i.e. ``--validate-output``).
Also worth adding ``argName="file"`` so that the autogenerated --help output
includes ``<file>`` instead of the default of ``<arg>``.
Also, it looks like scallop is defaulting to a short option of -v. I'm
concered that that could be confusing, since that usually means verbose. Maybe
we should just disable the short option by adding "noshort" as a parameter?
##########
File path: daffodil-cli/src/main/scala/org/apache/daffodil/Main.scala
##########
@@ -888,6 +899,23 @@ object Main extends Logging {
val loc =
parseResult.resultState.currentLocation.asInstanceOf[DataLoc]
displayDiagnostics(parseResult)
+ // allow raw validation output
+ if(!parseResult.isProcessingError) {
Review comment:
This will get the validation result even if the --validate-output flag
isn't set. Is is possible that validationResult() could do a decent amount of
work that should be avoided if valOutput is not set?
##########
File path: daffodil-cli/src/main/scala/org/apache/daffodil/Main.scala
##########
@@ -888,6 +899,23 @@ object Main extends Logging {
val loc =
parseResult.resultState.currentLocation.asInstanceOf[DataLoc]
displayDiagnostics(parseResult)
+ // allow raw validation output
+ if(!parseResult.isProcessingError) {
+ (parseOpts.valOutput.toOption, parseResult.validationResult())
match {
+ case (Some(of), Some(vr: RawValidationResult)) =>
+ Try(new FileOutputStream(of)) match {
+ case Success(os) =>
+ os.write(vr.rawValidationData())
+ os.close()
+ case Failure(ex) =>
+ log(LogLevel.Error, "Failure writing raw validation
data to file.", ex)
Review comment:
This doesn't change the exit code. I wonder if this should just be a
warning? Or if it should stay an error but make sure there is a non-zero exit
code?
##########
File path:
daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/DataProcessor.scala
##########
@@ -685,6 +685,8 @@ class ParseResult(dp: DataProcessor, override val
resultState: PState)
extends DFDL.ParseResult
with WithDiagnosticsImpl {
+ private var valres: Option[ValidationResult] = None
Review comment:
Rather than making this a var, I wonder if we should instead do this
validation prior to creating the ParseResult, and then our ParseResult become
something like:
```scala
class ParseResult(
dp: DataProcessor,
override val resultState: PState,
val validationResult: Option[ValidationResult])
```
Avoids the mutable state
##########
File path:
daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/DataProcessor.scala
##########
@@ -685,6 +685,8 @@ class ParseResult(dp: DataProcessor, override val
resultState: PState)
extends DFDL.ParseResult
with WithDiagnosticsImpl {
+ private var valres: Option[ValidationResult] = None
Review comment:
Also, I notice this doesn't update the Scala or Java API's. Is the
intention to keep this a sort of internal/experimental API until all the new
validation stuff is run through its paces?
##########
File path: daffodil-cli/src/main/scala/org/apache/daffodil/Main.scala
##########
@@ -328,7 +332,7 @@ class CLIConf(arguments: Array[String]) extends
scallop.ScallopConf(arguments)
object parse extends scallop.Subcommand("parse") {
banner("""|Usage: daffodil parse (-s <schema> [-r [{namespace}]<root>] [-p
<path>] |
| -P <parser>)
- | [--validate [mode]]
+ | [--validate [mode]] [--validate_output
[file]]
Review comment:
The square brackets around file generaly mean that the argument is
optional, whereas angle brackets usually means the arg is required. In this
case it's required, so should be angle brackets.
##########
File path:
daffodil-schematron/src/main/scala/org/apache/daffodil/validation/schematron/SchematronResult.scala
##########
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.daffodil.validation.schematron
+
+import org.apache.daffodil.api.RawValidationResult
+import org.apache.daffodil.api.ValidationFailure
+import org.apache.daffodil.api.ValidationResult
+import org.apache.daffodil.api.ValidationWarning
+
+import java.util
+
+/**
+ * Captures the output of Schematron validation as a Daffodil ValidationResult
+ * @param warnings Schematron warnings parsed into ValidationWarning objects
+ * @param errors Schematron errors parsed into ValidationFailure objects
+ * @param svrl Full SVRL output
+ */
+case class SchematronResult(warnings: util.Collection[ValidationWarning],
+ errors: util.Collection[ValidationFailure],
+ svrl: String) extends ValidationResult with
RawValidationResult {
+
+ def rawValidationData(): Array[Byte] = svrl.getBytes
+}
Review comment:
Is there a big advantage to having a special RawValidationResult trait?
The CLI can easily just match/case the ValidationResult to a SchematronResult
and get what it needs? I guess my concern is that that a user of this schemtron
validator might want access to the Svrl String, or maybe even the svrl XML
Document, but instead we're converting it to bytes just to be generic and
forcing them to do something with it. But being generic doesn't seem to gain
much since the user still needs to know what it is to be able to do anything
with it.
So I guess what's the advantage of this bytes thing over something like this
in the CLI:
```scala
validateResult match {
case sr: SchematronResult => os.write(sr.svrl.toString)
case _ => // noop, no additional information
}
```
This way if someone wants direct access to the svrl document, they can get
it without any extra overhead of converting those generic bytes back to the
original data. But if they just want to output it to a file (like the Daffodil
CLI does), then we can do so with a pretty easy cast and toString.
##########
File path: daffodil-cli/src/main/scala/org/apache/daffodil/Main.scala
##########
@@ -356,6 +361,7 @@ class CLIConf(arguments: Array[String]) extends
scallop.ScallopConf(arguments)
requireOne(schema, parser) // must have one of --schema or --parser
conflicts(parser, List(rootNS)) // if --parser is provided, cannot also
provide --root
+ conflicts(stream, List(valOutput))
validateFileIsFile(config) // --config must be a file that exists
Review comment:
Do we need a coconstraint that --validate-output requires --validation
be enabled? Something like
```scala
dependsOnAll(valOutput, List(validate))
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]