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;
}
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());
}
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());
}
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());
}
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());
}
Aggregations