Search in sources :

Example 16 with DataElementGroup

use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.

the class PreheatServiceTest method testCollectReferenceCodeDEG1.

@Test
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.setCreatedBy(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()));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) User(org.hisp.dhis.user.User) DataSet(org.hisp.dhis.dataset.DataSet) LegendSet(org.hisp.dhis.legend.LegendSet) Set(java.util.Set) OptionSet(org.hisp.dhis.option.OptionSet) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 17 with DataElementGroup

use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.

the class PreheatServiceTest method testCollectReferenceUidDEG1.

@Test
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.setCreatedBy(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()));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) User(org.hisp.dhis.user.User) DataSet(org.hisp.dhis.dataset.DataSet) LegendSet(org.hisp.dhis.legend.LegendSet) Set(java.util.Set) OptionSet(org.hisp.dhis.option.OptionSet) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 18 with DataElementGroup

use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.

the class PreheatServiceTest method testPreheatReferenceWithScanUID.

@Test
void testPreheatReferenceWithScanUID() {
    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);
    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, "deabcdefghA"));
    assertTrue(preheat.containsKey(PreheatIdentifier.UID, DataElement.class, "deabcdefghB"));
    assertTrue(preheat.containsKey(PreheatIdentifier.UID, DataElement.class, "deabcdefghC"));
    assertTrue(preheat.containsKey(PreheatIdentifier.UID, User.class, "userabcdefA"));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) User(org.hisp.dhis.user.User) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 19 with DataElementGroup

use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.

the class PatchServiceTest method testSimpleIdObjectCollectionDiff.

@Test
void testSimpleIdObjectCollectionDiff() {
    DataElement deA = createDataElement('A');
    DataElement deB = createDataElement('B');
    DataElementGroup degA = createDataElementGroup('C');
    DataElementGroup degB = createDataElementGroup('D');
    manager.save(degA);
    manager.save(degB);
    deA.getGroups().add(degA);
    manager.update(degA);
    deB.getGroups().add(degB);
    deA.getAggregationLevels().add(1);
    deA.getAggregationLevels().add(2);
    deB.getAggregationLevels().add(2);
    deB.getAggregationLevels().add(3);
    deB.getAggregationLevels().add(4);
    Patch patch = patchService.diff(new PatchParams(deA, deB));
    checkCount(patch, "dataElementGroups", Mutation.Operation.ADDITION, 1);
    checkCount(patch, "dataElementGroups", Mutation.Operation.DELETION, 1);
    checkCount(patch, "aggregationLevels", Mutation.Operation.ADDITION, 2);
    checkCount(patch, "aggregationLevels", Mutation.Operation.DELETION, 1);
    patchService.apply(patch, deA);
    assertEquals(deA.getName(), deB.getName());
    assertEquals(deA.getShortName(), deB.getShortName());
    assertEquals(deA.getDescription(), deB.getDescription());
    assertEquals(deA.getAggregationLevels(), deB.getAggregationLevels());
    assertEquals(deA.getGroups(), deB.getGroups());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 20 with DataElementGroup

use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.

the class PatchServiceTest method testDeleteDataElementFromGroup.

@Test
void testDeleteDataElementFromGroup() {
    DataElementGroup dataElementGroup = createDataElementGroup('A');
    DataElement deA = createDataElement('A');
    DataElement deB = createDataElement('B');
    manager.save(deA);
    manager.save(deB);
    dataElementGroup.addDataElement(deA);
    dataElementGroup.addDataElement(deB);
    assertEquals(2, dataElementGroup.getMembers().size());
    Patch patch = new Patch().addMutation(new Mutation("name", "Updated Name")).addMutation(new Mutation("dataElements", Lists.newArrayList(deA.getUid()), Mutation.Operation.DELETION));
    patchService.apply(patch, dataElementGroup);
    assertEquals("Updated Name", dataElementGroup.getName());
    assertEquals(1, dataElementGroup.getMembers().size());
    patch = new Patch().addMutation(new Mutation("dataElements", Lists.newArrayList(deB.getUid()), Mutation.Operation.DELETION));
    patchService.apply(patch, dataElementGroup);
    assertTrue(dataElementGroup.getMembers().isEmpty());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

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