Search in sources :

Example 41 with DataElementGroup

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());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) HashMap(java.util.HashMap) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) ArrayList(java.util.ArrayList)

Example 42 with DataElementGroup

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;
}
Also used : DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) ArrayList(java.util.ArrayList)

Example 43 with DataElementGroup

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"));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 44 with DataElementGroup

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());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) User(org.hisp.dhis.user.User) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) List(java.util.List) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 45 with DataElementGroup

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());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) Disjunction(org.hisp.dhis.query.Disjunction) User(org.hisp.dhis.user.User) Query(org.hisp.dhis.query.Query) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) List(java.util.List) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

DataElementGroup (org.hisp.dhis.dataelement.DataElementGroup)55 DataElement (org.hisp.dhis.dataelement.DataElement)31 Test (org.junit.jupiter.api.Test)29 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)17 ArrayList (java.util.ArrayList)15 User (org.hisp.dhis.user.User)15 DataSet (org.hisp.dhis.dataset.DataSet)9 List (java.util.List)8 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)8 Set (java.util.Set)7 DhisSpringTest (org.hisp.dhis.DhisSpringTest)7 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)6 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)6 DataElementGroupSet (org.hisp.dhis.dataelement.DataElementGroupSet)6 DimensionalObject (org.hisp.dhis.common.DimensionalObject)5 LegendSet (org.hisp.dhis.legend.LegendSet)5 OptionSet (org.hisp.dhis.option.OptionSet)5 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)5 PeriodType (org.hisp.dhis.period.PeriodType)5 DimensionItemKeywords (org.hisp.dhis.common.DimensionItemKeywords)4