Skip to content

Commit

Permalink
AER-1036 log validation errors as debug since message is rethrown aga…
Browse files Browse the repository at this point in the history
…in and later logged if needd. (#236)
  • Loading branch information
Hilbrand authored Jan 8, 2024
1 parent b6a7f44 commit e8d1b14
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
*/
public final class GMLReaderFactory {
private static final Logger LOG = LoggerFactory.getLogger(GMLReaderFactory.class);
private static final Pattern PARSE_ERROR_PATTERN_1 = Pattern.compile("ParseError at \\[row,col\\]:\\[(\\d+),(\\d+)\\]");
private static final Pattern PARSE_ERROR_PATTERN_2 = Pattern.compile("The element type \"([^\"]+)\"[^\"]+\"([^\"]+)");
private static final XMLInputFactory XMLINPUT_FACTORY = SafeXMLInputFactory.newFactory();
private static final Object FACTORY_LOCK = new Object();
private static GMLReaderFactory instance;
Expand Down Expand Up @@ -114,15 +116,15 @@ public ValidationHelper createValidationHelper() {
return gmlHelper.getValidationHelper();
}

private void checkEvents(final List<ValidationEvent> events) throws AeriusException {
private static void checkEvents(final List<ValidationEvent> events) throws AeriusException {
// information like required elements not being present will not throw an exception, but will trigger an event.
// check for these events and throw exception if present.
if ((events != null) && !events.isEmpty()) {
throw newValidationFailed(events);
}
}

private FeatureCollection convertToCollection(final XMLStreamReader xmlStreamReader, final GMLVersionReaderFactory factory,
private static FeatureCollection convertToCollection(final XMLStreamReader xmlStreamReader, final GMLVersionReaderFactory factory,
final CustomValidationEventCollector vec, final boolean validate) throws AeriusException {
FeatureCollection collection = null;
try {
Expand All @@ -141,7 +143,7 @@ private FeatureCollection convertToCollection(final XMLStreamReader xmlStreamRea
return collection;
}

private void processException(final CustomValidationEventCollector vec, final JAXBException e) throws AeriusException {
private static void processException(final CustomValidationEventCollector vec, final JAXBException e) throws AeriusException {
if ((e.getLinkedException() instanceof UTFDataFormatException) || (e.getLinkedException() instanceof UnsupportedEncodingException)) {
throw new AeriusException(ImaerExceptionReason.GML_ENCODING_INCORRECT);
} else if (e.getLinkedException() instanceof XMLStreamException) {
Expand All @@ -152,11 +154,9 @@ private void processException(final CustomValidationEventCollector vec, final JA
}
}

private AeriusException newGmlParseError(final XMLStreamException e) {
final Pattern pattern1 = Pattern.compile("ParseError at \\[row,col\\]:\\[(\\d+),(\\d+)\\]");
final Pattern pattern2 = Pattern.compile("The element type \"([^\"]+)\"[^\"]+\"([^\"]+)");
final Matcher matcher1 = pattern1.matcher(e.getMessage());
final Matcher matcher2 = pattern2.matcher(e.getMessage());
private static AeriusException newGmlParseError(final XMLStreamException e) {
final Matcher matcher1 = PARSE_ERROR_PATTERN_1.matcher(e.getMessage());
final Matcher matcher2 = PARSE_ERROR_PATTERN_2.matcher(e.getMessage());
if (matcher1.find() && matcher2.find()) {
return new AeriusException(ImaerExceptionReason.GML_PARSE_ERROR, matcher1.group(1), matcher1.group(2), matcher2.group(1), matcher2.group(2));
} else {
Expand All @@ -165,13 +165,13 @@ private AeriusException newGmlParseError(final XMLStreamException e) {
}
}

private AeriusException newValidationFailed(final List<ValidationEvent> list) {
private static AeriusException newValidationFailed(final List<ValidationEvent> list) {
final StringBuilder errorLine = new StringBuilder();
for (final ValidationEvent event : list) {
errorLine.append(event.getMessage());
errorLine.append(' ');
}
LOG.error("validation error: {}", errorLine);
LOG.debug("validation error: {}", errorLine);
return new AeriusException(ImaerExceptionReason.GML_VALIDATION_FAILED, errorLine.toString().trim());
}
}

0 comments on commit e8d1b14

Please sign in to comment.