use of org.hisp.dhis.dataelement.DataElement in project dhis2-core by dhis2.
the class PreheatServiceTest method testPreheatWithDataSetElements.
@Test
public void testPreheatWithDataSetElements() {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = new HashMap<>();
DataElement de1 = createDataElement('A');
DataElement de2 = createDataElement('B');
DataElement de3 = createDataElement('C');
manager.save(de1);
manager.save(de2);
manager.save(de3);
DataSet dataSet = createDataSet('A');
dataSet.setAutoFields();
dataSet.getDataSetElements().add(new DataSetElement(dataSet, de1));
dataSet.getDataSetElements().add(new DataSetElement(dataSet, de2));
dataSet.getDataSetElements().add(new DataSetElement(dataSet, de3));
metadata.put(DataSet.class, new ArrayList<>());
metadata.get(DataSet.class).add(dataSet);
PreheatParams params = new PreheatParams();
params.setPreheatIdentifier(PreheatIdentifier.UID);
params.setPreheatMode(PreheatMode.REFERENCE);
params.setObjects(metadata);
preheatService.validate(params);
Preheat preheat = preheatService.preheat(params);
Map<String, IdentifiableObject> map = preheat.getMap().get(PreheatIdentifier.UID).get(DataElement.class);
assertEquals(3, map.size());
}
use of org.hisp.dhis.dataelement.DataElement in project dhis2-core by dhis2.
the class PreheatServiceTest method testPreheatReferenceConnectAUTO.
@Test
public void testPreheatReferenceConnectAUTO() {
DataElementGroup dataElementGroup = fromJson("preheat/degAAutoRef.json", DataElementGroup.class);
defaultSetup();
PreheatParams params = new PreheatParams();
params.setPreheatIdentifier(PreheatIdentifier.AUTO);
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.AUTO);
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 testCollectReferenceUidDEG2.
@Test
public void testCollectReferenceUidDEG2() {
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.UID);
assertTrue(references.containsKey(DataElement.class));
assertEquals(3, references.get(DataElement.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()));
}
use of org.hisp.dhis.dataelement.DataElement in project dhis2-core by dhis2.
the class PreheatServiceTest method defaultSetup.
private void defaultSetup() {
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);
}
use of org.hisp.dhis.dataelement.DataElement in project dhis2-core by dhis2.
the class PreheatServiceTest method testCollectReferenceCodeDEG1.
@Test
public void testCollectReferenceCodeDEG1() {
DataElementGroup dataElementGroup = createDataElementGroup('A');
DataElement de1 = createDataElement('A');
DataElement de2 = createDataElement('B');
DataElement de3 = createDataElement('C');
User user = createUser('A');
dataElementGroup.addDataElement(de1);
dataElementGroup.addDataElement(de2);
dataElementGroup.addDataElement(de3);
dataElementGroup.setUser(user);
Map<Class<? extends IdentifiableObject>, Set<String>> references = preheatService.collectReferences(dataElementGroup).get(PreheatIdentifier.CODE);
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.getCode()));
assertTrue(references.get(DataElement.class).contains(de2.getCode()));
assertTrue(references.get(DataElement.class).contains(de3.getCode()));
assertTrue(references.get(User.class).contains(user.getCode()));
}
Aggregations