public static PropertyData CreateReferencedProperty( ResourceProperty property, string desc = null, string className = null, ResourceClassBase resource = null) { var propertyData = new PropertyData(property); var associations = resource == null || !resource.References.Any() ? property.EntityProperty.IncomingAssociations : resource.References.Where( r => r.Properties.Contains( property, ModelComparers.ResourcePropertyNameOnly)) .Select(r => r.Association) .ToList(); // we want to prioritize identifiers that are not optional. var association = associations .OrderBy(x => x.ThisProperties.Any(y => y.PropertyType.IsNullable)) .ThenBy(x => x.Name) .FirstOrDefault( x => x.PropertyMappingByThisName.ContainsKey(property.PropertyName) || x.PropertyMappingByThisName.ContainsKey(property.EntityProperty.PropertyName)); var parent = association != null ? association.PropertyMappingByThisName.ContainsKey(property.PropertyName) ? association.PropertyMappingByThisName[property.PropertyName] .OtherProperty : association.PropertyMappingByThisName.ContainsKey(property.EntityProperty.PropertyName) ? association.PropertyMappingByThisName[property.EntityProperty.PropertyName] .OtherProperty : null : null; string parentPropertyName = parent != null ? property.IsLookup ? parent.PropertyName.TrimSuffix("Id") : UniqueIdSpecification.GetUniqueIdPropertyName(parent.PropertyName) : property.ParentFullName.Name; propertyData[ResourceRenderer.ParentPropertyName] = UniqueIdSpecification.GetUniqueIdPropertyName(parentPropertyName); if (className != null) { propertyData[ResourceRenderer.ClassName] = className; } if (desc != null) { propertyData[ResourceRenderer.DescriptionOverride] = desc; } if (associations.Any()) { propertyData.Associations.AddRange(associations); } if (property.IsLookup) { propertyData[ResourceRenderer.RenderType] = ResourceRenderer.RenderUnified; propertyData[ResourceRenderer.MiscellaneousComment] = string.Format( "// IS in a reference ({0}.{1}Id), IS a lookup column ", className ?? property.EntityProperty.Entity.ResolvedEdFiEntityName(), property.PropertyName); } else { propertyData[ResourceRenderer.MiscellaneousComment] = "// IS in a reference, NOT a lookup column "; propertyData[ResourceRenderer.RenderType] = ResourceRenderer.RenderReferenced; } return(propertyData); }
public static object CreatePropertyDto(PropertyData propertyData) { switch (propertyData[ResourceRenderer.RenderType]) { case ResourceRenderer.RenderNull: return(new { Null = new { }, Property = propertyData.Render() }); case ResourceRenderer.RenderNullLookup: return(new { NullLookup = new { }, Property = propertyData.Render() }); case ResourceRenderer.RenderStandard: return(new { Standard = new { }, Property = propertyData.Render() }); case ResourceRenderer.RenderUnified: return(new { UnifiedType = new { }, Property = propertyData.Render() }); case ResourceRenderer.RenderUsi: return(new { Usi = new { }, Property = propertyData.Render() }); case ResourceRenderer.RenderReferenced: return(new { Referenced = new { }, Property = propertyData.Render() }); case ResourceRenderer.RenderDerived: return(new { Property = propertyData.Render(), Derived = new { } }); default: return(new { Property = propertyData.Render() }); } }
public object AssemblePrimaryKeys( ResourceProfileData profileData, ResourceClassBase resourceClass, TemplateContext templateContext) { if (profileData == null) { throw new ArgumentNullException(nameof(profileData)); } if (resourceClass == null) { throw new ArgumentNullException(nameof(resourceClass)); } if (templateContext == null) { throw new ArgumentNullException(nameof(templateContext)); } var pks = new List <object>(); var activeResource = profileData.GetProfileActiveResource(resourceClass); var filteredResource = profileData.GetContainedResource(resourceClass) ?? resourceClass; if (resourceClass is ResourceChildItem) { pks.Add( new { HasParent = ResourceRenderer.DoRenderProperty, Property = new { PropertyName = resourceClass.GetResourceInterfaceName( templateContext.GetSchemaProperCaseNameForResource(resourceClass), templateContext.IsProfiles, templateContext.IsExtension), ReferencesWithUnifiedKey = resourceClass.References .Where(@ref => @ref.Properties.Any(rp => rp.IsUnified())) .Select(@ref => new { ReferencePropertyName = @ref.PropertyName, ReferenceFieldName = @ref.PropertyName.ToCamelCase(), UnifiedKeyProperties = @ref.Properties .Where(rp => rp.IsUnified()) .Select(rp => new { UnifiedKeyPropertyName = rp.PropertyName }) }) } }); } var props = new List <PropertyData>(); foreach (var property in activeResource.AllProperties .Where(x => x.IsIdentifying) .OrderBy(x => x.PropertyName)) { if (activeResource.IsDescriptorEntity()) { props.Add(PropertyData.CreateDerivedProperty(property)); continue; } if (activeResource.IsAggregateRoot()) { if (resourceClass.IsDerived) { props.Add(AssembleDerivedProperty(property)); } else { props.Add( property.IsPersonOrUsi() && !templateContext.IsExtension ? PropertyData.CreateUsiPrimaryKey(property) : property.HasAssociations() && !property.IsDirectLookup ? PropertyData.CreateReferencedProperty(property, resource: filteredResource) : PropertyData.CreateStandardProperty(property)); } } else { // non aggregate root if (activeResource.References.Any()) { if (property.IsPersonOrUsi()) { props.Add(PropertyData.CreateUsiPrimaryKey(property)); continue; } if (resourceClass.HasBackReferences() && resourceClass.BackReferencedProperties() .Contains(property, ModelComparers.ResourcePropertyNameOnly)) { continue; } props.Add( property.HasAssociations() && !property.IsDirectLookup ? PropertyData.CreateReferencedProperty(property) : PropertyData.CreateStandardProperty(property)); } else { props.Add(PropertyData.CreateStandardProperty(property)); } } } pks.AddRange(CreatePropertyDtos(props)); return(pks.Any() ? new { Properties = pks } : ResourceRenderer.DoNotRenderProperty); }
private IEnumerable <PropertyData> CreateProperties(ResourceClassBase resourceClass) { var allPossibleProperties = resourceClass.FilterContext.UnfilteredResourceClass?.NonIdentifyingProperties ?? resourceClass.NonIdentifyingProperties; var currentProperties = resourceClass.AllProperties; var propertyPairs = (from p in allPossibleProperties join c in currentProperties on p.PropertyName equals c.PropertyName into leftJoin from _c in leftJoin.DefaultIfEmpty() where // Non-identifying properties only !p.IsIdentifying // Exclude boilerplate "id" property && !p.PropertyName.Equals("Id") // Exclude inherited properties && !p.IsInheritedProperty() orderby p.PropertyName select new { UnderlyingProperty = p, CurrentProperty = _c }) .ToList(); foreach (var propertyPair in propertyPairs) { // If the property was filtered out, then generate an explicit interface "Null" implementation only. if (propertyPair.CurrentProperty == null) { yield return(PropertyData.CreateNullProperty(propertyPair.UnderlyingProperty)); continue; } var property = propertyPair.CurrentProperty; if (property.IsSynchronizable()) { if (resourceClass.IsDescriptorEntity()) { if (!property.IsInheritedProperty()) { yield return(AssembleDerivedProperty(property)); } } else if (property.IsDirectLookup) { yield return(PropertyData.CreateStandardProperty(property)); } else { yield return (property.HasAssociations() ? PropertyData.CreateReferencedProperty(property) : PropertyData.CreateStandardProperty(property)); } } else { if (property.HasAssociations()) { yield return(property.IsLookup ? PropertyData.CreateStandardProperty(property) : PropertyData.CreateReferencedProperty(property)); } else { yield return(PropertyData.CreateStandardProperty(property)); } } } }
public object AssembleInheritedProperties( ResourceProfileData profileData, ResourceClassBase resource) { if (profileData == null) { throw new ArgumentNullException(nameof(profileData)); } if (resource == null) { throw new ArgumentNullException(nameof(resource)); } IList <ResourcePropertyData> includedProperties = null; if (profileData.HasProfile) { includedProperties = (resource.Name == profileData.SuppliedResource.Name ? profileData.UnfilteredResource : resource).InheritedProperties() .Where(x => !x.IsIdentifying && !x.PropertyName.Equals("Id")) .OrderBy(x => x.PropertyName) .Select( x => new ResourcePropertyData { Property = x, IsStandardProperty = !profileData.IsIncluded(resource, x) }) .ToList(); } else { includedProperties = resource.InheritedProperties() .OrderBy(x => x.PropertyName) .Where(x => !x.IsIdentifying && !x.PropertyName.Equals("Id")) .Select( x => new ResourcePropertyData { Property = x, IsStandardProperty = false }) .ToList(); } var propertiesToRender = new List <PropertyData>(); if (resource.IsDescriptorEntity() && resource.InheritedProperties() .Any(x => !x.IsIdentifying && !x.PropertyName.Equals("Id"))) { propertiesToRender.AddRange( includedProperties.Select( x => { var propertyData = x.IsStandardProperty ? PropertyData.CreateNullProperty(x.Property) : PropertyData.CreateStandardProperty(x.Property); propertyData[ResourceRenderer.MiscellaneousComment] = "// NOT in a reference, NOT a lookup column "; return(propertyData); })); } else if (resource.IsDerived) { propertiesToRender.AddRange( includedProperties.Select( x => x.IsStandardProperty ? PropertyData.CreateNullProperty(x.Property) : PropertyData.CreateStandardProperty(x.Property))); } return(propertiesToRender.Any() ? new { Properties = CreatePropertyDtos(propertiesToRender) } : ResourceRenderer.DoNotRenderProperty); }