Search in sources :

Example 36 with DataSet

use of org.hisp.dhis.dataset.DataSet 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 37 with DataSet

use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.

the class DataIntegrityServiceTest method testGetDataElementsAssignedToDataSetsWithDifferentPeriodTypeNoResult.

@Test
void testGetDataElementsAssignedToDataSetsWithDifferentPeriodTypeNoResult() {
    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));
    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));
    when(dataElementService.getAllDataElements()).thenReturn(new ArrayList<>(dataElements.values()));
    when(dataSetService.getAllDataSets()).thenReturn(newArrayList(dataSet1, dataSet2));
    assertTrue(subject.getDataElementsAssignedToDataSetsWithDifferentPeriodTypes().isEmpty());
}
Also used : DhisConvenienceTest.createProgramRuleVariableWithDataElement(org.hisp.dhis.DhisConvenienceTest.createProgramRuleVariableWithDataElement) DhisConvenienceTest.createDataElement(org.hisp.dhis.DhisConvenienceTest.createDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) 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 38 with DataSet

use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.

the class OrgUnitMergeServiceTest method testMerge.

@Test
void testMerge() {
    DataSet dsA = createDataSet('A', ptA);
    dsA.addOrganisationUnit(ouA);
    dsA.addOrganisationUnit(ouB);
    DataSet dsB = createDataSet('B', ptA);
    dsB.addOrganisationUnit(ouA);
    idObjectManager.save(dsA);
    idObjectManager.save(dsB);
    OrganisationUnitGroup ougA = createOrganisationUnitGroup('A');
    ougA.addOrganisationUnit(ouA);
    ougA.addOrganisationUnit(ouB);
    OrganisationUnitGroup ougB = createOrganisationUnitGroup('B');
    ougB.addOrganisationUnit(ouA);
    idObjectManager.save(ougA);
    idObjectManager.save(ougB);
    assertNotNull(idObjectManager.get(OrganisationUnit.class, ouA.getUid()));
    assertNotNull(idObjectManager.get(OrganisationUnit.class, ouB.getUid()));
    assertNotNull(idObjectManager.get(OrganisationUnit.class, ouC.getUid()));
    assertEquals(2, ouA.getDataSets().size());
    assertEquals(1, ouB.getDataSets().size());
    assertEquals(0, ouC.getDataSets().size());
    OrgUnitMergeRequest request = new OrgUnitMergeRequest.Builder().addSource(ouA).addSource(ouB).withTarget(ouC).withDeleteSources(true).build();
    service.merge(request);
    assertEquals(2, ouC.getGroups().size());
    assertNull(idObjectManager.get(OrganisationUnit.class, ouA.getUid()));
    assertNull(idObjectManager.get(OrganisationUnit.class, ouB.getUid()));
    assertNotNull(idObjectManager.get(OrganisationUnit.class, ouC.getUid()));
}
Also used : OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSet(org.hisp.dhis.dataset.DataSet) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 39 with DataSet

use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.

the class MetadataOrgUnitSplitHandlerTest method testSplitDataSets.

@Test
void testSplitDataSets() {
    DataSet dsA = createDataSet('A');
    dsA.addOrganisationUnit(ouA);
    DataSet dsB = createDataSet('B');
    dsB.addOrganisationUnit(ouA);
    OrgUnitSplitRequest request = new OrgUnitSplitRequest.Builder().withSource(ouA).addTarget(ouB).addTarget(ouC).withPrimaryTarget(ouB).build();
    assertEquals(2, ouA.getDataSets().size());
    assertEquals(0, ouB.getDataSets().size());
    assertEquals(0, ouC.getDataSets().size());
    handler.splitDataSets(request);
    assertEquals(0, ouA.getDataSets().size());
    assertEquals(2, ouB.getDataSets().size());
    assertEquals(2, ouC.getDataSets().size());
}
Also used : DataSet(org.hisp.dhis.dataset.DataSet) DhisConvenienceTest.createDataSet(org.hisp.dhis.DhisConvenienceTest.createDataSet) OrgUnitSplitRequest(org.hisp.dhis.split.orgunit.OrgUnitSplitRequest) Test(org.junit.jupiter.api.Test)

Example 40 with DataSet

use of org.hisp.dhis.dataset.DataSet in project dhis2-core by dhis2.

the class DataDimensionExtractor method getBaseDimensionalItemObject.

private BaseDimensionalItemObject getBaseDimensionalItemObject(final MapMap<Class<? extends IdentifiableObject>, String, IdentifiableObject> atomicObjects, final DimensionalItemId id) {
    BaseDimensionalItemObject dimensionalItemObject = null;
    switch(id.getDimensionItemType()) {
        case DATA_ELEMENT:
            DataElement dataElement = (DataElement) atomicObjects.getValue(DataElement.class, id.getId0());
            if (dataElement != null) {
                dimensionalItemObject = cloneIfNeeded(dataElement, id);
            }
            break;
        case INDICATOR:
            final Indicator indicator = (Indicator) atomicObjects.getValue(Indicator.class, id.getId0());
            if (indicator != null) {
                dimensionalItemObject = cloneIfNeeded(indicator, id);
            }
            break;
        case DATA_ELEMENT_OPERAND:
            dataElement = (DataElement) atomicObjects.getValue(DataElement.class, id.getId0());
            final CategoryOptionCombo categoryOptionCombo = id.getId1() == null ? null : (CategoryOptionCombo) atomicObjects.getValue(CategoryOptionCombo.class, id.getId1());
            final CategoryOptionCombo attributeOptionCombo = id.getId2() == null ? null : (CategoryOptionCombo) atomicObjects.getValue(CategoryOptionCombo.class, id.getId2());
            if (dataElement != null && (id.getId1() != null) == (categoryOptionCombo != null) && (id.getId2() != null) == (attributeOptionCombo != null)) {
                dimensionalItemObject = new DataElementOperand(dataElement, categoryOptionCombo, attributeOptionCombo);
            }
            break;
        case REPORTING_RATE:
            final DataSet dataSet = (DataSet) atomicObjects.getValue(DataSet.class, id.getId0());
            if (dataSet != null) {
                dimensionalItemObject = new ReportingRate(dataSet, ReportingRateMetric.valueOf(id.getId1()));
            }
            break;
        case PROGRAM_DATA_ELEMENT:
            Program program = (Program) atomicObjects.getValue(Program.class, id.getId0());
            dataElement = (DataElement) atomicObjects.getValue(DataElement.class, id.getId1());
            if (program != null && dataElement != null) {
                dimensionalItemObject = new ProgramDataElementDimensionItem(program, dataElement);
            }
            break;
        case PROGRAM_ATTRIBUTE:
            program = (Program) atomicObjects.getValue(Program.class, id.getId0());
            final TrackedEntityAttribute attribute = (TrackedEntityAttribute) atomicObjects.getValue(TrackedEntityAttribute.class, id.getId1());
            if (program != null && attribute != null) {
                dimensionalItemObject = new ProgramTrackedEntityAttributeDimensionItem(program, attribute);
            }
            break;
        case PROGRAM_INDICATOR:
            final ProgramIndicator programIndicator = (ProgramIndicator) atomicObjects.getValue(ProgramIndicator.class, id.getId0());
            if (programIndicator != null) {
                dimensionalItemObject = cloneIfNeeded(programIndicator, id);
            }
            break;
        default:
            log.warn("Unrecognized DimensionItemType " + id.getDimensionItemType().name() + " in getItemObjectMap");
            break;
    }
    return dimensionalItemObject;
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) Program(org.hisp.dhis.program.Program) ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem) DataSet(org.hisp.dhis.dataset.DataSet) ReportingRate(org.hisp.dhis.common.ReportingRate) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) ProgramTrackedEntityAttributeDimensionItem(org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Indicator(org.hisp.dhis.indicator.Indicator) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) BaseDimensionalItemObject(org.hisp.dhis.common.BaseDimensionalItemObject)

Aggregations

DataSet (org.hisp.dhis.dataset.DataSet)199 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)82 Test (org.junit.jupiter.api.Test)69 DataElement (org.hisp.dhis.dataelement.DataElement)58 Period (org.hisp.dhis.period.Period)56 ArrayList (java.util.ArrayList)41 List (java.util.List)40 User (org.hisp.dhis.user.User)38 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)32 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)28 ClassPathResource (org.springframework.core.io.ClassPathResource)28 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)22 HashSet (java.util.HashSet)20 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)20 CategoryCombo (org.hisp.dhis.category.CategoryCombo)19 HashMap (java.util.HashMap)17 DhisSpringTest (org.hisp.dhis.DhisSpringTest)17 MonthlyPeriodType (org.hisp.dhis.period.MonthlyPeriodType)17 ReportingRate (org.hisp.dhis.common.ReportingRate)16 Section (org.hisp.dhis.dataset.Section)16