Search in sources :

Example 1 with ValidationResultView

use of org.hisp.dhis.webapi.webdomain.ValidationResultView in project dhis2-core by dhis2.

the class DataAnalysisController method validationResultsListToResponse.

private List<ValidationResultView> validationResultsListToResponse(List<ValidationResult> validationResults) {
    I18nFormat format = i18nManager.getI18nFormat();
    if (validationResults == null) {
        return Collections.emptyList();
    }
    List<ValidationResultView> validationResultViews = new ArrayList<>(validationResults.size());
    for (ValidationResult validationResult : validationResults) {
        ValidationResultView validationResultView = new ValidationResultView();
        ValidationRule validationRule = validationResult.getValidationRule();
        if (validationRule != null) {
            validationResultView.setValidationRuleId(validationRule.getUid());
            validationResultView.setValidationRuleDescription(validationRule.getDescription());
            validationResultView.setImportance(validationRule.getImportance().toString());
            validationResultView.setOperator(validationRule.getOperator().getMathematicalOperator());
        }
        OrganisationUnit organisationUnit = validationResult.getOrganisationUnit();
        if (organisationUnit != null) {
            validationResultView.setOrganisationUnitId(organisationUnit.getUid());
            validationResultView.setOrganisationUnitDisplayName(organisationUnit.getDisplayName());
            validationResultView.setOrganisationUnitPath(organisationUnit.getPath());
            validationResultView.setOrganisationUnitAncestorNames(organisationUnit.getAncestorNames());
        }
        Period period = validationResult.getPeriod();
        if (period != null) {
            validationResultView.setPeriodId(period.getIsoDate());
            validationResultView.setPeriodDisplayName(format.formatPeriod(period));
        }
        CategoryOptionCombo attributeOptionCombo = validationResult.getAttributeOptionCombo();
        if (attributeOptionCombo != null) {
            validationResultView.setAttributeOptionComboId(attributeOptionCombo.getUid());
            validationResultView.setAttributeOptionComboDisplayName(attributeOptionCombo.getDisplayName());
        }
        validationResultView.setLeftSideValue(validationResult.getLeftsideValue());
        validationResultView.setRightSideValue(validationResult.getRightsideValue());
        validationResultViews.add(validationResultView);
    }
    return validationResultViews;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) I18nFormat(org.hisp.dhis.i18n.I18nFormat) ValidationResultView(org.hisp.dhis.webapi.webdomain.ValidationResultView) ValidationResult(org.hisp.dhis.validation.ValidationResult) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) ValidationRule(org.hisp.dhis.validation.ValidationRule)

Aggregations

ArrayList (java.util.ArrayList)1 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)1 I18nFormat (org.hisp.dhis.i18n.I18nFormat)1 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1 Period (org.hisp.dhis.period.Period)1 ValidationResult (org.hisp.dhis.validation.ValidationResult)1 ValidationRule (org.hisp.dhis.validation.ValidationRule)1 ValidationResultView (org.hisp.dhis.webapi.webdomain.ValidationResultView)1