Search in sources :

Example 6 with Audited

use of org.hibernate.envers.Audited in project CzechIdMng by bcvsolutions.

the class IdmAuditStrategy method fillAbstractAuditedFields.

/**
 * Method initialize list with all audited fields from {@link AbstractEntity}.
 * The initialization will be done only once.
 *
 * @param auditCfg
 */
private void fillAbstractAuditedFields(AuditConfiguration auditCfg) {
    if (auditedFieldsFromAbstractEntity == null) {
        String modifiedFlagSuffix = auditCfg.getGlobalCfg().getModifiedFlagSuffix();
        // 
        auditedFieldsFromAbstractEntity = new ArrayList<>();
        // 
        for (Field field : AbstractEntity.class.getDeclaredFields()) {
            Audited annotation = field.getAnnotation(Audited.class);
            if (annotation != null) {
                auditedFieldsFromAbstractEntity.add(field.getName() + modifiedFlagSuffix);
            }
        }
    }
}
Also used : Field(java.lang.reflect.Field) Audited(org.hibernate.envers.Audited)

Example 7 with Audited

use of org.hibernate.envers.Audited in project hibernate-orm by hibernate.

the class AuditedPropertiesReader method addPropertiesFromClass.

/**
 * Recursively adds all audited properties of entity class and its superclasses.
 *
 * @param clazz Currently processed class.
 */
private void addPropertiesFromClass(XClass clazz) {
    final Audited allClassAudited = computeAuditConfiguration(clazz);
    // look in the class
    addFromProperties(clazz.getDeclaredProperties("field"), it -> "field", fieldAccessedPersistentProperties, allClassAudited);
    addFromProperties(clazz.getDeclaredProperties("property"), propertyAccessedPersistentProperties::get, propertyAccessedPersistentProperties.keySet(), allClassAudited);
    if (allClassAudited != null || !auditedPropertiesHolder.isEmpty()) {
        final XClass superclazz = clazz.getSuperclass();
        if (!clazz.isInterface() && !"java.lang.Object".equals(superclazz.getName())) {
            addPropertiesFromClass(superclazz);
        }
    }
}
Also used : Audited(org.hibernate.envers.Audited) NotAudited(org.hibernate.envers.NotAudited) XClass(org.hibernate.annotations.common.reflection.XClass)

Example 8 with Audited

use of org.hibernate.envers.Audited in project hibernate-orm by hibernate.

the class AuditedPropertiesReader method addPropertiesFromDynamicComponent.

private void addPropertiesFromDynamicComponent(DynamicComponentSource dynamicComponentSource) {
    Audited audited = computeAuditConfiguration(dynamicComponentSource.getXClass());
    if (!fieldAccessedPersistentProperties.isEmpty()) {
        throw new MappingException("Audited dynamic component cannot have properties with access=\"field\" for properties: " + fieldAccessedPersistentProperties + ". \n Change properties access=\"property\", to make it work)");
    }
    for (Map.Entry<String, String> entry : propertyAccessedPersistentProperties.entrySet()) {
        String property = entry.getKey();
        String accessType = entry.getValue();
        if (!auditedPropertiesHolder.contains(property)) {
            final Value propertyValue = persistentPropertiesSource.getProperty(property).getValue();
            if (propertyValue instanceof Component) {
                this.addFromComponentProperty(new DynamicProperty(dynamicComponentSource, property), accessType, (Component) propertyValue, audited);
            } else {
                this.addFromNotComponentProperty(new DynamicProperty(dynamicComponentSource, property), accessType, audited);
            }
        }
    }
}
Also used : Audited(org.hibernate.envers.Audited) NotAudited(org.hibernate.envers.NotAudited) Value(org.hibernate.mapping.Value) Component(org.hibernate.mapping.Component) Map(java.util.Map) Tools.newHashMap(org.hibernate.envers.internal.tools.Tools.newHashMap) MappingException(org.hibernate.MappingException)

Aggregations

Audited (org.hibernate.envers.Audited)8 NotAudited (org.hibernate.envers.NotAudited)4 XClass (org.hibernate.annotations.common.reflection.XClass)3 Field (java.lang.reflect.Field)2 MappingException (org.hibernate.MappingException)2 IdmAudit (eu.bcvsolutions.idm.core.audit.entity.IdmAudit)1 PropertyDescriptor (java.beans.PropertyDescriptor)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 EntityNotFoundException (javax.persistence.EntityNotFoundException)1 Document (org.dom4j.Document)1 ClassLoadingException (org.hibernate.annotations.common.reflection.ClassLoadingException)1 XProperty (org.hibernate.annotations.common.reflection.XProperty)1 AuditOverride (org.hibernate.envers.AuditOverride)1 DefaultRevisionEntity (org.hibernate.envers.DefaultRevisionEntity)1 DefaultTrackingModifiedEntitiesRevisionEntity (org.hibernate.envers.DefaultTrackingModifiedEntitiesRevisionEntity)1 RevisionEntity (org.hibernate.envers.RevisionEntity)1 SequenceIdRevisionEntity (org.hibernate.envers.enhanced.SequenceIdRevisionEntity)1