protected void ExcludeRelationData(System.Type entityType, string property) { var member = getMemberOrThrow(entityType, property); var attr = new AuditedAttribute { TargetAuditMode = RelationTargetAuditMode.NotAudited }; AttributeCollection.Add(new MemberInfoAndAttribute(entityType, member, attr)); }
public IFluentAudit <T> ExcludeRelationData(Expression <Func <T, object> > property) { var methodInfo = property.MethodInfo(); var attr = new AuditedAttribute { TargetAuditMode = RelationTargetAuditMode.NotAudited }; AttributeCollection.Add(new MemberInfoAndAttribute(typeof(T), methodInfo, attr)); return(this); }
private ModificationStore getDefaultAudited(System.Type typ) { AuditedAttribute defaultAudited = (AuditedAttribute)Attribute.GetCustomAttribute(typ, typeof(AuditedAttribute)); //AuditedAttribute defaultAudited = typ.GetCustomAttributes(typeof(AuditedAttribute),); if (defaultAudited != null) { return(defaultAudited.ModStore); } else { return(ModificationStore._NULL); } }
/// <summary> /// Checks if a property is audited and if yes, fills all of its data. /// </summary> /// <param name="property">Property to check.</param> /// <param name="mappedPropertyName">NH Property name</param> /// <param name="propertyData">Property data, on which to set this property's modification store.</param> /// <param name="accessType">Access type for the property.</param> /// <param name="allClassAudited">Is class fully audited</param> /// <returns>False if this property is not audited.</returns> private bool fillPropertyData(MemberInfo property, string mappedPropertyName, PropertyAuditingData propertyData, string accessType, AuditedAttribute allClassAudited) { // check if a property is declared as not audited to exclude it // useful if a class is audited but some properties should be excluded if ((_metaDataStore.MemberMeta <NotAuditedAttribute>(property) != null && !_overriddenAuditedProperties.Contains(mappedPropertyName)) || _overriddenNotAuditedProperties.Contains(mappedPropertyName)) { return(false); } // if the optimistic locking field has to be unversioned and the current property // is the optimistic locking field, don't audit it if (_globalCfg.DoNotAuditOptimisticLockingField && _persistentPropertiesSource.VersionedProperty != null && _persistentPropertiesSource.VersionedProperty.Name.Equals(mappedPropertyName)) { return(false); } if (!CheckAudited(property, mappedPropertyName, propertyData, allClassAudited)) { return(false); } var propertyName = _propertyNamePrefix + mappedPropertyName; propertyData.Name = propertyName; propertyData.ModifiedFlagName = MetadataTools.ModifiedFlagPropertyName(propertyName, _globalCfg.ModifiedFlagSuffix); propertyData.BeanName = mappedPropertyName; propertyData.AccessType = accessType; addPropertyJoinTables(property, propertyData); addPropertyAuditingOverrides(property, propertyData); if (!processPropertyAuditingOverrides(property, propertyData)) { return(false); // not audited due to AuditOverride annotation } setPropertyAuditMappedBy(property, propertyData); setCustomMapper(property, propertyData); return(true); }
protected virtual bool CheckAudited(MemberInfo property, string mappedPropertyName, PropertyAuditingData propertyData, AuditedAttribute allClassAudited) { // Checking if this property is explicitly audited or if all properties are. var aud = _metaDataStore.MemberMeta <AuditedAttribute>(property) ?? allClassAudited; if (aud == null && _overriddenAuditedProperties.Contains(mappedPropertyName) && !_overriddenNotAuditedProperties.Contains(mappedPropertyName)) { // Assigning AuditedAttribute defaults. If anyone needs to customize those values in the future, // appropriate fields shall be added to AuditOverrideAttribute annotation. aud = new AuditedAttribute(); } if (aud != null) { propertyData.RelationTargetAuditMode = aud.TargetAuditMode; propertyData.UsingModifiedFlag = checkUsingModifiedFlag(aud); return(true); } return(false); }
private void addFromProperties(AuditedAttribute allClassAudited, System.Type currentClass) { foreach (var declaredPersistentProperty in _persistentPropertiesSource.DeclaredPersistentProperties) { // If the property was already defined by the subclass, is ignored by superclasses if (_auditedPropertiesHolder.Contains(declaredPersistentProperty.Property.Name)) { continue; } //only get the property on specific class if not a component if ((declaredPersistentProperty.Member.DeclaringType != currentClass && !_persistentPropertiesSource.IsComponent) && !declaredPersistentProperty.Member.Equals(DeclaredPersistentProperty.NotAvailableMemberInfo) && !_overriddenAuditedProperties.Contains(declaredPersistentProperty.Property.Name)) { continue; } var propertyValue = declaredPersistentProperty.Property.Value; var componentValue = propertyValue as Component; if (componentValue != null) { if (declaredPersistentProperty.Member.Equals(DeclaredPersistentProperty.NotAvailableMemberInfo)) { addFromPropertiesGroup(declaredPersistentProperty, componentValue, allClassAudited); } else { addFromComponentProperty(declaredPersistentProperty, componentValue, allClassAudited); } } else { addFromNotComponentProperty(declaredPersistentProperty, allClassAudited); } } }
protected override bool CheckAudited(MemberInfo property, string mappedPropertyName, PropertyAuditingData propertyData, AuditedAttribute allClassAudited) { // Checking if this property is explicitly audited or if all properties are. var aud = _metaDataStore.MemberMeta <AuditedAttribute>(property); if (aud != null) { propertyData.RelationTargetAuditMode = aud.TargetAuditMode; } return(true); }
/** * Checks if a property is audited and if yes, fills all of its data. * @param property Property to check. * @param propertyData Property data, on which to set this property's modification store. * @param accessType Access type for the property. * @return False if this property is not audited. */ private bool FillPropertyData(PropertyInfo property, PropertyAuditingData propertyData, String accessType) { // check if a property is declared as not audited to exclude it // useful if a class is audited but some properties should be excluded NotAuditedAttribute unVer = (NotAuditedAttribute)Attribute.GetCustomAttribute(property, typeof(NotAuditedAttribute)); if (unVer != null) { return(false); } else { // if the optimistic locking field has to be unversioned and the current property // is the optimistic locking field, don't audit it if (_globalCfg.isDoNotAuditOptimisticLockingField()) { //Version jpaVer = property.getAnnotation(typeof(Version)); VersionAttribute jpaVer = (VersionAttribute)Attribute.GetCustomAttribute(property, typeof(VersionAttribute)); if (jpaVer != null) { return(false); } } } // Checking if this property is explicitly audited or if all properties are. //AuditedAttribute aud = property.getAnnotation(typeof(AuditedAttribute)); AuditedAttribute aud = (AuditedAttribute)Attribute.GetCustomAttribute(property, typeof(AuditedAttribute)); if (aud != null) { propertyData.Store = aud.ModStore; propertyData.setRelationTargetAuditMode(aud.TargetAuditMode); } else { if (_defaultStore != ModificationStore._NULL) { propertyData.Store = _defaultStore; } else { return(false); } } propertyData.Name = _propertyNamePrefix + property.Name; propertyData.BeanName = property.Name; propertyData.AccessType = accessType; AddPropertyJoinTables(property, propertyData); AddPropertyAuditingOverrides(property, propertyData); if (!ProcessPropertyAuditingOverrides(property, propertyData)) { return(false); // not audited due to AuditOverride annotation } AddPropertyMapKey(property, propertyData); SetPropertyAuditMappedBy(property, propertyData); return(true); }
private bool checkUsingModifiedFlag(AuditedAttribute aud) { return(_globalCfg.IsGlobalWithModifiedFlag || aud.WithModifiedFlag); }
private void addFromNotComponentProperty(DeclaredPersistentProperty property, AuditedAttribute allClassAudited) { var propertyData = new PropertyAuditingData(); var isAudited = fillPropertyData(property.Member, property.Property.Name, propertyData, property.Property.PropertyAccessorName, allClassAudited); if (isAudited) { // Now we know that the property is audited _auditedPropertiesHolder.AddPropertyAuditingData(property.Property.Name, propertyData); } }
private void addFromComponentProperty(DeclaredPersistentProperty property, Component componentValue, AuditedAttribute allClassAudited) { var componentData = new ComponentAuditingData(); var isAudited = fillPropertyData(property.Member, property.Property.Name, componentData, property.Property.PropertyAccessorName, allClassAudited); var componentPropertiesSource = new ComponentPropertiesSource(componentValue); var audPropReader = new ComponentAuditedPropertiesReader(_metaDataStore, componentPropertiesSource, componentData, _globalCfg, _propertyNamePrefix + MappingTools.CreateComponentPrefix(property.Property.Name)); audPropReader.Read(); if (isAudited) { // Now we know that the property is audited _auditedPropertiesHolder.AddPropertyAuditingData(property.Property.Name, componentData); } }