private PropertyData AssembleDerivedProperty(ResourceProperty property) { var propertyData = PropertyData.CreateDerivedProperty(property); if (property.EntityProperty.IsInheritedIdentifyingRenamed) { return(propertyData); } if (property.IsInherited) { var baseProperty = property.BaseEntityProperty(); if (!baseProperty.IncomingAssociations.Any()) { propertyData[ResourceRenderer.RenderType] = ResourceRenderer.RenderStandard; return(propertyData); } return(PropertyData.CreateReferencedProperty( baseProperty.ToResourceProperty(property.Parent), UniqueIdSpecification.IsUniqueId(property.PropertyName) ? string.Format( "A unique alphanumeric code assigned to a {0}.", property.RemoveUniqueIdOrUsiFromPropertyName() .ToCamelCase()) : property.Description.ScrubForXmlDocumentation(), property.Parent.Name)); } propertyData[ResourceRenderer.RenderType] = ResourceRenderer.RenderStandard; return(propertyData); }
public static int?GetMaxLength(ResourceProperty resourceProperty) { if (UniqueIdSpecification.IsUniqueId(resourceProperty.JsonPropertyName)) { return(32); } return(resourceProperty.PropertyType.ToCSharp().EqualsIgnoreCase("string") && resourceProperty.PropertyType.MaxLength > 0 ? resourceProperty.PropertyType.MaxLength : (int?)null); }
private string GetImplementedInterfaceString(ResourceClassBase resourceClass) { var interfaceStringBuilder = new StringBuilder(); if (resourceClass.Entity?.IsDerived == true) { AddInterface( $"{resourceClass.Entity.BaseEntity.SchemaProperCaseName()}.I{resourceClass.Entity.BaseEntity.Name}", interfaceStringBuilder); } if (resourceClass.Entity?.IsAbstractRequiringNoCompositeId() != true) { AddInterface("ISynchronizable", interfaceStringBuilder); AddInterface("IMappable", interfaceStringBuilder); } // We want to exclude base concrete classes, descriptors and types from extensions. if (resourceClass.IsExtendable()) { AddInterface("IHasExtensions", interfaceStringBuilder); } if (resourceClass is Resource) { AddInterface("IHasIdentifier", interfaceStringBuilder); } if (resourceClass.Properties.Where(p => p.IsIdentifying) .Any(p => UniqueIdSpecification.IsUniqueId(p.PropertyName) && p.IsLocallyDefined)) { AddInterface("IIdentifiablePerson", interfaceStringBuilder); } AddInterface("IGetByExample", interfaceStringBuilder); return(interfaceStringBuilder.ToString()); }
public object Render() { AssociationView derivedBaseProperty = Property.DerivedBaseProperty(); var derivedName = derivedBaseProperty != null ? derivedBaseProperty.OtherEntity.Name : null; var desc = this[ResourceRenderer.DescriptionOverride] != null ? this[ResourceRenderer.DescriptionOverride] .ScrubForXmlDocumentation() : UniqueIdSpecification.IsUniqueId(Property.PropertyName) ? string.Format( "A unique alphanumeric code assigned to a {0}.", Property.RemoveUniqueIdOrUsiFromPropertyName() .ToLower()) : Property.Description.ScrubForXmlDocumentation(); var propertyNamespacePrefix = Property.ProperCaseSchemaName() == null ? null : $"{Namespaces.Entities.Common.RelativeNamespace}.{Property.ProperCaseSchemaName()}."; return(new { Description = desc, Misc = this[ResourceRenderer.MiscellaneousComment], JsonPropertyName = Property.JsonPropertyName, PropertyName = IsReferencedProperty ? string.Format( "backReference.{0} != null && backReference.{0}.{1}", Property.EntityProperty.Entity.Aggregate.Name, Property.PropertyName) : Property.PropertyName, CSharpSafePropertyName = Property.PropertyName.MakeSafeForCSharpClass(Property.ParentFullName.Name), ParentName = Property.EntityProperty.IsFromParent ? Property.EntityProperty.Entity.Parent.Name : Property.EntityProperty.Entity.Name, PropertyFieldName = Property.EntityProperty.Entity .ResolvedEdFiEntityName() .ToCamelCase(), PropertyType = Property.PropertyType.ToCSharp(true), IsFirstProperty = IsFirstProperty, IsLastProperty = IsLastProperty, IsUnique = IsUnique, NumericAttribute = Property.ToRangeAttributeCSharp(), IsDateOnlyProperty = Property.PropertyType.DbType == DbType.Date, IsTimeSpanProperty = Property.PropertyType.DbType == DbType.Time, ClassName = this[ResourceRenderer.ClassName] ?? Property.EntityProperty.Entity .ResolvedEdFiEntityName(), UnifiedKeys = Associations.Any() ? AssembleOtherUnifiedChild(Associations) : null, UnifiedExtensions = ExtensionAssociations.Any() ? AssembleOtherUnifiedChild(ExtensionAssociations) : null, ImplicitPropertyName = Associations.Any() ? Associations.OrderByDescending(x => x.IsRequired) .First() .Name : null, ImplicitNullable = Property.PropertyType.IsNullableCSharpType() ? ".GetValueOrDefault()" : null, ParentPropertyName = this[ResourceRenderer.ParentPropertyName], DerivedName = derivedName, PropertyNamespacePrefix = propertyNamespacePrefix, NullPropertyPrefix = Property.EntityProperty.Entity.IsEntityExtension ? $"{propertyNamespacePrefix}I{Property.EntityProperty.Entity.Name}." : $"{propertyNamespacePrefix}I{Property.EntityProperty.Entity.ResolvedEdFiEntityName()}." }); }
public static string PropertyDescription(ResourceProperty resourceProperty) => UniqueIdSpecification.IsUniqueId(resourceProperty.JsonPropertyName) ? $"A unique alphanumeric code assigned to a {UniqueIdSpecification.RemoveUniqueIdSuffix(resourceProperty.JsonPropertyName.ScrubForOpenApi()).ToLower()}." : resourceProperty.Description .ScrubForOpenApi();
public static string PropertyFormat(ResourceProperty resourceProperty) => UniqueIdSpecification.IsUniqueId(resourceProperty.JsonPropertyName) ? null : resourceProperty.PropertyType.ToOpenApiFormat();
public static string PropertyType(ResourceProperty resourceProperty) => resourceProperty.IsLookup || UniqueIdSpecification.IsUniqueId(resourceProperty.JsonPropertyName) ? "string" : resourceProperty.PropertyType.ToOpenApiType();
/// <summary> /// Removes the trailing uniquid or usi from the property name. /// </summary> /// <param name="property"></param> /// <returns></returns> public static string RemoveUniqueIdOrUsiFromPropertyName(this ResourceProperty property) { return(UniqueIdSpecification.IsUniqueId(property.PropertyName) ? UniqueIdSpecification.RemoveUniqueIdSuffix(property.PropertyName) : UniqueIdSpecification.RemoveUsiSuffix(property.PropertyName)); }
/// <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))); }
private static bool IsDefiningUniqueId(ResourceClassBase resourceClass, ResourceProperty property) { return(UniqueIdSpecification.IsUniqueId(property.PropertyName) && PersonEntitySpecification.IsPersonEntity(resourceClass.Name)); }
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); } } }
protected override object Build() { var resourceClassesToRender = ResourceModelProvider.GetResourceModel() .GetAllResources() .SelectMany( r => r.AllContainedItemTypesOrSelf.Where( i => TemplateContext.ShouldRenderResourceClass(i) // Don't render artifacts for base class children in the context of derived resources && !i.IsInheritedChildItem())) .OrderBy(r => r.Name) .ToList(); var entityInterfacesModel = new { EntitiesBaseNamespace = EdFiConventions.BuildNamespace( Namespaces.Entities.Common.BaseNamespace, TemplateContext.SchemaProperCaseName), Interfaces = resourceClassesToRender .Where(TemplateContext.ShouldRenderResourceClass) .Select( r => new { r.FullName.Schema, r.Name, AggregateName = r.Name, ImplementedInterfaces = GetImplementedInterfaceString(r), ParentInterfaceName = GetParentInterfaceName(r), ParentClassName = GetParentClassName(r), IdentifyingProperties = r .IdentifyingProperties // Exclude inherited identifying properties where the property has not been renamed .Where( p => !( p.EntityProperty ?.IsInheritedIdentifying == true && !p .EntityProperty ?.IsInheritedIdentifyingRenamed == true)) .OrderBy( p => p .PropertyName) .Select( p => new { p.IsServerAssigned, IsUniqueId = UniqueIdSpecification .IsUniqueId( p.PropertyName) && PersonEntitySpecification .IsPersonEntity( r.Name), p.IsLookup, CSharpType = p .PropertyType .ToCSharp( false), Name = p .PropertyName, CSharpSafePropertyName = p .PropertyName .MakeSafeForCSharpClass( r.Name), LookupName = p .PropertyName }) .ToList(), r.IsDerived, InheritedNonIdentifyingProperties = r.IsDerived ? r.AllProperties .Where(p => p.IsInherited && !p.IsIdentifying) .OrderBy(p => p.PropertyName) .Where(IsModelInterfaceProperty) .Select( p => new { p.IsLookup, CSharpType = p.PropertyType.ToCSharp(true), Name = p.PropertyName, LookupName = p.PropertyName.TrimSuffix("Id") }) .ToList() : null, NonIdentifyingProperties = r.NonIdentifyingProperties .Where(p => !p.IsInherited) .OrderBy(p => p.PropertyName) .Where(IsModelInterfaceProperty) .Select( p => new { p.IsLookup, CSharpType = p.PropertyType.ToCSharp(true), Name = p.PropertyName, CSharpSafePropertyName = p.PropertyName .MakeSafeForCSharpClass(r.Name), LookupName = p.PropertyName.TrimSuffix("Id") }) .ToList(), HasNavigableOneToOnes = r.EmbeddedObjects.Any(), NavigableOneToOnes = r .EmbeddedObjects .Where(eo => !eo.IsInherited) .OrderBy( eo => eo .PropertyName) .Select( eo => new { Name = eo .PropertyName }) .ToList(), InheritedLists = r.IsDerived ? r.Collections .Where(c => c.IsInherited) .OrderBy(c => c.PropertyName) .Select( c => new { c.ItemType.Name, PluralName = c.PropertyName }) .ToList() : null, Lists = r.Collections .Where(c => !c.IsInherited) .OrderBy(c => c.PropertyName) .Select( c => new { c.ItemType.Name, PluralName = c.PropertyName }) .ToList(), HasDiscriminator = r.HasDiscriminator(), AggregateReferences = r.Entity?.GetAssociationsToReferenceableAggregateRoots() .OrderBy(a => a.Name) .Select( a => new { AggregateReferenceName = a.Name, MappedReferenceDataHasDiscriminator = a.OtherEntity.HasDiscriminator() }) .ToList() }) .ToList() }; return(entityInterfacesModel); }