Search in sources :

Example 1 with TrackedEntityDataValueAudit

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

the class MaintenanceServiceTest method testDeleteSoftDeletedProgramInstanceLinkedToATrackedEntityDataValueAudit.

@Test
void testDeleteSoftDeletedProgramInstanceLinkedToATrackedEntityDataValueAudit() {
    DataElement dataElement = createDataElement('A');
    dataElementService.addDataElement(dataElement);
    ProgramStageInstance programStageInstanceA = new ProgramStageInstance(programInstance, program.getProgramStageByStage(1));
    programStageInstanceA.setDueDate(enrollmentDate);
    programStageInstanceA.setUid("UID-A");
    programStageInstanceService.addProgramStageInstance(programStageInstanceA);
    TrackedEntityDataValueAudit trackedEntityDataValueAudit = new TrackedEntityDataValueAudit(dataElement, programStageInstanceA, "value", "modifiedBy", false, org.hisp.dhis.common.AuditType.UPDATE);
    trackedEntityDataValueAuditService.addTrackedEntityDataValueAudit(trackedEntityDataValueAudit);
    long idA = programInstanceService.addProgramInstance(programInstance);
    assertNotNull(programInstanceService.getProgramInstance(idA));
    programInstanceService.deleteProgramInstance(programInstance);
    assertNull(programInstanceService.getProgramInstance(idA));
    assertTrue(programInstanceService.programInstanceExistsIncludingDeleted(programInstance.getUid()));
    maintenanceService.deleteSoftDeletedProgramInstances();
    assertFalse(programInstanceService.programInstanceExistsIncludingDeleted(programInstance.getUid()));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) TrackedEntityDataValueAudit(org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAudit) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) Test(org.junit.jupiter.api.Test)

Example 2 with TrackedEntityDataValueAudit

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

the class HibernateTrackedEntityDataValueAuditStore method countTrackedEntityDataValueAudits.

@Override
public int countTrackedEntityDataValueAudits(List<DataElement> dataElements, List<ProgramStageInstance> programStageInstances, AuditType auditType) {
    CriteriaBuilder builder = sessionFactory.getCurrentSession().getCriteriaBuilder();
    CriteriaQuery<Long> query = builder.createQuery(Long.class);
    Root<TrackedEntityDataValueAudit> root = query.from(TrackedEntityDataValueAudit.class);
    query.select(builder.countDistinct(root.get("id")));
    List<Predicate> predicates = getTrackedEntityDataValueAuditCriteria(dataElements, programStageInstances, auditType, builder, root);
    query.where(predicates.toArray(new Predicate[predicates.size()]));
    return sessionFactory.getCurrentSession().createQuery(query).getSingleResult().intValue();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) TrackedEntityDataValueAudit(org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAudit) Predicate(javax.persistence.criteria.Predicate)

Example 3 with TrackedEntityDataValueAudit

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

the class HibernateTrackedEntityDataValueAuditStore method getTrackedEntityDataValueAudits.

@Override
public List<TrackedEntityDataValueAudit> getTrackedEntityDataValueAudits(List<DataElement> dataElements, List<ProgramStageInstance> programStageInstances, AuditType auditType, int first, int max) {
    CriteriaBuilder builder = sessionFactory.getCurrentSession().getCriteriaBuilder();
    CriteriaQuery<TrackedEntityDataValueAudit> query = builder.createQuery(TrackedEntityDataValueAudit.class);
    Root<TrackedEntityDataValueAudit> root = query.from(TrackedEntityDataValueAudit.class);
    query.select(root);
    List<Predicate> predicates = getTrackedEntityDataValueAuditCriteria(dataElements, programStageInstances, auditType, builder, root);
    query.where(predicates.toArray(new Predicate[predicates.size()]));
    query.orderBy(builder.desc(root.get("created")));
    return sessionFactory.getCurrentSession().createQuery(query).setFirstResult(first).setMaxResults(max).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) TrackedEntityDataValueAudit(org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAudit) Predicate(javax.persistence.criteria.Predicate)

Example 4 with TrackedEntityDataValueAudit

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

the class AuditController method getTrackedEntityDataValueAudit.

@RequestMapping(value = "trackedEntityDataValue", method = RequestMethod.GET)
@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, 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 (skipPaging) {
        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.filter(TrackedEntityDataValueAudit.class, dataValueAudits, fields).getChildren());
    return rootNode;
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) RootNode(org.hisp.dhis.node.types.RootNode) Pager(org.hisp.dhis.common.Pager) TrackedEntityDataValueAudit(org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAudit) CollectionNode(org.hisp.dhis.node.types.CollectionNode) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 5 with TrackedEntityDataValueAudit

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

the class HibernateTrackedEntityDataValueAuditStore method getTrackedEntityDataValueAudits.

@Override
public List<TrackedEntityDataValueAudit> getTrackedEntityDataValueAudits(List<DataElement> dataElements, List<ProgramStageInstance> programStageInstances, AuditType auditType) {
    CriteriaBuilder builder = sessionFactory.getCurrentSession().getCriteriaBuilder();
    CriteriaQuery<TrackedEntityDataValueAudit> query = builder.createQuery(TrackedEntityDataValueAudit.class);
    Root<TrackedEntityDataValueAudit> root = query.from(TrackedEntityDataValueAudit.class);
    query.select(root);
    List<Predicate> predicates = getTrackedEntityDataValueAuditCriteria(dataElements, programStageInstances, auditType, builder, root);
    query.where(predicates.toArray(new Predicate[predicates.size()]));
    query.orderBy(builder.desc(root.get("created")));
    return sessionFactory.getCurrentSession().createQuery(query).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) TrackedEntityDataValueAudit(org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAudit) Predicate(javax.persistence.criteria.Predicate)

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