Search in sources :

Example 31 with DataSet

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

the class VersionedObjectObjectBundleHook method postTypeImport.

@Override
public <T extends IdentifiableObject> void postTypeImport(Class<T> klass, List<T> objects, ObjectBundle bundle) {
    if (Section.class.isAssignableFrom(klass)) {
        Set<DataSet> dataSets = new HashSet<>();
        objects.forEach(o -> {
            DataSet dataSet = ((Section) o).getDataSet();
            if (dataSet != null && dataSet.getId() > 0) {
                dataSets.add(dataSet);
            }
        });
        dataSets.forEach(ds -> {
            ds.increaseVersion();
            sessionFactory.getCurrentSession().save(ds);
        });
    } else if (Option.class.isAssignableFrom(klass)) {
        Set<OptionSet> optionSets = new HashSet<>();
        objects.forEach(o -> {
            Option option = (Option) o;
            if (option.getOptionSet() != null && option.getId() > 0) {
                optionSets.add(option.getOptionSet());
            }
        });
        optionSets.forEach(os -> {
            os.increaseVersion();
            sessionFactory.getCurrentSession().save(os);
        });
    }
}
Also used : HashSet(java.util.HashSet) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) List(java.util.List) Option(org.hisp.dhis.option.Option) Component(org.springframework.stereotype.Component) ObjectBundle(org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundle) OptionSet(org.hisp.dhis.option.OptionSet) VersionedObject(org.hisp.dhis.common.VersionedObject) DataSet(org.hisp.dhis.dataset.DataSet) Set(java.util.Set) Section(org.hisp.dhis.dataset.Section) HashSet(java.util.HashSet) OptionSet(org.hisp.dhis.option.OptionSet) DataSet(org.hisp.dhis.dataset.DataSet) Set(java.util.Set) DataSet(org.hisp.dhis.dataset.DataSet) Option(org.hisp.dhis.option.Option) Section(org.hisp.dhis.dataset.Section) HashSet(java.util.HashSet)

Example 32 with DataSet

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

the class MetadataOrgUnitMergeHandlerTest method testMergeDataSets.

@Test
void testMergeDataSets() {
    DataSet dsA = createDataSet('A');
    dsA.addOrganisationUnit(ouA);
    dsA.addOrganisationUnit(ouB);
    DataSet dsB = createDataSet('B');
    dsB.addOrganisationUnit(ouA);
    OrgUnitMergeRequest request = new OrgUnitMergeRequest.Builder().addSource(ouA).addSource(ouB).withTarget(ouC).build();
    assertEquals(2, ouA.getDataSets().size());
    assertEquals(1, ouB.getDataSets().size());
    assertEquals(0, ouC.getDataSets().size());
    handler.mergeDataSets(request);
    assertEquals(0, ouA.getDataSets().size());
    assertEquals(0, ouB.getDataSets().size());
    assertEquals(2, ouC.getDataSets().size());
}
Also used : DataSet(org.hisp.dhis.dataset.DataSet) DhisConvenienceTest.createDataSet(org.hisp.dhis.DhisConvenienceTest.createDataSet) OrgUnitMergeRequest(org.hisp.dhis.merge.orgunit.OrgUnitMergeRequest) Test(org.junit.jupiter.api.Test)

Example 33 with DataSet

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

the class ResourceTableServiceTest method setUpTest.

@Override
public void setUpTest() {
    PeriodType pt = new MonthlyPeriodType();
    DataElement deA = createDataElement('A');
    DataElement deB = createDataElement('B');
    idObjectManager.save(deA);
    idObjectManager.save(deB);
    DataElementGroup degA = createDataElementGroup('A');
    DataElementGroup degB = createDataElementGroup('B');
    DataElementGroup degC = createDataElementGroup('C');
    DataElementGroup degD = createDataElementGroup('D');
    degA.addDataElement(deA);
    degB.addDataElement(deB);
    idObjectManager.save(degA);
    idObjectManager.save(degB);
    idObjectManager.save(degC);
    idObjectManager.save(degD);
    DataElementGroupSet degsA = createDataElementGroupSet('A');
    DataElementGroupSet degsB = createDataElementGroupSet('B');
    degsB.setName("Data \"Element\" Group Set \"B\"");
    degsA.addDataElementGroup(degA);
    degsA.addDataElementGroup(degB);
    degsB.addDataElementGroup(degC);
    degsB.addDataElementGroup(degD);
    idObjectManager.save(degsA);
    idObjectManager.save(degsB);
    OrganisationUnit ouA = createOrganisationUnit('A');
    OrganisationUnit ouB = createOrganisationUnit('B');
    OrganisationUnit ouC = createOrganisationUnit('C');
    ouB.setParent(ouA);
    ouC.setParent(ouA);
    ouA.getChildren().add(ouB);
    ouA.getChildren().add(ouC);
    idObjectManager.save(ouA);
    idObjectManager.save(ouB);
    idObjectManager.save(ouC);
    DataSet dsA = createDataSet('A', pt);
    DataSet dsB = createDataSet('B', pt);
    dsA.addDataSetElement(deA);
    dsB.addDataSetElement(deA);
    dsA.addOrganisationUnit(ouA);
    dsB.addOrganisationUnit(ouA);
    dataSetService.addDataSet(dsA);
    dataSetService.addDataSet(dsB);
}
Also used : MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) PeriodType(org.hisp.dhis.period.PeriodType) DataElement(org.hisp.dhis.dataelement.DataElement) DataElementGroupSet(org.hisp.dhis.dataelement.DataElementGroupSet) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) DataSet(org.hisp.dhis.dataset.DataSet) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup)

Example 34 with DataSet

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

the class OrgUnitSplitServiceTest method testSplit.

@Test
void testSplit() {
    DataSet dsA = createDataSet('A', ptA);
    dsA.addOrganisationUnit(ouA);
    DataSet dsB = createDataSet('B', ptA);
    dsB.addOrganisationUnit(ouA);
    idObjectManager.save(dsA);
    idObjectManager.save(dsB);
    assertNotNull(idObjectManager.get(OrganisationUnit.class, ouA.getUid()));
    assertNotNull(idObjectManager.get(OrganisationUnit.class, ouB.getUid()));
    assertNotNull(idObjectManager.get(OrganisationUnit.class, ouC.getUid()));
    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());
    service.split(request);
    assertEquals(2, ouB.getDataSets().size());
    assertEquals(2, ouC.getDataSets().size());
    assertNull(idObjectManager.get(OrganisationUnit.class, ouA.getUid()));
    assertNotNull(idObjectManager.get(OrganisationUnit.class, ouB.getUid()));
    assertNotNull(idObjectManager.get(OrganisationUnit.class, ouC.getUid()));
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSet(org.hisp.dhis.dataset.DataSet) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 35 with DataSet

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

the class DataQueryParams method getDataSetPeriodTypeMap.

/**
 * Returns a mapping between identifier and period type for all data sets in
 * this query.
 */
public Map<String, PeriodType> getDataSetPeriodTypeMap() {
    Map<String, PeriodType> map = new HashMap<>();
    for (DimensionalItemObject reportingRate : getReportingRates()) {
        ReportingRate rr = (ReportingRate) reportingRate;
        DataSet ds = rr.getDataSet();
        map.put(ds.getUid(), ds.getPeriodType());
    }
    return map;
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) HashMap(java.util.HashMap) ReportingRate(org.hisp.dhis.common.ReportingRate) DataSet(org.hisp.dhis.dataset.DataSet)

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