Search in sources :

Example 1 with AuditType

use of org.hisp.dhis.common.AuditType in project dhis2-core by dhis2.

the class HibernateDataValueAuditStore method getDataValueAudits.

@Override
public List<DataValueAudit> getDataValueAudits(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 getList(builder, newJpaParameters().addPredicate(root -> builder.and(predicates.stream().map(p -> p.apply(root)).collect(Collectors.toList()).toArray(new Predicate[predicates.size()]))).addOrder(root -> builder.desc(root.get("created"))));
    } else {
        return new ArrayList<>();
    }
}
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) ArrayList(java.util.ArrayList) DataValueAudit(org.hisp.dhis.datavalue.DataValueAudit)

Example 2 with AuditType

use of org.hisp.dhis.common.AuditType in project dhis2-core by dhis2.

the class AbstractTrackerPersister method saveOrUpdate.

private void saveOrUpdate(Session session, TrackerPreheat preheat, boolean isNew, TrackedEntityInstance trackedEntityInstance, TrackedEntityAttributeValue trackedEntityAttributeValue, boolean isUpdated) {
    if (isFileResource(trackedEntityAttributeValue)) {
        assignFileResource(session, preheat, trackedEntityAttributeValue.getValue());
    }
    AuditType auditType = null;
    if (isNew) {
        session.persist(trackedEntityAttributeValue);
        // In case it's a newly created attribute we'll add it back to TEI,
        // so it can end up in preheat
        trackedEntityInstance.getTrackedEntityAttributeValues().add(trackedEntityAttributeValue);
        auditType = AuditType.CREATE;
    } else {
        session.merge(trackedEntityAttributeValue);
        if (isUpdated) {
            auditType = AuditType.UPDATE;
        }
    }
    logTrackedEntityAttributeValueHistory(preheat.getUsername(), trackedEntityAttributeValue, trackedEntityInstance, auditType);
}
Also used : AuditType(org.hisp.dhis.common.AuditType)

Example 3 with AuditType

use of org.hisp.dhis.common.AuditType in project dhis2-core by dhis2.

the class DefaultDataValueSetService method saveDataValueUpdate.

private void saveDataValueUpdate(ImportContext context, ImportCount importCount, DataValueEntry dataValue, ImportContext.DataValueContext valueContext, DataValue internalValue, DataValue existingValue) {
    AuditType auditType = AuditType.UPDATE;
    if (internalValue.isNullValue() || internalValue.isDeleted() || dataValueIsZeroAndInsignificant(dataValue.getValue(), valueContext.getDataElement())) {
        internalValue.setDeleted(true);
        auditType = AuditType.DELETE;
        importCount.incrementDeleted();
    } else {
        importCount.incrementUpdated();
    }
    if (!internalValue.isDeleted() && Objects.equals(existingValue.getValue(), internalValue.getValue()) && Objects.equals(existingValue.getComment(), internalValue.getComment())) {
        // avoid performing unnecessary updates
        return;
    }
    if (!context.isDryRun()) {
        context.getDataValueBatchHandler().updateObject(internalValue);
        if (!context.isSkipAudit()) {
            DataValueAudit auditValue = new DataValueAudit(internalValue, existingValue.getValue(), context.getStoredBy(dataValue), auditType);
            context.getAuditBatchHandler().addObject(auditValue);
        }
        if (valueContext.getDataElement().isFileType()) {
            FileResource fr = fileResourceService.getFileResource(internalValue.getValue());
            fr.setAssigned(true);
            fileResourceService.updateFileResource(fr);
        }
    }
}
Also used : AuditType(org.hisp.dhis.common.AuditType) FileResource(org.hisp.dhis.fileresource.FileResource) DataValueAudit(org.hisp.dhis.datavalue.DataValueAudit)

Example 4 with AuditType

use of org.hisp.dhis.common.AuditType in project dhis2-core by dhis2.

the class HibernateDataValueAuditStore method getDataValueAudits.

@Override
public List<DataValueAudit> getDataValueAudits(List<DataElement> dataElements, List<Period> periods, List<OrganisationUnit> organisationUnits, CategoryOptionCombo categoryOptionCombo, CategoryOptionCombo attributeOptionCombo, AuditType auditType, int first, int max) {
    CriteriaBuilder builder = getSession().getCriteriaBuilder();
    List<Function<Root<DataValueAudit>, Predicate>> predicates = getDataValueAuditPredicates(builder, dataElements, periods, organisationUnits, categoryOptionCombo, attributeOptionCombo, auditType);
    if (!predicates.isEmpty()) {
        return getList(builder, newJpaParameters().addPredicate(root -> builder.and(predicates.stream().map(p -> p.apply(root)).collect(Collectors.toList()).toArray(new Predicate[predicates.size()]))).addOrder(root -> builder.desc(root.get("created"))).setFirstResult(first).setMaxResults(max));
    } else {
        return new ArrayList<>();
    }
}
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) ArrayList(java.util.ArrayList) DataValueAudit(org.hisp.dhis.datavalue.DataValueAudit)

Example 5 with AuditType

use of org.hisp.dhis.common.AuditType 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)

Aggregations

AuditType (org.hisp.dhis.common.AuditType)5 DataValueAudit (org.hisp.dhis.datavalue.DataValueAudit)4 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)3 Lists (com.google.common.collect.Lists)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Function (java.util.function.Function)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 SessionFactory (org.hibernate.SessionFactory)3 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)3 DataElement (org.hisp.dhis.dataelement.DataElement)3 DataValue (org.hisp.dhis.datavalue.DataValue)3 DataValueAuditStore (org.hisp.dhis.datavalue.DataValueAuditStore)3 HibernateGenericStore (org.hisp.dhis.hibernate.HibernateGenericStore)3 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)3 Period (org.hisp.dhis.period.Period)3 PeriodStore (org.hisp.dhis.period.PeriodStore)3