/// <summary> /// Indicates whether the supplied property name is one that should be included /// in the resource model. /// </summary> /// <param name="entityPropertyName">The name of the property to be evaluated.</param> /// <returns><b>true</b> if the property is allowed to appear in the resource; otherwise <b>false</b>.</returns> public static bool IsAllowableResourceProperty(string entityPropertyName) { // Exclude boilerplate dates from resources return(!(entityPropertyName.EqualsIgnoreCase("LastModifiedDate") || entityPropertyName.EqualsIgnoreCase("CreateDate") || UniqueIdSpecification.IsUSI(entityPropertyName))); }
private bool ShouldIncludeInQueryCriteria(PropertyDescriptor property, object value, TEntity entity) { // Null values and underscore-prefixed properties are ignored for specification purposes if (value == null || property.Name.StartsWith("_") || "|Url|".Contains(property.Name)) { // TODO: Come up with better way to exclude non-data properties return(false); } Type valueType = value.GetType(); // Only use value types (or strings), and non-default values (i.e. ignore 0's) var result = (valueType.IsValueType || valueType == typeof(string)) && (!value.Equals(valueType.GetDefaultValue()) || UniqueIdSpecification.IsUSI(property.Name) && GetPropertyValue(entity, UniqueIdSpecification.GetUniqueIdPropertyName(property.Name)) != null); // Don't include properties that are explicitly to be ignored result = result && !_propertiesToIgnore.Contains(property.Name); // Don't include UniqueId properties when they appear on a Person entity result = result && (!_uniqueIdProperties.Contains(property.Name) || PersonEntitySpecification.IsPersonEntity(entity.GetType())); return(result); }
private bool IsUsiWithTransformedResourcePropertyName(EntityProperty property) { //Not: Use C# 7 '_' wildcard instead when available. string notUsed; //If the resource property name was flipped to a UniqueId for this USI property return(UniqueIdSpecification.IsUSI(property.PropertyName) && UniqueIdSpecification.TryGetUniqueIdPersonType(PropertyName, out notUsed)); }
private IEnumerable <KeyValuePair <string, object> > EnumerateKeyValuePairs( Hashtable sourceRow, NullValueHandling nullValueHandling, IEnumerable <string> keysToProcess, Dictionary <string, object> descriptorNamespaceByKey, HashSet <string> selectedKeys) { foreach (string key in keysToProcess) { string renamedKey = null; // Handle Pass through values if (key.EndsWith(CompositeDefinitionHelper.PassThroughMarker)) { renamedKey = key.TrimSuffix(CompositeDefinitionHelper.PassThroughMarker); yield return(new KeyValuePair <string, object>(renamedKey ?? key, sourceRow[key])); } else { // Remove null values, if appropriate object value; if (sourceRow[key] == null) { if (nullValueHandling == NullValueHandling.Include) { value = sourceRow[key]; } else { continue; } } else { if (descriptorNamespaceByKey.TryGetValue(key, out object namespaceForDescriptor)) { value = EdFiDescriptorReferenceSpecification.GetFullyQualifiedDescriptorReference( namespaceForDescriptor.ToString(), sourceRow[key] .ToString()); } else { // See if we need to convert an USI to a UniqueId if (UniqueIdSpecification.IsUSI(key) && UniqueIdSpecification.TryGetUSIPersonTypeAndRoleName(key, out string personType, out string roleName)) { // Translate to UniqueId string uniqueId = _personUniqueIdToUsiCache.GetUniqueId(personType, (int)sourceRow[key]); string uniqueIdKey = (roleName + personType + CompositeDefinitionHelper.UniqueId).ToCamelCase(); renamedKey = uniqueIdKey; value = uniqueId; }
private IEnumerable <AuthorizationContextProperty> UniqueIdProperties(Resource resource) { return(resource.Entity.Properties.Where(p => UniqueIdSpecification.IsUSI(p.PropertyName)) .Select( p => new AuthorizationContextProperty { PropertyName = p.PropertyName, PropertyType = "int", IsIdentifying = p.IsIdentifying, IsIncluded = p.IsIdentifying, Reason = p.IsIdentifying ? "USI" : "Not part of primary key" })); }
/// <summary> /// Will convert a USI property to a UniqueID format /// If the property is not a USI type property, then an exception is thrown. /// </summary> /// <param name="usiPropertyName"></param> /// <returns></returns> public static string ConvertToUniqueId(this string usiPropertyName) { if (!UniqueIdSpecification.IsUSI(usiPropertyName)) { throw new ArgumentException( string.Format( "Supplied property '{0}' is not an USI property.", usiPropertyName)); } return(UniqueIdSpecification.GetUniqueIdPropertyName(usiPropertyName)); }
private static PropertyType GetBasePersonUniqueIdPropertyType(EntityProperty property) { //we need to go find the correct PropertyType information by looking through //the incoming associations for the ones that have the USI property //and walking those entities until we find the person type that is the base of this //property, then return the entity's unique id property's property type from there. return(GetNestedPersonEntityProperty(property, property.PropertyName) .Entity.Properties .Where(x => !UniqueIdSpecification.IsUSI(x.PropertyName) && PersonEntitySpecification.IsPersonIdentifier(x.PropertyName)) .Select(x => x.PropertyType) .Single()); }
private static string GetResourcePropertyName(EntityProperty property) { // Simplistic conversion using conventions if (property.IsLookup) { return(property.PropertyName.TrimSuffix("Id")); } // Convert USIs to UniqueIds everywhere but on the people if (UniqueIdSpecification.IsUSI(property.PropertyName) && !PersonEntitySpecification.IsPersonEntity(property.Entity.Name)) { return(property.PropertyName.Replace("USI", "UniqueId")); } return(property.PropertyName); }
protected ResourceMemberBase(ResourceClassBase resourceClass, string propertyName) { ResourceClass = resourceClass; PropertyName = propertyName; _jsonPropertyName = new Lazy <string>( () => { var jsonPropertyName = ResourceClass.AllProperties.Any(x => x.PropertyName == PropertyName) || ResourceClass.MemberNamesInvolvedInJsonCollisions.Contains(PropertyName) ? PropertyName.ToCamelCase() : JsonNamingConvention.ProposeJsonPropertyName(ParentFullName.Name, PropertyName); return(UniqueIdSpecification.IsUSI(jsonPropertyName) ? UniqueIdSpecification.GetUniqueIdPropertyName(jsonPropertyName) : jsonPropertyName); }); }
/// <summary> /// Checks to see if the property is an USI property or a UniqueId, and if the property is a person entity, similar as EntityMapper.IsDefiningUniqueId /// </summary> /// <param name="property"></param> /// <returns></returns> public static bool IsDefiningUniqueIdOrUsi(this ResourceProperty property) { return(property.Parent.Entity?.IsPersonEntity() == true && (UniqueIdSpecification.IsUniqueId(property.PropertyName) || UniqueIdSpecification.IsUSI(property.PropertyName))); }
public static IEnumerable <EntityProperty> TransformUsisToUniqueIds(this IEnumerable <EntityProperty> properties) { var suppliedProperties = properties.ToList(); // Return an empty enumerable if there aren't any properties in the source if (!suppliedProperties.Any()) { yield break; } var containingEntity = suppliedProperties .Select(x => x.Entity) .FirstOrDefault(x => x != null); if (containingEntity == null) { throw new InvalidOperationException("None of the properties supplied have an associated Entity."); } foreach (var entityProperty in suppliedProperties) { // If column is an USI column... if (UniqueIdSpecification.IsUSI(entityProperty.PropertyName)) { string uniqueIdPropertyName = entityProperty.PropertyName.ConvertToUniqueId(); // Find a corresponding UniqueId column, if it exists var correspondingUniqueIdProperty = containingEntity .Properties .SingleOrDefault(p => p.PropertyName.EqualsIgnoreCase(uniqueIdPropertyName)); if (correspondingUniqueIdProperty != null) { // Swap the UniqueId column in for the USI yield return(correspondingUniqueIdProperty); continue; } // Replace the USI column with a newly created UniqueId column yield return (new EntityProperty(uniqueIdPropertyName, new PropertyType(DbType.AnsiString, 32, entityProperty.PropertyType.IsNullable), string.Format("A unique alpha-numeric code assigned to a {0}.", entityProperty.Entity.Name))); } else if (UniqueIdSpecification.IsUniqueId(entityProperty.PropertyName)) { string usiPropertyName = UniqueIdSpecification.GetUsiPropertyName(entityProperty.PropertyName); // Find a corresponding USI column, if it exists var correspondingUsiProperty = containingEntity .Properties .SingleOrDefault(p => p.PropertyName.EqualsIgnoreCase(usiPropertyName)); // If a corresponding USI property exists, then skip the UniqueId (it's been returned for use wherever the USI had been used) if (correspondingUsiProperty != null) { continue; } yield return(entityProperty); } else { yield return(entityProperty); } } }
/// <summary> /// Checks to see if the property is an USI property or if the property is a person entity /// </summary> /// <param name="property"></param> /// <returns></returns> public static bool IsPersonOrUsi(this ResourceProperty property) { return(property.Parent.Entity.IsPersonEntity() || UniqueIdSpecification.IsUSI(property.PropertyName)); }