Class TLcdValidationResult
A TLcdValidationResult
is used to contain the result of a validation operation.
It contain the severity of the validation result (see TLcdValidationResult.Severity
) and the corresponding warning and error messages.
The benefit of using this class is that is collects all warnings and errors, instead of relying on a single message as a result.
Usage:
public TLcdValidationResult validateModelMetaDataForWcsService(TLcdModelMetadata aModelMetadata) {
TLcdValidationResult validationResult = TLcdValidationResult.ok();
if (!aModelMetadata.getDataSource().isPresent()) {
validationResult.addError("The model metadata is empty");
}
if (!aModelMetadata.getDataCategories().contains(TLcdModelMetadata.DataCategory.RASTER)) {
validationResult.addError("The model metadata does not contain raster data.");
}
if (aModelMetadata.getDataCategories().size() > 1) {
validationResult.addError("The model metadata contains mixed data. Only metadata containing nothing but raster data is supported.");
}
List<? extends ILcdDimension<?>> dimensions = aModelMetadata.getDimensions();
if (dimensions.size() > 1
|| (dimensions.size() == 1 && dimensions.get(0).getValues().size() > 1)) {
validationResult.addWarning("The model metadata contains data with multiple dimensions and values. "
+ "This is not supported and only the first dimension value will be used.");
}
return validationResult;
}
- Since:
- 2021.0
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Describes the different severity levels of a validation result. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAll
(TLcdValidationResult aValidationResult) Adds all warnings and errors fromaValidationResult
to this validation result.void
Adds an error message to this validation result.void
addWarning
(String aMessage) Adds a warning message to this validation result.boolean
static TLcdValidationResult
Creates a new validation result object with an error associated to it.Returns the list of error messages associated with this validation result.Returns the severity of this validation result.Returns the list of warning messages associated with this validation result.int
hashCode()
merge
(TLcdValidationResult aValidationResult) Merges this validation result with another validation result.static TLcdValidationResult
ok()
Creates a new validation result object without any warnings or errors associated to it.toString()
static TLcdValidationResult
Creates a new validation result object with a warning associated to it.
-
Method Details
-
ok
Creates a new validation result object without any warnings or errors associated to it. The severity of the created validation result isTLcdValidationResult.Severity.OK
.- Returns:
- a new validation result with severity ok.
-
warning
Creates a new validation result object with a warning associated to it. The severity of the created validation result isTLcdValidationResult.Severity.WARNING
.- Parameters:
aWarningMessage
- the warning message to associate with the new validation result- Returns:
- a new validation result with a warning associated with it.
-
error
Creates a new validation result object with an error associated to it. The severity of the created validation result isTLcdValidationResult.Severity.ERROR
.- Parameters:
aErrorMessage
- the error message to associate with the new validation result- Returns:
- a new validation result with an error associated with it.
-
getSeverity
Returns the severity of this validation result. This can be used to determine if any warning or errors were discovered during validation.- Returns:
- severity of the validation result
- See Also:
-
addWarning
Adds a warning message to this validation result. The warning message cannot be null. If the current severity isTLcdValidationResult.Severity.OK
, it will be updated toTLcdValidationResult.Severity.WARNING
.- Parameters:
aMessage
- the warning message to add
-
getWarningMessages
Returns the list of warning messages associated with this validation result. This list is not modifiable, useaddWarning(String)
instead. If the current severity isTLcdValidationResult.Severity.OK
, the list will be empty.- Returns:
- the list of warning messages associated with this validation result
-
addError
Adds an error message to this validation result. The error message cannot be null. If the current severity isTLcdValidationResult.Severity.OK
orTLcdValidationResult.Severity.WARNING
, it will be updated toTLcdValidationResult.Severity.ERROR
.- Parameters:
aMessage
- the error message to add
-
getErrorMessages
Returns the list of error messages associated with this validation result. This list is not modifiable, useaddError(String)
instead. If the current severity isTLcdValidationResult.Severity.OK
orTLcdValidationResult.Severity.WARNING
, the list will be empty.- Returns:
- the list of error messages associated with this validation result
-
addAll
Adds all warnings and errors from
aValidationResult
to this validation result.The severity of this validation result is updated if the severity of
aValidationResult
is more severe than this validation result. For example, adding all messages from a validation result with severityTLcdValidationResult.Severity.ERROR
to a validation result with severityTLcdValidationResult.Severity.WARNING
will result in the severity of the validation result being updated fromTLcdValidationResult.Severity.WARNING
toTLcdValidationResult.Severity.ERROR
.- Parameters:
aValidationResult
- the validation result to add warnings and errors from
-
merge
Merges this validation result with another validation result. A new validation result is returned that contains the warnings and errors from both this validation result and
aValidationResult
.The severity of the resulting merged validation result will be the most severe value of both validation results. For example, merging a validation result with severity
TLcdValidationResult.Severity.WARNING
with a validation result with severityTLcdValidationResult.Severity.ERROR
will result in a validation result with severityTLcdValidationResult.Severity.ERROR
.- Parameters:
aValidationResult
- the validation result to merge with- Returns:
- the merged validation result
-
toString
-
equals
-
hashCode
public int hashCode()
-