Search in sources :

Example 6 with TrackedEntityDataValueAudit

use of org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAudit in project dhis2-core by dhis2.

the class TrackedEntityDataValueAuditStoreTest method testGetTrackedEntityDataValueAudits.

@Test
void testGetTrackedEntityDataValueAudits() {
    TrackedEntityDataValueAudit dataValueAudit = new TrackedEntityDataValueAudit(dataElementA, stageInstance, dataValueA.getAuditValue(), "userA", dataValueA.getProvidedElsewhere(), AuditType.UPDATE);
    auditStore.addTrackedEntityDataValueAudit(dataValueAudit);
    Assertions.assertEquals(1, auditStore.getTrackedEntityDataValueAudits(Lists.newArrayList(dataElementA), Lists.newArrayList(stageInstance), AuditType.UPDATE).size());
    Assertions.assertEquals(1, auditStore.countTrackedEntityDataValueAudits(Lists.newArrayList(dataElementA, dataElementB), Lists.newArrayList(stageInstance), AuditType.UPDATE));
}
Also used : TrackedEntityDataValueAudit(org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAudit) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 7 with TrackedEntityDataValueAudit

use of org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAudit in project dhis2-core by dhis2.

the class DefaultProgramStageInstanceService method createAndAddAudit.

private void createAndAddAudit(EventDataValue dataValue, DataElement dataElement, ProgramStageInstance programStageInstance, AuditType auditType) {
    if (!config.isEnabled(CHANGELOG_TRACKER) || dataElement == null) {
        return;
    }
    TrackedEntityDataValueAudit dataValueAudit = new TrackedEntityDataValueAudit(dataElement, programStageInstance, dataValue.getValue(), dataValue.getStoredBy(), dataValue.getProvidedElsewhere(), auditType);
    dataValueAuditService.addTrackedEntityDataValueAudit(dataValueAudit);
}
Also used : TrackedEntityDataValueAudit(org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAudit)

Example 8 with TrackedEntityDataValueAudit

use of org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAudit in project dhis2-core by dhis2.

the class AuditController method getTrackedEntityDataValueAudit.

@GetMapping("trackedEntityDataValue")
@ResponseBody
public RootNode getTrackedEntityDataValueAudit(@RequestParam(required = false, defaultValue = "") List<String> de, @RequestParam(required = false, defaultValue = "") List<String> psi, @RequestParam(required = false) AuditType auditType, @RequestParam(required = false) Boolean skipPaging, @RequestParam(required = false) Boolean paging, @RequestParam(required = false, defaultValue = "50") int pageSize, @RequestParam(required = false, defaultValue = "1") int page) throws WebMessageException {
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    if (fields.isEmpty()) {
        fields.addAll(Preset.ALL.getFields());
    }
    List<DataElement> dataElements = getDataElements(de);
    List<ProgramStageInstance> programStageInstances = getProgramStageInstances(psi);
    List<TrackedEntityDataValueAudit> dataValueAudits;
    Pager pager = null;
    if (PagerUtils.isSkipPaging(skipPaging, paging)) {
        dataValueAudits = trackedEntityDataValueAuditService.getTrackedEntityDataValueAudits(dataElements, programStageInstances, auditType);
    } else {
        int total = trackedEntityDataValueAuditService.countTrackedEntityDataValueAudits(dataElements, programStageInstances, auditType);
        pager = new Pager(page, total, pageSize);
        dataValueAudits = trackedEntityDataValueAuditService.getTrackedEntityDataValueAudits(dataElements, programStageInstances, auditType, pager.getOffset(), pager.getPageSize());
    }
    RootNode rootNode = NodeUtils.createMetadata();
    if (pager != null) {
        rootNode.addChild(NodeUtils.createPager(pager));
    }
    CollectionNode trackedEntityAttributeValueAudits = rootNode.addChild(new CollectionNode("trackedEntityDataValueAudits", true));
    trackedEntityAttributeValueAudits.addChildren(fieldFilterService.toCollectionNode(TrackedEntityDataValueAudit.class, new FieldFilterParams(dataValueAudits, fields)).getChildren());
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) CollectionNode(org.hisp.dhis.node.types.CollectionNode) DataElement(org.hisp.dhis.dataelement.DataElement) Pager(org.hisp.dhis.common.Pager) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) TrackedEntityDataValueAudit(org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAudit) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

TrackedEntityDataValueAudit (org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAudit)8 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)3 Predicate (javax.persistence.criteria.Predicate)3 DataElement (org.hisp.dhis.dataelement.DataElement)3 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)3 Pager (org.hisp.dhis.common.Pager)2 CollectionNode (org.hisp.dhis.node.types.CollectionNode)2 RootNode (org.hisp.dhis.node.types.RootNode)2 Test (org.junit.jupiter.api.Test)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 DhisSpringTest (org.hisp.dhis.DhisSpringTest)1 FieldFilterParams (org.hisp.dhis.fieldfilter.FieldFilterParams)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1