From 4e8a9d0f718e555d95a44385724773377e9c0afe Mon Sep 17 00:00:00 2001 From: "kenad.araujo" Date: Mon, 8 Feb 2021 10:14:59 -0300 Subject: [PATCH] - Creation of a 'FailMessage' translation mechanism from a message in a 'ResourceBundle' --- .project | 17 +++++++ README.md | 12 +++++ csv-validator-cmd/.project | 17 +++++++ .../.settings/org.eclipse.m2e.core.prefs | 4 ++ csv-validator-core/.classpath | 34 +++++++++++++ csv-validator-core/.project | 48 +++++++++++++++++++ .../org.eclipse.core.resources.prefs | 3 ++ .../.settings/org.eclipse.jdt.apt.core.prefs | 2 + .../.settings/org.eclipse.jdt.core.prefs | 12 +++++ .../.settings/org.eclipse.m2e.core.prefs | 4 ++ .../org.eclipse.wst.common.component | 5 ++ ....eclipse.wst.common.project.facet.core.xml | 5 ++ .../org.eclipse.wst.validation.prefs | 2 + csv-validator-core/pom.xml | 8 +++- .../csv/validator/MetaDataValidator.scala | 24 +++++----- csv-validator-java-api/.classpath | 28 +++++++++++ csv-validator-java-api/.project | 48 +++++++++++++++++++ .../org.eclipse.core.resources.prefs | 3 ++ .../.settings/org.eclipse.jdt.apt.core.prefs | 2 + .../.settings/org.eclipse.jdt.core.prefs | 12 +++++ .../.settings/org.eclipse.m2e.core.prefs | 4 ++ .../org.eclipse.wst.common.component | 5 ++ ....eclipse.wst.common.project.facet.core.xml | 5 ++ .../org.eclipse.wst.validation.prefs | 2 + csv-validator-java-api/pom.xml | 26 ++++++++-- .../csv/validator/api/java/CsvValidator.java | 31 ++++++++++++ .../csv/validator/api/java/ErrorMessage.java | 3 ++ .../csv/validator/api/java/FailMessage.java | 17 +++++++ .../validator/api/java/WarningMessage.java | 3 ++ .../java/exceptions/FailMessageException.java | 22 +++++++++ .../exceptions/ResourceBundleException.java | 22 +++++++++ .../api/java/CsvValidatorJavaBridge.scala | 6 +-- csv-validator-parent/.project | 17 +++++++ .../org.eclipse.core.resources.prefs | 2 + .../.settings/org.eclipse.m2e.core.prefs | 4 ++ csv-validator-parent/pom.xml | 7 ++- csv-validator-ui/.project | 17 +++++++ .../.settings/org.eclipse.m2e.core.prefs | 4 ++ 38 files changed, 465 insertions(+), 22 deletions(-) create mode 100644 .project create mode 100644 csv-validator-cmd/.project create mode 100644 csv-validator-cmd/.settings/org.eclipse.m2e.core.prefs create mode 100644 csv-validator-core/.classpath create mode 100644 csv-validator-core/.project create mode 100644 csv-validator-core/.settings/org.eclipse.core.resources.prefs create mode 100644 csv-validator-core/.settings/org.eclipse.jdt.apt.core.prefs create mode 100644 csv-validator-core/.settings/org.eclipse.jdt.core.prefs create mode 100644 csv-validator-core/.settings/org.eclipse.m2e.core.prefs create mode 100644 csv-validator-core/.settings/org.eclipse.wst.common.component create mode 100644 csv-validator-core/.settings/org.eclipse.wst.common.project.facet.core.xml create mode 100644 csv-validator-core/.settings/org.eclipse.wst.validation.prefs create mode 100644 csv-validator-java-api/.classpath create mode 100644 csv-validator-java-api/.project create mode 100644 csv-validator-java-api/.settings/org.eclipse.core.resources.prefs create mode 100644 csv-validator-java-api/.settings/org.eclipse.jdt.apt.core.prefs create mode 100644 csv-validator-java-api/.settings/org.eclipse.jdt.core.prefs create mode 100644 csv-validator-java-api/.settings/org.eclipse.m2e.core.prefs create mode 100644 csv-validator-java-api/.settings/org.eclipse.wst.common.component create mode 100644 csv-validator-java-api/.settings/org.eclipse.wst.common.project.facet.core.xml create mode 100644 csv-validator-java-api/.settings/org.eclipse.wst.validation.prefs create mode 100644 csv-validator-java-api/src/main/java/uk/gov/nationalarchives/csv/validator/api/java/exceptions/FailMessageException.java create mode 100644 csv-validator-java-api/src/main/java/uk/gov/nationalarchives/csv/validator/api/java/exceptions/ResourceBundleException.java create mode 100644 csv-validator-parent/.project create mode 100644 csv-validator-parent/.settings/org.eclipse.core.resources.prefs create mode 100644 csv-validator-parent/.settings/org.eclipse.m2e.core.prefs create mode 100644 csv-validator-ui/.project create mode 100644 csv-validator-ui/.settings/org.eclipse.m2e.core.prefs diff --git a/.project b/.project new file mode 100644 index 00000000..1e5d566e --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + csv-validator + + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + + diff --git a/README.md b/README.md index b47963f1..d82880e6 100644 --- a/README.md +++ b/README.md @@ -102,3 +102,15 @@ The CSV Validator implements almost all of `CSV Schema 1.1` language, current li * `PartialDateExpr` is not yet implemented (raises Schema check error). * At least `MD5`, `SHA-1`, `SHA-2`, `SHA-3`, and `SHA-256` checksum algorithms are supported. Probably many more as well as we defer to Java's `java.security.MessageDigest` class. + +# Internationalization + +The CSV Validator for Java API implements almost internationalization through Resource Bundle messages: + +* metadata.empty.notBeenPermitted - alternative message for "metadata file is empty but this has not been permitted" +* metadata.empty.noHeader - alternative message for "metadata file is empty but should contain at least a header" +* metadata.empty.noData - alternative message for "metadata file has a header but no data and this has not been permitted" +* metadata.empty.missingColumns - alternative message for "Metadata header, cannot find the column headers" +* metadata.utf8 - alternative message for "[UTF-8 Error]" +* metadata.expectedTotalColumns - alternative message for "Expected @totalColumns of ${tc.get.numberOfColumns} and found ${row.cells.length} on line ${row.lineNumber}" +* metadata.missingValue - alternative message for "Missing value at line: ${row.lineNumber}, column: ${schema.columnDefinitions(columnIndex).id}" \ No newline at end of file diff --git a/csv-validator-cmd/.project b/csv-validator-cmd/.project new file mode 100644 index 00000000..fde0bd26 --- /dev/null +++ b/csv-validator-cmd/.project @@ -0,0 +1,17 @@ + + + csv-validator-cmd + + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + + diff --git a/csv-validator-cmd/.settings/org.eclipse.m2e.core.prefs b/csv-validator-cmd/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 00000000..f897a7f1 --- /dev/null +++ b/csv-validator-cmd/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/csv-validator-core/.classpath b/csv-validator-core/.classpath new file mode 100644 index 00000000..9fa21710 --- /dev/null +++ b/csv-validator-core/.classpath @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/csv-validator-core/.project b/csv-validator-core/.project new file mode 100644 index 00000000..8b6d6f8e --- /dev/null +++ b/csv-validator-core/.project @@ -0,0 +1,48 @@ + + + csv-validator-core + + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.jboss.tools.jst.web.kb.kbbuilder + + + + + org.jboss.tools.cdi.core.cdibuilder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + org.eclipse.wst.common.project.facet.core.nature + org.jboss.tools.jst.web.kb.kbnature + org.jboss.tools.cdi.core.cdinature + + diff --git a/csv-validator-core/.settings/org.eclipse.core.resources.prefs b/csv-validator-core/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 00000000..17093aeb --- /dev/null +++ b/csv-validator-core/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,3 @@ +eclipse.preferences.version=1 +encoding//src/test/resources=UTF-8 +encoding/=UTF-8 diff --git a/csv-validator-core/.settings/org.eclipse.jdt.apt.core.prefs b/csv-validator-core/.settings/org.eclipse.jdt.apt.core.prefs new file mode 100644 index 00000000..d4313d4b --- /dev/null +++ b/csv-validator-core/.settings/org.eclipse.jdt.apt.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.apt.aptEnabled=false diff --git a/csv-validator-core/.settings/org.eclipse.jdt.core.prefs b/csv-validator-core/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..59664bbb --- /dev/null +++ b/csv-validator-core/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.processAnnotations=disabled +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/csv-validator-core/.settings/org.eclipse.m2e.core.prefs b/csv-validator-core/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 00000000..f897a7f1 --- /dev/null +++ b/csv-validator-core/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/csv-validator-core/.settings/org.eclipse.wst.common.component b/csv-validator-core/.settings/org.eclipse.wst.common.component new file mode 100644 index 00000000..f003811a --- /dev/null +++ b/csv-validator-core/.settings/org.eclipse.wst.common.component @@ -0,0 +1,5 @@ + + + + + diff --git a/csv-validator-core/.settings/org.eclipse.wst.common.project.facet.core.xml b/csv-validator-core/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 00000000..c78d9323 --- /dev/null +++ b/csv-validator-core/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/csv-validator-core/.settings/org.eclipse.wst.validation.prefs b/csv-validator-core/.settings/org.eclipse.wst.validation.prefs new file mode 100644 index 00000000..04cad8cb --- /dev/null +++ b/csv-validator-core/.settings/org.eclipse.wst.validation.prefs @@ -0,0 +1,2 @@ +disabled=06target +eclipse.preferences.version=1 diff --git a/csv-validator-core/pom.xml b/csv-validator-core/pom.xml index 962d9582..ff25c607 100644 --- a/csv-validator-core/pom.xml +++ b/csv-validator-core/pom.xml @@ -4,7 +4,7 @@ uk.gov.nationalarchives csv-validator-parent - 1.2-RC3-SNAPSHOT + 1.2.1 ../csv-validator-parent @@ -58,6 +58,9 @@ -nobootcp + + dependencies + @@ -73,6 +76,9 @@ true + + dependencies + diff --git a/csv-validator-core/src/main/scala/uk/gov/nationalarchives/csv/validator/MetaDataValidator.scala b/csv-validator-core/src/main/scala/uk/gov/nationalarchives/csv/validator/MetaDataValidator.scala index 51dea38b..eb41a6b9 100644 --- a/csv-validator-core/src/main/scala/uk/gov/nationalarchives/csv/validator/MetaDataValidator.scala +++ b/csv-validator-core/src/main/scala/uk/gov/nationalarchives/csv/validator/MetaDataValidator.scala @@ -37,18 +37,18 @@ sealed trait ErrorType case object ValidationWarning extends ErrorType case object ValidationError extends ErrorType case object SchemaDefinitionError extends ErrorType -case class FailMessage(`type`: ErrorType, message : String, lineNumber: Option[Int] = None, columnIndex: Option[Int] = None) //TODO(AR) consider a better name, e.g. CsvValidationFailure +case class FailMessage(`type`: ErrorType, message : String, lineNumber: Option[Int] = None, columnIndex: Option[Int] = None,resourceTag:Option[String] = None) //TODO(AR) consider a better name, e.g. CsvValidationFailure object FailMessage { def isWarning : PartialFunction[FailMessage, FailMessage] = { - case fm @ FailMessage(ValidationWarning, _, _, _) => fm + case fm @ FailMessage(ValidationWarning, _, _, _, _) => fm } def isError : PartialFunction[FailMessage, FailMessage] = { - case fm @ FailMessage(ValidationError, _, _, _) => fm + case fm @ FailMessage(ValidationError, _, _, _, _) => fm } def isSchemaDefinitionError : PartialFunction[FailMessage, FailMessage] = { - case fm @ FailMessage(SchemaDefinitionError, _, _, _) => fm + case fm @ FailMessage(SchemaDefinitionError, _, _, _, _) => fm } } @@ -127,19 +127,19 @@ trait MetaDataValidator { val maybeNoData = if (schema.globalDirectives.contains(NoHeader())) { if (!rowIt.hasNext && !schema.globalDirectives.contains(PermitEmpty())) { - Some(FailMessage(ValidationError, "metadata file is empty but this has not been permitted").failureNel[Any]) + Some(FailMessage(ValidationError, "metadata file is empty but this has not been permitted",resourceTag = Some("metadata.empty.notBeenPermitted")).failureNel[Any]) } else { None } } else { if(!rowIt.hasNext) { - Some(FailMessage(ValidationError, "metadata file is empty but should contain at least a header").failureNel[Any]) + Some(FailMessage(ValidationError, "metadata file is empty but should contain at least a header",resourceTag = Some("metadata.empty.noHeader")).failureNel[Any]) } else { val header = rowIt.skipHeader() val headerValidation = validateHeader(header, schema) headerValidation.orElse { if(!rowIt.hasNext && !schema.globalDirectives.contains(PermitEmpty())) { - Some(FailMessage(ValidationError, "metadata file has a header but no data and this has not been permitted").failureNel[Any]) + Some(FailMessage(ValidationError, "metadata file has a header but no data and this has not been permitted",resourceTag = Some("metadata.empty.noData")).failureNel[Any]) } else { None } @@ -195,7 +195,7 @@ trait MetaDataValidator { if (headerList.sameElements(schemaHeader)) None else - Some(FailMessage(ValidationError, s"Metadata header, cannot find the column headers - ${Util.diff(schemaHeader.toSet, headerList.toSet).mkString(", ")} - .${if (icnc.isEmpty) " (Case sensitive)" else ""}").failureNel[Any]) + Some(FailMessage(ValidationError, s"Metadata header, cannot find the column headers - ${Util.diff(schemaHeader.toSet, headerList.toSet).mkString(", ")} - .${if (icnc.isEmpty) " (Case sensitive)" else ""}", resourceTag = Some("metadata.empty.missingColumns")).failureNel[Any]) } def validateRow(row: Row, schema: Schema, mayBeLast: Option[Boolean] = None): MetaDataValidation[Any] = { @@ -220,7 +220,7 @@ trait MetaDataValidator { case None => true.successNel case Some(nel) => { val ret = nel.reverse.map { - case (offset, message) => FailMessage(ValidationError, s"[UTF-8 Error][@$offset] ${message}") + case (offset, message) => FailMessage(ValidationError, s"[UTF-8 Error][@$offset] ${message}", resourceTag = Some("metadata.utf8")) } ret.failure } @@ -233,7 +233,7 @@ trait MetaDataValidator { } if (tc.isEmpty || tc.get.numberOfColumns == row.cells.length) true.successNel[FailMessage] - else FailMessage(ValidationError, s"Expected @totalColumns of ${tc.get.numberOfColumns} and found ${row.cells.length} on line ${row.lineNumber}", Some(row.lineNumber), Some(row.cells.length)).failureNel[Any] + else FailMessage(ValidationError, s"Expected @totalColumns of ${tc.get.numberOfColumns} and found ${row.cells.length} on line ${row.lineNumber}", Some(row.lineNumber), Some(row.cells.length), Some("metadata.expectedTotalColumns")).failureNel[Any] } protected def rules(row: Row, schema: Schema, mayBeLast: Option[Boolean] = None): MetaDataValidation[List[Any]] @@ -241,7 +241,7 @@ trait MetaDataValidator { protected def validateCell(columnIndex: Int, cells: (Int) => Option[Cell], row: Row, schema: Schema, mayBeLast: Option[Boolean] = None): MetaDataValidation[Any] = { cells(columnIndex) match { case Some(c) => rulesForCell(columnIndex, row, schema, mayBeLast) - case _ => FailMessage(ValidationError, s"Missing value at line: ${row.lineNumber}, column: ${schema.columnDefinitions(columnIndex).id}", Some(row.lineNumber), Some(columnIndex)).failureNel[Any] + case _ => FailMessage(ValidationError, s"Missing value at line: ${row.lineNumber}, column: ${schema.columnDefinitions(columnIndex).id}", Some(row.lineNumber), Some(columnIndex), Some("metadata.missingValue")).failureNel[Any] } } @@ -347,4 +347,4 @@ class RowIterator(parser: CsvParser, progress: Option[ProgressFor]) extends Iter override def hasNext: Boolean = current.nonEmpty private def toRow(rowData: Option[Array[String]]): Option[Row] = rowData.map(data => Row(data.toList.map(d => Cell(Option(d).getOrElse(""))), index)) -} +} \ No newline at end of file diff --git a/csv-validator-java-api/.classpath b/csv-validator-java-api/.classpath new file mode 100644 index 00000000..150c2efd --- /dev/null +++ b/csv-validator-java-api/.classpath @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/csv-validator-java-api/.project b/csv-validator-java-api/.project new file mode 100644 index 00000000..a911f030 --- /dev/null +++ b/csv-validator-java-api/.project @@ -0,0 +1,48 @@ + + + csv-validator-java-api + + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.jboss.tools.jst.web.kb.kbbuilder + + + + + org.jboss.tools.cdi.core.cdibuilder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + org.eclipse.wst.common.project.facet.core.nature + org.jboss.tools.jst.web.kb.kbnature + org.jboss.tools.cdi.core.cdinature + + diff --git a/csv-validator-java-api/.settings/org.eclipse.core.resources.prefs b/csv-validator-java-api/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 00000000..e9441bb1 --- /dev/null +++ b/csv-validator-java-api/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,3 @@ +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding/=UTF-8 diff --git a/csv-validator-java-api/.settings/org.eclipse.jdt.apt.core.prefs b/csv-validator-java-api/.settings/org.eclipse.jdt.apt.core.prefs new file mode 100644 index 00000000..d4313d4b --- /dev/null +++ b/csv-validator-java-api/.settings/org.eclipse.jdt.apt.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.apt.aptEnabled=false diff --git a/csv-validator-java-api/.settings/org.eclipse.jdt.core.prefs b/csv-validator-java-api/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..fa50df0e --- /dev/null +++ b/csv-validator-java-api/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.processAnnotations=disabled +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/csv-validator-java-api/.settings/org.eclipse.m2e.core.prefs b/csv-validator-java-api/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 00000000..f897a7f1 --- /dev/null +++ b/csv-validator-java-api/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/csv-validator-java-api/.settings/org.eclipse.wst.common.component b/csv-validator-java-api/.settings/org.eclipse.wst.common.component new file mode 100644 index 00000000..90832d4f --- /dev/null +++ b/csv-validator-java-api/.settings/org.eclipse.wst.common.component @@ -0,0 +1,5 @@ + + + + + diff --git a/csv-validator-java-api/.settings/org.eclipse.wst.common.project.facet.core.xml b/csv-validator-java-api/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 00000000..f4bf050d --- /dev/null +++ b/csv-validator-java-api/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/csv-validator-java-api/.settings/org.eclipse.wst.validation.prefs b/csv-validator-java-api/.settings/org.eclipse.wst.validation.prefs new file mode 100644 index 00000000..04cad8cb --- /dev/null +++ b/csv-validator-java-api/.settings/org.eclipse.wst.validation.prefs @@ -0,0 +1,2 @@ +disabled=06target +eclipse.preferences.version=1 diff --git a/csv-validator-java-api/pom.xml b/csv-validator-java-api/pom.xml index 7314bd60..cfdc853d 100644 --- a/csv-validator-java-api/pom.xml +++ b/csv-validator-java-api/pom.xml @@ -1,10 +1,11 @@ - + 4.0.0 uk.gov.nationalarchives csv-validator-parent - 1.2-RC3-SNAPSHOT + 1.2.1 ../csv-validator-parent @@ -18,8 +19,8 @@ scm:git:https://github.com/digital-preservation/csv-validator.git scm:git:https://github.com/digital-preservation/csv-validator.git scm:git:https://github.com/digital-preservation/csv-validator.git - HEAD - + HEAD + @@ -73,6 +74,23 @@ + + org.apache.maven.plugins + maven-assembly-plugin + + + package + + single + + + + jar-with-dependencies + + + + + org.apache.maven.plugins diff --git a/csv-validator-java-api/src/main/java/uk/gov/nationalarchives/csv/validator/api/java/CsvValidator.java b/csv-validator-java-api/src/main/java/uk/gov/nationalarchives/csv/validator/api/java/CsvValidator.java index 7c7578f9..2c59182e 100644 --- a/csv-validator-java-api/src/main/java/uk/gov/nationalarchives/csv/validator/api/java/CsvValidator.java +++ b/csv-validator-java-api/src/main/java/uk/gov/nationalarchives/csv/validator/api/java/CsvValidator.java @@ -10,7 +10,13 @@ import java.io.Reader; import java.nio.charset.Charset; +import java.util.ArrayList; import java.util.List; +import java.util.ResourceBundle; + +import uk.gov.nationalarchives.csv.validator.api.java.exceptions.FailMessageException; +import uk.gov.nationalarchives.csv.validator.api.java.exceptions.ResourceBundleException; + import static uk.gov.nationalarchives.csv.validator.api.CsvValidator$.MODULE$; /** @@ -164,5 +170,30 @@ public static List validate(final Reader csvData, final Reader csvS public static List validate(final Reader csvData, final Reader csvSchema, final boolean failFast, final List pathSubstitutions, final Boolean enforceCaseSensitivePathChecks, final Boolean trace, final ProgressCallback progress) { return CsvValidatorJavaBridge.validate(csvData, csvSchema, failFast, pathSubstitutions, enforceCaseSensitivePathChecks, trace, progress); } + /** + * Translate CSV FailMessage with ResourceBundle + * + * @param originMessages FailMessages don't translated + * @param resource is ResourceBudle with messages in language destiny + * + * @return List of FailMessage with message translated. + */ + public static List translate(List originMessages,ResourceBundle resource) throws ResourceBundleException,FailMessageException{ + if(originMessages==null||originMessages.isEmpty()){ + throw new FailMessageException("FailMessage was not provided to translate"); + } + if(resource==null){ + throw new ResourceBundleException("ResourceBundle was not null"); + } + List translatedMessage = new ArrayList<>(); + for(FailMessage failMessage:originMessages){ + if(resource.containsKey(failMessage.getResourceTag())){ + String messageTranslate = resource.getString(failMessage.getResourceTag()); + translatedMessage.add( + new ErrorMessage(messageTranslate,failMessage.getLineNumber(),failMessage.getColumnIndex(),failMessage.getResourceTag())); + } + } + return translatedMessage; + } } diff --git a/csv-validator-java-api/src/main/java/uk/gov/nationalarchives/csv/validator/api/java/ErrorMessage.java b/csv-validator-java-api/src/main/java/uk/gov/nationalarchives/csv/validator/api/java/ErrorMessage.java index c4752684..720bc475 100644 --- a/csv-validator-java-api/src/main/java/uk/gov/nationalarchives/csv/validator/api/java/ErrorMessage.java +++ b/csv-validator-java-api/src/main/java/uk/gov/nationalarchives/csv/validator/api/java/ErrorMessage.java @@ -16,4 +16,7 @@ public class ErrorMessage extends FailMessage { public ErrorMessage(final String message, final int lineNumber, final int columnIndex) { super(message, lineNumber, columnIndex); } + public ErrorMessage(final String message, final int lineNumber, final int columnIndex,final String resourceTag) { + super(message, lineNumber, columnIndex,resourceTag); + } } diff --git a/csv-validator-java-api/src/main/java/uk/gov/nationalarchives/csv/validator/api/java/FailMessage.java b/csv-validator-java-api/src/main/java/uk/gov/nationalarchives/csv/validator/api/java/FailMessage.java index bee85ada..b7db33c7 100644 --- a/csv-validator-java-api/src/main/java/uk/gov/nationalarchives/csv/validator/api/java/FailMessage.java +++ b/csv-validator-java-api/src/main/java/uk/gov/nationalarchives/csv/validator/api/java/FailMessage.java @@ -15,7 +15,20 @@ public abstract class FailMessage { private final String message; private final int lineNumber; private final int columnIndex; + private final String resourceTag; + /** + * @param message The failure message + * @param lineNumber The original line number in the file + * @param columnIndex Zero-based column index + * @param resourceTag ResourceTag parameter + */ + public FailMessage(final String message, final int lineNumber, final int columnIndex,final String resourceTag) { + this.message = message; + this.lineNumber = lineNumber; + this.columnIndex = columnIndex; + this.resourceTag = resourceTag; + } /** * @param message The failure message * @param lineNumber The original line number in the file @@ -25,6 +38,7 @@ public FailMessage(final String message, final int lineNumber, final int columnI this.message = message; this.lineNumber = lineNumber; this.columnIndex = columnIndex; + this.resourceTag = "general.tag"; } public String getMessage() { @@ -40,4 +54,7 @@ public int getColumnIndex() { return columnIndex; } + public String getResourceTag(){ + return resourceTag; + } } \ No newline at end of file diff --git a/csv-validator-java-api/src/main/java/uk/gov/nationalarchives/csv/validator/api/java/WarningMessage.java b/csv-validator-java-api/src/main/java/uk/gov/nationalarchives/csv/validator/api/java/WarningMessage.java index 0d3d26a3..5aeace11 100644 --- a/csv-validator-java-api/src/main/java/uk/gov/nationalarchives/csv/validator/api/java/WarningMessage.java +++ b/csv-validator-java-api/src/main/java/uk/gov/nationalarchives/csv/validator/api/java/WarningMessage.java @@ -16,4 +16,7 @@ public class WarningMessage extends FailMessage { public WarningMessage(final String message, final int lineNumber, final int columnIndex) { super(message, lineNumber, columnIndex); } + public WarningMessage(final String message, final int lineNumber, final int columnIndex, final String resourceTag){ + super(message, lineNumber, columnIndex,resourceTag); + } } diff --git a/csv-validator-java-api/src/main/java/uk/gov/nationalarchives/csv/validator/api/java/exceptions/FailMessageException.java b/csv-validator-java-api/src/main/java/uk/gov/nationalarchives/csv/validator/api/java/exceptions/FailMessageException.java new file mode 100644 index 00000000..a0cf2bf5 --- /dev/null +++ b/csv-validator-java-api/src/main/java/uk/gov/nationalarchives/csv/validator/api/java/exceptions/FailMessageException.java @@ -0,0 +1,22 @@ +/** + * Copyright (c) 2013, The National Archives + * http://www.nationalarchives.gov.uk + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package uk.gov.nationalarchives.csv.validator.api.java.exceptions; +/** + * FailMessage Exception (failure) + */ +public class FailMessageException extends Throwable{ + + private static final long serialVersionUID = 1L; + /** + * @param message The failure message + */ + public FailMessageException(String message) { + super(message); + } +} diff --git a/csv-validator-java-api/src/main/java/uk/gov/nationalarchives/csv/validator/api/java/exceptions/ResourceBundleException.java b/csv-validator-java-api/src/main/java/uk/gov/nationalarchives/csv/validator/api/java/exceptions/ResourceBundleException.java new file mode 100644 index 00000000..b5ade69c --- /dev/null +++ b/csv-validator-java-api/src/main/java/uk/gov/nationalarchives/csv/validator/api/java/exceptions/ResourceBundleException.java @@ -0,0 +1,22 @@ +/** + * Copyright (c) 2013, The National Archives + * http://www.nationalarchives.gov.uk + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package uk.gov.nationalarchives.csv.validator.api.java.exceptions; +/** + * ResourceBundle Exception (failure) + */ +public class ResourceBundleException extends Throwable{ + + private static final long serialVersionUID = 1L; + /** + * @param message The failure message + */ + public ResourceBundleException(String message) { + super(message); + } +} diff --git a/csv-validator-java-api/src/main/scala/uk/gov/nationalarchives/csv/validator/api/java/CsvValidatorJavaBridge.scala b/csv-validator-java-api/src/main/scala/uk/gov/nationalarchives/csv/validator/api/java/CsvValidatorJavaBridge.scala index 925970a6..a8917a7a 100644 --- a/csv-validator-java-api/src/main/scala/uk/gov/nationalarchives/csv/validator/api/java/CsvValidatorJavaBridge.scala +++ b/csv-validator-java-api/src/main/scala/uk/gov/nationalarchives/csv/validator/api/java/CsvValidatorJavaBridge.scala @@ -107,8 +107,8 @@ object CsvValidatorJavaBridge { } private def asJavaMessage(f: SFailMessage): FailMessage = f match { - case SFailMessage(ValidationWarning, msg, lineNr, columnIdx) => new WarningMessage(msg, lineNr.getOrElse(-1), columnIdx.getOrElse(-1)).asInstanceOf[FailMessage] - case SFailMessage(ValidationError, msg, lineNr, columnIdx) => new ErrorMessage(msg, lineNr.getOrElse(-1), columnIdx.getOrElse(-1)).asInstanceOf[FailMessage] - case SFailMessage(SchemaDefinitionError, msg, lineNr, columnIdx) => new ErrorMessage(msg, lineNr.getOrElse(-1), columnIdx.getOrElse(-1)).asInstanceOf[FailMessage] + case SFailMessage(ValidationWarning, msg, lineNr, columnIdx, resrcTag) => new WarningMessage(msg, lineNr.getOrElse(-1), columnIdx.getOrElse(-1),resrcTag.getOrElse("general.tag")).asInstanceOf[FailMessage] + case SFailMessage(ValidationError, msg, lineNr, columnIdx, resrcTag) => new ErrorMessage(msg, lineNr.getOrElse(-1), columnIdx.getOrElse(-1),resrcTag.getOrElse("general.tag")).asInstanceOf[FailMessage] + case SFailMessage(SchemaDefinitionError, msg, lineNr, columnIdx, resrcTag) => new ErrorMessage(msg, lineNr.getOrElse(-1), columnIdx.getOrElse(-1),resrcTag.getOrElse("general.tag")).asInstanceOf[FailMessage] } } \ No newline at end of file diff --git a/csv-validator-parent/.project b/csv-validator-parent/.project new file mode 100644 index 00000000..49c2049f --- /dev/null +++ b/csv-validator-parent/.project @@ -0,0 +1,17 @@ + + + csv-validator-parent + + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + + diff --git a/csv-validator-parent/.settings/org.eclipse.core.resources.prefs b/csv-validator-parent/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 00000000..99f26c02 --- /dev/null +++ b/csv-validator-parent/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/csv-validator-parent/.settings/org.eclipse.m2e.core.prefs b/csv-validator-parent/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 00000000..f897a7f1 --- /dev/null +++ b/csv-validator-parent/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/csv-validator-parent/pom.xml b/csv-validator-parent/pom.xml index 6480847e..7f2f6bc2 100644 --- a/csv-validator-parent/pom.xml +++ b/csv-validator-parent/pom.xml @@ -11,7 +11,7 @@ uk.gov.nationalarchives csv-validator-parent - 1.2-RC3-SNAPSHOT + 1.2.1 pom csv-validator-parent @@ -63,6 +63,9 @@ Eric Torreborre + + Kenad Araujo + @@ -85,7 +88,7 @@ 2.11.12 7.2.30 3.7.1 - 1.7 + 8 UTF-8 digitalpreservation@nationalarchives.gov.uk diff --git a/csv-validator-ui/.project b/csv-validator-ui/.project new file mode 100644 index 00000000..83ed2ada --- /dev/null +++ b/csv-validator-ui/.project @@ -0,0 +1,17 @@ + + + csv-validator-ui + + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + + diff --git a/csv-validator-ui/.settings/org.eclipse.m2e.core.prefs b/csv-validator-ui/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 00000000..f897a7f1 --- /dev/null +++ b/csv-validator-ui/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1