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