Search in sources :

Example 16 with DataValueAudit

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;
    }
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) HibernateGenericStore(org.hisp.dhis.hibernate.HibernateGenericStore) DataValueAuditStore(org.hisp.dhis.datavalue.DataValueAuditStore) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) SessionFactory(org.hibernate.SessionFactory) DataValueAudit(org.hisp.dhis.datavalue.DataValueAudit) AuditType(org.hisp.dhis.common.AuditType) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) DataElement(org.hisp.dhis.dataelement.DataElement) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) List(java.util.List) Lists(com.google.common.collect.Lists) Predicate(javax.persistence.criteria.Predicate) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) PeriodStore(org.hisp.dhis.period.PeriodStore) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) DataValue(org.hisp.dhis.datavalue.DataValue) Repository(org.springframework.stereotype.Repository) Root(javax.persistence.criteria.Root) Period(org.hisp.dhis.period.Period) Transactional(org.springframework.transaction.annotation.Transactional) Function(java.util.function.Function) DataValueAudit(org.hisp.dhis.datavalue.DataValueAudit) Predicate(javax.persistence.criteria.Predicate)

Example 17 with DataValueAudit

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;
}
Also used : DataValueAudit(org.hisp.dhis.datavalue.DataValueAudit)

Example 18 with DataValueAudit

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;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) RootNode(org.hisp.dhis.node.types.RootNode) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) 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) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) DataValueAudit(org.hisp.dhis.datavalue.DataValueAudit) TrackedEntityDataValueAudit(org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAudit) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

DataValueAudit (org.hisp.dhis.datavalue.DataValueAudit)18 DataValue (org.hisp.dhis.datavalue.DataValue)11 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)7 Period (org.hisp.dhis.period.Period)7 Test (org.junit.jupiter.api.Test)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)6 DataElement (org.hisp.dhis.dataelement.DataElement)6 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)6 ClassPathResource (org.springframework.core.io.ClassPathResource)6 Function (java.util.function.Function)4 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)4 AuditType (org.hisp.dhis.common.AuditType)4 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)3 Lists (com.google.common.collect.Lists)3 Collectors (java.util.stream.Collectors)3 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)3 Predicate (javax.persistence.criteria.Predicate)3 Root (javax.persistence.criteria.Root)3