@@ -136,7 +136,10 @@ object CsvValidatorUi extends SimpleSwingApplication {
136136 }
137137 }
138138
139- private def validate (csvFilePath : String , csvEncoding : Charset , csvSchemaFilePath : String , csvSchemaEncoding : Charset , failOnFirstError : Boolean , pathSubstitutions : List [(String , String )], enforceCaseSensitivePathChecks : Boolean , progress : Option [ProgressCallback ], validateEncoding : Boolean , skipFileChecks : Boolean , outputTextSuffix : String )(output : String => Unit ) : Unit = {
139+ private def validate (csvFilePath : String , csvEncoding : Charset , csvSchemaFilePath : String , csvSchemaEncoding : Charset ,
140+ failOnFirstError : Boolean , pathSubstitutions : List [(String , String )], enforceCaseSensitivePathChecks : Boolean ,
141+ progress : Option [ProgressCallback ], validateEncoding : Boolean , potentialMaxNumOfLines : String ,
142+ skipFileChecks : Boolean , outputTextSuffix : String )(output : String => Unit ) : Unit = {
140143
141144 def toConsole (msg : String ): Unit = Swing .onEDT {
142145 output(msg)
@@ -145,24 +148,32 @@ object CsvValidatorUi extends SimpleSwingApplication {
145148 var badLines = 0
146149 var truncated = false
147150
148- def rowCallback (row : ValidatedNel [FailMessage , Any ]): Unit = row match {
151+ val maxNumOfLines = Try (potentialMaxNumOfLines.toInt) match {
152+ case Success (number) if number > 0 => number
153+ case _ =>
154+ toConsole(" Error: Maximum number of errors to display should be more than 0" )
155+ 0
156+ }
157+ val safeToRunValidation = csvFilePath.nonEmpty && csvSchemaFilePath.nonEmpty && maxNumOfLines > 0
149158
159+ def logRowCallback (maxBadLines : Int )(row : ValidatedNel [FailMessage , Any ]): Unit = row match {
150160 case Invalid (failures) =>
151- if (badLines > 2000 ) {
161+ if (badLines >= maxBadLines ) {
152162 if (! truncated) {
153- toConsole(" Too many errors/warnings, truncating" )
163+ toConsole(
164+ s " ... \n\n Note: Number of errors to display has reached the set limit of $maxBadLines; " +
165+ " increase this limit and re-run in order to display more errors."
166+ )
154167 truncated = true
155168 }
156- } else {
157- toConsole(CsvValidatorCmdApp .prettyPrint(failures))
158- }
169+ } else toConsole(CsvValidatorCmdApp .prettyPrint(failures))
159170
160171 badLines += failures.size
161172
162173 case _ =>
163174 }
164175
165- if (csvFilePath.nonEmpty && csvSchemaFilePath.nonEmpty ) {
176+ if (safeToRunValidation ) {
166177 val (status, cliExitCode) = CsvValidatorCmdApp .validate(
167178 TextFile (Paths .get(csvFilePath), csvEncoding, validateEncoding),
168179 TextFile (Paths .get(csvSchemaFilePath), csvSchemaEncoding),
@@ -172,7 +183,7 @@ object CsvValidatorUi extends SimpleSwingApplication {
172183 trace = false ,
173184 progress,
174185 skipFileChecks,
175- rowCallback
186+ logRowCallback(maxNumOfLines)
176187 )
177188
178189 cliExitCode match {
@@ -346,7 +357,7 @@ object CsvValidatorUi extends SimpleSwingApplication {
346357 Swing .onEDT {
347358 progressBar.max = total
348359 progressBar.value = processed
349- progressBar.label = s " Line $processed of $total"
360+ progressBar.label = s " Row $processed of $total"
350361 }
351362 }
352363 }
@@ -383,6 +394,7 @@ object CsvValidatorUi extends SimpleSwingApplication {
383394 settingsPanel.enforceCaseSensitivePathChecks,
384395 Some (progress),
385396 settingsPanel.validateUtf8,
397+ settingsPanel.numOfLinesToDisplay,
386398 skipFileChecks,
387399 suffix
388400 )
@@ -468,15 +480,17 @@ object CsvValidatorUi extends SimpleSwingApplication {
468480 }
469481
470482 val settingsGroup = new SJXTaskPane (" Settings" , true )
471- private val lblCsvEncoding = new Label (" CSV Encoding" )
483+ private val lblCsvEncoding = new Label (" CSV Encoding: " )
472484 private val cmbCsvEncoding = new ComboBox (CHARACTER_ENCODINGS )
473- private val lblCsvSchemaEncoding = new Label (" CSV Schema Encoding" )
485+ private val lblCsvSchemaEncoding = new Label (" CSV Schema Encoding: " )
474486 private val cmbCsvSchemaEncoding = new ComboBox (CHARACTER_ENCODINGS )
475487 private val cbFailOnFirstError = new CheckBox (" Fail on first error" )
476488 cbFailOnFirstError.tooltip = " Indicates whether to fail on the first error, or whether to collect all errors!"
477489 private val cbValidateUtf8 = new CheckBox (" Validate CSV for valid UTF-8 characters" )
478490 cbValidateUtf8.selected = true
479- private val lblPathSubstitutions = new Label (" Path Substitutions" )
491+ private val tfDisplayLinesLabel = new Label (" Maximum number of errors to display:" )
492+ private val tfDisplayLines = new TextField (" 2000" , 5 )
493+ private val lblPathSubstitutions = new Label (" Path Substitutions:" )
480494 private val cbEnforceCaseSensitivePathChecks = new CheckBox (" Enforce case-sensitive file path checks" )
481495 cbEnforceCaseSensitivePathChecks.tooltip = " Performs additional checks to ensure that the case of file-paths in the CSV file match those of the filesystem"
482496
@@ -565,33 +579,43 @@ object CsvValidatorUi extends SimpleSwingApplication {
565579
566580 c.gridx = 0
567581 c.gridy = 2
568- layout(cbFailOnFirstError) = c
582+ c.insets = new Insets (0 , 0 , 0 , 0 )
583+ layout(tfDisplayLinesLabel) = c
584+
585+ c.gridx = 1
586+ c.gridy = 2
587+ c.insets = new Insets (0 , 0 , 0 , 0 )
588+ layout(tfDisplayLines) = c
569589
570590 c.gridx = 0
571591 c.gridy = 3
572- layout(cbEnforceCaseSensitivePathChecks ) = c
592+ layout(cbFailOnFirstError ) = c
573593
574594 c.gridx = 0
575595 c.gridy = 4
576- layout(cbValidateUtf8 ) = c
596+ layout(cbEnforceCaseSensitivePathChecks ) = c
577597
578598 c.gridx = 0
579599 c.gridy = 5
600+ layout(cbValidateUtf8) = c
601+
602+ c.gridx = 0
603+ c.gridy = 6
580604 c.insets = new Insets (0 ,10 ,0 ,0 )
581605 layout(lblPathSubstitutions) = c
582606
583607 c.gridx = 0
584- c.gridy = 6
608+ c.gridy = 7
585609 c.gridwidth = 2
586610 layout(spTblPathSubstitutions) = c
587611
588612 c.gridx = 0
589- c.gridy = 7
613+ c.gridy = 8
590614 c.anchor = Anchor .LineStart
591615 layout(btnRemovePathSubstitution) = c
592616
593617 c.gridx = 1
594- c.gridy = 7
618+ c.gridy = 8
595619 c.anchor = Anchor .LastLineEnd
596620 layout(btnAddPathSubstitution) = c
597621 }
@@ -605,5 +629,6 @@ object CsvValidatorUi extends SimpleSwingApplication {
605629 def pathSubstitutions : List [(String , String )] = tblPathSubstitutions.pathSubstitutions
606630 def enforceCaseSensitivePathChecks : Boolean = cbEnforceCaseSensitivePathChecks.selected
607631 def validateUtf8 : Boolean = cbValidateUtf8.selected
632+ def numOfLinesToDisplay : String = tfDisplayLines.text.strip()
608633 }
609634}
0 commit comments