Search in sources :

Example 6 with DataIntegrityIssue

use of org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue in project dhis2-core by dhis2.

the class DefaultDataIntegrityService method getInvalidIndicators.

private List<DataIntegrityIssue> getInvalidIndicators(Function<Indicator, String> getter) {
    List<DataIntegrityIssue> issues = new ArrayList<>();
    I18n i18n = i18nManager.getI18n();
    for (Indicator indicator : indicatorService.getAllIndicators()) {
        ExpressionValidationOutcome result = expressionService.expressionIsValid(getter.apply(indicator), INDICATOR_EXPRESSION);
        if (!result.isValid()) {
            issues.add(toIssue(indicator, i18n.getString(result.getKey())));
        }
    }
    return issues;
}
Also used : DataIntegrityIssue(org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue) ExpressionValidationOutcome(org.hisp.dhis.expression.ExpressionValidationOutcome) ArrayList(java.util.ArrayList) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Indicator(org.hisp.dhis.indicator.Indicator) I18n(org.hisp.dhis.i18n.I18n)

Example 7 with DataIntegrityIssue

use of org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue in project dhis2-core by dhis2.

the class DefaultDataIntegrityService method registerNonDatabaseIntegrityCheck.

private void registerNonDatabaseIntegrityCheck(DataIntegrityCheckType type, Supplier<List<DataIntegrityIssue>> check) {
    String name = type.getName();
    checksByName.put(name, DataIntegrityCheck.builder().name(name).severity(DataIntegritySeverity.WARNING).section("Legacy").description(name.replace('_', ' ')).runDetailsCheck(c -> new DataIntegrityDetails(c, new Date(), null, check.get())).runSummaryCheck(c -> new DataIntegritySummary(c, new Date(), null, check.get().size(), null)).build());
}
Also used : ProgramRuleVariableService(org.hisp.dhis.programrule.ProgramRuleVariableService) Arrays(java.util.Arrays) CategoryService(org.hisp.dhis.category.CategoryService) Date(java.util.Date) BiFunction(java.util.function.BiFunction) PeriodService(org.hisp.dhis.period.PeriodService) RequiredArgsConstructor(lombok.RequiredArgsConstructor) OrganisationUnitService(org.hisp.dhis.organisationunit.OrganisationUnitService) DataIntegrityIssue.toRefsList(org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue.toRefsList) Collections.unmodifiableCollection(java.util.Collections.unmodifiableCollection) DataIntegrityIssue(org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue) ValidationRuleService(org.hisp.dhis.validation.ValidationRuleService) Map(java.util.Map) INDICATOR_EXPRESSION(org.hisp.dhis.expression.ParseType.INDICATOR_EXPRESSION) ExpressionValidationOutcome(org.hisp.dhis.expression.ExpressionValidationOutcome) Period(org.hisp.dhis.period.Period) OrganisationUnitGroupService(org.hisp.dhis.organisationunit.OrganisationUnitGroupService) Predicate(java.util.function.Predicate) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Objects(java.util.Objects) ProgramRule(org.hisp.dhis.programrule.ProgramRule) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) ProgramRuleService(org.hisp.dhis.programrule.ProgramRuleService) Cache(org.hisp.dhis.cache.Cache) Entry(java.util.Map.Entry) PostConstruct(javax.annotation.PostConstruct) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) ProgramIndicatorService(org.hisp.dhis.program.ProgramIndicatorService) System.currentTimeMillis(java.lang.System.currentTimeMillis) DataElementService(org.hisp.dhis.dataelement.DataElementService) DataSet(org.hisp.dhis.dataset.DataSet) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ProgramRuleVariable(org.hisp.dhis.programrule.ProgramRuleVariable) Collectors.toUnmodifiableSet(java.util.stream.Collectors.toUnmodifiableSet) I18n(org.hisp.dhis.i18n.I18n) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ProgramRuleAction(org.hisp.dhis.programrule.ProgramRuleAction) Program(org.hisp.dhis.program.Program) Collectors.toUnmodifiableList(java.util.stream.Collectors.toUnmodifiableList) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) DataElement(org.hisp.dhis.dataelement.DataElement) ExpressionService(org.hisp.dhis.expression.ExpressionService) DataIntegrityIssue.toIssue(org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue.toIssue) Service(org.springframework.stereotype.Service) ListUtils.getDuplicates(org.hisp.dhis.commons.collection.ListUtils.getDuplicates) Indicator(org.hisp.dhis.indicator.Indicator) DataElementGroupSet(org.hisp.dhis.dataelement.DataElementGroupSet) VALIDATION_RULE_EXPRESSION(org.hisp.dhis.expression.ParseType.VALIDATION_RULE_EXPRESSION) I18nManager(org.hisp.dhis.i18n.I18nManager) LinkedHashSet(java.util.LinkedHashSet) ProgramRuleActionService(org.hisp.dhis.programrule.ProgramRuleActionService) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) DataIntegrityYamlReader.readDataIntegrityYaml(org.hisp.dhis.dataintegrity.DataIntegrityYamlReader.readDataIntegrityYaml) ValidationRule(org.hisp.dhis.validation.ValidationRule) DataEntryFormService(org.hisp.dhis.dataentryform.DataEntryFormService) JobProgress(org.hisp.dhis.scheduling.JobProgress) CacheProvider(org.hisp.dhis.cache.CacheProvider) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Collectors.toList(java.util.stream.Collectors.toList) IndicatorService(org.hisp.dhis.indicator.IndicatorService) Collections.unmodifiableSet(java.util.Collections.unmodifiableSet) ParserException(org.hisp.dhis.antlr.ParserException) PeriodType(org.hisp.dhis.period.PeriodType) DataSetService(org.hisp.dhis.dataset.DataSetService) Expression(org.hisp.dhis.expression.Expression) IndicatorGroupSet(org.hisp.dhis.indicator.IndicatorGroupSet) Transactional(org.springframework.transaction.annotation.Transactional) Date(java.util.Date)

Example 8 with DataIntegrityIssue

use of org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue in project dhis2-core by dhis2.

the class DefaultDataIntegrityService method getInvalidValidationRuleExpressions.

private List<DataIntegrityIssue> getInvalidValidationRuleExpressions(Function<ValidationRule, Expression> getter) {
    List<DataIntegrityIssue> issues = new ArrayList<>();
    I18n i18n = i18nManager.getI18n();
    for (ValidationRule rule : validationRuleService.getAllValidationRules()) {
        ExpressionValidationOutcome result = expressionService.expressionIsValid(getter.apply(rule).getExpression(), VALIDATION_RULE_EXPRESSION);
        if (!result.isValid()) {
            issues.add(toIssue(rule, i18n.getString(result.getKey())));
        }
    }
    return issues;
}
Also used : DataIntegrityIssue(org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue) ExpressionValidationOutcome(org.hisp.dhis.expression.ExpressionValidationOutcome) ArrayList(java.util.ArrayList) I18n(org.hisp.dhis.i18n.I18n) ValidationRule(org.hisp.dhis.validation.ValidationRule)

Example 9 with DataIntegrityIssue

use of org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue in project dhis2-core by dhis2.

the class DefaultDataIntegrityService method getIndicatorsWithIdenticalFormulas.

// -------------------------------------------------------------------------
// Indicator
// -------------------------------------------------------------------------
/**
 * Gets all indicators with identical numerator and denominator.
 */
List<DataIntegrityIssue> getIndicatorsWithIdenticalFormulas() {
    List<DataIntegrityIssue> issues = new ArrayList<>();
    Map<String, List<Indicator>> byFormula = indicatorService.getAllIndicators().stream().collect(groupingBy(indicator -> indicator.getNumerator() + FORMULA_SEPARATOR + indicator.getDenominator()));
    for (Entry<String, List<Indicator>> e : byFormula.entrySet()) {
        if (e.getValue().size() > 1) {
            issues.add(new DataIntegrityIssue(null, e.getKey(), null, toRefsList(e.getValue().stream())));
        }
    }
    return issues;
}
Also used : ProgramRuleVariableService(org.hisp.dhis.programrule.ProgramRuleVariableService) Arrays(java.util.Arrays) CategoryService(org.hisp.dhis.category.CategoryService) Date(java.util.Date) BiFunction(java.util.function.BiFunction) PeriodService(org.hisp.dhis.period.PeriodService) RequiredArgsConstructor(lombok.RequiredArgsConstructor) OrganisationUnitService(org.hisp.dhis.organisationunit.OrganisationUnitService) DataIntegrityIssue.toRefsList(org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue.toRefsList) Collections.unmodifiableCollection(java.util.Collections.unmodifiableCollection) DataIntegrityIssue(org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue) ValidationRuleService(org.hisp.dhis.validation.ValidationRuleService) Map(java.util.Map) INDICATOR_EXPRESSION(org.hisp.dhis.expression.ParseType.INDICATOR_EXPRESSION) ExpressionValidationOutcome(org.hisp.dhis.expression.ExpressionValidationOutcome) Period(org.hisp.dhis.period.Period) OrganisationUnitGroupService(org.hisp.dhis.organisationunit.OrganisationUnitGroupService) Predicate(java.util.function.Predicate) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Objects(java.util.Objects) ProgramRule(org.hisp.dhis.programrule.ProgramRule) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) ProgramRuleService(org.hisp.dhis.programrule.ProgramRuleService) Cache(org.hisp.dhis.cache.Cache) Entry(java.util.Map.Entry) PostConstruct(javax.annotation.PostConstruct) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) ProgramIndicatorService(org.hisp.dhis.program.ProgramIndicatorService) System.currentTimeMillis(java.lang.System.currentTimeMillis) DataElementService(org.hisp.dhis.dataelement.DataElementService) DataSet(org.hisp.dhis.dataset.DataSet) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ProgramRuleVariable(org.hisp.dhis.programrule.ProgramRuleVariable) Collectors.toUnmodifiableSet(java.util.stream.Collectors.toUnmodifiableSet) I18n(org.hisp.dhis.i18n.I18n) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ProgramRuleAction(org.hisp.dhis.programrule.ProgramRuleAction) Program(org.hisp.dhis.program.Program) Collectors.toUnmodifiableList(java.util.stream.Collectors.toUnmodifiableList) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) DataElement(org.hisp.dhis.dataelement.DataElement) ExpressionService(org.hisp.dhis.expression.ExpressionService) DataIntegrityIssue.toIssue(org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue.toIssue) Service(org.springframework.stereotype.Service) ListUtils.getDuplicates(org.hisp.dhis.commons.collection.ListUtils.getDuplicates) Indicator(org.hisp.dhis.indicator.Indicator) DataElementGroupSet(org.hisp.dhis.dataelement.DataElementGroupSet) VALIDATION_RULE_EXPRESSION(org.hisp.dhis.expression.ParseType.VALIDATION_RULE_EXPRESSION) I18nManager(org.hisp.dhis.i18n.I18nManager) LinkedHashSet(java.util.LinkedHashSet) ProgramRuleActionService(org.hisp.dhis.programrule.ProgramRuleActionService) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) DataIntegrityYamlReader.readDataIntegrityYaml(org.hisp.dhis.dataintegrity.DataIntegrityYamlReader.readDataIntegrityYaml) ValidationRule(org.hisp.dhis.validation.ValidationRule) DataEntryFormService(org.hisp.dhis.dataentryform.DataEntryFormService) JobProgress(org.hisp.dhis.scheduling.JobProgress) CacheProvider(org.hisp.dhis.cache.CacheProvider) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Collectors.toList(java.util.stream.Collectors.toList) IndicatorService(org.hisp.dhis.indicator.IndicatorService) Collections.unmodifiableSet(java.util.Collections.unmodifiableSet) ParserException(org.hisp.dhis.antlr.ParserException) PeriodType(org.hisp.dhis.period.PeriodType) DataSetService(org.hisp.dhis.dataset.DataSetService) Expression(org.hisp.dhis.expression.Expression) IndicatorGroupSet(org.hisp.dhis.indicator.IndicatorGroupSet) Transactional(org.springframework.transaction.annotation.Transactional) DataIntegrityIssue(org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue) ArrayList(java.util.ArrayList) DataIntegrityIssue.toRefsList(org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue.toRefsList) List(java.util.List) Collectors.toUnmodifiableList(java.util.stream.Collectors.toUnmodifiableList) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList)

Example 10 with DataIntegrityIssue

use of org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue in project dhis2-core by dhis2.

the class DefaultDataIntegrityService method getDuplicatePeriods.

// -------------------------------------------------------------------------
// Period
// -------------------------------------------------------------------------
/**
 * Lists all Periods which are duplicates, based on the period type and
 * start date.
 */
List<DataIntegrityIssue> getDuplicatePeriods() {
    List<Period> periods = periodService.getAllPeriods();
    List<DataIntegrityIssue> issues = new ArrayList<>();
    for (Entry<String, List<Period>> group : periods.stream().collect(groupingBy(p -> p.getPeriodType().getName() + p.getStartDate().toString())).entrySet()) {
        if (group.getValue().size() > 1) {
            issues.add(new DataIntegrityIssue(null, group.getKey(), null, group.getValue().stream().map(p -> p.toString() + ":" + p.getUid()).collect(toUnmodifiableList())));
        }
    }
    return issues;
}
Also used : ProgramRuleVariableService(org.hisp.dhis.programrule.ProgramRuleVariableService) Arrays(java.util.Arrays) CategoryService(org.hisp.dhis.category.CategoryService) Date(java.util.Date) BiFunction(java.util.function.BiFunction) PeriodService(org.hisp.dhis.period.PeriodService) RequiredArgsConstructor(lombok.RequiredArgsConstructor) OrganisationUnitService(org.hisp.dhis.organisationunit.OrganisationUnitService) DataIntegrityIssue.toRefsList(org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue.toRefsList) Collections.unmodifiableCollection(java.util.Collections.unmodifiableCollection) DataIntegrityIssue(org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue) ValidationRuleService(org.hisp.dhis.validation.ValidationRuleService) Map(java.util.Map) INDICATOR_EXPRESSION(org.hisp.dhis.expression.ParseType.INDICATOR_EXPRESSION) ExpressionValidationOutcome(org.hisp.dhis.expression.ExpressionValidationOutcome) Period(org.hisp.dhis.period.Period) OrganisationUnitGroupService(org.hisp.dhis.organisationunit.OrganisationUnitGroupService) Predicate(java.util.function.Predicate) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Objects(java.util.Objects) ProgramRule(org.hisp.dhis.programrule.ProgramRule) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) ProgramRuleService(org.hisp.dhis.programrule.ProgramRuleService) Cache(org.hisp.dhis.cache.Cache) Entry(java.util.Map.Entry) PostConstruct(javax.annotation.PostConstruct) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) ProgramIndicatorService(org.hisp.dhis.program.ProgramIndicatorService) System.currentTimeMillis(java.lang.System.currentTimeMillis) DataElementService(org.hisp.dhis.dataelement.DataElementService) DataSet(org.hisp.dhis.dataset.DataSet) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ProgramRuleVariable(org.hisp.dhis.programrule.ProgramRuleVariable) Collectors.toUnmodifiableSet(java.util.stream.Collectors.toUnmodifiableSet) I18n(org.hisp.dhis.i18n.I18n) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ProgramRuleAction(org.hisp.dhis.programrule.ProgramRuleAction) Program(org.hisp.dhis.program.Program) Collectors.toUnmodifiableList(java.util.stream.Collectors.toUnmodifiableList) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) DataElement(org.hisp.dhis.dataelement.DataElement) ExpressionService(org.hisp.dhis.expression.ExpressionService) DataIntegrityIssue.toIssue(org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue.toIssue) Service(org.springframework.stereotype.Service) ListUtils.getDuplicates(org.hisp.dhis.commons.collection.ListUtils.getDuplicates) Indicator(org.hisp.dhis.indicator.Indicator) DataElementGroupSet(org.hisp.dhis.dataelement.DataElementGroupSet) VALIDATION_RULE_EXPRESSION(org.hisp.dhis.expression.ParseType.VALIDATION_RULE_EXPRESSION) I18nManager(org.hisp.dhis.i18n.I18nManager) LinkedHashSet(java.util.LinkedHashSet) ProgramRuleActionService(org.hisp.dhis.programrule.ProgramRuleActionService) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) DataIntegrityYamlReader.readDataIntegrityYaml(org.hisp.dhis.dataintegrity.DataIntegrityYamlReader.readDataIntegrityYaml) ValidationRule(org.hisp.dhis.validation.ValidationRule) DataEntryFormService(org.hisp.dhis.dataentryform.DataEntryFormService) JobProgress(org.hisp.dhis.scheduling.JobProgress) CacheProvider(org.hisp.dhis.cache.CacheProvider) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Collectors.toList(java.util.stream.Collectors.toList) IndicatorService(org.hisp.dhis.indicator.IndicatorService) Collections.unmodifiableSet(java.util.Collections.unmodifiableSet) ParserException(org.hisp.dhis.antlr.ParserException) PeriodType(org.hisp.dhis.period.PeriodType) DataSetService(org.hisp.dhis.dataset.DataSetService) Expression(org.hisp.dhis.expression.Expression) IndicatorGroupSet(org.hisp.dhis.indicator.IndicatorGroupSet) Transactional(org.springframework.transaction.annotation.Transactional) DataIntegrityIssue(org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) DataIntegrityIssue.toRefsList(org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue.toRefsList) List(java.util.List) Collectors.toUnmodifiableList(java.util.stream.Collectors.toUnmodifiableList) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList)

Aggregations

DataIntegrityIssue (org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue)18 ArrayList (java.util.ArrayList)11 ProgramIndicator (org.hisp.dhis.program.ProgramIndicator)9 Test (org.junit.jupiter.api.Test)8 DataElement (org.hisp.dhis.dataelement.DataElement)7 HashSet (java.util.HashSet)5 LinkedHashSet (java.util.LinkedHashSet)5 ParserException (org.hisp.dhis.antlr.ParserException)5 ExpressionValidationOutcome (org.hisp.dhis.expression.ExpressionValidationOutcome)5 I18n (org.hisp.dhis.i18n.I18n)5 Indicator (org.hisp.dhis.indicator.Indicator)5 Date (java.util.Date)4 DataElementGroupSet (org.hisp.dhis.dataelement.DataElementGroupSet)4 IndicatorGroupSet (org.hisp.dhis.indicator.IndicatorGroupSet)4 ValidationRule (org.hisp.dhis.validation.ValidationRule)4 System.currentTimeMillis (java.lang.System.currentTimeMillis)3 Arrays (java.util.Arrays)3 Collection (java.util.Collection)3 Collections.unmodifiableCollection (java.util.Collections.unmodifiableCollection)3 Collections.unmodifiableSet (java.util.Collections.unmodifiableSet)3