use of com.helger.phive.api.IValidationType in project phive by phax.
the class PhiveJsonHelper method getAsValidationResultList.
/**
* Try to parse a JSON structure and convert it back to a
* {@link ValidationResultList}.
*
* @param aJson
* The JSON to be read. May be <code>null</code>.
* @param aValidationTypeResolver
* The validation type resolver to be used. May not be
* <code>null</code>.
* @return <code>null</code> in case reverse operation fails.
*/
@Nullable
public static ValidationResultList getAsValidationResultList(@Nullable final IJsonObject aJson, @Nonnull final Function<String, IValidationType> aValidationTypeResolver) {
ValueEnforcer.notNull(aValidationTypeResolver, "ValidationTypeResolver");
if (aJson == null)
return null;
final IJsonArray aResults = aJson.getAsArray(JSON_RESULTS);
if (aResults == null)
return null;
final ValidationResultList ret = new ValidationResultList();
for (final IJson aResult : aResults) {
final IJsonObject aResultObj = aResult.getAsObject();
if (aResultObj != null) {
final String sSuccess = aResultObj.getAsString(JSON_SUCCESS);
final ETriState eSuccess = getAsTriState(sSuccess);
if (eSuccess == null) {
if (LOGGER.isDebugEnabled())
LOGGER.debug("Failed to resolve TriState '" + sSuccess + "'");
continue;
}
final String sValidationType = aResultObj.getAsString(JSON_ARTIFACT_TYPE);
final IValidationType aValidationType = aValidationTypeResolver.apply(sValidationType);
if (aValidationType == null) {
if (LOGGER.isDebugEnabled())
LOGGER.debug("Failed to resolve ValidationType '" + sValidationType + "'");
continue;
}
final String sArtefactPathType = aResultObj.getAsString(JSON_ARTIFACT_PATH_TYPE);
final String sArtefactPath = aResultObj.getAsString(JSON_ARTIFACT_PATH);
final IReadableResource aRes = getAsValidationResource(sArtefactPathType, sArtefactPath);
if (aRes == null) {
if (LOGGER.isDebugEnabled())
LOGGER.debug("Failed to resolve ValidationArtefact '" + sArtefactPathType + "' with path '" + sArtefactPath + "'");
continue;
}
final ValidationArtefact aVA = new ValidationArtefact(aValidationType, aRes);
if (eSuccess.isUndefined()) {
// Ignored level
ret.add(ValidationResult.createIgnoredResult(aVA));
} else {
// We have results
final IJsonArray aItems = aResultObj.getAsArray(JSON_ITEMS);
final ErrorList aErrorList = new ErrorList();
for (final IJson aItem : aItems) {
final IJsonObject aItemObj = aItem.getAsObject();
if (aItemObj != null) {
final IError aError = getAsIError(aItemObj);
aErrorList.add(aError);
}
}
final ValidationResult aVR = new ValidationResult(aVA, aErrorList);
ret.add(aVR);
}
}
}
return ret;
}
use of com.helger.phive.api.IValidationType in project phive by phax.
the class ValidationExecutorSchematron method _createSchematronResource.
@Nonnull
private AbstractSchematronResource _createSchematronResource(@Nullable final Locale aLocale, @Nonnull final ErrorList aErrorList, @Nonnull final Consumer<ESchematronOutput> aSpecialOutputHdl) {
final IValidationArtefact aArtefact = getValidationArtefact();
// get the Schematron resource to be used for this validation artefact
final IReadableResource aSCHRes = aArtefact.getRuleResource();
final IValidationType aVT = aArtefact.getValidationArtefactType();
if (aVT == EValidationType.SCHEMATRON_PURE) {
final SchematronResourcePure aPureSCH = new SchematronResourcePure(aSCHRes);
aPureSCH.setErrorHandler(new WrappedCollectingPSErrorHandler(aErrorList));
// consecutive calls!
return aPureSCH;
}
if (aVT == EValidationType.SCHEMATRON_SCH) {
final SchematronResourceSCH aSCHSCH = new SchematronResourceSCH(aSCHRes);
aSCHSCH.setErrorListener(new WrappedCollectingTransformErrorListener(aErrorList));
if (aLocale != null && StringHelper.hasText(aLocale.getLanguage()))
aSCHSCH.setLanguageCode(aLocale.getLanguage());
return aSCHSCH;
}
if (aVT == EValidationType.SCHEMATRON_SCHXSLT) {
final SchematronResourceSchXslt_XSLT2 aSCHSCH = new SchematronResourceSchXslt_XSLT2(aSCHRes);
aSCHSCH.setErrorListener(new WrappedCollectingTransformErrorListener(aErrorList));
if (aLocale != null && StringHelper.hasText(aLocale.getLanguage()))
aSCHSCH.setLanguageCode(aLocale.getLanguage());
return aSCHSCH;
}
if (aVT == EValidationType.SCHEMATRON_XSLT) {
final SchematronResourceXSLT aSCHXSLT = new SchematronResourceXSLT(aSCHRes);
aSCHXSLT.setErrorListener(new WrappedCollectingTransformErrorListener(aErrorList));
return aSCHXSLT;
}
if (aVT == EValidationType.SCHEMATRON_OIOUBL) {
final SchematronResourceXSLT aSCHXSLT = new SchematronResourceXSLT(aSCHRes);
aSCHXSLT.setErrorListener(new WrappedCollectingTransformErrorListener(aErrorList));
// Special output layout
aSpecialOutputHdl.accept(ESchematronOutput.OIOUBL);
return aSCHXSLT;
}
throw new IllegalStateException("Unsupported Schematron validation type: " + aVT);
}
Aggregations