Search in sources :

Example 31 with DataElementGroup

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

the class GetDataElementsNotInGroupAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() {
    canReadType(DataElement.class);
    if (groupId != null) {
        DataElementGroup group = dataElementService.getDataElementGroup(groupId);
        groupMembers = new ArrayList<>(group.getMembers());
        Collections.sort(groupMembers);
    }
    User currentUser = currentUserService.getCurrentUser();
    groupMembers.forEach(instance -> canReadInstance(instance, currentUser));
    // ---------------------------------------------------------------------
    // Get available elements
    // ---------------------------------------------------------------------
    dataElements = new ArrayList<>(dataElementService.getAllDataElements());
    dataElements.removeAll(groupMembers);
    Collections.sort(dataElements);
    dataElements.forEach(instance -> canReadInstance(instance, currentUser));
    if (usePaging) {
        this.paging = createPaging(dataElements.size());
        dataElements = dataElements.subList(paging.getStartPos(), paging.getEndPos());
    }
    return SUCCESS;
}
Also used : User(org.hisp.dhis.user.User) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup)

Example 32 with DataElementGroup

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

the class PatchServiceTest method testAddDataElementToGroup.

@Test
void testAddDataElementToGroup() {
    DataElementGroup dataElementGroup = createDataElementGroup('A');
    DataElement deA = createDataElement('A');
    DataElement deB = createDataElement('B');
    manager.save(deA);
    manager.save(deB);
    assertTrue(dataElementGroup.getMembers().isEmpty());
    Patch patch = new Patch().addMutation(new Mutation("name", "Updated Name")).addMutation(new Mutation("dataElements", Lists.newArrayList(deA.getUid(), deB.getUid())));
    patchService.apply(patch, dataElementGroup);
    assertEquals("Updated Name", dataElementGroup.getName());
    assertEquals(2, dataElementGroup.getMembers().size());
}
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 33 with DataElementGroup

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

the class PatchServiceTest method testPatchFromJsonNode2.

@Test
void testPatchFromJsonNode2() {
    JsonNode jsonNode = loadJsonNodeFromFile("patch/id-collection.json");
    DataElement dataElement = createDataElement('A');
    DataElementGroup degA = createDataElementGroup('C');
    DataElementGroup degB = createDataElementGroup('D');
    manager.save(degA);
    manager.save(degB);
    Patch patch = patchService.diff(new PatchParams(jsonNode));
    patchService.apply(patch, dataElement);
    assertEquals(dataElement.getName(), "Updated Name");
    assertEquals(dataElement.getShortName(), "Updated Short Name");
    assertEquals(2, dataElement.getGroups().size());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 34 with DataElementGroup

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

the class JsonPatchManagerTest method testCollectionAddPatchNoPersist.

@Test
void testCollectionAddPatchNoPersist() throws Exception {
    DataElementGroup dataElementGroup = createDataElementGroup('A');
    assertEquals("DataElementGroupA", dataElementGroup.getName());
    DataElement dataElementA = createDataElement('A');
    DataElement dataElementB = createDataElement('B');
    dataElementGroup.getMembers().add(dataElementA);
    dataElementGroup.getMembers().add(dataElementB);
    assertEquals(2, dataElementGroup.getMembers().size());
    JsonPatch patch = jsonMapper.readValue("[" + "{\"op\": \"add\", \"path\": \"/name\", \"value\": \"updated\"}," + "{\"op\": \"add\", \"path\": \"/dataElements/-\", \"value\": {\"id\": \"my-uid\"}}" + "]", JsonPatch.class);
    assertNotNull(patch);
    DataElementGroup patchedDataElementGroup = jsonPatchManager.apply(patch, dataElementGroup);
    assertEquals("DataElementGroupA", dataElementGroup.getName());
    assertEquals(2, dataElementGroup.getMembers().size());
    assertEquals("updated", patchedDataElementGroup.getName());
    assertEquals(3, patchedDataElementGroup.getMembers().size());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) JsonPatch(org.hisp.dhis.commons.jackson.jsonpatch.JsonPatch) Test(org.junit.jupiter.api.Test)

Example 35 with DataElementGroup

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

the class PreheatServiceTest method testPreheatReferenceConnectCODE.

@Test
void testPreheatReferenceConnectCODE() {
    DataElementGroup dataElementGroup = fromJson("preheat/degACodeRef.json", DataElementGroup.class);
    defaultSetup();
    PreheatParams params = new PreheatParams();
    params.setPreheatIdentifier(PreheatIdentifier.CODE);
    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.CODE);
    List<DataElement> members = new ArrayList<>(dataElementGroup.getMembers());
    assertContains(members, "DataElementA", "DataElementCodeA");
    assertContains(members, "DataElementB", "DataElementCodeB");
    assertContains(members, "DataElementC", "DataElementCodeC");
    assertEquals("FirstNameA", dataElementGroup.getCreatedBy().getFirstName());
    assertEquals("SurnameA", dataElementGroup.getCreatedBy().getSurname());
    assertEquals("UserCodeA", dataElementGroup.getCreatedBy().getCode());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) ArrayList(java.util.ArrayList) 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