use of org.hisp.dhis.datavalue.DataValueAudit in project dhis2-core by dhis2.
the class HibernateDataValueAuditStore method countDataValueAudits.
@Override
public int countDataValueAudits(List<DataElement> dataElements, List<Period> periods, List<OrganisationUnit> organisationUnits, CategoryOptionCombo categoryOptionCombo, CategoryOptionCombo attributeOptionCombo, AuditType auditType) {
CriteriaBuilder builder = getSession().getCriteriaBuilder();
List<Function<Root<DataValueAudit>, Predicate>> predicates = getDataValueAuditPredicates(builder, dataElements, periods, organisationUnits, categoryOptionCombo, attributeOptionCombo, auditType);
if (!predicates.isEmpty()) {
return getCount(builder, newJpaParameters().addPredicate(root -> builder.and(predicates.stream().map(p -> p.apply(root)).collect(Collectors.toList()).toArray(new Predicate[predicates.size()]))).count(root -> builder.countDistinct(root.get("id")))).intValue();
} else {
return 0;
}
}
use of org.hisp.dhis.datavalue.DataValueAudit in project dhis2-core by dhis2.
the class DataValueAuditBatchHandler method mapRow.
@Override
public DataValueAudit mapRow(ResultSet resultSet) throws SQLException {
DataValueAudit dva = new DataValueAudit();
dva.setValue(resultSet.getString("value"));
dva.setModifiedBy(resultSet.getString("modifiedby"));
dva.setCreated(resultSet.getDate("created"));
dva.setAuditType(AuditType.valueOf(resultSet.getString("audittype")));
return dva;
}
use of org.hisp.dhis.datavalue.DataValueAudit in project dhis2-core by dhis2.
the class AuditController method getAggregateDataValueAudit.
@GetMapping("dataValue")
@ResponseBody
public RootNode getAggregateDataValueAudit(@RequestParam(required = false, defaultValue = "") List<String> ds, @RequestParam(required = false, defaultValue = "") List<String> de, @RequestParam(required = false, defaultValue = "") List<String> pe, @RequestParam(required = false, defaultValue = "") List<String> ou, @RequestParam(required = false) String co, @RequestParam(required = false) String cc, @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 = new ArrayList<>();
dataElements.addAll(getDataElements(de));
dataElements.addAll(getDataElementsByDataSet(ds));
List<Period> periods = getPeriods(pe);
List<OrganisationUnit> organisationUnits = getOrganisationUnit(ou);
CategoryOptionCombo categoryOptionCombo = getCategoryOptionCombo(co);
CategoryOptionCombo attributeOptionCombo = getAttributeOptionCombo(cc);
List<DataValueAudit> dataValueAudits;
Pager pager = null;
if (PagerUtils.isSkipPaging(skipPaging, paging)) {
dataValueAudits = dataValueAuditService.getDataValueAudits(dataElements, periods, organisationUnits, categoryOptionCombo, attributeOptionCombo, auditType);
} else {
int total = dataValueAuditService.countDataValueAudits(dataElements, periods, organisationUnits, categoryOptionCombo, attributeOptionCombo, auditType);
pager = new Pager(page, total, pageSize);
dataValueAudits = dataValueAuditService.getDataValueAudits(dataElements, periods, organisationUnits, categoryOptionCombo, attributeOptionCombo, auditType, pager.getOffset(), pager.getPageSize());
}
RootNode rootNode = NodeUtils.createMetadata();
if (pager != null) {
rootNode.addChild(NodeUtils.createPager(pager));
}
CollectionNode trackedEntityAttributeValueAudits = rootNode.addChild(new CollectionNode("dataValueAudits", true));
trackedEntityAttributeValueAudits.addChildren(fieldFilterService.toCollectionNode(DataValueAudit.class, new FieldFilterParams(dataValueAudits, fields)).getChildren());
return rootNode;
}
Aggregations