Search in sources :

Example 1 with AuditType

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

the class HibernatePotentialDuplicateStore method moveTrackedEntityAttributeValues.

@Override
public void moveTrackedEntityAttributeValues(TrackedEntityInstance original, TrackedEntityInstance duplicate, List<String> trackedEntityAttributes) {
    // Collect existing teav from original for the tea list
    Map<String, TrackedEntityAttributeValue> originalAttributeValueMap = new HashMap<>();
    original.getTrackedEntityAttributeValues().forEach(oav -> {
        if (trackedEntityAttributes.contains(oav.getAttribute().getUid())) {
            originalAttributeValueMap.put(oav.getAttribute().getUid(), oav);
        }
    });
    duplicate.getTrackedEntityAttributeValues().stream().filter(av -> trackedEntityAttributes.contains(av.getAttribute().getUid())).forEach(av -> {
        TrackedEntityAttributeValue updatedTeav;
        org.hisp.dhis.common.AuditType auditType;
        if (originalAttributeValueMap.containsKey(av.getAttribute().getUid())) {
            // Teav exists in original, overwrite the value
            updatedTeav = originalAttributeValueMap.get(av.getAttribute().getUid());
            updatedTeav.setValue(av.getValue());
            auditType = UPDATE;
        } else {
            // teav does not exist in original, so create new and attach
            // it to original
            updatedTeav = new TrackedEntityAttributeValue();
            updatedTeav.setAttribute(av.getAttribute());
            updatedTeav.setEntityInstance(original);
            updatedTeav.setValue(av.getValue());
            auditType = CREATE;
        }
        getSession().delete(av);
        // We need to flush to make sure the previous teav is
        // deleted.
        // Or else we might end up breaking a
        // constraint, since hibernate does not respect order.
        getSession().flush();
        getSession().saveOrUpdate(updatedTeav);
        auditTeav(av, updatedTeav, auditType);
    });
}
Also used : PotentialDuplicate(org.hisp.dhis.deduplication.PotentialDuplicate) PotentialDuplicateQuery(org.hisp.dhis.deduplication.PotentialDuplicateQuery) Arrays(java.util.Arrays) DeduplicationMergeParams(org.hisp.dhis.deduplication.DeduplicationMergeParams) DELETE(org.hisp.dhis.common.AuditType.DELETE) PotentialDuplicateStore(org.hisp.dhis.deduplication.PotentialDuplicateStore) Date(java.util.Date) AuditManager(org.hisp.dhis.artemis.audit.AuditManager) LocalDateTime(java.time.LocalDateTime) UPDATE(org.hisp.dhis.common.AuditType.UPDATE) HashMap(java.util.HashMap) TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue) TrackedEntityInstanceStore(org.hisp.dhis.trackedentity.TrackedEntityInstanceStore) AuditType(org.hisp.dhis.audit.AuditType) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) DeduplicationStatus(org.hisp.dhis.deduplication.DeduplicationStatus) TrackedEntityAttributeValueAuditService(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueAuditService) HibernateIdentifiableObjectStore(org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore) CREATE(org.hisp.dhis.common.AuditType.CREATE) Map(java.util.Map) NativeQuery(org.hibernate.query.NativeQuery) Query(org.hibernate.query.Query) ProgramInstance(org.hisp.dhis.program.ProgramInstance) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) BigInteger(java.math.BigInteger) AuditScope(org.hisp.dhis.audit.AuditScope) Repository(org.springframework.stereotype.Repository) MergeObject(org.hisp.dhis.deduplication.MergeObject) CHANGELOG_TRACKER(org.hisp.dhis.external.conf.ConfigurationKey.CHANGELOG_TRACKER) HibernateProxyUtils(org.hisp.dhis.hibernate.HibernateProxyUtils) TrackedEntityAttributeValueAudit(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueAudit) DhisConfigurationProvider(org.hisp.dhis.external.conf.DhisConfigurationProvider) PotentialDuplicateConflictException(org.hisp.dhis.deduplication.PotentialDuplicateConflictException) UserInfoSnapshot(org.hisp.dhis.program.UserInfoSnapshot) SessionFactory(org.hibernate.SessionFactory) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Audit(org.hisp.dhis.artemis.audit.Audit) Collectors(java.util.stream.Collectors) List(java.util.List) RelationshipItem(org.hisp.dhis.relationship.RelationshipItem) CurrentUserService(org.hisp.dhis.user.CurrentUserService) AclService(org.hisp.dhis.security.acl.AclService) Optional(java.util.Optional) Collections(java.util.Collections) AuditableEntity(org.hisp.dhis.artemis.audit.AuditableEntity) Relationship(org.hisp.dhis.relationship.Relationship) HashMap(java.util.HashMap) TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue)

Example 2 with AuditType

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

the class AuditMatrixConfigurer method configure.

public Map<AuditScope, Map<AuditType, Boolean>> configure() {
    Map<AuditScope, Map<AuditType, Boolean>> matrix = new HashMap<>();
    for (AuditScope value : AuditScope.values()) {
        Optional<ConfigurationKey> confKey = ConfigurationKey.getByKey(PROPERTY_PREFIX + value.name().toLowerCase());
        if (confKey.isPresent() && !StringUtils.isEmpty(config.getProperty(confKey.get()))) {
            String[] configuredTypes = config.getProperty(confKey.get()).split(AUDIT_TYPE_STRING_SEPAR);
            Map<AuditType, Boolean> matrixAuditTypes = new HashMap<>();
            for (AuditType auditType : AuditType.values()) {
                matrixAuditTypes.put(auditType, ArrayUtils.contains(configuredTypes, auditType.name()));
            }
            matrix.put(value, matrixAuditTypes);
        } else {
            matrix.put(value, DEFAULT_AUDIT_CONFIGURATION);
        }
    }
    return matrix;
}
Also used : ConfigurationKey(org.hisp.dhis.external.conf.ConfigurationKey) HashMap(java.util.HashMap) AuditType(org.hisp.dhis.audit.AuditType) AuditScope(org.hisp.dhis.audit.AuditScope) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

HashMap (java.util.HashMap)2 Map (java.util.Map)2 AuditScope (org.hisp.dhis.audit.AuditScope)2 AuditType (org.hisp.dhis.audit.AuditType)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 BigInteger (java.math.BigInteger)1 LocalDateTime (java.time.LocalDateTime)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Date (java.util.Date)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 SessionFactory (org.hibernate.SessionFactory)1 NativeQuery (org.hibernate.query.NativeQuery)1 Query (org.hibernate.query.Query)1 Audit (org.hisp.dhis.artemis.audit.Audit)1 AuditManager (org.hisp.dhis.artemis.audit.AuditManager)1 AuditableEntity (org.hisp.dhis.artemis.audit.AuditableEntity)1 CREATE (org.hisp.dhis.common.AuditType.CREATE)1