use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.
the class DefaultCsvImportService method dataElementGroupMembersFromCsv.
private List<DataElementGroup> dataElementGroupMembersFromCsv(CsvReader reader) throws IOException {
Map<String, DataElementGroup> uidMap = new HashMap<>();
while (reader.readRecord()) {
String[] values = reader.getValues();
if (values != null && values.length > 0) {
String groupUid = values[0];
String memberUid = values[1];
DataElementGroup persistedGroup = dataElementGroupService.getDataElementGroupByUid(groupUid);
if (persistedGroup != null) {
DataElementGroup group = uidMap.computeIfAbsent(groupUid, key -> {
DataElementGroup nonPersistedGroup = new DataElementGroup();
nonPersistedGroup.setUid(persistedGroup.getUid());
nonPersistedGroup.setName(persistedGroup.getName());
return nonPersistedGroup;
});
DataElement member = new DataElement();
member.setUid(memberUid);
group.addDataElement(member);
}
}
}
return new ArrayList<>(uidMap.values());
}
use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.
the class DefaultCsvImportService method dataElementGroupsFromCsv.
private List<DataElementGroup> dataElementGroupsFromCsv(CsvReader reader) throws IOException {
List<DataElementGroup> list = new ArrayList<>();
while (reader.readRecord()) {
String[] values = reader.getValues();
if (values != null && values.length > 0) {
DataElementGroup object = new DataElementGroup();
setIdentifiableObject(object, values);
object.setShortName(getSafe(values, 3, object.getName(), 50));
object.setAutoFields();
list.add(object);
}
}
return list;
}
use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.
the class ObjectBundleServiceTest method testCreateDoesPreheating.
@Test
void testCreateDoesPreheating() {
DataElementGroup dataElementGroup = fromJson("dxf2/degAUidRef.json", DataElementGroup.class);
defaultSetup();
ObjectBundleParams params = new ObjectBundleParams();
params.setPreheatMode(PreheatMode.REFERENCE);
params.addObject(dataElementGroup);
ObjectBundle bundle = objectBundleService.create(params);
assertNotNull(bundle);
assertFalse(bundle.getPreheat().isEmpty());
assertFalse(bundle.getPreheat().isEmpty(PreheatIdentifier.UID));
assertFalse(bundle.getPreheat().isEmpty(PreheatIdentifier.UID, DataElement.class));
assertTrue(bundle.getPreheat().containsKey(PreheatIdentifier.UID, DataElement.class, "deabcdefghA"));
assertTrue(bundle.getPreheat().containsKey(PreheatIdentifier.UID, DataElement.class, "deabcdefghB"));
assertTrue(bundle.getPreheat().containsKey(PreheatIdentifier.UID, DataElement.class, "deabcdefghC"));
assertFalse(bundle.getPreheat().containsKey(PreheatIdentifier.UID, DataElement.class, "deabcdefghD"));
}
use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.
the class MetadataExportServiceTest method testMetadataExport.
@Test
void testMetadataExport() {
DataElementGroup deg1 = createDataElementGroup('A');
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);
deg1.addDataElement(de1);
deg1.addDataElement(de2);
deg1.addDataElement(de3);
deg1.setCreatedBy(user);
manager.save(deg1);
MetadataExportParams params = new MetadataExportParams();
Map<Class<? extends IdentifiableObject>, List<? extends IdentifiableObject>> metadata = metadataExportService.getMetadata(params);
assertEquals(1, metadata.get(User.class).size());
assertEquals(1, metadata.get(DataElementGroup.class).size());
assertEquals(3, metadata.get(DataElement.class).size());
}
use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.
the class MetadataExportServiceTest method testMetadataExportWithCustomQueries.
@Test
void testMetadataExportWithCustomQueries() {
DataElementGroup deg1 = createDataElementGroup('A');
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);
deg1.addDataElement(de1);
deg1.addDataElement(de2);
deg1.addDataElement(de3);
deg1.setCreatedBy(user);
manager.save(deg1);
Query deQuery = Query.from(schemaService.getDynamicSchema(DataElement.class));
Disjunction disjunction = deQuery.disjunction();
disjunction.add(Restrictions.eq("id", de1.getUid()));
disjunction.add(Restrictions.eq("id", de2.getUid()));
deQuery.add(disjunction);
Query degQuery = Query.from(schemaService.getDynamicSchema(DataElementGroup.class));
degQuery.add(Restrictions.eq("id", "INVALID UID"));
MetadataExportParams params = new MetadataExportParams();
params.addQuery(deQuery);
params.addQuery(degQuery);
Map<Class<? extends IdentifiableObject>, List<? extends IdentifiableObject>> metadata = metadataExportService.getMetadata(params);
assertFalse(metadata.containsKey(User.class));
assertFalse(metadata.containsKey(DataElementGroup.class));
assertTrue(metadata.containsKey(DataElement.class));
assertEquals(2, metadata.get(DataElement.class).size());
}
Aggregations