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