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