Пример #1
0
        private object BuildMapper(ResourceClassBase resourceClass)
        {
            return(new
            {
                ModelName = resourceClass.Name,
                ModelParentName = resourceClass.Entity?.Parent?.Name ?? resourceClass.Name.TrimSuffix("Extension"),
                ExtensionName = TemplateContext.SchemaProperCaseName, IsEntityExtension = resourceClass.IsResourceExtensionClass,
                BaseClassName = resourceClass.Entity?.BaseEntity?.Name, AllowPrimaryKeyUpdates = resourceClass.Entity?.Identifier.IsUpdatable,
                AnnotatedLocalPrimaryKeyList = AnnotateLocalIdentifyingPropertyKeys(resourceClass.Entity), BackSynchedPrimaryKeyList =
                    resourceClass.IdentifyingProperties
                    .Where(p => !IsDefiningUniqueId(resourceClass, p))
                    .OrderBy(x => x.PropertyName)
                    .Select(
                        x => new
                {
                    CSharpSafePrimaryKeyName = x.PropertyName.MakeSafeForCSharpClass(resourceClass.Name)
                }),
                IsDerivedEntity = resourceClass.Entity?.IsDerived, BaseClassNonPkPropertyList = resourceClass.NonIdentifyingProperties
                                                                                                .Where(
                    p => p.IsInherited &&
                    p.IsSynchronizedProperty())
                                                                                                .OrderBy(p => p.PropertyName)
                                                                                                .Select(
                    p => new
                {
                    BasePropertyName =
                        p.PropertyName
                }),
                NonPrimaryKeyList = resourceClass.NonIdentifyingProperties
                                    .Where(p => !p.IsInherited && p.IsSynchronizedProperty())

                                    // Add mappings for UniqueId values defined on Person resources
                                    .Concat(resourceClass.IdentifyingProperties.Where(p => IsDefiningUniqueId(resourceClass, p)))
                                    .OrderBy(p => p.PropertyName)
                                    .Select(
                    p => new
                {
                    p.PropertyName, CSharpSafePropertyName =
                        p.PropertyName.MakeSafeForCSharpClass(resourceClass.Name)
                }),
                HasOneToOneRelationships = resourceClass.EmbeddedObjects.Any(), OneToOneClassList = resourceClass.EmbeddedObjects
                                                                                                    .Select(
                    x => new
                {
                    OtherClassName =
                        x.PropertyName
                }),
                BaseNavigableChildrenList = resourceClass.Collections
                                            .Where(c => c.IsInherited)
                                            .Select(
                    c => new
                {
                    OtherClassPlural = c.PropertyName, OtherClassSingular = c.ItemType.Name
                }),
                NavigableChildrenList = resourceClass.Collections
                                        .Where(c => !c.IsInherited)
                                        .Select(
                    c => new
                {
                    IsExtensionClass = resourceClass.IsResourceExtensionClass,
                    IsCollectionAggregateExtension = c.ItemType.Entity.IsAggregateExtensionTopLevelEntity,
                    ParentName = (resourceClass as ResourceChildItem)?.Parent.Name,
                    ChildClassPlural = c.PropertyName, ChildClassSingular = c.ItemType.Name
                }),

                // Only Ed-Fi Standard entities that are non-lookups can have extensions
                IsExtendable = resourceClass.IsEdFiStandardResource &&
                               !resourceClass.IsLookup() &&
                               !resourceClass.IsDescriptorEntity() &&
                               !resourceClass.IsAbstract(),
                IsBaseClassConcrete = IsBaseClassConcrete(resourceClass), IsBaseEntity = resourceClass.Entity?.IsBase,
                DerivedEntitiesList = BuildDerivedEntities(resourceClass), IsRootEntity = resourceClass is Resource, ContextualKeysList =
                    resourceClass.IdentifyingProperties
                    .OrderBy(p => p.PropertyName)
                    .Select(
                        p => new
                {
                    CSharpSafePropertyName = p.PropertyName.MakeSafeForCSharpClass(resourceClass.Name)
                }),
                SourceSupportPropertyList = BuildSourceSupportProperties(resourceClass), FilterDelegatePropertyList = resourceClass.Collections
                                                                                                                      .OrderBy(
                    c => c
                    .ItemType
                    .Name)
                                                                                                                      .Select(
                    c => new
                {
                    PropertyName
                        = c
                          .ItemType
                          .Name
                }),
                HasAggregateReferences =
                    resourceClass.Entity?.GetAssociationsToReferenceableAggregateRoots(includeInherited: true).Any(),
                AggregateReferences =
                    resourceClass.Entity?.GetAssociationsToReferenceableAggregateRoots(includeInherited: true)
                    .OrderBy(a => a.Name)
                    .Select(
                        a => new
                {
                    AggregateReferenceName = a.Name,
                    MappedReferenceDataHasDiscriminator = a.OtherEntity.HasDiscriminator()
                })
            });
        }
Пример #2
0
        private object CreateResourceClass(ResourceProfileData profileData, ResourceClassBase resourceClass)
        {
            // NOTE model matching
            if (resourceClass.IsAbstract())
            {
                return(new
                {
                    ResourceReference = new
                    {
                        ReferenceName = resourceClass.Name,
                        ReferenceIdentifiers =
                            _resourcePropertyRenderer.AssembleIdentifiers(profileData, resourceClass),
                        Href = AssembleHref(profileData, resourceClass),
                        HasDiscriminator = resourceClass.HasDiscriminator()
                    },
                    ShouldRenderClass = false,
                    HasDiscriminator = resourceClass.HasDiscriminator()
                });
            }

            var parentResource = (resourceClass as ResourceChildItem)?.Parent;

            // NOTE model matching
            if (parentResource != null && parentResource.IsAbstract() &&
                parentResource.Entity?.IsSameAggregate(resourceClass.Entity) != true)
            {
                return(new { ShouldRenderClass = false });
            }

            object putPostRequestValidator = _resourceCollectionRenderer.CreatePutPostRequestValidator(profileData, resourceClass, TemplateContext);

            // Contextual parent handling
            var resourceAsChildItem = resourceClass as ResourceChildItem;
            var contextualParent    = GetContextualParent(resourceAsChildItem, profileData);

            var parentProperCaseSchemaName =
                contextualParent?.ResourceModel.SchemaNameMapProvider
                .GetSchemaMapByPhysicalName(contextualParent.FullName.Schema)
                .ProperCaseName;

            var collections = _resourceCollectionRenderer.Collections(profileData, resourceClass, TemplateContext);

            return(new
            {
                ShouldRenderClass = true,
                ResourceReference = resourceClass.IsAggregateReference()
                    ? new
                {
                    ReferenceName = resourceClass.Name,
                    ReferenceIdentifiers = _resourcePropertyRenderer
                                           .AssembleIdentifiers(profileData, resourceClass),
                    Href = AssembleHref(profileData, resourceClass)
                }
                    : ResourceRenderer.DoNotRenderProperty,
                ContextSpecificResourceReferences = CreateContextSpecificResourceReferences(profileData, resourceClass),
                ClassName = resourceClass.Name,
                EntityName = resourceClass.Name,
                Constructor = AssembleConstructor(profileData, resourceClass),
                HasCollections = ((IList)collections).Count > 0,
                Collections = collections,
                Identifiers = _resourcePropertyRenderer.AssemblePrimaryKeys(profileData, resourceClass, TemplateContext),
                NonIdentifiers = _resourcePropertyRenderer.AssembleProperties(resourceClass),
                InheritedProperties = _resourcePropertyRenderer.AssembleInheritedProperties(profileData, resourceClass),
                InheritedCollections =
                    _resourceCollectionRenderer.InheritedCollections(profileData, resourceClass, TemplateContext),
                OnDeserialize = _resourceCollectionRenderer.OnDeserialize(profileData, resourceClass, TemplateContext),
                Guid =
                    resourceClass.IsAggregateRoot()
                        ? new
                {
                    ResourceName = resourceClass.Name,
                    GuidConverterTypeName = "GuidConverter"
                }
                        : ResourceRenderer.DoNotRenderProperty,
                NavigableOneToOnes = _resourceCollectionRenderer.NavigableOneToOnes(profileData, resourceClass),
                InheritedNavigableOneToOnes = _resourceCollectionRenderer.InheritedNavigableOneToOnes(profileData, resourceClass),
                SynchronizationSourceSupport =
                    _resourceCollectionRenderer
                    .SynchronizationSourceSupport(profileData, resourceClass, TemplateContext),
                Versioning = resourceClass.IsAggregateRoot()
                    ? ResourceRenderer.DoRenderProperty
                    : ResourceRenderer.DoNotRenderProperty,
                References = _resourceCollectionRenderer.References(profileData, resourceClass, TemplateContext),
                FQName = resourceClass.FullName,
                IsAbstract = resourceClass.IsAbstract(),
                IsAggregateRoot = resourceClass.IsAggregateRoot(),
                DerivedName = resourceClass.IsDerived
                    ? $@", {EdFiConventions.BuildNamespace(
                            Namespaces.Entities.Common.RelativeNamespace,
                            resourceClass.Entity.BaseEntity.SchemaProperCaseName())
                        }.I{resourceClass.Entity.BaseEntity.Name}"
                    : ResourceRenderer.DoNotRenderProperty,
                ParentName = contextualParent?.Name,
                ParentFieldName = contextualParent?.Name.ToCamelCase(),
                InterfaceParentFieldName = contextualParent?.Name,
                ParentNamespacePrefix = parentProperCaseSchemaName == null
                    ? null
                    : $"{Namespaces.Entities.Common.RelativeNamespace}.{parentProperCaseSchemaName}.",
                IsBaseClassConcrete = resourceClass.Entity != null &&
                                      resourceClass.Entity.IsDerived &&
                                      resourceClass.Entity.BaseEntity != null &&
                                      !resourceClass.Entity.BaseEntity.IsAbstractRequiringNoCompositeId(),
                DerivedBaseTypeName = resourceClass.IsDerived && resourceClass.Entity != null
                    ? resourceClass.Entity.BaseEntity?.Name
                    : ResourceRenderer.DoNotRenderProperty,
                FilteredDelegates = _resourceCollectionRenderer.FilteredDelegates(profileData, resourceClass),
                ShouldRenderValidator = putPostRequestValidator != ResourceRenderer.DoNotRenderProperty,
                Validator = putPostRequestValidator,
                IsExtendable = resourceClass.IsExtendable(),
                IsProfileProject = TemplateContext.IsProfiles,
                HasSupportedExtensions = profileData.SuppliedResource.Extensions.Any(),
                SupportedExtensions = profileData.SuppliedResource.Extensions
                                      .Select(e => new { ExtensionName = TemplateContext.GetSchemaProperCaseNameForExtension(e) }),
                IsEdFiResource = resourceClass.IsEdFiResource(),
                NamespacePrefix = resourceClass.GetNamespacePrefix(),
                HasDiscriminator = resourceClass.HasDiscriminator(),

                // Foreign Key Discriminators should not have any profile applied to this, as this data is required for links
                ResourceReferences = CreateResourceReferences(resourceClass)
            });
        }