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