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));
}
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());
}
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));
}
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;
}
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;
}
Aggregations