Search in sources :

Example 1 with DataIntegrityIssue

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

the class DataIntegrityServiceTest method testGetDataElementsAssignedToDataSetsWithDifferentPeriodType.

@Test
void testGetDataElementsAssignedToDataSetsWithDifferentPeriodType() {
    String seed = "abcde";
    Map<String, DataElement> dataElements = createRandomDataElements(6, seed);
    DataSet dataSet1 = rnd.nextObject(DataSet.class);
    dataSet1.setPeriodType(PeriodType.getPeriodTypeFromIsoString("2011"));
    dataSet1.addDataSetElement(dataElements.get(seed + 1));
    dataSet1.addDataSetElement(dataElements.get(seed + 2));
    dataSet1.addDataSetElement(dataElements.get(seed + 3));
    dataSet1.addDataSetElement(dataElements.get(seed + 4));
    DataSet dataSet2 = rnd.nextObject(DataSet.class);
    dataSet2.setPeriodType(PeriodType.getByIndex(5));
    dataSet2.addDataSetElement(dataElements.get(seed + 4));
    dataSet2.addDataSetElement(dataElements.get(seed + 5));
    dataSet2.addDataSetElement(dataElements.get(seed + 6));
    dataSet2.addDataSetElement(dataElements.get(seed + 1));
    when(dataElementService.getAllDataElements()).thenReturn(List.copyOf(dataElements.values()));
    when(dataSetService.getAllDataSets()).thenReturn(List.of(dataSet1, dataSet2));
    List<DataIntegrityIssue> result = subject.getDataElementsAssignedToDataSetsWithDifferentPeriodTypes();
    assertEquals(2, result.size());
    DataIntegrityIssue issue0 = result.get(0);
    assertEquals(seed + 1, issue0.getId());
    assertContainsOnly(issue0.getRefs(), issueName(dataSet1), issueName(dataSet2));
    DataIntegrityIssue issue1 = result.get(1);
    assertEquals(seed + 4, issue1.getId());
    assertContainsOnly(issue1.getRefs(), issueName(dataSet1), issueName(dataSet2));
}
Also used : DhisConvenienceTest.createProgramRuleVariableWithDataElement(org.hisp.dhis.DhisConvenienceTest.createProgramRuleVariableWithDataElement) DhisConvenienceTest.createDataElement(org.hisp.dhis.DhisConvenienceTest.createDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) DataIntegrityIssue(org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue) DhisConvenienceTest.createDataSet(org.hisp.dhis.DhisConvenienceTest.createDataSet) DataSet(org.hisp.dhis.dataset.DataSet) Mockito.anyString(org.mockito.Mockito.anyString) Test(org.junit.jupiter.api.Test)

Example 2 with DataIntegrityIssue

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

the class DataIntegrityServiceTest method testInvalidProgramIndicatorExpression.

@Test
void testInvalidProgramIndicatorExpression() {
    ProgramIndicator programIndicator = new ProgramIndicator();
    programIndicator.setName("Test-PI");
    programIndicator.setExpression("A{someuid} + 1");
    when(programIndicatorService.expressionIsValid(anyString())).thenReturn(false);
    when(programIndicatorService.getAllProgramIndicators()).thenReturn(List.of(programIndicator));
    when(expressionService.getExpressionDescription(anyString(), any())).thenThrow(new ParserException(INVALID_EXPRESSION));
    List<DataIntegrityIssue> issues = subject.getInvalidProgramIndicatorExpressions();
    assertNotNull(issues);
    assertEquals(1, issues.size());
    DataIntegrityIssue issue = issues.get(0);
    assertEquals(issueName(programIndicator), issue.getName());
    assertEquals(INVALID_EXPRESSION, issue.getComment());
}
Also used : ParserException(org.hisp.dhis.antlr.ParserException) DataIntegrityIssue(org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Test(org.junit.jupiter.api.Test)

Example 3 with DataIntegrityIssue

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

the class DataIntegrityServiceTest method testGetProgramRuleActionsWithNoDataObject.

@Test
void testGetProgramRuleActionsWithNoDataObject() {
    programRuleActionA.setProgramRule(programRuleA);
    when(programRuleActionService.getProgramActionsWithNoLinkToDataObject()).thenReturn(List.of(programRuleActionA));
    List<DataIntegrityIssue> issues = subject.getProgramRuleActionsWithNoDataObject();
    verify(programRuleActionService).getProgramActionsWithNoLinkToDataObject();
    verify(programRuleActionService, times(1)).getProgramActionsWithNoLinkToDataObject();
    assertEquals(1, issues.size());
    DataIntegrityIssue issue = issues.get(0);
    assertEquals(issueName(programRuleA), issue.getName());
    assertContainsOnly(issue.getRefs(), issueName(programRuleActionA));
}
Also used : DataIntegrityIssue(org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue) Test(org.junit.jupiter.api.Test)

Example 4 with DataIntegrityIssue

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

the class DefaultDataIntegrityService method getDataElementsAssignedToDataSetsWithDifferentPeriodTypes.

/**
 * Returns all data elements which are members of data sets with different
 * period types.
 */
List<DataIntegrityIssue> getDataElementsAssignedToDataSetsWithDifferentPeriodTypes() {
    Collection<DataElement> dataElements = dataElementService.getAllDataElements();
    Collection<DataSet> dataSets = dataSetService.getAllDataSets();
    List<DataIntegrityIssue> issues = new ArrayList<>();
    for (DataElement element : dataElements) {
        final Set<PeriodType> targetPeriodTypes = new HashSet<>();
        final List<DataSet> targetDataSets = new ArrayList<>();
        for (DataSet dataSet : dataSets) {
            if (dataSet.getDataElements().contains(element)) {
                targetPeriodTypes.add(dataSet.getPeriodType());
                targetDataSets.add(dataSet);
            }
        }
        if (targetPeriodTypes.size() > 1) {
            issues.add(DataIntegrityIssue.toIssue(element, targetDataSets));
        }
    }
    return issues;
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataIntegrityIssue(org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue) PeriodType(org.hisp.dhis.period.PeriodType) DataSet(org.hisp.dhis.dataset.DataSet) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 5 with DataIntegrityIssue

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

the class DefaultDataIntegrityService method getDataElementsInDataSetNotInForm.

/**
 * Returns all data elements which are member of a data set but not part of
 * either the custom form or sections of the data set.
 */
List<DataIntegrityIssue> getDataElementsInDataSetNotInForm() {
    List<DataIntegrityIssue> issues = new ArrayList<>();
    Collection<DataSet> dataSets = dataSetService.getAllDataSets();
    for (DataSet dataSet : dataSets) {
        if (!dataSet.getFormType().isDefault()) {
            Set<DataElement> formElements = new HashSet<>();
            if (dataSet.hasDataEntryForm()) {
                formElements.addAll(dataEntryFormService.getDataElementsInDataEntryForm(dataSet));
            } else if (dataSet.hasSections()) {
                formElements.addAll(dataSet.getDataElementsInSections());
            }
            Set<DataElement> dataSetElements = new HashSet<>(dataSet.getDataElements());
            dataSetElements.removeAll(formElements);
            if (!dataSetElements.isEmpty()) {
                issues.add(DataIntegrityIssue.toIssue(dataSet, dataSetElements));
            }
        }
    }
    return issues;
}
Also used : DataIntegrityIssue(org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue) DataElement(org.hisp.dhis.dataelement.DataElement) DataSet(org.hisp.dhis.dataset.DataSet) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

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