use of org.hisp.dhis.dataelement.DataElement in project dhis2-core by dhis2.
the class MinMaxDataElementStoreTest method testBasic.
@Test
public void testBasic() {
OrganisationUnit source1 = createOrganisationUnit('A');
OrganisationUnit source2 = createOrganisationUnit('B');
organisationUnitService.addOrganisationUnit(source1);
organisationUnitService.addOrganisationUnit(source2);
DataElement dataElement1 = createDataElement('A');
DataElement dataElement2 = createDataElement('B');
DataElement dataElement3 = createDataElement('C');
DataElement dataElement4 = createDataElement('D');
dataElementService.addDataElement(dataElement1);
dataElementService.addDataElement(dataElement2);
dataElementService.addDataElement(dataElement3);
dataElementService.addDataElement(dataElement4);
DataElementCategoryOptionCombo optionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
MinMaxDataElement minMaxDataElement1 = new MinMaxDataElement(source1, dataElement1, optionCombo, 0, 100, false);
MinMaxDataElement minMaxDataElement2 = new MinMaxDataElement(source2, dataElement2, optionCombo, 0, 100, false);
MinMaxDataElement minMaxDataElement3 = new MinMaxDataElement(source2, dataElement3, optionCombo, 0, 100, false);
MinMaxDataElement minMaxDataElement4 = new MinMaxDataElement(source2, dataElement4, optionCombo, 0, 100, false);
minMaxDataElementStore.save(minMaxDataElement1);
int mmdeid1 = minMaxDataElement1.getId();
minMaxDataElementStore.save(minMaxDataElement2);
minMaxDataElementStore.save(minMaxDataElement3);
minMaxDataElementStore.save(minMaxDataElement4);
// ----------------------------------------------------------------------
// Assertions
// ----------------------------------------------------------------------
assertNotNull(minMaxDataElementStore.get(mmdeid1));
assertTrue(minMaxDataElementStore.get(mmdeid1).getMax() == 100);
List<DataElement> dataElements1 = new ArrayList<>();
dataElements1.add(dataElement1);
List<DataElement> dataElements2 = new ArrayList<>();
dataElements2.add(dataElement2);
dataElements2.add(dataElement3);
dataElements2.add(dataElement4);
assertNotNull(minMaxDataElementStore.get(source1, dataElement1, optionCombo));
assertNull(minMaxDataElementStore.get(source2, dataElement1, optionCombo));
assertEquals(1, minMaxDataElementStore.get(source1, dataElements1).size());
assertEquals(3, minMaxDataElementStore.get(source2, dataElements2).size());
minMaxDataElementStore.delete(minMaxDataElement1);
assertNull(minMaxDataElementStore.get(mmdeid1));
}
use of org.hisp.dhis.dataelement.DataElement in project dhis2-core by dhis2.
the class PreheatServiceTest method testPreheatReferenceConnectUID.
@Test
public void testPreheatReferenceConnectUID() {
DataElementGroup dataElementGroup = fromJson("preheat/degAUidRef.json", DataElementGroup.class);
defaultSetup();
PreheatParams params = new PreheatParams();
params.setPreheatMode(PreheatMode.REFERENCE);
params.getObjects().put(DataElementGroup.class, Lists.newArrayList(dataElementGroup));
preheatService.validate(params);
Preheat preheat = preheatService.preheat(params);
preheatService.connectReferences(dataElementGroup, preheat, PreheatIdentifier.UID);
List<DataElement> members = new ArrayList<>(dataElementGroup.getMembers());
assertEquals("DataElementA", members.get(0).getName());
assertEquals("DataElementCodeA", members.get(0).getCode());
assertEquals("DataElementB", members.get(1).getName());
assertEquals("DataElementCodeB", members.get(1).getCode());
assertEquals("DataElementC", members.get(2).getName());
assertEquals("DataElementCodeC", members.get(2).getCode());
assertEquals("FirstNameA", dataElementGroup.getUser().getFirstName());
assertEquals("SurnameA", dataElementGroup.getUser().getSurname());
assertEquals("UserCodeA", dataElementGroup.getUser().getCode());
}
use of org.hisp.dhis.dataelement.DataElement in project dhis2-core by dhis2.
the class PreheatServiceTest method testCollectReferenceCodeDEG2.
@Test
public void testCollectReferenceCodeDEG2() {
DataElementGroup deg1 = createDataElementGroup('A');
DataElementGroup deg2 = createDataElementGroup('B');
DataElement de1 = createDataElement('A');
DataElement de2 = createDataElement('B');
DataElement de3 = createDataElement('C');
deg1.addDataElement(de1);
deg1.addDataElement(de2);
deg2.addDataElement(de3);
Map<Class<? extends IdentifiableObject>, Set<String>> references = preheatService.collectReferences(Lists.newArrayList(deg1, deg2)).get(PreheatIdentifier.CODE);
assertTrue(references.containsKey(DataElement.class));
assertEquals(3, references.get(DataElement.class).size());
assertTrue(references.get(DataElement.class).contains(de1.getCode()));
assertTrue(references.get(DataElement.class).contains(de2.getCode()));
assertTrue(references.get(DataElement.class).contains(de3.getCode()));
}
use of org.hisp.dhis.dataelement.DataElement in project dhis2-core by dhis2.
the class PreheatServiceTest method testPreheatAllMetadataUID.
@Test
public void testPreheatAllMetadataUID() {
DataElementGroup dataElementGroup = new DataElementGroup("DataElementGroupA");
dataElementGroup.setAutoFields();
DataElement de1 = createDataElement('A');
DataElement de2 = createDataElement('B');
DataElement de3 = createDataElement('C');
manager.save(de1);
manager.save(de2);
manager.save(de3);
User user = createUser('A');
manager.save(user);
dataElementGroup.addDataElement(de1);
dataElementGroup.addDataElement(de2);
dataElementGroup.addDataElement(de3);
dataElementGroup.setUser(user);
manager.save(dataElementGroup);
PreheatParams params = new PreheatParams();
params.setPreheatMode(PreheatMode.ALL);
preheatService.validate(params);
Preheat preheat = preheatService.preheat(params);
assertFalse(preheat.isEmpty());
assertFalse(preheat.isEmpty(PreheatIdentifier.UID));
assertFalse(preheat.isEmpty(PreheatIdentifier.UID, DataElement.class));
assertFalse(preheat.isEmpty(PreheatIdentifier.UID, DataElementGroup.class));
assertFalse(preheat.isEmpty(PreheatIdentifier.UID, User.class));
assertTrue(preheat.containsKey(PreheatIdentifier.UID, DataElement.class, de1.getUid()));
assertTrue(preheat.containsKey(PreheatIdentifier.UID, DataElement.class, de2.getUid()));
assertTrue(preheat.containsKey(PreheatIdentifier.UID, DataElement.class, de3.getUid()));
assertTrue(preheat.containsKey(PreheatIdentifier.UID, DataElementGroup.class, dataElementGroup.getUid()));
assertTrue(preheat.containsKey(PreheatIdentifier.UID, User.class, user.getUid()));
}
use of org.hisp.dhis.dataelement.DataElement in project dhis2-core by dhis2.
the class PreheatServiceTest method testCollectReferenceUidDEG1.
@Test
public void testCollectReferenceUidDEG1() {
DataElementGroup deg1 = createDataElementGroup('A');
DataElement de1 = createDataElement('A');
DataElement de2 = createDataElement('B');
DataElement de3 = createDataElement('C');
User user = createUser('A');
deg1.addDataElement(de1);
deg1.addDataElement(de2);
deg1.addDataElement(de3);
deg1.setUser(user);
Map<Class<? extends IdentifiableObject>, Set<String>> references = preheatService.collectReferences(deg1).get(PreheatIdentifier.UID);
assertTrue(references.containsKey(DataElement.class));
assertTrue(references.containsKey(User.class));
assertEquals(3, references.get(DataElement.class).size());
assertEquals(1, references.get(User.class).size());
assertTrue(references.get(DataElement.class).contains(de1.getUid()));
assertTrue(references.get(DataElement.class).contains(de2.getUid()));
assertTrue(references.get(DataElement.class).contains(de3.getUid()));
assertTrue(references.get(User.class).contains(user.getUid()));
}
Aggregations